mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
Monitor: total power counts the cards that report it, as the energy meter does (#4430)
PR #4430 by jun76, applied by hand: its new reportedPower helper duplicates the
base's reportedPowerW (#6012, the energy meter), so that function takes the
PR's key argument and the Monitor's total power and power limit use it. Before,
one card without a power counter (an AMD iGPU on Windows) made the Power tile a
dash on a PC whose discrete card reports 72 W, while the energy meter already
counted the 72 W.
Test: tests/energy-meter.test.mjs (the PR's, with the base's function name, plus
a check that the Monitor uses it): fails on 12121745c, passes; with the monitor and
energy tests 35/35.
This commit is contained in:
1 parent
12121745ce
commit
2ce8d8272c
3 files changed
+31
-3
No files matched your search
@@ -16,8 +16,9 @@ export const energyWh = () => meter.wh;
|
||||
/**
|
||||
* The power the meter adds up (#6012): the sum over the GPUs that report one. A GPU with no power counter (an AMD iGPU
|
||||
* on Windows, a unified-memory GPU) adds nothing instead of making the whole sum unknown; with no reading at all, null.
|
||||
* PR #4430: the Monitor's total power and power limit are summed the same way (the `key` argument), so the tile shows what the meter counts.
|
||||
*/
|
||||
export function reportedPowerW(readings) {
|
||||
const values = (readings ?? []).map(g => g?.powerW).filter(v => typeof v === 'number' && Number.isFinite(v) && v >= 0);
|
||||
export function reportedPowerW(readings, key = 'powerW') {
|
||||
const values = (readings ?? []).map(g => g?.[key]).filter(v => typeof v === 'number' && Number.isFinite(v) && v >= 0);
|
||||
return values.length ? values.reduce((n, v) => n + v, 0) : null;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ function hardwareSnapshot() {
|
||||
vramTotalGb:memory.total,
|
||||
ramUsedGb:systemReading?.ramUsedGb??null,ramTotalGb:systemReading?.ramTotalGb??hw.ramTotalGb,
|
||||
gpuTempC:aggregate(readings,'temperatureC','max'),tempLimitC:hw.tempLimitC,
|
||||
powerW:aggregate(readings,'powerW'),powerLimitW:aggregate(readings,'powerLimitW'),
|
||||
powerW:reportedPowerW(readings),powerLimitW:reportedPowerW(readings,'powerLimitW'),
|
||||
pcieRxMbs:aggregate(readings,'pcieRxMbs'),
|
||||
cpuTempC:demo?54:temperatures.cpuTempC,ssdTempC:demo?41:temperatures.ssdTempC,energyWh:round(energyWh(),3),
|
||||
diskReadGbs:systemReading?.diskReadGbs??null,diskWriteMbs:systemReading?.diskWriteMbs??null,
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { addEnergy, reportedPowerW } from '../server/energy-meter.mjs';
|
||||
|
||||
test('an unmetered iGPU does not prevent energy accumulation from a metered GPU', () => {
|
||||
const readings = [
|
||||
{ id: 'GPU-discrete', powerW: 72, powerLimitW: 575 },
|
||||
{ id: 'GPU-integrated', powerW: null, powerLimitW: null },
|
||||
];
|
||||
assert.equal(reportedPowerW(readings), 72);
|
||||
assert.equal(reportedPowerW(readings, 'powerLimitW'), 575);
|
||||
const start = addEnergy(reportedPowerW(readings), 1_000);
|
||||
assert.equal(addEnergy(reportedPowerW(readings), 6_000) - start, 0.1);
|
||||
});
|
||||
|
||||
test('power remains unavailable when no GPU reports it, and multiple readings are summed', () => {
|
||||
assert.equal(reportedPowerW([]), null);
|
||||
assert.equal(reportedPowerW([{ powerW: null }, { powerW: NaN }]), null);
|
||||
assert.equal(reportedPowerW([{ powerW: 20 }, { powerW: 30 }]), 50);
|
||||
});
|
||||
|
||||
// GUI-1116: the Monitor's total power and limit come from the same sum as the energy meter (a mixed PC no longer shows a dash).
|
||||
test('the Monitor sums the cards that report power, as the meter does', async () => {
|
||||
const { readFileSync } = await import('node:fs');
|
||||
const src = readFileSync(new URL('../server/monitor.mjs', import.meta.url), 'utf8');
|
||||
assert.match(src, /powerW:reportedPowerW\(readings\),powerLimitW:reportedPowerW\(readings,'powerLimitW'\),/);
|
||||
});
|
||||
Reference in new issue
Block a user