From 9c4cab53b876c0229a24af0dd9b900dd6c87d9f4 Mon Sep 17 00:00:00 2001 From: Alex Castañeiras Bueno <33935297+acastaneiras@users.noreply.github.com> Date: Tue, 24 Jun 2025 16:49:33 +0200 Subject: 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> --- services/SystemUsage.qml | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/services/SystemUsage.qml b/services/SystemUsage.qml index 7cdcace..f4cbc4f 100644 --- a/services/SystemUsage.qml +++ b/services/SystemUsage.qml @@ -9,6 +9,7 @@ Singleton { property real cpuPerc property real cpuTemp + property string gpuType: "NONE" property real gpuPerc property real gpuTemp 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 { id: gpuUsage 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 { onStreamFinished: { - const percs = text.trim().split("\n"); - const sum = percs.reduce((acc, d) => acc + parseInt(d, 10), 0); - root.gpuPerc = sum / percs.length / 100; + if (root.gpuType === "GENERIC") { + const percs = text.trim().split("\n"); + 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 { onStreamFinished: { - let cpuTemp = text.match(/(?:Package id [0-9]+|Tdie):\s+((\+|-)[0-9.]+)(°| )C/); - if (!cpuTemp) { - // If AMD Tdie pattern failed, try fallback on Tctl - cpuTemp = text.match(/Tctl:\s+((\+|-)[0-9.]+)(°| )C/); - } + let cpuTemp = text.match(/(?:Package id [0-9]+|Tdie):\s+((\+|-)[0-9.]+)(°| )C/); + if (!cpuTemp) { + // If AMD Tdie pattern failed, try fallback on Tctl + cpuTemp = text.match(/Tctl:\s+((\+|-)[0-9.]+)(°| )C/); + } if (cpuTemp) root.cpuTemp = parseFloat(cpuTemp[1]); + if (root.gpuType !== "GENERIC") + return; + let eligible = false; let sum = 0; let count = 0; -- cgit v1.2.3-freya