Add a timestamp for the samples and weight the report by the sample duration - #284
Merged
Merged
Conversation
mattip
force-pushed
the
lost-samples
branch
from
September 22, 2026 03:49
88e8d4b to
5af0321
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.
Fixes #232 Fixes #233
vmprof samples via a signal handler driven by one process-wide
setitimer. Apending signal is a single bit, not a queue, so every timer expiry that lands
while the process is off the cpu or the previous signal is still pending is
silently dropped. Stack records carry no timestamp and their
countis always1, so nothing can tell that samples went missing, and every consumer assumes
samples * interval == time.This PR adds such a timestamp and weights each sample by the time it actually stands for.
Writer: every stack sample ends with a 64-bit nanosecond timestamp, after
the existing fields, and the header version becomes
VERSION_SAMPLE_TIME(7).The clock matches the timer: process cpu time for
ITIMER_PROF, the monotonicwall clock for
ITIMER_REALand for the Windows sampler thread. Using the wallclock in cpu-time mode would charge idle time to whichever frame ran next.
The frame walk reserves room for the trailer, which also closes a one-slot overrun
when memory profiling was on.
Reader: a sample is worth the gap to the previous sample divided by the
period (at least 1) capped at
max_sample_gap(default 1 s) so a process stoppedin a debugger does not attribute minutes to one frame. The previous sample is
tracked per thread in real-time mode, where every registered thread gets its own
signal, and process-wide in cpu-time mode, where there is one timer. Counts become
sums of weights and may be floats.
Statsgainsn_samples,expected_samples,lost_timeandget_lost_fraction(). Older files are read as before with every weight set to 1.This echoes the approach used in Linux perf, Austin, Scalene, Datadog's python profiler, and pyinstrument. All these statistical profilers take the approach of measuring sample duration, and not just a count.