diff options
Diffstat (limited to 'services')
| -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; |