From 55dd900257392efe6dd052744e75c948e474a026 Mon Sep 17 00:00:00 2001 From: zach Date: Fri, 10 Apr 2026 14:32:48 +0200 Subject: [PATCH] test fix for amd --- Helpers/SystemUsage.qml | 63 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/Helpers/SystemUsage.qml b/Helpers/SystemUsage.qml index e613060..02c035a 100644 --- a/Helpers/SystemUsage.qml +++ b/Helpers/SystemUsage.qml @@ -81,6 +81,9 @@ Singleton { meminfo.reload(); if (root.gpuType === "GENERIC") gpuUsage.running = true; + + if (root.gpuType === "GENERIC" && root.gpuMemTotal === 0) + oneshotMemAmd.running = true; } } @@ -303,6 +306,26 @@ Singleton { } } + Process { + id: oneshotMemAmd + + command: ["sh", "-c", "cat /sys/class/drm/card*/device/mem_info_vram_total"] + running: root.gpuType === "GENERIC" && root.gpuMemTotal === 0 + + stdout: StdioCollector { + onStreamFinished: { + const values = text.trim().split("\n").map(v => parseInt(v, 10)).filter(v => Number.isFinite(v)); + + if (values.length > 0) { + const totalBytes = values.reduce((a, b) => a + b, 0); + root.gpuMemTotal = totalBytes / (1024 * 1024); + } + + oneshotMemAmd.running = false; + } + } + } + Process { id: gpuUsageNvidia @@ -342,15 +365,45 @@ Singleton { Process { id: gpuUsage - command: root.gpuType === "GENERIC" ? ["sh", "-c", "cat /sys/class/drm/card*/device/gpu_busy_percent"] : ["echo"] + command: root.gpuType === "GENERIC" ? ["sh", "-c", "paste -d ' ' /sys/class/drm/card*/device/gpu_busy_percent /sys/class/drm/card*/device/mem_info_vram_used"] : ["echo"] stdout: StdioCollector { onStreamFinished: { - console.log("this is running"); 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; + const lines = text.trim().split("\n"); + + let percSum = 0; + let memSum = 0; + let count = 0; + + for (const line of lines) { + const parts = line.trim().split(/\s+/); + if (parts.length < 2) + continue; + + const gpuBusy = parseInt(parts[0], 10); + const memUsed = parseInt(parts[1], 10); + + if (!Number.isFinite(gpuBusy) || !Number.isFinite(memUsed)) + continue; + + percSum += gpuBusy; + memSum += memUsed; + count++; + } + + if (count > 0) { + // GPU usage % + root.gpuPerc = (percSum / count) / 100; + + // VRAM usage (bytes → MiB → normalized) + const memUsedMiB = memSum / (1024 * 1024); + + const newGpuMemUsed = root.gpuMemTotal > 0 ? Math.max(0, Math.min(1, memUsedMiB / root.gpuMemTotal)) : 0; + + if (Math.abs(root.gpuMemUsed - newGpuMemUsed) >= 0.01) + root.gpuMemUsed = newGpuMemUsed; + } } else { root.gpuPerc = 0; root.gpuTemp = 0;