fix(powermetrics): report 0 W when powermetrics returns no samples - #1345
Open
davidberenstein1957 wants to merge 2 commits into
Open
fix(powermetrics): report 0 W when powermetrics returns no samples#1345davidberenstein1957 wants to merge 2 commits into
davidberenstein1957 wants to merge 2 commits into
Conversation
np.mean([]) returns NaN without raising, so an empty powermetrics log (missing sudoers rule, or a sampler that emits no GPU Power lines) fed NaN into every tracker accumulator, making energy, emissions and emissions_rate NaN for the rest of the run. Closes #1306 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1345 +/- ##
==========================================
+ Coverage 91.39% 91.44% +0.04%
==========================================
Files 49 49
Lines 5056 5061 +5
==========================================
+ Hits 4621 4628 +7
+ Misses 435 433 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
get_details() runs on every measurement cycle, so a machine whose cpu_power sampler never emits "GPU Power:" lines logged a warning at every interval for the whole run. Warn once per chip part instead, matching the warn-once guards used in the RAPL and GPU fallbacks. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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