systemusage: add NVIDIA GPU support to performance metrics (#156)

* systemusage: add NVIDIA GPU support to performance metrics

* some fixes

---------

Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
This commit is contained in:
Alex Castañeiras Bueno 2025-06-24 16:49:33 +02:00 committed by GitHub
parent 9da75ed626
commit 9c4cab53b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,6 +9,7 @@ Singleton {
property real cpuPerc property real cpuPerc
property real cpuTemp property real cpuTemp
property string gpuType: "NONE"
property real gpuPerc property real gpuPerc
property real gpuTemp property real gpuTemp
property int memUsed property int memUsed
@ -135,16 +136,38 @@ Singleton {
} }
} }
Process {
id: gpuTypeCheck
running: true
command: ["sh", "-c", "if ls /sys/class/drm/card*/device/gpu_busy_percent 2>/dev/null | grep -q .; then echo GENERIC; elif command -v nvidia-smi >/dev/null; then echo NVIDIA; else echo NONE; fi"]
stdout: StdioCollector {
onStreamFinished: {
root.gpuType = text.trim();
gpuUsage.running = true;
}
}
}
Process { Process {
id: gpuUsage id: gpuUsage
running: true running: true
command: ["sh", "-c", "cat /sys/class/drm/card*/device/gpu_busy_percent"] command: root.gpuType === "GENERIC" ? ["sh", "-c", "cat /sys/class/drm/card*/device/gpu_busy_percent"] : root.gpuType === "NVIDIA" ? ["nvidia-smi", "--query-gpu=utilization.gpu,temperature.gpu", "--format=csv,noheader,nounits"] : ["echo"]
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
const percs = text.trim().split("\n"); if (root.gpuType === "GENERIC") {
const sum = percs.reduce((acc, d) => acc + parseInt(d, 10), 0); const percs = text.trim().split("\n");
root.gpuPerc = sum / percs.length / 100; const sum = percs.reduce((acc, d) => acc + parseInt(d, 10), 0);
root.gpuPerc = sum / percs.length / 100;
} else if (root.gpuType === "NVIDIA") {
const [usage, temp] = text.trim().split(",");
root.gpuPerc = parseInt(usage, 10) / 100;
root.gpuTemp = parseInt(temp, 10);
} else {
root.gpuPerc = 0;
root.gpuTemp = 0;
}
} }
} }
} }
@ -160,14 +183,17 @@ Singleton {
}) })
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
let cpuTemp = text.match(/(?:Package id [0-9]+|Tdie):\s+((\+|-)[0-9.]+)(°| )C/); let cpuTemp = text.match(/(?:Package id [0-9]+|Tdie):\s+((\+|-)[0-9.]+)(°| )C/);
if (!cpuTemp) { if (!cpuTemp) {
// If AMD Tdie pattern failed, try fallback on Tctl // If AMD Tdie pattern failed, try fallback on Tctl
cpuTemp = text.match(/Tctl:\s+((\+|-)[0-9.]+)(°| )C/); cpuTemp = text.match(/Tctl:\s+((\+|-)[0-9.]+)(°| )C/);
} }
if (cpuTemp) if (cpuTemp)
root.cpuTemp = parseFloat(cpuTemp[1]); root.cpuTemp = parseFloat(cpuTemp[1]);
if (root.gpuType !== "GENERIC")
return;
let eligible = false; let eligible = false;
let sum = 0; let sum = 0;
let count = 0; let count = 0;