@datadog/pprof 5.20.0 → 5.21.0

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.
Files changed (86) hide show
  1. package/out/src/heap-profiler-bindings.d.ts +1 -0
  2. package/out/src/heap-profiler-bindings.js +4 -0
  3. package/out/src/heap-profiler-bindings.js.map +1 -1
  4. package/out/src/heap-profiler.d.ts +13 -3
  5. package/out/src/heap-profiler.js +81 -50
  6. package/out/src/heap-profiler.js.map +1 -1
  7. package/out/src/index.d.ts +7 -1
  8. package/out/src/index.js +7 -1
  9. package/out/src/index.js.map +1 -1
  10. package/out/src/otel-serializer.d.ts +164 -0
  11. package/out/src/otel-serializer.js +431 -0
  12. package/out/src/otel-serializer.js.map +1 -0
  13. package/out/src/profile-normalizer.d.ts +182 -0
  14. package/out/src/profile-normalizer.js +425 -0
  15. package/out/src/profile-normalizer.js.map +1 -0
  16. package/out/src/profile-serializer.d.ts +37 -7
  17. package/out/src/profile-serializer.js +158 -399
  18. package/out/src/profile-serializer.js.map +1 -1
  19. package/out/src/time-profiler.d.ts +13 -2
  20. package/out/src/time-profiler.js +67 -18
  21. package/out/src/time-profiler.js.map +1 -1
  22. package/out/src/v8-types.d.ts +8 -2
  23. package/package.json +7 -7
  24. package/prebuilds/darwin-arm64/dd_pprof.node.abi108.node +0 -0
  25. package/prebuilds/darwin-arm64/dd_pprof.node.abi111.node +0 -0
  26. package/prebuilds/darwin-arm64/dd_pprof.node.abi115.node +0 -0
  27. package/prebuilds/darwin-arm64/dd_pprof.node.abi120.node +0 -0
  28. package/prebuilds/darwin-arm64/dd_pprof.node.abi127.node +0 -0
  29. package/prebuilds/darwin-arm64/dd_pprof.node.abi131.node +0 -0
  30. package/prebuilds/darwin-arm64/dd_pprof.node.abi137.node +0 -0
  31. package/prebuilds/darwin-arm64/dd_pprof.node.abi141.node +0 -0
  32. package/prebuilds/darwin-arm64/dd_pprof.node.abi147.node +0 -0
  33. package/prebuilds/darwin-x64/dd_pprof.node.abi108.node +0 -0
  34. package/prebuilds/darwin-x64/dd_pprof.node.abi111.node +0 -0
  35. package/prebuilds/darwin-x64/dd_pprof.node.abi115.node +0 -0
  36. package/prebuilds/darwin-x64/dd_pprof.node.abi120.node +0 -0
  37. package/prebuilds/darwin-x64/dd_pprof.node.abi127.node +0 -0
  38. package/prebuilds/darwin-x64/dd_pprof.node.abi131.node +0 -0
  39. package/prebuilds/darwin-x64/dd_pprof.node.abi137.node +0 -0
  40. package/prebuilds/darwin-x64/dd_pprof.node.abi141.node +0 -0
  41. package/prebuilds/darwin-x64/dd_pprof.node.abi147.node +0 -0
  42. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi108.node +0 -0
  43. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi111.node +0 -0
  44. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi115.node +0 -0
  45. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi120.node +0 -0
  46. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi127.node +0 -0
  47. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi131.node +0 -0
  48. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi137.node +0 -0
  49. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi141.node +0 -0
  50. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi147.node +0 -0
  51. package/prebuilds/linux-arm64/dd_pprof.node.abi108.node +0 -0
  52. package/prebuilds/linux-arm64/dd_pprof.node.abi111.node +0 -0
  53. package/prebuilds/linux-arm64/dd_pprof.node.abi115.node +0 -0
  54. package/prebuilds/linux-arm64/dd_pprof.node.abi120.node +0 -0
  55. package/prebuilds/linux-arm64/dd_pprof.node.abi127.node +0 -0
  56. package/prebuilds/linux-arm64/dd_pprof.node.abi131.node +0 -0
  57. package/prebuilds/linux-arm64/dd_pprof.node.abi137.node +0 -0
  58. package/prebuilds/linux-arm64/dd_pprof.node.abi141.node +0 -0
  59. package/prebuilds/linux-arm64/dd_pprof.node.abi147.node +0 -0
  60. package/prebuilds/linux-x64/dd_pprof.musl.node.abi108.node +0 -0
  61. package/prebuilds/linux-x64/dd_pprof.musl.node.abi111.node +0 -0
  62. package/prebuilds/linux-x64/dd_pprof.musl.node.abi115.node +0 -0
  63. package/prebuilds/linux-x64/dd_pprof.musl.node.abi120.node +0 -0
  64. package/prebuilds/linux-x64/dd_pprof.musl.node.abi127.node +0 -0
  65. package/prebuilds/linux-x64/dd_pprof.musl.node.abi131.node +0 -0
  66. package/prebuilds/linux-x64/dd_pprof.musl.node.abi137.node +0 -0
  67. package/prebuilds/linux-x64/dd_pprof.musl.node.abi141.node +0 -0
  68. package/prebuilds/linux-x64/dd_pprof.musl.node.abi147.node +0 -0
  69. package/prebuilds/linux-x64/dd_pprof.node.abi108.node +0 -0
  70. package/prebuilds/linux-x64/dd_pprof.node.abi111.node +0 -0
  71. package/prebuilds/linux-x64/dd_pprof.node.abi115.node +0 -0
  72. package/prebuilds/linux-x64/dd_pprof.node.abi120.node +0 -0
  73. package/prebuilds/linux-x64/dd_pprof.node.abi127.node +0 -0
  74. package/prebuilds/linux-x64/dd_pprof.node.abi131.node +0 -0
  75. package/prebuilds/linux-x64/dd_pprof.node.abi137.node +0 -0
  76. package/prebuilds/linux-x64/dd_pprof.node.abi141.node +0 -0
  77. package/prebuilds/linux-x64/dd_pprof.node.abi147.node +0 -0
  78. package/prebuilds/win32-x64/dd_pprof.node.abi108.node +0 -0
  79. package/prebuilds/win32-x64/dd_pprof.node.abi111.node +0 -0
  80. package/prebuilds/win32-x64/dd_pprof.node.abi115.node +0 -0
  81. package/prebuilds/win32-x64/dd_pprof.node.abi120.node +0 -0
  82. package/prebuilds/win32-x64/dd_pprof.node.abi127.node +0 -0
  83. package/prebuilds/win32-x64/dd_pprof.node.abi131.node +0 -0
  84. package/prebuilds/win32-x64/dd_pprof.node.abi137.node +0 -0
  85. package/prebuilds/win32-x64/dd_pprof.node.abi141.node +0 -0
  86. package/prebuilds/win32-x64/dd_pprof.node.abi147.node +0 -0
@@ -0,0 +1,425 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2026 Datadog. All Rights Reserved.
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.GARBAGE_COLLECTION_FUNCTION_NAME = exports.NON_JS_THREADS_FUNCTION_NAME = void 0;
19
+ exports.frameFunctionName = frameFunctionName;
20
+ exports.computeTotalHitCount = computeTotalHitCount;
21
+ exports.visitTimeProfile = visitTimeProfile;
22
+ exports.visitHeapProfile = visitHeapProfile;
23
+ exports.NON_JS_THREADS_FUNCTION_NAME = 'Non JS threads activity';
24
+ exports.GARBAGE_COLLECTION_FUNCTION_NAME = 'Garbage Collection';
25
+ function isGeneratedLocation(location) {
26
+ return (location.column !== undefined &&
27
+ location.line !== undefined &&
28
+ location.line > 0);
29
+ }
30
+ /**
31
+ * @returns the frame's function name, or a synthesized
32
+ * `(anonymous:L#line:C#column)` name for anonymous functions.
33
+ */
34
+ function frameFunctionName(frame) {
35
+ if (frame.name) {
36
+ return frame.name;
37
+ }
38
+ if (frame.line) {
39
+ if (frame.column) {
40
+ return `(anonymous:L#${frame.line}:C#${frame.column})`;
41
+ }
42
+ return `(anonymous:L#${frame.line})`;
43
+ }
44
+ return '(anonymous)';
45
+ }
46
+ function toSampleLabels(labelSet) {
47
+ const labels = [];
48
+ // A for...in loop doesn't allocate the entries array of Object.entries()
49
+ for (const key in labelSet) {
50
+ if (!Object.hasOwn(labelSet, key))
51
+ continue;
52
+ const value = labelSet[key];
53
+ switch (typeof value) {
54
+ case 'string':
55
+ case 'number':
56
+ case 'bigint':
57
+ labels.push([key, value]);
58
+ break;
59
+ }
60
+ }
61
+ return labels;
62
+ }
63
+ function requireAllocationStat(value, field) {
64
+ if (value === undefined) {
65
+ throw new Error(`Allocation profile is missing ${field}.`);
66
+ }
67
+ return value;
68
+ }
69
+ /**
70
+ * Walks the V8 profile tree depth first, delivering each distinct frame and
71
+ * stack, and the samples emitted for each node to the visitor.
72
+ *
73
+ * Stacks are interned by prefix: a node's stack is identified by its parent's
74
+ * stack and its own frame ID, so stacks with equal frames get the same ID
75
+ * without comparing whole arrays. A stack is only materialized and delivered
76
+ * to the visitor when its first sample is emitted.
77
+ */
78
+ function visitTree(root, visitor, emitSamples, ignoreSamplesPath, sourceMapper) {
79
+ // Frames, by internal frame index: the visitor's frame ID. Indexed by the
80
+ // raw position (before source mapping), so a repeated position skips
81
+ // source mapping, and by resolved identity, so different positions that
82
+ // resolve to the same frame share it.
83
+ const frameIndexByPosition = new Map();
84
+ const frameIndexByIdentity = new Map();
85
+ const frameIds = [];
86
+ let hasMissingMapFiles = false;
87
+ // Interned stacks, by internal stack index: the parent stack index (-1 for
88
+ // none), the internal frame index, the visitor's stack ID (undefined until
89
+ // delivered), and the child stacks by frame index. Top-level stacks are
90
+ // the children of rootStacks.
91
+ const stackParents = [];
92
+ const stackFrames = [];
93
+ const stackIds = [];
94
+ const stackChildren = [];
95
+ const rootStacks = new Map();
96
+ let currentStack = -1;
97
+ const emit = (values, labels, timestamp) => {
98
+ visitor.sample({
99
+ stackId: getStackId(currentStack),
100
+ values,
101
+ labels,
102
+ timestamp,
103
+ });
104
+ };
105
+ const entries = root.children.map((n) => ({
106
+ node: n,
107
+ parentStack: -1,
108
+ }));
109
+ while (entries.length > 0) {
110
+ const entry = entries.pop();
111
+ const node = entry.node;
112
+ // mjs files have a `file://` prefix in the scriptName -> remove it
113
+ const scriptName = node.scriptName.startsWith('file://')
114
+ ? node.scriptName.slice(7)
115
+ : node.scriptName;
116
+ if (ignoreSamplesPath && scriptName.indexOf(ignoreSamplesPath) > -1) {
117
+ continue;
118
+ }
119
+ const stack = internStack(entry.parentStack, getFrameIndex(node, scriptName));
120
+ currentStack = stack;
121
+ emitSamples(node, emit);
122
+ for (const child of node.children) {
123
+ entries.push({ node: child, parentStack: stack });
124
+ }
125
+ }
126
+ const result = { hasMissingMapFiles };
127
+ visitor.end?.(result);
128
+ return result;
129
+ function internStack(parent, frame) {
130
+ let children;
131
+ if (parent < 0) {
132
+ children = rootStacks;
133
+ }
134
+ else {
135
+ children = stackChildren[parent];
136
+ if (children === undefined) {
137
+ children = new Map();
138
+ stackChildren[parent] = children;
139
+ }
140
+ }
141
+ let stack = children.get(frame);
142
+ if (stack === undefined) {
143
+ stack = stackParents.length;
144
+ stackParents.push(parent);
145
+ stackFrames.push(frame);
146
+ stackIds.push(undefined);
147
+ stackChildren.push(undefined);
148
+ children.set(frame, stack);
149
+ }
150
+ return stack;
151
+ }
152
+ function getStackId(stack) {
153
+ let id = stackIds[stack];
154
+ if (id === undefined) {
155
+ const stackFrameIds = [];
156
+ for (let s = stack; s !== -1; s = stackParents[s]) {
157
+ stackFrameIds.push(frameIds[stackFrames[s]]);
158
+ }
159
+ id = visitor.stack(stackFrameIds);
160
+ stackIds[stack] = id;
161
+ }
162
+ return id;
163
+ }
164
+ function getFrameIndex(node, scriptName) {
165
+ // The script ID identifies a script in V8 profiles; without one, the
166
+ // script name has to. The name comes last, so the key is unambiguous.
167
+ const positionKey = node.scriptId !== undefined
168
+ ? `${node.scriptId}:${node.lineNumber}:${node.columnNumber}:${node.name}`
169
+ : `:${scriptName.length}:${scriptName}:${node.lineNumber}:${node.columnNumber}:${node.name}`;
170
+ let index = frameIndexByPosition.get(positionKey);
171
+ if (index === undefined) {
172
+ index = resolveFrameIndex(node, scriptName);
173
+ frameIndexByPosition.set(positionKey, index);
174
+ }
175
+ return index;
176
+ }
177
+ function resolveFrameIndex(node, scriptName) {
178
+ let loc = {
179
+ file: scriptName || '',
180
+ line: node.lineNumber,
181
+ column: node.columnNumber,
182
+ name: node.name,
183
+ };
184
+ let mapped = false;
185
+ if (loc.line) {
186
+ if (sourceMapper && isGeneratedLocation(loc)) {
187
+ loc = sourceMapper.mappingInfo(loc);
188
+ mapped = true;
189
+ if (loc.missingMapFile) {
190
+ hasMissingMapFiles = true;
191
+ }
192
+ }
193
+ }
194
+ const file = loc.file || '';
195
+ // An unmapped frame is identified by its position, which was just looked
196
+ // up. Source mapping can resolve different positions to the same frame,
197
+ // so a mapped frame needs to be looked up by its resolved identity. The
198
+ // resolved file is part of that: after source mapping, one script can map
199
+ // to several original files. The file's length makes the key unambiguous.
200
+ const keyStr = mapped
201
+ ? `${node.scriptId}:${loc.line}:${loc.column}:${loc.missingMapFile ? 1 : 0}:${file.length}:${file}:${loc.name}`
202
+ : undefined;
203
+ let index = keyStr === undefined ? undefined : frameIndexByIdentity.get(keyStr);
204
+ if (index === undefined) {
205
+ index = frameIds.length;
206
+ frameIds.push(visitor.frame({
207
+ name: loc.name,
208
+ file,
209
+ line: loc.line,
210
+ column: loc.column,
211
+ scriptId: node.scriptId,
212
+ missingMapFile: loc.missingMapFile === true,
213
+ }));
214
+ if (keyStr !== undefined)
215
+ frameIndexByIdentity.set(keyStr, index);
216
+ }
217
+ return index;
218
+ }
219
+ }
220
+ function computeTotalHitCount(root) {
221
+ return (root.hitCount +
222
+ root.children.reduce((sum, node) => sum + computeTotalHitCount(node), 0));
223
+ }
224
+ /** Perform some modifications on time profile:
225
+ * - Add non-JS thread activity node if available
226
+ * - remove `(program)` nodes
227
+ * - remove `(idle)` nodes with no context
228
+ * - set `(idle)` nodes' wall time to zero when they have a context
229
+ * - Convert `(garbage collector)` node to `Garbage Collection`
230
+ * - Put `non-JS thread activity` node and `Garbage Collection` under a top level `Node.js` node
231
+ * This function does not change the input profile.
232
+ */
233
+ function updateTimeProfile(prof) {
234
+ const newTopLevelChildren = [];
235
+ let runtimeNode;
236
+ function getRuntimeNode() {
237
+ if (!runtimeNode) {
238
+ runtimeNode = {
239
+ name: 'Node.js',
240
+ scriptName: '',
241
+ scriptId: 0,
242
+ lineNumber: 0,
243
+ columnNumber: 0,
244
+ children: [],
245
+ hitCount: 0,
246
+ };
247
+ newTopLevelChildren.push(runtimeNode);
248
+ }
249
+ return runtimeNode;
250
+ }
251
+ for (const child of prof.topDownRoot.children) {
252
+ if (child.name === '(program)') {
253
+ continue;
254
+ }
255
+ if (child.name === '(idle)' && child.contexts?.length === 0) {
256
+ continue;
257
+ }
258
+ if (child.name === '(garbage collector)') {
259
+ // Create a new node to avoid modifying the input one
260
+ const newChild = {
261
+ ...child,
262
+ name: exports.GARBAGE_COLLECTION_FUNCTION_NAME,
263
+ };
264
+ getRuntimeNode().children.push(newChild);
265
+ }
266
+ else {
267
+ newTopLevelChildren.push(child);
268
+ }
269
+ }
270
+ if (prof.hasCpuTime && prof.nonJSThreadsCpuTime) {
271
+ const node = {
272
+ name: exports.NON_JS_THREADS_FUNCTION_NAME,
273
+ scriptName: '',
274
+ scriptId: 0,
275
+ lineNumber: 0,
276
+ columnNumber: 0,
277
+ children: [],
278
+ hitCount: 0, // 0 because this should not be accounted for wall time
279
+ contexts: [
280
+ {
281
+ context: {},
282
+ timestamp: BigInt(0),
283
+ cpuTime: prof.nonJSThreadsCpuTime,
284
+ asyncId: -1,
285
+ },
286
+ ],
287
+ };
288
+ getRuntimeNode().children.push(node);
289
+ }
290
+ return {
291
+ ...prof,
292
+ topDownRoot: { ...prof.topDownRoot, children: newTopLevelChildren },
293
+ };
294
+ }
295
+ /**
296
+ * Normalizes a V8 time profile and passes it to the visitor.
297
+ *
298
+ * Sample values are [sample count, wall nanoseconds] plus CPU nanoseconds if
299
+ * the profile has CPU time.
300
+ */
301
+ function visitTimeProfile(prof, visitor, options) {
302
+ const { sourceMapper, recomputeSamplingInterval, generateLabels, samplePerContext, } = options;
303
+ let intervalMicros = options.intervalMicros;
304
+ // If requested, recompute sampling interval from profile duration and total number of hits,
305
+ // since profile duration should be #hits x interval.
306
+ // Recomputing an average interval is more accurate, since in practice intervals between
307
+ // samples are larger than the requested sampling interval (eg. 12.5ms vs 10ms requested).
308
+ // For very short durations, computation becomes meaningless (eg. if there is only one hit),
309
+ // therefore keep intervalMicros as a lower bound and 2 * intervalMicros as upper bound.
310
+ if (recomputeSamplingInterval) {
311
+ const totalHitCount = prof.totalHitCount ?? computeTotalHitCount(prof.topDownRoot);
312
+ if (totalHitCount > 0) {
313
+ intervalMicros = Math.min(Math.max(Math.floor((prof.endTime - prof.startTime) / totalHitCount), intervalMicros), 2 * intervalMicros);
314
+ }
315
+ }
316
+ const intervalNanos = intervalMicros * 1000;
317
+ const timeType = { type: 'wall', unit: 'nanoseconds' };
318
+ const sampleTypes = [{ type: 'sample', unit: 'count' }, timeType];
319
+ if (prof.hasCpuTime) {
320
+ sampleTypes.push({ type: 'cpu', unit: 'nanoseconds' });
321
+ }
322
+ const timeNanos = BigInt(Date.now()) * 1000000n;
323
+ const durationNanos = (prof.endTime - prof.startTime) * 1000;
324
+ visitor.metadata({
325
+ sampleTypes,
326
+ timeNanos,
327
+ // Exact with the native profiler's epoch offset. Without one, estimate it
328
+ // on the assumption that the profile was just stopped.
329
+ startTimeNanos: prof.epochOffset !== undefined
330
+ ? BigInt(Math.round(prof.startTime + prof.epochOffset)) * 1000n
331
+ : timeNanos - BigInt(Math.round(durationNanos)),
332
+ durationNanos,
333
+ periodType: timeType,
334
+ period: intervalNanos,
335
+ });
336
+ const emitTimeSamples = (node, emit) => {
337
+ let unlabelledHits = node.hitCount;
338
+ let unlabelledCpuTime = 0;
339
+ const isIdle = node.name === '(idle)';
340
+ for (const context of node.contexts || []) {
341
+ const labels = toSampleLabels(generateLabels
342
+ ? generateLabels({ node, context })
343
+ : (context.context ?? {}));
344
+ if (labels.length > 0 || samplePerContext) {
345
+ // Only assign wall time if there are hits, some special nodes such as `(Non-JS threads)`
346
+ // have zero hit count (since they do not count as wall time) and should not be assigned any
347
+ // wall time. Also, `(idle)` nodes should be assigned zero wall time.
348
+ const values = unlabelledHits > 0 ? [1, isIdle ? 0 : intervalNanos] : [0, 0];
349
+ if (prof.hasCpuTime) {
350
+ values.push(context.cpuTime ?? 0);
351
+ }
352
+ // Context timestamps are in microseconds; 0 marks a synthetic context.
353
+ emit(values, labels, context.timestamp ? BigInt(context.timestamp) * 1000n : undefined);
354
+ unlabelledHits--;
355
+ }
356
+ else if (prof.hasCpuTime) {
357
+ unlabelledCpuTime += context.cpuTime ?? 0;
358
+ }
359
+ }
360
+ if ((!isIdle && unlabelledHits > 0) || unlabelledCpuTime > 0) {
361
+ const labels = generateLabels ? generateLabels({ node }) : {};
362
+ const values = unlabelledHits > 0
363
+ ? [unlabelledHits, isIdle ? 0 : unlabelledHits * intervalNanos]
364
+ : [0, 0];
365
+ if (prof.hasCpuTime) {
366
+ values.push(unlabelledCpuTime);
367
+ }
368
+ emit(values, toSampleLabels(labels));
369
+ }
370
+ };
371
+ return visitTree(updateTimeProfile(prof).topDownRoot, visitor, emitTimeSamples, undefined, sourceMapper);
372
+ }
373
+ /**
374
+ * Normalizes a V8 heap profile and passes it to the visitor.
375
+ *
376
+ * Sample values are [inuse objects, inuse bytes], or [inuse objects, alloc
377
+ * objects, inuse bytes, alloc bytes] in allocation mode.
378
+ */
379
+ function visitHeapProfile(prof, visitor, options) {
380
+ const { ignoreSamplesPath, sourceMapper, generateLabels, allocations } = options;
381
+ const sampleTypes = allocations
382
+ ? [
383
+ { type: 'inuse_objects', unit: 'count' },
384
+ { type: 'alloc_objects', unit: 'count' },
385
+ { type: 'inuse_space', unit: 'bytes' },
386
+ { type: 'alloc_space', unit: 'bytes' },
387
+ ]
388
+ : [
389
+ { type: 'inuse_objects', unit: 'count' },
390
+ { type: 'inuse_space', unit: 'bytes' },
391
+ ];
392
+ visitor.metadata({
393
+ sampleTypes,
394
+ timeNanos: options.startTimeNanos,
395
+ periodType: sampleTypes[sampleTypes.length - 1],
396
+ period: options.intervalBytes,
397
+ });
398
+ const emitHeapSamples = (node, emit) => {
399
+ if (node.allocations.length === 0) {
400
+ return;
401
+ }
402
+ const labels = generateLabels
403
+ ? toSampleLabels(generateLabels({ node: node }))
404
+ : [];
405
+ for (const alloc of node.allocations) {
406
+ // Live heap only
407
+ if (!allocations) {
408
+ const heapAllocation = alloc;
409
+ emit([
410
+ heapAllocation.count,
411
+ heapAllocation.sizeBytes * heapAllocation.count,
412
+ ], labels);
413
+ continue;
414
+ }
415
+ const stats = alloc;
416
+ const inuseObjects = requireAllocationStat(stats.inuseObjects, 'inuseObjects');
417
+ const inuseSpaceBytes = requireAllocationStat(stats.inuseSpaceBytes, 'inuseSpaceBytes');
418
+ const allocObjects = requireAllocationStat(stats.allocObjects, 'allocObjects');
419
+ const allocSpaceBytes = requireAllocationStat(stats.allocSpaceBytes, 'allocSpaceBytes');
420
+ emit([inuseObjects, allocObjects, inuseSpaceBytes, allocSpaceBytes], labels);
421
+ }
422
+ };
423
+ return visitTree(prof, visitor, emitHeapSamples, ignoreSamplesPath, sourceMapper);
424
+ }
425
+ //# sourceMappingURL=profile-normalizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile-normalizer.js","sourceRoot":"","sources":["../../ts/src/profile-normalizer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAqNH,8CAWC;AA2MD,oDAQC;AAmFD,4CA2GC;AAQD,4CAqFC;AA/qBY,QAAA,4BAA4B,GAAG,yBAAyB,CAAC;AACzD,QAAA,gCAAgC,GAAG,oBAAoB,CAAC;AAuKrE,SAAS,mBAAmB,CAC1B,QAAwB;IAExB,OAAO,CACL,QAAQ,CAAC,MAAM,KAAK,SAAS;QAC7B,QAAQ,CAAC,IAAI,KAAK,SAAS;QAC3B,QAAQ,CAAC,IAAI,GAAG,CAAC,CAClB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,KAAY;IAC5C,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC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CAAC;YACrC,iBAAiB;YACjB,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,MAAM,cAAc,GAAG,KAAmB,CAAC;gBAC3C,IAAI,CACF;oBACE,cAAc,CAAC,KAAK;oBACpB,cAAc,CAAC,SAAS,GAAG,cAAc,CAAC,KAAK;iBAChD,EACD,MAAM,CAEP,CAAC;gBACF,SAAS;YACX,CAAC;YAED,MAAM,KAAK,GAAG,KAA4B,CAAC;YAC3C,MAAM,YAAY,GAAG,qBAAqB,CACxC,KAAK,CAAC,YAAY,EAClB,cAAc,CACf,CAAC;YACF,MAAM,eAAe,GAAG,qBAAqB,CAC3C,KAAK,CAAC,eAAe,EACrB,iBAAiB,CAClB,CAAC;YACF,MAAM,YAAY,GAAG,qBAAqB,CACxC,KAAK,CAAC,YAAY,EAClB,cAAc,CACf,CAAC;YACF,MAAM,eAAe,GAAG,qBAAqB,CAC3C,KAAK,CAAC,eAAe,EACrB,iBAAiB,CAClB,CAAC;YACF,IAAI,CACF,CAAC,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe,CAAC,EAC9D,MAAM,CAEP,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,SAAS,CACd,IAAI,EACJ,OAAO,EACP,eAAe,EACf,iBAAiB,EACjB,YAAY,CACb,CAAC;AACJ,CAAC"}
@@ -14,10 +14,10 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { Profile } from 'pprof-format';
17
+ import { ProfileVisitor } from './profile-normalizer';
17
18
  import { SourceMapper } from './sourcemapper/sourcemapper';
18
- import { AllocationProfileNode, AllocationProfileNodeWithStats, GenerateAllocationLabelsFunction, GenerateTimeLabelsFunction, TimeProfile, TimeProfileNode } from './v8-types';
19
- export declare const NON_JS_THREADS_FUNCTION_NAME = "Non JS threads activity";
20
- export declare const GARBAGE_COLLECTION_FUNCTION_NAME = "Garbage Collection";
19
+ import { AllocationProfileNode, AllocationProfileNodeWithStats, GenerateAllocationLabelsFunction, GenerateTimeLabelsFunction, TimeProfile } from './v8-types';
20
+ export { computeTotalHitCount, GARBAGE_COLLECTION_FUNCTION_NAME, NON_JS_THREADS_FUNCTION_NAME, } from './profile-normalizer';
21
21
  /**
22
22
  * Controls how a frame's column number is represented in the emitted profile.
23
23
  * - `'drop'`: omit the column; only the line number is emitted. This is the
@@ -40,7 +40,39 @@ export declare const GARBAGE_COLLECTION_FUNCTION_NAME = "Garbage Collection";
40
40
  */
41
41
  export type ColumnNumbers = 'drop' | 'pack' | 'emit';
42
42
  export declare const DEFAULT_COLUMN_NUMBERS: ColumnNumbers;
43
- export declare function computeTotalHitCount(root: TimeProfileNode): number;
43
+ export interface PprofSerializerOptions {
44
+ /**
45
+ * Keys of labels with few distinct values, whose Label objects are shared
46
+ * between samples to save memory.
47
+ */
48
+ lowCardinalityLabels?: string[];
49
+ /** How frame columns are encoded. */
50
+ columnNumbers?: ColumnNumbers;
51
+ /**
52
+ * Name of a numeric label that receives each sample's timestamp, in
53
+ * nanoseconds since the epoch, e.g. `end_timestamp_ns`. pprof samples have no
54
+ * timestamps, so without it they are not encoded.
55
+ */
56
+ timestampLabel?: string;
57
+ }
58
+ /**
59
+ * Builds a pprof profile from one normalized profile, delivered to the
60
+ * visitor from visitor(): by the normalizer, or by a profiler emitting
61
+ * samples itself. pprof samples have no timestamps, so sample timestamps are
62
+ * encoded as a label if the options name one, and not at all otherwise.
63
+ *
64
+ * The visit runs synchronously; call build() after it ends.
65
+ */
66
+ export declare class PprofProfileBuilder {
67
+ private readonly profileVisitor;
68
+ private readonly buildProfile;
69
+ private visited;
70
+ constructor(options?: PprofSerializerOptions);
71
+ /** Returns the visitor for the profile. A builder takes a single visit. */
72
+ visitor(): ProfileVisitor;
73
+ /** Builds the profile from the visit. */
74
+ build(): Profile;
75
+ }
44
76
  /**
45
77
  * Converts v8 time profile into into a profile proto.
46
78
  * (https://github.com/google/pprof/blob/master/proto/profile.proto)
@@ -55,8 +87,6 @@ export declare function serializeTimeProfile(prof: TimeProfile, intervalMicros:
55
87
  *
56
88
  * @param prof - profile to be converted.
57
89
  * @param startTimeNanos - start time of profile, in nanoseconds (POSIX time).
58
- * @param durationsNanos - duration of the profile (wall clock time) in
59
- * nanoseconds.
60
90
  * @param intervalBytes - bytes allocated between samples.
61
91
  */
62
- export declare function serializeHeapProfile(prof: AllocationProfileNode | AllocationProfileNodeWithStats, startTimeNanos: number, intervalBytes: number, ignoreSamplesPath?: string, sourceMapper?: SourceMapper, generateLabels?: GenerateAllocationLabelsFunction, allocations?: boolean, columnNumbers?: ColumnNumbers): Profile;
92
+ export declare function serializeHeapProfile(prof: AllocationProfileNode | AllocationProfileNodeWithStats, startTimeNanos: number | bigint, intervalBytes: number, ignoreSamplesPath?: string, sourceMapper?: SourceMapper, generateLabels?: GenerateAllocationLabelsFunction, allocations?: boolean, columnNumbers?: ColumnNumbers): Profile;