Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

system-monitor-graph@rcassani: Add error handling for amdgpu #1407

Merged
merged 6 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ SystemMonitorGraph.prototype = {
this.ram_values = new Array(2).fill(0.0);
this.swap_values = new Array(2).fill(0.0);
this.hdd_values = new Array(4).fill(0.0);
this.gpu_use = 0;
this.gpu_use = NaN;
this.gpu_mem = new Array(2).fill(0.0);

// set colors
Expand Down Expand Up @@ -514,21 +514,31 @@ SystemMonitorGraph.prototype = {
},

get_nvidia_gpu_use: function() {
let subprocess = Gio.Subprocess.new(
['/usr/bin/nvidia-smi', '--query-gpu=utilization.gpu', '--format=csv', '--id='+ this.gpu_id],
Gio.SubprocessFlags.STDOUT_PIPE|Gio.SubprocessFlags.STDERR_PIPE
);
let subprocess
try {
subprocess = Gio.Subprocess.new(
['/usr/bin/nvidia-smi', '--query-gpu=utilization.gpu', '--format=csv', '--id='+ this.gpu_id],
Gio.SubprocessFlags.STDOUT_PIPE|Gio.SubprocessFlags.STDERR_PIPE
);
} catch (err) {
return;
}
subprocess.communicate_utf8_async(null, null, (subprocess, result) => {
let [, stdout, stderr] = subprocess.communicate_utf8_finish(result);
this.gpu_use = parseInt(stdout.match(/[^\r\n]+/g)[1]); // parse integer in second line
});
},

get_nvidia_gpu_mem: function() {
let subprocess = Gio.Subprocess.new(
['/usr/bin/nvidia-smi', '--query-gpu=memory.total,memory.used', '--format=csv', '--id='+ this.gpu_id],
Gio.SubprocessFlags.STDOUT_PIPE|Gio.SubprocessFlags.STDERR_PIPE
);
let subprocess
try {
subprocess = Gio.Subprocess.new(
['/usr/bin/nvidia-smi', '--query-gpu=memory.total,memory.used', '--format=csv', '--id='+ this.gpu_id],
Gio.SubprocessFlags.STDOUT_PIPE|Gio.SubprocessFlags.STDERR_PIPE
);
} catch {
return;
}
subprocess.communicate_utf8_async(null, null, (subprocess, result) => {
let [, stdout, stderr] = subprocess.communicate_utf8_finish(result);
let fslines = stdout.split(/\r?\n/); // Line0:Headers Line1:Values
Expand All @@ -555,39 +565,46 @@ SystemMonitorGraph.prototype = {

// File gpu_busy_percent contains the percentage of time that the gpu is busy
// expresed as an integer number from 0 to 100
let [, gpu_use_bytes, ] = Gio.File.new_for_path(gpu_dir + "gpu_busy_percent").load_contents(null);
let gpu_use = parseInt(ByteArray.toString(gpu_use_bytes));
GLib.free(gpu_use_bytes);

this.gpu_use = gpu_use_bytes;
Gio.File.new_for_path(gpu_dir + "gpu_busy_percent").load_contents_async(null, (file, response) => {
let [success, contents, tag] = file.load_contents_finish(response);
if(success) {
this.gpu_use = parseInt(ByteArray.toString(contents));
}
GLib.free(contents);
});
},

get_amdgpu_gpu_mem: function() {
// Sysfs directory with files related to the chosen gpu
let gpu_dir = "/sys/class/drm/card" + this.gpu_id + "/device/";

// File mem_info_vram_total contains the total amount of gpu VRAM in bytes
let [, mem_tot_bytes, ] = Gio.File.new_for_path(gpu_dir + "mem_info_vram_total").load_contents(null);
let mem_tot = parseInt(ByteArray.toString(mem_tot_bytes));
GLib.free(mem_tot_bytes);
Gio.File.new_for_path(gpu_dir + "mem_info_vram_total").load_contents_async(null, (file, response) => {
let [success, contents, tag] = file.load_contents_finish(response);
if(success) {
let mem_tot = parseInt(ByteArray.toString(contents));
if (this.data_prefix_gpumem == 1) {
this.gpu_mem[0] = mem_tot / GB_TO_B;
} else {
this.gpu_mem[0] = mem_tot / 1024 / 1024 / GIB_TO_MIB;
}
}
GLib.free(contents);
});

// File mem_info_vram_used contains the used amount of gpu VRAM in bytes
let [, mem_usd_bytes, ] = Gio.File.new_for_path(gpu_dir + "mem_info_vram_used").load_contents(null);
let mem_usd = parseInt(ByteArray.toString(mem_usd_bytes));
GLib.free(mem_usd_bytes);

// Math here is different, because nvidia-smi returns memory amounts in MiB,
// but amdgpu provides them in bytes
if (this.data_prefix_gpumem == 1) {
mem_tot = mem_tot / GB_TO_B;
mem_usd = mem_usd / GB_TO_B;
} else {
mem_tot = mem_tot / 1024 / 1024 / GIB_TO_MIB;
mem_usd = mem_usd / 1024 / 1024 / GIB_TO_MIB;
}

this.gpu_mem[0] = mem_tot;
this.gpu_mem[1] = mem_usd;
Gio.File.new_for_path(gpu_dir + "mem_info_vram_used").load_contents_async(null, (file, response) => {
let [success, contents, tag] = file.load_contents_finish(response);
if(success) {
let mem_usd = parseInt(ByteArray.toString(contents));
if (this.data_prefix_gpumem == 1) {
this.gpu_mem[1] = mem_usd / GB_TO_B;
} else {
this.gpu_mem[1] = mem_usd / 1024 / 1024 / GIB_TO_MIB;
}
}
GLib.free(contents);
});
}

};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"uuid": "system-monitor-graph@rcassani",
"name": "System monitor graph",
"description": "Creates graphs for system variables.",
"version": "1.8",
"version": "1.9",
"prevent-decorations": true
}