diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-05-28 23:56:44 +0800 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-05-28 23:56:44 +0800 |
| commit | ea573554d47dac0bca9034aee5f3fc591ac063f3 (patch) | |
| tree | 46333e8c0abfcb9a5388cf3275c998c718dd6fc2 /services/SystemUsage.qml | |
| parent | internal: move weather into service (diff) | |
| download | caelestia-shell-ea573554d47dac0bca9034aee5f3fc591ac063f3.tar.gz caelestia-shell-ea573554d47dac0bca9034aee5f3fc591ac063f3.tar.bz2 caelestia-shell-ea573554d47dac0bca9034aee5f3fc591ac063f3.zip | |
feat: dashboard performance panel
Diffstat (limited to 'services/SystemUsage.qml')
| -rw-r--r-- | services/SystemUsage.qml | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/services/SystemUsage.qml b/services/SystemUsage.qml index c5503b9..e545210 100644 --- a/services/SystemUsage.qml +++ b/services/SystemUsage.qml @@ -8,6 +8,9 @@ Singleton { id: root property real cpuPerc + property real cpuTemp + property real gpuPerc + property real gpuTemp property int memUsed property int memTotal readonly property real memPerc: memTotal > 0 ? memUsed / memTotal : 0 @@ -18,14 +21,41 @@ Singleton { property int lastCpuIdle property int lastCpuTotal + function formatKib(kib: int): var { + const mib = 1024; + const gib = 1024 ** 2; + const tib = 1024 ** 3; + + if (kib >= tib) + return { + value: kib / tib, + unit: "TiB" + }; + if (kib >= gib) + return { + value: kib / gib, + unit: "GiB" + }; + if (kib >= mib) + return { + value: kib / mib, + unit: "MiB" + }; + return { + value: kib, + unit: "KiB" + }; + } + Timer { running: true - interval: 1000 + interval: 3000 repeat: true onTriggered: { stat.reload(); meminfo.reload(); storage.running = true; + cpuTemp.running = true; } } @@ -81,4 +111,56 @@ Singleton { } } } + + Process { + id: cpuTemp + + running: true + command: ["fish", "-c", "cat /sys/class/thermal/thermal_zone*/temp | string join ' '"] + stdout: SplitParser { + onRead: data => { + const temps = data.trim().split(" "); + const sum = temps.reduce((acc, d) => acc + parseInt(d, 10), 0); + root.cpuTemp = sum / temps.length / 1000; + } + } + } + + Process { + id: gpuUsage + + running: true + command: ["sh", "-c", "cat /sys/class/drm/card*/device/gpu_busy_percent"] + stdout: SplitParser { + splitMarker: "" + onRead: data => root.gpuPerc = data.trim().split("\n").reduce((acc, d) => acc + parseInt(d, 10), 0) + } + } + + Process { + id: gpuTemp + + running: true + command: ["sh", "-c", "sensors | jq -nRc '[inputs]'"] + stdout: SplitParser { + readonly property var tempTest: new RegExp("^temp[0-9]+:") + + onRead: data => { + let eligible = false; + let sum = 0; + let count = 0; + for (const line of JSON.parse(data)) { + if (line === "Adapter: PCI Adapter") + eligible = true; + else if (line === "") + eligible = false; + else if (eligible && (line.startsWith("GPU core:") || tempTest.test(line))) { + sum += parseFloat(line).split(" ")[1]; + count++; + } + } + root.gpuTemp = count > 0 ? sum / count : 0; + } + } + } } |