Skip to content

Commit

Permalink
added: additional indicators for cpu freq and vram
Browse files Browse the repository at this point in the history
added: additional status bar icons for gpu and vram
fixed: nvidia vram indicator was displaying fb usage, not vram
fixed: possible crash case when a gpu was not detected
  • Loading branch information
ProPuke committed Aug 29, 2024
1 parent df89439 commit ccd7d50
Show file tree
Hide file tree
Showing 15 changed files with 320 additions and 60 deletions.
20 changes: 15 additions & 5 deletions data/com.github.stsdc.monitor.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,21 @@
<summary>To show CPU usage in Monitor Indicator or not</summary>
<description>To show CPU usage in Monitor Indicator or not</description>
</key>
<key type='b' name="indicator-cpu-frequency-state">
<default>false</default>
<summary>To show CPU frequency in Monitor Indicator or not</summary>
<description>To show CPU frequency in Monitor Indicator or not</description>
</key>
<key type='b' name="indicator-cpu-temperature-state">
<default>true</default>
<summary>To show CPU temperature value in Monitor Indicator or not</summary>
<description>To show CPU temperature value in Monitor Indicator or not</description>
</key>
<key type='b' name="indicator-memory-state">
<default>true</default>
<summary>To show memory usage in Monitor Indicator or not</summary>
<description>To show memory usage in Monitor Indicator or not</description>
</key>
<key type='b' name="indicator-temperature-state">
<default>true</default>
<summary>To show temperature value in Monitor Indicator or not</summary>
<description>To show temperature value in Monitor Indicator or not</description>
</key>
<key type='b' name="indicator-network-upload-state">
<default>false</default>
<summary>To show network up bandwidth data in Monitor Indicator or not</summary>
Expand All @@ -70,6 +75,11 @@
<summary>To show GPU used percentage in Monitor Indicator or not</summary>
<description>To show GPU used percentage in Monitor Indicator or not</description>
</key>
<key type='b' name="indicator-gpu-memory-state">
<default>false</default>
<summary>To show GPU memory usage in Monitor Indicator or not</summary>
<description>To show GPU memory usage in Monitor Indicator or not</description>
</key>
<key type='b' name="indicator-gpu-temperature-state">
<default>false</default>
<summary>To show GPU temperature in Monitor Indicator or not</summary>
Expand Down
3 changes: 2 additions & 1 deletion data/icons/icons.indicator.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<gresources>
<gresource prefix="/com/github/stsdc/monitor/icons">
<file compressed="true" preprocess="xml-stripblanks">cpu-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">ram-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">gpu-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">ram-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">memory-gpu-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">swap-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">file-deleted-symbolic.svg</file>
<file compressed="true" preprocess="xml-stripblanks">temperature-sensor-symbolic.svg</file>
Expand Down
112 changes: 112 additions & 0 deletions data/icons/memory-gpu-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions src/Indicator/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,37 @@ public class Monitor.Indicator : Wingpanel.Indicator {
dbusclient.monitor_appeared.connect (() => {
this.visible = settings.get_boolean ("indicator-state");
display_widget.cpu_widget.visible = settings.get_boolean ("indicator-cpu-state");
display_widget.cpu_frequency_widget.visible = settings.get_boolean ("indicator-cpu-frequency-state");
display_widget.cpu_temperature_widget.visible = settings.get_boolean ("indicator-cpu-temperature-state");
display_widget.memory_widget.visible = settings.get_boolean ("indicator-memory-state");
display_widget.temperature_widget.visible = settings.get_boolean ("indicator-temperature-state");
display_widget.network_up_widget.visible = settings.get_boolean ("indicator-network-upload-state");
display_widget.network_down_widget.visible = settings.get_boolean ("indicator-network-download-state");
display_widget.gpu_widget.visible = settings.get_boolean ("indicator-gpu-state");
display_widget.gpu_memory_widget.visible = settings.get_boolean ("indicator-gpu-memory-state");
display_widget.gpu_temperature_widget.visible = settings.get_boolean ("indicator-gpu-temperature-state");

});

dbusclient.interface.indicator_state.connect ((state) => this.visible = state);
dbusclient.interface.indicator_cpu_state.connect ((state) => display_widget.cpu_widget.visible = state);
dbusclient.interface.indicator_cpu_frequency_state.connect ((state) => display_widget.cpu_frequency_widget.visible = state);
dbusclient.interface.indicator_cpu_temperature_state.connect ((state) => display_widget.cpu_temperature_widget.visible = state);
dbusclient.interface.indicator_memory_state.connect ((state) => display_widget.memory_widget.visible = state);
dbusclient.interface.indicator_temperature_state.connect ((state) => display_widget.temperature_widget.visible = state);
dbusclient.interface.indicator_network_up_state.connect ((state) => display_widget.network_up_widget.visible = state);
dbusclient.interface.indicator_network_down_state.connect ((state) => display_widget.network_down_widget.visible = state);
dbusclient.interface.indicator_gpu_state.connect ((state) => display_widget.gpu_widget.visible = state);
dbusclient.interface.indicator_gpu_memory_state.connect ((state) => display_widget.gpu_memory_widget.visible = state);
dbusclient.interface.indicator_gpu_temperature_state.connect ((state) => display_widget.gpu_temperature_widget.visible = state);

dbusclient.interface.update.connect ((sysres) => {
display_widget.cpu_widget.state_percentage = sysres.cpu_percentage;
display_widget.temperature_widget.state_temperature = (int) Math.round (sysres.cpu_temperature);
display_widget.cpu_frequency_widget.state_frequency = sysres.cpu_frequency;
display_widget.cpu_temperature_widget.state_temperature = (int) Math.round (sysres.cpu_temperature);
display_widget.memory_widget.state_percentage = sysres.memory_percentage;
display_widget.network_up_widget.state_bandwidth = sysres.network_up;
display_widget.network_down_widget.state_bandwidth = sysres.network_down;
display_widget.gpu_widget.state_percentage = sysres.gpu_percentage;
display_widget.gpu_memory_widget.state_percentage = sysres.gpu_memory_percentage;
display_widget.gpu_temperature_widget.state_temperature = (int) Math.round (sysres.gpu_temperature);
});

Expand Down
4 changes: 3 additions & 1 deletion src/Indicator/Services/DBusClient.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ public interface Monitor.DBusClientInterface : Object {
public signal void update (ResourcesSerialized data);
public signal void indicator_state (bool state);
public signal void indicator_cpu_state (bool state);
public signal void indicator_cpu_frequency_state (bool state);
public signal void indicator_cpu_temperature_state (bool state);
public signal void indicator_memory_state (bool state);
public signal void indicator_temperature_state (bool state);
public signal void indicator_network_up_state (bool state);
public signal void indicator_network_down_state (bool state);
public signal void indicator_gpu_state (bool state);
public signal void indicator_gpu_memory_state (bool state);
public signal void indicator_gpu_temperature_state (bool state);

}
Expand Down
9 changes: 7 additions & 2 deletions src/Indicator/Widgets/DisplayWidget.vala
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
public class Monitor.Widgets.DisplayWidget : Gtk.Grid {
public IndicatorWidget cpu_widget = new IndicatorWidget ("cpu-symbolic");
public IndicatorWidget cpu_frequency_widget = new IndicatorWidget ("cpu-symbolic");
public IndicatorWidget cpu_temperature_widget = new IndicatorWidget ("temperature-sensor-symbolic");

public IndicatorWidget memory_widget = new IndicatorWidget ("ram-symbolic");

public IndicatorWidget temperature_widget = new IndicatorWidget ("temperature-sensor-symbolic");
public IndicatorWidget network_up_widget = new IndicatorWidget ("go-up-symbolic");
public IndicatorWidget network_down_widget = new IndicatorWidget ("go-down-symbolic");

public IndicatorWidget gpu_widget = new IndicatorWidget ("gpu-symbolic");
public IndicatorWidget gpu_memory_widget = new IndicatorWidget ("memory-gpu-symbolic");
public IndicatorWidget gpu_temperature_widget = new IndicatorWidget ("temperature-gpu-symbolic");

construct {
valign = Gtk.Align.CENTER;

add (cpu_widget);
add (cpu_frequency_widget);
add (cpu_temperature_widget);
add (memory_widget);
add (gpu_widget);
add (gpu_memory_widget);
add (gpu_temperature_widget);
add (temperature_widget);
add (network_up_widget);
add (network_down_widget);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Indicator/Widgets/IndicatorWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class Monitor.IndicatorWidget : Gtk.Box {
}
}

public double state_frequency {
set {
label.label = ("%.2f %s").printf (value, _("GHz"));
}
}

public int state_bandwidth {
set {
label.label = ("%s").printf (Utils.HumanUnitFormatter.string_bytes_to_human (value.to_string (), true));
Expand Down
36 changes: 32 additions & 4 deletions src/Resources/GPU/GPUNvidia.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Monitor.GPUNvidia : IGPU, Object {

public int memory_percentage { get; protected set; }

public int fb_percentage { get; protected set; }

public double memory_vram_used { get; protected set; }

public double memory_vram_total { get; set; }
Expand All @@ -19,8 +21,12 @@ public class Monitor.GPUNvidia : IGPU, Object {

public int nvidia_memory_vram_used = 0;

public int nvidia_memory_vram_total = 0;

public int nvidia_memory_percentage = 0;

public int nvidia_fb_percentage = 0;

public int nvidia_percentage = 0;

public char * nvidia_used = "";
Expand All @@ -29,6 +35,8 @@ public class Monitor.GPUNvidia : IGPU, Object {

public bool nvidia_resources_vram_used;

public bool nvidia_resources_vram_total;

public bool nvidia_resources_used;

public X.Display nvidia_display;
Expand Down Expand Up @@ -66,6 +74,20 @@ public class Monitor.GPUNvidia : IGPU, Object {
return;
}

nvidia_resources_vram_total = NVCtrl.XNVCTRLQueryTargetAttribute (
nvidia_display,
NV_CTRL_TARGET_TYPE_GPU,
0,
0,
NV_CTRL_TOTAL_DEDICATED_GPU_MEMORY,
&nvidia_memory_vram_total
);

if (!nvidia_resources_vram_total) {
warning ("Could not query NV_CTRL_TOTAL_DEDICATED_GPU_MEMORY attribute!\n");
return;
}

nvidia_resources_used = NVCtrl.XNVCTRLQueryTargetStringAttribute (
nvidia_display,
NV_CTRL_TARGET_TYPE_GPU,
Expand All @@ -77,9 +99,9 @@ public class Monitor.GPUNvidia : IGPU, Object {

// var str_used = (string)nvidia_used;
nvidia_percentage = int.parse (((string) nvidia_used).split_set ("=,")[1]);
nvidia_memory_percentage = int.parse (((string) nvidia_used).split_set ("=,")[3]);
nvidia_fb_percentage = int.parse (((string) nvidia_used).split_set ("=,")[3]);
debug ("USED_GRAPHICS: %d%\n", nvidia_percentage);
debug ("USED_MEMORY: %d%\n", nvidia_memory_percentage);
debug ("USED_FB_MEMORY: %d%\n", nvidia_fb_percentage);

if (!nvidia_resources_used) {
warning ("Could not query NV_CTRL_STRING_GPU_UTILIZATION attribute!\n");
Expand All @@ -93,14 +115,19 @@ public class Monitor.GPUNvidia : IGPU, Object {
}

private void update_memory_vram_used () {
memory_vram_used = (double) nvidia_memory_vram_used;
memory_vram_used = (double) nvidia_memory_vram_used * 1000000.0;
}

private void update_memory_vram_total () {
memory_vram_total = (double) nvidia_memory_vram_total * 1000000.0;
}

private void update_memory_percentage () {
memory_percentage = nvidia_memory_percentage;
memory_percentage = (int) (Math.round ((memory_vram_used / memory_vram_total) * 100));
}

private void update_fb_percentage () {
fb_percentage = nvidia_fb_percentage;
}

private void update_percentage () {
Expand All @@ -111,6 +138,7 @@ public class Monitor.GPUNvidia : IGPU, Object {
update_nv_resources ();
update_temperature ();
update_memory_vram_used ();
update_memory_vram_total ();
update_memory_percentage ();
update_percentage ();
}
Expand Down
29 changes: 16 additions & 13 deletions src/Resources/Resources.vala
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,22 @@ public class Monitor.Resources : Object {

public ResourcesSerialized serialize () {
return ResourcesSerialized () {
cpu_percentage = cpu.percentage,
cpu_frequency = cpu.frequency,
cpu_temperature = cpu.temperature_mean,
memory_percentage = memory.used_percentage,
memory_used = memory.used,
memory_total = memory.total,
swap_percentage = swap.percentage,
swap_used = swap.used,
swap_total = swap.total,
network_up = network.bytes_out,
network_down = network.bytes_in,
gpu_percentage = gpu != null ? gpu.percentage : 0,
gpu_temperature = gpu.temperature
cpu_percentage = cpu.percentage,
cpu_frequency = cpu.frequency,
cpu_temperature = cpu.temperature_mean,
memory_percentage = memory.used_percentage,
memory_used = memory.used,
memory_total = memory.total,
swap_percentage = swap.percentage,
swap_used = swap.used,
swap_total = swap.total,
network_up = network.bytes_out,
network_down = network.bytes_in,
gpu_percentage = gpu != null ? gpu.percentage : 0,
gpu_memory_percentage = gpu != null ? gpu.memory_percentage : 0,
gpu_memory_used = gpu != null ? gpu.memory_vram_used : 0,
gpu_memory_total = gpu != null ? gpu.memory_vram_total : 0,
gpu_temperature = gpu != null ? gpu.temperature : 0
};
}
}
Loading

0 comments on commit ccd7d50

Please sign in to comment.