dashboard: fix performance gpu stats

This commit is contained in:
2 * r + 2 * t 2025-06-02 21:25:47 +10:00
parent f52ecc446f
commit 2054708406

View file

@ -135,7 +135,11 @@ Singleton {
command: ["sh", "-c", "cat /sys/class/drm/card*/device/gpu_busy_percent"] command: ["sh", "-c", "cat /sys/class/drm/card*/device/gpu_busy_percent"]
stdout: SplitParser { stdout: SplitParser {
splitMarker: "" splitMarker: ""
onRead: data => root.gpuPerc = data.trim().split("\n").reduce((acc, d) => acc + parseInt(d, 10), 0) onRead: data => {
const percs = data.trim().split("\n");
const sum = percs.reduce((acc, d) => acc + parseInt(d, 10), 0);
root.gpuPerc = sum / percs.length / 100;
}
} }
} }
@ -145,20 +149,21 @@ Singleton {
running: true running: true
command: ["sh", "-c", "sensors | jq -nRc '[inputs]'"] command: ["sh", "-c", "sensors | jq -nRc '[inputs]'"]
stdout: SplitParser { stdout: SplitParser {
readonly property var tempTest: new RegExp("^temp[0-9]+:")
onRead: data => { onRead: data => {
let eligible = false; let eligible = false;
let sum = 0; let sum = 0;
let count = 0; let count = 0;
for (const line of JSON.parse(data)) { for (const line of JSON.parse(data)) {
if (line === "Adapter: PCI Adapter") if (line === "Adapter: PCI adapter")
eligible = true; eligible = true;
else if (line === "") else if (line === "")
eligible = false; eligible = false;
else if (eligible && (line.startsWith("GPU core:") || tempTest.test(line))) { else if (eligible) {
sum += parseFloat(line).split(" ")[1]; const match = line.match(/^\w+:\s+\+([0-9]+\.[0-9]+)°C/);
count++; if (match) {
sum += parseFloat(match[1]);
count++;
}
} }
} }
root.gpuTemp = count > 0 ? sum / count : 0; root.gpuTemp = count > 0 ? sum / count : 0;