Skip to content

Commit

Permalink
Merge branch 'dev' into added/additional-indicators-and-status-bar-items
Browse files Browse the repository at this point in the history
  • Loading branch information
stsdc authored Sep 4, 2024
2 parents f5b9aaf + 764e56e commit 5c2d342
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/Resources/GPU/GPUAmd.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,53 @@ public class Monitor.GPUAmd : IGPU, Object {

public double temperature { get; protected set; }

private string path { get; set; }

construct {
// session_manager = get_sessman ();
// When path for GPU is created it can be assigned to card0 or card1
// this a bit random. This should be removed when multiple GPU
// support will be added.
try {
var dir = Dir.open ("/sys/class/drm/");
string ? name;
while ((name = dir.read_name ()) != null) {
if (name == "card0") {
path = "/sys/class/drm/card0/";
debug ("GPU path: %s", path);

} else if (name == "card1") {
path = "/sys/class/drm/card1/";
debug ("GPU path: %s", path);

}
}
if (path == null) {
debug ("Can't detect right path for AMD GPU");
}
} catch (Error e) {
print ("Error: %s\n", e.message);
}
}

private void update_temperature () {
temperature = double.parse (hwmon_temperatures.get ("edge").input) / 1000;
}

private void update_memory_vram_used () {
memory_vram_used = double.parse (get_sysfs_value ("/sys/class/drm/card0/device/mem_info_vram_used"));
memory_vram_used = double.parse (get_sysfs_value (path + "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"));
memory_vram_total = double.parse (get_sysfs_value (path + "device/mem_info_vram_total"));
}

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

private void update_percentage () {
percentage = int.parse (get_sysfs_value ("/sys/class/drm/card0/device/gpu_busy_percent"));
percentage = int.parse (get_sysfs_value (path + "device/gpu_busy_percent"));
}

public void update () {
Expand Down

0 comments on commit 5c2d342

Please sign in to comment.