okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
09cfbffed
main
1/** 2* GPU energy since the host started, in Wh (#3628): the power reading held for the time since the last tick, added up. 3* A long gap (the PC slept, the host was paused) counts for at most 5 s, so a sleep never adds a made-up hour of use. 4*/ 5const meter = { wh :0 , at :0 }; 6 7export function addEnergy ( powerW , at ) { 8const dt = meter . at ?Math . min (( at - meter . at ) / 1000 , 5 ) :0 ; 9meter . at = at ; 10if ( typeof powerW === 'number' && Number . isFinite ( powerW ) && powerW >= 0 && dt > 0 ) meter . wh += powerW * dt / 3600 ; 11return meter . wh ; 12} 13 14export const energyWh = () => meter . wh ; 15 16/** 17* The power the meter adds up (#6012): the sum over the GPUs that report one. A GPU with no power counter (an AMD iGPU 18* on Windows, a unified-memory GPU) adds nothing instead of making the whole sum unknown; with no reading at all, null. 19*/ 20export function reportedPowerW ( readings ) { 21const values = ( readings ?? []). map ( g => g ?. powerW ). filter ( v => typeof v === 'number' && Number . isFinite ( v ) && v >= 0 ); 22return values . length ?values . reduce (( n , v ) => n + v , 0 ) :null ; 23}