Files
AetherForge/agent/stats/cpu_common.go
AetherForge f404a76caa
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Fix exotic CPU stub idle-mining guard and document Linux headless screenshots.
Return sane fallback CPU percent after first sample on unknown Unix platforms; add xvfb/scrot docs and stub tests; clear PROBLEMS.md open bugs.
2026-06-07 06:27:19 -07:00

32 lines
784 B
Go

package stats
// StubFallbackCPUPercent is returned after the first sample on platforms without
// OS CPU counters (cpu_stub.go). Kept below the default idle threshold (20%).
const StubFallbackCPUPercent = 5.0
// stubSystemCPUPercent implements idle-mining-safe defaults when real counters
// are unavailable: first sample returns 0 (no delta yet), then a low busy %.
func (r *Reporter) stubSystemCPUPercent() float64 {
r.mu.Lock()
defer r.mu.Unlock()
if !r.hasSample {
r.hasSample = true
return 0
}
return StubFallbackCPUPercent
}
func cpuBusyPercentFromDeltas(idleDelta, totalDelta float64) float64 {
if totalDelta <= 0 {
return 0
}
busyPct := (1.0 - idleDelta/totalDelta) * 100
if busyPct < 0 {
return 0
}
if busyPct > 100 {
return 100
}
return busyPct
}