@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
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import { AllocationProfileNode, AllocationProfileNodeWithStats } from './v8-types';
17
17
  export declare function startSamplingHeapProfiler(heapIntervalBytes: number, heapStackDepth: number, allocations?: boolean): void;
18
+ export declare function restartSamplingHeapProfiler(heapIntervalBytes: number, heapStackDepth: number, allocations: boolean): void;
18
19
  export declare function stopSamplingHeapProfiler(): void;
19
20
  export declare function getAllocationProfile(): AllocationProfileNode | AllocationProfileNodeWithStats;
20
21
  export declare function mapAllocationProfile<T>(callback: (root: AllocationProfileNode) => T): T;
@@ -49,6 +49,7 @@ var __importStar = (this && this.__importStar) || (function () {
49
49
  })();
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
51
  exports.startSamplingHeapProfiler = startSamplingHeapProfiler;
52
+ exports.restartSamplingHeapProfiler = restartSamplingHeapProfiler;
52
53
  exports.stopSamplingHeapProfiler = stopSamplingHeapProfiler;
53
54
  exports.getAllocationProfile = getAllocationProfile;
54
55
  exports.mapAllocationProfile = mapAllocationProfile;
@@ -60,6 +61,9 @@ const profiler = findBinding(path.join(__dirname, '..', '..'));
60
61
  function startSamplingHeapProfiler(heapIntervalBytes, heapStackDepth, allocations = false) {
61
62
  profiler.heapProfiler.startSamplingHeapProfiler(heapIntervalBytes, heapStackDepth, allocations);
62
63
  }
64
+ function restartSamplingHeapProfiler(heapIntervalBytes, heapStackDepth, allocations) {
65
+ profiler.heapProfiler.restartSamplingHeapProfiler(heapIntervalBytes, heapStackDepth, allocations);
66
+ }
63
67
  function stopSamplingHeapProfiler() {
64
68
  profiler.heapProfiler.stopSamplingHeapProfiler();
65
69
  }
@@ -1 +1 @@
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;A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
+ import { CapturedProfile, HeapProfileNormalizerOptions } from './profile-normalizer';
18
19
  import { SourceMapper } from './sourcemapper/sourcemapper';
19
20
  import { AllocationProfileNode, AllocationProfileNodeWithStats, GenerateAllocationLabelsFunction } from './v8-types';
20
21
  export declare function v8Profile(): AllocationProfileNode | AllocationProfileNodeWithStats;
@@ -38,6 +39,16 @@ export declare function v8ProfileV2<T>(callback: (root: AllocationProfileNode) =
38
39
  * @param sourceMapper
39
40
  */
40
41
  export declare function profile(ignoreSamplePath?: string, sourceMapper?: SourceMapper, generateLabels?: GenerateAllocationLabelsFunction, columnNumbers?: ColumnNumbers): Profile;
42
+ /** Options of a heap profile's normalization, set when it is captured. */
43
+ export type HeapProfileCaptureOptions = Pick<HeapProfileNormalizerOptions, 'ignoreSamplesPath' | 'sourceMapper' | 'generateLabels'>;
44
+ /**
45
+ * Like profile(), but captures the profile to be visited later, instead of
46
+ * serializing it as pprof: see {@link CapturedProfile}. Collecting the profile
47
+ * from V8, and in allocation mode restarting sampling, happens now.
48
+ * `generateLabels` runs when the profile is visited. Throws if heap profiler
49
+ * is not enabled.
50
+ */
51
+ export declare function capture(options?: HeapProfileCaptureOptions): CapturedProfile;
41
52
  export declare function convertProfile(rootNode: AllocationProfileNode | AllocationProfileNodeWithStats, ignoreSamplePath?: string, sourceMapper?: SourceMapper, generateLabels?: GenerateAllocationLabelsFunction, columnNumbers?: ColumnNumbers): Profile;
42
53
  /**
43
54
  * Collects a profile and returns it serialized in pprof format using lazy V2 API.
@@ -56,9 +67,8 @@ export declare function profileV2(ignoreSamplePath?: string, sourceMapper?: Sour
56
67
  * @param intervalBytes - average number of bytes between samples.
57
68
  * @param stackDepth - maximum stack depth for samples collected.
58
69
  * @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.
70
+ * Retains samples of objects collected by GC. Liveness reflects the most
71
+ * recent GC; collecting a profile does not force one. Requires Node.js >= 26.
62
72
  */
63
73
  export declare function start(intervalBytes: number, stackDepth: number, allocations?: boolean): void;
64
74
  export declare function stop(): void;
@@ -19,6 +19,7 @@ exports.CallbackMode = void 0;
19
19
  exports.v8Profile = v8Profile;
20
20
  exports.v8ProfileV2 = v8ProfileV2;
21
21
  exports.profile = profile;
22
+ exports.capture = capture;
22
23
  exports.convertProfile = convertProfile;
23
24
  exports.profileV2 = profileV2;
24
25
  exports.start = start;
@@ -26,6 +27,7 @@ exports.stop = stop;
26
27
  exports.monitorOutOfMemory = monitorOutOfMemory;
27
28
  const heap_profiler_bindings_1 = require("./heap-profiler-bindings");
28
29
  const profile_serializer_1 = require("./profile-serializer");
30
+ const profile_normalizer_1 = require("./profile-normalizer");
29
31
  const worker_threads_1 = require("worker_threads");
30
32
  let enabled = false;
31
33
  let heapIntervalBytes = 0;
@@ -71,63 +73,93 @@ function v8ProfileV2(callback) {
71
73
  * @param sourceMapper
72
74
  */
73
75
  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);
76
+ return collectProfile(root => convertProfile(root, ignoreSamplePath, sourceMapper, generateLabels, columnNumbers));
77
+ }
78
+ /**
79
+ * Like profile(), but captures the profile to be visited later, instead of
80
+ * serializing it as pprof: see {@link CapturedProfile}. Collecting the profile
81
+ * from V8, and in allocation mode restarting sampling, happens now.
82
+ * `generateLabels` runs when the profile is visited. Throws if heap profiler
83
+ * is not enabled.
84
+ */
85
+ function capture(options = {}) {
86
+ return collectProfile(root => {
87
+ const profile = addExternalMemoryNode(root, startedWithAllocations);
88
+ const normalizerOptions = {
89
+ ...options,
90
+ startTimeNanos: BigInt(Date.now()) * 1000000n,
91
+ intervalBytes: heapIntervalBytes,
92
+ allocations: startedWithAllocations,
93
+ };
94
+ return {
95
+ visit: visitor => (0, profile_normalizer_1.visitHeapProfile)(profile, visitor, normalizerOptions),
96
+ };
97
+ });
98
+ }
99
+ function collectProfile(processProfile) {
100
+ const root = v8Profile();
101
+ try {
102
+ return processProfile(root);
103
+ }
104
+ finally {
105
+ // In allocation mode V8 keeps every sampled object (live + collected-by-GC)
106
+ // in an append-only buffer that's only freed by stopping V8 sampling.
107
+ // Without this reset, each call to getAllocationProfile re-reads the entire
108
+ // history, so alloc_* totals grow linearly with wall-clock time and V8's
109
+ // internal sample buffer leaks for the lifetime of the process. Reset even
110
+ // if processing throws: the collected window is consumed either way, so it
111
+ // isn't counted again by the next collection. Preserve OOM monitoring
112
+ // when starting the next sampling interval.
113
+ if (startedWithAllocations) {
114
+ (0, heap_profiler_bindings_1.restartSamplingHeapProfiler)(heapIntervalBytes, heapStackDepth, true);
115
+ }
83
116
  }
84
- return result;
85
117
  }
86
118
  function convertProfile(rootNode, ignoreSamplePath, sourceMapper, generateLabels, columnNumbers = profile_serializer_1.DEFAULT_COLUMN_NUMBERS) {
87
119
  const allocations = startedWithAllocations;
88
- const startTimeNanos = Date.now() * 1000 * 1000;
89
- // Add node for external memory usage.
120
+ const startTimeNanos = BigInt(Date.now()) * 1000000n;
121
+ return (0, profile_serializer_1.serializeHeapProfile)(addExternalMemoryNode(rootNode, allocations), startTimeNanos, heapIntervalBytes, ignoreSamplePath, sourceMapper, generateLabels, allocations, columnNumbers);
122
+ }
123
+ /**
124
+ * Returns the profile with a node for external memory usage added under the
125
+ * root, if there is any external memory. Does not modify the input.
126
+ */
127
+ function addExternalMemoryNode(rootNode, allocations) {
90
128
  // Current type definitions do not have external.
91
129
  // TODO: remove any once type definition is updated to include external.
92
130
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
131
  const { external } = process.memoryUsage();
94
- let root;
95
- if (external > 0) {
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
- }
132
+ if (external <= 0) {
133
+ return rootNode;
126
134
  }
127
- else {
128
- root = rootNode;
135
+ if (allocations) {
136
+ const externalNode = {
137
+ name: '(external)',
138
+ scriptName: '',
139
+ children: [],
140
+ allocations: [
141
+ {
142
+ inuseObjects: 1,
143
+ inuseSpaceBytes: external,
144
+ allocObjects: 1,
145
+ allocSpaceBytes: external,
146
+ },
147
+ ],
148
+ };
149
+ const allocationRoot = rootNode;
150
+ return {
151
+ ...allocationRoot,
152
+ children: [...allocationRoot.children, externalNode],
153
+ };
129
154
  }
130
- return (0, profile_serializer_1.serializeHeapProfile)(root, startTimeNanos, heapIntervalBytes, ignoreSamplePath, sourceMapper, generateLabels, allocations, columnNumbers);
155
+ const externalNode = {
156
+ name: '(external)',
157
+ scriptName: '',
158
+ children: [],
159
+ allocations: [{ sizeBytes: external, count: 1 }],
160
+ };
161
+ const heapRoot = rootNode;
162
+ return { ...heapRoot, children: [...heapRoot.children, externalNode] };
131
163
  }
132
164
  /**
133
165
  * Collects a profile and returns it serialized in pprof format using lazy V2 API.
@@ -150,9 +182,8 @@ function profileV2(ignoreSamplePath, sourceMapper, generateLabels, columnNumbers
150
182
  * @param intervalBytes - average number of bytes between samples.
151
183
  * @param stackDepth - maximum stack depth for samples collected.
152
184
  * @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.
185
+ * Retains samples of objects collected by GC. Liveness reflects the most
186
+ * recent GC; collecting a profile does not force one. Requires Node.js >= 26.
156
187
  */
157
188
  function start(intervalBytes, stackDepth, allocations = false) {
158
189
  if (enabled) {
@@ -1 +1 @@
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;IAE5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IACD,IAAI,sBAAsB,EAAE,CAAC;QAC3B,MAAM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O,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpC,WAAW,GAAG,CAAC,OAA8B,EAAE,EAAE;YAC/C,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;QACpC,CAAC,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,sBAAsB,KAAK,MAAM,CAAC;IACpD,IAAA,2CAA0B,EACxB,SAAS,CAAC,CAAC,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"}
@@ -2,7 +2,11 @@ import * as heapProfiler from './heap-profiler';
2
2
  import * as otelThreadCtxModule from './otel-thread-ctx';
3
3
  import * as timeProfiler from './time-profiler';
4
4
  export { AllocationProfileNode, TimeProfileNode, ProfileNode, LabelSet, } from './v8-types';
5
- export { HeapLimitExtensionSize } from './heap-profiler';
5
+ export { CapturedProfile, Frame, NormalizedSample, ProfileMetadata, ProfileVisitor, SampleLabel, SampleLabelValue, SampleType, VisitResult, } from './profile-normalizer';
6
+ export { ColumnNumbers, PprofProfileBuilder, PprofSerializerOptions, } from './profile-serializer';
7
+ export { LinkExtractor, OtelColumns, OtelProfileOptions, OtelProfilesBuilder, OtelSerializerOptions, ProfileAttribute, SampleLink, } from './otel-serializer';
8
+ export { HeapLimitExtensionSize, HeapProfileCaptureOptions, } from './heap-profiler';
9
+ export { TimeProfileCaptureOptions } from './time-profiler';
6
10
  export { encode, encodeSync } from './profile-encoder';
7
11
  export { SourceMapper } from './sourcemapper/sourcemapper';
8
12
  export { setLogger } from './logger';
@@ -11,6 +15,7 @@ export declare const time: {
11
15
  profile: typeof timeProfiler.profile;
12
16
  start: typeof timeProfiler.start;
13
17
  stop: typeof timeProfiler.stop;
18
+ stopAndCapture: typeof timeProfiler.stopAndCapture;
14
19
  profileV2: typeof timeProfiler.profileV2;
15
20
  getContext: typeof timeProfiler.getContext;
16
21
  setContext: typeof timeProfiler.setContext;
@@ -30,6 +35,7 @@ export declare const heap: {
30
35
  stop: typeof heapProfiler.stop;
31
36
  profile: typeof heapProfiler.profile;
32
37
  profileV2: typeof heapProfiler.profileV2;
38
+ capture: typeof heapProfiler.capture;
33
39
  convertProfile: typeof heapProfiler.convertProfile;
34
40
  v8Profile: typeof heapProfiler.v8Profile;
35
41
  monitorOutOfMemory: typeof heapProfiler.monitorOutOfMemory;
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.otelThreadCtx = 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 = exports.OtelProfilesBuilder = exports.PprofProfileBuilder = void 0;
37
37
  /**
38
38
  * Copyright 2019 Google Inc. All Rights Reserved.
39
39
  *
@@ -54,6 +54,10 @@ const heapProfiler = __importStar(require("./heap-profiler"));
54
54
  const otelThreadCtxModule = __importStar(require("./otel-thread-ctx"));
55
55
  const profile_encoder_1 = require("./profile-encoder");
56
56
  const timeProfiler = __importStar(require("./time-profiler"));
57
+ var profile_serializer_1 = require("./profile-serializer");
58
+ Object.defineProperty(exports, "PprofProfileBuilder", { enumerable: true, get: function () { return profile_serializer_1.PprofProfileBuilder; } });
59
+ var otel_serializer_1 = require("./otel-serializer");
60
+ Object.defineProperty(exports, "OtelProfilesBuilder", { enumerable: true, get: function () { return otel_serializer_1.OtelProfilesBuilder; } });
57
61
  var profile_encoder_2 = require("./profile-encoder");
58
62
  Object.defineProperty(exports, "encode", { enumerable: true, get: function () { return profile_encoder_2.encode; } });
59
63
  Object.defineProperty(exports, "encodeSync", { enumerable: true, get: function () { return profile_encoder_2.encodeSync; } });
@@ -67,6 +71,7 @@ exports.time = {
67
71
  profile: timeProfiler.profile,
68
72
  start: timeProfiler.start,
69
73
  stop: timeProfiler.stop,
74
+ stopAndCapture: timeProfiler.stopAndCapture,
70
75
  profileV2: timeProfiler.profileV2,
71
76
  getContext: timeProfiler.getContext,
72
77
  setContext: timeProfiler.setContext,
@@ -82,6 +87,7 @@ exports.heap = {
82
87
  stop: heapProfiler.stop,
83
88
  profile: heapProfiler.profile,
84
89
  profileV2: heapProfiler.profileV2,
90
+ capture: heapProfiler.capture,
85
91
  convertProfile: heapProfiler.convertProfile,
86
92
  v8Profile: heapProfiler.v8Profile,
87
93
  monitorOutOfMemory: heapProfiler.monitorOutOfMemory,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,2BAAiC;AAEjC,8DAAgD;AAChD,uEAAyD;AACzD,uDAA6C;AAC7C,8DAAgD;AAUhD,qDAAqD;AAA7C,yGAAA,MAAM,OAAA;AAAE,6GAAA,UAAU,OAAA;AAC1B,4DAAyD;AAAjD,4GAAA,YAAY,OAAA;AACpB,mCAAmC;AAA3B,mGAAA,SAAS,OAAA;AACjB,iDAAkD;AAA1C,kHAAA,iBAAiB,OAAA;AAEZ,QAAA,IAAI,GAAG;IAClB,OAAO,EAAE,YAAY,CAAC,OAAO;IAC7B,KAAK,EAAE,YAAY,CAAC,KAAK;IACzB,IAAI,EAAE,YAAY,CAAC,IAAI;IACvB,SAAS,EAAE,YAAY,CAAC,SAAS;IACjC,UAAU,EAAE,YAAY,CAAC,UAAU;IACnC,UAAU,EAAE,YAAY,CAAC,UAAU;IACnC,cAAc,EAAE,YAAY,CAAC,cAAc;IAC3C,SAAS,EAAE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AC,OAAO;IAC7B,cAAc,EAAE,YAAY,CAAC,cAAc;IAC3C,SAAS,EAAE,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,164 @@
1
+ /**
2
+ * Serializes normalized profiles as OpenTelemetry profiles, in an
3
+ * ExportProfilesServiceRequest of pprof-format/otel.
4
+ *
5
+ * The request has one profile per sample type, since an OTel profile has a
6
+ * single sample type, and all of them share one dictionary. A sample count
7
+ * is the exception when every sampling event is a single timestamped
8
+ * observation (time profiles normalized with samplePerContext): it is then
9
+ * folded into the profile of the period type, whose observations include
10
+ * every sampling event, even zero-valued ones such as idle samples' wall
11
+ * time. Otherwise the count keeps a profile of its own, so no count is lost.
12
+ *
13
+ * Samples with the same stack, attributes and link are merged into one, as
14
+ * the OTel format requires: timestamped samples accumulate a value and a
15
+ * timestamp per observation, and samples without a timestamp are summed into
16
+ * one value. Other zero values are left out of the profile of their sample
17
+ * type: e.g. zero CPU time, or the wall time of the synthetic non-JS threads
18
+ * sample.
19
+ *
20
+ * OtelProfilesBuilder collects several profiles, e.g. time and heap, into one
21
+ * request.
22
+ *
23
+ * Frames carry their columns. With the `missing-source-maps` column policy,
24
+ * only frames whose script declares a source map that can't be found locally
25
+ * do: the candidates for server-side unminification, which can then be told
26
+ * apart without attributes of their own, as with pprof's `emit` columns.
27
+ */
28
+ import { AnyValueInput, ExportProfilesServiceRequest, InstrumentationScopeInput, KeyValueInput } from 'pprof-format/otel';
29
+ import { ProfileVisitor, SampleType, SampleLabel } from './profile-normalizer';
30
+ /**
31
+ * Trace and span IDs that link a sample to a span. The builder copies them,
32
+ * and treats a link whose trace ID or span ID is all zeros, which is invalid,
33
+ * as no link.
34
+ */
35
+ export interface SampleLink {
36
+ /** 16 bytes. */
37
+ traceId: Uint8Array;
38
+ /** 8 bytes. */
39
+ spanId: Uint8Array;
40
+ }
41
+ /**
42
+ * Turns some of a sample's labels into a link to a span. Returns the link, if
43
+ * any, and the labels to keep as the sample's attributes.
44
+ */
45
+ export type LinkExtractor = (labels: SampleLabel[]) => {
46
+ link?: SampleLink;
47
+ labels: SampleLabel[];
48
+ };
49
+ /**
50
+ * Which frames carry their column: `all` of them, or only those whose script
51
+ * declares a source map that can't be found locally (`missing-source-maps`),
52
+ * the candidates for server-side unminification.
53
+ */
54
+ export type OtelColumns = 'all' | 'missing-source-maps';
55
+ export interface OtelSerializerOptions {
56
+ /** Attributes of the resource that produced the profile. */
57
+ resourceAttributes?: KeyValueInput[];
58
+ /** The instrumentation scope. Defaults to `@datadog/pprof`. */
59
+ scope?: InstrumentationScopeInput;
60
+ /** Without one, all labels become attributes. */
61
+ extractLink?: LinkExtractor;
62
+ /** Which frames carry their column. Defaults to `all`. */
63
+ columns?: OtelColumns;
64
+ /**
65
+ * Renames the sample types of profiles, e.g. to the names another profiler
66
+ * gives the same measures. It renames both the sample types and the period
67
+ * types of the OTel profiles, and nothing else about them changes. Without
68
+ * it, they keep the names of the normalized profile.
69
+ */
70
+ renameSampleType?: (sampleType: SampleType) => SampleType;
71
+ }
72
+ /**
73
+ * An attribute of a profile. The value can be structured, e.g. an
74
+ * `arrayValue` or a `kvlistValue`.
75
+ */
76
+ export interface ProfileAttribute {
77
+ key: string;
78
+ value: AnyValueInput;
79
+ }
80
+ /** Options for one profile added to an OtelProfilesBuilder. */
81
+ export interface OtelProfileOptions {
82
+ /**
83
+ * Attributes of each OTel profile that the visit adds. They are interned in
84
+ * the request's attribute table, so repeating them on several profiles costs
85
+ * an index each.
86
+ */
87
+ attributes?: ProfileAttribute[];
88
+ /**
89
+ * The profile in another format, set as the original payload of each OTel
90
+ * profile that the visit adds. The payload is not copied.
91
+ */
92
+ originalPayload?: {
93
+ format: string;
94
+ payload: Uint8Array;
95
+ };
96
+ }
97
+ /**
98
+ * Builds one ExportProfilesServiceRequest from any number of normalized
99
+ * profiles, which share the request's dictionary: e.g. the time and heap
100
+ * profiles of one collection cycle. Each profile is added through a visitor
101
+ * from visitor(), so that whatever drives the visit (the normalizer, or a
102
+ * profiler emitting samples itself) needs no knowledge of the OTel format.
103
+ *
104
+ * Functions, locations, stacks, attributes and links are deduplicated across
105
+ * all profiles, and each dictionary table starts with its zero value. A
106
+ * sample whose stack has no frames refers to the zero-value stack.
107
+ *
108
+ * All profiles of the request get the same time range, the union of their
109
+ * own: one collection cycle's profiles then cover the same period, even a heap
110
+ * profile, which is a snapshot at a single instant.
111
+ *
112
+ * Visitors run synchronously, and build() can be called after any number of
113
+ * completed visits. A visit's profiles are added to the request when it ends,
114
+ * so a visit that throws, or isn't ended, adds none: the builder can go on
115
+ * with other visits, and its request has their profiles only. (A failed
116
+ * visit can leave dictionary entries that no profile refers to.)
117
+ */
118
+ export declare class OtelProfilesBuilder {
119
+ private readonly options;
120
+ private readonly strings;
121
+ private readonly functionTable;
122
+ private readonly locationTable;
123
+ private readonly stackTable;
124
+ private readonly attributeTable;
125
+ private readonly linkTable;
126
+ private readonly functionIndices;
127
+ private readonly locationIndices;
128
+ private readonly stackIndices;
129
+ private readonly labelAttributeIndices;
130
+ private readonly profileAttributeIndices;
131
+ private readonly linkIndices;
132
+ private readonly profiles;
133
+ constructor(options?: OtelSerializerOptions);
134
+ /**
135
+ * Returns a visitor that adds one normalized profile to the request, as one
136
+ * OTel profile per sample type, when the visit ends: its end() must be
137
+ * called. Use a new visitor for each profile.
138
+ */
139
+ visitor(options?: OtelProfileOptions): ProfileVisitor;
140
+ /**
141
+ * Creates the OTel profiles for a normalized profile's sample types.
142
+ *
143
+ * A sample count type can be folded into the profile of the period type
144
+ * (wall time, for time profiles) instead of keeping a profile of its own:
145
+ * that profile gets an observation for every sampling event, even one whose
146
+ * value is zero, so the count is its number of observations. That keeps
147
+ * idle samples, which have zero wall time, as timestamped evidence that
148
+ * sampling happened, without repeating every sample in a count profile.
149
+ * The fold is only lossless if every sampling event is a single timestamped
150
+ * observation, so the count profile is built anyway, and dropped at the end
151
+ * of the visit only if that turned out to be the case.
152
+ */
153
+ private layout;
154
+ /** Builds the request from the profiles added so far. */
155
+ build(): ExportProfilesServiceRequest;
156
+ private addSample;
157
+ private valueType;
158
+ private functionIndex;
159
+ private locationIndex;
160
+ private stackIndex;
161
+ private attributeIndex;
162
+ private profileAttributeIndex;
163
+ private linkIndex;
164
+ }