Repository navigation
v5.21.0 - #446
Merged
Merged
v5.21.0#446
Conversation
…serializer (#430) * Extract a format-neutral profile normalizer from the pprof serializer Move everything in profile-serializer.ts that is about profile semantics rather than pprof encoding into a new profile-normalizer.ts. That covers the tree walk, source mapping, synthetic runtime frames, per-context sample expansion, CPU time attribution, label generation and sample values. The normalizer streams resolved frames, stacks and samples to a ProfileVisitor, and reports the visit result to its end() method. The pprof serializer is now one such visitor and its output is byte-identical. Samples refer to a deduplicated stack by ID, which mirrors the OTel profiles stack_table and libdatadog's stacktrace interning. Stacks are interned by prefix, through a small map of child stacks per stack, so equal stacks get equal IDs without comparing arrays. A stack is only delivered when its first sample is emitted, so visitors never receive stacks that no sample uses. Frames are looked up by their raw position first, with a short key. The source mapper, and the longer key that includes the resolved file, are needed only for a position not seen before, so a repeated position no longer goes through the source mapper again, which the serializer on main did for every node. On profiles from a TypeScript-compiler workload (about 43,000 time and 12,000 to 20,000 heap nodes), pprof serialization is within about 3-7% of main. Expose the new layer publicly: normalizeTimeProfile/normalizeHeapProfile, visitTimeProfile/visitHeapProfile, time.stopNormalized() and heap.normalizedProfile(). This lets other encoders, such as an OTel profiles exporter, reuse the same profile semantics. * Add per-sample timing to time profile normalization Samples emitted for a labelled context now carry the context's timestamp as NormalizedSample.timestamp, in nanoseconds since epoch. Aggregated samples and synthetic contexts (timestamp 0) have none. Until now the only way to see a timestamp was through generateLabels, which dd-trace uses to add an end_timestamp_ns label. OTel profiles carry timestamps in Sample.timestamps_unix_nano instead, and labels there should have bounded cardinality. By default, the hits and CPU time of contexts without labels are folded into one sample per node, without a timestamp, so a profile can mix timestamped and aggregated samples. OTel profiles recommend that all samples in a profile have the same shape. With the new samplePerContext option, every context becomes its own timestamped sample. Hits without any context are still aggregated, so the totals match the default mode. time.stopNormalized() now takes an options object (generateLabels, samplePerContext). The option types are exported. * Report exact collection times in profile metadata The collection time in nanoseconds since epoch is around 1.7e18, beyond Number.MAX_SAFE_INTEGER, so Date.now() * 1000 * 1000 rounded it to a double. ProfileMetadata.timeNanos is now a bigint computed exactly, and so is the heap normalizer's startTimeNanos option that feeds it. The pprof serializer still gives Profile.timeNanos a number equal to Date.now() * 1000 * 1000, so pprof output and the Profile objects returned to callers are unchanged. serializeHeapProfile() accepts either a number or a bigint start time. Context timestamps are V8 timer values converted to microseconds since the UNIX epoch with an offset the native profiler computes at stop. The profile's startTime and endTime remained raw V8 timer values, so the collection period couldn't be placed on the epoch timeline that sample timestamps use, and timeNanos, the time of normalization, lies after every sample. A format that bounds sample timestamps by the profile's time range (OTel: [time_unix_nano, time_unix_nano + duration_nano)) therefore got timestamps before the range. The native profiler now computes the offset once per stop, uses it for the sample timestamps, and returns it as the profile's epochOffset. The normalizer reports the start of the collection period as the new ProfileMetadata.startTimeNanos: exactly with the offset, or estimated as the collection time minus the duration without one. timeNanos keeps its meaning, so pprof output is unchanged.
* Add a pprof profile builder * Add an OpenTelemetry profiles serializer * Add CapturedProfile, time.stopAndCapture() and heap.capture() * Remove the materialized normalized profile, and narrow the normalizer's exports
szegedi
requested review from
IlyasShabi,
nsavoire and
r1viollet
as code owners
November 24, 2026 16:36
Overall package sizeSelf size: 3.01 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | pprof-format | 2.4.1 | 924.37 kB | 924.37 kB | | source-map | 0.8.0 | 185.66 kB | 185.66 kB | | node-gyp-build | 4.8.4 | 13.86 kB | 13.86 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 1 Pipeline job failed
Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: f20d4e5 | Docs | View more details | Give us feedback! |
IlyasShabi
approved these changes
Nov 25, 2026
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.
New features
Improvements