diff options
| author | Alex Castañeiras Bueno <33935297+acastaneiras@users.noreply.github.com> | 2025-06-24 16:49:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-25 00:49:33 +1000 |
| commit | 9c4cab53b876c0229a24af0dd9b900dd6c87d9f4 (patch) | |
| tree | a110d9cc8a29afa7c41dd98f6be00b1ae17e0415 | |
| parent | lock: fix space inputs (diff) | |
| download | caelestia-shell-9c4cab53b876c0229a24af0dd9b900dd6c87d9f4.tar.gz caelestia-shell-9c4cab53b876c0229a24af0dd9b900dd6c87d9f4.tar.bz2 caelestia-shell-9c4cab53b876c0229a24af0dd9b900dd6c87d9f4.zip | |
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>
| -rw-r--r-- | services/SystemUsage.qml | 44 |
1 files 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 @@ -136,15 +137,37 @@ 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; |