profiler-md 0.7.0 → 0.8.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.
- package/dist/cli/index.mjs +313 -84
- package/dist/index.d.mts +65 -26
- package/dist/index.js +2 -2
- package/docs/languages/javascript.md +13 -1
- package/docs/languages/php.md +12 -0
- package/package.json +1 -1
- package/readme.md +5 -4
package/dist/cli/index.mjs
CHANGED
|
@@ -17,9 +17,9 @@ import { defineProgram } from "@optique/core/program";
|
|
|
17
17
|
import { formatUsageTerm } from "@optique/core/usage";
|
|
18
18
|
import { choice, float, integer, string } from "@optique/core/valueparser";
|
|
19
19
|
import { path } from "@optique/run";
|
|
20
|
-
import { glob, readFile, stat } from "node:fs/promises";
|
|
20
|
+
import { access, constants, glob, readFile, stat } from "node:fs/promises";
|
|
21
21
|
import { Ansis } from "ansis";
|
|
22
|
-
import { createWriteStream, openAsBlob } from "node:fs";
|
|
22
|
+
import { createReadStream, createWriteStream, openAsBlob } from "node:fs";
|
|
23
23
|
import { spawn } from "node:child_process";
|
|
24
24
|
import { blob } from "node:stream/consumers";
|
|
25
25
|
import { pipeline } from "node:stream/promises";
|
|
@@ -79,8 +79,8 @@ const concatUint8Arrays = (arrays) => {
|
|
|
79
79
|
* Decoding is synchronous and correct across multi-byte sequences split at a
|
|
80
80
|
* chunk boundary.
|
|
81
81
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
82
|
+
* Replaces an invalid sequence, including a truncated trailing one, with
|
|
83
|
+
* U+FFFD.
|
|
84
84
|
*
|
|
85
85
|
* Yields the same lines as `decoder.decode(bytes).split('\n')` would (with `\r`
|
|
86
86
|
* stripped), i.e. a trailing empty line when the input ends with a newline.
|
|
@@ -101,8 +101,8 @@ function* decodeUtf8Lines(bytes, chunkSize = DECODE_CHUNK_SIZE) {
|
|
|
101
101
|
* whole input. Decoding is correct across multi-byte sequences split at a chunk
|
|
102
102
|
* boundary.
|
|
103
103
|
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
104
|
+
* Replaces an invalid sequence, including a truncated trailing one, with
|
|
105
|
+
* U+FFFD.
|
|
106
106
|
*
|
|
107
107
|
* Yields a trailing empty line when the input ends with a newline.
|
|
108
108
|
*/
|
|
@@ -137,7 +137,7 @@ const hasLeadingNulByte = (bytes) => bytes.subarray(0, NUL_SCAN_LENGTH).includes
|
|
|
137
137
|
const NUL_SCAN_LENGTH = 4096;
|
|
138
138
|
/** A streaming UTF-8 and line-splitting decoder. */
|
|
139
139
|
var Utf8LineDecoder = class {
|
|
140
|
-
#decoder = new TextDecoder(`utf-8
|
|
140
|
+
#decoder = new TextDecoder(`utf-8`);
|
|
141
141
|
#pending = ``;
|
|
142
142
|
*push(bytes) {
|
|
143
143
|
this.#pending += this.#decoder.decode(bytes, { stream: true });
|
|
@@ -145,11 +145,6 @@ var Utf8LineDecoder = class {
|
|
|
145
145
|
this.#pending = lines.pop();
|
|
146
146
|
for (const line of lines) yield stripCarriageReturn(line);
|
|
147
147
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Flush buffered bytes.
|
|
150
|
-
*
|
|
151
|
-
* @throws if a trailing sequence is truncated.
|
|
152
|
-
*/
|
|
153
148
|
*flush() {
|
|
154
149
|
this.#pending += this.#decoder.decode();
|
|
155
150
|
yield stripCarriageReturn(this.#pending);
|
|
@@ -1765,6 +1760,7 @@ const collapsedConverter = {
|
|
|
1765
1760
|
languages: [
|
|
1766
1761
|
`elixir`,
|
|
1767
1762
|
`java`,
|
|
1763
|
+
`php`,
|
|
1768
1764
|
`python`,
|
|
1769
1765
|
`ruby`
|
|
1770
1766
|
],
|
|
@@ -2576,7 +2572,7 @@ const CATEGORY_NAMES = {
|
|
|
2576
2572
|
stdlib: `Standard library`,
|
|
2577
2573
|
native: `Native`,
|
|
2578
2574
|
unknown: `Unknown`,
|
|
2579
|
-
"garbage
|
|
2575
|
+
"garbage-collector": `Garbage collector`,
|
|
2580
2576
|
compiler: `Compiler`,
|
|
2581
2577
|
jit: `JIT`,
|
|
2582
2578
|
kernel: `Kernel`,
|
|
@@ -2584,15 +2580,15 @@ const CATEGORY_NAMES = {
|
|
|
2584
2580
|
object: `Object`,
|
|
2585
2581
|
array: `Array`,
|
|
2586
2582
|
string: `String`,
|
|
2587
|
-
"concatenated
|
|
2588
|
-
"sliced
|
|
2583
|
+
"concatenated-string": `Concatenated string`,
|
|
2584
|
+
"sliced-string": `Sliced string`,
|
|
2589
2585
|
function: `Function`,
|
|
2590
2586
|
code: `Code`,
|
|
2591
2587
|
regexp: `Regular expression`,
|
|
2592
2588
|
number: `Number`,
|
|
2593
|
-
"big
|
|
2589
|
+
"big-number": `Big number`,
|
|
2594
2590
|
symbol: `Symbol`,
|
|
2595
|
-
"object
|
|
2591
|
+
"object-shape": `Object shape`,
|
|
2596
2592
|
internal: `Internal`,
|
|
2597
2593
|
synthetic: `Synthetic`
|
|
2598
2594
|
};
|
|
@@ -3659,16 +3655,16 @@ const HEAP_SNAPSHOT_NODE_CATEGORIES = [
|
|
|
3659
3655
|
`object`,
|
|
3660
3656
|
`array`,
|
|
3661
3657
|
`string`,
|
|
3662
|
-
`concatenated
|
|
3663
|
-
`sliced
|
|
3658
|
+
`concatenated-string`,
|
|
3659
|
+
`sliced-string`,
|
|
3664
3660
|
`function`,
|
|
3665
3661
|
`code`,
|
|
3666
3662
|
`regexp`,
|
|
3667
3663
|
`number`,
|
|
3668
|
-
`big
|
|
3664
|
+
`big-number`,
|
|
3669
3665
|
`symbol`,
|
|
3670
3666
|
`native`,
|
|
3671
|
-
`object
|
|
3667
|
+
`object-shape`,
|
|
3672
3668
|
`internal`,
|
|
3673
3669
|
`synthetic`,
|
|
3674
3670
|
`unknown`
|
|
@@ -4496,7 +4492,7 @@ const SYNTHETIC_FRAME_LABEL = /^\((?<label>[A-Za-z][A-Za-z0-9 _-]*)\)$/u;
|
|
|
4496
4492
|
* name (`jit`, `kernel`, `native`).
|
|
4497
4493
|
*/
|
|
4498
4494
|
const SYNTHETIC_FRAME_LABEL_CATEGORIES = /* @__PURE__ */ new Map([
|
|
4499
|
-
[`garbage collector`, `garbage
|
|
4495
|
+
[`garbage collector`, `garbage-collector`],
|
|
4500
4496
|
[`compiler`, `compiler`],
|
|
4501
4497
|
[`idle`, `idle`],
|
|
4502
4498
|
[`unknown`, `unknown`]
|
|
@@ -4599,7 +4595,7 @@ const JVM_STDLIB_PACKAGE = /^(?:(?:java|javax|jdk|sun|com[./]sun|kotlin|kotlinx|
|
|
|
4599
4595
|
*
|
|
4600
4596
|
* A GC write barrier is generated code executed inline in a compiled method, so
|
|
4601
4597
|
* it satisfies `jit` as literally as the dispatch stubs do. It is
|
|
4602
|
-
* `garbage
|
|
4598
|
+
* `garbage-collector` because a named activity takes precedence, leaving `jit`
|
|
4603
4599
|
* for generated code with no more specific one. Folding it into `jit` would
|
|
4604
4600
|
* hide the cost of collection and leave `jit` meaning two unrelated things.
|
|
4605
4601
|
*/
|
|
@@ -4607,7 +4603,7 @@ const hotspotRuntimeCategory = (entry) => {
|
|
|
4607
4603
|
const { name } = entry;
|
|
4608
4604
|
if (name === void 0 || !isHotspotNativeStackFrame(entry)) return;
|
|
4609
4605
|
if (JIT_STUB.test(name)) return `jit`;
|
|
4610
|
-
if (GC_STUB.test(name)) return `garbage
|
|
4606
|
+
if (GC_STUB.test(name)) return `garbage-collector`;
|
|
4611
4607
|
return HOTSPOT_COMPILER.test(name) ? `compiler` : void 0;
|
|
4612
4608
|
};
|
|
4613
4609
|
/**
|
|
@@ -4719,7 +4715,7 @@ const nativeModuleCategory = ({ name, location }) => location && !sourceReferenc
|
|
|
4719
4715
|
const jvmConstructorCategory = (name) => CLASS_NAME_TO_CATEGORY$1.get(name);
|
|
4720
4716
|
const CLASS_NAME_TO_CATEGORY$1 = new Map(Object.entries({
|
|
4721
4717
|
"java.lang.String": `string`,
|
|
4722
|
-
"java.lang.Class": `object
|
|
4718
|
+
"java.lang.Class": `object-shape`,
|
|
4723
4719
|
"java.util.regex.Pattern": `regexp`,
|
|
4724
4720
|
"java.lang.Byte": `number`,
|
|
4725
4721
|
"java.lang.Short": `number`,
|
|
@@ -4727,8 +4723,8 @@ const CLASS_NAME_TO_CATEGORY$1 = new Map(Object.entries({
|
|
|
4727
4723
|
"java.lang.Long": `number`,
|
|
4728
4724
|
"java.lang.Float": `number`,
|
|
4729
4725
|
"java.lang.Double": `number`,
|
|
4730
|
-
"java.math.BigInteger": `big
|
|
4731
|
-
"java.math.BigDecimal": `big
|
|
4726
|
+
"java.math.BigInteger": `big-number`,
|
|
4727
|
+
"java.math.BigDecimal": `big-number`
|
|
4732
4728
|
}));
|
|
4733
4729
|
/** Converts an internal class name (`java/util/Arrays`) to source form. */
|
|
4734
4730
|
const jvmSourceClassName = (internalName) => internalName.replaceAll(`/`, `.`);
|
|
@@ -5202,7 +5198,7 @@ const buildHeapSnapshot = (dump, nodes) => {
|
|
|
5202
5198
|
const unresolvedCategoryOf$2 = (nodeOrdinal, { bytes }, { recordOffsets }) => {
|
|
5203
5199
|
if (nodeOrdinal === GC_ROOT_ORDINAL) return { category: `synthetic` };
|
|
5204
5200
|
switch (bytes[recordOffsets[nodeOrdinal] - 1]) {
|
|
5205
|
-
case HPROF_GC_CLASS_DUMP: return { category: `object
|
|
5201
|
+
case HPROF_GC_CLASS_DUMP: return { category: `object-shape` };
|
|
5206
5202
|
case HPROF_GC_INSTANCE_DUMP: return { category: `object` };
|
|
5207
5203
|
default: return { category: `array` };
|
|
5208
5204
|
}
|
|
@@ -5769,11 +5765,11 @@ const CONTENTIONS = countMetricOf(`contention`, { improvement: `decrease` });
|
|
|
5769
5765
|
* metric and is ranked by its sample count.
|
|
5770
5766
|
*
|
|
5771
5767
|
* Allocation events sample: `jdk.ObjectAllocationSample` stands in for the
|
|
5772
|
-
* allocations since the previous one, a TLAB event
|
|
5773
|
-
*
|
|
5774
|
-
* `--nativemem <bytes>` set a sampling interval for the
|
|
5775
|
-
* `profiler.Malloc` events. Live-object and lock events each record
|
|
5776
|
-
* occurrence of what their kind names, so their rate is per object or per
|
|
5768
|
+
* allocations since the previous one, a TLAB event stands for a whole TLAB
|
|
5769
|
+
* refill or for one allocation made outside a TLAB, and async-profiler's
|
|
5770
|
+
* `--alloc <bytes>` and `--nativemem <bytes>` set a sampling interval for the
|
|
5771
|
+
* heap and `profiler.Malloc` events. Live-object and lock events each record
|
|
5772
|
+
* one occurrence of what their kind names, so their rate is per object or per
|
|
5777
5773
|
* contention rather than per sample.
|
|
5778
5774
|
*/
|
|
5779
5775
|
const KINDS = [
|
|
@@ -5836,7 +5832,7 @@ const EVENT_KINDS_BY_NAME = [
|
|
|
5836
5832
|
}],
|
|
5837
5833
|
[`jdk.ObjectAllocationInNewTLAB`, {
|
|
5838
5834
|
kind: `alloc`,
|
|
5839
|
-
weightField: `
|
|
5835
|
+
weightField: `tlabSize`,
|
|
5840
5836
|
allocFamily: `tlab`
|
|
5841
5837
|
}],
|
|
5842
5838
|
[`jdk.ObjectAllocationOutsideTLAB`, {
|
|
@@ -10447,16 +10443,16 @@ const V8_NODE_TYPE_TO_CATEGORY = /* @__PURE__ */ new Map([
|
|
|
10447
10443
|
[`object`, `object`],
|
|
10448
10444
|
[`array`, `array`],
|
|
10449
10445
|
[`string`, `string`],
|
|
10450
|
-
[`concatenated string`, `concatenated
|
|
10451
|
-
[`sliced string`, `sliced
|
|
10446
|
+
[`concatenated string`, `concatenated-string`],
|
|
10447
|
+
[`sliced string`, `sliced-string`],
|
|
10452
10448
|
[`closure`, `function`],
|
|
10453
10449
|
[`code`, `code`],
|
|
10454
10450
|
[`regexp`, `regexp`],
|
|
10455
10451
|
[`number`, `number`],
|
|
10456
|
-
[`bigint`, `big
|
|
10452
|
+
[`bigint`, `big-number`],
|
|
10457
10453
|
[`symbol`, `symbol`],
|
|
10458
10454
|
[`native`, `native`],
|
|
10459
|
-
[`object shape`, `object
|
|
10455
|
+
[`object shape`, `object-shape`],
|
|
10460
10456
|
[`hidden`, `internal`],
|
|
10461
10457
|
[`synthetic`, `synthetic`]
|
|
10462
10458
|
]);
|
|
@@ -10808,7 +10804,7 @@ const CATEGORY_TO_CLASS_NAMES = {
|
|
|
10808
10804
|
*/
|
|
10809
10805
|
const jscConstructorCategory = (name) => CLASS_NAME_TO_CATEGORY.get(name);
|
|
10810
10806
|
const CLASS_NAME_TO_CATEGORY = new Map(Object.entries({
|
|
10811
|
-
Structure: `object
|
|
10807
|
+
Structure: `object-shape`,
|
|
10812
10808
|
"Immutable Butterfly": `array`,
|
|
10813
10809
|
SparseArrayValueMap: `array`,
|
|
10814
10810
|
Callee: `function`,
|
|
@@ -11260,17 +11256,63 @@ const ELIXIR_CORE_MODULES = /* @__PURE__ */ new Set([
|
|
|
11260
11256
|
/**
|
|
11261
11257
|
* The Excimer sampling profiler for PHP.
|
|
11262
11258
|
*
|
|
11263
|
-
*
|
|
11264
|
-
*
|
|
11265
|
-
* parser's origin hint from the
|
|
11259
|
+
* Its speedscope output contains plain file paths and its collapsed output
|
|
11260
|
+
* contains no location, so {@link CLOSURE_FRAME} is the only evidence in either
|
|
11261
|
+
* format. Detection also uses the speedscope parser's origin hint from the
|
|
11262
|
+
* file's self-identifying `exporter` field.
|
|
11266
11263
|
*/
|
|
11267
11264
|
const excimerOriginSpec = {
|
|
11268
11265
|
id: `excimer`,
|
|
11269
11266
|
title: `Excimer`,
|
|
11270
|
-
formats: [`speedscope`],
|
|
11271
|
-
isMarkerEntry: () =>
|
|
11272
|
-
categorizeEntry:
|
|
11267
|
+
formats: [`collapsed`, `speedscope`],
|
|
11268
|
+
isMarkerEntry: ({ name }) => name !== void 0 && CLOSURE_FRAME.test(name),
|
|
11269
|
+
categorizeEntry: (entry) => vendorCategory(entry) ?? (entry.location ? `ours` : `unknown`),
|
|
11270
|
+
normalizeStackFrame: (input) => {
|
|
11271
|
+
const { name, location } = input;
|
|
11272
|
+
if (name === void 0) return input;
|
|
11273
|
+
const closure = CLOSURE_FRAME.exec(name);
|
|
11274
|
+
if (closure) {
|
|
11275
|
+
const { file, line } = closure.groups;
|
|
11276
|
+
return { location: {
|
|
11277
|
+
type: `file`,
|
|
11278
|
+
urlOrPath: file,
|
|
11279
|
+
line: Number(line)
|
|
11280
|
+
} };
|
|
11281
|
+
}
|
|
11282
|
+
if (location) return input;
|
|
11283
|
+
if (name.includes(`/`)) return { location: {
|
|
11284
|
+
type: `file`,
|
|
11285
|
+
urlOrPath: name
|
|
11286
|
+
} };
|
|
11287
|
+
const separator = name.lastIndexOf(`::`);
|
|
11288
|
+
if (separator === -1) return input;
|
|
11289
|
+
return {
|
|
11290
|
+
name: name.slice(separator + 2),
|
|
11291
|
+
location: {
|
|
11292
|
+
type: `logical`,
|
|
11293
|
+
name: name.slice(0, separator)
|
|
11294
|
+
}
|
|
11295
|
+
};
|
|
11296
|
+
}
|
|
11273
11297
|
};
|
|
11298
|
+
/**
|
|
11299
|
+
* An anonymous function, which Excimer names by its file and the line its
|
|
11300
|
+
* definition starts on: `{closure:/srv/app/Hooks.php(42)}`.
|
|
11301
|
+
*
|
|
11302
|
+
* PHP itself writes `{closure}`, and from 8.4 `{closure:/srv/app/Hooks.php:42}`,
|
|
11303
|
+
* so the parenthesized line marks Excimer's output in either format.
|
|
11304
|
+
*/
|
|
11305
|
+
const CLOSURE_FRAME = /^\{closure:(?<file>.+)\((?<line>\d+)\)\}$/su;
|
|
11306
|
+
/**
|
|
11307
|
+
* Categorizes a frame under Composer's `vendor/` as `third-party`.
|
|
11308
|
+
*
|
|
11309
|
+
* A collapsed frame keeps its declaring class instead of a file, and a class
|
|
11310
|
+
* name contains no install directory, so only file-scope and closure frames
|
|
11311
|
+
* reach this rule.
|
|
11312
|
+
*/
|
|
11313
|
+
const vendorCategory = ({ location }) => location && VENDOR_DIRECTORY.test(sourceReferencePathOrName(location)) ? `third-party` : void 0;
|
|
11314
|
+
/** Composer's install directory, at the root of a project or of a package. */
|
|
11315
|
+
const VENDOR_DIRECTORY = /(?:^|\/)vendor\//u;
|
|
11274
11316
|
|
|
11275
11317
|
//#endregion
|
|
11276
11318
|
//#region src/origins/specs/ghc.ts
|
|
@@ -11327,7 +11369,7 @@ const BOOT_LIBRARY_SOURCE = /^libraries\/[^/]+\//u;
|
|
|
11327
11369
|
*/
|
|
11328
11370
|
const runtimeActivityCategory = ({ name, location }) => location || name === void 0 ? void 0 : RUNTIME_ACTIVITY_CATEGORIES.get(name);
|
|
11329
11371
|
/** The built-in cost centre names that name a runtime activity. */
|
|
11330
|
-
const RUNTIME_ACTIVITY_CATEGORIES = /* @__PURE__ */ new Map([[`GC.GC`, `garbage
|
|
11372
|
+
const RUNTIME_ACTIVITY_CATEGORIES = /* @__PURE__ */ new Map([[`GC.GC`, `garbage-collector`], [`IDLE.IDLE`, `idle`]]);
|
|
11331
11373
|
|
|
11332
11374
|
//#endregion
|
|
11333
11375
|
//#region src/origins/specs/go.ts
|
|
@@ -11337,19 +11379,32 @@ const RUNTIME_ACTIVITY_CATEGORIES = /* @__PURE__ */ new Map([[`GC.GC`, `garbage
|
|
|
11337
11379
|
*
|
|
11338
11380
|
* Go function names embed the import path of their package
|
|
11339
11381
|
* (`encoding/json.Marshal`, `github.com/user/repo/pkg.Func`, `main.work`), so
|
|
11340
|
-
* categorization follows Go's own convention:
|
|
11341
|
-
*
|
|
11342
|
-
*
|
|
11382
|
+
* categorization follows Go's own convention: the `main` package is the
|
|
11383
|
+
* profiled program, and a first path segment naming a standard-library
|
|
11384
|
+
* package is Go's own code where the file agrees. A dependency's location
|
|
11385
|
+
* categorizes it, since the profiled program's own import paths may resemble a
|
|
11386
|
+
* dependency's.
|
|
11387
|
+
*
|
|
11388
|
+
* A `-trimpath` build rewrites every file path to the import path alone,
|
|
11389
|
+
* stripping the GOROOT prefix from the standard library and the module cache
|
|
11390
|
+
* prefix from a downloaded module, and leaves function names unchanged. The
|
|
11391
|
+
* profiled program's own packages keep their module path, so under `-trimpath`
|
|
11392
|
+
* they take the domain-like shape of a downloaded module. Only the module
|
|
11393
|
+
* cache's `@version` segment separates the two.
|
|
11394
|
+
*
|
|
11395
|
+
* A `GO111MODULE=off` build resolves a dependency and the profiled program's
|
|
11396
|
+
* own packages alike under `$GOPATH/src/`, under equally domain-like import
|
|
11397
|
+
* paths, so its dependencies are categorized `ours`.
|
|
11343
11398
|
*/
|
|
11344
11399
|
const goOriginSpec = {
|
|
11345
11400
|
id: `go`,
|
|
11346
11401
|
title: `pprof`,
|
|
11347
11402
|
formats: [`pprof`],
|
|
11348
|
-
isMarkerEntry: (entry) => (entry.name?.startsWith(`runtime.`) ?? false) &&
|
|
11349
|
-
categorizeEntry: (entry) => goCollectorCategory(entry) ??
|
|
11403
|
+
isMarkerEntry: (entry) => (entry.name?.startsWith(`runtime.`) ?? false) && isStdlibLocated(entry.location),
|
|
11404
|
+
categorizeEntry: (entry) => goCollectorCategory(entry) ?? goDependencyCategory(entry) ?? locationlessCategory(entry) ?? goPackageCategory(entry)
|
|
11350
11405
|
};
|
|
11351
11406
|
/**
|
|
11352
|
-
* Categorizes Go's collector as `garbage
|
|
11407
|
+
* Categorizes Go's collector as `garbage-collector`: the background mark
|
|
11353
11408
|
* workers and their drain loops, the sweeper, and the assist path a goroutine
|
|
11354
11409
|
* enters when it allocates faster than the collector reclaims.
|
|
11355
11410
|
*
|
|
@@ -11358,17 +11413,36 @@ const goOriginSpec = {
|
|
|
11358
11413
|
* would report most of a heap profile as collection cost, a claim the profile
|
|
11359
11414
|
* doesn't make.
|
|
11360
11415
|
*
|
|
11361
|
-
* The
|
|
11362
|
-
* matching, since the location distinguishes them
|
|
11416
|
+
* The standard-library guard keeps a package of the profiled program named
|
|
11417
|
+
* `runtime` from matching, since only the location distinguishes them.
|
|
11363
11418
|
*/
|
|
11364
|
-
const goCollectorCategory = ({ name, location }) => name !== void 0 && GO_COLLECTOR.test(name) && (location === void 0 ||
|
|
11419
|
+
const goCollectorCategory = ({ name, location }) => name !== void 0 && GO_COLLECTOR.test(name) && (location === void 0 || isStdlibLocated(location)) ? `garbage-collector` : void 0;
|
|
11365
11420
|
/** Go's collector entry points, all in the `runtime` package. */
|
|
11366
11421
|
const GO_COLLECTOR = /^runtime\.(?:gc(?!WriteBarrier)[A-Z]|gcstopm|bgsweep|sweepone|\(\*sweepLocked\)\.sweep)/u;
|
|
11367
11422
|
/**
|
|
11368
|
-
* Categorizes a frame resolved from
|
|
11369
|
-
*
|
|
11423
|
+
* Categorizes a frame resolved from a dependency as `third-party`.
|
|
11424
|
+
*
|
|
11425
|
+
* `go get` writes a downloaded module to `$GOPATH/pkg/mod/`, in a directory
|
|
11426
|
+
* whose name ends with `@version`. A `-trimpath` build strips the prefix and
|
|
11427
|
+
* leaves the `@version` segment. `go mod vendor` instead copies a dependency
|
|
11428
|
+
* into the profiled program's own `vendor/` directory, a path with neither the
|
|
11429
|
+
* prefix nor the `@version` segment.
|
|
11430
|
+
*
|
|
11431
|
+
* The standard library vendors packages of its own, so the standard-library
|
|
11432
|
+
* check runs first.
|
|
11433
|
+
*/
|
|
11434
|
+
const goDependencyCategory = ({ location }) => {
|
|
11435
|
+
if (!location || isStdlibLocated(location)) return;
|
|
11436
|
+
const path = sourceReferencePathOrName(location);
|
|
11437
|
+
return path.includes(`/pkg/mod/`) || path.includes(`/vendor/`) || MODULE_CACHE_VERSION.test(path) ? `third-party` : void 0;
|
|
11438
|
+
};
|
|
11439
|
+
/**
|
|
11440
|
+
* The `@version` a module cache directory name ends with. Every Go module
|
|
11441
|
+
* version starts with a `v` followed by the major number, so the pattern
|
|
11442
|
+
* distinguishes the segment from an `@` in a directory containing the profiled
|
|
11443
|
+
* program.
|
|
11370
11444
|
*/
|
|
11371
|
-
const
|
|
11445
|
+
const MODULE_CACHE_VERSION = /@v\d/u;
|
|
11372
11446
|
/**
|
|
11373
11447
|
* Categorizes a located frame by the import path embedded in its function name.
|
|
11374
11448
|
*
|
|
@@ -11376,14 +11450,116 @@ const goModuleCacheCategory = ({ location }) => location && sourceReferencePathO
|
|
|
11376
11450
|
* before here.
|
|
11377
11451
|
*/
|
|
11378
11452
|
const goPackageCategory = ({ name, location }) => {
|
|
11379
|
-
|
|
11453
|
+
const stdlibLocated = isStdlibLocated(location);
|
|
11454
|
+
if (name === void 0) return stdlibLocated ? `stdlib` : `ours`;
|
|
11380
11455
|
if (name === `main` || name.startsWith(`main.`)) return `ours`;
|
|
11381
|
-
const
|
|
11382
|
-
if (
|
|
11383
|
-
|
|
11384
|
-
|
|
11385
|
-
|
|
11456
|
+
const packagePath = goPackagePath(name);
|
|
11457
|
+
if (packagePath === void 0) return stdlibLocated ? `stdlib` : `ours`;
|
|
11458
|
+
return GO_STDLIB_PACKAGES.has(packagePath.split(`/`)[0]) && stdlibLocated ? `stdlib` : `ours`;
|
|
11459
|
+
};
|
|
11460
|
+
/**
|
|
11461
|
+
* Returns the import path of the package {@link name} declares, or `undefined`
|
|
11462
|
+
* for a bare linker symbol with no package.
|
|
11463
|
+
*
|
|
11464
|
+
* The symbol follows the import path after a dot, and both may contain further
|
|
11465
|
+
* dots (`encoding/json.(*decodeState).value`), so the package ends at the
|
|
11466
|
+
* first dot after the last slash. A generic instantiation's type arguments
|
|
11467
|
+
* contain import paths of their own
|
|
11468
|
+
* (`slices.Sort[go.shape.[]github.com/user/repo.T]`), so they are dropped
|
|
11469
|
+
* first.
|
|
11470
|
+
*/
|
|
11471
|
+
const goPackagePath = (name) => {
|
|
11472
|
+
const path = name.slice(0, indexOrEnd(name, `[`));
|
|
11473
|
+
const dot = path.indexOf(`.`, path.lastIndexOf(`/`) + 1);
|
|
11474
|
+
return dot === -1 ? void 0 : path.slice(0, dot);
|
|
11475
|
+
};
|
|
11476
|
+
const indexOrEnd = (value, search) => {
|
|
11477
|
+
const index = value.indexOf(search);
|
|
11478
|
+
return index === -1 ? value.length : index;
|
|
11386
11479
|
};
|
|
11480
|
+
/**
|
|
11481
|
+
* Returns whether {@link location} is in Go's own standard library.
|
|
11482
|
+
*
|
|
11483
|
+
* An ordinary build locates it in a GOROOT source tree. A `-trimpath` build
|
|
11484
|
+
* leaves each file at the relative import path of the package declaring it,
|
|
11485
|
+
* which starts with a standard-library package name. The path's own package
|
|
11486
|
+
* categorizes the frame, since Go inlines across packages and reports the
|
|
11487
|
+
* inlined frame at the file it was inlined into (`reflect.typedmemmove` at
|
|
11488
|
+
* `runtime/mbarrier.go`).
|
|
11489
|
+
*
|
|
11490
|
+
* The extension excludes a relative path another language's profiler wrote,
|
|
11491
|
+
* since the Go toolchain compiles Go and assembly sources alone. An absolute
|
|
11492
|
+
* path starts with an empty segment, which no package name matches.
|
|
11493
|
+
*/
|
|
11494
|
+
const isStdlibLocated = (location) => {
|
|
11495
|
+
if (!location) return false;
|
|
11496
|
+
const path = sourceReferencePathOrName(location);
|
|
11497
|
+
return path.includes(`/go/src/`) || GO_STDLIB_PACKAGES.has(path.slice(0, indexOrEnd(path, `/`))) && GO_SOURCE_EXTENSION.test(path);
|
|
11498
|
+
};
|
|
11499
|
+
/** The extensions of the source files the Go compiler and assembler read. */
|
|
11500
|
+
const GO_SOURCE_EXTENSION = /\.(?:go|s)$/u;
|
|
11501
|
+
/**
|
|
11502
|
+
* Go's top-level standard-library import paths, as reported by `go list std`.
|
|
11503
|
+
* A dot-less first segment is reserved for the standard library, but the `go`
|
|
11504
|
+
* command still accepts a domain-less module path, so matching the set rather
|
|
11505
|
+
* than the shape keeps such a module's packages out of `stdlib`.
|
|
11506
|
+
*
|
|
11507
|
+
* Keep this set in sync with `go-std-packages.txt`, a pinned `go list std`,
|
|
11508
|
+
* since a top-level package a later Go release adds would otherwise be
|
|
11509
|
+
* categorized `ours`.
|
|
11510
|
+
*/
|
|
11511
|
+
const GO_STDLIB_PACKAGES = /* @__PURE__ */ new Set([
|
|
11512
|
+
`archive`,
|
|
11513
|
+
`bufio`,
|
|
11514
|
+
`bytes`,
|
|
11515
|
+
`cmp`,
|
|
11516
|
+
`compress`,
|
|
11517
|
+
`container`,
|
|
11518
|
+
`context`,
|
|
11519
|
+
`crypto`,
|
|
11520
|
+
`database`,
|
|
11521
|
+
`debug`,
|
|
11522
|
+
`embed`,
|
|
11523
|
+
`encoding`,
|
|
11524
|
+
`errors`,
|
|
11525
|
+
`expvar`,
|
|
11526
|
+
`flag`,
|
|
11527
|
+
`fmt`,
|
|
11528
|
+
`go`,
|
|
11529
|
+
`hash`,
|
|
11530
|
+
`html`,
|
|
11531
|
+
`image`,
|
|
11532
|
+
`index`,
|
|
11533
|
+
`internal`,
|
|
11534
|
+
`io`,
|
|
11535
|
+
`iter`,
|
|
11536
|
+
`log`,
|
|
11537
|
+
`maps`,
|
|
11538
|
+
`math`,
|
|
11539
|
+
`mime`,
|
|
11540
|
+
`net`,
|
|
11541
|
+
`os`,
|
|
11542
|
+
`path`,
|
|
11543
|
+
`plugin`,
|
|
11544
|
+
`reflect`,
|
|
11545
|
+
`regexp`,
|
|
11546
|
+
`runtime`,
|
|
11547
|
+
`slices`,
|
|
11548
|
+
`sort`,
|
|
11549
|
+
`strconv`,
|
|
11550
|
+
`strings`,
|
|
11551
|
+
`structs`,
|
|
11552
|
+
`sync`,
|
|
11553
|
+
`syscall`,
|
|
11554
|
+
`testing`,
|
|
11555
|
+
`text`,
|
|
11556
|
+
`time`,
|
|
11557
|
+
`unicode`,
|
|
11558
|
+
`unique`,
|
|
11559
|
+
`unsafe`,
|
|
11560
|
+
`vendor`,
|
|
11561
|
+
`weak`
|
|
11562
|
+
]);
|
|
11387
11563
|
|
|
11388
11564
|
//#endregion
|
|
11389
11565
|
//#region src/origins/swift.ts
|
|
@@ -11549,9 +11725,9 @@ const PACKED_ANONYMOUS = /^\(anonymous:L#(?<line>\d+):C#(?<column>\d+)\)$/u;
|
|
|
11549
11725
|
const NODE_PROTOCOLS$1 = [`node:`];
|
|
11550
11726
|
/**
|
|
11551
11727
|
* Categorizes the `pprof` package's garbage-collection frame, labelled
|
|
11552
|
-
* `Garbage Collection`, as `garbage
|
|
11728
|
+
* `Garbage Collection`, as `garbage-collector`.
|
|
11553
11729
|
*/
|
|
11554
|
-
const garbageCollectionCategory = ({ name }) => name === `Garbage Collection` ? `garbage
|
|
11730
|
+
const garbageCollectionCategory = ({ name }) => name === `Garbage Collection` ? `garbage-collector` : void 0;
|
|
11555
11731
|
|
|
11556
11732
|
//#endregion
|
|
11557
11733
|
//#region src/origins/specs/node.ts
|
|
@@ -11724,8 +11900,8 @@ const JULIA_TYPE_CATEGORIES = new Map([
|
|
|
11724
11900
|
[`Symbol`, `symbol`],
|
|
11725
11901
|
[`Regex`, `regexp`],
|
|
11726
11902
|
[`Base.Regex`, `regexp`],
|
|
11727
|
-
[`BigInt`, `big
|
|
11728
|
-
[`BigFloat`, `big
|
|
11903
|
+
[`BigInt`, `big-number`],
|
|
11904
|
+
[`BigFloat`, `big-number`],
|
|
11729
11905
|
[`Base.BitSet`, `array`],
|
|
11730
11906
|
[`Core.SimpleVector`, `array`],
|
|
11731
11907
|
...[`Bool`, `Char`].map((name) => [name, `number`]),
|
|
@@ -14240,7 +14416,7 @@ const FUNCTION_CATEGORIES = [
|
|
|
14240
14416
|
`stdlib`,
|
|
14241
14417
|
`native`,
|
|
14242
14418
|
`unknown`,
|
|
14243
|
-
`garbage
|
|
14419
|
+
`garbage-collector`,
|
|
14244
14420
|
`compiler`,
|
|
14245
14421
|
`jit`,
|
|
14246
14422
|
`regexp`,
|
|
@@ -14344,8 +14520,8 @@ const isSyntheticEntry = ({ name, category }) => !TEXT_CATEGORIES.has(category)
|
|
|
14344
14520
|
/** The categories of a heap snapshot node named by the text it holds. */
|
|
14345
14521
|
const TEXT_CATEGORIES = /* @__PURE__ */ new Set([
|
|
14346
14522
|
`string`,
|
|
14347
|
-
`concatenated
|
|
14348
|
-
`sliced
|
|
14523
|
+
`concatenated-string`,
|
|
14524
|
+
`sliced-string`
|
|
14349
14525
|
]);
|
|
14350
14526
|
|
|
14351
14527
|
//#endregion
|
|
@@ -14603,7 +14779,7 @@ const collectInferableURLs = (inputs, options) => {
|
|
|
14603
14779
|
//#endregion
|
|
14604
14780
|
//#region package.json
|
|
14605
14781
|
var name = "profiler-md";
|
|
14606
|
-
var version = "0.
|
|
14782
|
+
var version = "0.8.0";
|
|
14607
14783
|
var description = "Converts performance profiles to human and LLM friendly Markdown.";
|
|
14608
14784
|
|
|
14609
14785
|
//#endregion
|
|
@@ -14816,10 +14992,13 @@ const regexCategory = () => ({
|
|
|
14816
14992
|
},
|
|
14817
14993
|
format: ([regex, category]) => `${regex.source}=${category}`
|
|
14818
14994
|
});
|
|
14995
|
+
/** The `--format` and `--origin` value meaning the format or origin is detected. */
|
|
14996
|
+
const AUTO = `auto`;
|
|
14997
|
+
const specified = (value) => value === AUTO ? void 0 : value;
|
|
14819
14998
|
const parser = object({
|
|
14820
14999
|
help: optional(or(option(`-h`, `--help`, choice(helpTopics, { metavar: `[TOPIC]` }), { description: message`Show this help message or topic docs` }), flag(`-h`, `--help`, { hidden: `help` }))),
|
|
14821
|
-
format: optional(option(`-f`, `--format`, choice(formats, { metavar: `FORMAT` }), { description: message`Input profile format (default: auto)` })),
|
|
14822
|
-
origin: optional(option(`-r`, `--origin`, choice(origins, { metavar: `ORIGIN` }), { description: message`Input profile origin (default: auto)` })),
|
|
15000
|
+
format: map(optional(option(`-f`, `--format`, choice([AUTO, ...formats], { metavar: `FORMAT` }), { description: message`Input profile format (default: auto)` })), specified),
|
|
15001
|
+
origin: map(optional(option(`-r`, `--origin`, choice([AUTO, ...origins], { metavar: `ORIGIN` }), { description: message`Input profile origin (default: auto)` })), specified),
|
|
14823
15002
|
output: withDefault(option(`-o`, `--output`, path({ metavar: `FILE` }), { description: message`Output file (default: - for stdout)` }), `-`),
|
|
14824
15003
|
topN: optional(option(`--top-n`, integer({ metavar: `N` }), { description: message`Entries to show per ranking, including category subsections (default: 20)` })),
|
|
14825
15004
|
minCategoryShare: optional(option(`--min-category-share`, float({
|
|
@@ -14909,6 +15088,7 @@ const reportError = (error) => {
|
|
|
14909
15088
|
process.stderr.write(`error: ${String(error)}\n`);
|
|
14910
15089
|
process.exit(1);
|
|
14911
15090
|
};
|
|
15091
|
+
const reasonOf = (error) => error instanceof Error ? error.message : String(error);
|
|
14912
15092
|
|
|
14913
15093
|
//#endregion
|
|
14914
15094
|
//#region src/cli/ansis.ts
|
|
@@ -14978,16 +15158,29 @@ const writeOutput = async (text, outputPath, { pager }) => {
|
|
|
14978
15158
|
const isTTYOutput = (outputPath) => outputPath === `-` && Boolean(process.stdout.isTTY);
|
|
14979
15159
|
const openOutput = async (outputPath) => {
|
|
14980
15160
|
if (outputPath === `-`) return { write: (text) => new Promise((resolve, reject) => {
|
|
14981
|
-
|
|
15161
|
+
const finish = (error) => {
|
|
15162
|
+
if (!error || error.code === `EPIPE`) resolve();
|
|
15163
|
+
else reject(error);
|
|
15164
|
+
};
|
|
15165
|
+
process.stdout.on(`error`, finish);
|
|
15166
|
+
process.stdout.write(text, finish);
|
|
14982
15167
|
}) };
|
|
14983
15168
|
const stream = createWriteStream(outputPath);
|
|
14984
15169
|
await new Promise((resolve, reject) => {
|
|
14985
|
-
stream.once(`open`, () => resolve()).once(`error`, reject);
|
|
15170
|
+
stream.once(`open`, () => resolve()).once(`error`, (error) => reject(writeError(outputPath, error)));
|
|
14986
15171
|
});
|
|
14987
15172
|
return { write: (text) => new Promise((resolve, reject) => {
|
|
14988
|
-
stream.write(text, (error) => error ? reject(error) : stream.end(resolve));
|
|
15173
|
+
stream.write(text, (error) => error ? reject(writeError(outputPath, error)) : stream.end(resolve));
|
|
14989
15174
|
}) };
|
|
14990
15175
|
};
|
|
15176
|
+
const writeError = (outputPath, error) => new CliError(`cannot write ${outputPath}: ${WRITE_ERROR_REASONS.get(errorCodeOf(error)) ?? reasonOf(error)}`, 1, { cause: error });
|
|
15177
|
+
const errorCodeOf = (error) => error instanceof Error && `code` in error && typeof error.code === `string` ? error.code : void 0;
|
|
15178
|
+
const WRITE_ERROR_REASONS = /* @__PURE__ */ new Map([
|
|
15179
|
+
[`ENOENT`, `no such directory`],
|
|
15180
|
+
[`EISDIR`, `is a directory`],
|
|
15181
|
+
[`EACCES`, `permission denied`],
|
|
15182
|
+
[`EPERM`, `permission denied`]
|
|
15183
|
+
]);
|
|
14991
15184
|
|
|
14992
15185
|
//#endregion
|
|
14993
15186
|
//#region src/cli/theme-kindling.ts
|
|
@@ -15604,7 +15797,7 @@ const printHelpTopic = async (topic, { pager }) => {
|
|
|
15604
15797
|
//#region src/cli/input.ts
|
|
15605
15798
|
const openInputAsBlob = async (filePath) => decompressBlob(await openRawInputAsBlob(filePath), filePath);
|
|
15606
15799
|
const openRawInputAsBlob = async (filePath) => {
|
|
15607
|
-
if (!filePath) return
|
|
15800
|
+
if (!filePath || STDIN_PATHS.has(filePath)) return await readStreamAsBlob(process.stdin, filePath ?? `stdin`);
|
|
15608
15801
|
let stats;
|
|
15609
15802
|
try {
|
|
15610
15803
|
stats = await stat(filePath);
|
|
@@ -15613,12 +15806,37 @@ const openRawInputAsBlob = async (filePath) => {
|
|
|
15613
15806
|
throw new CliError(`cannot read ${filePath}: ${reasonOf(error)}`, 1, { cause: error });
|
|
15614
15807
|
}
|
|
15615
15808
|
if (stats.isDirectory()) throw new CliError(`cannot read ${filePath}: is a directory`, 1);
|
|
15809
|
+
try {
|
|
15810
|
+
await access(filePath, constants.R_OK);
|
|
15811
|
+
} catch (error) {
|
|
15812
|
+
throw new CliError(`cannot read ${filePath}: permission denied`, 1, { cause: error });
|
|
15813
|
+
}
|
|
15814
|
+
if (!stats.isFile()) return await readStreamAsBlob(createReadStream(filePath), filePath);
|
|
15616
15815
|
try {
|
|
15617
15816
|
return await openAsBlob(filePath);
|
|
15618
15817
|
} catch (error) {
|
|
15619
15818
|
throw new CliError(`cannot read ${filePath}: ${reasonOf(error)}`, 1, { cause: error });
|
|
15620
15819
|
}
|
|
15621
15820
|
};
|
|
15821
|
+
/**
|
|
15822
|
+
* The paths that name the process's own standard input.
|
|
15823
|
+
*
|
|
15824
|
+
* Opening one of these paths creates a second descriptor on the same pipe, and
|
|
15825
|
+
* reads on it fail with `EAGAIN`, so read `process.stdin` instead.
|
|
15826
|
+
*/
|
|
15827
|
+
const STDIN_PATHS = /* @__PURE__ */ new Set([
|
|
15828
|
+
`-`,
|
|
15829
|
+
`/dev/stdin`,
|
|
15830
|
+
`/dev/fd/0`,
|
|
15831
|
+
`/proc/self/fd/0`
|
|
15832
|
+
]);
|
|
15833
|
+
const readStreamAsBlob = async (stream, source) => {
|
|
15834
|
+
try {
|
|
15835
|
+
return await blob(stream);
|
|
15836
|
+
} catch (error) {
|
|
15837
|
+
throw new CliError(`cannot read ${source}: ${reasonOf(error)}`, 1, { cause: error });
|
|
15838
|
+
}
|
|
15839
|
+
};
|
|
15622
15840
|
const decompressBlob = async (data, filePath) => {
|
|
15623
15841
|
try {
|
|
15624
15842
|
if (filePath?.endsWith(`.br`)) return await decompressStream(data, createBrotliDecompress({ chunkSize: DECOMPRESS_CHUNK_SIZE }));
|
|
@@ -15629,7 +15847,6 @@ const decompressBlob = async (data, filePath) => {
|
|
|
15629
15847
|
throw new CliError(`cannot decompress ${filePath ?? `stdin`}: ${reasonOf(error)}`, 1, { cause: error });
|
|
15630
15848
|
}
|
|
15631
15849
|
};
|
|
15632
|
-
const reasonOf = (error) => error instanceof Error ? error.message : String(error);
|
|
15633
15850
|
/**
|
|
15634
15851
|
* The output buffer size for the decompression transforms. With zlib's 16 KiB
|
|
15635
15852
|
* default, a transform emits a large decompressed input as thousands of
|
|
@@ -15698,13 +15915,25 @@ const matchesEntry = (regex, { name, location }) => name !== void 0 && regex.tes
|
|
|
15698
15915
|
const loadSourceMaps = async (patterns) => {
|
|
15699
15916
|
const paths = (await Promise.all(patterns.map((pattern) => Array.fromAsync(glob(pattern))))).flat();
|
|
15700
15917
|
return Promise.all(paths.map(async (path) => {
|
|
15701
|
-
|
|
15702
|
-
|
|
15703
|
-
|
|
15704
|
-
|
|
15705
|
-
|
|
15918
|
+
let content;
|
|
15919
|
+
try {
|
|
15920
|
+
content = await readFile(path, `utf8`);
|
|
15921
|
+
} catch (error) {
|
|
15922
|
+
throw new CliError(`cannot read source map ${path}: ${reasonOf(error)}`, 1, { cause: error });
|
|
15923
|
+
}
|
|
15924
|
+
try {
|
|
15925
|
+
return parseSourceMap(content, path);
|
|
15926
|
+
} catch (error) {
|
|
15927
|
+
throw new CliError(`cannot parse source map ${path}: ${reasonOf(error)}`, 1, { cause: error });
|
|
15928
|
+
}
|
|
15706
15929
|
}));
|
|
15707
15930
|
};
|
|
15931
|
+
const parseSourceMap = (content, path) => {
|
|
15932
|
+
const inlineSourceMap = convertSourceMap.fromSource(content)?.toObject();
|
|
15933
|
+
if (!inlineSourceMap) return resolveSourceMapSources(JSON.parse(content), path);
|
|
15934
|
+
inlineSourceMap.file ??= pathToFileURL(resolve(path)).href;
|
|
15935
|
+
return resolveSourceMapSources(inlineSourceMap, path);
|
|
15936
|
+
};
|
|
15708
15937
|
/**
|
|
15709
15938
|
* Pre-resolves relative source paths against the map file's directory so that
|
|
15710
15939
|
* `source-map-js` returns absolute URLs.
|