Use wait_async for get_nvidia_gpu_mem
This commit is contained in:
parent
36df869c64
commit
d65250d7e6
@ -100,6 +100,7 @@ SystemMonitorGraph.prototype = {
|
|||||||
this.hdd_hdd_tot = 0;
|
this.hdd_hdd_tot = 0;
|
||||||
// values to graph
|
// values to graph
|
||||||
this.gpu_use = 0;
|
this.gpu_use = 0;
|
||||||
|
this.gpu_mem = new Array(2).fill(0.0);
|
||||||
// set colors
|
// set colors
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case "cpu":
|
case "cpu":
|
||||||
@ -200,13 +201,13 @@ SystemMonitorGraph.prototype = {
|
|||||||
text2 = Math.round(this.gpu_use).toString() + "%";
|
text2 = Math.round(this.gpu_use).toString() + "%";
|
||||||
break;
|
break;
|
||||||
case "memory":
|
case "memory":
|
||||||
let gpu_mem_values = this.get_nvidia_gpu_mem();
|
this.get_nvidia_gpu_mem();
|
||||||
let gpu_mem_use = 100 * gpu_mem_values[1] / gpu_mem_values[0];
|
let gpu_mem_use = 100 * this.gpu_mem[1] / this.gpu_mem[0];
|
||||||
value = gpu_mem_use / 100;
|
value = gpu_mem_use / 100;
|
||||||
text1 = _("GPU Memory");
|
text1 = _("GPU Memory");
|
||||||
text2 = Math.round(gpu_mem_use).toString() + "%"
|
text2 = Math.round(gpu_mem_use).toString() + "%"
|
||||||
text3 = gpu_mem_values[1].toFixed(1) + " / "
|
text3 = this.gpu_mem[1].toFixed(1) + " / "
|
||||||
+ gpu_mem_values[0].toFixed(1) + " " + _("GiB");
|
+ this.gpu_mem[0].toFixed(1) + " " + _("GiB");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -426,13 +427,20 @@ SystemMonitorGraph.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get_nvidia_gpu_mem: function() {
|
get_nvidia_gpu_mem: function() {
|
||||||
let [result, stdout, stderr] = GLib.spawn_command_line_sync("nvidia-smi --query-gpu=memory.total --format=csv --id=" + this.gpu_id);
|
let subprocess = new Gio.Subprocess({
|
||||||
let mem_tot = parseInt(stdout.toString().match(/[^\r\n]+/g)[1]); // parse integer in second line
|
argv: ['nvidia-smi', '--query-gpu=memory.total,memory.used', '--format=csv', '--id='+ this.gpu_id],
|
||||||
[result, stdout, stderr] = GLib.spawn_command_line_sync("nvidia-smi --query-gpu=memory.used --format=csv --id=" + this.gpu_id);
|
flags: Gio.SubprocessFlags.STDOUT_PIPE|Gio.SubprocessFlags.STDERR_PIPE,
|
||||||
let mem_usd = parseInt(stdout.toString().match(/[^\r\n]+/g)[1]); // parse integer in second line
|
});
|
||||||
let gpu_mem_tot = mem_tot / GIB_TO_MIB;
|
subprocess.init(null);
|
||||||
let gpu_mem_usd = mem_usd / GIB_TO_MIB;
|
subprocess.wait_async(null, (sourceObject, res) => {
|
||||||
return [gpu_mem_tot, gpu_mem_usd];
|
let [, stdout, stderr] = sourceObject.communicate_utf8(null, null);
|
||||||
|
let fslines = stdout.split(/\r?\n/); // Line0:Headers Line1:Values
|
||||||
|
let items = fslines[1].split(','); // Values are comma-separated
|
||||||
|
let mem_tot = parseInt(items[0]);
|
||||||
|
let mem_usd = parseInt(items[1]);
|
||||||
|
this.gpu_mem[0] = mem_tot / GIB_TO_MIB;
|
||||||
|
this.gpu_mem[1] = mem_usd / GIB_TO_MIB;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user