perf: gate cpuCores rebuild behind coreConsumers counter; 30s grace timer + history clear in SystemStats

This commit is contained in:
Damocles 2026-04-15 19:56:24 +02:00
parent f5e076c7ac
commit 9fa2a72a0b
2 changed files with 38 additions and 12 deletions

View file

@ -32,6 +32,18 @@ M.BarSection {
readonly property bool _anyHover: root._hovered || hoverPanel.panelHovered readonly property bool _anyHover: root._hovered || hoverPanel.panelHovered
readonly property bool _showPanel: _anyHover || _pinned readonly property bool _showPanel: _anyHover || _pinned
property bool _coreConsumerActive: false
on_ShowPanelChanged: {
if (_showPanel && !_coreConsumerActive) {
_coreConsumerActive = true;
M.SystemStats.coreConsumers++;
} else if (!_showPanel && _coreConsumerActive) {
_coreConsumerActive = false;
M.SystemStats.coreConsumers--;
}
}
property M.ProcessList _procs: M.ProcessList { property M.ProcessList _procs: M.ProcessList {
sortBy: "cpu" sortBy: "cpu"
active: root._showPanel active: root._showPanel

View file

@ -10,7 +10,19 @@ QtObject {
// CPU // CPU
property int cpuUsage: 0 property int cpuUsage: 0
property real cpuFreqGhz: 0 property real cpuFreqGhz: 0
property var cpuCores: [] // [{usage, freq_ghz, history:[]}] property var cpuCores: [] // [{usage, freq_ghz, history:[]}] only rebuilt while coreConsumers > 0
property int coreConsumers: 0
onCoreConsumersChanged: {
if (coreConsumers > 0)
_coreGraceTimer.stop();
else
_coreGraceTimer.start();
}
property var _coreGraceTimer: Timer {
interval: 30000
onTriggered: root.cpuCores = []
}
property var cpuCoreMaxFreq: [] property var cpuCoreMaxFreq: []
property var cpuCoreTypes: [] property var cpuCoreTypes: []
@ -44,17 +56,19 @@ QtObject {
if (ev.type === "cpu") { if (ev.type === "cpu") {
root.cpuUsage = ev.usage; root.cpuUsage = ev.usage;
root.cpuFreqGhz = ev.freq_ghz; root.cpuFreqGhz = ev.freq_ghz;
const histLen = 16; if (root.coreConsumers > 0) {
const prev = root.cpuCores; const histLen = 16;
root.cpuCores = ev.cores.map((c, i) => { const prev = root.cpuCores;
const oldHist = prev[i]?.history ?? []; root.cpuCores = ev.cores.map((c, i) => {
const hist = oldHist.concat([c.usage]); const oldHist = prev[i]?.history ?? [];
return { const hist = oldHist.concat([c.usage]);
usage: c.usage, return {
freq_ghz: c.freq_ghz, usage: c.usage,
history: hist.length > histLen ? hist.slice(hist.length - histLen) : hist freq_ghz: c.freq_ghz,
}; history: hist.length > histLen ? hist.slice(hist.length - histLen) : hist
}); };
});
}
} else if (ev.type === "temp") { } else if (ev.type === "temp") {
root.tempCelsius = ev.celsius; root.tempCelsius = ev.celsius;
} else if (ev.type === "mem") { } else if (ev.type === "mem") {