slight changes, gpu usage down by 20%

This commit is contained in:
Zacharias-Brohn
2026-03-11 11:22:22 +01:00
parent 0375491dc8
commit bab596850b
3 changed files with 97 additions and 92 deletions
+49 -27
View File
@@ -17,7 +17,6 @@ Singleton {
property var disks: []
property real gpuMemTotal: 0
property real gpuMemUsed
property string gpuName: ""
property real gpuPerc
property real gpuTemp
readonly property string gpuType: Config.services.gpuType.toUpperCase() || autoGpuType
@@ -80,9 +79,19 @@ Singleton {
onTriggered: {
stat.reload();
meminfo.reload();
storage.running = false;
if (root.gpuName === "GENERIC")
storage.running = true;
if (root.gpuType === "GENERIC")
gpuUsage.running = true;
}
}
Timer {
interval: Config.dashboard.resourceUpdateInterval * 5
repeat: true
running: root.refCount > 0
triggeredOnStart: true
onTriggered: {
sensors.running = true;
}
}
@@ -113,10 +122,13 @@ Singleton {
const totalDiff = total - root.lastCpuTotal;
const idleDiff = idle - root.lastCpuIdle;
root.cpuPerc = totalDiff > 0 ? (1 - idleDiff / totalDiff) : 0;
const newCpuPerc = totalDiff > 0 ? (1 - idleDiff / totalDiff) : 0;
root.lastCpuTotal = total;
root.lastCpuIdle = idle;
if (Math.abs(newCpuPerc - root.cpuPerc) >= 0.01)
root.cpuPerc = newCpuPerc;
}
}
}
@@ -128,8 +140,14 @@ Singleton {
onLoaded: {
const data = text();
root.memTotal = parseInt(data.match(/MemTotal: *(\d+)/)[1], 10) || 1;
root.memUsed = (root.memTotal - parseInt(data.match(/MemAvailable: *(\d+)/)[1], 10)) || 0;
const total = parseInt(data.match(/MemTotal: *(\d+)/)[1], 10) || 1;
const used = (root.memTotal - parseInt(data.match(/MemAvailable: *(\d+)/)[1], 10)) || 0;
if (root.memTotal !== total)
root.memTotal = total;
if (Math.abs(used - root.memUsed) >= 16384)
root.memUsed = used;
}
}
@@ -279,27 +297,36 @@ Singleton {
id: gpuUsageNvidia
command: ["/usr/bin/nvidia-smi", "--query-gpu=utilization.gpu,temperature.gpu,memory.used", "--format=csv,noheader,nounits", "-lms", "1000"]
running: true
running: root.refCount > 0 && root.gpuType === "NVIDIA"
stderr: SplitParser {
onRead: data => {
console.log("nvidia-smi stderr:", String(data).trim());
}
}
stdout: SplitParser {
onRead: data => {
const [usage, temp, mem] = String(data).trim().split(/\s*,\s*/);
const parts = String(data).trim().split(/\s*,\s*/);
if (parts.length < 3)
return;
root.gpuPerc = parseInt(usage, 10) / 100;
root.gpuTemp = parseInt(temp, 10);
root.gpuMemUsed = parseInt(mem, 10) / root.gpuMemTotal;
}
}
const usageRaw = parseInt(parts[0], 10);
const tempRaw = parseInt(parts[1], 10);
const memRaw = parseInt(parts[2], 10);
onExited: (exitCode, exitStatus) => {
console.log("gpuUsageNvidia exited:", exitCode, exitStatus);
if (!Number.isFinite(usageRaw) || !Number.isFinite(tempRaw) || !Number.isFinite(memRaw))
return;
const newGpuPerc = Math.max(0, Math.min(1, usageRaw / 100));
const newGpuTemp = tempRaw;
const newGpuMemUsed = root.gpuMemTotal > 0 ? Math.max(0, Math.min(1, memRaw / root.gpuMemTotal)) : 0;
// Only publish meaningful changes to avoid needless binding churn / repaints
if (Math.abs(root.gpuPerc - newGpuPerc) >= 0.01)
root.gpuPerc = newGpuPerc;
if (Math.abs(root.gpuTemp - newGpuTemp) >= 1)
root.gpuTemp = newGpuTemp;
if (Math.abs(root.gpuMemUsed - newGpuMemUsed) >= 0.01)
root.gpuMemUsed = newGpuMemUsed;
}
}
onStarted: console.log("gpuUsageNvidia started, pid =", processId)
}
Process {
@@ -314,11 +341,6 @@ Singleton {
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, mem] = text.trim().split(",");
root.gpuPerc = parseInt(usage, 10) / 100;
root.gpuTemp = parseInt(temp, 10);
root.gpuMemUsed = parseInt(mem, 10) / root.gpuMemTotal;
} else {
root.gpuPerc = 0;
root.gpuTemp = 0;
@@ -343,7 +365,7 @@ Singleton {
// If AMD Tdie pattern failed, try fallback on Tctl
cpuTemp = text.match(/Tctl:\s+((\+|-)[0-9.]+)(°| )C/);
if (cpuTemp)
if (cpuTemp && Math.abs(parseFloat(cpuTemp[1]) - root.cpuTemp) >= 0.5)
root.cpuTemp = parseFloat(cpuTemp[1]);
if (root.gpuType !== "GENERIC")
+47 -64
View File
@@ -36,75 +36,58 @@ Item {
Component.onCompleted: animatedPercentage = percentage
onPercentageChanged: animatedPercentage = percentage
// Canvas {
// id: gaugeCanvas
//
// anchors.centerIn: parent
// height: width
// width: Math.min(parent.width, parent.height)
//
// Component.onCompleted: requestPaint()
// onPaint: {
// const ctx = getContext("2d");
// ctx.reset();
// const cx = width / 2;
// const cy = (height / 2) + 1;
// const radius = (Math.min(width, height) - 12) / 2;
// const lineWidth = 3;
// ctx.beginPath();
// ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep);
// ctx.lineWidth = lineWidth;
// ctx.lineCap = "round";
// ctx.strokeStyle = DynamicColors.layer(DynamicColors.palette.m3surfaceContainerHigh, 2);
// ctx.stroke();
// if (root.animatedPercentage > 0) {
// ctx.beginPath();
// ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep * root.animatedPercentage);
// ctx.lineWidth = lineWidth;
// ctx.lineCap = "round";
// ctx.strokeStyle = root.accentColor;
// ctx.stroke();
// }
// }
//
// Connections {
// function onAnimatedPercentageChanged() {
// gaugeCanvas.requestPaint();
// }
//
// target: root
// }
//
// Connections {
// function onPaletteChanged() {
// gaugeCanvas.requestPaint();
// }
//
// target: DynamicColors
// }
// }
Canvas {
id: gaugeCanvas
anchors.centerIn: parent
height: width
width: Math.min(parent.width, parent.height)
Component.onCompleted: requestPaint()
onPaint: {
const ctx = getContext("2d");
ctx.reset();
const cx = width / 2;
const cy = (height / 2) + 1;
const radius = (Math.min(width, height) - 12) / 2;
const lineWidth = 3;
ctx.beginPath();
ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep);
ctx.lineWidth = lineWidth;
ctx.lineCap = "round";
ctx.strokeStyle = DynamicColors.layer(DynamicColors.palette.m3surfaceContainerHigh, 2);
ctx.stroke();
if (root.animatedPercentage > 0) {
ctx.beginPath();
ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep * root.animatedPercentage);
ctx.lineWidth = lineWidth;
ctx.lineCap = "round";
ctx.strokeStyle = root.accentColor;
ctx.stroke();
}
}
Connections {
function onAnimatedPercentageChanged() {
gaugeCanvas.requestPaint();
}
target: root
}
Connections {
function onPaletteChanged() {
gaugeCanvas.requestPaint();
}
target: DynamicColors
}
}
MaterialIcon {
id: icon
anchors.centerIn: parent
color: DynamicColors.palette.m3onSurface
font.pointSize: 12
text: root.icon
}
CustomRect {
anchors.left: icon.right
color: DynamicColors.layer(DynamicColors.palette.m3surfaceContainerHigh, 2)
implicitHeight: parent.height
implicitWidth: 5
radius: Appearance.rounding.full
CustomRect {
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
color: root.mainColor
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
//@ pragma UseQApplication
//@ pragma Env QSG_RENDER_LOOP=threaded
//@ pragma Env QSG_USE_SIMPLE_ANIMATION_DRIVER=1
//@ pragma Env QSG_USE_SIMPLE_ANIMATION_DRIVER=0
//@ pragma Env QS_NO_RELOAD_POPUP=1
import Quickshell
import qs.Modules