@datadog/pprof 6.0.0-pre-83708df → 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 +25 -3
- package/out/src/profile-serializer.js +100 -24
- package/out/src/profile-serializer.js.map +1 -1
- package/out/src/time-profiler.d.ts +18 -4
- package/out/src/time-profiler.js +38 -5
- package/out/src/time-profiler.js.map +1 -1
- package/out/src/v8-types.d.ts +10 -0
- package/package.json +42 -17
- 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/out/src/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.heap = exports.time = exports.getNativeThreadId = exports.setLogger = exports.SourceMapper = exports.encodeSync = exports.encode = void 0;
|
|
36
|
+
exports.otelThreadCtx = exports.heap = exports.time = exports.getNativeThreadId = exports.setLogger = exports.SourceMapper = exports.encodeSync = exports.encode = void 0;
|
|
37
37
|
/**
|
|
38
38
|
* Copyright 2019 Google Inc. All Rights Reserved.
|
|
39
39
|
*
|
|
@@ -51,6 +51,7 @@ exports.heap = exports.time = exports.getNativeThreadId = exports.setLogger = ex
|
|
|
51
51
|
*/
|
|
52
52
|
const fs_1 = require("fs");
|
|
53
53
|
const heapProfiler = __importStar(require("./heap-profiler"));
|
|
54
|
+
const otelThreadCtxModule = __importStar(require("./otel-thread-ctx"));
|
|
54
55
|
const profile_encoder_1 = require("./profile-encoder");
|
|
55
56
|
const timeProfiler = __importStar(require("./time-profiler"));
|
|
56
57
|
var profile_encoder_2 = require("./profile-encoder");
|
|
@@ -66,6 +67,7 @@ exports.time = {
|
|
|
66
67
|
profile: timeProfiler.profile,
|
|
67
68
|
start: timeProfiler.start,
|
|
68
69
|
stop: timeProfiler.stop,
|
|
70
|
+
profileV2: timeProfiler.profileV2,
|
|
69
71
|
getContext: timeProfiler.getContext,
|
|
70
72
|
setContext: timeProfiler.setContext,
|
|
71
73
|
runWithContext: timeProfiler.runWithContext,
|
|
@@ -79,11 +81,22 @@ exports.heap = {
|
|
|
79
81
|
start: heapProfiler.start,
|
|
80
82
|
stop: heapProfiler.stop,
|
|
81
83
|
profile: heapProfiler.profile,
|
|
84
|
+
profileV2: heapProfiler.profileV2,
|
|
82
85
|
convertProfile: heapProfiler.convertProfile,
|
|
83
86
|
v8Profile: heapProfiler.v8Profile,
|
|
84
87
|
monitorOutOfMemory: heapProfiler.monitorOutOfMemory,
|
|
85
88
|
CallbackMode: heapProfiler.CallbackMode,
|
|
86
89
|
};
|
|
90
|
+
// Writer for the OpenTelemetry Thread Local Context Record (OTEP-4947).
|
|
91
|
+
// Linux + AsyncContextFrame (Node 22 with --experimental-async-context-frame,
|
|
92
|
+
// Node 24+ by default) only; degrades to no-ops on other platforms / Node
|
|
93
|
+
// versions.
|
|
94
|
+
exports.otelThreadCtx = {
|
|
95
|
+
ThreadContext: otelThreadCtxModule.ThreadContext,
|
|
96
|
+
getContext: otelThreadCtxModule.getContext,
|
|
97
|
+
clearContext: otelThreadCtxModule.clearContext,
|
|
98
|
+
getProcessContextAttributes: otelThreadCtxModule.getProcessContextAttributes,
|
|
99
|
+
};
|
|
87
100
|
// If loaded with --require, start profiling.
|
|
88
101
|
if (module.parent && module.parent.id === 'internal/preload') {
|
|
89
102
|
exports.time.start({});
|
package/out/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;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AAE,YAAY,CAAC,SAAS;IACjC,kBAAkB,EAAE,YAAY,CAAC,kBAAkB;IACnD,YAAY,EAAE,YAAY,CAAC,YAAY;CACxC,CAAC;AAEF,wEAAwE;AACxE,8EAA8E;AAC9E,0EAA0E;AAC1E,YAAY;AACC,QAAA,aAAa,GAAG;IAC3B,aAAa,EAAE,mBAAmB,CAAC,aAAa;IAChD,UAAU,EAAE,mBAAmB,CAAC,UAAU;IAC1C,YAAY,EAAE,mBAAmB,CAAC,YAAY;IAC9C,2BAA2B,EAAE,mBAAmB,CAAC,2BAA2B;CAC7E,CAAC;AAEF,6CAA6C;AAC7C,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,kBAAkB,EAAE,CAAC;IAC7D,YAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACtB,uEAAuE;QACvE,kBAAkB;QAClB,MAAM,OAAO,GAAG,YAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,IAAA,4BAAU,EAAC,OAAO,CAAC,CAAC;QACnC,IAAA,kBAAa,EAAC,iBAAiB,OAAO,CAAC,GAAG,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OTEP-4719 process-context attributes corresponding to a particular
|
|
3
|
+
* key list. Spread this into whatever attribute map the application
|
|
4
|
+
* hands to its OTEP-4719 process-context publisher.
|
|
5
|
+
*/
|
|
6
|
+
export interface ProcessContextAttributes {
|
|
7
|
+
readonly 'threadlocal.schema_version': 'nodejs_v1_dev';
|
|
8
|
+
readonly 'threadlocal.attribute_key_map': readonly string[];
|
|
9
|
+
readonly 'threadlocal.js_object_record_offset': number;
|
|
10
|
+
readonly 'threadlocal.tagged_size': number;
|
|
11
|
+
readonly 'threadlocal.js_map_table_offset': number;
|
|
12
|
+
readonly 'threadlocal.ordered_hash_map_header_size': number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A thread-context record. Construct with `new ThreadContext(...)`; install
|
|
16
|
+
* via the {@link enter} or {@link run} instance methods. The underlying
|
|
17
|
+
* native record is GC-owned: when no JS or async-context-frame reference
|
|
18
|
+
* survives, it's freed.
|
|
19
|
+
*
|
|
20
|
+
* `appendAttributes` mutates the context's record in place. Because every
|
|
21
|
+
* async-context frame that holds the same `ThreadContext` reference observes
|
|
22
|
+
* the same native record, an append is visible across all those frames even
|
|
23
|
+
* when the reallocate path runs (the record is re-published on the same JS
|
|
24
|
+
* object, which is never replaced).
|
|
25
|
+
*/
|
|
26
|
+
export interface ThreadContext {
|
|
27
|
+
appendAttributes(attributes: Array<string | null | undefined> | undefined): void;
|
|
28
|
+
/**
|
|
29
|
+
* Mark this context's underlying record `valid` byte as 0 in place.
|
|
30
|
+
* Every async-context frame that still holds this `ThreadContext`
|
|
31
|
+
* reference (including those that inherited it verbatim from a
|
|
32
|
+
* parent frame) will subsequently present a record with `valid = 0`
|
|
33
|
+
* to a reader, so this one call drops the record out of scope for
|
|
34
|
+
* every such frame at once. Intended for the span-finish path, where
|
|
35
|
+
* clearing only the current frame's context via {@link clearContext}
|
|
36
|
+
* would leave sibling and detached-continuation frames still exposing
|
|
37
|
+
* the finished span's trace / span IDs. Idempotent.
|
|
38
|
+
*/
|
|
39
|
+
invalidate(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Overwrite this context's W3C trace-flags byte in place, for the case
|
|
42
|
+
* where the flags are not yet known when the context is built — an SDK
|
|
43
|
+
* whose sampling decision is deferred learns the sampled bit later, and a
|
|
44
|
+
* decision already taken can still be overridden. Like {@link invalidate},
|
|
45
|
+
* the write is seen at once by every async-context frame holding this
|
|
46
|
+
* context, because they all share one record.
|
|
47
|
+
*
|
|
48
|
+
* Must be an integer in 0..255. Bits beyond those W3C currently defines are
|
|
49
|
+
* stored as given rather than masked off, since W3C requires unknown flag
|
|
50
|
+
* bits to be propagated.
|
|
51
|
+
*/
|
|
52
|
+
setTraceFlags(traceFlags: number): void;
|
|
53
|
+
isTruncated(): boolean;
|
|
54
|
+
/** Debug-only: returns the on-the-wire record bytes. Not stable. */
|
|
55
|
+
debugBytes(): Uint8Array;
|
|
56
|
+
/**
|
|
57
|
+
* Attach this context to the current async-context frame (and every
|
|
58
|
+
* frame derived from it until the frame ends or {@link clearContext}
|
|
59
|
+
* detaches it). Re-installing the same context reference is cheap (no
|
|
60
|
+
* allocation); per-span caching of the context on the caller side is
|
|
61
|
+
* the intended usage pattern.
|
|
62
|
+
*
|
|
63
|
+
* On non-Linux platforms this is a no-op.
|
|
64
|
+
*/
|
|
65
|
+
enter(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Attach this context for the duration of `fn`. Equivalent to
|
|
68
|
+
* `als.run(this, fn)` — after `fn` returns, the previous context is
|
|
69
|
+
* restored. Returns whatever `fn` returns; if `fn` returns a Promise,
|
|
70
|
+
* the same Promise is propagated. On non-Linux platforms simply
|
|
71
|
+
* invokes `fn`.
|
|
72
|
+
*/
|
|
73
|
+
run<T>(fn: () => T): T;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Constructor for {@link ThreadContext}. On non-Linux platforms, returns a
|
|
77
|
+
* no-op instance whose methods do nothing — the OTEP-4947 reader
|
|
78
|
+
* contract is ELF-TLSDESC, only meaningful on Linux.
|
|
79
|
+
*/
|
|
80
|
+
export interface ThreadContextCtor {
|
|
81
|
+
new (traceId: Uint8Array, spanId: Uint8Array, traceFlags?: number, attributes?: Array<string | null | undefined>): ThreadContext;
|
|
82
|
+
readonly prototype: ThreadContext;
|
|
83
|
+
}
|
|
84
|
+
/** {@inheritDoc ThreadContextCtor} */
|
|
85
|
+
export declare let ThreadContext: ThreadContextCtor;
|
|
86
|
+
/**
|
|
87
|
+
* Returns the {@link ThreadContext} currently attached to the active
|
|
88
|
+
* async-context frame, or `undefined` if none is.
|
|
89
|
+
*/
|
|
90
|
+
export declare let getContext: () => ThreadContext | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Detach any {@link ThreadContext} from the current async-context frame.
|
|
93
|
+
* Idempotent when no context is attached. On non-Linux platforms this is
|
|
94
|
+
* a no-op.
|
|
95
|
+
*/
|
|
96
|
+
export declare let clearContext: () => void;
|
|
97
|
+
export declare let _currentRecordBytes: () => Uint8Array | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Returns the OTEP-4719 process-context attributes the caller should
|
|
100
|
+
* publish so an out-of-process reader can decode the on-the-wire uint8
|
|
101
|
+
* key indexes back to attribute names. The supplied `keys` array is the
|
|
102
|
+
* same string list the caller writes into the positional `attributes`
|
|
103
|
+
* argument of {@link ThreadContext}: index N here is the uint8 key index
|
|
104
|
+
* N in each record.
|
|
105
|
+
*
|
|
106
|
+
* `keys` is validated: must be a string array of length ≤ 256 with no
|
|
107
|
+
* duplicates.
|
|
108
|
+
*/
|
|
109
|
+
export declare function getProcessContextAttributes(keys: string[]): ProcessContextAttributes;
|
|
@@ -0,0 +1,166 @@
|
|
|
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._currentRecordBytes = exports.clearContext = exports.getContext = exports.ThreadContext = void 0;
|
|
19
|
+
exports.getProcessContextAttributes = getProcessContextAttributes;
|
|
20
|
+
// Vendored from https://github.com/polarsignals/custom-labels/tree/otel-thread-ctx-wip/js/
|
|
21
|
+
// (originally js/index.js + js/index.d.ts, merged into TypeScript). Kept
|
|
22
|
+
// as a near-verbatim copy: edits should ideally land upstream first and
|
|
23
|
+
// be ported here, so the two stay in sync. We plan to drop this vendored
|
|
24
|
+
// copy once the upstream package is suitable to depend on directly.
|
|
25
|
+
//
|
|
26
|
+
// Known divergence from upstream: AsyncContextFrame availability is
|
|
27
|
+
// feature-detected via ./async-context-frame instead of being inferred from
|
|
28
|
+
// `process.execArgv`, which is wrong in both directions — see that module. Keep
|
|
29
|
+
// the divergence across re-syncs until upstream does the same.
|
|
30
|
+
// Node.js writer for the OpenTelemetry Thread Local Context Record
|
|
31
|
+
// (OTEP-4947), discoverable from an out-of-process reader via the
|
|
32
|
+
// `otel_thread_ctx_nodejs_v1` thread-local symbol exported by
|
|
33
|
+
// `dd_pprof.node`.
|
|
34
|
+
//
|
|
35
|
+
// Linux only; on other platforms the exported functions degrade to no-ops.
|
|
36
|
+
const path_1 = require("path");
|
|
37
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
38
|
+
const async_context_frame_1 = require("./async-context-frame");
|
|
39
|
+
const SCHEMA_VERSION = 'nodejs_v1_dev';
|
|
40
|
+
// V8 layout constants the addon captured from the V8 headers Node bundles.
|
|
41
|
+
// On non-Linux these fall back to values matching Node's standard build
|
|
42
|
+
// (no V8 pointer compression, no sandbox); the reader is Linux-only per
|
|
43
|
+
// the OTEP anyway, so the fallbacks just keep processContextAttributes
|
|
44
|
+
// consistent in shape.
|
|
45
|
+
let JS_OBJECT_RECORD_OFFSET = 24;
|
|
46
|
+
let TAGGED_SIZE = 8;
|
|
47
|
+
let JS_MAP_TABLE_OFFSET = 0x18;
|
|
48
|
+
let ORDERED_HASH_MAP_HEADER_SIZE = 0x10;
|
|
49
|
+
// Debug accessor (not part of the stable API; for tests / reader dev).
|
|
50
|
+
let _currentRecordBytes = () => undefined;
|
|
51
|
+
exports._currentRecordBytes = _currentRecordBytes;
|
|
52
|
+
if (process.platform === 'linux') {
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
54
|
+
const findBinding = require('node-gyp-build');
|
|
55
|
+
const addon = findBinding((0, path_1.join)(__dirname, '..', '..'));
|
|
56
|
+
JS_OBJECT_RECORD_OFFSET = addon.otelThreadCtxJsObjectRecordOffset;
|
|
57
|
+
TAGGED_SIZE = addon.otelThreadCtxTaggedSize;
|
|
58
|
+
JS_MAP_TABLE_OFFSET = addon.otelThreadCtxJsMapTableOffset;
|
|
59
|
+
ORDERED_HASH_MAP_HEADER_SIZE = addon.otelThreadCtxOrderedHashMapHeaderSize;
|
|
60
|
+
exports.ThreadContext = addon.threadContext;
|
|
61
|
+
let als;
|
|
62
|
+
function ensureHook() {
|
|
63
|
+
if (als)
|
|
64
|
+
return als;
|
|
65
|
+
if (!(0, async_context_frame_1.isAsyncContextFrameActive)()) {
|
|
66
|
+
throw new Error('otel thread-ctx writer requires async_context_frame support, which is ' +
|
|
67
|
+
`unavailable: ${(0, async_context_frame_1.asyncContextFrameHint)()}.`);
|
|
68
|
+
}
|
|
69
|
+
als = new node_async_hooks_1.AsyncLocalStorage();
|
|
70
|
+
addon.otelThreadCtxStoreAls(als);
|
|
71
|
+
return als;
|
|
72
|
+
}
|
|
73
|
+
exports.getContext = function () {
|
|
74
|
+
return als ? als.getStore() : undefined;
|
|
75
|
+
};
|
|
76
|
+
// Idempotent: clearing when the hook hasn't been installed (no prior
|
|
77
|
+
// enter / run on a ThreadContext) is a no-op.
|
|
78
|
+
exports.clearContext = function () {
|
|
79
|
+
if (!als)
|
|
80
|
+
return;
|
|
81
|
+
als.enterWith(undefined);
|
|
82
|
+
};
|
|
83
|
+
// Install the active-context channel on the ThreadContext prototype so
|
|
84
|
+
// the only way to push a ThreadContext into our AsyncLocalStorage is
|
|
85
|
+
// via the context itself — callers can't poison the ALS with an
|
|
86
|
+
// arbitrary object.
|
|
87
|
+
exports.ThreadContext.prototype.enter = function () {
|
|
88
|
+
ensureHook().enterWith(this);
|
|
89
|
+
};
|
|
90
|
+
exports.ThreadContext.prototype.run = function (fn) {
|
|
91
|
+
return ensureHook().run(this, fn);
|
|
92
|
+
};
|
|
93
|
+
exports._currentRecordBytes = function () {
|
|
94
|
+
if (!als)
|
|
95
|
+
return undefined;
|
|
96
|
+
const context = als.getStore();
|
|
97
|
+
return context ? context.debugBytes() : undefined;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// Non-Linux degradation. The writer's reader contract is ELF-TLSDESC,
|
|
102
|
+
// meaningful only on Linux; on other platforms we still want the API
|
|
103
|
+
// to be callable so consumers don't have to gate every call site —
|
|
104
|
+
// construction succeeds but produces an inert context, and the
|
|
105
|
+
// enter/run/clearContext entry points don't wire anything into
|
|
106
|
+
// AsyncLocalStorage.
|
|
107
|
+
class NoopThreadContext {
|
|
108
|
+
appendAttributes() { }
|
|
109
|
+
invalidate() { }
|
|
110
|
+
setTraceFlags() { }
|
|
111
|
+
isTruncated() {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
debugBytes() {
|
|
115
|
+
return new Uint8Array(0);
|
|
116
|
+
}
|
|
117
|
+
enter() { }
|
|
118
|
+
run(fn) {
|
|
119
|
+
return fn();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.ThreadContext = NoopThreadContext;
|
|
123
|
+
exports.getContext = function () {
|
|
124
|
+
return undefined;
|
|
125
|
+
};
|
|
126
|
+
exports.clearContext = function () { };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Returns the OTEP-4719 process-context attributes the caller should
|
|
130
|
+
* publish so an out-of-process reader can decode the on-the-wire uint8
|
|
131
|
+
* key indexes back to attribute names. The supplied `keys` array is the
|
|
132
|
+
* same string list the caller writes into the positional `attributes`
|
|
133
|
+
* argument of {@link ThreadContext}: index N here is the uint8 key index
|
|
134
|
+
* N in each record.
|
|
135
|
+
*
|
|
136
|
+
* `keys` is validated: must be a string array of length ≤ 256 with no
|
|
137
|
+
* duplicates.
|
|
138
|
+
*/
|
|
139
|
+
function getProcessContextAttributes(keys) {
|
|
140
|
+
if (!Array.isArray(keys)) {
|
|
141
|
+
throw new TypeError('keys must be an array of attribute names');
|
|
142
|
+
}
|
|
143
|
+
if (keys.length > 256) {
|
|
144
|
+
throw new RangeError('keys array exceeds 256 entries');
|
|
145
|
+
}
|
|
146
|
+
const seen = new Set();
|
|
147
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
148
|
+
const name = keys[i];
|
|
149
|
+
if (typeof name !== 'string') {
|
|
150
|
+
throw new TypeError('every key must be a string');
|
|
151
|
+
}
|
|
152
|
+
if (seen.has(name)) {
|
|
153
|
+
throw new Error(`duplicate key name at index ${i}: ${name}`);
|
|
154
|
+
}
|
|
155
|
+
seen.add(name);
|
|
156
|
+
}
|
|
157
|
+
return Object.freeze({
|
|
158
|
+
'threadlocal.schema_version': SCHEMA_VERSION,
|
|
159
|
+
'threadlocal.attribute_key_map': Object.freeze(keys.slice()),
|
|
160
|
+
'threadlocal.js_object_record_offset': JS_OBJECT_RECORD_OFFSET,
|
|
161
|
+
'threadlocal.tagged_size': TAGGED_SIZE,
|
|
162
|
+
'threadlocal.js_map_table_offset': JS_MAP_TABLE_OFFSET,
|
|
163
|
+
'threadlocal.ordered_hash_map_header_size': ORDERED_HASH_MAP_HEADER_SIZE,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=otel-thread-ctx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel-thread-ctx.js","sourceRoot":"","sources":["../../ts/src/otel-thread-ctx.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAuQH,kEA4BC;AAjSD,2FAA2F;AAC3F,yEAAyE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AM,CAAC;QACnB,4BAA4B,EAAE,cAAc;QAC5C,+BAA+B,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAC5D,qCAAqC,EAAE,uBAAuB;QAC9D,yBAAyB,EAAE,WAAW;QACtC,iCAAiC,EAAE,mBAAmB;QACtD,0CAA0C,EAAE,4BAA4B;KACzE,CAA6B,CAAC;AACjC,CAAC"}
|
|
@@ -15,9 +15,31 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { Profile } from 'pprof-format';
|
|
17
17
|
import { SourceMapper } from './sourcemapper/sourcemapper';
|
|
18
|
-
import { AllocationProfileNode, GenerateAllocationLabelsFunction, GenerateTimeLabelsFunction, TimeProfile, TimeProfileNode } from './v8-types';
|
|
18
|
+
import { AllocationProfileNode, AllocationProfileNodeWithStats, GenerateAllocationLabelsFunction, GenerateTimeLabelsFunction, TimeProfile, TimeProfileNode } from './v8-types';
|
|
19
19
|
export declare const NON_JS_THREADS_FUNCTION_NAME = "Non JS threads activity";
|
|
20
20
|
export declare const GARBAGE_COLLECTION_FUNCTION_NAME = "Garbage Collection";
|
|
21
|
+
/**
|
|
22
|
+
* Controls how a frame's column number is represented in the emitted profile.
|
|
23
|
+
* - `'drop'`: omit the column; only the line number is emitted. This is the
|
|
24
|
+
* default and matches the historical behavior and standard pprof line
|
|
25
|
+
* semantics, so existing consumers see unchanged line numbers.
|
|
26
|
+
* - `'pack'`: pack the column into the high 32 bits of the line field
|
|
27
|
+
* (`column << 32 | line`) — the encoding the Datadog deobfuscation backend
|
|
28
|
+
* decodes (the same one the Chrome profile intake uses). Required to
|
|
29
|
+
* deobfuscate single-line (bundled/minified) frames, where the column is the
|
|
30
|
+
* only discriminator between functions. Only frames whose source map was
|
|
31
|
+
* declared but missing locally are packed.
|
|
32
|
+
* - `'emit'`: like `'pack'`, but records the column in the dedicated pprof
|
|
33
|
+
* `Line.column` field instead of packing it into the line field, so the line
|
|
34
|
+
* field stays standards-compliant and the two concerns are cleanly separated.
|
|
35
|
+
* Scoped to the same frames as `'pack'` — only those whose source map was
|
|
36
|
+
* declared but missing locally, i.e. the frames bound for server-side
|
|
37
|
+
* unminification. The Datadog backend performs the `column << 32 | line`
|
|
38
|
+
* packing itself (for Node.js profiles) when it consumes the column field.
|
|
39
|
+
* Requires pprof-format >= 2.3.0, the version that added `Line.column`.
|
|
40
|
+
*/
|
|
41
|
+
export type ColumnNumbers = 'drop' | 'pack' | 'emit';
|
|
42
|
+
export declare const DEFAULT_COLUMN_NUMBERS: ColumnNumbers;
|
|
21
43
|
export declare function computeTotalHitCount(root: TimeProfileNode): number;
|
|
22
44
|
/**
|
|
23
45
|
* Converts v8 time profile into into a profile proto.
|
|
@@ -26,7 +48,7 @@ export declare function computeTotalHitCount(root: TimeProfileNode): number;
|
|
|
26
48
|
* @param prof - profile to be converted.
|
|
27
49
|
* @param intervalMicros - average time (microseconds) between samples.
|
|
28
50
|
*/
|
|
29
|
-
export declare function serializeTimeProfile(prof: TimeProfile, intervalMicros: number, sourceMapper?: SourceMapper, recomputeSamplingInterval?: boolean, generateLabels?: GenerateTimeLabelsFunction, lowCardinalityLabels?: string[]): Profile;
|
|
51
|
+
export declare function serializeTimeProfile(prof: TimeProfile, intervalMicros: number, sourceMapper?: SourceMapper, recomputeSamplingInterval?: boolean, generateLabels?: GenerateTimeLabelsFunction, lowCardinalityLabels?: string[], columnNumbers?: ColumnNumbers): Profile;
|
|
30
52
|
/**
|
|
31
53
|
* Converts v8 heap profile into into a profile proto.
|
|
32
54
|
* (https://github.com/google/pprof/blob/master/proto/profile.proto)
|
|
@@ -37,4 +59,4 @@ export declare function serializeTimeProfile(prof: TimeProfile, intervalMicros:
|
|
|
37
59
|
* nanoseconds.
|
|
38
60
|
* @param intervalBytes - bytes allocated between samples.
|
|
39
61
|
*/
|
|
40
|
-
export declare function serializeHeapProfile(prof: AllocationProfileNode, startTimeNanos: number, intervalBytes: number, ignoreSamplesPath?: string, sourceMapper?: SourceMapper, generateLabels?: GenerateAllocationLabelsFunction): Profile;
|
|
62
|
+
export declare function serializeHeapProfile(prof: AllocationProfileNode | AllocationProfileNodeWithStats, startTimeNanos: number, intervalBytes: number, ignoreSamplesPath?: string, sourceMapper?: SourceMapper, generateLabels?: GenerateAllocationLabelsFunction, allocations?: boolean, columnNumbers?: ColumnNumbers): Profile;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.GARBAGE_COLLECTION_FUNCTION_NAME = exports.NON_JS_THREADS_FUNCTION_NAME = void 0;
|
|
18
|
+
exports.DEFAULT_COLUMN_NUMBERS = exports.GARBAGE_COLLECTION_FUNCTION_NAME = exports.NON_JS_THREADS_FUNCTION_NAME = void 0;
|
|
19
19
|
exports.computeTotalHitCount = computeTotalHitCount;
|
|
20
20
|
exports.serializeTimeProfile = serializeTimeProfile;
|
|
21
21
|
exports.serializeHeapProfile = serializeHeapProfile;
|
|
@@ -27,6 +27,34 @@ function isGeneratedLocation(location) {
|
|
|
27
27
|
location.line !== undefined &&
|
|
28
28
|
location.line > 0);
|
|
29
29
|
}
|
|
30
|
+
exports.DEFAULT_COLUMN_NUMBERS = 'drop';
|
|
31
|
+
/**
|
|
32
|
+
* Packs a frame's line and column into the single value carried by the pprof
|
|
33
|
+
* Line.line field: the column in the high 32 bits, the line in the low 32 bits
|
|
34
|
+
* (matching the backend's JavaScriptProfileUnminifier.decodeLineAndColumn).
|
|
35
|
+
*
|
|
36
|
+
* BigInt is required: JavaScript's bitwise operators are 32-bit, so `column <<
|
|
37
|
+
* 32` on a plain number is a no-op that returns `column` unchanged. Computing
|
|
38
|
+
* the pack arithmetically as `column * 2**32 + line` instead loses integer
|
|
39
|
+
* precision once the column exceeds 2**21 (the product passes 2**53, Number's
|
|
40
|
+
* safe-integer limit) — and minified single-line bundles routinely have columns
|
|
41
|
+
* that large.
|
|
42
|
+
*/
|
|
43
|
+
function packLineAndColumn(line, column) {
|
|
44
|
+
if (!line) {
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
if (!column) {
|
|
48
|
+
return line;
|
|
49
|
+
}
|
|
50
|
+
return (BigInt(column) << 32n) | BigInt(line);
|
|
51
|
+
}
|
|
52
|
+
function requireAllocationStat(value, field) {
|
|
53
|
+
if (value === undefined) {
|
|
54
|
+
throw new Error(`Allocation profile is missing ${field}.`);
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
30
58
|
/**
|
|
31
59
|
* Takes v8 profile and populates sample, location, and function fields of
|
|
32
60
|
* profile.proto.
|
|
@@ -39,12 +67,14 @@ function isGeneratedLocation(location) {
|
|
|
39
67
|
* appends these to end of an array of samples.
|
|
40
68
|
* @param stringTable - string table for the existing profile.
|
|
41
69
|
*/
|
|
42
|
-
function serialize(profile, root, appendToSamples, stringTable, ignoreSamplesPath, sourceMapper) {
|
|
70
|
+
function serialize(profile, root, appendToSamples, stringTable, ignoreSamplesPath, sourceMapper, columnNumbers = exports.DEFAULT_COLUMN_NUMBERS) {
|
|
43
71
|
const samples = [];
|
|
44
72
|
const locations = [];
|
|
45
73
|
const functions = [];
|
|
46
74
|
const functionIdMap = new Map();
|
|
47
75
|
const locationIdMap = new Map();
|
|
76
|
+
const packColumns = columnNumbers === 'pack';
|
|
77
|
+
const emitColumns = columnNumbers === 'emit';
|
|
48
78
|
let hasMissingMapFiles = false;
|
|
49
79
|
const entries = root.children.map((n) => ({
|
|
50
80
|
node: n,
|
|
@@ -104,9 +134,22 @@ function serialize(profile, root, appendToSamples, stringTable, ignoreSamplesPat
|
|
|
104
134
|
return location;
|
|
105
135
|
}
|
|
106
136
|
function getLine(loc, scriptId) {
|
|
137
|
+
// Both 'pack' and 'emit' carry the column only for frames whose source map
|
|
138
|
+
// was declared but missing locally — i.e. exactly the frames bound for
|
|
139
|
+
// server-side unminification (the same condition that sets
|
|
140
|
+
// dd:has-missing-map-files). Locally-resolved frames keep a plain line and
|
|
141
|
+
// no column, so column data never reaches profiles that skip server-side
|
|
142
|
+
// unminification.
|
|
143
|
+
const carryColumn = loc.missingMapFile === true;
|
|
107
144
|
return new pprof_format_1.Line({
|
|
108
145
|
functionId: getFunction(loc, scriptId).id,
|
|
109
|
-
line
|
|
146
|
+
// 'pack' encodes the column into the high 32 bits of the line field.
|
|
147
|
+
line: packColumns && carryColumn
|
|
148
|
+
? packLineAndColumn(loc.line, loc.column)
|
|
149
|
+
: loc.line,
|
|
150
|
+
// 'emit' records the column in the dedicated pprof Line.column field
|
|
151
|
+
// instead; the backend does the line/column packing itself.
|
|
152
|
+
column: emitColumns && carryColumn ? loc.column : undefined,
|
|
110
153
|
});
|
|
111
154
|
}
|
|
112
155
|
function getFunction(loc, scriptId) {
|
|
@@ -175,23 +218,27 @@ function createCpuValueType(table) {
|
|
|
175
218
|
unit: table.dedup('nanoseconds'),
|
|
176
219
|
});
|
|
177
220
|
}
|
|
178
|
-
|
|
179
|
-
* @return value type for object counts (type:objects, units:count), and
|
|
180
|
-
* adds strings used in this value type to the table.
|
|
181
|
-
*/
|
|
182
|
-
function createObjectCountValueType(table) {
|
|
221
|
+
function createInUseObjectCountValueType(table) {
|
|
183
222
|
return new pprof_format_1.ValueType({
|
|
184
|
-
type: table.dedup('
|
|
223
|
+
type: table.dedup('inuse_objects'),
|
|
185
224
|
unit: table.dedup('count'),
|
|
186
225
|
});
|
|
187
226
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
227
|
+
function createAllocatedObjectCountValueType(table) {
|
|
228
|
+
return new pprof_format_1.ValueType({
|
|
229
|
+
type: table.dedup('alloc_objects'),
|
|
230
|
+
unit: table.dedup('count'),
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function createInUseSpaceValueType(table) {
|
|
193
234
|
return new pprof_format_1.ValueType({
|
|
194
|
-
type: table.dedup('
|
|
235
|
+
type: table.dedup('inuse_space'),
|
|
236
|
+
unit: table.dedup('bytes'),
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function createAllocatedSpaceValueType(table) {
|
|
240
|
+
return new pprof_format_1.ValueType({
|
|
241
|
+
type: table.dedup('alloc_space'),
|
|
195
242
|
unit: table.dedup('bytes'),
|
|
196
243
|
});
|
|
197
244
|
}
|
|
@@ -277,7 +324,7 @@ function updateTimeProfile(prof) {
|
|
|
277
324
|
* @param prof - profile to be converted.
|
|
278
325
|
* @param intervalMicros - average time (microseconds) between samples.
|
|
279
326
|
*/
|
|
280
|
-
function serializeTimeProfile(prof, intervalMicros, sourceMapper, recomputeSamplingInterval = false, generateLabels, lowCardinalityLabels = []) {
|
|
327
|
+
function serializeTimeProfile(prof, intervalMicros, sourceMapper, recomputeSamplingInterval = false, generateLabels, lowCardinalityLabels = [], columnNumbers = exports.DEFAULT_COLUMN_NUMBERS) {
|
|
281
328
|
// If requested, recompute sampling interval from profile duration and total number of hits,
|
|
282
329
|
// since profile duration should be #hits x interval.
|
|
283
330
|
// Recomputing an average interval is more accurate, since in practice intervals between
|
|
@@ -375,7 +422,7 @@ function serializeTimeProfile(prof, intervalMicros, sourceMapper, recomputeSampl
|
|
|
375
422
|
period: intervalNanos,
|
|
376
423
|
};
|
|
377
424
|
const updatedProf = updateTimeProfile(prof);
|
|
378
|
-
serialize(profile, updatedProf.topDownRoot, appendTimeEntryToSamples, stringTable, undefined, sourceMapper);
|
|
425
|
+
serialize(profile, updatedProf.topDownRoot, appendTimeEntryToSamples, stringTable, undefined, sourceMapper, columnNumbers);
|
|
379
426
|
return new pprof_format_1.Profile(profile);
|
|
380
427
|
}
|
|
381
428
|
function buildLabels(labelSet, stringTable) {
|
|
@@ -409,16 +456,36 @@ function buildLabels(labelSet, stringTable) {
|
|
|
409
456
|
* nanoseconds.
|
|
410
457
|
* @param intervalBytes - bytes allocated between samples.
|
|
411
458
|
*/
|
|
412
|
-
function serializeHeapProfile(prof, startTimeNanos, intervalBytes, ignoreSamplesPath, sourceMapper, generateLabels) {
|
|
459
|
+
function serializeHeapProfile(prof, startTimeNanos, intervalBytes, ignoreSamplesPath, sourceMapper, generateLabels, allocations = false, columnNumbers = exports.DEFAULT_COLUMN_NUMBERS) {
|
|
413
460
|
const appendHeapEntryToSamples = (entry, samples) => {
|
|
414
461
|
if (entry.node.allocations.length > 0) {
|
|
415
462
|
const labels = generateLabels
|
|
416
463
|
? buildLabels(generateLabels({ node: entry.node }), stringTable)
|
|
417
464
|
: [];
|
|
418
465
|
for (const alloc of entry.node.allocations) {
|
|
466
|
+
// Live heap only
|
|
467
|
+
if (!allocations) {
|
|
468
|
+
const heapAllocation = alloc;
|
|
469
|
+
const sample = new pprof_format_1.Sample({
|
|
470
|
+
locationId: entry.stack,
|
|
471
|
+
value: [
|
|
472
|
+
heapAllocation.count,
|
|
473
|
+
heapAllocation.sizeBytes * heapAllocation.count,
|
|
474
|
+
],
|
|
475
|
+
label: labels,
|
|
476
|
+
// TODO: add tag for allocation size
|
|
477
|
+
});
|
|
478
|
+
samples.push(sample);
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
const stats = alloc;
|
|
482
|
+
const inuseObjects = requireAllocationStat(stats.inuseObjects, 'inuseObjects');
|
|
483
|
+
const inuseSpaceBytes = requireAllocationStat(stats.inuseSpaceBytes, 'inuseSpaceBytes');
|
|
484
|
+
const allocObjects = requireAllocationStat(stats.allocObjects, 'allocObjects');
|
|
485
|
+
const allocSpaceBytes = requireAllocationStat(stats.allocSpaceBytes, 'allocSpaceBytes');
|
|
419
486
|
const sample = new pprof_format_1.Sample({
|
|
420
487
|
locationId: entry.stack,
|
|
421
|
-
value: [
|
|
488
|
+
value: [inuseObjects, allocObjects, inuseSpaceBytes, allocSpaceBytes],
|
|
422
489
|
label: labels,
|
|
423
490
|
// TODO: add tag for allocation size
|
|
424
491
|
});
|
|
@@ -427,15 +494,24 @@ function serializeHeapProfile(prof, startTimeNanos, intervalBytes, ignoreSamples
|
|
|
427
494
|
}
|
|
428
495
|
};
|
|
429
496
|
const stringTable = new pprof_format_1.StringTable();
|
|
430
|
-
const
|
|
431
|
-
|
|
497
|
+
const sampleTypes = allocations
|
|
498
|
+
? [
|
|
499
|
+
createInUseObjectCountValueType(stringTable),
|
|
500
|
+
createAllocatedObjectCountValueType(stringTable),
|
|
501
|
+
createInUseSpaceValueType(stringTable),
|
|
502
|
+
createAllocatedSpaceValueType(stringTable),
|
|
503
|
+
]
|
|
504
|
+
: [
|
|
505
|
+
createInUseObjectCountValueType(stringTable),
|
|
506
|
+
createInUseSpaceValueType(stringTable),
|
|
507
|
+
];
|
|
432
508
|
const profile = {
|
|
433
|
-
sampleType:
|
|
509
|
+
sampleType: sampleTypes,
|
|
434
510
|
timeNanos: startTimeNanos,
|
|
435
|
-
periodType:
|
|
511
|
+
periodType: sampleTypes[sampleTypes.length - 1],
|
|
436
512
|
period: intervalBytes,
|
|
437
513
|
};
|
|
438
|
-
serialize(profile, prof, appendHeapEntryToSamples, stringTable, ignoreSamplesPath, sourceMapper);
|
|
514
|
+
serialize(profile, prof, appendHeapEntryToSamples, stringTable, ignoreSamplesPath, sourceMapper, columnNumbers);
|
|
439
515
|
return new pprof_format_1.Profile(profile);
|
|
440
516
|
}
|
|
441
517
|
//# sourceMappingURL=profile-serializer.js.map
|