perf: merge cpuCoreUsage/cpuCoreFreq/cpuCoreHistory into single cpuCores array

This commit is contained in:
Damocles 2026-04-15 18:58:24 +02:00
parent 8fdd9692e6
commit c8d71bd871
3 changed files with 25 additions and 34 deletions

View file

@ -22,9 +22,7 @@ M.BarSection {
}
}
readonly property var _coreUsage: M.SystemStats.cpuCoreUsage
readonly property var _coreFreq: M.SystemStats.cpuCoreFreq
readonly property var _coreHistory: M.SystemStats.cpuCoreHistory
readonly property var _cores: M.SystemStats.cpuCores
readonly property var _coreMaxFreq: M.SystemStats.cpuCoreMaxFreq
readonly property var _coreTypes: M.SystemStats.cpuCoreTypes
@ -114,14 +112,14 @@ M.BarSection {
// Per-core rows
Repeater {
model: root._coreUsage.length
model: root._cores.length
delegate: Item {
required property int index
width: hoverPanel.contentWidth
readonly property int _u: root._coreUsage[index] ?? 0
readonly property real _f: root._coreFreq[index] ?? 0
readonly property int _u: root._cores[index]?.usage ?? 0
readonly property real _f: root._cores[index]?.freq_ghz ?? 0
readonly property color _barColor: root._loadColor(_u)
readonly property bool _throttled: {
const maxF = root._coreMaxFreq[index] ?? 0;
@ -204,7 +202,7 @@ M.BarSection {
width: 32
height: 10
property var _hist: root._coreHistory[parent.parent.index] || []
property var _hist: root._cores[parent.parent.index]?.history ?? []
property color _col: parent.parent._barColor
on_HistChanged: if (root._showPanel)

View file

@ -10,9 +10,7 @@ QtObject {
// CPU
property int cpuUsage: 0
property real cpuFreqGhz: 0
property var cpuCoreUsage: []
property var cpuCoreFreq: []
property var cpuCoreHistory: []
property var cpuCores: [] // [{usage, freq_ghz, history:[]}]
property var cpuCoreMaxFreq: []
property var cpuCoreTypes: []
@ -40,17 +38,17 @@ QtObject {
if (ev.type === "cpu") {
root.cpuUsage = ev.usage;
root.cpuFreqGhz = ev.freq_ghz;
root.cpuCoreUsage = ev.core_usage;
root.cpuCoreFreq = ev.core_freq_ghz;
const histLen = 16;
const oldH = root.cpuCoreHistory;
const newH = [];
for (let i = 0; i < ev.core_usage.length; i++) {
const prev = i < oldH.length ? oldH[i] : [];
const next = prev.concat([ev.core_usage[i]]);
newH.push(next.length > histLen ? next.slice(next.length - histLen) : next);
}
root.cpuCoreHistory = newH;
const prev = root.cpuCores;
root.cpuCores = ev.cores.map((c, i) => {
const oldHist = prev[i]?.history ?? [];
const hist = oldHist.concat([c.usage]);
return {
usage: c.usage,
freq_ghz: c.freq_ghz,
history: hist.length > histLen ? hist.slice(hist.length - histLen) : hist
};
});
} else if (ev.type === "mem") {
root.memPercent = ev.percent;
root.memUsedGb = ev.used_gb;