fix(powermetrics): time out the powermetrics subprocess - #1397
Open
davidberenstein1957 wants to merge 1 commit into
Open
fix(powermetrics): time out the powermetrics subprocess#1397davidberenstein1957 wants to merge 1 commit into
davidberenstein1957 wants to merge 1 commit into
Conversation
subprocess.call had no timeout, so a hung powermetrics blocked the measurement thread forever. Allow twice the expected sampling duration plus a startup margin.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1397 +/- ##
=======================================
Coverage 91.43% 91.44%
=======================================
Files 49 49
Lines 5057 5062 +5
=======================================
+ Hits 4624 4629 +5
Misses 433 433 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Split out of #1333, which also rejects powermetrics on non-Apple-Silicon Macs. This is just the subprocess timeout, separated so it can land independently.
ApplePowermetrics._log_values()shells out withsubprocess.call(cmd, universal_newlines=True)and no timeout. The command issudo powermetrics ..., so if sudo has no cached credential and no tty to prompt on, or if powermetrics itself wedges, the call blocks forever. It is invoked fromget_details()on every measurement, which means the tracker's measurement path hangs with no output and no way out short of killing the process.This passes a timeout and, on
subprocess.TimeoutExpired, logs a warning and returnsNoneso that measure is skipped rather than blocking. The existing non-zero-returncode path is unchanged.The timeout value is a heuristic, not a measured bound:
_n_pointssamples at_intervalmilliseconds each is the nominal runtime of the command, son_points * interval / 1000is that runtime in seconds. It is doubled to absorb sampler overhead and scheduling jitter, and 5 seconds is added as a floor so that short configurations still get a usable margin. With the defaults (n_points=10,interval=100) that is 1 second of expected work and a 7 second limit.Nothing measured picks the 2x and the +5; they are chosen to be comfortably loose so a healthy run never trips them, and the timeout only exists to bound a hang. If a reviewer has real numbers for how long powermetrics overruns its nominal duration under load, that is the input that should replace this formula.
tests/test_powermetrics.pygains a case asserting_log_values()returnsNoneand warns once whensubprocess.callraisesTimeoutExpired.uv run pytest tests/test_powermetrics.pypasses (17 tests).