Skip to content

Commit

Permalink
Fixes VRAM percentage #369
Browse files Browse the repository at this point in the history
  • Loading branch information
stsdc committed Feb 28, 2024
1 parent 002146e commit 10bb4a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/Resources/GPU/GPUAmd.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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 () {
Expand All @@ -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 ();
}
Expand Down
8 changes: 6 additions & 2 deletions src/Resources/GPU/GPUNvidia.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -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; }

Expand Down
6 changes: 5 additions & 1 deletion src/Resources/GPU/IGPU.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ 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; }

public abstract void update_temperature ();

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 ();
Expand Down

0 comments on commit 10bb4a8

Please sign in to comment.