ostia 0.2.12 → 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/LICENSE +21 -0
- package/README.md +50 -358
- package/docs/agent-protocol.md +210 -0
- package/docs/cli.md +1196 -0
- package/docs/config.md +233 -0
- package/docs/document-schema.md +224 -0
- package/docs/library.md +421 -0
- package/docs/preload-recipes.md +169 -0
- package/docs/statistics.md +218 -0
- package/index.d.ts +923 -679
- package/package.json +16 -14
- package/src/ab/ab-runner.ts +487 -0
- package/src/ab/index.ts +1160 -0
- package/src/baseline/index.ts +69 -0
- package/src/bench/index.ts +516 -0
- package/src/bench/projects.ts +43 -0
- package/src/bench/range.ts +27 -0
- package/src/bench/registry.ts +426 -0
- package/src/bench/run-tasks.ts +179 -0
- package/src/bench/run.ts +52 -0
- package/src/bench/runner.ts +162 -0
- package/src/bench/support.ts +161 -0
- package/src/bench/sweep.ts +41 -0
- package/src/cache/fingerprint.ts +62 -0
- package/src/cache/store.ts +40 -0
- package/src/capture/bunflags.ts +92 -0
- package/src/capture/cpu-parse.ts +131 -0
- package/src/capture/cpu.ts +47 -0
- package/src/capture/frames.ts +60 -0
- package/src/capture/heap-parse.ts +111 -0
- package/src/capture/heap.ts +36 -0
- package/src/capture/inspector.ts +47 -0
- package/src/capture/jsc-parse.ts +167 -0
- package/src/capture/jsc.ts +35 -0
- package/src/capture/sampling.ts +5 -0
- package/src/ci/index.ts +440 -0
- package/src/cli/flags.ts +263 -0
- package/{chunk-9sx15b08.js → src/cli/help.ts} +23 -11
- package/src/cli/main.ts +18 -0
- package/src/cli/output.ts +179 -0
- package/src/cli/run.ts +1110 -0
- package/src/compare/index.ts +624 -0
- package/src/config/env.ts +13 -0
- package/src/config/index.ts +283 -0
- package/src/config/validate.ts +273 -0
- package/src/errors.ts +8 -0
- package/src/format.ts +35 -0
- package/src/glob.ts +45 -0
- package/src/index.ts +60 -0
- package/src/ir/cpu.ts +10 -0
- package/src/ir/defined.ts +12 -0
- package/src/ir/document.ts +491 -0
- package/src/ir/fp.ts +28 -0
- package/src/ir/git.ts +37 -0
- package/src/ir/types.ts +615 -0
- package/src/measure/alloc.ts +56 -0
- package/src/measure/cpu.ts +91 -0
- package/src/measure/environment.ts +38 -0
- package/src/measure/inprocess.ts +191 -0
- package/src/measure/instructions.ts +139 -0
- package/src/measure/loop.ts +64 -0
- package/src/measure/noise.ts +55 -0
- package/src/measure/paired.ts +304 -0
- package/src/measure/peak.ts +201 -0
- package/src/measure/timing.ts +263 -0
- package/src/profile.ts +110 -0
- package/src/renderers/collapsed.ts +42 -0
- package/src/renderers/cpu-tree.ts +191 -0
- package/src/renderers/cpuprofile.ts +43 -0
- package/src/renderers/format.ts +132 -0
- package/src/renderers/index.ts +37 -0
- package/src/renderers/json.ts +10 -0
- package/src/renderers/jsonl.ts +19 -0
- package/src/renderers/markdown.ts +543 -0
- package/src/renderers/mermaid.ts +90 -0
- package/src/renderers/minimal.ts +602 -0
- package/src/renderers/paired.ts +223 -0
- package/src/renderers/relative.ts +60 -0
- package/src/renderers/select.ts +264 -0
- package/src/renderers/speedscope.ts +73 -0
- package/src/renderers/terminal.ts +470 -0
- package/src/renderers/types.ts +27 -0
- package/src/spawn/index.ts +387 -0
- package/src/stats/bootstrap.ts +151 -0
- package/src/stats/index.ts +144 -0
- package/src/stats/mannwhitney.ts +82 -0
- package/src/time.ts +337 -0
- package/src/version.ts +3 -0
- package/ab-runner.ts +0 -8
- package/chunk-05jfst35.js +0 -28
- package/chunk-1g1x9zz2.js +0 -15
- package/chunk-23g2rwrn.js +0 -3
- package/chunk-468h5412.js +0 -25
- package/chunk-4esjfc2m.js +0 -2
- package/chunk-ct2xsezd.js +0 -14
- package/cli.js +0 -3
- package/index.js +0 -2
- package/runner.ts +0 -7
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { formatDuration, pickDurationUnit } from "../format.ts";
|
|
2
|
+
import type {
|
|
3
|
+
AbSummary,
|
|
4
|
+
Measurement,
|
|
5
|
+
MemoryChange,
|
|
6
|
+
PairedEvidence,
|
|
7
|
+
ProfileDocument,
|
|
8
|
+
} from "../ir/types.ts";
|
|
9
|
+
import { comparable, metricRatios, sideLabel } from "../measure/paired.ts";
|
|
10
|
+
import {
|
|
11
|
+
formatBytes,
|
|
12
|
+
formatInstructions,
|
|
13
|
+
formatSignedPct,
|
|
14
|
+
labelOrId,
|
|
15
|
+
} from "./format.ts";
|
|
16
|
+
import { workloadsById } from "./select.ts";
|
|
17
|
+
|
|
18
|
+
export type PairedRun = Measurement & {
|
|
19
|
+
timing: NonNullable<Measurement["timing"]>;
|
|
20
|
+
paired: PairedEvidence;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type ThrewRun = Measurement & {
|
|
24
|
+
threw: NonNullable<Measurement["threw"]>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Matches a throw on either side, in the first process or a repeat, since
|
|
28
|
+
// both set `threw`.
|
|
29
|
+
function isThrewRun(m: Measurement): m is ThrewRun {
|
|
30
|
+
return m.phase === "paired" && m.threw !== undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isPairedRun(m: Measurement): m is PairedRun {
|
|
34
|
+
return (
|
|
35
|
+
m.phase === "paired" &&
|
|
36
|
+
m.threw === undefined &&
|
|
37
|
+
m.timing !== undefined &&
|
|
38
|
+
m.paired !== undefined
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function pairedRuns(doc: ProfileDocument): PairedRun[] {
|
|
43
|
+
return doc.measurements.filter(isPairedRun);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function threwRuns(doc: ProfileDocument): ThrewRun[] {
|
|
47
|
+
return doc.measurements.filter(isThrewRun);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type AbRow =
|
|
51
|
+
{ kind: "timed"; run: PairedRun } | { kind: "threw"; run: ThrewRun };
|
|
52
|
+
|
|
53
|
+
export function abRows(doc: ProfileDocument): AbRow[] {
|
|
54
|
+
const rows: AbRow[] = [];
|
|
55
|
+
for (const m of doc.measurements) {
|
|
56
|
+
if (isThrewRun(m)) rows.push({ kind: "threw", run: m });
|
|
57
|
+
else if (isPairedRun(m)) rows.push({ kind: "timed", run: m });
|
|
58
|
+
}
|
|
59
|
+
return rows;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function formatThrew(threw: ThrewRun["threw"]): string {
|
|
63
|
+
return `${sideLabel(threw.side)} threw${threw.repeat ? ` (repeat ${threw.repeat})` : ""}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function formatRatio(ratio: number): string {
|
|
67
|
+
return formatSignedPct((ratio - 1) * 100);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Blank for unchanged; a flagged workload that fresh processes didn't
|
|
71
|
+
// reproduce reads `unconfirmed`. Repeats follow so the confirmation is
|
|
72
|
+
// visible. A changed suite with changed output reads `not comparable`.
|
|
73
|
+
function pairedVerdict(p: PairedEvidence, metric: AbSummary["metric"]): string {
|
|
74
|
+
if (!comparable(p)) return "not comparable";
|
|
75
|
+
if (!p.flagged) return "";
|
|
76
|
+
const repeats = p.repeats?.length
|
|
77
|
+
? ` (repeats: ${p.repeats.map((r) => formatRatio(metricRatios(r, metric)?.medianRatio ?? Number.NaN)).join(", ")})`
|
|
78
|
+
: "";
|
|
79
|
+
if (p.confirmed === undefined) return `${p.flagged}${repeats}`;
|
|
80
|
+
return `${p.confirmed ? `${p.flagged}, confirmed` : `${p.flagged}? unconfirmed`}${repeats}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function formatNewSuites(ab: AbSummary): string | undefined {
|
|
84
|
+
if (!ab.newSuites?.length) return undefined;
|
|
85
|
+
return `New suite${ab.newSuites.length > 1 ? "s" : ""}, not at ${ab.base.ref}: ${ab.newSuites.join(", ")}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface PairedCells {
|
|
89
|
+
base: string;
|
|
90
|
+
candidate: string;
|
|
91
|
+
change: string;
|
|
92
|
+
spread: string;
|
|
93
|
+
also: string;
|
|
94
|
+
verdict: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// `also` is the other metric's change (see `alsoHeader`), blank on a task
|
|
98
|
+
// without an instruction count.
|
|
99
|
+
export function pairedCells(
|
|
100
|
+
run: PairedRun,
|
|
101
|
+
metric: AbSummary["metric"],
|
|
102
|
+
): PairedCells {
|
|
103
|
+
const p = run.paired;
|
|
104
|
+
const i = p.instructions;
|
|
105
|
+
const judged = metricRatios(p, metric);
|
|
106
|
+
const other = metricRatios(p, metric === "time" ? "instructions" : "time");
|
|
107
|
+
let base = "-";
|
|
108
|
+
let candidate = "-";
|
|
109
|
+
if (metric === "time") {
|
|
110
|
+
const unit = pickDurationUnit(Math.min(p.baseMedianNs, run.timing.median));
|
|
111
|
+
base = formatDuration(p.baseMedianNs, unit);
|
|
112
|
+
candidate = formatDuration(run.timing.median, unit);
|
|
113
|
+
} else if (i) {
|
|
114
|
+
base = formatInstructions(i.baseMedian);
|
|
115
|
+
candidate = formatInstructions(i.candMedian);
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
base,
|
|
119
|
+
candidate,
|
|
120
|
+
change: judged ? formatRatio(judged.medianRatio) : "",
|
|
121
|
+
spread: judged
|
|
122
|
+
? `${formatRatio(judged.ratioP25)}…${formatRatio(judged.ratioP75)}`
|
|
123
|
+
: "",
|
|
124
|
+
also: other ? formatRatio(other.medianRatio) : "",
|
|
125
|
+
verdict: pairedVerdict(p, metric),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function alsoHeader(
|
|
130
|
+
doc: ProfileDocument,
|
|
131
|
+
metric: AbSummary["metric"],
|
|
132
|
+
): string | undefined {
|
|
133
|
+
if (metric === "instructions") return "Time";
|
|
134
|
+
return doc.measurements.some((m) => m.paired?.instructions)
|
|
135
|
+
? "Instr"
|
|
136
|
+
: undefined;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface MemoryRow {
|
|
140
|
+
run: PairedRun;
|
|
141
|
+
reading: "retained/op" | "peak";
|
|
142
|
+
change: MemoryChange;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function memoryRows(doc: ProfileDocument): MemoryRow[] {
|
|
146
|
+
return pairedRuns(doc).flatMap((run) => {
|
|
147
|
+
const rows: MemoryRow[] = [];
|
|
148
|
+
const { retained, peak } = run.paired;
|
|
149
|
+
if (retained) rows.push({ run, reading: "retained/op", change: retained });
|
|
150
|
+
if (peak) rows.push({ run, reading: "peak", change: peak });
|
|
151
|
+
return rows;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// No percent when the base is under the noise floor, where it would be
|
|
156
|
+
// huge and meaningless.
|
|
157
|
+
function formatByteChange(c: MemoryChange): string {
|
|
158
|
+
const base = Math.round(c.baseBytes);
|
|
159
|
+
const diff = Math.round(c.candBytes) - base;
|
|
160
|
+
if (diff === 0) return "0B";
|
|
161
|
+
const bytes = `${diff > 0 ? "+" : "-"}${formatBytes(Math.abs(diff))}`;
|
|
162
|
+
if (base === 0 || c.baseBytes < c.floorBytes) return bytes;
|
|
163
|
+
return `${bytes} (${formatSignedPct((diff / base) * 100)})`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface MemoryCells {
|
|
167
|
+
reading: MemoryRow["reading"];
|
|
168
|
+
base: string;
|
|
169
|
+
candidate: string;
|
|
170
|
+
change: string;
|
|
171
|
+
verdict: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function memoryCells({ reading, change: c }: MemoryRow): MemoryCells {
|
|
175
|
+
return {
|
|
176
|
+
reading,
|
|
177
|
+
base: formatBytes(c.baseBytes),
|
|
178
|
+
candidate: formatBytes(c.candBytes),
|
|
179
|
+
change: formatByteChange(c),
|
|
180
|
+
verdict: c.verdict === "unchanged" ? "" : c.verdict,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function formatAbHeader(ab: AbSummary): string {
|
|
185
|
+
const metric = ab.metric === "instructions" ? " · by instructions/call" : "";
|
|
186
|
+
const memory = ab.memory
|
|
187
|
+
? ` · memory threshold ${ab.memory.thresholdPct}%`
|
|
188
|
+
: "";
|
|
189
|
+
return `working tree vs ${ab.base.ref} (${ab.base.sha.slice(0, 7)}) · ${ab.rounds} rounds${metric} · threshold ${ab.thresholdPct}% · geomean threshold ${ab.geomeanThresholdPct}%${memory}`;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function formatAbSummary(ab: AbSummary): string {
|
|
193
|
+
const geomean =
|
|
194
|
+
ab.geomeanPct === null
|
|
195
|
+
? "Geomean -"
|
|
196
|
+
: `Geomean ${formatSignedPct(ab.geomeanPct)} (threshold ${ab.geomeanThresholdPct}%)`;
|
|
197
|
+
const notes = [
|
|
198
|
+
ab.unconfirmed > 0 && `${ab.unconfirmed} unconfirmed`,
|
|
199
|
+
ab.notComparable > 0 && `${ab.notComparable} not comparable`,
|
|
200
|
+
ab.threw > 0 && `${ab.threw} threw`,
|
|
201
|
+
].filter(Boolean);
|
|
202
|
+
const unconfirmed = notes.length > 0 ? ` (${notes.join(", ")})` : "";
|
|
203
|
+
const memory = ab.memory
|
|
204
|
+
? ` · memory: ${ab.memory.regressed} regressed, ${ab.memory.improved} improved`
|
|
205
|
+
: "";
|
|
206
|
+
return `${geomean} · ${ab.regressed} regressed, ${ab.improved} improved, ${ab.unchanged} unchanged of ${ab.matched}${unconfirmed}${memory} · ${ab.verdict}`;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function abNotes(doc: ProfileDocument): {
|
|
210
|
+
outputDiffers: string[];
|
|
211
|
+
baseOnly: string[];
|
|
212
|
+
candOnly: string[];
|
|
213
|
+
} {
|
|
214
|
+
const byId = workloadsById(doc);
|
|
215
|
+
const label = (id: string) => labelOrId(byId.get(id), id);
|
|
216
|
+
return {
|
|
217
|
+
outputDiffers: pairedRuns(doc)
|
|
218
|
+
.filter((m) => !m.paired.sameOutput)
|
|
219
|
+
.map((m) => label(m.workloadId)),
|
|
220
|
+
baseOnly: (doc.unmatched?.baseOnly ?? []).map(label),
|
|
221
|
+
candOnly: (doc.unmatched?.candOnly ?? []).map(label),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Workload } from "../ir/types.ts";
|
|
2
|
+
import type { TimingRun } from "./select.ts";
|
|
3
|
+
|
|
4
|
+
export interface TimingRow {
|
|
5
|
+
run: TimingRun;
|
|
6
|
+
workload: Workload | undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// The explicit `entry.group` the bench runner records, else the
|
|
10
|
+
// "group/name" id split on its last "/" (documents from before that field
|
|
11
|
+
// existed).
|
|
12
|
+
export function groupOf(workload: Workload | undefined): string | undefined {
|
|
13
|
+
if (!workload?.entry) return undefined;
|
|
14
|
+
if (workload.entry.group !== undefined) return workload.entry.group;
|
|
15
|
+
const id = workload.entry.task;
|
|
16
|
+
const idx = id.lastIndexOf("/");
|
|
17
|
+
return idx === -1 ? undefined : id.slice(0, idx);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// The task name alone, since the group's header already shows the group.
|
|
21
|
+
export function labelInGroup(label: string, group: string | undefined): string {
|
|
22
|
+
return group !== undefined && label.startsWith(`${group}/`)
|
|
23
|
+
? label.slice(group.length + 1)
|
|
24
|
+
: label;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Each row's reference median is its group's
|
|
28
|
+
// `task(..., { baseline: true })` task, else the group's fastest.
|
|
29
|
+
// Ungrouped rows use the fastest in the document; tasks never compare
|
|
30
|
+
// across groups. Undefined with fewer than two rows, where "relative"
|
|
31
|
+
// means nothing.
|
|
32
|
+
export function relativeRatios<R extends TimingRow>(
|
|
33
|
+
rows: R[],
|
|
34
|
+
): Map<R, number> | undefined {
|
|
35
|
+
if (rows.length < 2) return undefined;
|
|
36
|
+
const fastestMedian = Math.min(...rows.map((r) => r.run.timing.median));
|
|
37
|
+
const siblingsByGroup = new Map<string, R[]>();
|
|
38
|
+
for (const row of rows) {
|
|
39
|
+
const key = groupOf(row.workload);
|
|
40
|
+
if (key === undefined) continue;
|
|
41
|
+
const siblings = siblingsByGroup.get(key);
|
|
42
|
+
if (siblings) siblings.push(row);
|
|
43
|
+
else siblingsByGroup.set(key, [row]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const ratios = new Map<R, number>();
|
|
47
|
+
for (const row of rows) {
|
|
48
|
+
const key = groupOf(row.workload);
|
|
49
|
+
let reference = fastestMedian;
|
|
50
|
+
if (key !== undefined) {
|
|
51
|
+
const siblings = siblingsByGroup.get(key) ?? [row];
|
|
52
|
+
const baselineRow = siblings.find((s) => s.workload?.baseline);
|
|
53
|
+
reference = baselineRow
|
|
54
|
+
? baselineRow.run.timing.median
|
|
55
|
+
: Math.min(...siblings.map((s) => s.run.timing.median));
|
|
56
|
+
}
|
|
57
|
+
ratios.set(row, row.run.timing.median / reference);
|
|
58
|
+
}
|
|
59
|
+
return ratios;
|
|
60
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ComparedTask,
|
|
3
|
+
Comparison,
|
|
4
|
+
Measurement,
|
|
5
|
+
MemoryDelta,
|
|
6
|
+
ProfileDocument,
|
|
7
|
+
Warning,
|
|
8
|
+
Workload,
|
|
9
|
+
} from "../ir/types.ts";
|
|
10
|
+
import {
|
|
11
|
+
formatBytes,
|
|
12
|
+
formatSignedPct,
|
|
13
|
+
labelOrId,
|
|
14
|
+
workloadLabel,
|
|
15
|
+
} from "./format.ts";
|
|
16
|
+
|
|
17
|
+
// Below this absolute percent a frame/heap-type delta is noise, so it gets
|
|
18
|
+
// no row.
|
|
19
|
+
const MIN_DISPLAY_DELTA_PCT = 0.5;
|
|
20
|
+
|
|
21
|
+
export type TimingRun = Measurement & {
|
|
22
|
+
timing: NonNullable<Measurement["timing"]>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type FrameDelta = NonNullable<Comparison["frames"]>[number];
|
|
26
|
+
type HeapTypeDelta = NonNullable<Comparison["heapTypes"]>[number];
|
|
27
|
+
|
|
28
|
+
export function workloadsById(doc: ProfileDocument): Map<string, Workload> {
|
|
29
|
+
return new Map(doc.workloads.map((w) => [w.id, w]));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function timingRuns(doc: ProfileDocument): TimingRun[] {
|
|
33
|
+
return doc.measurements.filter(
|
|
34
|
+
(r): r is TimingRun => r.phase === "timing" && r.timing !== undefined,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Every trial timed out or missed the `timeSource` pattern. Renderers show
|
|
39
|
+
// these as "no samples" rows so their warnings stay visible.
|
|
40
|
+
export function noSampleRuns(doc: ProfileDocument): Measurement[] {
|
|
41
|
+
return doc.measurements.filter(
|
|
42
|
+
(r) => r.phase === "timing" && r.timing === undefined,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function skippedWorkloads(
|
|
47
|
+
doc: ProfileDocument,
|
|
48
|
+
runs: { workloadId: string }[],
|
|
49
|
+
): Workload[] {
|
|
50
|
+
const measured = new Set(runs.map((r) => r.workloadId));
|
|
51
|
+
return doc.workloads.filter((w) => w.skipped && !measured.has(w.id));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// `environment-mismatch` is the same on every comparison because it
|
|
55
|
+
// concerns the base/cand pair, so renderers print it once, from here, and
|
|
56
|
+
// drop it per row.
|
|
57
|
+
export function environmentMismatch(doc: ProfileDocument): Warning | undefined {
|
|
58
|
+
for (const c of doc.comparisons ?? []) {
|
|
59
|
+
const w = c.warnings?.find((w) => w.code === "environment-mismatch");
|
|
60
|
+
if (w) return w;
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function rowComparisonWarnings(cmp: Comparison): Warning[] {
|
|
66
|
+
return (cmp.warnings ?? []).filter((w) => w.code !== "environment-mismatch");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The workload id is the display fallback when the document lacks the
|
|
70
|
+
// workload. A skipped candidate has no measurement, so
|
|
71
|
+
// `candidateMeasurementId` then holds the workload id itself.
|
|
72
|
+
function comparisonResolver(doc: ProfileDocument) {
|
|
73
|
+
const workloads = workloadsById(doc);
|
|
74
|
+
const runs = new Map(doc.measurements.map((m) => [m.id, m]));
|
|
75
|
+
return (cmp: Comparison) => {
|
|
76
|
+
const run = runs.get(cmp.candidateMeasurementId);
|
|
77
|
+
const workloadId = run?.workloadId ?? cmp.candidateMeasurementId;
|
|
78
|
+
return { run, workloadId, workload: workloads.get(workloadId) };
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function shownFrameDeltas(cmp: Comparison, limit: number): FrameDelta[] {
|
|
83
|
+
return (cmp.frames ?? [])
|
|
84
|
+
.slice(0, limit)
|
|
85
|
+
.filter((f) => Math.abs(f.deltaPct) >= MIN_DISPLAY_DELTA_PCT);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function shownHeapDeltas(
|
|
89
|
+
cmp: Comparison,
|
|
90
|
+
limit: number,
|
|
91
|
+
): HeapTypeDelta[] {
|
|
92
|
+
return (cmp.heapTypes ?? [])
|
|
93
|
+
.slice(0, limit)
|
|
94
|
+
.filter((h) => Math.abs(h.deltaPct) >= MIN_DISPLAY_DELTA_PCT);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface MemoryReadings {
|
|
98
|
+
/** `--alloc`: heap each call retains, bytes. */
|
|
99
|
+
retained?: number;
|
|
100
|
+
/** `--peak-mem`: RSS rise of one call, bytes. */
|
|
101
|
+
peak?: number;
|
|
102
|
+
/** The `memstats` measurements' warnings (e.g. `peak-hidden`). */
|
|
103
|
+
warnings: Warning[];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function memoryReadings(
|
|
107
|
+
doc: ProfileDocument,
|
|
108
|
+
): Map<string, MemoryReadings> {
|
|
109
|
+
const byWorkload = new Map<string, MemoryReadings>();
|
|
110
|
+
for (const m of doc.measurements) {
|
|
111
|
+
if (m.phase !== "memstats" || !m.memory) continue;
|
|
112
|
+
const readings = byWorkload.get(m.workloadId) ?? { warnings: [] };
|
|
113
|
+
if (m.memory.bytesPerOp !== undefined)
|
|
114
|
+
readings.retained = m.memory.bytesPerOp;
|
|
115
|
+
if (m.memory.peakBytes !== undefined) readings.peak = m.memory.peakBytes;
|
|
116
|
+
readings.warnings.push(...m.warnings);
|
|
117
|
+
byWorkload.set(m.workloadId, readings);
|
|
118
|
+
}
|
|
119
|
+
return byWorkload;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function runWarnings(
|
|
123
|
+
run: Measurement,
|
|
124
|
+
memory: Map<string, MemoryReadings>,
|
|
125
|
+
): Warning[] {
|
|
126
|
+
const extra = memory.get(run.workloadId)?.warnings;
|
|
127
|
+
return extra?.length ? [...run.warnings, ...extra] : run.warnings;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
interface MemoryColumn {
|
|
131
|
+
header: string;
|
|
132
|
+
/** Formatted bytes, or undefined when this workload has no reading. */
|
|
133
|
+
cell: (workloadId: string) => string | undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function memoryColumns(
|
|
137
|
+
memory: Map<string, MemoryReadings>,
|
|
138
|
+
): MemoryColumn[] {
|
|
139
|
+
const candidates = [
|
|
140
|
+
{ header: "Retained/op", read: (r: MemoryReadings) => r.retained },
|
|
141
|
+
{ header: "Peak mem", read: (r: MemoryReadings) => r.peak },
|
|
142
|
+
];
|
|
143
|
+
return candidates
|
|
144
|
+
.filter((c) => {
|
|
145
|
+
for (const r of memory.values()) if (c.read(r) !== undefined) return true;
|
|
146
|
+
return false;
|
|
147
|
+
})
|
|
148
|
+
.map((c) => ({
|
|
149
|
+
header: c.header,
|
|
150
|
+
cell: (id) => {
|
|
151
|
+
const readings = memory.get(id);
|
|
152
|
+
const bytes = readings && c.read(readings);
|
|
153
|
+
return bytes === undefined ? undefined : formatBytes(bytes);
|
|
154
|
+
},
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// A document compared before `compared` existed gets rows rebuilt from
|
|
159
|
+
// `comparisons` and `unmatched`: no sample counts or memory, the base
|
|
160
|
+
// median derived from the change, base-only tasks named by id.
|
|
161
|
+
export function comparedRows(
|
|
162
|
+
doc: ProfileDocument,
|
|
163
|
+
): { row: ComparedTask; cmp: Comparison | undefined }[] {
|
|
164
|
+
// Most documents were never compared: skip building the lookups.
|
|
165
|
+
if (!doc.compared && !doc.comparisons?.length && !doc.unmatched) return [];
|
|
166
|
+
const byId = new Map((doc.comparisons ?? []).map((c) => [c.id, c]));
|
|
167
|
+
const rows = doc.compared ?? rebuildCompared(doc);
|
|
168
|
+
return rows.map((row) => ({
|
|
169
|
+
row,
|
|
170
|
+
cmp:
|
|
171
|
+
row.comparisonId === undefined ? undefined : byId.get(row.comparisonId),
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function rebuildCompared(doc: ProfileDocument): ComparedTask[] {
|
|
176
|
+
const resolve = comparisonResolver(doc);
|
|
177
|
+
const workloads = workloadsById(doc);
|
|
178
|
+
const oneSided = (
|
|
179
|
+
id: string,
|
|
180
|
+
verdict: "missing-base" | "missing-cand",
|
|
181
|
+
): ComparedTask => {
|
|
182
|
+
const w = workloads.get(id);
|
|
183
|
+
return {
|
|
184
|
+
workloadId: id,
|
|
185
|
+
task: labelOrId(w, id),
|
|
186
|
+
...(w?.entry?.group !== undefined && { group: w.entry.group }),
|
|
187
|
+
verdict,
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
return [
|
|
191
|
+
...(doc.comparisons ?? []).map((cmp): ComparedTask => {
|
|
192
|
+
const { run, workload, workloadId } = resolve(cmp);
|
|
193
|
+
const row: ComparedTask = {
|
|
194
|
+
workloadId,
|
|
195
|
+
task: workload ? workloadLabel(workload) : workloadId,
|
|
196
|
+
...(workload?.entry?.group !== undefined && {
|
|
197
|
+
group: workload.entry.group,
|
|
198
|
+
}),
|
|
199
|
+
verdict: cmp.timing?.verdict ?? "unchanged",
|
|
200
|
+
comparisonId: cmp.id,
|
|
201
|
+
pass: cmp.verdict === "pass",
|
|
202
|
+
};
|
|
203
|
+
if (cmp.timing && run?.timing) {
|
|
204
|
+
const { medianDeltaPct, ci95, pValue } = cmp.timing;
|
|
205
|
+
row.timing = {
|
|
206
|
+
unit: "ns",
|
|
207
|
+
baseMedian: run.timing.median / (1 + medianDeltaPct / 100),
|
|
208
|
+
candMedian: run.timing.median,
|
|
209
|
+
candSamples: run.timing.samples.length,
|
|
210
|
+
medianDeltaPct,
|
|
211
|
+
...(ci95 && { ci95 }),
|
|
212
|
+
...(pValue !== undefined && { pValue }),
|
|
213
|
+
thresholdPct: cmp.thresholds.effectiveTimingPct,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return row;
|
|
217
|
+
}),
|
|
218
|
+
...(doc.unmatched?.candOnly ?? []).map((id) =>
|
|
219
|
+
oneSided(id, "missing-base"),
|
|
220
|
+
),
|
|
221
|
+
...(doc.unmatched?.baseOnly ?? []).map((id) =>
|
|
222
|
+
oneSided(id, "missing-cand"),
|
|
223
|
+
),
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Heap readings move with GC timing, so a small change is noise, not a
|
|
228
|
+
// line.
|
|
229
|
+
const MIN_MEMORY_DISPLAY_PCT = 10;
|
|
230
|
+
|
|
231
|
+
const MEMORY_READING_LABELS: Record<MemoryDelta["reading"], string> = {
|
|
232
|
+
heapUsedBefore: "heap used before",
|
|
233
|
+
heapUsedAfter: "heap used after",
|
|
234
|
+
retained: "retained/op",
|
|
235
|
+
peak: "peak",
|
|
236
|
+
maxRss: "max RSS",
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
export function shownMemoryDeltas(row: ComparedTask, arrow = "→"): string[] {
|
|
240
|
+
return (row.memory ?? [])
|
|
241
|
+
.filter((m) => !(Math.abs(m.deltaPct) < MIN_MEMORY_DISPLAY_PCT))
|
|
242
|
+
.map(
|
|
243
|
+
(m) =>
|
|
244
|
+
`${MEMORY_READING_LABELS[m.reading]} ${formatBytes(m.baseBytes)} ${arrow} ${formatBytes(m.candBytes)} (${Number.isFinite(m.deltaPct) ? formatSignedPct(m.deltaPct) : "new"})`,
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function thresholdNote(doc: ProfileDocument): string | undefined {
|
|
249
|
+
const summary = doc.comparisonSummary;
|
|
250
|
+
const base = doc.comparisons?.[0]?.thresholds.timingPct;
|
|
251
|
+
if (!summary || base === undefined) return undefined;
|
|
252
|
+
if (!(summary.effectiveTimingPct > base)) return undefined;
|
|
253
|
+
const drift =
|
|
254
|
+
summary.driftPct !== undefined && summary.driftPct > 0
|
|
255
|
+
? ` and drift (${summary.driftPct.toFixed(1)}%); \`ostia ab\` alternates base and candidate in one process, so drift can't favor either`
|
|
256
|
+
: "";
|
|
257
|
+
return `Timing threshold ${base.toFixed(1)}%, widened to ${summary.effectiveTimingPct.toFixed(1)}% by machine noise${drift}`;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function oneSidedNote(verdict: "missing-base" | "missing-cand"): string {
|
|
261
|
+
return verdict === "missing-base"
|
|
262
|
+
? "candidate only (new, or renamed without `aliases`)"
|
|
263
|
+
: "base only (removed, or renamed without `aliases`)";
|
|
264
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ProfileDocument } from "../ir/types.ts";
|
|
2
|
+
import { buildDenseTree, renderCpuFiles } from "./cpu-tree.ts";
|
|
3
|
+
import { frameName } from "./format.ts";
|
|
4
|
+
import { workloadsById } from "./select.ts";
|
|
5
|
+
import type { Renderer, RenderResult, VizOptions } from "./types.ts";
|
|
6
|
+
|
|
7
|
+
const SCHEMA_URL = "https://www.speedscope.app/file-format-schema.json";
|
|
8
|
+
|
|
9
|
+
export const speedscopeRenderer: Renderer<VizOptions> = {
|
|
10
|
+
name: "speedscope",
|
|
11
|
+
render(
|
|
12
|
+
doc: ProfileDocument,
|
|
13
|
+
options: VizOptions = {},
|
|
14
|
+
): Promise<RenderResult> {
|
|
15
|
+
return Promise.try(() => {
|
|
16
|
+
const byWorkload = workloadsById(doc);
|
|
17
|
+
|
|
18
|
+
return renderCpuFiles(doc, options, "speedscope.json", (run) => {
|
|
19
|
+
const { cpu } = run;
|
|
20
|
+
const { nodes } = cpu;
|
|
21
|
+
const tree = buildDenseTree(cpu);
|
|
22
|
+
const nodeIds = cpu.samples?.nodeIds ?? [];
|
|
23
|
+
const weights = cpu.samples?.timeDeltasUs ?? [];
|
|
24
|
+
|
|
25
|
+
const stackOf = new Array<number[]>(tree.count);
|
|
26
|
+
for (const i of tree.order) {
|
|
27
|
+
const node = nodes[i];
|
|
28
|
+
if (node === undefined) continue;
|
|
29
|
+
const p = tree.parentIx[i] ?? -1;
|
|
30
|
+
stackOf[i] =
|
|
31
|
+
p === -1 ? [node.frameIx] : [...(stackOf[p] ?? []), node.frameIx];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const samples = nodeIds.map((id) => {
|
|
35
|
+
const ix = tree.indexOf(id);
|
|
36
|
+
return (ix === -1 ? undefined : stackOf[ix]) ?? [];
|
|
37
|
+
});
|
|
38
|
+
const workload = byWorkload.get(run.workloadId);
|
|
39
|
+
const name =
|
|
40
|
+
workload?.label ??
|
|
41
|
+
workload?.command?.join(" ") ??
|
|
42
|
+
workload?.entry?.task ??
|
|
43
|
+
"profile";
|
|
44
|
+
|
|
45
|
+
const document = {
|
|
46
|
+
$schema: SCHEMA_URL,
|
|
47
|
+
exporter: "ostia",
|
|
48
|
+
name,
|
|
49
|
+
activeProfileIndex: 0,
|
|
50
|
+
shared: {
|
|
51
|
+
frames: cpu.frames.map((f) => ({
|
|
52
|
+
name: frameName(f),
|
|
53
|
+
file: f.url,
|
|
54
|
+
line: f.line !== undefined ? f.line + 1 : undefined,
|
|
55
|
+
})),
|
|
56
|
+
},
|
|
57
|
+
profiles: [
|
|
58
|
+
{
|
|
59
|
+
type: "sampled",
|
|
60
|
+
name,
|
|
61
|
+
unit: "microseconds",
|
|
62
|
+
startValue: 0,
|
|
63
|
+
endValue: weights.reduce((sum, w) => sum + w, 0),
|
|
64
|
+
samples,
|
|
65
|
+
weights,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
return `${JSON.stringify(document, null, 2)}\n`;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
};
|