Repository navigation
Make the Callgrind profile's summary line match its totals - #579
Open
thomasklemm wants to merge 1 commit into
Open
thomasklemm wants to merge 1 commit into
thomasklemm wants to merge 1 commit into
Conversation
harness/callgrind.rb started instrumentation, zeroed the counters, ran the measured iterations, stopped instrumentation and then dumped. In that order Callgrind writes a wrapped negative summary line into the dump (summary: 18446744073709549767 for fib, totals: 1959670074). callgrind_annotate takes the summary as the program total, so PROGRAM TOTALS is meaningless and every function shows 0.00%, and a script that reads the summary gets a number near 2^64 for every benchmark. Zero before starting and dump before stopping: the summary then equals the totals, with and without --instr-atstart=no. The profile now also counts the dump request itself, about 2K instructions on fib. Zeroing again after stopping keeps the exit dump at zero; its summary still wraps when other threads ran during the measured iterations, because Callgrind's zero request resets only the calling thread. The benchmark name is computed before instrumentation starts, so its regexp match stays out of the profile now that the dump comes first.
thomasklemm
added a commit
to thomasklemm/lowrail
that referenced
this pull request
Nov 14, 2026
Contributor
|
We probably want to use zero_stats instead of start/stop; so leave it on but zero immediately before |
Contributor
|
I am in the middle of another PR that measures callgrind instruction counts per iteration instead of time |
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.
harness/callgrind.rbstarts instrumentation, zeroes the counters, runs the measured iterations, stops instrumentation and then dumps. In that order Callgrind writes a wrapped-around negativesummary:line into the dump.fib,--warmup=1 --bench=1, Ruby 4.0.9, Valgrind 3.24.0:summary:totals:callgrind_annotatetakes the summary as the program total, so on main it prints18,446,744,073,709,549,767 (100.0%) PROGRAM TOTALSand every function at 0.00%. A script that readssummary:, aszjit_callgrind.rbin ruby/ruby#19851 does, gets a number near 2^64 for every benchmark.This zeroes before starting and dumps before stopping. The summary then equals the totals, with and without
--instr-atstart=no. The profile now also counts the dump request itself: +1,715 instructions (interpreter) and +1,861 (YJIT) against main's totals on fib. Zeroing again after stopping keeps the dump at exit at 0, as on main, unless other threads ran during the measured iterations: Callgrind's zero request resets only the calling thread. The benchmark name is computed before instrumentation starts, so its regexp match stays out of the profile now that the dump comes first.