@datadog/pprof 6.0.0-pre-fdd7f20 → 6.0.0-pre-90fbe2b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -6
- package/out/src/async-context-frame.d.ts +48 -0
- package/out/src/async-context-frame.js +106 -0
- package/out/src/async-context-frame.js.map +1 -0
- package/out/src/heap-profiler-bindings.d.ts +4 -3
- package/out/src/heap-profiler-bindings.js +8 -4
- package/out/src/heap-profiler-bindings.js.map +1 -1
- package/out/src/heap-profiler.d.ts +48 -21
- package/out/src/heap-profiler.js +103 -31
- package/out/src/heap-profiler.js.map +1 -1
- package/out/src/index.d.ts +10 -0
- package/out/src/index.js +14 -1
- package/out/src/index.js.map +1 -1
- package/out/src/otel-thread-ctx.d.ts +109 -0
- package/out/src/otel-thread-ctx.js +166 -0
- package/out/src/otel-thread-ctx.js.map +1 -0
- package/out/src/profile-serializer.d.ts +26 -3
- package/out/src/profile-serializer.js +110 -26
- package/out/src/profile-serializer.js.map +1 -1
- package/out/src/sourcemapper/sourcemapper.d.ts +38 -7
- package/out/src/sourcemapper/sourcemapper.js +265 -75
- package/out/src/sourcemapper/sourcemapper.js.map +1 -1
- package/out/src/time-profiler.d.ts +21 -3
- package/out/src/time-profiler.js +63 -20
- package/out/src/time-profiler.js.map +1 -1
- package/out/src/v8-types.d.ts +12 -0
- package/package.json +44 -23
- package/prebuilds/darwin-arm64/dd_pprof.node.abi108.node +0 -0
- package/prebuilds/darwin-arm64/dd_pprof.node.abi111.node +0 -0
- package/prebuilds/darwin-arm64/dd_pprof.node.abi115.node +0 -0
- package/prebuilds/darwin-arm64/dd_pprof.node.abi120.node +0 -0
- package/prebuilds/darwin-arm64/dd_pprof.node.abi127.node +0 -0
- package/prebuilds/darwin-arm64/dd_pprof.node.abi131.node +0 -0
- package/prebuilds/darwin-arm64/dd_pprof.node.abi137.node +0 -0
- package/prebuilds/darwin-arm64/dd_pprof.node.abi141.node +0 -0
- package/prebuilds/darwin-arm64/dd_pprof.node.abi147.node +0 -0
- package/prebuilds/darwin-x64/dd_pprof.node.abi108.node +0 -0
- package/prebuilds/darwin-x64/dd_pprof.node.abi111.node +0 -0
- package/prebuilds/darwin-x64/dd_pprof.node.abi115.node +0 -0
- package/prebuilds/darwin-x64/dd_pprof.node.abi120.node +0 -0
- package/prebuilds/darwin-x64/dd_pprof.node.abi127.node +0 -0
- package/prebuilds/darwin-x64/dd_pprof.node.abi131.node +0 -0
- package/prebuilds/darwin-x64/dd_pprof.node.abi137.node +0 -0
- package/prebuilds/darwin-x64/dd_pprof.node.abi141.node +0 -0
- package/prebuilds/darwin-x64/dd_pprof.node.abi147.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.musl.node.abi108.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.musl.node.abi111.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.musl.node.abi115.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.musl.node.abi120.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.musl.node.abi127.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.musl.node.abi131.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.musl.node.abi137.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.musl.node.abi141.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.musl.node.abi147.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.node.abi108.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.node.abi111.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.node.abi115.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.node.abi120.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.node.abi127.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.node.abi131.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.node.abi137.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.node.abi141.node +0 -0
- package/prebuilds/linux-arm64/dd_pprof.node.abi147.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.musl.node.abi108.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.musl.node.abi111.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.musl.node.abi115.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.musl.node.abi120.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.musl.node.abi127.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.musl.node.abi131.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.musl.node.abi137.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.musl.node.abi141.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.musl.node.abi147.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.node.abi108.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.node.abi111.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.node.abi115.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.node.abi120.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.node.abi127.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.node.abi131.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.node.abi137.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.node.abi141.node +0 -0
- package/prebuilds/linux-x64/dd_pprof.node.abi147.node +0 -0
- package/prebuilds/win32-x64/dd_pprof.node.abi108.node +0 -0
- package/prebuilds/win32-x64/dd_pprof.node.abi111.node +0 -0
- package/prebuilds/win32-x64/dd_pprof.node.abi115.node +0 -0
- package/prebuilds/win32-x64/dd_pprof.node.abi120.node +0 -0
- package/prebuilds/win32-x64/dd_pprof.node.abi127.node +0 -0
- package/prebuilds/win32-x64/dd_pprof.node.abi131.node +0 -0
- package/prebuilds/win32-x64/dd_pprof.node.abi137.node +0 -0
- package/prebuilds/win32-x64/dd_pprof.node.abi141.node +0 -0
- package/prebuilds/win32-x64/dd_pprof.node.abi147.node +0 -0
- package/prebuilds/darwin-arm64/node-108.node +0 -0
- package/prebuilds/darwin-arm64/node-111.node +0 -0
- package/prebuilds/darwin-arm64/node-115.node +0 -0
- package/prebuilds/darwin-arm64/node-120.node +0 -0
- package/prebuilds/darwin-arm64/node-127.node +0 -0
- package/prebuilds/darwin-arm64/node-131.node +0 -0
- package/prebuilds/darwin-arm64/node-137.node +0 -0
- package/prebuilds/darwin-arm64/node-141.node +0 -0
- package/prebuilds/darwin-x64/node-108.node +0 -0
- package/prebuilds/darwin-x64/node-111.node +0 -0
- package/prebuilds/darwin-x64/node-115.node +0 -0
- package/prebuilds/darwin-x64/node-120.node +0 -0
- package/prebuilds/darwin-x64/node-127.node +0 -0
- package/prebuilds/darwin-x64/node-131.node +0 -0
- package/prebuilds/darwin-x64/node-137.node +0 -0
- package/prebuilds/darwin-x64/node-141.node +0 -0
- package/prebuilds/linuxglibc-arm64/node-108.node +0 -0
- package/prebuilds/linuxglibc-arm64/node-111.node +0 -0
- package/prebuilds/linuxglibc-arm64/node-115.node +0 -0
- package/prebuilds/linuxglibc-arm64/node-120.node +0 -0
- package/prebuilds/linuxglibc-arm64/node-127.node +0 -0
- package/prebuilds/linuxglibc-arm64/node-131.node +0 -0
- package/prebuilds/linuxglibc-arm64/node-137.node +0 -0
- package/prebuilds/linuxglibc-arm64/node-141.node +0 -0
- package/prebuilds/linuxglibc-x64/node-108.node +0 -0
- package/prebuilds/linuxglibc-x64/node-111.node +0 -0
- package/prebuilds/linuxglibc-x64/node-115.node +0 -0
- package/prebuilds/linuxglibc-x64/node-120.node +0 -0
- package/prebuilds/linuxglibc-x64/node-127.node +0 -0
- package/prebuilds/linuxglibc-x64/node-131.node +0 -0
- package/prebuilds/linuxglibc-x64/node-137.node +0 -0
- package/prebuilds/linuxglibc-x64/node-141.node +0 -0
- package/prebuilds/linuxmusl-arm64/node-108.node +0 -0
- package/prebuilds/linuxmusl-arm64/node-111.node +0 -0
- package/prebuilds/linuxmusl-arm64/node-115.node +0 -0
- package/prebuilds/linuxmusl-arm64/node-120.node +0 -0
- package/prebuilds/linuxmusl-arm64/node-127.node +0 -0
- package/prebuilds/linuxmusl-arm64/node-131.node +0 -0
- package/prebuilds/linuxmusl-arm64/node-137.node +0 -0
- package/prebuilds/linuxmusl-arm64/node-141.node +0 -0
- package/prebuilds/linuxmusl-x64/node-108.node +0 -0
- package/prebuilds/linuxmusl-x64/node-111.node +0 -0
- package/prebuilds/linuxmusl-x64/node-115.node +0 -0
- package/prebuilds/linuxmusl-x64/node-120.node +0 -0
- package/prebuilds/linuxmusl-x64/node-127.node +0 -0
- package/prebuilds/linuxmusl-x64/node-131.node +0 -0
- package/prebuilds/linuxmusl-x64/node-137.node +0 -0
- package/prebuilds/linuxmusl-x64/node-141.node +0 -0
- package/prebuilds/win32-x64/node-108.node +0 -0
- package/prebuilds/win32-x64/node-111.node +0 -0
- package/prebuilds/win32-x64/node-115.node +0 -0
- package/prebuilds/win32-x64/node-120.node +0 -0
- package/prebuilds/win32-x64/node-127.node +0 -0
- package/prebuilds/win32-x64/node-131.node +0 -0
- package/prebuilds/win32-x64/node-137.node +0 -0
- package/prebuilds/win32-x64/node-141.node +0 -0
package/README.md
CHANGED
|
@@ -97,14 +97,10 @@ Install [`pprof`][npm-url] with `npm` or add to your `package.json`.
|
|
|
97
97
|
pprof -http=: heap.pb.gz
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
* Collecting a heap profile with
|
|
100
|
+
* Collecting a heap profile with V8 allocation profile format:
|
|
101
101
|
```javascript
|
|
102
|
-
const profile = pprof.heap.v8Profile(
|
|
102
|
+
const profile = await pprof.heap.v8Profile();
|
|
103
103
|
```
|
|
104
|
-
`v8Profile` accepts a callback and returns its result. Allocation nodes
|
|
105
|
-
are only valid during the callback, so copy/transform what you need
|
|
106
|
-
before returning. `heap.convertProfile` performs that conversion during
|
|
107
|
-
the callback, and `heap.profile()` uses it under the hood.
|
|
108
104
|
|
|
109
105
|
[build-image]: https://github.com/Datadog/pprof-nodejs/actions/workflows/build.yml/badge.svg?branch=main
|
|
110
106
|
[build-url]: https://github.com/Datadog/pprof-nodejs/actions/workflows/build.yml
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this process's `AsyncLocalStorage` is backed by AsyncContextFrame,
|
|
3
|
+
* which is what puts the active value in the isolate's
|
|
4
|
+
* ContinuationPreservedEmbedderData slot that this addon reads.
|
|
5
|
+
*
|
|
6
|
+
* Feature-detected rather than inferred from the Node version plus
|
|
7
|
+
* `process.execArgv`, because the two disagree in both directions and each
|
|
8
|
+
* combination is reachable today:
|
|
9
|
+
*
|
|
10
|
+
* - `NODE_OPTIONS=--experimental-async-context-frame` is accepted from Node
|
|
11
|
+
* 22.7.0 through 23 and turns ACF on without appearing in `execArgv`.
|
|
12
|
+
* Inferring "off" there makes callers refuse to run in a process that would
|
|
13
|
+
* have worked.
|
|
14
|
+
* - `NODE_OPTIONS=--no-async-context-frame` is accepted on Node 24 and turns
|
|
15
|
+
* ACF off without appearing in `execArgv`. Inferring "on" there is the worse
|
|
16
|
+
* error: the CPED slot is never written, so a writer that starts anyway keeps
|
|
17
|
+
* looking healthy from JS — `getStore()` still works — while every
|
|
18
|
+
* out-of-process reader sees a record that nothing ever updates.
|
|
19
|
+
* - A worker thread created with an explicit `execArgv` doesn't inherit the
|
|
20
|
+
* main thread's command line either, and tooling sometimes rewrites
|
|
21
|
+
* `process.execArgv` outright.
|
|
22
|
+
*
|
|
23
|
+
* Detected by asking the addon what is in the CPED slot during a `run()`. With
|
|
24
|
+
* ACF, Node installs an AsyncContextFrame — a JS Map keyed by the
|
|
25
|
+
* `AsyncLocalStorage` instance, valued by its store — as the running
|
|
26
|
+
* continuation's CPED; without it, nothing writes the slot. So a probe storage
|
|
27
|
+
* whose own store is visible there is direct evidence, and it is evidence about
|
|
28
|
+
* the exact slot both consumers read: `WallProfiler::SetContext` requires that
|
|
29
|
+
* Map, and the thread-ctx reader looks this very key up by the identity hash
|
|
30
|
+
* published as `als_identity_hash`.
|
|
31
|
+
*
|
|
32
|
+
* Observing whether `run()` delegates to `enterWith()` would be an indirect
|
|
33
|
+
* proxy for the same thing: it holds today, but it depends on `run()`
|
|
34
|
+
* dispatching through the instance property, which is unspecified and which
|
|
35
|
+
* anything patching `AsyncLocalStorage` can break — and the failure would be
|
|
36
|
+
* silent and in the dangerous direction.
|
|
37
|
+
*
|
|
38
|
+
* Memoized: the answer is fixed for the life of the thread.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isAsyncContextFrameActive(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* How to turn AsyncContextFrame on, for the error message of whatever declined
|
|
43
|
+
* to run without it.
|
|
44
|
+
*
|
|
45
|
+
* Advisory text only — never decide availability from this. That is what
|
|
46
|
+
* {@link isAsyncContextFrameActive} is for.
|
|
47
|
+
*/
|
|
48
|
+
export declare function asyncContextFrameHint(): string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 Datadog, Inc
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.isAsyncContextFrameActive = isAsyncContextFrameActive;
|
|
19
|
+
exports.asyncContextFrameHint = asyncContextFrameHint;
|
|
20
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
21
|
+
const path_1 = require("path");
|
|
22
|
+
let addon;
|
|
23
|
+
// Required lazily so importing this module doesn't force the addon to load;
|
|
24
|
+
// memoized by isAsyncContextFrameActive, so this runs at most once per thread.
|
|
25
|
+
function bindings() {
|
|
26
|
+
if (!addon) {
|
|
27
|
+
const findBinding = require('node-gyp-build');
|
|
28
|
+
addon = findBinding((0, path_1.join)(__dirname, '..', '..'));
|
|
29
|
+
}
|
|
30
|
+
return addon;
|
|
31
|
+
}
|
|
32
|
+
let active;
|
|
33
|
+
/**
|
|
34
|
+
* Whether this process's `AsyncLocalStorage` is backed by AsyncContextFrame,
|
|
35
|
+
* which is what puts the active value in the isolate's
|
|
36
|
+
* ContinuationPreservedEmbedderData slot that this addon reads.
|
|
37
|
+
*
|
|
38
|
+
* Feature-detected rather than inferred from the Node version plus
|
|
39
|
+
* `process.execArgv`, because the two disagree in both directions and each
|
|
40
|
+
* combination is reachable today:
|
|
41
|
+
*
|
|
42
|
+
* - `NODE_OPTIONS=--experimental-async-context-frame` is accepted from Node
|
|
43
|
+
* 22.7.0 through 23 and turns ACF on without appearing in `execArgv`.
|
|
44
|
+
* Inferring "off" there makes callers refuse to run in a process that would
|
|
45
|
+
* have worked.
|
|
46
|
+
* - `NODE_OPTIONS=--no-async-context-frame` is accepted on Node 24 and turns
|
|
47
|
+
* ACF off without appearing in `execArgv`. Inferring "on" there is the worse
|
|
48
|
+
* error: the CPED slot is never written, so a writer that starts anyway keeps
|
|
49
|
+
* looking healthy from JS — `getStore()` still works — while every
|
|
50
|
+
* out-of-process reader sees a record that nothing ever updates.
|
|
51
|
+
* - A worker thread created with an explicit `execArgv` doesn't inherit the
|
|
52
|
+
* main thread's command line either, and tooling sometimes rewrites
|
|
53
|
+
* `process.execArgv` outright.
|
|
54
|
+
*
|
|
55
|
+
* Detected by asking the addon what is in the CPED slot during a `run()`. With
|
|
56
|
+
* ACF, Node installs an AsyncContextFrame — a JS Map keyed by the
|
|
57
|
+
* `AsyncLocalStorage` instance, valued by its store — as the running
|
|
58
|
+
* continuation's CPED; without it, nothing writes the slot. So a probe storage
|
|
59
|
+
* whose own store is visible there is direct evidence, and it is evidence about
|
|
60
|
+
* the exact slot both consumers read: `WallProfiler::SetContext` requires that
|
|
61
|
+
* Map, and the thread-ctx reader looks this very key up by the identity hash
|
|
62
|
+
* published as `als_identity_hash`.
|
|
63
|
+
*
|
|
64
|
+
* Observing whether `run()` delegates to `enterWith()` would be an indirect
|
|
65
|
+
* proxy for the same thing: it holds today, but it depends on `run()`
|
|
66
|
+
* dispatching through the instance property, which is unspecified and which
|
|
67
|
+
* anything patching `AsyncLocalStorage` can break — and the failure would be
|
|
68
|
+
* silent and in the dangerous direction.
|
|
69
|
+
*
|
|
70
|
+
* Memoized: the answer is fixed for the life of the thread.
|
|
71
|
+
*/
|
|
72
|
+
function isAsyncContextFrameActive() {
|
|
73
|
+
if (active === undefined) {
|
|
74
|
+
const probe = new node_async_hooks_1.AsyncLocalStorage();
|
|
75
|
+
// Object identity, so a stray equal-valued binding can't answer for us.
|
|
76
|
+
const sentinel = {};
|
|
77
|
+
let bound = false;
|
|
78
|
+
probe.run(sentinel, () => {
|
|
79
|
+
bound = bindings().cpedMapContains(probe, sentinel);
|
|
80
|
+
});
|
|
81
|
+
probe.disable();
|
|
82
|
+
active = bound;
|
|
83
|
+
}
|
|
84
|
+
return active;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* How to turn AsyncContextFrame on, for the error message of whatever declined
|
|
88
|
+
* to run without it.
|
|
89
|
+
*
|
|
90
|
+
* Advisory text only — never decide availability from this. That is what
|
|
91
|
+
* {@link isAsyncContextFrameActive} is for.
|
|
92
|
+
*/
|
|
93
|
+
function asyncContextFrameHint() {
|
|
94
|
+
const version = process.versions.node;
|
|
95
|
+
const [major, minor] = version.split('.').map(Number);
|
|
96
|
+
// Hand-rolled rather than semver.satisfies: semver is a devDependency, and
|
|
97
|
+
// this module ships.
|
|
98
|
+
if (major < 22 || (major === 22 && minor < 7)) {
|
|
99
|
+
return `Node ${version} does not support it at all; Node 24 and later enable it by default`;
|
|
100
|
+
}
|
|
101
|
+
if (major < 24) {
|
|
102
|
+
return `Node ${version} needs --experimental-async-context-frame, on the command line or in NODE_OPTIONS; Node 24 and later enable it by default`;
|
|
103
|
+
}
|
|
104
|
+
return `Node ${version} enables it by default, so something turned it off — look for --no-async-context-frame on the command line, in NODE_OPTIONS, or in this worker's execArgv`;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=async-context-frame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context-frame.js","sourceRoot":"","sources":["../../ts/src/async-context-frame.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AA8DH,8DAaC;AASD,sDAYC;AA9FD,uDAAmD;AACnD,+BAA0B;AAM1B,IAAI,KAAwB,CAAC;AAE7B,4EAA4E;AAC5E,+EAA+E;AAC/E,SAAS,QAAQ;IACf,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAC9C,KAAK,GAAG,WAAW,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAU,CAAC;IAC5D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,IAAI,MAA2B,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,SAAgB,yBAAyB;IACvC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,IAAI,oCAAiB,EAAU,CAAC;QAC9C,wEAAwE;QACxE,MAAM,QAAQ,GAAG,EAAE,CAAC;QACpB,IAAI,KAAK,GAAG,KAAK,CAAC;QAClB,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE;YACvB,KAAK,GAAG,QAAQ,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,MAAM,GAAG,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB;IACnC,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IACtC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACtD,2EAA2E;IAC3E,qBAAqB;IACrB,IAAI,KAAK,GAAG,EAAE,IAAI,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;QAC9C,OAAO,QAAQ,OAAO,qEAAqE,CAAC;IAC9F,CAAC;IACD,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;QACf,OAAO,QAAQ,OAAO,2HAA2H,CAAC;IACpJ,CAAC;IACD,OAAO,QAAQ,OAAO,2JAA2J,CAAC;AACpL,CAAC"}
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { AllocationProfileNode } from './v8-types';
|
|
17
|
-
export declare function startSamplingHeapProfiler(heapIntervalBytes: number, heapStackDepth: number): void;
|
|
16
|
+
import { AllocationProfileNode, AllocationProfileNodeWithStats } from './v8-types';
|
|
17
|
+
export declare function startSamplingHeapProfiler(heapIntervalBytes: number, heapStackDepth: number, allocations?: boolean): void;
|
|
18
18
|
export declare function stopSamplingHeapProfiler(): void;
|
|
19
|
+
export declare function getAllocationProfile(): AllocationProfileNode | AllocationProfileNodeWithStats;
|
|
19
20
|
export declare function mapAllocationProfile<T>(callback: (root: AllocationProfileNode) => T): T;
|
|
20
21
|
export type NearHeapLimitCallback = (profile: AllocationProfileNode) => void;
|
|
21
|
-
export declare function monitorOutOfMemory(heapLimitExtensionSize: number, maxHeapLimitExtensionCount: number, dumpHeapProfileOnSdterr: boolean, exportCommand: Array<
|
|
22
|
+
export declare function monitorOutOfMemory(heapLimitExtensionSize: number, maxHeapLimitExtensionCount: number, dumpHeapProfileOnSdterr: boolean, exportCommand: Array<string> | undefined, callback: NearHeapLimitCallback | undefined, callbackMode: number, isMainThread: boolean, automaticHeapLimitExtension: boolean): void;
|
|
@@ -50,22 +50,26 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
51
|
exports.startSamplingHeapProfiler = startSamplingHeapProfiler;
|
|
52
52
|
exports.stopSamplingHeapProfiler = stopSamplingHeapProfiler;
|
|
53
|
+
exports.getAllocationProfile = getAllocationProfile;
|
|
53
54
|
exports.mapAllocationProfile = mapAllocationProfile;
|
|
54
55
|
exports.monitorOutOfMemory = monitorOutOfMemory;
|
|
55
56
|
const path = __importStar(require("path"));
|
|
56
57
|
const findBinding = require('node-gyp-build');
|
|
57
58
|
const profiler = findBinding(path.join(__dirname, '..', '..'));
|
|
58
59
|
// Wrappers around native heap profiler functions.
|
|
59
|
-
function startSamplingHeapProfiler(heapIntervalBytes, heapStackDepth) {
|
|
60
|
-
profiler.heapProfiler.startSamplingHeapProfiler(heapIntervalBytes, heapStackDepth);
|
|
60
|
+
function startSamplingHeapProfiler(heapIntervalBytes, heapStackDepth, allocations = false) {
|
|
61
|
+
profiler.heapProfiler.startSamplingHeapProfiler(heapIntervalBytes, heapStackDepth, allocations);
|
|
61
62
|
}
|
|
62
63
|
function stopSamplingHeapProfiler() {
|
|
63
64
|
profiler.heapProfiler.stopSamplingHeapProfiler();
|
|
64
65
|
}
|
|
66
|
+
function getAllocationProfile() {
|
|
67
|
+
return profiler.heapProfiler.getAllocationProfile();
|
|
68
|
+
}
|
|
65
69
|
function mapAllocationProfile(callback) {
|
|
66
70
|
return profiler.heapProfiler.mapAllocationProfile(callback);
|
|
67
71
|
}
|
|
68
|
-
function monitorOutOfMemory(heapLimitExtensionSize, maxHeapLimitExtensionCount, dumpHeapProfileOnSdterr, exportCommand, callback, callbackMode, isMainThread) {
|
|
69
|
-
profiler.heapProfiler.monitorOutOfMemory(heapLimitExtensionSize, maxHeapLimitExtensionCount, dumpHeapProfileOnSdterr, exportCommand, callback, callbackMode, isMainThread);
|
|
72
|
+
function monitorOutOfMemory(heapLimitExtensionSize, maxHeapLimitExtensionCount, dumpHeapProfileOnSdterr, exportCommand, callback, callbackMode, isMainThread, automaticHeapLimitExtension) {
|
|
73
|
+
profiler.heapProfiler.monitorOutOfMemory(heapLimitExtensionSize, maxHeapLimitExtensionCount, dumpHeapProfileOnSdterr, exportCommand, callback, callbackMode, isMainThread, automaticHeapLimitExtension);
|
|
70
74
|
}
|
|
71
75
|
//# sourceMappingURL=heap-profiler-bindings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heap-profiler-bindings.js","sourceRoot":"","sources":["../../ts/src/heap-profiler-bindings.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"heap-profiler-bindings.js","sourceRoot":"","sources":["../../ts/src/heap-profiler-bindings.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcH,8DAUC;AAED,4DAEC;AAED,oDAIC;AAED,oDAIC;AAID,gDAoBC;AA9DD,2CAA6B;AAO7B,MAAM,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC9C,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE/D,kDAAkD;AAElD,SAAgB,yBAAyB,CACvC,iBAAyB,EACzB,cAAsB,EACtB,WAAW,GAAG,KAAK;IAEnB,QAAQ,CAAC,YAAY,CAAC,yBAAyB,CAC7C,iBAAiB,EACjB,cAAc,EACd,WAAW,CACZ,CAAC;AACJ,CAAC;AAED,SAAgB,wBAAwB;IACtC,QAAQ,CAAC,YAAY,CAAC,wBAAwB,EAAE,CAAC;AACnD,CAAC;AAED,SAAgB,oBAAoB;IAGlC,OAAO,QAAQ,CAAC,YAAY,CAAC,oBAAoB,EAAE,CAAC;AACtD,CAAC;AAED,SAAgB,oBAAoB,CAClC,QAA4C;IAE5C,OAAO,QAAQ,CAAC,YAAY,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AAC9D,CAAC;AAID,SAAgB,kBAAkB,CAChC,sBAA8B,EAC9B,0BAAkC,EAClC,uBAAgC,EAChC,aAAwC,EACxC,QAA2C,EAC3C,YAAoB,EACpB,YAAqB,EACrB,2BAAoC;IAEpC,QAAQ,CAAC,YAAY,CAAC,kBAAkB,CACtC,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,2BAA2B,CAC5B,CAAC;AACJ,CAAC"}
|
|
@@ -14,21 +14,31 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { Profile } from 'pprof-format';
|
|
17
|
+
import { ColumnNumbers } from './profile-serializer';
|
|
17
18
|
import { SourceMapper } from './sourcemapper/sourcemapper';
|
|
18
|
-
import { AllocationProfileNode, GenerateAllocationLabelsFunction } from './v8-types';
|
|
19
|
+
import { AllocationProfileNode, AllocationProfileNodeWithStats, GenerateAllocationLabelsFunction } from './v8-types';
|
|
20
|
+
export declare function v8Profile(): AllocationProfileNode | AllocationProfileNodeWithStats;
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
21
|
-
* an error.
|
|
22
|
-
* Map the heap profiler to a converted profile using callback function.
|
|
22
|
+
* Map the heap profile to a converted profile using callback function when
|
|
23
|
+
* heapProfiler is enabled. Otherwise throws an error.
|
|
23
24
|
*
|
|
24
25
|
* WARNING: Nodes in the tree are only valid during the callback. Do not store
|
|
25
26
|
* references to them. The memory is freed when the callback returns.
|
|
26
27
|
*
|
|
27
|
-
* @param callback - function to convert the heap
|
|
28
|
+
* @param callback - function to convert the heap profile to a converted
|
|
29
|
+
|file
|
|
28
30
|
* @returns <T> converted profile
|
|
29
31
|
*/
|
|
30
|
-
export declare function
|
|
31
|
-
|
|
32
|
+
export declare function v8ProfileV2<T>(callback: (root: AllocationProfileNode) => T): T;
|
|
33
|
+
/**
|
|
34
|
+
* Collects a profile and returns it serialized in pprof format.
|
|
35
|
+
* Throws if heap profiler is not enabled.
|
|
36
|
+
*
|
|
37
|
+
* @param ignoreSamplePath
|
|
38
|
+
* @param sourceMapper
|
|
39
|
+
*/
|
|
40
|
+
export declare function profile(ignoreSamplePath?: string, sourceMapper?: SourceMapper, generateLabels?: GenerateAllocationLabelsFunction, columnNumbers?: ColumnNumbers): Profile;
|
|
41
|
+
export declare function convertProfile(rootNode: AllocationProfileNode | AllocationProfileNodeWithStats, ignoreSamplePath?: string, sourceMapper?: SourceMapper, generateLabels?: GenerateAllocationLabelsFunction, columnNumbers?: ColumnNumbers): Profile;
|
|
32
42
|
/**
|
|
33
43
|
* Collects a profile and returns it serialized in pprof format using lazy V2 API.
|
|
34
44
|
* Throws if heap profiler is not enabled.
|
|
@@ -37,7 +47,7 @@ export declare function convertProfile(rootNode: AllocationProfileNode, ignoreSa
|
|
|
37
47
|
* @param sourceMapper
|
|
38
48
|
* @param generateLabels
|
|
39
49
|
*/
|
|
40
|
-
export declare function
|
|
50
|
+
export declare function profileV2(ignoreSamplePath?: string, sourceMapper?: SourceMapper, generateLabels?: GenerateAllocationLabelsFunction, columnNumbers?: ColumnNumbers): Profile;
|
|
41
51
|
/**
|
|
42
52
|
* Starts heap profiling. If heap profiling has already been started with
|
|
43
53
|
* the same parameters, this is a noop. If heap profiler has already been
|
|
@@ -45,8 +55,12 @@ export declare function profile(ignoreSamplePath?: string, sourceMapper?: Source
|
|
|
45
55
|
*
|
|
46
56
|
* @param intervalBytes - average number of bytes between samples.
|
|
47
57
|
* @param stackDepth - maximum stack depth for samples collected.
|
|
58
|
+
* @param allocations - include total allocation samples in the profile.
|
|
59
|
+
* When true, each call to `profile()` forces a full GC (via
|
|
60
|
+
* v8::HeapProfiler::kSamplingForceGC) to classify sampled objects as
|
|
61
|
+
* live/dead, which adds a measurable pause. Requires Node.js >= 26.
|
|
48
62
|
*/
|
|
49
|
-
export declare function start(intervalBytes: number, stackDepth: number): void;
|
|
63
|
+
export declare function start(intervalBytes: number, stackDepth: number, allocations?: boolean): void;
|
|
50
64
|
export declare function stop(): void;
|
|
51
65
|
export type NearHeapLimitCallback = (profile: Profile) => void;
|
|
52
66
|
export declare const CallbackMode: {
|
|
@@ -54,25 +68,38 @@ export declare const CallbackMode: {
|
|
|
54
68
|
Interrupt: number;
|
|
55
69
|
Both: number;
|
|
56
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* How much the heap limit is raised when v8 signals it is near the limit.
|
|
73
|
+
*
|
|
74
|
+
* A number is an exact byte count, and 0 means "grant no extension and let v8
|
|
75
|
+
* run its normal OOM handling". `'auto'` instead sizes the extension to one
|
|
76
|
+
* maximum young generation - the same budget Node.js grants its own near-OOM
|
|
77
|
+
* heap snapshot callback - which is what v8 actually needs to finish one more
|
|
78
|
+
* GC while the profile is captured.
|
|
79
|
+
*/
|
|
80
|
+
export type HeapLimitExtensionSize = number | 'auto';
|
|
57
81
|
/**
|
|
58
82
|
* Add monitoring for v8 heap, heap profiler must already be started.
|
|
59
83
|
* When an out of heap memory event occurs:
|
|
60
|
-
* -
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
84
|
+
* - the heap limit is extended by |heapLimitExtensionSize| so a profile can
|
|
85
|
+
* be captured before the process dies. If the extension amount is not
|
|
86
|
+
* enough to satisfy the memory allocation that triggers GC and OOM, the
|
|
87
|
+
* process will abort, so prefer 'auto' over a hand-picked constant. This
|
|
88
|
+
* top-level extension can occur |maxHeapLimitExtensionCount| times.
|
|
89
|
+
* Reentrant rescue extensions used to finish an in-progress capture are
|
|
90
|
+
* additional and are not included in that count.
|
|
64
91
|
* - heap profile is dumped as folded stacks on stderr if
|
|
65
92
|
* |dumpHeapProfileOnSdterr| is true
|
|
66
93
|
* - heap profile is dumped in temporary file and a new process is spawned
|
|
67
94
|
* with |exportCommand| arguments and profile path appended at the end.
|
|
68
|
-
* - |callback| is called. Callback can be invoked only if
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
95
|
+
* - |callback| is called. Callback can be invoked only if the extension is
|
|
96
|
+
* enough for the process to continue. Invocation will be done by a
|
|
97
|
+
* RequestInterrupt if |callbackMode| is Interrupt or Both, this might be
|
|
98
|
+
* unsafe since Isolate should not be reentered from RequestInterrupt, but
|
|
99
|
+
* this allows to interrupt synchronous code. Otherwise the callback is
|
|
100
|
+
* scheduled to be called asynchronously.
|
|
74
101
|
* @param heapLimitExtensionSize - amount of bytes heap should be expanded
|
|
75
|
-
* with upon OOM
|
|
102
|
+
* with upon OOM, or 'auto' to size it to one maximum young generation
|
|
76
103
|
* @param maxHeapLimitExtensionCount - maximum number of times heap size
|
|
77
104
|
* extension can occur
|
|
78
105
|
* @param dumpHeapProfileOnSdterr - dump heap profile on stderr upon OOM
|
|
@@ -81,4 +108,4 @@ export declare const CallbackMode: {
|
|
|
81
108
|
* @param callback - callback to call when OOM occurs
|
|
82
109
|
* @param callbackMode
|
|
83
110
|
*/
|
|
84
|
-
export declare function monitorOutOfMemory(heapLimitExtensionSize:
|
|
111
|
+
export declare function monitorOutOfMemory(heapLimitExtensionSize: HeapLimitExtensionSize, maxHeapLimitExtensionCount: number, dumpHeapProfileOnSdterr: boolean, exportCommand?: Array<string>, callback?: NearHeapLimitCallback, callbackMode?: number): void;
|
package/out/src/heap-profiler.js
CHANGED
|
@@ -17,8 +17,10 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.CallbackMode = void 0;
|
|
19
19
|
exports.v8Profile = v8Profile;
|
|
20
|
-
exports.
|
|
20
|
+
exports.v8ProfileV2 = v8ProfileV2;
|
|
21
21
|
exports.profile = profile;
|
|
22
|
+
exports.convertProfile = convertProfile;
|
|
23
|
+
exports.profileV2 = profileV2;
|
|
22
24
|
exports.start = start;
|
|
23
25
|
exports.stop = stop;
|
|
24
26
|
exports.monitorOutOfMemory = monitorOutOfMemory;
|
|
@@ -28,24 +30,61 @@ const worker_threads_1 = require("worker_threads");
|
|
|
28
30
|
let enabled = false;
|
|
29
31
|
let heapIntervalBytes = 0;
|
|
30
32
|
let heapStackDepth = 0;
|
|
31
|
-
|
|
33
|
+
let startedWithAllocations = false;
|
|
34
|
+
/*
|
|
32
35
|
* Collects a heap profile when heapProfiler is enabled. Otherwise throws
|
|
33
36
|
* an error.
|
|
34
|
-
*
|
|
37
|
+
*
|
|
38
|
+
* Data is returned in V8 allocation profile format.
|
|
39
|
+
*/
|
|
40
|
+
function v8Profile() {
|
|
41
|
+
if (!enabled) {
|
|
42
|
+
throw new Error('Heap profiler is not enabled.');
|
|
43
|
+
}
|
|
44
|
+
return (0, heap_profiler_bindings_1.getAllocationProfile)();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Map the heap profile to a converted profile using callback function when
|
|
48
|
+
* heapProfiler is enabled. Otherwise throws an error.
|
|
35
49
|
*
|
|
36
50
|
* WARNING: Nodes in the tree are only valid during the callback. Do not store
|
|
37
51
|
* references to them. The memory is freed when the callback returns.
|
|
38
52
|
*
|
|
39
|
-
* @param callback - function to convert the heap
|
|
53
|
+
* @param callback - function to convert the heap profile to a converted
|
|
54
|
+
|file
|
|
40
55
|
* @returns <T> converted profile
|
|
41
56
|
*/
|
|
42
|
-
function
|
|
57
|
+
function v8ProfileV2(callback) {
|
|
43
58
|
if (!enabled) {
|
|
44
59
|
throw new Error('Heap profiler is not enabled.');
|
|
45
60
|
}
|
|
61
|
+
if (startedWithAllocations) {
|
|
62
|
+
throw new Error('profileV2 does not support allocation mode.');
|
|
63
|
+
}
|
|
46
64
|
return (0, heap_profiler_bindings_1.mapAllocationProfile)(callback);
|
|
47
65
|
}
|
|
48
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Collects a profile and returns it serialized in pprof format.
|
|
68
|
+
* Throws if heap profiler is not enabled.
|
|
69
|
+
*
|
|
70
|
+
* @param ignoreSamplePath
|
|
71
|
+
* @param sourceMapper
|
|
72
|
+
*/
|
|
73
|
+
function profile(ignoreSamplePath, sourceMapper, generateLabels, columnNumbers = profile_serializer_1.DEFAULT_COLUMN_NUMBERS) {
|
|
74
|
+
const result = convertProfile(v8Profile(), ignoreSamplePath, sourceMapper, generateLabels, columnNumbers);
|
|
75
|
+
// In allocation mode V8 keeps every sampled object (live + collected-by-GC)
|
|
76
|
+
// in an append-only buffer that's only freed by stopSamplingHeapProfiler.
|
|
77
|
+
// Without this reset, each call to getAllocationProfile re-reads the entire
|
|
78
|
+
// history, so alloc_* totals grow linearly with wall-clock time and V8's
|
|
79
|
+
// internal sample buffer leaks for the lifetime of the process.
|
|
80
|
+
if (startedWithAllocations) {
|
|
81
|
+
(0, heap_profiler_bindings_1.stopSamplingHeapProfiler)();
|
|
82
|
+
(0, heap_profiler_bindings_1.startSamplingHeapProfiler)(heapIntervalBytes, heapStackDepth, true);
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
function convertProfile(rootNode, ignoreSamplePath, sourceMapper, generateLabels, columnNumbers = profile_serializer_1.DEFAULT_COLUMN_NUMBERS) {
|
|
87
|
+
const allocations = startedWithAllocations;
|
|
49
88
|
const startTimeNanos = Date.now() * 1000 * 1000;
|
|
50
89
|
// Add node for external memory usage.
|
|
51
90
|
// Current type definitions do not have external.
|
|
@@ -54,18 +93,41 @@ function convertProfile(rootNode, ignoreSamplePath, sourceMapper, generateLabels
|
|
|
54
93
|
const { external } = process.memoryUsage();
|
|
55
94
|
let root;
|
|
56
95
|
if (external > 0) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
96
|
+
if (allocations) {
|
|
97
|
+
const externalNode = {
|
|
98
|
+
name: '(external)',
|
|
99
|
+
scriptName: '',
|
|
100
|
+
children: [],
|
|
101
|
+
allocations: [
|
|
102
|
+
{
|
|
103
|
+
inuseObjects: 1,
|
|
104
|
+
inuseSpaceBytes: external,
|
|
105
|
+
allocObjects: 1,
|
|
106
|
+
allocSpaceBytes: external,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
const allocationRoot = rootNode;
|
|
111
|
+
root = {
|
|
112
|
+
...allocationRoot,
|
|
113
|
+
children: [...allocationRoot.children, externalNode],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const externalNode = {
|
|
118
|
+
name: '(external)',
|
|
119
|
+
scriptName: '',
|
|
120
|
+
children: [],
|
|
121
|
+
allocations: [{ sizeBytes: external, count: 1 }],
|
|
122
|
+
};
|
|
123
|
+
const heapRoot = rootNode;
|
|
124
|
+
root = { ...heapRoot, children: [...heapRoot.children, externalNode] };
|
|
125
|
+
}
|
|
64
126
|
}
|
|
65
127
|
else {
|
|
66
128
|
root = rootNode;
|
|
67
129
|
}
|
|
68
|
-
return (0, profile_serializer_1.serializeHeapProfile)(root, startTimeNanos, heapIntervalBytes, ignoreSamplePath, sourceMapper, generateLabels);
|
|
130
|
+
return (0, profile_serializer_1.serializeHeapProfile)(root, startTimeNanos, heapIntervalBytes, ignoreSamplePath, sourceMapper, generateLabels, allocations, columnNumbers);
|
|
69
131
|
}
|
|
70
132
|
/**
|
|
71
133
|
* Collects a profile and returns it serialized in pprof format using lazy V2 API.
|
|
@@ -75,9 +137,9 @@ function convertProfile(rootNode, ignoreSamplePath, sourceMapper, generateLabels
|
|
|
75
137
|
* @param sourceMapper
|
|
76
138
|
* @param generateLabels
|
|
77
139
|
*/
|
|
78
|
-
function
|
|
79
|
-
return
|
|
80
|
-
return convertProfile(root, ignoreSamplePath, sourceMapper, generateLabels);
|
|
140
|
+
function profileV2(ignoreSamplePath, sourceMapper, generateLabels, columnNumbers = profile_serializer_1.DEFAULT_COLUMN_NUMBERS) {
|
|
141
|
+
return v8ProfileV2(root => {
|
|
142
|
+
return convertProfile(root, ignoreSamplePath, sourceMapper, generateLabels, columnNumbers);
|
|
81
143
|
});
|
|
82
144
|
}
|
|
83
145
|
/**
|
|
@@ -87,20 +149,26 @@ function profile(ignoreSamplePath, sourceMapper, generateLabels) {
|
|
|
87
149
|
*
|
|
88
150
|
* @param intervalBytes - average number of bytes between samples.
|
|
89
151
|
* @param stackDepth - maximum stack depth for samples collected.
|
|
152
|
+
* @param allocations - include total allocation samples in the profile.
|
|
153
|
+
* When true, each call to `profile()` forces a full GC (via
|
|
154
|
+
* v8::HeapProfiler::kSamplingForceGC) to classify sampled objects as
|
|
155
|
+
* live/dead, which adds a measurable pause. Requires Node.js >= 26.
|
|
90
156
|
*/
|
|
91
|
-
function start(intervalBytes, stackDepth) {
|
|
157
|
+
function start(intervalBytes, stackDepth, allocations = false) {
|
|
92
158
|
if (enabled) {
|
|
93
159
|
throw new Error(`Heap profiler is already started with intervalBytes ${heapIntervalBytes} and stackDepth ${stackDepth}`);
|
|
94
160
|
}
|
|
95
161
|
heapIntervalBytes = intervalBytes;
|
|
96
162
|
heapStackDepth = stackDepth;
|
|
97
|
-
|
|
163
|
+
startedWithAllocations = allocations;
|
|
164
|
+
(0, heap_profiler_bindings_1.startSamplingHeapProfiler)(intervalBytes, stackDepth, allocations);
|
|
98
165
|
enabled = true;
|
|
99
166
|
}
|
|
100
167
|
// Stops heap profiling. If heap profiling has not been started, does nothing.
|
|
101
168
|
function stop() {
|
|
102
169
|
if (enabled) {
|
|
103
170
|
enabled = false;
|
|
171
|
+
startedWithAllocations = false;
|
|
104
172
|
(0, heap_profiler_bindings_1.stopSamplingHeapProfiler)();
|
|
105
173
|
}
|
|
106
174
|
}
|
|
@@ -112,22 +180,25 @@ exports.CallbackMode = {
|
|
|
112
180
|
/**
|
|
113
181
|
* Add monitoring for v8 heap, heap profiler must already be started.
|
|
114
182
|
* When an out of heap memory event occurs:
|
|
115
|
-
* -
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
183
|
+
* - the heap limit is extended by |heapLimitExtensionSize| so a profile can
|
|
184
|
+
* be captured before the process dies. If the extension amount is not
|
|
185
|
+
* enough to satisfy the memory allocation that triggers GC and OOM, the
|
|
186
|
+
* process will abort, so prefer 'auto' over a hand-picked constant. This
|
|
187
|
+
* top-level extension can occur |maxHeapLimitExtensionCount| times.
|
|
188
|
+
* Reentrant rescue extensions used to finish an in-progress capture are
|
|
189
|
+
* additional and are not included in that count.
|
|
119
190
|
* - heap profile is dumped as folded stacks on stderr if
|
|
120
191
|
* |dumpHeapProfileOnSdterr| is true
|
|
121
192
|
* - heap profile is dumped in temporary file and a new process is spawned
|
|
122
193
|
* with |exportCommand| arguments and profile path appended at the end.
|
|
123
|
-
* - |callback| is called. Callback can be invoked only if
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
194
|
+
* - |callback| is called. Callback can be invoked only if the extension is
|
|
195
|
+
* enough for the process to continue. Invocation will be done by a
|
|
196
|
+
* RequestInterrupt if |callbackMode| is Interrupt or Both, this might be
|
|
197
|
+
* unsafe since Isolate should not be reentered from RequestInterrupt, but
|
|
198
|
+
* this allows to interrupt synchronous code. Otherwise the callback is
|
|
199
|
+
* scheduled to be called asynchronously.
|
|
129
200
|
* @param heapLimitExtensionSize - amount of bytes heap should be expanded
|
|
130
|
-
* with upon OOM
|
|
201
|
+
* with upon OOM, or 'auto' to size it to one maximum young generation
|
|
131
202
|
* @param maxHeapLimitExtensionCount - maximum number of times heap size
|
|
132
203
|
* extension can occur
|
|
133
204
|
* @param dumpHeapProfileOnSdterr - dump heap profile on stderr upon OOM
|
|
@@ -146,6 +217,7 @@ function monitorOutOfMemory(heapLimitExtensionSize, maxHeapLimitExtensionCount,
|
|
|
146
217
|
callback(convertProfile(profile));
|
|
147
218
|
};
|
|
148
219
|
}
|
|
149
|
-
|
|
220
|
+
const automatic = heapLimitExtensionSize === 'auto';
|
|
221
|
+
(0, heap_profiler_bindings_1.monitorOutOfMemory)(automatic ? 0 : heapLimitExtensionSize, maxHeapLimitExtensionCount, dumpHeapProfileOnSdterr, exportCommand || [], newCallback, typeof callbackMode !== 'undefined' ? callbackMode : exports.CallbackMode.Async, worker_threads_1.isMainThread, automatic);
|
|
150
222
|
}
|
|
151
223
|
//# sourceMappingURL=heap-profiler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heap-profiler.js","sourceRoot":"","sources":["../../ts/src/heap-profiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;
|
|
1
|
+
{"version":3,"file":"heap-profiler.js","sourceRoot":"","sources":["../../ts/src/heap-profiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAmCH,8BAOC;AAaD,kCAUC;AASD,0BAuBC;AAED,wCA0DC;AAUD,8BAeC;AAcD,sBAeC;AAGD,oBAMC;AAmDD,gDA8BC;AAzSD,qEAMkC;AAClC,6DAI8B;AAO9B,mDAA4C;AAE5C,IAAI,OAAO,GAAG,KAAK,CAAC;AACpB,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAC1B,IAAI,cAAc,GAAG,CAAC,CAAC;AACvB,IAAI,sBAAsB,GAAG,KAAK,CAAC;AAEnC;;;;;GAKG;AACH,SAAgB,SAAS;IAGvB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,IAAA,6CAAoB,GAAE,CAAC;AAChC,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,WAAW,CACzB,QAA4C;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C,CAAC,CAAC,CAAC,CAAC,CAAC,sBAAsB,EACtC,0BAA0B,EAC1B,uBAAuB,EACvB,aAAa,IAAI,EAAE,EACnB,WAAW,EACX,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,oBAAY,CAAC,KAAK,EACvE,6BAAY,EACZ,SAAS,CACV,CAAC;AACJ,CAAC"}
|
package/out/src/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as heapProfiler from './heap-profiler';
|
|
2
|
+
import * as otelThreadCtxModule from './otel-thread-ctx';
|
|
2
3
|
import * as timeProfiler from './time-profiler';
|
|
3
4
|
export { AllocationProfileNode, TimeProfileNode, ProfileNode, LabelSet, } from './v8-types';
|
|
5
|
+
export { HeapLimitExtensionSize } from './heap-profiler';
|
|
4
6
|
export { encode, encodeSync } from './profile-encoder';
|
|
5
7
|
export { SourceMapper } from './sourcemapper/sourcemapper';
|
|
6
8
|
export { setLogger } from './logger';
|
|
@@ -9,6 +11,7 @@ export declare const time: {
|
|
|
9
11
|
profile: typeof timeProfiler.profile;
|
|
10
12
|
start: typeof timeProfiler.start;
|
|
11
13
|
stop: typeof timeProfiler.stop;
|
|
14
|
+
profileV2: typeof timeProfiler.profileV2;
|
|
12
15
|
getContext: typeof timeProfiler.getContext;
|
|
13
16
|
setContext: typeof timeProfiler.setContext;
|
|
14
17
|
runWithContext: typeof timeProfiler.runWithContext;
|
|
@@ -26,6 +29,7 @@ export declare const heap: {
|
|
|
26
29
|
start: typeof heapProfiler.start;
|
|
27
30
|
stop: typeof heapProfiler.stop;
|
|
28
31
|
profile: typeof heapProfiler.profile;
|
|
32
|
+
profileV2: typeof heapProfiler.profileV2;
|
|
29
33
|
convertProfile: typeof heapProfiler.convertProfile;
|
|
30
34
|
v8Profile: typeof heapProfiler.v8Profile;
|
|
31
35
|
monitorOutOfMemory: typeof heapProfiler.monitorOutOfMemory;
|
|
@@ -35,3 +39,9 @@ export declare const heap: {
|
|
|
35
39
|
Both: number;
|
|
36
40
|
};
|
|
37
41
|
};
|
|
42
|
+
export declare const otelThreadCtx: {
|
|
43
|
+
ThreadContext: otelThreadCtxModule.ThreadContextCtor;
|
|
44
|
+
getContext: () => otelThreadCtxModule.ThreadContext | undefined;
|
|
45
|
+
clearContext: () => void;
|
|
46
|
+
getProcessContextAttributes: typeof otelThreadCtxModule.getProcessContextAttributes;
|
|
47
|
+
};
|