From 10bb4a89f2959bf7a88518ea4832e540c77df65a Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:34:00 +0100 Subject: [PATCH] Fixes VRAM percentage #369 --- src/Resources/GPU/GPUAmd.vala | 13 ++++++++++--- src/Resources/GPU/GPUNvidia.vala | 8 ++++++-- src/Resources/GPU/IGPU.vala | 6 +++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Resources/GPU/GPUAmd.vala b/src/Resources/GPU/GPUAmd.vala index c57667df..38ecc512 100644 --- a/src/Resources/GPU/GPUAmd.vala +++ b/src/Resources/GPU/GPUAmd.vala @@ -9,7 +9,9 @@ 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; } @@ -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,6 +42,7 @@ 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..6c325634 100644 --- a/src/Resources/GPU/GPUNvidia.vala +++ b/src/Resources/GPU/GPUNvidia.vala @@ -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; } @@ -88,7 +90,9 @@ public class Monitor.GPUNvidia : IGPU, Object { private void update_temperature () { temperature = nvidia_temperature; } - private void update_memory_vram_used () { memory_vram_used = nvidia_memory_vram_used; } + private void update_memory_vram_used () { memory_vram_used = (double) nvidia_memory_vram_used; } + + private void update_memory_vram_total () { } private void update_memory_percentage () { memory_percentage = nvidia_memory_percentage; } diff --git a/src/Resources/GPU/IGPU.vala b/src/Resources/GPU/IGPU.vala index d15abce5..bccbfc67 100644 --- a/src/Resources/GPU/IGPU.vala +++ b/src/Resources/GPU/IGPU.vala @@ -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 ();