@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,528 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2016 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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || (function () {
34
+ var ownKeys = function(o) {
35
+ ownKeys = Object.getOwnPropertyNames || function (o) {
36
+ var ar = [];
37
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
+ return ar;
39
+ };
40
+ return ownKeys(o);
41
+ };
42
+ return function (mod) {
43
+ if (mod && mod.__esModule) return mod;
44
+ var result = {};
45
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
+ __setModuleDefault(result, mod);
47
+ return result;
48
+ };
49
+ })();
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.SourceMapper = exports.ANNOTATION_TAIL_BYTES = void 0;
52
+ exports.extractSourceMappingURL = extractSourceMappingURL;
53
+ exports.readSourceMappingURL = readSourceMappingURL;
54
+ // Originally copied from cloud-debug-nodejs's sourcemapper.ts from
55
+ // https://github.com/googleapis/cloud-debug-nodejs/blob/7bdc2f1f62a3b45b7b53ea79f9444c8ed50e138b/src/agent/io/sourcemapper.ts
56
+ // Modified to map from generated code to source code, rather than from source
57
+ // code to generated code.
58
+ const fs = __importStar(require("fs"));
59
+ const path = __importStar(require("path"));
60
+ const sourceMap = __importStar(require("source-map"));
61
+ const logger_1 = require("../logger");
62
+ const readFile = fs.promises.readFile;
63
+ const CONCURRENCY = 10;
64
+ function createLimiter(concurrency) {
65
+ let active = 0;
66
+ const queue = [];
67
+ return function limit(fn) {
68
+ return new Promise((resolve, reject) => {
69
+ const run = () => {
70
+ active++;
71
+ fn()
72
+ .then(resolve, reject)
73
+ .finally(() => {
74
+ active--;
75
+ if (queue.length > 0)
76
+ queue.shift()();
77
+ });
78
+ };
79
+ if (active < concurrency)
80
+ run();
81
+ else
82
+ queue.push(run);
83
+ });
84
+ };
85
+ }
86
+ const MAP_EXT = '.map';
87
+ // Per TC39 ECMA-426 §11.1.2.1 JavaScriptExtractSourceMapURL (without parsing):
88
+ // https://tc39.es/ecma426/#sec-linking-inline
89
+ //
90
+ // Split on these line terminators (ECMA-262 LineTerminatorSequence):
91
+ const LINE_SPLIT_RE = /\r\n|\n|\r|\u2028|\u2029/;
92
+ // Bytes to read from the end of a JS file when scanning for the annotation.
93
+ // The annotation must be on the last non-empty line, which is always short
94
+ // for external URLs. If no line terminator appears in the tail we fall back
95
+ // to a full file read (handles very large inline data: maps).
96
+ exports.ANNOTATION_TAIL_BYTES = 4 * 1024;
97
+ // Quote code points that invalidate the annotation (U+0022, U+0027, U+0060):
98
+ const QUOTE_CHARS_RE = /["'`]/;
99
+ // MatchSourceMapURL pattern applied to the comment text that follows "//":
100
+ const MATCH_SOURCE_MAP_URL_RE = /^[@#]\s*sourceMappingURL=(\S*?)\s*$/;
101
+ /**
102
+ * Extracts a sourceMappingURL from JS source per ECMA-426 §11.1.2.1
103
+ * (without-parsing variant).
104
+ *
105
+ * Scans lines from the end, skipping empty/whitespace-only lines.
106
+ * Returns null as soon as the first non-empty line is found that does not
107
+ * carry a valid annotation — the URL must be on the last non-empty line.
108
+ */
109
+ function extractSourceMappingURL(content) {
110
+ const lines = content.split(LINE_SPLIT_RE);
111
+ for (let i = lines.length - 1; i >= 0; i--) {
112
+ const line = lines[i];
113
+ if (line.trim() === '')
114
+ continue; // skip empty / whitespace-only lines
115
+ // This is the last non-empty line; it must carry the annotation or we stop.
116
+ const commentStart = line.indexOf('//');
117
+ if (commentStart === -1)
118
+ return undefined;
119
+ const comment = line.slice(commentStart + 2);
120
+ if (QUOTE_CHARS_RE.test(comment))
121
+ return undefined;
122
+ const match = MATCH_SOURCE_MAP_URL_RE.exec(comment);
123
+ return match ? match[1] || undefined : undefined;
124
+ }
125
+ return undefined;
126
+ }
127
+ /**
128
+ * Reads the sourceMappingURL from a JS file efficiently by only reading a
129
+ * small tail of the file.
130
+ *
131
+ * The annotation must be on the last non-empty line (ECMA-426), so as long as
132
+ * the tail contains at least one line terminator the last line is fully
133
+ * captured. If no line terminator appears in the tail the entire tail is part
134
+ * of one very long inline data: line; we fall back to a full file read in
135
+ * that case.
136
+ */
137
+ async function readSourceMappingURL(filePath) {
138
+ const fd = await fs.promises.open(filePath, 'r');
139
+ try {
140
+ const { size } = await fd.stat();
141
+ if (size === 0)
142
+ return undefined;
143
+ const tailSize = Math.min(exports.ANNOTATION_TAIL_BYTES, size);
144
+ const buf = Buffer.allocUnsafe(tailSize);
145
+ await fd.read(buf, 0, tailSize, size - tailSize);
146
+ const tail = buf.toString('utf8');
147
+ // The last non-empty line is fully captured in the tail if and only if a
148
+ // line terminator that precedes it also falls within the tail — i.e. the
149
+ // last non-empty segment is not the very first element of the split result.
150
+ //
151
+ // Counter-example: a large inline map followed by trailing empty lines.
152
+ // The tail might be "<end of base64>\n\n", which contains line terminators
153
+ // but whose last non-empty content ("<end of base64>") is the first
154
+ // segment — it extends before the window. Checking LINE_TERM_RE alone
155
+ // would incorrectly accept this tail.
156
+ const lines = tail.split(LINE_SPLIT_RE);
157
+ let lastNonEmptyIdx = lines.length - 1;
158
+ while (lastNonEmptyIdx > 0 && lines[lastNonEmptyIdx].trim() === '') {
159
+ lastNonEmptyIdx--;
160
+ }
161
+ if (tailSize === size || lastNonEmptyIdx > 0) {
162
+ return extractSourceMappingURL(tail);
163
+ }
164
+ const fullContent = await readFile(filePath, 'utf8');
165
+ return extractSourceMappingURL(fullContent);
166
+ }
167
+ finally {
168
+ await fd.close();
169
+ }
170
+ }
171
+ function error(msg) {
172
+ logger_1.logger.debug(`Error: ${msg}`);
173
+ return new Error(msg);
174
+ }
175
+ /**
176
+ * @param {!Map} infoMap The map that maps input source files to
177
+ * SourceMapConsumer objects that are used to calculate mapping information
178
+ * @param {string} mapPath The path to the source map file to process. The
179
+ * path should be relative to the process's current working directory
180
+ * @private
181
+ */
182
+ async function processSourceMap(infoMap, mapPath, debug) {
183
+ // this handles the case when the path is undefined, null, or
184
+ // the empty string
185
+ if (!mapPath || !mapPath.endsWith(MAP_EXT)) {
186
+ throw error(`The path "${mapPath}" does not specify a source map file`);
187
+ }
188
+ mapPath = path.normalize(mapPath);
189
+ let contents;
190
+ try {
191
+ contents = await readFile(mapPath, 'utf8');
192
+ }
193
+ catch (e) {
194
+ throw error('Could not read source map file ' + mapPath + ': ' + e);
195
+ }
196
+ /* If the source map file defines a "file" attribute, use it as
197
+ * the output file where the path is relative to the directory
198
+ * containing the map file. Otherwise, use the name of the output
199
+ * file (with the .map extension removed) as the output file.
200
+
201
+ * With nextjs/webpack, when there are subdirectories in `pages` directory,
202
+ * the generated source maps do not reference correctly the generated files
203
+ * in their `file` property.
204
+ * For example if the generated file / source maps have paths:
205
+ * <root>/pages/sub/foo.js(.map)
206
+ * foo.js.map will have ../pages/sub/foo.js as `file` property instead of
207
+ * ../../pages/sub/foo.js
208
+ * To workaround this, check first if file referenced in `file` property
209
+ * exists and if it does not, check if generated file exists alongside the
210
+ * source map file.
211
+ */
212
+ const dir = path.dirname(mapPath);
213
+ // Parse JSON once: extract the `file` property for early-exit checks and
214
+ // reuse the parsed object when constructing SourceMapConsumer (avoids a
215
+ // second parse inside the library).
216
+ let parsedMap;
217
+ let rawFile;
218
+ try {
219
+ parsedMap = JSON.parse(contents);
220
+ rawFile = parsedMap.file;
221
+ }
222
+ catch {
223
+ // Will fail again below when creating SourceMapConsumer; let that throw.
224
+ }
225
+ const generatedPathCandidates = [];
226
+ if (rawFile) {
227
+ generatedPathCandidates.push(path.resolve(dir, rawFile));
228
+ }
229
+ const samePath = path.resolve(dir, path.basename(mapPath, MAP_EXT));
230
+ if (generatedPathCandidates.length === 0 ||
231
+ generatedPathCandidates[0] !== samePath) {
232
+ generatedPathCandidates.push(samePath);
233
+ }
234
+ // Find the first candidate that exists and hasn't been loaded already.
235
+ let targetPath;
236
+ for (const candidate of generatedPathCandidates) {
237
+ if (infoMap.has(candidate)) {
238
+ // Already loaded via sourceMappingURL annotation; skip this map file.
239
+ if (debug) {
240
+ logger_1.logger.debug(`Skipping ${mapPath}: ${candidate} already loaded via sourceMappingURL`);
241
+ }
242
+ return;
243
+ }
244
+ try {
245
+ await fs.promises.access(candidate, fs.constants.F_OK);
246
+ targetPath = candidate;
247
+ break;
248
+ }
249
+ catch {
250
+ if (debug) {
251
+ logger_1.logger.debug(`Generated path ${candidate} does not exist`);
252
+ }
253
+ }
254
+ }
255
+ if (!targetPath) {
256
+ if (debug) {
257
+ logger_1.logger.debug(`Unable to find generated file for ${mapPath}`);
258
+ }
259
+ return;
260
+ }
261
+ let consumer;
262
+ try {
263
+ // TODO: Determine how to reconsile the type conflict where `consumer`
264
+ // is constructed as a SourceMapConsumer but is used as a
265
+ // RawSourceMap.
266
+ consumer = (await new sourceMap.SourceMapConsumer((parsedMap ?? contents)));
267
+ }
268
+ catch (e) {
269
+ throw error('An error occurred while reading the ' +
270
+ 'sourceMap file ' +
271
+ mapPath +
272
+ ': ' +
273
+ e);
274
+ }
275
+ infoMap.set(targetPath, { mapFileDir: dir, mapConsumer: consumer });
276
+ if (debug) {
277
+ logger_1.logger.debug(`Loaded source map for ${targetPath} => ${mapPath}`);
278
+ }
279
+ }
280
+ class SourceMapper {
281
+ static async create(searchDirs, debug = false) {
282
+ const mapper = new SourceMapper(debug);
283
+ for (const dir of searchDirs) {
284
+ await mapper.loadDirectory(dir);
285
+ }
286
+ return mapper;
287
+ }
288
+ constructor(debug = false) {
289
+ /** JS files that declared a sourceMappingURL but no map was ultimately found. */
290
+ this.declaredMissingMap = new Set();
291
+ this.infoMap = new Map();
292
+ this.debug = debug;
293
+ }
294
+ /**
295
+ * Scans `searchDir` recursively for JS files and source map files, loading
296
+ * source maps for all JS files found.
297
+ *
298
+ * Priority for each JS file:
299
+ * 1. A map pointed to by a `sourceMappingURL` annotation in the JS file
300
+ * (inline `data:` URL or external file path, only if the file exists).
301
+ * 2. A `.map` file found in the directory scan that claims to belong to
302
+ * that JS file (via its `file` property or naming convention).
303
+ *
304
+ * Safe to call multiple times; already-loaded files are skipped.
305
+ */
306
+ async loadDirectory(searchDir) {
307
+ // Resolve to absolute so all paths in infoMap are consistent regardless of
308
+ // whether the caller passed a relative or absolute directory.
309
+ searchDir = path.resolve(searchDir);
310
+ if (this.debug) {
311
+ logger_1.logger.debug(`Loading source maps from directory: ${searchDir}`);
312
+ }
313
+ const jsFiles = [];
314
+ const mapFiles = [];
315
+ for await (const entry of walk(searchDir, filename => /\.[cm]?js$/.test(filename) || /\.[cm]?js\.map$/.test(filename), (root, dirname) => root !== '/proc' && dirname !== '.git' && dirname !== 'node_modules')) {
316
+ if (entry.endsWith(MAP_EXT)) {
317
+ mapFiles.push(entry);
318
+ }
319
+ else {
320
+ jsFiles.push(entry);
321
+ }
322
+ }
323
+ if (this.debug) {
324
+ logger_1.logger.debug(`Found ${jsFiles.length} JS files and ${mapFiles.length} map files in ${searchDir}`);
325
+ }
326
+ const limit = createLimiter(CONCURRENCY);
327
+ // JS files that declared a sourceMappingURL but Phase 1 couldn't load the map.
328
+ const annotatedNotLoaded = new Set();
329
+ // Phase 1: Check sourceMappingURL annotations in JS files (higher priority).
330
+ await Promise.all(jsFiles.map(jsPath => limit(async () => {
331
+ if (this.infoMap.has(jsPath))
332
+ return;
333
+ let url;
334
+ try {
335
+ url = await readSourceMappingURL(jsPath);
336
+ }
337
+ catch {
338
+ return;
339
+ }
340
+ if (!url)
341
+ return;
342
+ if (url.startsWith('data:')) {
343
+ // Inline source map data URL. Handles both:
344
+ // data:application/json;base64,<b64>
345
+ // data:application/json;charset=utf-8;base64,<b64>
346
+ // data:application/json,<urlencoded> (and other non-base64 forms)
347
+ const commaIdx = url.indexOf(',');
348
+ if (commaIdx !== -1) {
349
+ const meta = url.slice(0, commaIdx);
350
+ const data = url.slice(commaIdx + 1);
351
+ const mapContent = meta.endsWith(';base64')
352
+ ? Buffer.from(data, 'base64').toString()
353
+ : decodeURIComponent(data);
354
+ await this.loadMapContent(jsPath, mapContent, path.dirname(jsPath));
355
+ }
356
+ // If the data URL is malformed (no comma), skip silently — not a
357
+ // missing map file, just an unreadable inline annotation.
358
+ }
359
+ else {
360
+ const mapPath = path.resolve(path.dirname(jsPath), url);
361
+ try {
362
+ const mapContent = await readFile(mapPath, 'utf8');
363
+ await this.loadMapContent(jsPath, mapContent, path.dirname(mapPath));
364
+ }
365
+ catch {
366
+ // Map file doesn't exist or is unreadable; fall through to Phase 2.
367
+ annotatedNotLoaded.add(jsPath);
368
+ }
369
+ }
370
+ })));
371
+ // Phase 2: Process .map files for any JS files not yet resolved.
372
+ await Promise.all(mapFiles.map(mapPath => limit(() => processSourceMap(this.infoMap, mapPath, this.debug))));
373
+ // Any file whose annotation pointed to a missing map and that still has no
374
+ // entry after Phase 2 is tracked as "declared but missing".
375
+ for (const jsPath of annotatedNotLoaded) {
376
+ if (!this.infoMap.has(jsPath)) {
377
+ this.declaredMissingMap.add(jsPath);
378
+ }
379
+ }
380
+ }
381
+ async loadMapContent(jsPath, mapContent, mapDir) {
382
+ try {
383
+ const parsedMap = JSON.parse(mapContent);
384
+ const consumer = (await new sourceMap.SourceMapConsumer(parsedMap));
385
+ this.infoMap.set(jsPath, { mapFileDir: mapDir, mapConsumer: consumer });
386
+ if (this.debug) {
387
+ logger_1.logger.debug(`Loaded source map for ${jsPath} via sourceMappingURL`);
388
+ }
389
+ }
390
+ catch (e) {
391
+ logger_1.logger.debug(`Failed to parse source map for ${jsPath}: ${e}`);
392
+ }
393
+ }
394
+ /**
395
+ * Used to get the information about the transpiled file from a given input
396
+ * source file provided there isn't any ambiguity with associating the input
397
+ * path to exactly one output transpiled file.
398
+ *
399
+ * @param inputPath The (possibly relative) path to the original source file.
400
+ * @return The `MapInfoCompiled` object that describes the transpiled file
401
+ * associated with the specified input path. `null` is returned if either
402
+ * zero files are associated with the input path or if more than one file
403
+ * could possibly be associated with the given input path.
404
+ */
405
+ getMappingInfo(inputPath) {
406
+ const normalizedPath = path.normalize(inputPath);
407
+ if (this.infoMap.has(normalizedPath)) {
408
+ return this.infoMap.get(normalizedPath);
409
+ }
410
+ return null;
411
+ }
412
+ /**
413
+ * Used to determine if the source file specified by the given path has
414
+ * a .map file and an output file associated with it.
415
+ *
416
+ * If there is no such mapping, it could be because the input file is not
417
+ * the input to a transpilation process or it is the input to a transpilation
418
+ * process but its corresponding .map file was not given to the constructor
419
+ * of this mapper.
420
+ *
421
+ * @param {string} inputPath The path to an input file that could
422
+ * possibly be the input to a transpilation process. The path should be
423
+ * relative to the process's current working directory.
424
+ */
425
+ hasMappingInfo(inputPath) {
426
+ return this.getMappingInfo(inputPath) !== null;
427
+ }
428
+ /**
429
+ * @param {string} inputPath The path to an input file that could possibly
430
+ * be the input to a transpilation process. The path should be relative to
431
+ * the process's current working directory
432
+ * @param {number} The line number in the input file where the line number is
433
+ * zero-based.
434
+ * @param {number} (Optional) The column number in the line of the file
435
+ * specified where the column number is zero-based.
436
+ * @return {Object} The object returned has a "file" attribute for the
437
+ * path of the output file associated with the given input file (where the
438
+ * path is relative to the process's current working directory),
439
+ * a "line" attribute of the line number in the output file associated with
440
+ * the given line number for the input file, and an optional "column" number
441
+ * of the column number of the output file associated with the given file
442
+ * and line information.
443
+ *
444
+ * If the given input file does not have mapping information associated
445
+ * with it then the input location is returned.
446
+ */
447
+ mappingInfo(location) {
448
+ const inputPath = path.normalize(location.file);
449
+ const entry = this.getMappingInfo(inputPath);
450
+ if (entry === null) {
451
+ if (this.debug) {
452
+ logger_1.logger.debug(`Source map lookup failed: no map found for ${location.file} (normalized: ${inputPath})`);
453
+ }
454
+ if (this.declaredMissingMap.has(inputPath)) {
455
+ return { ...location, missingMapFile: true };
456
+ }
457
+ return location;
458
+ }
459
+ const generatedPos = {
460
+ line: location.line,
461
+ column: location.column > 0 ? location.column - 1 : 0, // SourceMapConsumer expects column to be 0-based
462
+ };
463
+ // TODO: Determine how to remove the explicit cast here.
464
+ const consumer = entry.mapConsumer;
465
+ // When column is 0, we don't have real column info (e.g., from V8's LineTick
466
+ // which only provides line numbers). Use LEAST_UPPER_BOUND to find the first
467
+ // mapping on this line instead of failing because there's nothing at column 0.
468
+ const bias = generatedPos.column === 0
469
+ ? sourceMap.SourceMapConsumer.LEAST_UPPER_BOUND
470
+ : sourceMap.SourceMapConsumer.GREATEST_LOWER_BOUND;
471
+ const pos = consumer.originalPositionFor({ ...generatedPos, bias });
472
+ if (pos.source === null) {
473
+ if (this.debug) {
474
+ logger_1.logger.debug(`Source map lookup failed for ${location.name}(${location.file}:${location.line}:${location.column})`);
475
+ }
476
+ return location;
477
+ }
478
+ const loc = {
479
+ file: path.resolve(entry.mapFileDir, pos.source),
480
+ line: pos.line || undefined,
481
+ name: pos.name || location.name,
482
+ column: pos.column === null ? undefined : pos.column + 1, // convert column back to 1-based
483
+ };
484
+ if (this.debug) {
485
+ logger_1.logger.debug(`Source map lookup succeeded for ${location.name}(${location.file}:${location.line}:${location.column}) => ${loc.name}(${loc.file}:${loc.line}:${loc.column})`);
486
+ }
487
+ return loc;
488
+ }
489
+ }
490
+ exports.SourceMapper = SourceMapper;
491
+ function isErrnoException(e) {
492
+ return e instanceof Error && 'code' in e;
493
+ }
494
+ function isNonFatalError(error) {
495
+ const nonFatalErrors = ['ENOENT', 'EPERM', 'EACCES', 'ELOOP'];
496
+ return (isErrnoException(error) && error.code && nonFatalErrors.includes(error.code));
497
+ }
498
+ async function* walk(dir,
499
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
500
+ fileFilter = (filename) => true,
501
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
502
+ directoryFilter = (root, dirname) => true) {
503
+ async function* walkRecursive(dir) {
504
+ try {
505
+ for await (const d of await fs.promises.opendir(dir)) {
506
+ const entry = path.join(dir, d.name);
507
+ if (d.isDirectory() && directoryFilter(dir, d.name)) {
508
+ yield* walkRecursive(entry);
509
+ }
510
+ else if (d.isFile() && fileFilter(d.name)) {
511
+ // check that the file is readable
512
+ await fs.promises.access(entry, fs.constants.R_OK);
513
+ yield entry;
514
+ }
515
+ }
516
+ }
517
+ catch (error) {
518
+ if (!isNonFatalError(error)) {
519
+ throw error;
520
+ }
521
+ else {
522
+ logger_1.logger.debug(() => `Non fatal error: ${error}`);
523
+ }
524
+ }
525
+ }
526
+ yield* walkRecursive(dir);
527
+ }
528
+ //# sourceMappingURL=sourcemapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sourcemapper.js","sourceRoot":"","sources":["../../../ts/src/sourcemapper/sourcemapper.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DH,0DAiBC;AAYD,oDAoCC;AA3HD,mEAAmE;AACnE,8HAA8H;AAC9H,8EAA8E;AAC9E,0BAA0B;AAE1B,uCAAyB;AACzB,2CAA6B;AAC7B,sDAAwC;AACxC,sCAAiC;AAEjC,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAEtC,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,SAAS,aAAa,CAAC,WAAmB;IACxC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,MAAM,KAAK,GAAsB,EAAE,CAAC;IACpC,OAAO,SAAS,KAAK,CAAI,EAAoB;QAC3C,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxC,MAAM,GAAG,GAAG,GAAG,EAAE;gBACf,MAAM,EAAE,CAAC;gBACT,EAAE,EAAE;qBACD,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;qBACrB,OAAO,CAAC,GAAG,EAAE;oBACZ,MAAM,EAAE,CAAC;oBACT,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;wBAAE,KAAK,CAAC,KAAK,EAAG,EAAE,CAAC;gBACzC,CAAC,CAAC,CAAC;YACP,CAAC,CAAC;YACF,IAAI,MAAM,GAAG,WAAW;gBAAE,GAAG,EAAE,CAAC;;gBAC3B,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,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E,IAAI,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC5C,kCAAkC;oBAClC,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;oBACnD,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC5B,MAAM,KAAK,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,eAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,oBAAoB,KAAK,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const TimeProfiler: any;
2
+ export declare const constants: any;
3
+ export declare const getNativeThreadId: any;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNativeThreadId = exports.constants = exports.TimeProfiler = void 0;
4
+ /**
5
+ * Copyright 2018 Google Inc. All Rights Reserved.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const path_1 = require("path");
20
+ const findBinding = require('node-gyp-build');
21
+ const profiler = findBinding((0, path_1.join)(__dirname, '..', '..'));
22
+ exports.TimeProfiler = profiler.TimeProfiler;
23
+ exports.constants = profiler.constants;
24
+ exports.getNativeThreadId = profiler.getNativeThreadId;
25
+ //# sourceMappingURL=time-profiler-bindings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time-profiler-bindings.js","sourceRoot":"","sources":["../../ts/src/time-profiler-bindings.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,+BAA0B;AAE1B,MAAM,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC9C,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE7C,QAAA,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;AACrC,QAAA,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;AAC/B,QAAA,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Copyright 2017 Google Inc. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Profile } from 'pprof-format';
17
+ import { ColumnNumbers } from './profile-serializer';
18
+ import { SourceMapper } from './sourcemapper/sourcemapper';
19
+ import { getNativeThreadId } from './time-profiler-bindings';
20
+ import { GenerateTimeLabelsFunction, TimeProfilerMetrics } from './v8-types';
21
+ type Microseconds = number;
22
+ type Milliseconds = number;
23
+ export interface TimeProfilerOptions {
24
+ /** time in milliseconds for which to collect profile. */
25
+ durationMillis?: Milliseconds;
26
+ /** average time in microseconds between samples */
27
+ intervalMicros?: Microseconds;
28
+ sourceMapper?: SourceMapper;
29
+ /**
30
+ * This configuration option is experimental.
31
+ * When set to true, functions will be aggregated at the line level, rather
32
+ * than at the function level.
33
+ * This defaults to false.
34
+ */
35
+ lineNumbers?: boolean;
36
+ withContexts?: boolean;
37
+ workaroundV8Bug?: boolean;
38
+ collectCpuTime?: boolean;
39
+ collectAsyncId?: boolean;
40
+ useCPED?: boolean;
41
+ /**
42
+ * Controls how frame column numbers are represented in the serialized
43
+ * profile. Defaults to `'drop'` (column omitted) to preserve the historical
44
+ * line-number semantics for existing consumers. Set to `'pack'` to pack the
45
+ * column into the high 32 bits of the line field for backends that support
46
+ * it (e.g. Datadog's JS/Node deobfuscation). See {@link ColumnNumbers}.
47
+ */
48
+ columnNumbers?: ColumnNumbers;
49
+ }
50
+ export declare function profile(options?: TimeProfilerOptions): Promise<Profile>;
51
+ export declare function profileV2(options?: TimeProfilerOptions): Promise<any>;
52
+ export declare function start(options?: TimeProfilerOptions): void;
53
+ export declare function stop(restart?: boolean, generateLabels?: GenerateTimeLabelsFunction, lowCardinalityLabels?: string[]): Profile;
54
+ /**
55
+ * Same as stop() but uses the lazy callback path: serialization happens inside
56
+ * a native callback while the V8 profile is still alive.
57
+ * This reduces memory overhead.
58
+ */
59
+ export declare function stopV2(restart?: boolean, generateLabels?: GenerateTimeLabelsFunction, lowCardinalityLabels?: string[]): any;
60
+ export declare function getState(): any;
61
+ export declare function setContext(context?: object): void;
62
+ export declare function runWithContext<R, TArgs extends unknown[]>(context: object, f: (...args: TArgs) => R, ...args: TArgs): R;
63
+ export declare function getContext(): any;
64
+ export declare function getMetrics(): TimeProfilerMetrics;
65
+ export declare function isStarted(): boolean;
66
+ export declare function v8ProfilerStuckEventLoopDetected(): number;
67
+ export declare const constants: {
68
+ kSampleCount: any;
69
+ GARBAGE_COLLECTION_FUNCTION_NAME: string;
70
+ NON_JS_THREADS_FUNCTION_NAME: string;
71
+ };
72
+ export { getNativeThreadId };