fix(powermetrics): reject unsupported Macs and report 0 W when no samples - #1345
Open
davidberenstein1957 wants to merge 1 commit into
Open
fix(powermetrics): reject unsupported Macs and report 0 W when no samples#1345davidberenstein1957 wants to merge 1 commit into
davidberenstein1957 wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1345 +/- ##
==========================================
+ Coverage 91.43% 91.45% +0.01%
==========================================
Files 49 49
Lines 5057 5055 -2
==========================================
- Hits 4624 4623 -1
+ Misses 433 432 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
davidberenstein1957
marked this pull request as ready for review
August 12, 2026 17:37
This was referenced Aug 12, 2026
davidberenstein1957
force-pushed
the
fix/powermetrics-nan-totals
branch
2 times, most recently
from
August 19, 2026 14:27
5247f57 to
f67379e
Compare
…ples Two failure modes in the powermetrics backend produced silently wrong totals. `_setup_cli` returned without setting `_cli` and without raising on an Intel Mac, so `ApplePowermetrics()` succeeded there and `ResourceTracker` could register an `AppleSiliconChip` on hardware that has none. It also crashed with `AttributeError` when `detect_cpu_model()` returned None. Both paths now raise `SystemError`, the argv uses the validated `self._cli`, and a stray empty argument is dropped. Averaging an empty sample list returned NaN (numpy) or raised (`statistics.fmean`), and the NaN poisoned every downstream total. Report 0 W instead. This also drops the numpy dependency from this module. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
davidberenstein1957
force-pushed
the
fix/powermetrics-nan-totals
branch
from
August 20, 2026 06:14
f67379e to
c583b1d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ApplePowermetrics.get_details()now guards against an empty match list before averaging: ifpowermetricsproduced noCPU Power:/GPU Power:lines it logs a warning and reports0.0W instead ofnan. The CPU and GPU branches were identical, so they are now one loop.Why
np.mean([])returnsnanand only emits aRuntimeWarning, so the surroundingexcept Exceptionnever fired and nothing was logged. The NaN flowed throughAppleSiliconChip._get_powerinto the tracker accumulators, and since NaN is absorbing under addition, one bad sample madeenergy_consumed,emissionsandemissions_rateNaN for the remainder of the run — written toemissions.csvand POSTed to the API as bareNaN.This is reachable in the field whenever the powermetrics sudoers rule is missing (empty log), and on machines where the
cpu_powersampler emits noGPU Power:lines, where it happened on every single call.Reporting 0 W understates rather than invalidates, and the warning makes the condition visible.
Verification
Two new cases in
tests/test_powermetrics.py(test_get_details_without_samples,test_get_details_without_gpu_samples) both fail on master and pass with this change.uv run pytest tests/test_powermetrics.py -q-> 18 passed. The existingtest_get_detailsis unchanged, confirming the non-empty path still behaves identically.Note:
uv run task lintreports pre-existing violations across the repo anduv run task formatreformats ~120 unrelated files, so neither was applied wholesale;black --checkis clean on the two touched files.Closes #1306
🤖 Generated with Claude Code