ostia 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -30
- package/docs/agent-protocol.md +13 -9
- package/docs/cli.md +174 -126
- package/docs/config.md +2 -2
- package/docs/document-schema.md +15 -12
- package/docs/library.md +32 -21
- package/docs/preload-recipes.md +4 -4
- package/docs/statistics.md +14 -13
- package/index.d.ts +202 -60
- package/package.json +1 -1
- package/src/ab/ab-runner.ts +6 -6
- package/src/ab/index.ts +56 -6
- package/src/ab/unpaired.ts +54 -0
- package/src/bench/index.ts +40 -3
- package/src/bench/registry.ts +6 -4
- package/src/bench/run-tasks.ts +16 -2
- package/src/bench/runner.ts +10 -3
- package/src/bench/support.ts +8 -4
- package/src/bench/sweep.ts +2 -2
- package/src/cache/fingerprint.ts +2 -2
- package/src/capture/bunflags.ts +2 -2
- package/src/capture/cpu.ts +2 -2
- package/src/capture/heap-parse.ts +2 -2
- package/src/ci/index.ts +39 -48
- package/src/cli/agent.ts +54 -0
- package/src/cli/flags.ts +58 -9
- package/src/cli/help.ts +670 -245
- package/src/cli/main.ts +2 -3
- package/src/cli/output.ts +17 -14
- package/src/cli/run.ts +317 -92
- package/src/compare/index.ts +4 -4
- package/src/config/index.ts +14 -10
- package/src/config/validate.ts +4 -4
- package/src/glob.ts +2 -2
- package/src/index.ts +3 -2
- package/src/ir/document.ts +2 -2
- package/src/ir/types.ts +49 -24
- package/src/measure/alloc.ts +2 -2
- package/src/measure/cpu.ts +2 -2
- package/src/measure/environment.ts +11 -6
- package/src/measure/inprocess.ts +14 -10
- package/src/measure/instructions.ts +2 -2
- package/src/measure/noise.ts +51 -13
- package/src/measure/paired.ts +2 -2
- package/src/measure/peak.ts +4 -4
- package/src/measure/timing.ts +27 -6
- package/src/profile.ts +6 -4
- package/src/renderers/collapsed.ts +2 -2
- package/src/renderers/concise.ts +148 -0
- package/src/renderers/format.ts +13 -4
- package/src/renderers/human.ts +402 -0
- package/src/renderers/index.ts +9 -2
- package/src/renderers/markdown.ts +2 -2
- package/src/renderers/mermaid.ts +2 -2
- package/src/renderers/minimal.ts +8 -7
- package/src/renderers/relative.ts +2 -2
- package/src/renderers/select.ts +2 -2
- package/src/renderers/terminal.ts +1178 -383
- package/src/renderers/types.ts +3 -0
- package/src/spawn/index.ts +47 -14
- package/src/stats/bootstrap.ts +2 -2
- package/src/stats/index.ts +2 -2
- package/src/terminal.ts +321 -0
- package/src/time.ts +124 -20
|
@@ -23,8 +23,8 @@ export const collapsedRenderer: Renderer<VizOptions> = {
|
|
|
23
23
|
pathOf[i] = p === -1 ? name : `${pathOf[p]};${name}`;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
// Typed counts plus a first-seen list, because this runs over
|
|
27
|
-
// sample.
|
|
26
|
+
// Typed counts plus a first-seen list, because this runs over
|
|
27
|
+
// every sample.
|
|
28
28
|
const counts = new Float64Array(tree.count);
|
|
29
29
|
const seen: number[] = [];
|
|
30
30
|
for (const id of cpu.samples?.nodeIds ?? []) {
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { formatDuration, pickDurationUnit } from "../format.ts";
|
|
2
|
+
import type { ProfileDocument, Warning, Workload } from "../ir/types.ts";
|
|
3
|
+
import {
|
|
4
|
+
formatRelative,
|
|
5
|
+
formatShellLine,
|
|
6
|
+
formatSignedPct,
|
|
7
|
+
workloadLabel,
|
|
8
|
+
} from "./format.ts";
|
|
9
|
+
import { abRows, formatAbSummary, formatThrew, pairedCells } from "./paired.ts";
|
|
10
|
+
import { relativeRatios, type TimingRow } from "./relative.ts";
|
|
11
|
+
import {
|
|
12
|
+
comparedRows,
|
|
13
|
+
memoryReadings,
|
|
14
|
+
noSampleRuns,
|
|
15
|
+
oneSidedNote,
|
|
16
|
+
runWarnings,
|
|
17
|
+
timingRuns,
|
|
18
|
+
workloadsById,
|
|
19
|
+
} from "./select.ts";
|
|
20
|
+
import type { Renderer, RenderResult } from "./types.ts";
|
|
21
|
+
|
|
22
|
+
// One line per command or task, and each warning on a short line after
|
|
23
|
+
// them: the fewest tokens that still read as text, for an agent or a
|
|
24
|
+
// person (metonym/ostia#54). `events` is the format a script parses.
|
|
25
|
+
|
|
26
|
+
// Each line's columns, padded so they line up.
|
|
27
|
+
function aligned(rows: string[][]): string[] {
|
|
28
|
+
const widths: number[] = [];
|
|
29
|
+
for (const row of rows) {
|
|
30
|
+
for (const [i, cell] of row.entries()) {
|
|
31
|
+
widths[i] = Math.max(widths[i] ?? 0, cell.length);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return rows.map((row) =>
|
|
35
|
+
row
|
|
36
|
+
.map((cell, i) =>
|
|
37
|
+
i === row.length - 1 ? cell : cell.padEnd(widths[i] ?? 0),
|
|
38
|
+
)
|
|
39
|
+
.join(" ")
|
|
40
|
+
.trimEnd(),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function warningLines(label: string, warnings: readonly Warning[]): string[] {
|
|
45
|
+
return warnings.map((w) => `! ${label}: ${w.message}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function timingLines(doc: ProfileDocument): string[] {
|
|
49
|
+
const memory = memoryReadings(doc);
|
|
50
|
+
const byId = new Map(timingRuns(doc).map((run) => [run.workloadId, run]));
|
|
51
|
+
const empty = new Map(noSampleRuns(doc).map((run) => [run.workloadId, run]));
|
|
52
|
+
const measured: TimingRow[] = [];
|
|
53
|
+
for (const workload of doc.workloads) {
|
|
54
|
+
const run = byId.get(workload.id);
|
|
55
|
+
if (run) measured.push({ run, workload });
|
|
56
|
+
}
|
|
57
|
+
const ratios = relativeRatios(measured);
|
|
58
|
+
const rows: string[][] = [];
|
|
59
|
+
const warnings: string[] = [];
|
|
60
|
+
for (const workload of doc.workloads) {
|
|
61
|
+
const label = workloadLabel(workload);
|
|
62
|
+
const run = byId.get(workload.id);
|
|
63
|
+
const noSamples = empty.get(workload.id);
|
|
64
|
+
if (run) {
|
|
65
|
+
const { median, mad } = run.timing;
|
|
66
|
+
const unit = pickDurationUnit(median);
|
|
67
|
+
const row = measured.find((r) => r.run === run);
|
|
68
|
+
const ratio = row && ratios?.get(row);
|
|
69
|
+
rows.push([
|
|
70
|
+
label,
|
|
71
|
+
formatDuration(median, unit),
|
|
72
|
+
`±${(median === 0 ? 0 : (mad / median) * 100).toFixed(1)}%`,
|
|
73
|
+
ratio === undefined ? "" : formatRelative(ratio, !!workload.baseline),
|
|
74
|
+
]);
|
|
75
|
+
warnings.push(...warningLines(label, runWarnings(run, memory)));
|
|
76
|
+
} else if (noSamples) {
|
|
77
|
+
rows.push([label, "no samples"]);
|
|
78
|
+
warnings.push(...warningLines(label, runWarnings(noSamples, memory)));
|
|
79
|
+
} else if (workload.skipped) {
|
|
80
|
+
rows.push([label, "skipped"]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return [...aligned(rows), ...warnings];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function comparisonLines(doc: ProfileDocument): string[] {
|
|
87
|
+
const rows: string[][] = [];
|
|
88
|
+
const notCompared: string[] = [];
|
|
89
|
+
for (const { row } of comparedRows(doc)) {
|
|
90
|
+
if (row.verdict === "missing-base" || row.verdict === "missing-cand") {
|
|
91
|
+
notCompared.push(`- ${row.task}: ${oneSidedNote(row.verdict)}`);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const mark = row.pass === false ? "✗" : "✓";
|
|
95
|
+
if (!row.timing) {
|
|
96
|
+
rows.push([`${mark} ${row.task}`, `(${row.verdict})`]);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const { baseMedian, candMedian, medianDeltaPct } = row.timing;
|
|
100
|
+
const unit = pickDurationUnit(Math.max(baseMedian, candMedian));
|
|
101
|
+
rows.push([
|
|
102
|
+
`${mark} ${row.task}`,
|
|
103
|
+
`${formatDuration(baseMedian, unit)} -> ${formatDuration(candMedian, unit)}`,
|
|
104
|
+
formatSignedPct(medianDeltaPct),
|
|
105
|
+
`(${row.verdict})`,
|
|
106
|
+
]);
|
|
107
|
+
}
|
|
108
|
+
return [...aligned(rows), ...notCompared];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function abLines(
|
|
112
|
+
doc: ProfileDocument,
|
|
113
|
+
ab: NonNullable<ProfileDocument["ab"]>,
|
|
114
|
+
): string[] {
|
|
115
|
+
const workloads = workloadsById(doc);
|
|
116
|
+
const label = (id: string) => {
|
|
117
|
+
const workload: Workload | undefined = workloads.get(id);
|
|
118
|
+
return workload ? workloadLabel(workload) : id;
|
|
119
|
+
};
|
|
120
|
+
const rows: string[][] = [];
|
|
121
|
+
for (const row of abRows(doc)) {
|
|
122
|
+
if (row.kind === "threw") {
|
|
123
|
+
rows.push([label(row.run.workloadId), formatThrew(row.run.threw)]);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const cells = pairedCells(row.run, ab.metric);
|
|
127
|
+
rows.push([
|
|
128
|
+
label(row.run.workloadId),
|
|
129
|
+
`${cells.base} -> ${cells.candidate}`,
|
|
130
|
+
cells.change,
|
|
131
|
+
cells.verdict,
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
return [formatAbSummary(ab), ...aligned(rows)];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const conciseRenderer: Renderer = {
|
|
138
|
+
name: "concise",
|
|
139
|
+
render(doc: ProfileDocument): Promise<RenderResult> {
|
|
140
|
+
return Promise.try(() => {
|
|
141
|
+
const lines = doc.ab
|
|
142
|
+
? abLines(doc, doc.ab)
|
|
143
|
+
: [...timingLines(doc), ...comparisonLines(doc)];
|
|
144
|
+
if (doc.shell) lines.push(formatShellLine(doc.shell));
|
|
145
|
+
return { text: lines.length > 0 ? `${lines.join("\n")}\n` : "" };
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
};
|
package/src/renderers/format.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
GitMetadata,
|
|
7
7
|
HeapEvidence,
|
|
8
8
|
Measurement,
|
|
9
|
+
ProfileDocument,
|
|
9
10
|
Workload,
|
|
10
11
|
} from "../ir/types.ts";
|
|
11
12
|
import { percentile, sortedCopy } from "../stats/index.ts";
|
|
@@ -41,8 +42,8 @@ export function frameName(frame: Frame | undefined): string {
|
|
|
41
42
|
return frame?.name || "(anonymous)";
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
// `cpu.totals` is pre-sorted by self time, so the first `limit` are
|
|
45
|
-
// heaviest.
|
|
45
|
+
// `cpu.totals` is pre-sorted by self time, so the first `limit` are
|
|
46
|
+
// the heaviest.
|
|
46
47
|
export function topSelfFrames(
|
|
47
48
|
cpu: CpuEvidence,
|
|
48
49
|
limit: number,
|
|
@@ -81,6 +82,14 @@ export function labelOrId(w: Workload | undefined, id: string): string {
|
|
|
81
82
|
return w ? workloadLabel(w) : id;
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
// The shell a run went through and its startup, which every time it
|
|
86
|
+
// prints includes, so a fast command's time isn't read as its own.
|
|
87
|
+
export function formatShellLine(
|
|
88
|
+
shell: NonNullable<ProfileDocument["shell"]>,
|
|
89
|
+
): string {
|
|
90
|
+
return `Shell: ${shell.command} -c, ${formatDuration(shell.startupNs)} to start, included in each time`;
|
|
91
|
+
}
|
|
92
|
+
|
|
84
93
|
export function formatRelative(relative: number, baseline: boolean): string {
|
|
85
94
|
if (relative === 1) return baseline ? "1.00× (baseline)" : "1.00×";
|
|
86
95
|
if (relative > 1) return `${relative.toFixed(2)}× slower`;
|
|
@@ -97,8 +106,8 @@ export function escapeMdCell(s: string): string {
|
|
|
97
106
|
.replace(/\r\n|\r|\n/g, "<br>");
|
|
98
107
|
}
|
|
99
108
|
|
|
100
|
-
// Median per trial; in-process measurements have no CPU times,
|
|
101
|
-
// undefined.
|
|
109
|
+
// Median per trial; in-process measurements have no CPU times,
|
|
110
|
+
// so undefined.
|
|
102
111
|
export function cpuTimes(
|
|
103
112
|
run: Pick<Measurement, "trials">,
|
|
104
113
|
): { userNs: number; systemNs: number } | undefined {
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
// The pieces of the human (table) format that every command shares:
|
|
2
|
+
// numbers to three significant figures, the context line, a warning in
|
|
3
|
+
// words, and a table whose names shrink to fit 80 columns.
|
|
4
|
+
|
|
5
|
+
import type { Environment, TimingStats, Warning } from "../ir/types.ts";
|
|
6
|
+
import { percentile, sortedCopy } from "../stats/index.ts";
|
|
7
|
+
import {
|
|
8
|
+
aligned,
|
|
9
|
+
MEASURE,
|
|
10
|
+
MISSING,
|
|
11
|
+
NOTE_INDENT,
|
|
12
|
+
type Paint,
|
|
13
|
+
plural,
|
|
14
|
+
SEPARATOR,
|
|
15
|
+
signed,
|
|
16
|
+
textWidth,
|
|
17
|
+
truncateWords,
|
|
18
|
+
withNotes,
|
|
19
|
+
} from "../terminal.ts";
|
|
20
|
+
|
|
21
|
+
// Three significant figures, so a column of numbers reads at one
|
|
22
|
+
// precision: 22.2, 248, 8.80.
|
|
23
|
+
function toSig3(value: number): string {
|
|
24
|
+
if (value === 0) return "0";
|
|
25
|
+
const abs = Math.abs(value);
|
|
26
|
+
return abs >= 100
|
|
27
|
+
? value.toFixed(0)
|
|
28
|
+
: abs >= 10
|
|
29
|
+
? value.toFixed(1)
|
|
30
|
+
: value.toFixed(2);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Up a unit when rounding reaches 1000, since 999.7 µs should print
|
|
34
|
+
// 1.00 ms, not 1000 µs.
|
|
35
|
+
function scaled(
|
|
36
|
+
value: number,
|
|
37
|
+
units: readonly (readonly [string, number])[],
|
|
38
|
+
): string {
|
|
39
|
+
if (!Number.isFinite(value)) return MISSING;
|
|
40
|
+
const abs = Math.abs(value);
|
|
41
|
+
let i = 0;
|
|
42
|
+
while (i < units.length - 1 && abs >= (units[i + 1]?.[1] ?? Infinity)) i++;
|
|
43
|
+
let [unit, size] = units[i] ?? ["", 1];
|
|
44
|
+
let text = toSig3(value / size);
|
|
45
|
+
const next = units[i + 1];
|
|
46
|
+
if (next && Math.abs(Number(text)) >= 1000) {
|
|
47
|
+
[unit, size] = next;
|
|
48
|
+
text = toSig3(value / size);
|
|
49
|
+
}
|
|
50
|
+
return unit === "" ? text : `${text}${unit}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const DURATION_UNITS = [
|
|
54
|
+
[" ns", 1],
|
|
55
|
+
[" µs", 1e3],
|
|
56
|
+
[" ms", 1e6],
|
|
57
|
+
[" s", 1e9],
|
|
58
|
+
] as const;
|
|
59
|
+
|
|
60
|
+
const COUNT_UNITS = [
|
|
61
|
+
["", 1],
|
|
62
|
+
["K", 1e3],
|
|
63
|
+
["M", 1e6],
|
|
64
|
+
["G", 1e9],
|
|
65
|
+
] as const;
|
|
66
|
+
|
|
67
|
+
// invariant: every byte count ostia prints is 1024-based.
|
|
68
|
+
const BYTE_UNITS = [
|
|
69
|
+
[" B", 1],
|
|
70
|
+
[" KiB", 1024],
|
|
71
|
+
[" MiB", 1024 ** 2],
|
|
72
|
+
[" GiB", 1024 ** 3],
|
|
73
|
+
] as const;
|
|
74
|
+
|
|
75
|
+
export function toDuration(ns: number): string {
|
|
76
|
+
return scaled(ns, DURATION_UNITS);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function toCount(count: number): string {
|
|
80
|
+
return count < 1000 ? String(Math.round(count)) : scaled(count, COUNT_UNITS);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function toBytes(bytes: number): string {
|
|
84
|
+
return Math.abs(bytes) < 1024
|
|
85
|
+
? `${Math.round(bytes)} B`
|
|
86
|
+
: scaled(bytes, BYTE_UNITS);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function toElapsed(ms: number): string {
|
|
90
|
+
return toDuration(ms * 1e6);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function toShare(pct: number): string {
|
|
94
|
+
return `${toSig3(pct)}%`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function toTimes(ratio: number): string {
|
|
98
|
+
return `${ratio < 1000 ? toSig3(ratio) : toCount(ratio)}×`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const toPercent = (pct: number) =>
|
|
102
|
+
`${Math.abs(pct) < 100 ? pct.toFixed(1) : pct.toFixed(0)}%`;
|
|
103
|
+
|
|
104
|
+
// The minus is ASCII, so a pasted change parses; zero has no sign.
|
|
105
|
+
export function toChange(pct: number): string {
|
|
106
|
+
if (!Number.isFinite(pct)) return MISSING;
|
|
107
|
+
// Past 10×, a multiple reads at a glance where +64237% doesn't.
|
|
108
|
+
if (pct >= 900) return toTimes(1 + pct / 100);
|
|
109
|
+
return Number(toPercent(pct).slice(0, -1)) === 0
|
|
110
|
+
? "0.0%"
|
|
111
|
+
: signed(pct, toPercent);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// The median absolute deviation, since a long right tail would skew a
|
|
115
|
+
// standard deviation.
|
|
116
|
+
export function toNoise(mad: number, median: number): string {
|
|
117
|
+
return median > 0 ? `±${toPercent((mad / median) * 100)}` : "";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function medianAbsoluteDeviation(values: readonly number[]): number {
|
|
121
|
+
if (values.length === 0) return Number.NaN;
|
|
122
|
+
const median = percentile(sortedCopy([...values]), 0.5);
|
|
123
|
+
return percentile(sortedCopy(values.map((v) => Math.abs(v - median))), 0.5);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// The parts of a verdict that fit 80 columns: every required part, then
|
|
127
|
+
// the optional ones in order while they fit, so a long verdict drops its
|
|
128
|
+
// least telling counts rather than wrap.
|
|
129
|
+
export function fittedParts(
|
|
130
|
+
parts: readonly { text: string; required?: boolean }[],
|
|
131
|
+
): string {
|
|
132
|
+
let width = parts
|
|
133
|
+
.filter((p) => p.required)
|
|
134
|
+
.reduce((sum, p, i) => sum + textWidth(p.text) + (i > 0 ? 3 : 0), 0);
|
|
135
|
+
return parts
|
|
136
|
+
.filter((p) => {
|
|
137
|
+
if (p.required) return true;
|
|
138
|
+
const more = textWidth(p.text) + 3;
|
|
139
|
+
if (width + more > MEASURE) return false;
|
|
140
|
+
width += more;
|
|
141
|
+
return true;
|
|
142
|
+
})
|
|
143
|
+
.map((p) => p.text)
|
|
144
|
+
.join(SEPARATOR);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// The machine, since a number means little without where it ran.
|
|
148
|
+
export function environmentParts(env: Environment | undefined): string[] {
|
|
149
|
+
if (!env) return [];
|
|
150
|
+
return [
|
|
151
|
+
env.cpuModel,
|
|
152
|
+
`${env.cores} cores`,
|
|
153
|
+
`load ${env.loadAvg1.toFixed(1)}`,
|
|
154
|
+
`noise floor ${env.noise.floorPct.toFixed(1)}%`,
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// The context, packed into as few dim lines as fit 80 columns, a part
|
|
159
|
+
// never split, so a long environment wraps between parts.
|
|
160
|
+
export function contextLines(parts: readonly string[], paint: Paint): string[] {
|
|
161
|
+
const lines: string[] = [];
|
|
162
|
+
let line = "";
|
|
163
|
+
for (const part of parts.filter((p) => p !== "")) {
|
|
164
|
+
const next = line === "" ? part : `${line}${SEPARATOR}${part}`;
|
|
165
|
+
if (line !== "" && textWidth(next) > MEASURE) {
|
|
166
|
+
lines.push(line);
|
|
167
|
+
line = truncateWords(part, MEASURE);
|
|
168
|
+
} else
|
|
169
|
+
line = textWidth(next) > MEASURE ? truncateWords(next, MEASURE) : next;
|
|
170
|
+
}
|
|
171
|
+
if (line !== "") lines.push(line);
|
|
172
|
+
return lines.map((l) => paint.dim(l));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
type Tone = "good" | "warn" | "bad" | "dim";
|
|
176
|
+
|
|
177
|
+
export interface Note {
|
|
178
|
+
text: string;
|
|
179
|
+
tone: Tone;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Tukey's fences, as `computeTimingStats` uses, so a note agrees with
|
|
183
|
+
// the count.
|
|
184
|
+
const OUTLIER_FENCE = 1.5;
|
|
185
|
+
|
|
186
|
+
// Whether the outliers move the median by more than the noise: the median
|
|
187
|
+
// with them dropped, against the median, past one MAD. The median shrugs
|
|
188
|
+
// off a few outliers, so a count alone says nothing; a shift past the
|
|
189
|
+
// noise is what makes the number wrong.
|
|
190
|
+
function isOutlierShifted(timing: TimingStats): boolean {
|
|
191
|
+
const iqr = timing.p75 - timing.p25;
|
|
192
|
+
const low = timing.p25 - OUTLIER_FENCE * iqr;
|
|
193
|
+
const high = timing.p75 + OUTLIER_FENCE * iqr;
|
|
194
|
+
const kept = timing.samples.filter((s) => s >= low && s <= high);
|
|
195
|
+
if (kept.length === 0 || kept.length === timing.samples.length) return false;
|
|
196
|
+
const median = percentile(sortedCopy(kept), 0.5);
|
|
197
|
+
return Math.abs(median - timing.median) > Math.max(timing.mad, 0);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export const numberIn = (
|
|
201
|
+
data: Warning["data"],
|
|
202
|
+
key: string,
|
|
203
|
+
): number | undefined => {
|
|
204
|
+
const value = data?.[key];
|
|
205
|
+
return typeof value === "number" ? value : undefined;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// A message as written for the JSON, without its full stop, so it reads
|
|
209
|
+
// as a note.
|
|
210
|
+
const asNote = (message: string) => message.replace(/\.$/, "");
|
|
211
|
+
|
|
212
|
+
// A warning in words, with its fix where there is one; `timing` decides
|
|
213
|
+
// whether outliers are a problem or an aside, since that turns on
|
|
214
|
+
// the samples.
|
|
215
|
+
export function toWarningNote(w: Warning, timing?: TimingStats): Note {
|
|
216
|
+
const data = w.data;
|
|
217
|
+
switch (w.code) {
|
|
218
|
+
case "slow-first-run": {
|
|
219
|
+
const firstNs = numberIn(data, "firstNs");
|
|
220
|
+
const medianNs = numberIn(data, "medianNs");
|
|
221
|
+
if (firstNs === undefined || medianNs === undefined || medianNs <= 0) {
|
|
222
|
+
return { text: asNote(w.message), tone: "warn" };
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
text: `first run ${toDuration(firstNs)}, ${toTimes(firstNs / medianNs)} the median: add warmup`,
|
|
226
|
+
tone: "warn",
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
case "outliers-detected": {
|
|
230
|
+
const mild = numberIn(data, "mild") ?? 0;
|
|
231
|
+
const severe = numberIn(data, "severe") ?? 0;
|
|
232
|
+
const shifted = timing !== undefined && isOutlierShifted(timing);
|
|
233
|
+
return {
|
|
234
|
+
text: `${plural(mild + severe, "outlier")}, ${severe} severe${shifted ? ", enough to move the median: a busy machine, or GC" : ": the median holds"}`,
|
|
235
|
+
tone: shifted ? "warn" : "dim",
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
case "fast-command":
|
|
239
|
+
return { text: "under 5 ms: spawn overhead may dominate", tone: "dim" };
|
|
240
|
+
case "nonzero-exit":
|
|
241
|
+
return {
|
|
242
|
+
text: `${asNote(w.message)}: --ignore-failure times them anyway`,
|
|
243
|
+
tone: "bad",
|
|
244
|
+
};
|
|
245
|
+
case "timeout":
|
|
246
|
+
case "time-source-no-match":
|
|
247
|
+
return { text: asNote(w.message), tone: "bad" };
|
|
248
|
+
case "noisy-machine": {
|
|
249
|
+
const load = numberIn(data, "loadAvg1");
|
|
250
|
+
const cores = numberIn(data, "cores");
|
|
251
|
+
return load === undefined || cores === undefined
|
|
252
|
+
? { text: asNote(w.message), tone: "warn" }
|
|
253
|
+
: {
|
|
254
|
+
text: `load ${load.toFixed(1)} on ${cores} cores: timings may be noisy`,
|
|
255
|
+
tone: "warn",
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
case "jit-cold": {
|
|
259
|
+
const slow =
|
|
260
|
+
(numberIn(data, "llintPct") ?? 0) +
|
|
261
|
+
(numberIn(data, "baselinePct") ?? 0);
|
|
262
|
+
return {
|
|
263
|
+
text: `${slow.toFixed(0)}% of samples in the slow tiers: the JIT never warmed it up`,
|
|
264
|
+
tone: "warn",
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
case "thin-comparison": {
|
|
268
|
+
const base = numberIn(data, "baseSamples");
|
|
269
|
+
const cand = numberIn(data, "candSamples");
|
|
270
|
+
return {
|
|
271
|
+
text: `only ${base ?? "?"} and ${cand ?? "?"} samples: judged by a threshold, not a CI`,
|
|
272
|
+
tone: "warn",
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
case "low-sample-count": {
|
|
276
|
+
const samples = numberIn(data, "samples");
|
|
277
|
+
const target = numberIn(data, "target");
|
|
278
|
+
return samples === undefined || target === undefined
|
|
279
|
+
? { text: asNote(w.message), tone: "warn" }
|
|
280
|
+
: {
|
|
281
|
+
text: `only ${samples} samples, under the ${target} this cost needs: raise the budget`,
|
|
282
|
+
tone: "warn",
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
case "peak-hidden": {
|
|
286
|
+
const slack = numberIn(data, "slackBytes");
|
|
287
|
+
return slack === undefined
|
|
288
|
+
? { text: asNote(w.message), tone: "warn" }
|
|
289
|
+
: {
|
|
290
|
+
text: `may read up to ${toBytes(slack)} low: setup freed memory the call reused; skip it when OSTIA_PEAK_MEM is set`,
|
|
291
|
+
tone: "warn",
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
case "suite-changed":
|
|
295
|
+
return {
|
|
296
|
+
text: "the suite and its output both changed, so it isn't judged",
|
|
297
|
+
tone: "dim",
|
|
298
|
+
};
|
|
299
|
+
case "repeats-disagree": {
|
|
300
|
+
const factor = numberIn(data, "factor");
|
|
301
|
+
return {
|
|
302
|
+
text:
|
|
303
|
+
factor === undefined
|
|
304
|
+
? asNote(w.message)
|
|
305
|
+
: `fresh-process repeats ${toTimes(factor)} apart from the paired run: --filter to measure it alone`,
|
|
306
|
+
tone: "warn",
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
case "skipped":
|
|
310
|
+
return { text: asNote(w.message), tone: "dim" };
|
|
311
|
+
case "aborted":
|
|
312
|
+
case "artifact-missing":
|
|
313
|
+
case "empty-profile":
|
|
314
|
+
case "environment-mismatch":
|
|
315
|
+
return { text: asNote(w.message), tone: "warn" };
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Shown once, under the table, since they're about the run, not a row.
|
|
320
|
+
export const RUN_WARNINGS: ReadonlySet<string> = new Set([
|
|
321
|
+
"noisy-machine",
|
|
322
|
+
"aborted",
|
|
323
|
+
"environment-mismatch",
|
|
324
|
+
]);
|
|
325
|
+
|
|
326
|
+
const paintTone = (paint: Paint, tone: Tone): ((s: string) => string) =>
|
|
327
|
+
tone === "good"
|
|
328
|
+
? paint.good
|
|
329
|
+
: tone === "warn"
|
|
330
|
+
? paint.warn
|
|
331
|
+
: tone === "bad"
|
|
332
|
+
? paint.bad
|
|
333
|
+
: paint.dim;
|
|
334
|
+
|
|
335
|
+
// A note wrapped at a word to fit 80 columns, each line at its indent:
|
|
336
|
+
// a note is read whole, so it isn't cut.
|
|
337
|
+
export function noteLines(note: Note, indent: string, paint: Paint): string[] {
|
|
338
|
+
const room = MEASURE - indent.length;
|
|
339
|
+
const lines: string[] = [];
|
|
340
|
+
let line = "";
|
|
341
|
+
for (const word of note.text.split(" ")) {
|
|
342
|
+
if (line !== "" && textWidth(`${line} ${word}`) > room) {
|
|
343
|
+
lines.push(line);
|
|
344
|
+
line = word;
|
|
345
|
+
} else line = line === "" ? word : `${line} ${word}`;
|
|
346
|
+
}
|
|
347
|
+
if (line !== "") lines.push(line);
|
|
348
|
+
return lines.map((l) => `${indent}${paintTone(paint, note.tone)(l)}`);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** One row of a named table: its label, then its cells. */
|
|
352
|
+
export interface NamedRow {
|
|
353
|
+
/** `├ ` or `└ ` under a group, else empty. */
|
|
354
|
+
branch: string;
|
|
355
|
+
name: string;
|
|
356
|
+
/** Bold for a group's label row; plain for a task. */
|
|
357
|
+
bold?: boolean;
|
|
358
|
+
cells: readonly string[];
|
|
359
|
+
notes?: readonly Note[];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const MIN_NAME_WIDTH = 12;
|
|
363
|
+
|
|
364
|
+
// The table's names cut at a word to fit 80 columns, since the numbers
|
|
365
|
+
// can't shrink; notes under a row indent past its branch.
|
|
366
|
+
export function namedTable(
|
|
367
|
+
header: readonly string[],
|
|
368
|
+
rows: readonly NamedRow[],
|
|
369
|
+
rightColumns: readonly number[],
|
|
370
|
+
paint: Paint,
|
|
371
|
+
): string[] {
|
|
372
|
+
const widths = header
|
|
373
|
+
.slice(1)
|
|
374
|
+
.map((cell, i) =>
|
|
375
|
+
Math.max(
|
|
376
|
+
textWidth(cell),
|
|
377
|
+
...rows.map((row) => textWidth(row.cells[i] ?? "")),
|
|
378
|
+
),
|
|
379
|
+
);
|
|
380
|
+
const used = widths.filter((w) => w > 0);
|
|
381
|
+
const room = Math.max(
|
|
382
|
+
MIN_NAME_WIDTH,
|
|
383
|
+
MEASURE - 2 - used.reduce((sum, w) => sum + w + 2, 0),
|
|
384
|
+
);
|
|
385
|
+
const table: string[][] = [[...header]];
|
|
386
|
+
const notes = new Map<number, string[]>();
|
|
387
|
+
for (const row of rows) {
|
|
388
|
+
const name = truncateWords(row.name, room - textWidth(row.branch));
|
|
389
|
+
table.push([
|
|
390
|
+
`${row.branch}${row.bold ? paint.bold(name) : name}`,
|
|
391
|
+
...row.cells,
|
|
392
|
+
]);
|
|
393
|
+
if (row.notes?.length) {
|
|
394
|
+
const indent = row.branch === "" ? NOTE_INDENT : ` ${NOTE_INDENT}`;
|
|
395
|
+
notes.set(
|
|
396
|
+
table.length - 1,
|
|
397
|
+
row.notes.flatMap((note) => noteLines(note, indent, paint)),
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return withNotes(aligned(table, rightColumns, paint.dim), notes);
|
|
402
|
+
}
|
package/src/renderers/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { collapsedRenderer } from "./collapsed.ts";
|
|
2
|
+
import { conciseRenderer } from "./concise.ts";
|
|
2
3
|
import { cpuprofileRenderer } from "./cpuprofile.ts";
|
|
3
4
|
import { jsonRenderer } from "./json.ts";
|
|
4
5
|
import { jsonlRenderer } from "./jsonl.ts";
|
|
@@ -6,18 +7,21 @@ import { markdownRenderer } from "./markdown.ts";
|
|
|
6
7
|
import { type MermaidOptions, mermaidRenderer } from "./mermaid.ts";
|
|
7
8
|
import { minimalRenderer, type MinimalRenderOptions } from "./minimal.ts";
|
|
8
9
|
import { speedscopeRenderer } from "./speedscope.ts";
|
|
9
|
-
import { terminalRenderer } from "./terminal.ts";
|
|
10
|
+
import { type TableOptions, terminalRenderer } from "./terminal.ts";
|
|
10
11
|
import type { FormatName, Renderer, VizOptions } from "./types.ts";
|
|
11
12
|
|
|
12
13
|
/** Each format's renderer, typed with its own options. `Renderer<never>` is
|
|
13
14
|
* the top type, so `satisfies` checks every format is present without
|
|
14
15
|
* widening the options. */
|
|
15
16
|
export const renderers: {
|
|
16
|
-
table: Renderer
|
|
17
|
+
table: Renderer<TableOptions>;
|
|
17
18
|
json: Renderer;
|
|
18
19
|
markdown: Renderer;
|
|
19
20
|
jsonl: Renderer;
|
|
21
|
+
events: Renderer<MinimalRenderOptions>;
|
|
22
|
+
/** `events`, by the name it had until 0.5.0. */
|
|
20
23
|
minimal: Renderer<MinimalRenderOptions>;
|
|
24
|
+
concise: Renderer;
|
|
21
25
|
collapsed: Renderer<VizOptions>;
|
|
22
26
|
mermaid: Renderer<MermaidOptions>;
|
|
23
27
|
speedscope: Renderer<VizOptions>;
|
|
@@ -27,11 +31,14 @@ export const renderers: {
|
|
|
27
31
|
json: jsonRenderer,
|
|
28
32
|
markdown: markdownRenderer,
|
|
29
33
|
jsonl: jsonlRenderer,
|
|
34
|
+
events: minimalRenderer,
|
|
30
35
|
minimal: minimalRenderer,
|
|
36
|
+
concise: conciseRenderer,
|
|
31
37
|
collapsed: collapsedRenderer,
|
|
32
38
|
mermaid: mermaidRenderer,
|
|
33
39
|
speedscope: speedscopeRenderer,
|
|
34
40
|
cpuprofile: cpuprofileRenderer,
|
|
35
41
|
} satisfies Record<FormatName, Renderer<never>>;
|
|
36
42
|
|
|
43
|
+
export type { TableOptions } from "./terminal.ts";
|
|
37
44
|
export type { FormatName, Renderer, RenderResult } from "./types.ts";
|
|
@@ -373,8 +373,8 @@ function timingSection(
|
|
|
373
373
|
for (const { run, workload } of groupRows) {
|
|
374
374
|
const v1 = workload?.params?.[key1];
|
|
375
375
|
const v2 = workload?.params?.[key2];
|
|
376
|
-
// invariant: `pivotKeysFor` pivots only rows whose params hold
|
|
377
|
-
// keys.
|
|
376
|
+
// invariant: `pivotKeysFor` pivots only rows whose params hold
|
|
377
|
+
// both keys.
|
|
378
378
|
if (v1 === undefined || v2 === undefined) continue;
|
|
379
379
|
if (!rowValues.includes(v1)) rowValues.push(v1);
|
|
380
380
|
if (!colValues.includes(v2)) colValues.push(v2);
|
package/src/renderers/mermaid.ts
CHANGED
|
@@ -57,8 +57,8 @@ export const mermaidRenderer: Renderer<MermaidOptions> = {
|
|
|
57
57
|
const { parentIx } = tree;
|
|
58
58
|
const rootIx = tree.roots[0] ?? -1;
|
|
59
59
|
|
|
60
|
-
// The top-N self-time nodes plus every ancestor, so each has a path to
|
|
61
|
-
// root.
|
|
60
|
+
// The top-N self-time nodes plus every ancestor, so each has a path to
|
|
61
|
+
// the root.
|
|
62
62
|
const included = new Set<number>(rootIx !== -1 ? [rootIx] : []);
|
|
63
63
|
for (const ix of topNBySelf(selfUs, tree.count, rootIx, topN)) {
|
|
64
64
|
const path: number[] = [];
|