@ohos-ports/datadog-pprof 5.17.0-1

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 (100) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +112 -0
  3. package/out/src/heap-profiler-bindings.d.ts +22 -0
  4. package/out/src/heap-profiler-bindings.js +75 -0
  5. package/out/src/heap-profiler-bindings.js.map +1 -0
  6. package/out/src/heap-profiler.d.ts +98 -0
  7. package/out/src/heap-profiler.js +219 -0
  8. package/out/src/heap-profiler.js.map +1 -0
  9. package/out/src/index.d.ts +46 -0
  10. package/out/src/index.js +111 -0
  11. package/out/src/index.js.map +1 -0
  12. package/out/src/logger.d.ts +18 -0
  13. package/out/src/logger.js +36 -0
  14. package/out/src/logger.js.map +1 -0
  15. package/out/src/otel-thread-ctx.d.ts +85 -0
  16. package/out/src/otel-thread-ctx.js +176 -0
  17. package/out/src/otel-thread-ctx.js.map +1 -0
  18. package/out/src/profile-encoder.d.ts +18 -0
  19. package/out/src/profile-encoder.js +29 -0
  20. package/out/src/profile-encoder.js.map +1 -0
  21. package/out/src/profile-serializer.d.ts +56 -0
  22. package/out/src/profile-serializer.js +509 -0
  23. package/out/src/profile-serializer.js.map +1 -0
  24. package/out/src/sourcemapper/sourcemapper.d.ts +123 -0
  25. package/out/src/sourcemapper/sourcemapper.js +528 -0
  26. package/out/src/sourcemapper/sourcemapper.js.map +1 -0
  27. package/out/src/time-profiler-bindings.d.ts +3 -0
  28. package/out/src/time-profiler-bindings.js +25 -0
  29. package/out/src/time-profiler-bindings.js.map +1 -0
  30. package/out/src/time-profiler.d.ts +72 -0
  31. package/out/src/time-profiler.js +202 -0
  32. package/out/src/time-profiler.js.map +1 -0
  33. package/out/src/v8-types.d.ts +82 -0
  34. package/out/src/v8-types.js +18 -0
  35. package/out/src/v8-types.js.map +1 -0
  36. package/package.json +112 -0
  37. package/prebuilds/darwin-arm64/dd_pprof.node.abi108.node +0 -0
  38. package/prebuilds/darwin-arm64/dd_pprof.node.abi111.node +0 -0
  39. package/prebuilds/darwin-arm64/dd_pprof.node.abi115.node +0 -0
  40. package/prebuilds/darwin-arm64/dd_pprof.node.abi120.node +0 -0
  41. package/prebuilds/darwin-arm64/dd_pprof.node.abi127.node +0 -0
  42. package/prebuilds/darwin-arm64/dd_pprof.node.abi131.node +0 -0
  43. package/prebuilds/darwin-arm64/dd_pprof.node.abi137.node +0 -0
  44. package/prebuilds/darwin-arm64/dd_pprof.node.abi141.node +0 -0
  45. package/prebuilds/darwin-arm64/dd_pprof.node.abi147.node +0 -0
  46. package/prebuilds/darwin-x64/dd_pprof.node.abi108.node +0 -0
  47. package/prebuilds/darwin-x64/dd_pprof.node.abi111.node +0 -0
  48. package/prebuilds/darwin-x64/dd_pprof.node.abi115.node +0 -0
  49. package/prebuilds/darwin-x64/dd_pprof.node.abi120.node +0 -0
  50. package/prebuilds/darwin-x64/dd_pprof.node.abi127.node +0 -0
  51. package/prebuilds/darwin-x64/dd_pprof.node.abi131.node +0 -0
  52. package/prebuilds/darwin-x64/dd_pprof.node.abi137.node +0 -0
  53. package/prebuilds/darwin-x64/dd_pprof.node.abi141.node +0 -0
  54. package/prebuilds/darwin-x64/dd_pprof.node.abi147.node +0 -0
  55. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi108.node +0 -0
  56. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi111.node +0 -0
  57. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi115.node +0 -0
  58. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi120.node +0 -0
  59. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi127.node +0 -0
  60. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi131.node +0 -0
  61. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi137.node +0 -0
  62. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi141.node +0 -0
  63. package/prebuilds/linux-arm64/dd_pprof.musl.node.abi147.node +0 -0
  64. package/prebuilds/linux-arm64/dd_pprof.node.abi108.node +0 -0
  65. package/prebuilds/linux-arm64/dd_pprof.node.abi111.node +0 -0
  66. package/prebuilds/linux-arm64/dd_pprof.node.abi115.node +0 -0
  67. package/prebuilds/linux-arm64/dd_pprof.node.abi120.node +0 -0
  68. package/prebuilds/linux-arm64/dd_pprof.node.abi127.node +0 -0
  69. package/prebuilds/linux-arm64/dd_pprof.node.abi131.node +0 -0
  70. package/prebuilds/linux-arm64/dd_pprof.node.abi137.node +0 -0
  71. package/prebuilds/linux-arm64/dd_pprof.node.abi141.node +0 -0
  72. package/prebuilds/linux-arm64/dd_pprof.node.abi147.node +0 -0
  73. package/prebuilds/linux-x64/dd_pprof.musl.node.abi108.node +0 -0
  74. package/prebuilds/linux-x64/dd_pprof.musl.node.abi111.node +0 -0
  75. package/prebuilds/linux-x64/dd_pprof.musl.node.abi115.node +0 -0
  76. package/prebuilds/linux-x64/dd_pprof.musl.node.abi120.node +0 -0
  77. package/prebuilds/linux-x64/dd_pprof.musl.node.abi127.node +0 -0
  78. package/prebuilds/linux-x64/dd_pprof.musl.node.abi131.node +0 -0
  79. package/prebuilds/linux-x64/dd_pprof.musl.node.abi137.node +0 -0
  80. package/prebuilds/linux-x64/dd_pprof.musl.node.abi141.node +0 -0
  81. package/prebuilds/linux-x64/dd_pprof.musl.node.abi147.node +0 -0
  82. package/prebuilds/linux-x64/dd_pprof.node.abi108.node +0 -0
  83. package/prebuilds/linux-x64/dd_pprof.node.abi111.node +0 -0
  84. package/prebuilds/linux-x64/dd_pprof.node.abi115.node +0 -0
  85. package/prebuilds/linux-x64/dd_pprof.node.abi120.node +0 -0
  86. package/prebuilds/linux-x64/dd_pprof.node.abi127.node +0 -0
  87. package/prebuilds/linux-x64/dd_pprof.node.abi131.node +0 -0
  88. package/prebuilds/linux-x64/dd_pprof.node.abi137.node +0 -0
  89. package/prebuilds/linux-x64/dd_pprof.node.abi141.node +0 -0
  90. package/prebuilds/linux-x64/dd_pprof.node.abi147.node +0 -0
  91. package/prebuilds/openharmony-arm64/dd_pprof.node.abi147.node +0 -0
  92. package/prebuilds/win32-x64/dd_pprof.node.abi108.node +0 -0
  93. package/prebuilds/win32-x64/dd_pprof.node.abi111.node +0 -0
  94. package/prebuilds/win32-x64/dd_pprof.node.abi115.node +0 -0
  95. package/prebuilds/win32-x64/dd_pprof.node.abi120.node +0 -0
  96. package/prebuilds/win32-x64/dd_pprof.node.abi127.node +0 -0
  97. package/prebuilds/win32-x64/dd_pprof.node.abi131.node +0 -0
  98. package/prebuilds/win32-x64/dd_pprof.node.abi137.node +0 -0
  99. package/prebuilds/win32-x64/dd_pprof.node.abi141.node +0 -0
  100. package/prebuilds/win32-x64/dd_pprof.node.abi147.node +0 -0
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2017 Google Inc. 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.CallbackMode = void 0;
19
+ exports.v8Profile = v8Profile;
20
+ exports.v8ProfileV2 = v8ProfileV2;
21
+ exports.profile = profile;
22
+ exports.convertProfile = convertProfile;
23
+ exports.profileV2 = profileV2;
24
+ exports.start = start;
25
+ exports.stop = stop;
26
+ exports.monitorOutOfMemory = monitorOutOfMemory;
27
+ const heap_profiler_bindings_1 = require("./heap-profiler-bindings");
28
+ const profile_serializer_1 = require("./profile-serializer");
29
+ const worker_threads_1 = require("worker_threads");
30
+ let enabled = false;
31
+ let heapIntervalBytes = 0;
32
+ let heapStackDepth = 0;
33
+ let startedWithAllocations = false;
34
+ /*
35
+ * Collects a heap profile when heapProfiler is enabled. Otherwise throws
36
+ * an error.
37
+ *
38
+ * Data is returned in V8 allocation profile format.
39
+ */
40
+ function v8Profile() {
41
+ if (!enabled) {
42
+ throw new Error('Heap profiler is not enabled.');
43
+ }
44
+ return (0, heap_profiler_bindings_1.getAllocationProfile)();
45
+ }
46
+ /**
47
+ * Map the heap profile to a converted profile using callback function when
48
+ * heapProfiler is enabled. Otherwise throws an error.
49
+ *
50
+ * WARNING: Nodes in the tree are only valid during the callback. Do not store
51
+ * references to them. The memory is freed when the callback returns.
52
+ *
53
+ * @param callback - function to convert the heap profile to a converted
54
+ |file
55
+ * @returns <T> converted profile
56
+ */
57
+ function v8ProfileV2(callback) {
58
+ if (!enabled) {
59
+ throw new Error('Heap profiler is not enabled.');
60
+ }
61
+ if (startedWithAllocations) {
62
+ throw new Error('profileV2 does not support allocation mode.');
63
+ }
64
+ return (0, heap_profiler_bindings_1.mapAllocationProfile)(callback);
65
+ }
66
+ /**
67
+ * Collects a profile and returns it serialized in pprof format.
68
+ * Throws if heap profiler is not enabled.
69
+ *
70
+ * @param ignoreSamplePath
71
+ * @param sourceMapper
72
+ */
73
+ function profile(ignoreSamplePath, sourceMapper, generateLabels, columnNumbers = profile_serializer_1.DEFAULT_COLUMN_NUMBERS) {
74
+ const result = convertProfile(v8Profile(), ignoreSamplePath, sourceMapper, generateLabels, columnNumbers);
75
+ // In allocation mode V8 keeps every sampled object (live + collected-by-GC)
76
+ // in an append-only buffer that's only freed by stopSamplingHeapProfiler.
77
+ // Without this reset, each call to getAllocationProfile re-reads the entire
78
+ // history, so alloc_* totals grow linearly with wall-clock time and V8's
79
+ // internal sample buffer leaks for the lifetime of the process.
80
+ if (startedWithAllocations) {
81
+ (0, heap_profiler_bindings_1.stopSamplingHeapProfiler)();
82
+ (0, heap_profiler_bindings_1.startSamplingHeapProfiler)(heapIntervalBytes, heapStackDepth, true);
83
+ }
84
+ return result;
85
+ }
86
+ function convertProfile(rootNode, ignoreSamplePath, sourceMapper, generateLabels, columnNumbers = profile_serializer_1.DEFAULT_COLUMN_NUMBERS) {
87
+ const allocations = startedWithAllocations;
88
+ const startTimeNanos = Date.now() * 1000 * 1000;
89
+ // Add node for external memory usage.
90
+ // Current type definitions do not have external.
91
+ // TODO: remove any once type definition is updated to include external.
92
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
+ 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
+ }
126
+ }
127
+ else {
128
+ root = rootNode;
129
+ }
130
+ return (0, profile_serializer_1.serializeHeapProfile)(root, startTimeNanos, heapIntervalBytes, ignoreSamplePath, sourceMapper, generateLabels, allocations, columnNumbers);
131
+ }
132
+ /**
133
+ * Collects a profile and returns it serialized in pprof format using lazy V2 API.
134
+ * Throws if heap profiler is not enabled.
135
+ *
136
+ * @param ignoreSamplePath
137
+ * @param sourceMapper
138
+ * @param generateLabels
139
+ */
140
+ function profileV2(ignoreSamplePath, sourceMapper, generateLabels, columnNumbers = profile_serializer_1.DEFAULT_COLUMN_NUMBERS) {
141
+ return v8ProfileV2(root => {
142
+ return convertProfile(root, ignoreSamplePath, sourceMapper, generateLabels, columnNumbers);
143
+ });
144
+ }
145
+ /**
146
+ * Starts heap profiling. If heap profiling has already been started with
147
+ * the same parameters, this is a noop. If heap profiler has already been
148
+ * started with different parameters, this throws an error.
149
+ *
150
+ * @param intervalBytes - average number of bytes between samples.
151
+ * @param stackDepth - maximum stack depth for samples collected.
152
+ * @param allocations - include total allocation samples in the profile.
153
+ * When true, each call to `profile()` forces a full GC (via
154
+ * v8::HeapProfiler::kSamplingForceGC) to classify sampled objects as
155
+ * live/dead, which adds a measurable pause. Requires Node.js >= 26.
156
+ */
157
+ function start(intervalBytes, stackDepth, allocations = false) {
158
+ if (enabled) {
159
+ throw new Error(`Heap profiler is already started with intervalBytes ${heapIntervalBytes} and stackDepth ${stackDepth}`);
160
+ }
161
+ heapIntervalBytes = intervalBytes;
162
+ heapStackDepth = stackDepth;
163
+ startedWithAllocations = allocations;
164
+ (0, heap_profiler_bindings_1.startSamplingHeapProfiler)(intervalBytes, stackDepth, allocations);
165
+ enabled = true;
166
+ }
167
+ // Stops heap profiling. If heap profiling has not been started, does nothing.
168
+ function stop() {
169
+ if (enabled) {
170
+ enabled = false;
171
+ startedWithAllocations = false;
172
+ (0, heap_profiler_bindings_1.stopSamplingHeapProfiler)();
173
+ }
174
+ }
175
+ exports.CallbackMode = {
176
+ Async: 1,
177
+ Interrupt: 2,
178
+ Both: 3,
179
+ };
180
+ /**
181
+ * Add monitoring for v8 heap, heap profiler must already be started.
182
+ * When an out of heap memory event occurs:
183
+ * - an extension of heap memory of |heapLimitExtensionSize| bytes is
184
+ * requested to v8. This extension can occur |maxHeapLimitExtensionCount|
185
+ * number of times. If the extension amount is not enough to satisfy
186
+ * memory allocation that triggers GC and OOM, process will abort.
187
+ * - heap profile is dumped as folded stacks on stderr if
188
+ * |dumpHeapProfileOnSdterr| is true
189
+ * - heap profile is dumped in temporary file and a new process is spawned
190
+ * with |exportCommand| arguments and profile path appended at the end.
191
+ * - |callback| is called. Callback can be invoked only if
192
+ * heapLimitExtensionSize is enough for the process to continue. Invocation
193
+ * will be done by a RequestInterrupt if |callbackMode| is Interrupt or Both,
194
+ * this might be unsafe since Isolate should not be reentered
195
+ * from RequestInterrupt, but this allows to interrupt synchronous code.
196
+ * Otherwise the callback is scheduled to be called asynchronously.
197
+ * @param heapLimitExtensionSize - amount of bytes heap should be expanded
198
+ * with upon OOM
199
+ * @param maxHeapLimitExtensionCount - maximum number of times heap size
200
+ * extension can occur
201
+ * @param dumpHeapProfileOnSdterr - dump heap profile on stderr upon OOM
202
+ * @param exportCommand - command to execute upon OOM, filepath of a
203
+ * temporary file containing heap profile will be appended
204
+ * @param callback - callback to call when OOM occurs
205
+ * @param callbackMode
206
+ */
207
+ function monitorOutOfMemory(heapLimitExtensionSize, maxHeapLimitExtensionCount, dumpHeapProfileOnSdterr, exportCommand, callback, callbackMode) {
208
+ if (!enabled) {
209
+ throw new Error('Heap profiler must already be started to call monitorOutOfMemory');
210
+ }
211
+ let newCallback;
212
+ if (typeof callback !== 'undefined') {
213
+ newCallback = (profile) => {
214
+ callback(convertProfile(profile));
215
+ };
216
+ }
217
+ (0, heap_profiler_bindings_1.monitorOutOfMemory)(heapLimitExtensionSize, maxHeapLimitExtensionCount, dumpHeapProfileOnSdterr, exportCommand || [], newCallback, typeof callbackMode !== 'undefined' ? callbackMode : exports.CallbackMode.Async, worker_threads_1.isMainThread);
218
+ }
219
+ //# sourceMappingURL=heap-profiler.js.map
@@ -0,0 +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;AAqCD,gDA4BC;AAzRD,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,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,OAAO,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,IAAA,2CAA0B,EACxB,sBAAsB,EACtB,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,CACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ import * as heapProfiler from './heap-profiler';
2
+ import * as otelThreadCtxModule from './otel-thread-ctx';
3
+ import * as timeProfiler from './time-profiler';
4
+ export { AllocationProfileNode, TimeProfileNode, ProfileNode, LabelSet, } from './v8-types';
5
+ export { encode, encodeSync } from './profile-encoder';
6
+ export { SourceMapper } from './sourcemapper/sourcemapper';
7
+ export { setLogger } from './logger';
8
+ export { getNativeThreadId } from './time-profiler';
9
+ export declare const time: {
10
+ profile: typeof timeProfiler.profile;
11
+ start: typeof timeProfiler.start;
12
+ stop: typeof timeProfiler.stop;
13
+ profileV2: typeof timeProfiler.profileV2;
14
+ getContext: typeof timeProfiler.getContext;
15
+ setContext: typeof timeProfiler.setContext;
16
+ runWithContext: typeof timeProfiler.runWithContext;
17
+ isStarted: typeof timeProfiler.isStarted;
18
+ v8ProfilerStuckEventLoopDetected: typeof timeProfiler.v8ProfilerStuckEventLoopDetected;
19
+ getState: typeof timeProfiler.getState;
20
+ getMetrics: typeof timeProfiler.getMetrics;
21
+ constants: {
22
+ kSampleCount: any;
23
+ GARBAGE_COLLECTION_FUNCTION_NAME: string;
24
+ NON_JS_THREADS_FUNCTION_NAME: string;
25
+ };
26
+ };
27
+ export declare const heap: {
28
+ start: typeof heapProfiler.start;
29
+ stop: typeof heapProfiler.stop;
30
+ profile: typeof heapProfiler.profile;
31
+ profileV2: typeof heapProfiler.profileV2;
32
+ convertProfile: typeof heapProfiler.convertProfile;
33
+ v8Profile: typeof heapProfiler.v8Profile;
34
+ monitorOutOfMemory: typeof heapProfiler.monitorOutOfMemory;
35
+ CallbackMode: {
36
+ Async: number;
37
+ Interrupt: number;
38
+ Both: number;
39
+ };
40
+ };
41
+ export declare const otelThreadCtx: {
42
+ ThreadContext: otelThreadCtxModule.ThreadContextCtor;
43
+ getContext: () => otelThreadCtxModule.ThreadContext | undefined;
44
+ clearContext: () => void;
45
+ getProcessContextAttributes: typeof otelThreadCtxModule.getProcessContextAttributes;
46
+ };
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
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;
37
+ /**
38
+ * Copyright 2019 Google Inc. All Rights Reserved.
39
+ *
40
+ * Licensed under the Apache License, Version 2.0 (the "License");
41
+ * you may not use this file except in compliance with the License.
42
+ * You may obtain a copy of the License at
43
+ *
44
+ * http://www.apache.org/licenses/LICENSE-2.0
45
+ *
46
+ * Unless required by applicable law or agreed to in writing, software
47
+ * distributed under the License is distributed on an "AS IS" BASIS,
48
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49
+ * See the License for the specific language governing permissions and
50
+ * limitations under the License.
51
+ */
52
+ const fs_1 = require("fs");
53
+ const heapProfiler = __importStar(require("./heap-profiler"));
54
+ const otelThreadCtxModule = __importStar(require("./otel-thread-ctx"));
55
+ const profile_encoder_1 = require("./profile-encoder");
56
+ const timeProfiler = __importStar(require("./time-profiler"));
57
+ var profile_encoder_2 = require("./profile-encoder");
58
+ Object.defineProperty(exports, "encode", { enumerable: true, get: function () { return profile_encoder_2.encode; } });
59
+ Object.defineProperty(exports, "encodeSync", { enumerable: true, get: function () { return profile_encoder_2.encodeSync; } });
60
+ var sourcemapper_1 = require("./sourcemapper/sourcemapper");
61
+ Object.defineProperty(exports, "SourceMapper", { enumerable: true, get: function () { return sourcemapper_1.SourceMapper; } });
62
+ var logger_1 = require("./logger");
63
+ Object.defineProperty(exports, "setLogger", { enumerable: true, get: function () { return logger_1.setLogger; } });
64
+ var time_profiler_1 = require("./time-profiler");
65
+ Object.defineProperty(exports, "getNativeThreadId", { enumerable: true, get: function () { return time_profiler_1.getNativeThreadId; } });
66
+ exports.time = {
67
+ profile: timeProfiler.profile,
68
+ start: timeProfiler.start,
69
+ stop: timeProfiler.stop,
70
+ profileV2: timeProfiler.profileV2,
71
+ getContext: timeProfiler.getContext,
72
+ setContext: timeProfiler.setContext,
73
+ runWithContext: timeProfiler.runWithContext,
74
+ isStarted: timeProfiler.isStarted,
75
+ v8ProfilerStuckEventLoopDetected: timeProfiler.v8ProfilerStuckEventLoopDetected,
76
+ getState: timeProfiler.getState,
77
+ getMetrics: timeProfiler.getMetrics,
78
+ constants: timeProfiler.constants,
79
+ };
80
+ exports.heap = {
81
+ start: heapProfiler.start,
82
+ stop: heapProfiler.stop,
83
+ profile: heapProfiler.profile,
84
+ profileV2: heapProfiler.profileV2,
85
+ convertProfile: heapProfiler.convertProfile,
86
+ v8Profile: heapProfiler.v8Profile,
87
+ monitorOutOfMemory: heapProfiler.monitorOutOfMemory,
88
+ CallbackMode: heapProfiler.CallbackMode,
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
+ };
100
+ // If loaded with --require, start profiling.
101
+ if (module.parent && module.parent.id === 'internal/preload') {
102
+ exports.time.start({});
103
+ process.on('exit', () => {
104
+ // The process is going to terminate imminently. All work here needs to
105
+ // be synchronous.
106
+ const profile = exports.time.stop();
107
+ const buffer = (0, profile_encoder_1.encodeSync)(profile);
108
+ (0, fs_1.writeFileSync)(`pprof-profile-${process.pid}.pb.gz`, buffer);
109
+ });
110
+ }
111
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,2BAAiC;AAEjC,8DAA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AE,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,18 @@
1
+ export interface Logger {
2
+ error(...args: Array<{}>): void;
3
+ trace(...args: Array<{}>): void;
4
+ debug(...args: Array<{}>): void;
5
+ info(...args: Array<{}>): void;
6
+ warn(...args: Array<{}>): void;
7
+ fatal(...args: Array<{}>): void;
8
+ }
9
+ export declare class NullLogger implements Logger {
10
+ info(...args: Array<{}>): void;
11
+ error(...args: Array<{}>): void;
12
+ trace(...args: Array<{}>): void;
13
+ warn(...args: Array<{}>): void;
14
+ fatal(...args: Array<{}>): void;
15
+ debug(...args: Array<{}>): void;
16
+ }
17
+ export declare let logger: NullLogger;
18
+ export declare function setLogger(newLogger: Logger): void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = exports.NullLogger = void 0;
4
+ exports.setLogger = setLogger;
5
+ class NullLogger {
6
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
+ info(...args) {
8
+ return;
9
+ }
10
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+ error(...args) {
12
+ return;
13
+ }
14
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
+ trace(...args) {
16
+ return;
17
+ }
18
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
19
+ warn(...args) {
20
+ return;
21
+ }
22
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
+ fatal(...args) {
24
+ return;
25
+ }
26
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
+ debug(...args) {
28
+ return;
29
+ }
30
+ }
31
+ exports.NullLogger = NullLogger;
32
+ exports.logger = new NullLogger();
33
+ function setLogger(newLogger) {
34
+ exports.logger = newLogger;
35
+ }
36
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../ts/src/logger.ts"],"names":[],"mappings":";;;AAsCA,8BAEC;AA/BD,MAAa,UAAU;IACrB,6DAA6D;IAC7D,IAAI,CAAC,GAAG,IAAe;QACrB,OAAO;IACT,CAAC;IACD,6DAA6D;IAC7D,KAAK,CAAC,GAAG,IAAe;QACtB,OAAO;IACT,CAAC;IACD,6DAA6D;IAC7D,KAAK,CAAC,GAAG,IAAe;QACtB,OAAO;IACT,CAAC;IACD,6DAA6D;IAC7D,IAAI,CAAC,GAAG,IAAe;QACrB,OAAO;IACT,CAAC;IACD,6DAA6D;IAC7D,KAAK,CAAC,GAAG,IAAe;QACtB,OAAO;IACT,CAAC;IACD,6DAA6D;IAC7D,KAAK,CAAC,GAAG,IAAe;QACtB,OAAO;IACT,CAAC;CACF;AAzBD,gCAyBC;AAEU,QAAA,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;AAErC,SAAgB,SAAS,CAAC,SAAiB;IACzC,cAAM,GAAG,SAAS,CAAC;AACrB,CAAC"}
@@ -0,0 +1,85 @@
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.wrapped_object_offset': number;
10
+ readonly 'threadlocal.tagged_size': number;
11
+ readonly 'threadlocal.native_wrap_fields_offset': number;
12
+ readonly 'threadlocal.js_map_table_offset': number;
13
+ readonly 'threadlocal.ordered_hash_map_header_size': number;
14
+ }
15
+ /**
16
+ * A thread-context record. Construct with `new ThreadContext(...)`; install
17
+ * via the {@link enter} or {@link run} instance methods. The underlying
18
+ * native record is GC-owned: when no JS or async-context-frame reference
19
+ * survives, it's freed.
20
+ *
21
+ * `appendAttributes` mutates the context's record in place. Because every
22
+ * async-context frame that holds the same `ThreadContext` reference observes
23
+ * the same native record buffer, an append is visible across all those
24
+ * frames even when the reallocate path runs (the context's internal
25
+ * pointer is updated, the JS object is not replaced).
26
+ */
27
+ export interface ThreadContext {
28
+ appendAttributes(attributes: Array<string | null | undefined> | undefined): void;
29
+ isTruncated(): boolean;
30
+ /** Debug-only: returns the on-the-wire record bytes. Not stable. */
31
+ debugBytes(): Uint8Array;
32
+ /**
33
+ * Attach this context to the current async-context frame (and every
34
+ * frame derived from it until the frame ends or {@link clearContext}
35
+ * detaches it). Re-installing the same context reference is cheap (no
36
+ * allocation); per-span caching of the context on the caller side is
37
+ * the intended usage pattern.
38
+ *
39
+ * On non-Linux platforms this is a no-op.
40
+ */
41
+ enter(): void;
42
+ /**
43
+ * Attach this context for the duration of `fn`. Equivalent to
44
+ * `als.run(this, fn)` — after `fn` returns, the previous context is
45
+ * restored. Returns whatever `fn` returns; if `fn` returns a Promise,
46
+ * the same Promise is propagated. On non-Linux platforms simply
47
+ * invokes `fn`.
48
+ */
49
+ run<T>(fn: () => T): T;
50
+ }
51
+ /**
52
+ * Constructor for {@link ThreadContext}. On non-Linux platforms, returns a
53
+ * no-op instance whose methods do nothing — the OTEP-4947 reader
54
+ * contract is ELF-TLSDESC, only meaningful on Linux.
55
+ */
56
+ export interface ThreadContextCtor {
57
+ new (traceId: Uint8Array, spanId: Uint8Array, attributes?: Array<string | null | undefined>): ThreadContext;
58
+ readonly prototype: ThreadContext;
59
+ }
60
+ /** {@inheritDoc ThreadContextCtor} */
61
+ export declare let ThreadContext: ThreadContextCtor;
62
+ /**
63
+ * Returns the {@link ThreadContext} currently attached to the active
64
+ * async-context frame, or `undefined` if none is.
65
+ */
66
+ export declare let getContext: () => ThreadContext | undefined;
67
+ /**
68
+ * Detach any {@link ThreadContext} from the current async-context frame.
69
+ * Idempotent when no context is attached. On non-Linux platforms this is
70
+ * a no-op.
71
+ */
72
+ export declare let clearContext: () => void;
73
+ export declare let _currentRecordBytes: () => Uint8Array | undefined;
74
+ /**
75
+ * Returns the OTEP-4719 process-context attributes the caller should
76
+ * publish so an out-of-process reader can decode the on-the-wire uint8
77
+ * key indexes back to attribute names. The supplied `keys` array is the
78
+ * same string list the caller writes into the positional `attributes`
79
+ * argument of {@link ThreadContext}: index N here is the uint8 key index
80
+ * N in each record.
81
+ *
82
+ * `keys` is validated: must be a string array of length ≤ 256 with no
83
+ * duplicates.
84
+ */
85
+ export declare function getProcessContextAttributes(keys: string[]): ProcessContextAttributes;