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
@@ -20,16 +20,16 @@ export type PairedRun = Measurement & {
20
20
  paired: PairedEvidence;
21
21
  };
22
22
 
23
- export type ThrewRun = Measurement & {
23
+ type ThrewRun = Measurement & {
24
24
  threw: NonNullable<Measurement["threw"]>;
25
25
  };
26
26
 
27
- /** A task that threw, on either side, in its first process or a repeat. */
27
+ // Matches a throw on either side, in the first process or a repeat, since
28
+ // both set `threw`.
28
29
  function isThrewRun(m: Measurement): m is ThrewRun {
29
30
  return m.phase === "paired" && m.threw !== undefined;
30
31
  }
31
32
 
32
- /** A task judged on its time: measured, and it never threw. */
33
33
  function isPairedRun(m: Measurement): m is PairedRun {
34
34
  return (
35
35
  m.phase === "paired" &&
@@ -43,15 +43,13 @@ export function pairedRuns(doc: ProfileDocument): PairedRun[] {
43
43
  return doc.measurements.filter(isPairedRun);
44
44
  }
45
45
 
46
- /** An `ab()` document's tasks that threw. */
47
46
  export function threwRuns(doc: ProfileDocument): ThrewRun[] {
48
47
  return doc.measurements.filter(isThrewRun);
49
48
  }
50
49
 
51
- export type AbRow =
50
+ type AbRow =
52
51
  { kind: "timed"; run: PairedRun } | { kind: "threw"; run: ThrewRun };
53
52
 
54
- /** Every row of an A/B table, timed or threw, in document order. */
55
53
  export function abRows(doc: ProfileDocument): AbRow[] {
56
54
  const rows: AbRow[] = [];
57
55
  for (const m of doc.measurements) {
@@ -61,14 +59,10 @@ export function abRows(doc: ProfileDocument): AbRow[] {
61
59
  return rows;
62
60
  }
63
61
 
64
- /**
65
- * `base threw`, `candidate threw`, `both threw`, with `(repeat 1)` when it
66
- * threw in a confirmation repeat. */
67
62
  export function formatThrew(threw: ThrewRun["threw"]): string {
68
63
  return `${sideLabel(threw.side)} threw${threw.repeat ? ` (repeat ${threw.repeat})` : ""}`;
69
64
  }
70
65
 
71
- /** A candidate/base ratio as a signed percent change: `1.032` is `+3.2%`. */
72
66
  function formatRatio(ratio: number): string {
73
67
  return formatSignedPct((ratio - 1) * 100);
74
68
  }
@@ -86,17 +80,26 @@ function pairedVerdict(p: PairedEvidence, metric: AbSummary["metric"]): string {
86
80
  return `${p.confirmed ? `${p.flagged}, confirmed` : `${p.flagged}? unconfirmed`}${repeats}`;
87
81
  }
88
82
 
89
- /** `New suites, not at HEAD: bench/new.bench.ts`, or nothing. */
90
83
  export function formatNewSuites(ab: AbSummary): string | undefined {
91
84
  if (!ab.newSuites?.length) return undefined;
92
85
  return `New suite${ab.newSuites.length > 1 ? "s" : ""}, not at ${ab.base.ref}: ${ab.newSuites.join(", ")}`;
93
86
  }
94
87
 
95
- /**
96
- * The text of one paired row's table cells: `metric`'s per-call medians
97
- * and change, then in `also` the other metric's change (see `alsoHeader`),
98
- * blank on a task without an instruction count. */
99
- export function pairedCells(run: PairedRun, metric: AbSummary["metric"]) {
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 {
100
103
  const p = run.paired;
101
104
  const i = p.instructions;
102
105
  const judged = metricRatios(p, metric);
@@ -123,9 +126,6 @@ export function pairedCells(run: PairedRun, metric: AbSummary["metric"]) {
123
126
  };
124
127
  }
125
128
 
126
- /**
127
- * The header of `pairedCells`'s `also` column, or undefined when no row
128
- * would fill it. */
129
129
  export function alsoHeader(
130
130
  doc: ProfileDocument,
131
131
  metric: AbSummary["metric"],
@@ -136,13 +136,12 @@ export function alsoHeader(
136
136
  : undefined;
137
137
  }
138
138
 
139
- export interface MemoryRow {
139
+ interface MemoryRow {
140
140
  run: PairedRun;
141
141
  reading: "retained/op" | "peak";
142
142
  change: MemoryChange;
143
143
  }
144
144
 
145
- /** Each timed task's memory readings, retained before peak. */
146
145
  export function memoryRows(doc: ProfileDocument): MemoryRow[] {
147
146
  return pairedRuns(doc).flatMap((run) => {
148
147
  const rows: MemoryRow[] = [];
@@ -153,9 +152,8 @@ export function memoryRows(doc: ProfileDocument): MemoryRow[] {
153
152
  });
154
153
  }
155
154
 
156
- /**
157
- * `+1.50MiB (+87.4%)`, in whole bytes; no percent when the base is under
158
- * the noise floor, where it would be huge and meaningless. */
155
+ // No percent when the base is under the noise floor, where it would be
156
+ // huge and meaningless.
159
157
  function formatByteChange(c: MemoryChange): string {
160
158
  const base = Math.round(c.baseBytes);
161
159
  const diff = Math.round(c.candBytes) - base;
@@ -165,8 +163,15 @@ function formatByteChange(c: MemoryChange): string {
165
163
  return `${bytes} (${formatSignedPct((diff / base) * 100)})`;
166
164
  }
167
165
 
168
- /** The text of one memory row's table cells. */
169
- export function memoryCells({ reading, change: c }: MemoryRow) {
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 {
170
175
  return {
171
176
  reading,
172
177
  base: formatBytes(c.baseBytes),
@@ -176,10 +181,6 @@ export function memoryCells({ reading, change: c }: MemoryRow) {
176
181
  };
177
182
  }
178
183
 
179
- /**
180
- * `working tree vs HEAD (26e7d0d) · 15 rounds · threshold 10% · geomean
181
- * threshold 1.5%`, with `· by instructions/call` after the rounds when
182
- * that's the metric. */
183
184
  export function formatAbHeader(ab: AbSummary): string {
184
185
  const metric = ab.metric === "instructions" ? " · by instructions/call" : "";
185
186
  const memory = ab.memory
@@ -188,10 +189,6 @@ export function formatAbHeader(ab: AbSummary): string {
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}`;
189
190
  }
190
191
 
191
- /**
192
- * `Geomean +2.1% (threshold 1.5%) · 1 regressed, 0 improved, 47 unchanged
193
- * of 48 (1 unconfirmed) · memory: 0 regressed, 1 improved · fail`
194
- */
195
192
  export function formatAbSummary(ab: AbSummary): string {
196
193
  const geomean =
197
194
  ab.geomeanPct === null
@@ -209,9 +206,6 @@ export function formatAbSummary(ab: AbSummary): string {
209
206
  return `${geomean} · ${ab.regressed} regressed, ${ab.improved} improved, ${ab.unchanged} unchanged of ${ab.matched}${unconfirmed}${memory} · ${ab.verdict}`;
210
207
  }
211
208
 
212
- /**
213
- * Labels of workloads whose output differed between sides, and of those
214
- * present on only one side. */
215
209
  export function abNotes(doc: ProfileDocument): {
216
210
  outputDiffers: string[];
217
211
  baseOnly: string[];
@@ -6,10 +6,9 @@ export interface TimingRow {
6
6
  workload: Workload | undefined;
7
7
  }
8
8
 
9
- /**
10
- * The explicit `entry.group` the bench runner records, else the
11
- * "group/name" id split on its last "/" (documents from before that field
12
- * existed). */
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).
13
12
  export function groupOf(workload: Workload | undefined): string | undefined {
14
13
  if (!workload?.entry) return undefined;
15
14
  if (workload.entry.group !== undefined) return workload.entry.group;
@@ -18,21 +17,18 @@ export function groupOf(workload: Workload | undefined): string | undefined {
18
17
  return idx === -1 ? undefined : id.slice(0, idx);
19
18
  }
20
19
 
21
- /**
22
- * A row's label under its group's header: the task name alone, since the
23
- * header already shows the group. */
20
+ // The task name alone, since the group's header already shows the group.
24
21
  export function labelInGroup(label: string, group: string | undefined): string {
25
22
  return group !== undefined && label.startsWith(`${group}/`)
26
23
  ? label.slice(group.length + 1)
27
24
  : label;
28
25
  }
29
26
 
30
- /**
31
- * Each row's median over its reference median: its group's
32
- * `task(..., { baseline: true })` task, else the group's fastest.
33
- * Ungrouped rows use the fastest in the document; tasks never compare
34
- * across groups. Undefined with fewer than two rows, where "relative"
35
- * means nothing. */
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.
36
32
  export function relativeRatios<R extends TimingRow>(
37
33
  rows: R[],
38
34
  ): Map<R, number> | undefined {
@@ -52,7 +48,7 @@ export function relativeRatios<R extends TimingRow>(
52
48
  const key = groupOf(row.workload);
53
49
  let reference = fastestMedian;
54
50
  if (key !== undefined) {
55
- const siblings = siblingsByGroup.get(key)!;
51
+ const siblings = siblingsByGroup.get(key) ?? [row];
56
52
  const baselineRow = siblings.find((s) => s.workload?.baseline);
57
53
  reference = baselineRow
58
54
  ? baselineRow.run.timing.median
@@ -14,15 +14,16 @@ import {
14
14
  workloadLabel,
15
15
  } from "./format.ts";
16
16
 
17
- // Below this absolute percent a frame/heap-type delta is noise, not a row.
17
+ // Below this absolute percent a frame/heap-type delta is noise, so it gets
18
+ // no row.
18
19
  const MIN_DISPLAY_DELTA_PCT = 0.5;
19
20
 
20
21
  export type TimingRun = Measurement & {
21
22
  timing: NonNullable<Measurement["timing"]>;
22
23
  };
23
24
 
24
- export type FrameDelta = NonNullable<Comparison["frames"]>[number];
25
- export type HeapTypeDelta = NonNullable<Comparison["heapTypes"]>[number];
25
+ type FrameDelta = NonNullable<Comparison["frames"]>[number];
26
+ type HeapTypeDelta = NonNullable<Comparison["heapTypes"]>[number];
26
27
 
27
28
  export function workloadsById(doc: ProfileDocument): Map<string, Workload> {
28
29
  return new Map(doc.workloads.map((w) => [w.id, w]));
@@ -34,20 +35,14 @@ export function timingRuns(doc: ProfileDocument): TimingRun[] {
34
35
  );
35
36
  }
36
37
 
37
- /**
38
- * Timing measurements that produced no samples (every trial timed out or
39
- * missed the `timeSource` pattern). Renderers show them as "no samples"
40
- * rows so their warnings stay visible. */
38
+ // Every trial timed out or missed the `timeSource` pattern. Renderers show
39
+ // these as "no samples" rows so their warnings stay visible.
41
40
  export function noSampleRuns(doc: ProfileDocument): Measurement[] {
42
41
  return doc.measurements.filter(
43
42
  (r) => r.phase === "timing" && r.timing === undefined,
44
43
  );
45
44
  }
46
45
 
47
- /**
48
- * `task.skip()`'d workloads with no measurement, rendered as "- skipped"
49
- * rows.
50
- */
51
46
  export function skippedWorkloads(
52
47
  doc: ProfileDocument,
53
48
  runs: { workloadId: string }[],
@@ -56,10 +51,9 @@ export function skippedWorkloads(
56
51
  return doc.workloads.filter((w) => w.skipped && !measured.has(w.id));
57
52
  }
58
53
 
59
- /**
60
- * `environment-mismatch` is the same on every comparison (it concerns the
61
- * base/cand pair): renderers print it once, from here, and drop it per
62
- * row. */
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.
63
57
  export function environmentMismatch(doc: ProfileDocument): Warning | undefined {
64
58
  for (const c of doc.comparisons ?? []) {
65
59
  const w = c.warnings?.find((w) => w.code === "environment-mismatch");
@@ -72,11 +66,9 @@ export function rowComparisonWarnings(cmp: Comparison): Warning[] {
72
66
  return (cmp.warnings ?? []).filter((w) => w.code !== "environment-mismatch");
73
67
  }
74
68
 
75
- /**
76
- * Resolves a comparison to its candidate measurement and workload, plus
77
- * the workload id (the display fallback when the document lacks the
78
- * workload). A skipped candidate has no measurement, so
79
- * `candidateMeasurementId` then holds the workload id itself. */
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.
80
72
  function comparisonResolver(doc: ProfileDocument) {
81
73
  const workloads = workloadsById(doc);
82
74
  const runs = new Map(doc.measurements.map((m) => [m.id, m]));
@@ -102,7 +94,7 @@ export function shownHeapDeltas(
102
94
  .filter((h) => Math.abs(h.deltaPct) >= MIN_DISPLAY_DELTA_PCT);
103
95
  }
104
96
 
105
- export interface MemoryReadings {
97
+ interface MemoryReadings {
106
98
  /** `--alloc`: heap each call retains, bytes. */
107
99
  retained?: number;
108
100
  /** `--peak-mem`: RSS rise of one call, bytes. */
@@ -127,7 +119,6 @@ export function memoryReadings(
127
119
  return byWorkload;
128
120
  }
129
121
 
130
- /** A timing run's warnings plus its workload's `memstats` warnings. */
131
122
  export function runWarnings(
132
123
  run: Measurement,
133
124
  memory: Map<string, MemoryReadings>,
@@ -136,16 +127,12 @@ export function runWarnings(
136
127
  return extra?.length ? [...run.warnings, ...extra] : run.warnings;
137
128
  }
138
129
 
139
- export interface MemoryColumn {
130
+ interface MemoryColumn {
140
131
  header: string;
141
132
  /** Formatted bytes, or undefined when this workload has no reading. */
142
133
  cell: (workloadId: string) => string | undefined;
143
134
  }
144
135
 
145
- /**
146
- * `Retained/op` and `Peak mem` columns, each only when some workload has
147
- * it.
148
- */
149
136
  export function memoryColumns(
150
137
  memory: Map<string, MemoryReadings>,
151
138
  ): MemoryColumn[] {
@@ -168,11 +155,9 @@ export function memoryColumns(
168
155
  }));
169
156
  }
170
157
 
171
- /**
172
- * The document's `compared` rows, each with its `Comparison` (absent on a
173
- * one-sided task). A document compared before `compared` existed gets rows
174
- * rebuilt from `comparisons` and `unmatched`: no sample counts or memory,
175
- * the base median derived from the change, base-only tasks named by id. */
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.
176
161
  export function comparedRows(
177
162
  doc: ProfileDocument,
178
163
  ): { row: ComparedTask; cmp: Comparison | undefined }[] {
@@ -251,9 +236,6 @@ const MEMORY_READING_LABELS: Record<MemoryDelta["reading"], string> = {
251
236
  maxRss: "max RSS",
252
237
  };
253
238
 
254
- /**
255
- * `heap used before 12.00MiB → 16.80MiB (+40.0%)` for each memory reading
256
- * that moved at least 10%. */
257
239
  export function shownMemoryDeltas(row: ComparedTask, arrow = "→"): string[] {
258
240
  return (row.memory ?? [])
259
241
  .filter((m) => !(Math.abs(m.deltaPct) < MIN_MEMORY_DISPLAY_PCT))
@@ -263,9 +245,6 @@ export function shownMemoryDeltas(row: ComparedTask, arrow = "→"): string[] {
263
245
  );
264
246
  }
265
247
 
266
- /**
267
- * `Timing threshold 5.0%, widened to 17.3% by machine noise and drift
268
- * (12.3%)`, when noise or drift widened it; else undefined. */
269
248
  export function thresholdNote(doc: ProfileDocument): string | undefined {
270
249
  const summary = doc.comparisonSummary;
271
250
  const base = doc.comparisons?.[0]?.thresholds.timingPct;
@@ -278,7 +257,6 @@ export function thresholdNote(doc: ProfileDocument): string | undefined {
278
257
  return `Timing threshold ${base.toFixed(1)}%, widened to ${summary.effectiveTimingPct.toFixed(1)}% by machine noise${drift}`;
279
258
  }
280
259
 
281
- /** "base only" / "candidate only", and what that usually means. */
282
260
  export function oneSidedNote(verdict: "missing-base" | "missing-cand"): string {
283
261
  return verdict === "missing-base"
284
262
  ? "candidate only (new, or renamed without `aliases`)"
@@ -8,62 +8,66 @@ const SCHEMA_URL = "https://www.speedscope.app/file-format-schema.json";
8
8
 
9
9
  export const speedscopeRenderer: Renderer<VizOptions> = {
10
10
  name: "speedscope",
11
- async render(
11
+ render(
12
12
  doc: ProfileDocument,
13
13
  options: VizOptions = {},
14
14
  ): Promise<RenderResult> {
15
- const byWorkload = workloadsById(doc);
15
+ return Promise.try(() => {
16
+ const byWorkload = workloadsById(doc);
16
17
 
17
- return renderCpuFiles(doc, options, "speedscope.json", (run) => {
18
- const { cpu } = run;
19
- const { nodes } = cpu;
20
- const tree = buildDenseTree(cpu);
21
- const nodeIds = cpu.samples?.nodeIds ?? [];
22
- const weights = cpu.samples?.timeDeltasUs ?? [];
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 ?? [];
23
24
 
24
- const stackOf: number[][] = new Array(tree.count);
25
- for (const i of tree.order) {
26
- const p = tree.parentIx[i]!;
27
- const frameIx = nodes[i]!.frameIx;
28
- stackOf[i] = p === -1 ? [frameIx] : [...stackOf[p]!, frameIx];
29
- }
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
+ }
30
33
 
31
- const samples = nodeIds.map((id) => {
32
- const ix = tree.indexOf(id);
33
- return ix === -1 ? [] : stackOf[ix]!;
34
- });
35
- const workload = byWorkload.get(run.workloadId);
36
- const name =
37
- workload?.label ??
38
- workload?.command?.join(" ") ??
39
- workload?.entry?.task ??
40
- "profile";
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";
41
44
 
42
- const document = {
43
- $schema: SCHEMA_URL,
44
- exporter: "ostia",
45
- name,
46
- activeProfileIndex: 0,
47
- shared: {
48
- frames: cpu.frames.map((f) => ({
49
- name: frameName(f),
50
- file: f.url,
51
- line: f.line !== undefined ? f.line + 1 : undefined,
52
- })),
53
- },
54
- profiles: [
55
- {
56
- type: "sampled",
57
- name,
58
- unit: "microseconds",
59
- startValue: 0,
60
- endValue: weights.reduce((sum, w) => sum + w, 0),
61
- samples,
62
- weights,
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
+ })),
63
56
  },
64
- ],
65
- };
66
- return `${JSON.stringify(document, null, 2)}\n`;
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
+ });
67
71
  });
68
72
  },
69
73
  };
@@ -70,7 +70,7 @@ interface Column<R> {
70
70
 
71
71
  interface TableRow<R> {
72
72
  label: string;
73
- group?: string;
73
+ group?: string | undefined;
74
74
  /** Absent when there is nothing to tabulate; `status` says why. */
75
75
  data?: R;
76
76
  /** The row's text when `data` is absent: `skipped` or `no samples`. */
@@ -80,7 +80,6 @@ interface TableRow<R> {
80
80
 
81
81
  function textTable<R>(columns: Column<R>[], rows: TableRow<R>[]): string[] {
82
82
  const indentOf = (row: TableRow<R>) => (row.group !== undefined ? " " : "");
83
- // Under its group's header, a row shows the task name alone.
84
83
  const shown = (row: TableRow<R>) => labelInGroup(row.label, row.group);
85
84
  let labelWidth = 4;
86
85
  for (const r of rows) {
@@ -122,32 +121,34 @@ function finish(lines: string[]): RenderResult {
122
121
 
123
122
  export const terminalRenderer: Renderer = {
124
123
  name: "table",
125
- async render(doc: ProfileDocument): Promise<RenderResult> {
126
- const env = doc.environment
127
- ? [formatEnvironmentLine(doc.environment), ""]
128
- : [];
129
-
130
- // Only `ab()` writes paired measurements, and it always stamps `ab`.
131
- if (doc.ab) return finish(renderPaired(doc, doc.ab, env));
132
-
133
- const runs = timingRuns(doc);
134
- const empty = noSampleRuns(doc);
135
- const comparisons = renderComparisons(doc);
136
- if (
137
- runs.length === 0 &&
138
- empty.length === 0 &&
139
- skippedWorkloads(doc, runs).length === 0
140
- ) {
141
- return comparisons.length > 0
142
- ? finish([...env, ...comparisons])
143
- : { text: "(no timing runs)\n" };
144
- }
124
+ render(doc: ProfileDocument): Promise<RenderResult> {
125
+ return Promise.try(() => {
126
+ const env = doc.environment
127
+ ? [formatEnvironmentLine(doc.environment), ""]
128
+ : [];
129
+
130
+ // Only `ab()` writes paired measurements, and it always stamps `ab`.
131
+ if (doc.ab) return finish(renderPaired(doc, doc.ab, env));
132
+
133
+ const runs = timingRuns(doc);
134
+ const empty = noSampleRuns(doc);
135
+ const comparisons = renderComparisons(doc);
136
+ if (
137
+ runs.length === 0 &&
138
+ empty.length === 0 &&
139
+ skippedWorkloads(doc, runs).length === 0
140
+ ) {
141
+ return comparisons.length > 0
142
+ ? finish([...env, ...comparisons])
143
+ : { text: "(no timing runs)\n" };
144
+ }
145
145
 
146
- const lines = [...env, ...renderTiming(doc, runs, empty)];
147
- const instrumented = renderInstrumentedRuns(doc);
148
- if (instrumented.length > 0) lines.push("", ...instrumented);
149
- if (comparisons.length > 0) lines.push("", ...comparisons);
150
- return finish(lines);
146
+ const lines = [...env, ...renderTiming(doc, runs, empty)];
147
+ const instrumented = renderInstrumentedRuns(doc);
148
+ if (instrumented.length > 0) lines.push("", ...instrumented);
149
+ if (comparisons.length > 0) lines.push("", ...comparisons);
150
+ return finish(lines);
151
+ });
151
152
  },
152
153
  };
153
154
 
@@ -167,15 +168,13 @@ function renderTiming(
167
168
  const run = runByWorkloadId.get(workload.id);
168
169
  const label = workloadLabel(workload);
169
170
  const group = groupOf(workload);
171
+ const noSample = noSampleByWorkloadId.get(workload.id);
170
172
  if (run) {
171
173
  const data = { run, workload };
172
174
  measured.push(data);
173
175
  rows.push({ label, group, data, warnings: runWarnings(run, memory) });
174
- } else if (noSampleByWorkloadId.has(workload.id)) {
175
- const warnings = runWarnings(
176
- noSampleByWorkloadId.get(workload.id)!,
177
- memory,
178
- );
176
+ } else if (noSample) {
177
+ const warnings = runWarnings(noSample, memory);
179
178
  rows.push({ label, group, status: "no samples", warnings });
180
179
  } else if (workload.skipped) {
181
180
  rows.push({ label, group, status: "skipped", warnings: [] });
@@ -238,7 +237,12 @@ function renderTiming(
238
237
  columns.push({
239
238
  header: "Relative",
240
239
  width: 8,
241
- cell: (row) => formatRelative(ratios.get(row)!, !!row.workload?.baseline),
240
+ cell: (row) => {
241
+ const ratio = ratios.get(row);
242
+ return ratio === undefined
243
+ ? ""
244
+ : formatRelative(ratio, !!row.workload?.baseline);
245
+ },
242
246
  });
243
247
  }
244
248