Summary
The macOS CPU monitoring implementation incorrectly applies delta-based percentage calculation to instantaneous CPU percentages from top, resulting in incorrect CPU usage readings.
Bug Location
src/monitor/collectors/cpu.rs:166-221 (macOS parse_proc_stat implementation)
Root Cause
On macOS, the code:
- Parses instantaneous CPU percentages from
top -l 1 (e.g., "45.67% user, 3.21% sys, 51.12% idle")
- Truncates float to
u64, losing decimal precision (45.67 -> 45)
- Multiplies by 100 to "scale like Linux jiffies" (45 -> 4500)
- Stores these as
CpuStats which are meant for cumulative tick counts
calculate_percentage() then computes deltas between two readings
The problem: Linux's /proc/stat gives cumulative CPU tick counts, so delta calculation works. But macOS top gives instantaneous percentages already - computing deltas between two instantaneous percentage readings is mathematically incorrect.
Example of Bug
First reading: user=45%, idle=50% -> stored as CpuStats{user: 4500, idle: 5000}
Second reading: user=30%, idle=65% -> stored as CpuStats{user: 3000, idle: 6500}
Delta calculation:
total_delta = (3000+6500) - (4500+5000) = 0 (or negative!)
Result: 0% or NaN instead of ~30%
Expected Behavior
On macOS, the CPU percentage should directly use the instantaneous percentages from top without delta calculation.
Falsification Test (ttop-demo.md Claim 41)
Per specification Section 10.3, Claim 41: "CPU % within ±2% of top"
This claim is currently falsified - the bug causes readings to deviate significantly more than ±2%.
Fix Approach
For macOS:
- Store raw percentage directly from
top as the CPU usage value
- Skip delta calculation since we already have instantaneous percentages
- Maintain precision by using
f64 throughout
References
- ttop-demo.md Section 10.3, Claim 41
- tests/playbooks/macos_collectors.yaml (accuracy_tests)
- Popperian falsification checklist item 41
Labels
- bug
- macos
- cpu-monitoring
- falsification-failed
Summary
The macOS CPU monitoring implementation incorrectly applies delta-based percentage calculation to instantaneous CPU percentages from
top, resulting in incorrect CPU usage readings.Bug Location
src/monitor/collectors/cpu.rs:166-221(macOSparse_proc_statimplementation)Root Cause
On macOS, the code:
top -l 1(e.g., "45.67% user, 3.21% sys, 51.12% idle")u64, losing decimal precision (45.67 -> 45)CpuStatswhich are meant for cumulative tick countscalculate_percentage()then computes deltas between two readingsThe problem: Linux's
/proc/statgives cumulative CPU tick counts, so delta calculation works. But macOStopgives instantaneous percentages already - computing deltas between two instantaneous percentage readings is mathematically incorrect.Example of Bug
Expected Behavior
On macOS, the CPU percentage should directly use the instantaneous percentages from
topwithout delta calculation.Falsification Test (ttop-demo.md Claim 41)
Per specification Section 10.3, Claim 41: "CPU % within ±2% of top"
This claim is currently falsified - the bug causes readings to deviate significantly more than ±2%.
Fix Approach
For macOS:
topas the CPU usage valuef64throughoutReferences
Labels