ostia 0.3.0 → 0.4.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.
Files changed (71) hide show
  1. package/index.d.ts +127 -99
  2. package/package.json +1 -1
  3. package/src/ab/ab-runner.ts +57 -44
  4. package/src/ab/index.ts +186 -112
  5. package/src/baseline/index.ts +3 -9
  6. package/src/bench/index.ts +177 -123
  7. package/src/bench/projects.ts +14 -10
  8. package/src/bench/registry.ts +70 -68
  9. package/src/bench/run-tasks.ts +26 -23
  10. package/src/bench/run.ts +2 -1
  11. package/src/bench/runner.ts +20 -5
  12. package/src/bench/support.ts +26 -26
  13. package/src/bench/sweep.ts +7 -5
  14. package/src/cache/fingerprint.ts +9 -6
  15. package/src/cache/store.ts +17 -5
  16. package/src/capture/bunflags.ts +12 -11
  17. package/src/capture/cpu-parse.ts +36 -24
  18. package/src/capture/cpu.ts +7 -4
  19. package/src/capture/frames.ts +7 -1
  20. package/src/capture/heap-parse.ts +30 -5
  21. package/src/capture/heap.ts +9 -5
  22. package/src/capture/inspector.ts +8 -7
  23. package/src/capture/jsc-parse.ts +8 -8
  24. package/src/capture/jsc.ts +4 -4
  25. package/src/ci/index.ts +64 -40
  26. package/src/cli/flags.ts +42 -43
  27. package/src/cli/output.ts +29 -35
  28. package/src/cli/run.ts +95 -95
  29. package/src/compare/index.ts +39 -32
  30. package/src/config/env.ts +13 -0
  31. package/src/config/index.ts +31 -23
  32. package/src/config/validate.ts +33 -27
  33. package/src/format.ts +5 -6
  34. package/src/glob.ts +9 -12
  35. package/src/index.ts +19 -4
  36. package/src/ir/cpu.ts +2 -2
  37. package/src/ir/defined.ts +12 -0
  38. package/src/ir/document.ts +93 -73
  39. package/src/ir/fp.ts +7 -10
  40. package/src/ir/git.ts +4 -3
  41. package/src/ir/types.ts +3 -3
  42. package/src/measure/alloc.ts +7 -8
  43. package/src/measure/cpu.ts +12 -20
  44. package/src/measure/environment.ts +5 -8
  45. package/src/measure/inprocess.ts +15 -15
  46. package/src/measure/instructions.ts +22 -16
  47. package/src/measure/loop.ts +24 -17
  48. package/src/measure/noise.ts +8 -8
  49. package/src/measure/paired.ts +39 -47
  50. package/src/measure/peak.ts +20 -21
  51. package/src/measure/timing.ts +23 -23
  52. package/src/profile.ts +2 -1
  53. package/src/renderers/collapsed.ts +28 -21
  54. package/src/renderers/cpu-tree.ts +43 -35
  55. package/src/renderers/format.ts +16 -26
  56. package/src/renderers/index.ts +14 -4
  57. package/src/renderers/json.ts +2 -2
  58. package/src/renderers/jsonl.ts +11 -7
  59. package/src/renderers/markdown.ts +54 -36
  60. package/src/renderers/mermaid.ts +43 -31
  61. package/src/renderers/minimal.ts +15 -15
  62. package/src/renderers/paired.ts +31 -37
  63. package/src/renderers/relative.ts +10 -14
  64. package/src/renderers/select.ts +17 -39
  65. package/src/renderers/speedscope.ts +52 -48
  66. package/src/renderers/terminal.ts +37 -33
  67. package/src/spawn/index.ts +38 -47
  68. package/src/stats/bootstrap.ts +56 -58
  69. package/src/stats/index.ts +16 -12
  70. package/src/stats/mannwhitney.ts +11 -10
  71. package/src/time.ts +51 -39
@@ -10,7 +10,6 @@ import type {
10
10
  } from "../ir/types.ts";
11
11
  import { percentile, sortedCopy } from "../stats/index.ts";
12
12
 
13
- /** `lo…hi` in one shared unit. */
14
13
  export function formatSpan(lo: number, hi: number, unit: DurationUnit): string {
15
14
  return `${formatDuration(lo, unit)}…${formatDuration(hi, unit)}`;
16
15
  }
@@ -23,17 +22,13 @@ export function formatUsAsMs(us: number): string {
23
22
  return (us / 1000).toFixed(2);
24
23
  }
25
24
 
26
- /**
27
- * `512B`, `2.00KiB`, `14.90MiB`: every byte count ostia prints is
28
- * 1024-based.
29
- */
25
+ // invariant: every byte count ostia prints is 1024-based.
30
26
  export function formatBytes(bytes: number): string {
31
27
  if (bytes < 1024) return `${bytes.toFixed(0)}B`;
32
28
  if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)}KiB`;
33
29
  return `${(bytes / (1024 * 1024)).toFixed(2)}MiB`;
34
30
  }
35
31
 
36
- /** An instruction count: `840`, `12.4K`, `3.02M`, `1.25G`. */
37
32
  export function formatInstructions(count: number): string {
38
33
  if (count < 1e3) return count.toFixed(0);
39
34
  const [divisor, suffix] =
@@ -46,11 +41,17 @@ export function frameName(frame: Frame | undefined): string {
46
41
  return frame?.name || "(anonymous)";
47
42
  }
48
43
 
49
- /**
50
- * The `limit` heaviest frames by self time (`cpu.totals` is pre-sorted),
51
- * with each one's share of all self time as a one-decimal percent string.
52
- * */
53
- export function topSelfFrames(cpu: CpuEvidence, limit: number) {
44
+ // `cpu.totals` is pre-sorted by self time, so the first `limit` are the
45
+ // heaviest.
46
+ export function topSelfFrames(
47
+ cpu: CpuEvidence,
48
+ limit: number,
49
+ ): {
50
+ frame: Frame | undefined;
51
+ selfUs: number;
52
+ totalUs: number;
53
+ pct: string;
54
+ }[] {
54
55
  const totalSelfUs = cpu.totals.reduce((s, t) => s + t.selfUs, 0) || 1;
55
56
  return cpu.totals.slice(0, limit).map((t) => ({
56
57
  frame: cpu.frames[t.frameIx],
@@ -60,17 +61,14 @@ export function topSelfFrames(cpu: CpuEvidence, limit: number) {
60
61
  }));
61
62
  }
62
63
 
63
- /** `1200 objects, 3.42MiB` */
64
64
  export function formatHeapSummary(heap: HeapEvidence): string {
65
65
  return `${heap.objectCount ?? "?"} objects, ${formatBytes(heap.heapSizeBytes ?? 0)}`;
66
66
  }
67
67
 
68
- /** `Apple M2 Pro · 12 cores · load 2.1 · noise floor 1.8%` */
69
68
  export function formatEnvironmentLine(env: Environment): string {
70
69
  return `${env.cpuModel} · ${env.cores} cores · load ${env.loadAvg1.toFixed(1)} · noise floor ${env.noise.floorPct.toFixed(1)}%`;
71
70
  }
72
71
 
73
- /** `abc1234 (main, dirty)` */
74
72
  export function formatGit(git: GitMetadata): string {
75
73
  return `${git.sha} (${git.branch}${git.dirty ? ", dirty" : ""})`;
76
74
  }
@@ -79,24 +77,17 @@ export function workloadLabel(w: Workload): string {
79
77
  return w.label ?? w.command?.join(" ") ?? w.entry?.task ?? w.id;
80
78
  }
81
79
 
82
- /**
83
- * The workload's label, or its raw id when the document has no such
84
- * workload.
85
- */
86
80
  export function labelOrId(w: Workload | undefined, id: string): string {
87
81
  return w ? workloadLabel(w) : id;
88
82
  }
89
83
 
90
- /** `1.00× (baseline)` / `1.00×` / `2.43× slower` / `1.95× faster` */
91
84
  export function formatRelative(relative: number, baseline: boolean): string {
92
85
  if (relative === 1) return baseline ? "1.00× (baseline)" : "1.00×";
93
86
  if (relative > 1) return `${relative.toFixed(2)}× slower`;
94
87
  return `${(1 / relative).toFixed(2)}× faster`;
95
88
  }
96
89
 
97
- /**
98
- * Escapes `|`, `<`, `>`, backticks and newlines so a name can't break a
99
- * GFM table row. */
90
+ // So a name can't break a GFM table row.
100
91
  export function escapeMdCell(s: string): string {
101
92
  return s
102
93
  .replace(/\|/g, "\\|")
@@ -106,9 +97,8 @@ export function escapeMdCell(s: string): string {
106
97
  .replace(/\r\n|\r|\n/g, "<br>");
107
98
  }
108
99
 
109
- /**
110
- * Median user/system CPU time per trial of a subprocess measurement;
111
- * undefined for in-process ones. */
100
+ // Median per trial; in-process measurements have no CPU times, so
101
+ // undefined.
112
102
  export function cpuTimes(
113
103
  run: Pick<Measurement, "trials">,
114
104
  ): { userNs: number; systemNs: number } | undefined {
@@ -134,7 +124,7 @@ export function formatCpuTimes(times: {
134
124
  return `${formatDuration(times.userNs)}/${formatDuration(times.systemNs)}`;
135
125
  }
136
126
 
137
- /** `+3.2%`, `-1.5%`; a delta that rounds to zero is `0.0%`, unsigned. */
127
+ // A delta that rounds to zero prints unsigned, never `-0.0%`.
138
128
  export function formatSignedPct(pct: number): string {
139
129
  const text = pct.toFixed(1);
140
130
  if (Number(text) === 0) return "0.0%";
@@ -3,16 +3,26 @@ import { cpuprofileRenderer } from "./cpuprofile.ts";
3
3
  import { jsonRenderer } from "./json.ts";
4
4
  import { jsonlRenderer } from "./jsonl.ts";
5
5
  import { markdownRenderer } from "./markdown.ts";
6
- import { mermaidRenderer } from "./mermaid.ts";
7
- import { minimalRenderer } from "./minimal.ts";
6
+ import { type MermaidOptions, mermaidRenderer } from "./mermaid.ts";
7
+ import { minimalRenderer, type MinimalRenderOptions } from "./minimal.ts";
8
8
  import { speedscopeRenderer } from "./speedscope.ts";
9
9
  import { terminalRenderer } from "./terminal.ts";
10
- import type { FormatName, Renderer } from "./types.ts";
10
+ import type { FormatName, Renderer, VizOptions } from "./types.ts";
11
11
 
12
12
  /** Each format's renderer, typed with its own options. `Renderer<never>` is
13
13
  * the top type, so `satisfies` checks every format is present without
14
14
  * widening the options. */
15
- export const renderers = {
15
+ export const renderers: {
16
+ table: Renderer;
17
+ json: Renderer;
18
+ markdown: Renderer;
19
+ jsonl: Renderer;
20
+ minimal: Renderer<MinimalRenderOptions>;
21
+ collapsed: Renderer<VizOptions>;
22
+ mermaid: Renderer<MermaidOptions>;
23
+ speedscope: Renderer<VizOptions>;
24
+ cpuprofile: Renderer<VizOptions>;
25
+ } = {
16
26
  table: terminalRenderer,
17
27
  json: jsonRenderer,
18
28
  markdown: markdownRenderer,
@@ -4,7 +4,7 @@ import type { Renderer, RenderResult } from "./types.ts";
4
4
 
5
5
  export const jsonRenderer: Renderer = {
6
6
  name: "json",
7
- async render(doc: ProfileDocument): Promise<RenderResult> {
8
- return { text: serializeDocument(doc) };
7
+ render(doc: ProfileDocument): Promise<RenderResult> {
8
+ return Promise.try(() => ({ text: serializeDocument(doc) }));
9
9
  },
10
10
  };
@@ -4,12 +4,16 @@ import type { Renderer, RenderResult } from "./types.ts";
4
4
 
5
5
  export const jsonlRenderer: Renderer = {
6
6
  name: "jsonl",
7
- async render(doc: ProfileDocument): Promise<RenderResult> {
8
- const { measurements, ...header } = doc;
9
- const lines = [
10
- canonicalJSON({ kind: "document", ...header }),
11
- ...measurements.map((r) => canonicalJSON({ kind: "measurement", ...r })),
12
- ];
13
- return { text: `${lines.join("\n")}\n` };
7
+ render(doc: ProfileDocument): Promise<RenderResult> {
8
+ return Promise.try(() => {
9
+ const { measurements, ...header } = doc;
10
+ const lines = [
11
+ canonicalJSON({ kind: "document", ...header }),
12
+ ...measurements.map((r) =>
13
+ canonicalJSON({ kind: "measurement", ...r }),
14
+ ),
15
+ ];
16
+ return { text: `${lines.join("\n")}\n` };
17
+ });
14
18
  },
15
19
  };
@@ -89,43 +89,49 @@ function warningBullets(label: string, warnings: Warning[]): string[] {
89
89
  return warnings.map((w) => `- **${label}**: ${warningNote(w)}`);
90
90
  }
91
91
 
92
- /**
93
- * The two param keys every workload shares, when each has exactly those
94
- * two (a `sweep()` over two dimensions): the shape a pivot table needs. */
92
+ // The two param keys every workload shares, when each has exactly those
93
+ // two (a `sweep()` over two dimensions): the shape a pivot table needs.
95
94
  function pivotKeysFor(
96
95
  workloads: (Workload | undefined)[],
97
96
  ): [string, string] | undefined {
98
- let keys: string[] | undefined;
97
+ let keys: [string, string] | undefined;
99
98
  for (const w of workloads) {
100
- const k = w?.params ? Object.keys(w.params) : undefined;
101
- if (k?.length !== 2) return undefined;
102
- if (keys === undefined) keys = k;
103
- else if (k.some((kk, i) => kk !== keys![i])) return undefined;
99
+ const k = w?.params ? Object.keys(w.params) : [];
100
+ const [first, second] = k;
101
+ if (k.length !== 2 || first === undefined || second === undefined) {
102
+ return undefined;
103
+ }
104
+ if (keys === undefined) keys = [first, second];
105
+ else if (keys[0] !== first || keys[1] !== second) return undefined;
104
106
  }
105
- return keys as [string, string] | undefined;
107
+ return keys;
106
108
  }
107
109
 
108
110
  export const markdownRenderer: Renderer = {
109
111
  name: "markdown",
110
- async render(doc: ProfileDocument): Promise<RenderResult> {
111
- const byWorkload = workloadsById(doc);
112
- const gitSuffix = doc.git ? ` · ${formatGit(doc.git)}` : "";
113
- const mismatch = environmentMismatch(doc);
112
+ render(doc: ProfileDocument): Promise<RenderResult> {
113
+ return Promise.try(() => {
114
+ const byWorkload = workloadsById(doc);
115
+ const gitSuffix = doc.git ? ` · ${formatGit(doc.git)}` : "";
116
+ const mismatch = environmentMismatch(doc);
114
117
 
115
- const lines = [
116
- "# Profile Report",
117
- "",
118
- `Bun ${doc.bunVersion} · ostia ${doc.toolVersion} · ${doc.platform.os}/${doc.platform.arch} · ${doc.createdAt}${gitSuffix}`,
119
- "",
120
- ...(doc.environment ? [formatEnvironmentLine(doc.environment), ""] : []),
121
- ...(mismatch ? [`> ⚠ ${mismatch.message}`, ""] : []),
122
- // Only `ab()` writes paired measurements, and it always stamps `ab`.
123
- ...(doc.ab ? abSection(doc, doc.ab, byWorkload) : []),
124
- ...timingSection(doc, byWorkload),
125
- ...captureSections(doc, byWorkload),
126
- ...comparisonSection(doc),
127
- ];
128
- return { text: lines.join("\n") };
118
+ const lines = [
119
+ "# Profile Report",
120
+ "",
121
+ `Bun ${doc.bunVersion} · ostia ${doc.toolVersion} · ${doc.platform.os}/${doc.platform.arch} · ${doc.createdAt}${gitSuffix}`,
122
+ "",
123
+ ...(doc.environment
124
+ ? [formatEnvironmentLine(doc.environment), ""]
125
+ : []),
126
+ ...(mismatch ? [`> ⚠ ${mismatch.message}`, ""] : []),
127
+ // Only `ab()` writes paired measurements, and it always stamps `ab`.
128
+ ...(doc.ab ? abSection(doc, doc.ab, byWorkload) : []),
129
+ ...timingSection(doc, byWorkload),
130
+ ...captureSections(doc, byWorkload),
131
+ ...comparisonSection(doc),
132
+ ];
133
+ return { text: lines.join("\n") };
134
+ });
129
135
  },
130
136
  };
131
137
 
@@ -190,7 +196,10 @@ function abSection(
190
196
  if (threw.length > 0) {
191
197
  lines.push(`Threw (${threw.length}):`, "");
192
198
  for (const run of threw) {
193
- const message = run.threw.message.split("\n")[0]!.replaceAll("`", "'");
199
+ const message = (run.threw.message.split("\n")[0] ?? "").replaceAll(
200
+ "`",
201
+ "'",
202
+ );
194
203
  lines.push(
195
204
  `- **${taskCell(byWorkload.get(run.workloadId), run.workloadId)}**: ${formatThrew(run.threw)}: \`${message}\``,
196
205
  );
@@ -226,8 +235,6 @@ function timingSection(
226
235
  const runs = timingRuns(doc);
227
236
  const noSamples = noSampleRuns(doc);
228
237
  const memory = memoryReadings(doc);
229
- // Rows with nothing to tabulate: `task.skip()`'d and sample-less
230
- // workloads.
231
238
  const empty: {
232
239
  id: string;
233
240
  workload: Workload | undefined;
@@ -259,8 +266,12 @@ function timingSection(
259
266
  const flat: TimingRow[] = [];
260
267
  for (const row of rows) {
261
268
  const group = groupOf(row.workload);
262
- if (group === undefined) flat.push(row);
263
- else if (byGroup.has(group)) byGroup.get(group)!.push(row);
269
+ if (group === undefined) {
270
+ flat.push(row);
271
+ continue;
272
+ }
273
+ const groupRows = byGroup.get(group);
274
+ if (groupRows) groupRows.push(row);
264
275
  else byGroup.set(group, [row]);
265
276
  }
266
277
  const pivots: { group: string; keys: [string, string]; rows: TimingRow[] }[] =
@@ -302,8 +313,12 @@ function timingSection(
302
313
  if (ratios) {
303
314
  optional.push({
304
315
  header: "Relative",
305
- cell: (row) =>
306
- formatRelative(ratios.get(row)!, !!row.workload?.baseline),
316
+ cell: (row) => {
317
+ const ratio = ratios.get(row);
318
+ return ratio === undefined
319
+ ? "-"
320
+ : formatRelative(ratio, !!row.workload?.baseline);
321
+ },
307
322
  });
308
323
  }
309
324
 
@@ -356,8 +371,11 @@ function timingSection(
356
371
  const colValues: ParamValue[] = [];
357
372
  const medianAt = new Map<string, number>();
358
373
  for (const { run, workload } of groupRows) {
359
- const v1 = workload!.params![key1]!;
360
- const v2 = workload!.params![key2]!;
374
+ const v1 = workload?.params?.[key1];
375
+ const v2 = workload?.params?.[key2];
376
+ // invariant: `pivotKeysFor` pivots only rows whose params hold both
377
+ // keys.
378
+ if (v1 === undefined || v2 === undefined) continue;
361
379
  if (!rowValues.includes(v1)) rowValues.push(v1);
362
380
  if (!colValues.includes(v2)) colValues.push(v2);
363
381
  medianAt.set(`${v1} ${v2}`, run.timing.median);
@@ -17,7 +17,8 @@ function label(name: string, selfUs: number, totalUs: number): string {
17
17
  return `${name.replace(/"/g, "'")} (self ${formatUsAsMs(selfUs)}ms, total ${formatUsAsMs(totalUs)}ms)`;
18
18
  }
19
19
 
20
- // Insertion into a sorted window: O(count * n) with n small.
20
+ // Insertion into a sorted window instead of a full sort, since n is
21
+ // small: O(count * n).
21
22
  function topNBySelf(
22
23
  selfUs: Float64Array,
23
24
  count: number,
@@ -26,12 +27,14 @@ function topNBySelf(
26
27
  ): number[] {
27
28
  const top: number[] = [];
28
29
  if (n <= 0) return top;
30
+ const selfAt = (ix: number | undefined) =>
31
+ ix === undefined ? 0 : (selfUs[ix] ?? 0);
29
32
  for (let i = 0; i < count; i++) {
30
33
  if (i === exclude) continue;
31
- const v = selfUs[i]!;
32
- if (top.length === n && v <= selfUs[top[n - 1]!]!) continue;
34
+ const v = selfAt(i);
35
+ if (top.length === n && v <= selfAt(top[n - 1])) continue;
33
36
  let j = top.length;
34
- while (j > 0 && selfUs[top[j - 1]!]! < v) j--;
37
+ while (j > 0 && selfAt(top[j - 1]) < v) j--;
35
38
  top.splice(j, 0, i);
36
39
  if (top.length > n) top.pop();
37
40
  }
@@ -40,39 +43,48 @@ function topNBySelf(
40
43
 
41
44
  export const mermaidRenderer: Renderer<MermaidOptions> = {
42
45
  name: "mermaid",
43
- async render(
46
+ render(
44
47
  doc: ProfileDocument,
45
48
  options: MermaidOptions = {},
46
49
  ): Promise<RenderResult> {
47
- const topN = options.topN ?? DEFAULT_TOP_N;
50
+ return Promise.try(() => {
51
+ const topN = options.topN ?? DEFAULT_TOP_N;
48
52
 
49
- return renderCpuFiles(doc, options, "mermaid.md", ({ cpu }) => {
50
- const { nodes, frames } = cpu;
51
- const tree = buildDenseTree(cpu);
52
- const { selfUs, totalUs } = computeDenseNodeTimes(cpu, tree);
53
- const { parentIx } = tree;
54
- const rootIx = tree.roots[0] ?? -1;
53
+ return renderCpuFiles(doc, options, "mermaid.md", ({ cpu }) => {
54
+ const { nodes, frames } = cpu;
55
+ const tree = buildDenseTree(cpu);
56
+ const { selfUs, totalUs } = computeDenseNodeTimes(cpu, tree);
57
+ const { parentIx } = tree;
58
+ const rootIx = tree.roots[0] ?? -1;
55
59
 
56
- // The top-N self-time nodes plus every ancestor, so each has a path to the
57
- // root.
58
- const included = new Set<number>(rootIx !== -1 ? [rootIx] : []);
59
- for (const ix of topNBySelf(selfUs, tree.count, rootIx, topN)) {
60
- const path: number[] = [];
61
- for (let cur = ix; cur !== -1; cur = parentIx[cur]!) path.push(cur);
62
- for (let k = path.length - 1; k >= 0; k--) included.add(path[k]!);
63
- }
60
+ // The top-N self-time nodes plus every ancestor, so each has a path to the
61
+ // root.
62
+ const included = new Set<number>(rootIx !== -1 ? [rootIx] : []);
63
+ for (const ix of topNBySelf(selfUs, tree.count, rootIx, topN)) {
64
+ const path: number[] = [];
65
+ for (let cur = ix; cur !== -1; cur = parentIx[cur] ?? -1) {
66
+ path.push(cur);
67
+ }
68
+ for (const p of path.toReversed()) included.add(p);
69
+ }
64
70
 
65
- const id = (ix: number) => `n${nodes[ix]!.id}`;
66
- const lines = ["graph TD"];
67
- for (const ix of included) {
68
- const name = frameName(frames[nodes[ix]!.frameIx]);
69
- lines.push(` ${id(ix)}["${label(name, selfUs[ix]!, totalUs[ix]!)}"]`);
70
- }
71
- for (const ix of included) {
72
- const p = parentIx[ix]!;
73
- if (p !== -1 && included.has(p)) lines.push(` ${id(p)} --> ${id(ix)}`);
74
- }
75
- return `${lines.join("\n")}\n`;
71
+ const id = (ix: number) => `n${nodes[ix]?.id}`;
72
+ const lines = ["graph TD"];
73
+ for (const ix of included) {
74
+ const node = nodes[ix];
75
+ if (node === undefined) continue;
76
+ const name = frameName(frames[node.frameIx]);
77
+ lines.push(
78
+ ` ${id(ix)}["${label(name, selfUs[ix] ?? 0, totalUs[ix] ?? 0)}"]`,
79
+ );
80
+ }
81
+ for (const ix of included) {
82
+ const p = parentIx[ix] ?? -1;
83
+ if (p !== -1 && included.has(p))
84
+ lines.push(` ${id(p)} --> ${id(ix)}`);
85
+ }
86
+ return `${lines.join("\n")}\n`;
87
+ });
76
88
  });
77
89
  },
78
90
  };
@@ -98,7 +98,7 @@ interface MinimalMemoryChange {
98
98
  /**
99
99
  * One per timing run, for piping into an agent's context in place of the
100
100
  * full `ProfileDocument`. Numbers stay in the IR's units (ns). */
101
- interface MinimalRunLine {
101
+ export interface MinimalRunLine {
102
102
  event: "run";
103
103
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
104
104
  schemaVersion: ProfileDocument["schemaVersion"];
@@ -166,7 +166,7 @@ interface MinimalRunLine {
166
166
  }
167
167
 
168
168
  /** A workload present on only one side of a `compare`/`ci` run. */
169
- interface MinimalUnmatchedLine {
169
+ export interface MinimalUnmatchedLine {
170
170
  event: "unmatched";
171
171
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
172
172
  workloadId: string;
@@ -177,7 +177,7 @@ interface MinimalUnmatchedLine {
177
177
  /**
178
178
  * The last line of a `compare`/`ci`/`ab` run; never emitted for a bare
179
179
  * `time`/`bench` document. */
180
- interface MinimalSummaryLine {
180
+ export interface MinimalSummaryLine {
181
181
  event: "summary";
182
182
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
183
183
  command: "compare" | "ci" | "ab";
@@ -232,6 +232,7 @@ interface MinimalSummaryLine {
232
232
  exitCode: number;
233
233
  }
234
234
 
235
+ /** One parsed line of `--format minimal` output; narrow on `event`. */
235
236
  export type MinimalEvent =
236
237
  MinimalRunLine | MinimalUnmatchedLine | MinimalSummaryLine;
237
238
 
@@ -310,9 +311,6 @@ function deltaFrom(
310
311
  return delta;
311
312
  }
312
313
 
313
- /**
314
- * A `run` line with no stats: a `task.skip()`'d workload, or one whose
315
- * trials produced no samples (`samples: 0`). */
316
314
  function statlessLine(
317
315
  doc: ProfileDocument,
318
316
  workload: Workload,
@@ -428,7 +426,7 @@ function runLines(doc: ProfileDocument): MinimalRunLine[] {
428
426
  line.userNs = sig(times.userNs);
429
427
  line.systemNs = sig(times.systemNs);
430
428
  }
431
- // An `ab` run's stats are the candidate's, memory included.
429
+ // invariant: an `ab` run's stats are the candidate's, memory included.
432
430
  const readings = memory.get(run.workloadId);
433
431
  const retained = readings?.retained ?? run.paired?.retained?.candBytes;
434
432
  if (retained !== undefined) line.retainedBytesPerOp = Math.round(retained);
@@ -587,16 +585,18 @@ function summaryLine(
587
585
 
588
586
  export const minimalRenderer: Renderer<MinimalRenderOptions> = {
589
587
  name: "minimal",
590
- async render(
588
+ render(
591
589
  doc: ProfileDocument,
592
590
  options: MinimalRenderOptions = {},
593
591
  ): Promise<RenderResult> {
594
- const events: MinimalEvent[] = [...runLines(doc)];
595
- if (options.protocol) {
596
- events.push(...unmatchedLines(options.protocol));
597
- events.push(summaryLine(doc, options.protocol));
598
- }
599
- const lines = events.map((l) => JSON.stringify(l));
600
- return { text: lines.length > 0 ? `${lines.join("\n")}\n` : "" };
592
+ return Promise.try(() => {
593
+ const events: MinimalEvent[] = [...runLines(doc)];
594
+ if (options.protocol) {
595
+ events.push(...unmatchedLines(options.protocol));
596
+ events.push(summaryLine(doc, options.protocol));
597
+ }
598
+ const lines = events.map((l) => JSON.stringify(l));
599
+ return { text: lines.length > 0 ? `${lines.join("\n")}\n` : "" };
600
+ });
601
601
  },
602
602
  };