Repository navigation
Conversation
Integrations exporting OpenTelemetry spans and logs timestamp them with the monotonic clock of the benchmark markers, shifted to read as wall clock times. Each computing its own offset would shift timestamps differently within a process, so subtracting one offset would no longer give back the exact monotonic timestamp. Expose the offset from `instrument_hooks_current_timestamp` to the wall clock, computed on the first call and cached for the process, or 0 where the monotonic clock is unavailable. Also define the OpenTelemetry resource attribute carrying it, `codspeed.clock.monotonic_offset_ns`. Refs COD-3862 Co-Authored-By: Claude Opus 5.5 <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.
Add
instrument_hooks_monotonic_offset(), the offset in nanoseconds to add toinstrument_hooks_current_timestamp()to read it as a wall clock time since the Unix epoch. It returns 0 where the monotonic clock is unavailable (Windows).Integrations exporting OpenTelemetry spans and logs timestamp them with the same monotonic clock as the benchmark markers, shifted by this offset so they still read as wall clock times in standard tools. Subtracting the offset gives back the exact marker clock. For that to hold, every exporter in a process has to use the same offset, so it is computed on the first call and cached for the process instead of each integration computing its own. Two separately computed offsets differed by ~400 ns in practice.
The header also defines
INSTRUMENT_HOOKS_MONOTONIC_OFFSET_ATTRIBUTE("codspeed.clock.monotonic_offset_ns"), the OpenTelemetry resource attribute carrying the offset, so the name lives in one place.The offset pairs one realtime clock read with the midpoint of two monotonic reads. Wall clock adjustments after the first call make shifted timestamps drift from the wall clock (by milliseconds at most over a benchmark run), but the monotonic value recovered by subtracting stays exact.
Notes for review:
dist/core.cis regenerated with Zig 0.14.0. Neither 0.14.0 nor 0.14.1 reproduces the current file byte-for-byte here (symbol numbering is shifted), and 0.14.0 gives the smaller diff; it is mostly renumbered transpiler symbols.Refs COD-3862: the issue stays open for the integration side using this offset.