Skip to content

v5.21.0 - #446

Merged
szegedi merged 3 commits into
v5.xfrom
v5.21.0-proposal
Nov 25, 2026
Merged

szegedi merged 3 commits into
v5.xfrom
v5.21.0-proposal

Conversation

@szegedi

@szegedi szegedi commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

szegedi and others added 3 commits November 24, 2026 17:35
…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
@github-actions

Copy link
Copy Markdown

Overall package size

Self size: 3.01 MB
Deduped: 4.13 MB
No deduping: 4.13 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

@datadog-official

datadog-official Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Pipelines

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 1 Pipeline job failed

DataDog/apm-reliability/pprof-nodejs | benchmarks-pr-comment

View more details · View in GitLab

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: f20d4e5 | Docs | View more details | Give us feedback!

@szegedi
szegedi merged commit 30ff2b8 into v5.x Nov 25, 2026
67 of 69 checks passed
@szegedi
szegedi deleted the v5.21.0-proposal branch November 25, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants