diff --git a/src/Resources/GPU/GPUAmd.vala b/src/Resources/GPU/GPUAmd.vala index c57667df..667ab300 100644 --- a/src/Resources/GPU/GPUAmd.vala +++ b/src/Resources/GPU/GPUAmd.vala @@ -1,5 +1,5 @@ public class Monitor.GPUAmd : IGPU, Object { - public SessionManager? session_manager { get; protected set; } + public SessionManager ? session_manager { get; protected set; } public Gee.HashMap hwmon_temperatures { get; set; } @@ -9,12 +9,14 @@ public class Monitor.GPUAmd : IGPU, Object { public int memory_percentage { get; protected set; } - public int memory_vram_used { get; protected set; } + public double memory_vram_used { get; protected set; } + + public double memory_vram_total { get; set; } public double temperature { get; protected set; } construct { - // session_manager = get_sessman (); + // session_manager = get_sessman (); } private void update_temperature () { @@ -22,11 +24,15 @@ public class Monitor.GPUAmd : IGPU, Object { } private void update_memory_vram_used () { - memory_vram_used = int.parse (get_sysfs_value ("/sys/class/drm/card0/device/mem_info_vram_used")); + memory_vram_used = double.parse (get_sysfs_value ("/sys/class/drm/card0/device/mem_info_vram_used")); + } + + private void update_memory_vram_total () { + memory_vram_total = double.parse (get_sysfs_value ("/sys/class/drm/card0/device/mem_info_vram_total"));; } private void update_memory_percentage () { - memory_percentage = int.parse (get_sysfs_value ("/sys/class/drm/card0/device/mem_busy_percent")); + memory_percentage = (int) (Math.round ((memory_vram_used / memory_vram_total) * 100)); } private void update_percentage () { @@ -36,7 +42,9 @@ public class Monitor.GPUAmd : IGPU, Object { public void update () { update_temperature (); update_memory_vram_used (); + update_memory_vram_total (); update_memory_percentage (); update_percentage (); } + } diff --git a/src/Resources/GPU/GPUNvidia.vala b/src/Resources/GPU/GPUNvidia.vala index 66afe19b..1074d6a4 100644 --- a/src/Resources/GPU/GPUNvidia.vala +++ b/src/Resources/GPU/GPUNvidia.vala @@ -1,5 +1,5 @@ public class Monitor.GPUNvidia : IGPU, Object { - public SessionManager? session_manager { get; protected set; } + public SessionManager ? session_manager { get; protected set; } public Gee.HashMap hwmon_temperatures { get; set; } @@ -9,7 +9,9 @@ public class Monitor.GPUNvidia : IGPU, Object { public int memory_percentage { get; protected set; } - public int memory_vram_used { get; protected set; } + public double memory_vram_used { get; protected set; } + + public double memory_vram_total { get; set; } public double temperature { get; protected set; } @@ -21,7 +23,7 @@ public class Monitor.GPUNvidia : IGPU, Object { public int nvidia_percentage = 0; - public char *nvidia_used = ""; + public char * nvidia_used = ""; public bool nvidia_resources_temperature; @@ -32,7 +34,7 @@ public class Monitor.GPUNvidia : IGPU, Object { public X.Display nvidia_display; construct { - // session_manager = get_sessman (); + // session_manager = get_sessman (); nvidia_display = new X.Display (); } @@ -43,7 +45,7 @@ public class Monitor.GPUNvidia : IGPU, Object { 0, NV_CTRL_GPU_CORE_TEMPERATURE, &nvidia_temperature - ); + ); if (!nvidia_resources_temperature) { warning ("Could not query NV_CTRL_GPU_CORE_TEMPERATURE attribute!\n"); @@ -57,11 +59,11 @@ public class Monitor.GPUNvidia : IGPU, Object { 0, NV_CTRL_USED_DEDICATED_GPU_MEMORY, &nvidia_memory_vram_used - ); + ); if (!nvidia_resources_vram_used) { warning ("Could not query NV_CTRL_USED_DEDICATED_GPU_MEMORY attribute!\n"); - return ; + return; } nvidia_resources_used = NVCtrl.XNVCTRLQueryTargetStringAttribute ( @@ -71,28 +73,39 @@ public class Monitor.GPUNvidia : IGPU, Object { 0, NV_CTRL_STRING_GPU_UTILIZATION, &nvidia_used - ); + ); // 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_percentage = int.parse (((string) nvidia_used).split_set ("=,")[1]); + nvidia_memory_percentage = int.parse (((string) nvidia_used).split_set ("=,")[3]); debug ("USED_GRAPHICS: %d%\n", nvidia_percentage); debug ("USED_MEMORY: %d%\n", nvidia_memory_percentage); if (!nvidia_resources_used) { warning ("Could not query NV_CTRL_STRING_GPU_UTILIZATION attribute!\n"); - return ; + return; } } - private void update_temperature () { temperature = nvidia_temperature; } + private void update_temperature () { + temperature = nvidia_temperature; + } + + private void update_memory_vram_used () { + memory_vram_used = (double) nvidia_memory_vram_used; + } - private void update_memory_vram_used () { memory_vram_used = nvidia_memory_vram_used; } + private void update_memory_vram_total () { + } - private void update_memory_percentage () { memory_percentage = nvidia_memory_percentage; } + private void update_memory_percentage () { + memory_percentage = nvidia_memory_percentage; + } - private void update_percentage () { percentage = nvidia_percentage; } + private void update_percentage () { + percentage = nvidia_percentage; + } public void update () { update_nv_resources (); @@ -101,4 +114,5 @@ public class Monitor.GPUNvidia : IGPU, Object { update_memory_percentage (); update_percentage (); } + } diff --git a/src/Resources/GPU/IGPU.vala b/src/Resources/GPU/IGPU.vala index d15abce5..82abe02a 100644 --- a/src/Resources/GPU/IGPU.vala +++ b/src/Resources/GPU/IGPU.vala @@ -1,5 +1,5 @@ public interface Monitor.IGPU : Object { - public abstract SessionManager? session_manager { get; public set; } + public abstract SessionManager ? session_manager { get; public set; } public abstract Gee.HashMap hwmon_temperatures { get; set; } @@ -15,7 +15,9 @@ public interface Monitor.IGPU : Object { public abstract int memory_percentage { get; protected set; } - public abstract int memory_vram_used { get; protected set; } + public abstract double memory_vram_used { get; protected set; } + + public abstract double memory_vram_total { get; protected set; } public abstract double temperature { get; protected set; } @@ -23,6 +25,8 @@ public interface Monitor.IGPU : Object { public abstract void update_memory_vram_used (); + public abstract void update_memory_vram_total (); + public abstract void update_memory_percentage (); public abstract void update_percentage (); @@ -40,4 +44,5 @@ public interface Monitor.IGPU : Object { } return content; } + }