ostia 0.3.0 → 0.3.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.
- package/index.d.ts +62 -35
- package/package.json +1 -1
- package/src/ab/ab-runner.ts +57 -44
- package/src/ab/index.ts +186 -112
- package/src/baseline/index.ts +3 -9
- package/src/bench/index.ts +177 -123
- package/src/bench/projects.ts +14 -10
- package/src/bench/registry.ts +68 -66
- package/src/bench/run-tasks.ts +26 -23
- package/src/bench/run.ts +2 -1
- package/src/bench/runner.ts +20 -5
- package/src/bench/support.ts +26 -26
- package/src/bench/sweep.ts +6 -4
- package/src/cache/fingerprint.ts +9 -6
- package/src/cache/store.ts +17 -5
- package/src/capture/bunflags.ts +12 -11
- package/src/capture/cpu-parse.ts +36 -24
- package/src/capture/cpu.ts +7 -4
- package/src/capture/frames.ts +7 -1
- package/src/capture/heap-parse.ts +30 -5
- package/src/capture/heap.ts +9 -5
- package/src/capture/inspector.ts +8 -7
- package/src/capture/jsc-parse.ts +8 -8
- package/src/capture/jsc.ts +4 -4
- package/src/ci/index.ts +64 -40
- package/src/cli/flags.ts +42 -43
- package/src/cli/output.ts +29 -35
- package/src/cli/run.ts +95 -95
- package/src/compare/index.ts +39 -32
- package/src/config/env.ts +13 -0
- package/src/config/index.ts +31 -23
- package/src/config/validate.ts +33 -27
- package/src/format.ts +5 -6
- package/src/glob.ts +9 -12
- package/src/index.ts +1 -3
- package/src/ir/cpu.ts +2 -2
- package/src/ir/defined.ts +12 -0
- package/src/ir/document.ts +93 -73
- package/src/ir/fp.ts +7 -10
- package/src/ir/git.ts +4 -3
- package/src/measure/alloc.ts +7 -8
- package/src/measure/cpu.ts +12 -20
- package/src/measure/environment.ts +5 -8
- package/src/measure/inprocess.ts +15 -15
- package/src/measure/instructions.ts +22 -16
- package/src/measure/loop.ts +24 -17
- package/src/measure/noise.ts +8 -8
- package/src/measure/paired.ts +39 -47
- package/src/measure/peak.ts +20 -21
- package/src/measure/timing.ts +23 -23
- package/src/profile.ts +2 -1
- package/src/renderers/collapsed.ts +28 -21
- package/src/renderers/cpu-tree.ts +43 -35
- package/src/renderers/format.ts +16 -26
- package/src/renderers/index.ts +14 -4
- package/src/renderers/json.ts +2 -2
- package/src/renderers/jsonl.ts +11 -7
- package/src/renderers/markdown.ts +54 -36
- package/src/renderers/mermaid.ts +43 -31
- package/src/renderers/minimal.ts +12 -12
- package/src/renderers/paired.ts +31 -37
- package/src/renderers/relative.ts +10 -14
- package/src/renderers/select.ts +17 -39
- package/src/renderers/speedscope.ts +52 -48
- package/src/renderers/terminal.ts +37 -33
- package/src/spawn/index.ts +38 -47
- package/src/stats/bootstrap.ts +56 -58
- package/src/stats/index.ts +16 -12
- package/src/stats/mannwhitney.ts +11 -10
- package/src/time.ts +51 -39
package/src/capture/bunflags.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { processEnv } from "../config/env.ts";
|
|
1
2
|
import type { Warning } from "../ir/types.ts";
|
|
2
3
|
|
|
3
4
|
// BUN_OPTIONS is split on whitespace; a backslash escapes a space or quote
|
|
@@ -18,7 +19,10 @@ export function withBunFlags(
|
|
|
18
19
|
}
|
|
19
20
|
// A wrapper script that eventually execs bun still picks the flags up.
|
|
20
21
|
// Ours go last so they win over any the caller already set.
|
|
21
|
-
const merged
|
|
22
|
+
const merged: Record<string, string> = {};
|
|
23
|
+
for (const [key, value] of Object.entries({ ...processEnv(), ...env })) {
|
|
24
|
+
if (value !== undefined) merged[key] = value;
|
|
25
|
+
}
|
|
22
26
|
const ours = flags.map(escapeBunOption).join(" ");
|
|
23
27
|
return {
|
|
24
28
|
argv,
|
|
@@ -37,29 +41,26 @@ export interface ProfiledRunOptions {
|
|
|
37
41
|
fileName: string;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
|
-
|
|
44
|
+
interface ProfiledRun {
|
|
41
45
|
diagnosticWallNs: number;
|
|
42
46
|
exitCode: number;
|
|
43
47
|
artifactPath?: string;
|
|
44
|
-
raw?:
|
|
48
|
+
raw?: unknown;
|
|
45
49
|
warnings: Warning[];
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
* artifact it wrote; `raw` is absent (with an `artifact-missing` warning)
|
|
50
|
-
* when none appeared. */
|
|
51
|
-
export async function runProfiled<T>(
|
|
52
|
+
export async function runProfiled(
|
|
52
53
|
opts: ProfiledRunOptions,
|
|
53
54
|
flags: string[],
|
|
54
55
|
artifact: { what: string; kind: string },
|
|
55
|
-
): Promise<ProfiledRun
|
|
56
|
+
): Promise<ProfiledRun> {
|
|
56
57
|
const artifactPath = `${opts.artifactDir}/${opts.fileName}`;
|
|
57
58
|
const { argv, env } = withBunFlags(opts.argv, flags, opts.env);
|
|
58
59
|
|
|
59
60
|
const start = Bun.nanoseconds();
|
|
60
61
|
const proc = Bun.spawn(argv, {
|
|
61
|
-
cwd: opts.cwd,
|
|
62
|
-
env,
|
|
62
|
+
...(opts.cwd !== undefined && { cwd: opts.cwd }),
|
|
63
|
+
...(env !== undefined && { env }),
|
|
63
64
|
stdout: "ignore",
|
|
64
65
|
stderr: "ignore",
|
|
65
66
|
stdin: "ignore",
|
|
@@ -85,7 +86,7 @@ export async function runProfiled<T>(
|
|
|
85
86
|
diagnosticWallNs,
|
|
86
87
|
exitCode,
|
|
87
88
|
artifactPath,
|
|
88
|
-
raw:
|
|
89
|
+
raw: await file.json(),
|
|
89
90
|
warnings: [],
|
|
90
91
|
};
|
|
91
92
|
}
|
package/src/capture/cpu-parse.ts
CHANGED
|
@@ -24,8 +24,22 @@ export interface RawCpuProfile {
|
|
|
24
24
|
timeDeltas: number[];
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
//
|
|
28
|
-
|
|
27
|
+
// Checks only the arrays `parseCpuProfile` walks, not each node.
|
|
28
|
+
export function isRawCpuProfile(value: unknown): value is RawCpuProfile {
|
|
29
|
+
return (
|
|
30
|
+
typeof value === "object" &&
|
|
31
|
+
value !== null &&
|
|
32
|
+
"nodes" in value &&
|
|
33
|
+
Array.isArray(value.nodes) &&
|
|
34
|
+
"samples" in value &&
|
|
35
|
+
Array.isArray(value.samples) &&
|
|
36
|
+
"timeDeltas" in value &&
|
|
37
|
+
Array.isArray(value.timeDeltas)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// spec: cpu-prof and the inspector report sourcemapped `file://` URLs and
|
|
42
|
+
// 0-based lines (jsc's are 1-based).
|
|
29
43
|
function normalizeUrl(url: string): string {
|
|
30
44
|
return url.startsWith("file://") ? url.slice("file://".length) : url;
|
|
31
45
|
}
|
|
@@ -40,10 +54,9 @@ export function parseCpuProfile(
|
|
|
40
54
|
|
|
41
55
|
const { frames, intern } = createFrameTable();
|
|
42
56
|
const indexById = new Map<number, number>();
|
|
43
|
-
const nodes
|
|
57
|
+
const nodes = new Array<CallNode>(count);
|
|
44
58
|
|
|
45
|
-
for (
|
|
46
|
-
const node = rawNodes[i]!;
|
|
59
|
+
for (const [i, node] of rawNodes.entries()) {
|
|
47
60
|
const cf = node.callFrame;
|
|
48
61
|
const frameIx = intern(
|
|
49
62
|
cf.functionName,
|
|
@@ -59,16 +72,16 @@ export function parseCpuProfile(
|
|
|
59
72
|
const sampleCount = new Float64Array(count);
|
|
60
73
|
const sampleIds = raw.samples;
|
|
61
74
|
const deltas = raw.timeDeltas;
|
|
62
|
-
for (
|
|
63
|
-
const ix = indexById.get(
|
|
75
|
+
for (const [i, id] of sampleIds.entries()) {
|
|
76
|
+
const ix = indexById.get(id);
|
|
64
77
|
if (ix === undefined) continue;
|
|
65
|
-
selfUs[ix]
|
|
66
|
-
sampleCount[ix]
|
|
78
|
+
selfUs[ix] = (selfUs[ix] ?? 0) + (deltas[i] ?? 0);
|
|
79
|
+
sampleCount[ix] = (sampleCount[ix] ?? 0) + 1;
|
|
67
80
|
}
|
|
68
81
|
|
|
69
82
|
const parentIx = new Int32Array(count).fill(-1);
|
|
70
|
-
for (
|
|
71
|
-
const children =
|
|
83
|
+
for (const [i, node] of rawNodes.entries()) {
|
|
84
|
+
const children = node.children;
|
|
72
85
|
if (!children) continue;
|
|
73
86
|
for (const childId of children) {
|
|
74
87
|
const c = indexById.get(childId);
|
|
@@ -79,10 +92,9 @@ export function parseCpuProfile(
|
|
|
79
92
|
const order: number[] = [];
|
|
80
93
|
const stack: number[] = [];
|
|
81
94
|
for (let i = count - 1; i >= 0; i--) if (parentIx[i] === -1) stack.push(i);
|
|
82
|
-
|
|
83
|
-
const i = stack.pop()!;
|
|
95
|
+
for (let i = stack.pop(); i !== undefined; i = stack.pop()) {
|
|
84
96
|
order.push(i);
|
|
85
|
-
const children = rawNodes[i]
|
|
97
|
+
const children = rawNodes[i]?.children;
|
|
86
98
|
if (!children) continue;
|
|
87
99
|
for (const childId of children) {
|
|
88
100
|
const c = indexById.get(childId);
|
|
@@ -90,21 +102,21 @@ export function parseCpuProfile(
|
|
|
90
102
|
}
|
|
91
103
|
}
|
|
92
104
|
const totalUs = new Float64Array(count);
|
|
93
|
-
for (
|
|
94
|
-
const
|
|
95
|
-
totalUs[i]
|
|
96
|
-
const p = parentIx[i]
|
|
97
|
-
if (p >= 0) totalUs[p]
|
|
105
|
+
for (const i of order.toReversed()) {
|
|
106
|
+
const total = (totalUs[i] ?? 0) + (selfUs[i] ?? 0);
|
|
107
|
+
totalUs[i] = total;
|
|
108
|
+
const p = parentIx[i] ?? -1;
|
|
109
|
+
if (p >= 0) totalUs[p] = (totalUs[p] ?? 0) + total;
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
const totals = new Map<number, FrameTotal>();
|
|
101
|
-
for (
|
|
113
|
+
for (const [i, node] of nodes.entries()) {
|
|
102
114
|
addFrameTotal(
|
|
103
115
|
totals,
|
|
104
|
-
|
|
105
|
-
selfUs[i]
|
|
106
|
-
totalUs[i]
|
|
107
|
-
sampleCount[i]
|
|
116
|
+
node.frameIx,
|
|
117
|
+
selfUs[i] ?? 0,
|
|
118
|
+
totalUs[i] ?? 0,
|
|
119
|
+
sampleCount[i] ?? 0,
|
|
108
120
|
);
|
|
109
121
|
}
|
|
110
122
|
|
package/src/capture/cpu.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { CpuEvidence, Warning } from "../ir/types.ts";
|
|
2
2
|
import { type ProfiledRunOptions, runProfiled } from "./bunflags.ts";
|
|
3
|
-
import {
|
|
3
|
+
import { isRawCpuProfile, parseCpuProfile } from "./cpu-parse.ts";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
interface CpuCaptureOptions extends ProfiledRunOptions {
|
|
6
6
|
intervalUs: number;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
interface CpuCaptureResult {
|
|
10
10
|
diagnosticWallNs: number;
|
|
11
11
|
exitCode: number;
|
|
12
12
|
artifactPath?: string;
|
|
@@ -19,7 +19,7 @@ export interface CpuCaptureResult {
|
|
|
19
19
|
export async function runCpuCapture(
|
|
20
20
|
opts: CpuCaptureOptions,
|
|
21
21
|
): Promise<CpuCaptureResult> {
|
|
22
|
-
const { raw, ...run } = await runProfiled
|
|
22
|
+
const { raw, ...run } = await runProfiled(
|
|
23
23
|
opts,
|
|
24
24
|
[
|
|
25
25
|
"--cpu-prof",
|
|
@@ -33,6 +33,9 @@ export async function runCpuCapture(
|
|
|
33
33
|
{ what: "a .cpuprofile", kind: "CPU" },
|
|
34
34
|
);
|
|
35
35
|
if (!raw) return run;
|
|
36
|
+
if (!isRawCpuProfile(raw)) {
|
|
37
|
+
throw new Error(`ostia: ${run.artifactPath} isn't a CPU profile`);
|
|
38
|
+
}
|
|
36
39
|
|
|
37
40
|
if (raw.samples.length === 0) {
|
|
38
41
|
run.warnings.push({
|
package/src/capture/frames.ts
CHANGED
|
@@ -25,7 +25,13 @@ export function createFrameTable(): {
|
|
|
25
25
|
if (ix === undefined) {
|
|
26
26
|
ix = frames.length;
|
|
27
27
|
byUrl.set(urlKey, ix);
|
|
28
|
-
frames.push({
|
|
28
|
+
frames.push({
|
|
29
|
+
key: fp("fr", name, urlKey),
|
|
30
|
+
name,
|
|
31
|
+
...(url !== undefined && { url }),
|
|
32
|
+
...(line !== undefined && { line }),
|
|
33
|
+
...(col !== undefined && { col }),
|
|
34
|
+
});
|
|
29
35
|
}
|
|
30
36
|
return ix;
|
|
31
37
|
},
|
|
@@ -12,6 +12,29 @@ export interface RawHeapSnapshot {
|
|
|
12
12
|
strings: string[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
// Checks only the arrays `parseHeapSnapshot` walks and the count it
|
|
16
|
+
// reports.
|
|
17
|
+
export function isRawHeapSnapshot(value: unknown): value is RawHeapSnapshot {
|
|
18
|
+
if (typeof value !== "object" || value === null) return false;
|
|
19
|
+
if (!("nodes" in value) || !Array.isArray(value.nodes)) return false;
|
|
20
|
+
if (!("snapshot" in value)) return false;
|
|
21
|
+
const { snapshot } = value;
|
|
22
|
+
if (typeof snapshot !== "object" || snapshot === null) return false;
|
|
23
|
+
if (!("node_count" in snapshot) || typeof snapshot.node_count !== "number") {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (!("meta" in snapshot)) return false;
|
|
27
|
+
const { meta } = snapshot;
|
|
28
|
+
return (
|
|
29
|
+
typeof meta === "object" &&
|
|
30
|
+
meta !== null &&
|
|
31
|
+
"node_fields" in meta &&
|
|
32
|
+
Array.isArray(meta.node_fields) &&
|
|
33
|
+
"node_types" in meta &&
|
|
34
|
+
Array.isArray(meta.node_types)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
15
38
|
const TOP_N = 20;
|
|
16
39
|
|
|
17
40
|
interface TypeBucket {
|
|
@@ -32,8 +55,10 @@ export function parseHeapSnapshot(raw: RawHeapSnapshot): HeapEvidence {
|
|
|
32
55
|
}
|
|
33
56
|
|
|
34
57
|
const typeCount = typeNames.length;
|
|
35
|
-
const buckets
|
|
36
|
-
|
|
58
|
+
const buckets = new Array<TypeBucket | undefined>(typeCount);
|
|
59
|
+
// Keyed by `number | undefined` because a truncated `nodes` reads
|
|
60
|
+
// `undefined` for its last type.
|
|
61
|
+
const unknownBuckets = new Map<number | undefined, TypeBucket>();
|
|
37
62
|
const seen: TypeBucket[] = [];
|
|
38
63
|
const newBucket = (type: string): TypeBucket => {
|
|
39
64
|
const bucket = { type, count: 0, bytes: 0 };
|
|
@@ -45,12 +70,12 @@ export function parseHeapSnapshot(raw: RawHeapSnapshot): HeapEvidence {
|
|
|
45
70
|
const nodes = raw.nodes;
|
|
46
71
|
const len = nodes.length;
|
|
47
72
|
for (let offset = 0; offset < len; offset += fieldCount) {
|
|
48
|
-
const typeIdx = nodes[offset + typeIx]
|
|
73
|
+
const typeIdx = nodes[offset + typeIx];
|
|
49
74
|
const selfSize = nodes[offset + selfSizeIx] ?? 0;
|
|
50
75
|
heapSizeBytes += selfSize;
|
|
51
76
|
let bucket: TypeBucket | undefined;
|
|
52
|
-
if (typeIdx >= 0 && typeIdx < typeCount) {
|
|
53
|
-
bucket = buckets[typeIdx] ??= newBucket(typeNames[typeIdx]
|
|
77
|
+
if (typeIdx !== undefined && typeIdx >= 0 && typeIdx < typeCount) {
|
|
78
|
+
bucket = buckets[typeIdx] ??= newBucket(typeNames[typeIdx] ?? "");
|
|
54
79
|
} else {
|
|
55
80
|
bucket = unknownBuckets.get(typeIdx);
|
|
56
81
|
if (bucket === undefined) {
|
package/src/capture/heap.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { HeapEvidence, Warning } from "../ir/types.ts";
|
|
2
2
|
import { type ProfiledRunOptions, runProfiled } from "./bunflags.ts";
|
|
3
|
-
import {
|
|
3
|
+
import { isRawHeapSnapshot, parseHeapSnapshot } from "./heap-parse.ts";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
type HeapCaptureOptions = ProfiledRunOptions;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
interface HeapCaptureResult {
|
|
8
8
|
diagnosticWallNs: number;
|
|
9
9
|
exitCode: number;
|
|
10
10
|
artifactPath?: string;
|
|
@@ -17,7 +17,7 @@ export interface HeapCaptureResult {
|
|
|
17
17
|
export async function runHeapCapture(
|
|
18
18
|
opts: HeapCaptureOptions,
|
|
19
19
|
): Promise<HeapCaptureResult> {
|
|
20
|
-
const { raw, ...run } = await runProfiled
|
|
20
|
+
const { raw, ...run } = await runProfiled(
|
|
21
21
|
opts,
|
|
22
22
|
[
|
|
23
23
|
"--heap-prof",
|
|
@@ -28,5 +28,9 @@ export async function runHeapCapture(
|
|
|
28
28
|
],
|
|
29
29
|
{ what: "a heap snapshot", kind: "heap" },
|
|
30
30
|
);
|
|
31
|
-
|
|
31
|
+
if (!raw) return run;
|
|
32
|
+
if (!isRawHeapSnapshot(raw)) {
|
|
33
|
+
throw new Error(`ostia: ${run.artifactPath} isn't a heap snapshot`);
|
|
34
|
+
}
|
|
35
|
+
return { ...run, heap: parseHeapSnapshot(raw) };
|
|
32
36
|
}
|
package/src/capture/inspector.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { CpuEvidence } from "../ir/types.ts";
|
|
2
|
-
import {
|
|
2
|
+
import { isRawCpuProfile, parseCpuProfile } from "./cpu-parse.ts";
|
|
3
3
|
import {
|
|
4
4
|
DEFAULT_SAMPLING_INTERVAL_US,
|
|
5
5
|
type SamplingOptions,
|
|
6
6
|
} from "./sampling.ts";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
interface InspectorCaptureResult<T> {
|
|
9
9
|
result: T;
|
|
10
10
|
cpu: CpuEvidence;
|
|
11
11
|
diagnosticWallNs: number;
|
|
@@ -16,8 +16,8 @@ export async function captureInspectorProfile<T>(
|
|
|
16
16
|
opts: SamplingOptions = {},
|
|
17
17
|
): Promise<InspectorCaptureResult<T>> {
|
|
18
18
|
const intervalUs = opts.intervalUs ?? DEFAULT_SAMPLING_INTERVAL_US;
|
|
19
|
-
//
|
|
20
|
-
// invocation.
|
|
19
|
+
// perf: imported lazily, since importing node:inspector costs ~4ms of
|
|
20
|
+
// startup for every invocation.
|
|
21
21
|
const { Session } = await import("node:inspector/promises");
|
|
22
22
|
const session = new Session();
|
|
23
23
|
session.connect();
|
|
@@ -34,9 +34,10 @@ export async function captureInspectorProfile<T>(
|
|
|
34
34
|
|
|
35
35
|
const result = await fn();
|
|
36
36
|
|
|
37
|
-
const { profile } =
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const { profile } = await session.post("Profiler.stop");
|
|
38
|
+
if (!isRawCpuProfile(profile)) {
|
|
39
|
+
throw new Error("ostia: the inspector returned no CPU profile");
|
|
40
|
+
}
|
|
40
41
|
const diagnosticWallNs = Bun.nanoseconds() - start;
|
|
41
42
|
const cpu = parseCpuProfile(profile, "inspector", intervalUs);
|
|
42
43
|
return { result, cpu, diagnosticWallNs };
|
package/src/capture/jsc-parse.ts
CHANGED
|
@@ -53,7 +53,8 @@ export function parseJscProfile(
|
|
|
53
53
|
const { frames, intern } = createFrameTable();
|
|
54
54
|
function frameIxFromRaw(rf: RawJscFrame): number {
|
|
55
55
|
const isSentinel = rf.line === UINT32_SENTINEL;
|
|
56
|
-
// jsc lines
|
|
56
|
+
// spec: jsc lines and columns are 1-based; stored 0-based so they match
|
|
57
|
+
// cpu-prof and the inspector.
|
|
57
58
|
const line = isSentinel ? undefined : rf.line - 1;
|
|
58
59
|
const col =
|
|
59
60
|
isSentinel || rf.column === UINT32_SENTINEL ? undefined : rf.column - 1;
|
|
@@ -84,8 +85,8 @@ export function parseJscProfile(
|
|
|
84
85
|
for (const trace of raw.traces) {
|
|
85
86
|
const traceFrames = trace.frames;
|
|
86
87
|
let current = rootNode;
|
|
87
|
-
for (
|
|
88
|
-
const frameIx = frameIxFromRaw(
|
|
88
|
+
for (const rf of traceFrames.toReversed()) {
|
|
89
|
+
const frameIx = frameIxFromRaw(rf);
|
|
89
90
|
let child = current.children.get(frameIx);
|
|
90
91
|
if (!child) {
|
|
91
92
|
child = newNode(frameIx);
|
|
@@ -150,11 +151,10 @@ export function parseJscProfile(
|
|
|
150
151
|
[...byFrame.entries()]
|
|
151
152
|
.sort((a, b) => b[1] - a[1])
|
|
152
153
|
.slice(0, 3)
|
|
153
|
-
.
|
|
154
|
-
|
|
155
|
-
frameKey:
|
|
156
|
-
|
|
157
|
-
})),
|
|
154
|
+
.flatMap(([frameIx, samples]) => {
|
|
155
|
+
const frame = frames[frameIx];
|
|
156
|
+
return frame ? [{ tier, frameKey: frame.key, samples }] : [];
|
|
157
|
+
}),
|
|
158
158
|
);
|
|
159
159
|
|
|
160
160
|
const jit: JitTierBreakdown = {
|
package/src/capture/jsc.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { profile as jscProfile } from "bun:jsc";
|
|
2
2
|
|
|
3
3
|
import type { CpuEvidence, JitTierBreakdown } from "../ir/types.ts";
|
|
4
|
-
import { parseJscProfile
|
|
4
|
+
import { parseJscProfile } from "./jsc-parse.ts";
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_SAMPLING_INTERVAL_US,
|
|
7
7
|
type SamplingOptions,
|
|
8
8
|
} from "./sampling.ts";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface JscCaptureResult<T> {
|
|
11
11
|
result: T;
|
|
12
12
|
cpu: CpuEvidence;
|
|
13
13
|
jit: JitTierBreakdown;
|
|
@@ -24,10 +24,10 @@ export async function captureJscProfile<T>(
|
|
|
24
24
|
// Diagnostic window: profiler start through stop, nothing else. Matches
|
|
25
25
|
// the inspector capture, whose session setup is outside it.
|
|
26
26
|
const start = Bun.nanoseconds();
|
|
27
|
-
const raw =
|
|
27
|
+
const raw = await jscProfile(async () => {
|
|
28
28
|
result = await fn();
|
|
29
29
|
return result;
|
|
30
|
-
}, intervalUs)
|
|
30
|
+
}, intervalUs);
|
|
31
31
|
const diagnosticWallNs = Bun.nanoseconds() - start;
|
|
32
32
|
|
|
33
33
|
const { cpu, jit } = parseJscProfile(raw.stackTraces, intervalUs);
|
package/src/ci/index.ts
CHANGED
|
@@ -31,7 +31,7 @@ import { formatSignedPct, workloadLabel } from "../renderers/format.ts";
|
|
|
31
31
|
import { abortedWarning } from "../time.ts";
|
|
32
32
|
import { TOOL_VERSION } from "../version.ts";
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
interface CiOptions {
|
|
35
35
|
config: OstiaConfig;
|
|
36
36
|
full: boolean;
|
|
37
37
|
baselineName?: string;
|
|
@@ -43,9 +43,8 @@ export interface CiOptions {
|
|
|
43
43
|
signal?: AbortSignal;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* `WorkloadConfig.timeoutMs` / `BenchConfig.timeoutMs` override this. */
|
|
46
|
+
// So a hung workload times out instead of blocking a CI job;
|
|
47
|
+
// `WorkloadConfig.timeoutMs` / `BenchConfig.timeoutMs` override this.
|
|
49
48
|
const DEFAULT_CI_TIMEOUT_MS = 600_000;
|
|
50
49
|
|
|
51
50
|
type WorkloadStatus = "cached" | "executed";
|
|
@@ -64,7 +63,7 @@ interface CiWorkloadResult extends MeasuredWorkload {
|
|
|
64
63
|
comparison?: Comparison;
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
|
|
66
|
+
interface CiSummary {
|
|
68
67
|
total: number;
|
|
69
68
|
cached: number;
|
|
70
69
|
executed: number;
|
|
@@ -90,13 +89,15 @@ export interface CiSummary {
|
|
|
90
89
|
export class BaselineError extends OstiaUsageError {}
|
|
91
90
|
|
|
92
91
|
export class BaselineNotFoundError extends BaselineError {
|
|
93
|
-
|
|
92
|
+
readonly path: string;
|
|
93
|
+
|
|
94
|
+
constructor(path: string) {
|
|
94
95
|
super(
|
|
95
96
|
`No baseline document at ${path}. Create one with: ostia baseline save ${path
|
|
96
|
-
.
|
|
97
|
-
.pop()!
|
|
97
|
+
.slice(path.lastIndexOf("/") + 1)
|
|
98
98
|
.replace(/\.json$/, "")}`,
|
|
99
99
|
);
|
|
100
|
+
this.path = path;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
|
@@ -104,23 +105,26 @@ export class BaselineNotFoundError extends BaselineError {
|
|
|
104
105
|
* Thrown by `runCi` when the `onMissingBaseline` policy makes unmatched
|
|
105
106
|
* workloads a hard error. */
|
|
106
107
|
export class MissingBaselineError extends BaselineError {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
) {
|
|
108
|
+
readonly path: string;
|
|
109
|
+
readonly missing: number;
|
|
110
|
+
readonly total: number;
|
|
111
|
+
|
|
112
|
+
constructor(path: string, missing: number, total: number) {
|
|
112
113
|
super(
|
|
113
114
|
`${missing} of ${total} configured workload(s) have no matching row in baseline ${path} (by workload id). Re-seed with: ostia baseline save`,
|
|
114
115
|
);
|
|
116
|
+
this.path = path;
|
|
117
|
+
this.missing = missing;
|
|
118
|
+
this.total = total;
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
|
|
118
|
-
|
|
122
|
+
interface MeasureConfigWorkloadsResult {
|
|
119
123
|
results: MeasuredWorkload[];
|
|
120
124
|
/**
|
|
121
125
|
* One reference measurement taken before any workload runs, unless
|
|
122
126
|
* `config.noiseCheck` is false. */
|
|
123
|
-
environment?: Environment;
|
|
127
|
+
environment?: Environment | undefined;
|
|
124
128
|
/** The signal fired: `results` holds only what completed. */
|
|
125
129
|
aborted: boolean;
|
|
126
130
|
}
|
|
@@ -128,16 +132,17 @@ export interface MeasureConfigWorkloadsResult {
|
|
|
128
132
|
async function measureSuiteWorkloads(
|
|
129
133
|
config: OstiaConfig,
|
|
130
134
|
wc: WorkloadConfig,
|
|
135
|
+
suites: string[],
|
|
131
136
|
noiseWarning: Warning | undefined,
|
|
132
137
|
signal: AbortSignal | undefined,
|
|
133
138
|
): Promise<MeasuredWorkload[]> {
|
|
134
139
|
// Always executes: a suite file's task ids (so its cache keys) are unknown
|
|
135
140
|
// without importing it.
|
|
136
|
-
const suiteFiles = await scanGlobs(
|
|
141
|
+
const suiteFiles = await scanGlobs(suites, process.cwd());
|
|
137
142
|
if (suiteFiles.length === 0) {
|
|
138
143
|
// Gating zero tasks would pass silently.
|
|
139
144
|
throw new OstiaUsageError(
|
|
140
|
-
`Workload suites ${JSON.stringify(
|
|
145
|
+
`Workload suites ${JSON.stringify(suites)} matched no files.`,
|
|
141
146
|
);
|
|
142
147
|
}
|
|
143
148
|
// Same CLI-over-config resolution as `ostia bench`; only the defaults
|
|
@@ -149,9 +154,8 @@ async function measureSuiteWorkloads(
|
|
|
149
154
|
const doc = await bench({
|
|
150
155
|
...benchOpts,
|
|
151
156
|
outDir: benchOpts.outDir ?? config.outDir,
|
|
152
|
-
// The workload's own limit, then `bench.timeoutMs`, as for a command.
|
|
153
157
|
timeoutMs: wc.timeoutMs ?? benchOpts.timeoutMs ?? DEFAULT_CI_TIMEOUT_MS,
|
|
154
|
-
signal,
|
|
158
|
+
...(signal && { signal }),
|
|
155
159
|
});
|
|
156
160
|
const results: MeasuredWorkload[] = [];
|
|
157
161
|
for (const workload of doc.workloads) {
|
|
@@ -169,13 +173,14 @@ async function measureSuiteWorkloads(
|
|
|
169
173
|
async function measureCommandWorkload(
|
|
170
174
|
config: OstiaConfig,
|
|
171
175
|
wc: WorkloadConfig,
|
|
176
|
+
command: string[],
|
|
172
177
|
full: boolean,
|
|
173
178
|
noiseWarning: Warning | undefined,
|
|
174
179
|
signal: AbortSignal | undefined,
|
|
175
180
|
): Promise<MeasuredWorkload> {
|
|
176
|
-
const workload = makeSubprocessWorkload(
|
|
177
|
-
prepare: wc.prepare,
|
|
178
|
-
timeSource: wc.timeSource,
|
|
181
|
+
const workload = makeSubprocessWorkload(command, wc.label, {
|
|
182
|
+
...(wc.prepare !== undefined && { prepare: wc.prepare }),
|
|
183
|
+
...(wc.timeSource !== undefined && { timeSource: wc.timeSource }),
|
|
179
184
|
});
|
|
180
185
|
const cfgFp = configFingerprint({
|
|
181
186
|
samples: config.samples ?? null,
|
|
@@ -206,22 +211,26 @@ async function measureCommandWorkload(
|
|
|
206
211
|
run = cachedRun;
|
|
207
212
|
} else {
|
|
208
213
|
const phaseResult = await runTimingPhase({
|
|
209
|
-
argv:
|
|
210
|
-
samples: config.samples,
|
|
211
|
-
budgetMs: config.budgetMs,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
argv: command,
|
|
215
|
+
...(config.samples !== undefined && { samples: config.samples }),
|
|
216
|
+
...(config.budgetMs !== undefined && { budgetMs: config.budgetMs }),
|
|
217
|
+
...(config.minSamples !== undefined && {
|
|
218
|
+
minSamples: config.minSamples,
|
|
219
|
+
}),
|
|
220
|
+
...(config.warmup !== undefined && { warmup: config.warmup }),
|
|
221
|
+
...(wc.prepare !== undefined && { prepare: wc.prepare }),
|
|
222
|
+
...(wc.timeSource !== undefined && { timeSource: wc.timeSource }),
|
|
216
223
|
timeoutMs: wc.timeoutMs ?? DEFAULT_CI_TIMEOUT_MS,
|
|
217
|
-
|
|
218
|
-
|
|
224
|
+
...(wc.ignoreExitCodes !== undefined && {
|
|
225
|
+
ignoreExitCodes: wc.ignoreExitCodes,
|
|
226
|
+
}),
|
|
227
|
+
...(signal && { signal }),
|
|
219
228
|
});
|
|
220
229
|
run = makeTimingMeasurement({
|
|
221
230
|
workload,
|
|
222
231
|
configFingerprint: cfgFp,
|
|
223
232
|
trials: phaseResult.trials,
|
|
224
|
-
timing: phaseResult.timing,
|
|
233
|
+
...(phaseResult.timing && { timing: phaseResult.timing }),
|
|
225
234
|
warnings: noiseWarning
|
|
226
235
|
? [...phaseResult.warnings, noiseWarning]
|
|
227
236
|
: phaseResult.warnings,
|
|
@@ -240,10 +249,8 @@ async function measureCommandWorkload(
|
|
|
240
249
|
};
|
|
241
250
|
}
|
|
242
251
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
* comparison. Shared by `runCi` and `ostia baseline save`, so a saved
|
|
246
|
-
* baseline comes from the same code path `ci` gates against. */
|
|
252
|
+
// No baseline comparison. Shared by `runCi` and `ostia baseline save`, so
|
|
253
|
+
// a saved baseline comes from the same code path `ci` gates against.
|
|
247
254
|
export async function measureConfigWorkloads(
|
|
248
255
|
config: OstiaConfig,
|
|
249
256
|
full: boolean,
|
|
@@ -258,12 +265,29 @@ export async function measureConfigWorkloads(
|
|
|
258
265
|
if (signal?.aborted) break;
|
|
259
266
|
if (wc.suites) {
|
|
260
267
|
results.push(
|
|
261
|
-
...(await measureSuiteWorkloads(
|
|
268
|
+
...(await measureSuiteWorkloads(
|
|
269
|
+
config,
|
|
270
|
+
wc,
|
|
271
|
+
wc.suites,
|
|
272
|
+
noiseWarning,
|
|
273
|
+
signal,
|
|
274
|
+
)),
|
|
262
275
|
);
|
|
263
|
-
} else {
|
|
276
|
+
} else if (wc.command) {
|
|
264
277
|
results.push(
|
|
265
|
-
await measureCommandWorkload(
|
|
278
|
+
await measureCommandWorkload(
|
|
279
|
+
config,
|
|
280
|
+
wc,
|
|
281
|
+
wc.command,
|
|
282
|
+
full,
|
|
283
|
+
noiseWarning,
|
|
284
|
+
signal,
|
|
285
|
+
),
|
|
266
286
|
);
|
|
287
|
+
} else {
|
|
288
|
+
// invariant: config validation gives every workload exactly one of
|
|
289
|
+
// `command` and `suites`.
|
|
290
|
+
throw new Error("ci: a workload has neither command nor suites");
|
|
267
291
|
}
|
|
268
292
|
}
|
|
269
293
|
const aborted = signal?.aborted ?? false;
|
|
@@ -400,7 +424,7 @@ export function renderCiReport(summary: CiSummary): string {
|
|
|
400
424
|
const regressionDetails = summary.results
|
|
401
425
|
.filter((r) => r.comparison?.verdict === "fail")
|
|
402
426
|
.map((r) => {
|
|
403
|
-
const t = r.comparison
|
|
427
|
+
const t = r.comparison?.timing;
|
|
404
428
|
const label = workloadLabel(r.workload);
|
|
405
429
|
return t
|
|
406
430
|
? `${formatSignedPct(t.medianDeltaPct)} median on ${label}`
|