perf_hooks: add node:perf_hooks/pprof time profiler #67779
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #67779"
general
weight: 0.35
legendecas
👋 This PR starts the process of natively supporting profiling in the runtime. This is a port of the
@datadog/pprofmodule. This specific PR limits the implementation to profiling the CPU wall time. Heap and context/label sampling, and source map support are left for subsequent PRs.@mcollina and I discussed this at the OpenJSF conference in 2025. We agreed that this sort of thing should be provided by the runtime. In support of that assertion, I instructed Claude to review the dependents of the
@datadog/pprofmodule and generate a report of how it is used across the ecosystem. This is what it came up with:<details>
<summary>Ecosystem Report</summary>
How
@datadog/pprofis used across the JavaScript observability ecosystemData collected 2026-11-25. Sources:
@datadog/pprof;api.npmjs.org, for the last week;latestmanifest of each package;@datadog/pprofAPIs it calls.Scale
@datadog/pprofis downloaded about 17.6 million times a week.dd-trace, because it declares@datadog/pprofas anoptionalDependency. At about 15.2 million downloads a week,dd-traceaccounts for most of the module's installs.Who uses it
| Use | Package | Weekly downloads | APIs used |
| --- | --- | ---: | --- |
| Vendor APM agent |
dd-trace(Datadog) | 15,235,791 | Time and heap profilers, sampling contexts, source maps, logger || Continuous profiling agent |
@pyroscope/nodejs(Grafana) | 1,071,311 | Time profiler with CPU time and contexts, heap profiler, source maps || Continuous profiling agent |
@polarsignals/pprof(Polar Signals) | 180,021 | Heap profiler, out-of-memory monitoring, source maps || Developer tooling |
@platformatic/flame(Platformatic) | 27,937 | Source maps, encoding; CPU and heap flame graphs || OpenTelemetry profiling SDK |
@coralogix/opentelemetry-profiling(Coralogix) | 18,702 | Time profiler with contexts and line numbers, heap profiler, source maps || Application runtime |
@platformatic/wattpm-pprof-capture,@platformatic/watt-extra(Platformatic) | 9,410 + 1,201 | Time profiler with line numbers, source maps || Embedded in a database or application platform |
harperdb,@harperfast/harper-pro(Harper) | 7,394 + 4,445 | Time profiler with line numbers, source maps, encoding || In-house framework |
@rsdk/profiling.common(R-Vision) | 1,277 | Time profiler with CPU time and contexts, heap profiler, source maps || HTTP profiling endpoints |
flamegraph-middleware,express-pprof-middleware(Tesla) | 1,267 + 33 |time.profile(), heap profiler, encoding || OpenTelemetry resource bridge |
@beacon-observability/profiler-nodejs,@cloudcare/profiler-nodejs| 387 + 9 | Time profiler with CPU time and contexts, heap profiler || CLI wrapper |
pprof-it| 178 | Time profiler with line numbers, heap profiler, source maps |The remaining dependents each get fewer than 100 downloads a week:
dd-trace(dd-trace-andreas,dd-trace-sbs-dl,@e-one/dd-trace,trace-ts);@rudderstack/pyroscope-nodejs,rudderstack-pyroscope-nodejs,@popfendicollars/pyroscope-nodejs);@beincom/node-profile,@cornie-js/backend-monitoring,@yoniplayground/o11y,@swapnil454/tracepilot,perf-skill);@chatlayer/tracer, which still pins the obsolete^0.1.3.Observations
- Sentry ships its own native addon,
@sentry/node-cpu-profiler.- Elastic's agents have no Node.js profiler.
- OpenTelemetry has no Node.js profiler of its own. Its eBPF profiler's design doc for reading Node.js thread context cites
DataDog/pprof-nodejsas prior art.-
@pyroscope/nodejspins5.14.4;-
@platformatic/flameandharperdbpin5.15.1;- Pyroscope's forks pin
5.4.1.So the ecosystem gets fixes and new Node.js support unevenly.
time.start()/time.stop()ortime.profile(), then encodes the result as pprof. That's the partnode:perf_hooks/pprofprovides.- source maps (
SourceMapper): most dependents;- the heap profiler: Pyroscope, Polar Signals, Coralogix, R-Vision, the middleware packages and
pprof-it;- sampling contexts (
withContexts,useCPED,time.setContext): Datadog, Pyroscope, Coralogix, R-Vision and Beacon.These features decide how many consumers could move to the core module without also keeping the addon.
A few caveats:
</details>
Additionally, Sentry has their own native module to accomplish the same goal:
+ https://github.com/getsentry/sentry-javascript-profiling-node-binaries
I have reviewed all of the JavaScript code in this PR, mainly coercing useful jsdoc into the code. Everything seems reasonable to me. But I am unable to provide insight into the C++ code, as my knowledge there is basically zero. The C++ code _was_ heavily rewritten, though. The original upstream code relied on Nan and node-gyp. By directly integrating this functionality into core, we are able to skip those requirements. I asked Claude for a description of what it changed, and it reported:
<details>
<summary>C++ Port Details</summary>
It was modified heavily. The C++ is a port of the upstream design and algorithms, rewritten against Node.js internals; very little was copied as is. I compared it with upstream at the commit it was ported from, 3905f38, just now.
Size and overlap
- sigaction setup and its flags (SA_RESTART | SA_SIGINFO | SA_ONSTACK);
- std::atomic_signal_fence calls;
- Mach/Windows thread-time API calls;
- a std::lock_guard and a set of profilers;
- method names kept for compatibility, such as v8ProfilerStuckEventLoopDetected.
What changed
- sigprof_handler.{h,cc}: the signal handler;
- cpu_clock.{h,cc}: the thread CPU clocks;
- time_profile.{h,cc}: sample attribution, with no dependency on V8, so cctest can test it;
- node_pprof.{h,cc}: the binding.
- GetContextsByNode() became AttributeSamples(), a function that only takes and returns data.
- The translation of V8 profiles now returns flat tables of typed arrays, instead of a tree of JavaScript objects.
- sampling contexts, CPED and AsyncContextFrame reads (upstream wall.cc mentions contexts 133 times);
- async IDs, GC callbacks, metrics, and the per-Node-major #if branches.
- macOS: upstream calls mach_thread_self(), which adds a reference to the thread port on each call and never releases it. The port uses pthread_mach_thread_np(pthread_self()), which doesn't (src/pprof/cpu_clock.cc:143-144).
- Signal-handler chaining handles more cases: SA_SIGINFO vs sa_handler, SIG_DFL/SIG_IGN, and refusing to chain to itself. It also makes no V8 calls inside the handler.
- MonotonicNowMicros() reimplements V8's TimeTicks::Now(). V8's base headers aren't available to node_lib, and upstream redeclares V8's symbols, which isn't acceptable in core.
Why the upstream headers stay
Because the logic is derived from upstream, the files keep the Apache-2.0 copyright headers, with a "Modified for inclusion in Node.js core" notice and a pinned link to what each was ported from. tools/license-builder.sh adds the license to LICENSE. That attribution is required whatever the amount of verbatim text.
The overlap figure is a rough line-level measure, not a formal similarity analysis, and I didn't compare the files line by line.
</details>
-----
<details>
<summary>Claude Code Description</summary>
Adds an experimental
node:perf_hooks/pprofmodule. It collects wall time profiles of the current thread and encodes them in the pprof format, so they can be used with thepprofcommand-line tool and continuous profiling services without a native addon. Loading the module emits anExperimentalWarning; there is no flag.Where it comes from
@datadog/pprof(Apache-2.0).- The native profiler is in
src/node_pprof.ccandsrc/pprof/, built on Node.js internals instead of nan and node-gyp.- The JavaScript is in
lib/internal/perf/pprof/.pprof-format(MIT). Only the encoding half is included.LICENSEthroughtools/license-builder.sh.API
time.start([options]),time.stop([restart])andtime.isStarted().time.profile([options]), which profiles fordurationMillisand can be stopped early with anAbortSignal.time.v8ProfilerStuckEventLoopDetected()andtime.constants.encode(profile)andencodeSync(profile), which return a gzip-compressed pprofBuffer.@datadog/pprofare kept (intervalMicros,durationMillis,lineNumbers,collectCpuTime,workaroundV8Bug) so users can migrate easily.On POSIX systems,
collectCpuTimeattributes the thread's CPU time to samples by intercepting theSIGPROFsignals of V8's sampler. The same interception works around a V8 bug that can leave the CPU profiler stuck when it is restarted. If restarting after that bug fails,stop(true)still returns the profile and leaves the profiler stopped.The profiler owns its own
v8::CpuProfiler, so it can run alongsidev8.startCpuProfile()and the inspector'sProfilerdomain. It refuses to start while a startup snapshot is being built.Not included
Tests
test/parallel/test-perf-hooks-pprof-*.jscover:- the module and its warning, and option validation;
- the profile content, CPU time, line numbers and restarts;
- recovery from a stuck V8 profiler;
- encoding, and the normalizer and serializer, using synthetic profiles;
- workers, including workers terminated while profiling;
- running alongside
v8.startCpuProfile()and the inspector;- exiting without stopping the profiler, and rejection while a snapshot is built.
test/cctest/test_pprof.cccovers sample attribution, the thread CPU clock and signal chaining.test/common/pprof.jsis a minimal pprof decoder, written independently of the encoder, so that tests check the encoded bytes. It also providespprofTestBusyLoop(), a loop bounded by CPU time rather than wall time, so that it gets about as many samples on a loaded machine as on an idle one.Docs
pprof APIsection indoc/api/perf_hooks.md.type-map.jsonentry forpprof.Profile.🤖 Generated with Claude Code
</details>