Repository navigation
fix: convert proc_pidinfo CPU time from mach ticks to ns (v1.6.4) - #49
Merged
Merged
Conversation
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.
Summary
get_native_processes()was returningproc_pidinfo'spti_total_user/pti_total_systemfields as if they were nanoseconds. They are mach absolute-clock ticks, not ns. On Apple Silicon the timebase is 125/3 (1 tick = 41.667 ns), so every process's CPU% read ~2.4% of its real value (1.2 s of burned CPU appeared as 0.03 s). Intel's 1/1 timebase made the raw values coincide with ns, which is why the offset-verified struct never surfaced the unit.actop/native_sys.py: readmach_timebase_infoonce at module load;_mach_ticks_to_ns()converts with integer math;cpu_time_nsnow uses it.tests/test_native_sys.py: newtest_cpu_time_ns_is_nanoseconds_not_mach_ticks— burns ~1.2 s CPU and asserts the native delta ≥ 60% of thegetrusagedelta. Reverting the fix drops it to ~2.4%, so the test is load-bearing. The share-based process-power tests cannot catch this (numerator and denominator shrink together).Impact
cpu_percentvalue (previously understated 41.67x on every Apple Silicon machine).cpu_time_shareand watt attribution are ratio-based and were never affected.Validation
.venv/bin/ruff check --fix ./.venv/bin/ruff format .clean..venv/bin/pytest -q -m "not local"→ 91 passed..venv/bin/pytest -q -m local→ 48 passed (one re-run had a single flaky Textual#loading-splashmount-timing failure under load, not related to this change; passed on re-run).getrusagerecords 1.2 s, nativecpu_time_nsdelta now matches (~99.4–100%); before the fix it read ~0.03 s.Platform_machTicksToNanoseconds.