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
package/src/cli/run.ts
CHANGED
|
@@ -8,15 +8,12 @@ import {
|
|
|
8
8
|
AbSuiteError,
|
|
9
9
|
cleanAbTrees,
|
|
10
10
|
} from "../ab/index.ts";
|
|
11
|
+
import { importsHarnessRelatively, unpairedReason } from "../ab/unpaired.ts";
|
|
11
12
|
import { listBaselines, saveBaseline } from "../baseline/index.ts";
|
|
12
13
|
import { bench, resolveBenchOptions } from "../bench/index.ts";
|
|
13
|
-
import {
|
|
14
|
-
BaselineError,
|
|
15
|
-
BaselineNotFoundError,
|
|
16
|
-
renderCiReport,
|
|
17
|
-
runCi,
|
|
18
|
-
} from "../ci/index.ts";
|
|
14
|
+
import { BaselineError, BaselineNotFoundError, runCi } from "../ci/index.ts";
|
|
19
15
|
import { compareDocuments, DEFAULT_THRESHOLDS } from "../compare/index.ts";
|
|
16
|
+
import { nowMs, processEnv } from "../config/env.ts";
|
|
20
17
|
import {
|
|
21
18
|
baselinePath,
|
|
22
19
|
CONFIG_FILES,
|
|
@@ -37,14 +34,31 @@ import type { AbSummary, ProfileDocument } from "../ir/types.ts";
|
|
|
37
34
|
import { sideLabel } from "../measure/paired.ts";
|
|
38
35
|
import { isHarnessFailure } from "../measure/timing.ts";
|
|
39
36
|
import { formatGit, workloadLabel } from "../renderers/format.ts";
|
|
40
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
type FormatName,
|
|
39
|
+
renderers,
|
|
40
|
+
type TableOptions,
|
|
41
|
+
} from "../renderers/index.ts";
|
|
41
42
|
import type { MinimalProtocolContext } from "../renderers/minimal.ts";
|
|
42
43
|
import type { TimeSource, TimeUnit } from "../spawn/index.ts";
|
|
44
|
+
import {
|
|
45
|
+
createProgress,
|
|
46
|
+
type Paint,
|
|
47
|
+
PLAIN,
|
|
48
|
+
plural,
|
|
49
|
+
type Progress,
|
|
50
|
+
SILENT,
|
|
51
|
+
truncatePath,
|
|
52
|
+
truncateWords,
|
|
53
|
+
} from "../terminal.ts";
|
|
54
|
+
import { agentVariable, withDefaultFormat } from "./agent.ts";
|
|
43
55
|
import {
|
|
44
56
|
CliUsageError,
|
|
57
|
+
COLOR_FLAGS,
|
|
45
58
|
CONFIG_FLAGS,
|
|
46
59
|
type ConfigArgs,
|
|
47
60
|
flag,
|
|
61
|
+
FORMAT_ALIASES,
|
|
48
62
|
HELP_FLAGS,
|
|
49
63
|
NOISE_CHECK_FLAGS,
|
|
50
64
|
OUTPUT_DEFAULTS,
|
|
@@ -58,16 +72,7 @@ import {
|
|
|
58
72
|
SUITE_FLAGS,
|
|
59
73
|
VIZ_FORMATS,
|
|
60
74
|
} from "./flags.ts";
|
|
61
|
-
import {
|
|
62
|
-
AB_HELP,
|
|
63
|
-
BASELINE_HELP,
|
|
64
|
-
BENCH_HELP,
|
|
65
|
-
CI_HELP,
|
|
66
|
-
COMPARE_HELP,
|
|
67
|
-
MAIN_HELP,
|
|
68
|
-
REPORT_HELP,
|
|
69
|
-
TIME_HELP,
|
|
70
|
-
} from "./help.ts";
|
|
75
|
+
import { type HelpTopic, paintFor, showHelp } from "./help.ts";
|
|
71
76
|
import {
|
|
72
77
|
CliError,
|
|
73
78
|
type CliErrorCode,
|
|
@@ -75,13 +80,53 @@ import {
|
|
|
75
80
|
exportDocument,
|
|
76
81
|
orFail,
|
|
77
82
|
out,
|
|
78
|
-
showHelp,
|
|
79
83
|
writeCliError,
|
|
80
84
|
writeRenderResult,
|
|
81
85
|
} from "./output.ts";
|
|
82
86
|
|
|
83
87
|
const isHelpArg = (arg: string | undefined) => arg === "--help" || arg === "-h";
|
|
84
88
|
|
|
89
|
+
interface Human {
|
|
90
|
+
paint: Paint;
|
|
91
|
+
progress: Progress;
|
|
92
|
+
startNs: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Room for a progress step after its 20-cell bar and before its seconds,
|
|
96
|
+
// so the line fits 80 columns.
|
|
97
|
+
const PROGRESS_TEXT_WIDTH = 48;
|
|
98
|
+
|
|
99
|
+
const stepText = (text: string) => truncateWords(text, PROGRESS_TEXT_WIDTH);
|
|
100
|
+
|
|
101
|
+
const elapsedMsSince = (startNs: number) => (Bun.nanoseconds() - startNs) / 1e6;
|
|
102
|
+
|
|
103
|
+
// Color and the progress line only for the table on a terminal no coding
|
|
104
|
+
// agent reads, since every other format is read by a program.
|
|
105
|
+
async function humanFor(args: {
|
|
106
|
+
format: FormatName;
|
|
107
|
+
quiet: boolean;
|
|
108
|
+
color?: boolean;
|
|
109
|
+
}): Promise<Human> {
|
|
110
|
+
const startNs = Bun.nanoseconds();
|
|
111
|
+
if (args.format !== "table") {
|
|
112
|
+
return { paint: PLAIN, progress: SILENT, startNs };
|
|
113
|
+
}
|
|
114
|
+
const { isatty } = await import("node:tty");
|
|
115
|
+
const shown =
|
|
116
|
+
!args.quiet && isatty(2) && agentVariable(processEnv()) === undefined;
|
|
117
|
+
return {
|
|
118
|
+
paint: await paintFor(1, args.color),
|
|
119
|
+
progress: shown
|
|
120
|
+
? createProgress(
|
|
121
|
+
(text) => writeSync(2, text),
|
|
122
|
+
await paintFor(2, args.color),
|
|
123
|
+
nowMs,
|
|
124
|
+
)
|
|
125
|
+
: SILENT,
|
|
126
|
+
startNs,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
85
130
|
// Runs `run` with SIGINT wired to its `AbortSignal`, so Ctrl-C cancels
|
|
86
131
|
// cleanly with partial results.
|
|
87
132
|
async function withSigintAbort<T>(
|
|
@@ -150,8 +195,8 @@ const TIME_UNITS: readonly TimeUnit[] = ["ns", "us", "ms", "s"];
|
|
|
150
195
|
interface TimeArgs extends RunArgs {
|
|
151
196
|
commands: string[];
|
|
152
197
|
/**
|
|
153
|
-
* Everything after `--`: one more command, whose argv is
|
|
154
|
-
* whitespace-split.
|
|
198
|
+
* Everything after `--`: one more command, whose argv is
|
|
199
|
+
* never whitespace-split.
|
|
155
200
|
*/
|
|
156
201
|
argvCommand: string[];
|
|
157
202
|
/** One entry applies to every command; otherwise one per command. */
|
|
@@ -169,6 +214,9 @@ interface TimeArgs extends RunArgs {
|
|
|
169
214
|
timeoutMs?: number;
|
|
170
215
|
ignoreExitCodes: number[];
|
|
171
216
|
outDir?: string;
|
|
217
|
+
shell?: string;
|
|
218
|
+
saveOutput?: string;
|
|
219
|
+
showOutput?: boolean;
|
|
172
220
|
}
|
|
173
221
|
|
|
174
222
|
const TIME_FLAGS = {
|
|
@@ -179,6 +227,9 @@ const TIME_FLAGS = {
|
|
|
179
227
|
"--warmup": flag.int("warmup", 0),
|
|
180
228
|
"--no-interleave": flag.off("interleave"),
|
|
181
229
|
"--prepare": flag.list("prepare"),
|
|
230
|
+
"--shell": flag.str("shell"),
|
|
231
|
+
"--save-output": flag.str("saveOutput"),
|
|
232
|
+
"--show-output": flag.on("showOutput"),
|
|
182
233
|
"--time-source": flag.str("timeSource"),
|
|
183
234
|
"--time-unit": flag.oneOf("timeUnit", TIME_UNITS),
|
|
184
235
|
"--cpu": flag.on("cpu"),
|
|
@@ -216,7 +267,7 @@ async function timeCommand(argv: string[]): Promise<number> {
|
|
|
216
267
|
...(parsed.argvCommand.length > 0 ? [parsed.argvCommand] : []),
|
|
217
268
|
];
|
|
218
269
|
if (parsed.help || commandList.length === 0) {
|
|
219
|
-
return showHelp(
|
|
270
|
+
return showHelp("time", parsed.help);
|
|
220
271
|
}
|
|
221
272
|
|
|
222
273
|
if (
|
|
@@ -265,11 +316,19 @@ async function timeCommand(argv: string[]): Promise<number> {
|
|
|
265
316
|
}),
|
|
266
317
|
}));
|
|
267
318
|
|
|
319
|
+
const human = await humanFor(parsed);
|
|
268
320
|
const { result: doc, aborted } = await withSigintAbort(
|
|
269
321
|
"Run failed",
|
|
270
322
|
(signal) =>
|
|
271
323
|
time({
|
|
272
324
|
commands,
|
|
325
|
+
...(human.progress !== SILENT && {
|
|
326
|
+
onProgress: (p) =>
|
|
327
|
+
human.progress.step(
|
|
328
|
+
stepText(`time ${p.command} of ${p.commands} · ${p.label}`),
|
|
329
|
+
p.doneRatio,
|
|
330
|
+
),
|
|
331
|
+
}),
|
|
273
332
|
...definedFields({
|
|
274
333
|
timeSource,
|
|
275
334
|
samples: parsed.samples,
|
|
@@ -284,12 +343,21 @@ async function timeCommand(argv: string[]): Promise<number> {
|
|
|
284
343
|
ignoreExitCodes: parsed.ignoreExitCodes,
|
|
285
344
|
outDir: parsed.outDir,
|
|
286
345
|
noiseCheck: parsed.noiseCheck,
|
|
346
|
+
noiseBudgetMs: parsed.noiseBudgetMs,
|
|
347
|
+
shell: parsed.shell,
|
|
348
|
+
saveOutput: parsed.saveOutput,
|
|
349
|
+
showOutput: parsed.showOutput,
|
|
287
350
|
}),
|
|
288
351
|
signal,
|
|
289
|
-
}),
|
|
352
|
+
}).finally(() => human.progress.clear()),
|
|
290
353
|
);
|
|
291
354
|
|
|
292
|
-
await emitDocument(
|
|
355
|
+
await emitDocument(
|
|
356
|
+
doc,
|
|
357
|
+
parsed,
|
|
358
|
+
{},
|
|
359
|
+
{ paint: human.paint, elapsedMs: elapsedMsSince(human.startNs) },
|
|
360
|
+
);
|
|
293
361
|
if (aborted) return 130;
|
|
294
362
|
|
|
295
363
|
// A failing command is exit 2 (couldn't measure), not 1, because 1 is
|
|
@@ -374,21 +442,67 @@ function parseBenchArgs(argv: string[]): BenchArgs {
|
|
|
374
442
|
});
|
|
375
443
|
}
|
|
376
444
|
|
|
445
|
+
// One suite names itself and several are counted, so the context stays
|
|
446
|
+
// one line.
|
|
447
|
+
async function anyImportsHarnessRelatively(
|
|
448
|
+
suites: readonly string[],
|
|
449
|
+
): Promise<boolean> {
|
|
450
|
+
for (const suite of suites) {
|
|
451
|
+
const file = Bun.file(suite);
|
|
452
|
+
if ((await file.exists()) && importsHarnessRelatively(await file.text())) {
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function suitesRun(suites: readonly string[]): string {
|
|
460
|
+
const [only] = suites;
|
|
461
|
+
return suites.length === 1 && only !== undefined
|
|
462
|
+
? truncatePath(only, 40)
|
|
463
|
+
: plural(suites.length, "suite");
|
|
464
|
+
}
|
|
465
|
+
|
|
377
466
|
async function benchCommand(argv: string[]): Promise<number> {
|
|
378
467
|
const parsed = parseBenchArgs(argv);
|
|
379
|
-
if (parsed.help) return showHelp(
|
|
468
|
+
if (parsed.help) return showHelp("bench", true);
|
|
380
469
|
|
|
381
470
|
const config = await loadProjectConfig(parsed.config);
|
|
382
471
|
const resolved = await resolveBenchOptions(parsed, config?.bench);
|
|
383
472
|
|
|
384
|
-
if (resolved.suites.length === 0) return showHelp(
|
|
473
|
+
if (resolved.suites.length === 0) return showHelp("bench", false);
|
|
385
474
|
|
|
475
|
+
const human = await humanFor(parsed);
|
|
386
476
|
const { result: doc, aborted } = await withSigintAbort(
|
|
387
477
|
"Bench failed",
|
|
388
|
-
(signal) =>
|
|
478
|
+
(signal) =>
|
|
479
|
+
bench({
|
|
480
|
+
...resolved,
|
|
481
|
+
signal,
|
|
482
|
+
...(human.progress !== SILENT && {
|
|
483
|
+
onProgress: (p) =>
|
|
484
|
+
human.progress.step(
|
|
485
|
+
stepText(
|
|
486
|
+
p.suites > 1
|
|
487
|
+
? `bench ${p.file} · ${p.task} of ${p.tasks} · ${p.label}`
|
|
488
|
+
: `bench ${p.task} of ${p.tasks} · ${p.label}`,
|
|
489
|
+
),
|
|
490
|
+
(p.suite - 1 + (p.task - 1) / p.tasks) / p.suites,
|
|
491
|
+
),
|
|
492
|
+
}),
|
|
493
|
+
}).finally(() => human.progress.clear()),
|
|
389
494
|
);
|
|
390
495
|
|
|
391
|
-
await emitDocument(
|
|
496
|
+
await emitDocument(
|
|
497
|
+
doc,
|
|
498
|
+
parsed,
|
|
499
|
+
{},
|
|
500
|
+
{
|
|
501
|
+
paint: human.paint,
|
|
502
|
+
ran: suitesRun(resolved.suites),
|
|
503
|
+
elapsedMs: elapsedMsSince(human.startNs),
|
|
504
|
+
},
|
|
505
|
+
);
|
|
392
506
|
return aborted ? 130 : 0;
|
|
393
507
|
}
|
|
394
508
|
|
|
@@ -472,6 +586,50 @@ function progressWriter(tty: boolean): {
|
|
|
472
586
|
};
|
|
473
587
|
}
|
|
474
588
|
|
|
589
|
+
// The shared progress line: the step, and how far through every suite's
|
|
590
|
+
// two passes. Confirming and memory runs come after the passes, so they
|
|
591
|
+
// keep the bar where the passes left it.
|
|
592
|
+
function abProgressLine(line: Progress): {
|
|
593
|
+
onProgress: (p: AbProgress) => void;
|
|
594
|
+
done: () => void;
|
|
595
|
+
} {
|
|
596
|
+
let doneRatio = 0;
|
|
597
|
+
return {
|
|
598
|
+
onProgress: (p) => {
|
|
599
|
+
switch (p.phase) {
|
|
600
|
+
case "setup":
|
|
601
|
+
line.step(stepText(`ab base setup · ${p.command}`), 0);
|
|
602
|
+
return;
|
|
603
|
+
case "measure": {
|
|
604
|
+
doneRatio =
|
|
605
|
+
((p.suite - 1) * p.passes + p.pass - 1 + (p.task - 1) / p.tasks) /
|
|
606
|
+
(p.suites * p.passes);
|
|
607
|
+
const suite = p.suites > 1 ? `${p.file} · ` : "";
|
|
608
|
+
line.step(
|
|
609
|
+
stepText(`ab ${suite}${p.task} of ${p.tasks} · ${p.label}`),
|
|
610
|
+
doneRatio,
|
|
611
|
+
);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
case "confirm":
|
|
615
|
+
line.step(
|
|
616
|
+
stepText(`ab confirming ${p.repeat} of ${p.repeats} · ${p.label}`),
|
|
617
|
+
doneRatio,
|
|
618
|
+
);
|
|
619
|
+
return;
|
|
620
|
+
case "memory":
|
|
621
|
+
line.step(
|
|
622
|
+
stepText(
|
|
623
|
+
`ab memory ${p.run} of ${p.runs} · ${sideLabel(p.side)} · ${p.label}`,
|
|
624
|
+
),
|
|
625
|
+
doneRatio,
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
done: () => line.clear(),
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
|
|
475
633
|
function parseAbArgs(argv: string[]): AbArgs {
|
|
476
634
|
const args: AbArgs = {
|
|
477
635
|
...RUN_DEFAULTS,
|
|
@@ -491,7 +649,7 @@ function parseAbArgs(argv: string[]): AbArgs {
|
|
|
491
649
|
|
|
492
650
|
async function abCommand(argv: string[]): Promise<number> {
|
|
493
651
|
const parsed = parseAbArgs(argv);
|
|
494
|
-
if (parsed.help) return showHelp(
|
|
652
|
+
if (parsed.help) return showHelp("ab", true);
|
|
495
653
|
|
|
496
654
|
const config = await loadProjectConfig(parsed.config);
|
|
497
655
|
if (parsed.clean) {
|
|
@@ -514,15 +672,22 @@ async function abCommand(argv: string[]): Promise<number> {
|
|
|
514
672
|
timeoutMs,
|
|
515
673
|
outDir,
|
|
516
674
|
noiseCheck,
|
|
675
|
+
noiseBudgetMs,
|
|
517
676
|
} = await resolveBenchOptions(parsed, config?.bench);
|
|
518
|
-
if (suites.length === 0) return showHelp(
|
|
677
|
+
if (suites.length === 0) return showHelp("ab", false);
|
|
519
678
|
|
|
679
|
+
const human = await humanFor(parsed);
|
|
520
680
|
const { isatty } = await import("node:tty");
|
|
521
|
-
|
|
681
|
+
// The redrawn line where a person watches; the plain lines only when
|
|
682
|
+
// asked for, as for a log.
|
|
522
683
|
const progress =
|
|
523
|
-
|
|
524
|
-
?
|
|
525
|
-
:
|
|
684
|
+
parsed.progress === false
|
|
685
|
+
? undefined
|
|
686
|
+
: human.progress !== SILENT
|
|
687
|
+
? abProgressLine(human.progress)
|
|
688
|
+
: parsed.progress
|
|
689
|
+
? progressWriter(isatty(2))
|
|
690
|
+
: undefined;
|
|
526
691
|
|
|
527
692
|
const { result: doc, aborted } = await withSigintAbort(
|
|
528
693
|
"A/B run failed",
|
|
@@ -553,6 +718,7 @@ async function abCommand(argv: string[]): Promise<number> {
|
|
|
553
718
|
outDir,
|
|
554
719
|
keepTrees: parsed.keepTrees ?? config?.ab?.keepTrees,
|
|
555
720
|
noiseCheck,
|
|
721
|
+
noiseBudgetMs,
|
|
556
722
|
}),
|
|
557
723
|
signal,
|
|
558
724
|
...definedFields({ onProgress: progress?.onProgress }),
|
|
@@ -588,25 +754,40 @@ async function abCommand(argv: string[]): Promise<number> {
|
|
|
588
754
|
const byId = new Map(doc.workloads.map((w) => [w.id, w]));
|
|
589
755
|
const workloadsFor = (ids: string[] = []) =>
|
|
590
756
|
ids.flatMap((id) => byId.get(id) ?? []);
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
757
|
+
const paired = summary.matched + summary.threw;
|
|
758
|
+
const unpaired =
|
|
759
|
+
exitCode === 2 && paired === 0
|
|
760
|
+
? unpairedReason({
|
|
761
|
+
ref: summary.base.ref,
|
|
762
|
+
base: paired + (doc.unmatched?.baseOnly.length ?? 0),
|
|
763
|
+
cand: paired + (doc.unmatched?.candOnly.length ?? 0),
|
|
764
|
+
allNew: summary.newSuites?.length === suites.length,
|
|
765
|
+
relativeHarness: await anyImportsHarnessRelatively(suites),
|
|
766
|
+
})
|
|
767
|
+
: undefined;
|
|
768
|
+
await emitDocument(
|
|
769
|
+
doc,
|
|
770
|
+
parsed,
|
|
771
|
+
{
|
|
772
|
+
protocol: {
|
|
773
|
+
command: "ab",
|
|
774
|
+
exitCode,
|
|
775
|
+
unmatched: {
|
|
776
|
+
baseOnly: workloadsFor(doc.unmatched?.baseOnly),
|
|
777
|
+
candOnly: workloadsFor(doc.unmatched?.candOnly),
|
|
778
|
+
},
|
|
779
|
+
...(parsed.exportJson && { exportedTo: parsed.exportJson }),
|
|
780
|
+
} satisfies MinimalProtocolContext,
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
paint: human.paint,
|
|
784
|
+
ran: suitesRun(suites),
|
|
785
|
+
elapsedMs: elapsedMsSince(human.startNs),
|
|
786
|
+
...definedFields({ unpaired }),
|
|
787
|
+
},
|
|
788
|
+
);
|
|
789
|
+
if (unpaired) {
|
|
790
|
+
await writeCliError("no-matches", `${unpaired.what}: ${unpaired.next}.`);
|
|
610
791
|
}
|
|
611
792
|
return exitCode;
|
|
612
793
|
}
|
|
@@ -634,7 +815,7 @@ function parseCompareArgs(argv: string[]): CompareArgs {
|
|
|
634
815
|
|
|
635
816
|
async function compareCommand(argv: string[]): Promise<number> {
|
|
636
817
|
const parsed = parseCompareArgs(argv);
|
|
637
|
-
if (parsed.help) return showHelp(
|
|
818
|
+
if (parsed.help) return showHelp("compare", true);
|
|
638
819
|
|
|
639
820
|
const maxPaths = parsed.baseline ? 1 : 2;
|
|
640
821
|
if (parsed.paths.length > maxPaths) {
|
|
@@ -647,7 +828,7 @@ async function compareCommand(argv: string[]): Promise<number> {
|
|
|
647
828
|
const [basePath, candPath] = parsed.baseline
|
|
648
829
|
? [parsed.baseline, parsed.paths[0]]
|
|
649
830
|
: parsed.paths;
|
|
650
|
-
if (!basePath || !candPath) return showHelp(
|
|
831
|
+
if (!basePath || !candPath) return showHelp("compare", false);
|
|
651
832
|
|
|
652
833
|
const [base, cand] = await orFail(
|
|
653
834
|
"document-load-failed",
|
|
@@ -672,31 +853,41 @@ async function compareCommand(argv: string[]): Promise<number> {
|
|
|
672
853
|
compared: result.compared,
|
|
673
854
|
};
|
|
674
855
|
|
|
675
|
-
// json/jsonl/minimal stay pure JSON on stdout, so only
|
|
676
|
-
//
|
|
677
|
-
|
|
678
|
-
!parsed.quiet &&
|
|
679
|
-
(parsed.format === "table" || parsed.format === "markdown");
|
|
680
|
-
if (humanFormat) {
|
|
856
|
+
// json/jsonl/minimal stay pure JSON on stdout, so only markdown gets
|
|
857
|
+
// prose banners; the table puts the same facts in its context line.
|
|
858
|
+
if (!parsed.quiet && parsed.format === "markdown") {
|
|
681
859
|
await out(`thresholds: ${thresholdsSource}\n`);
|
|
682
860
|
if (base.git && cand.git) {
|
|
683
861
|
await out(`base ${formatGit(base.git)} → cand ${formatGit(cand.git)}\n`);
|
|
684
862
|
}
|
|
685
863
|
}
|
|
864
|
+
const human = await humanFor(parsed);
|
|
686
865
|
|
|
687
866
|
// Computed before rendering because `minimal`'s trailing `summary` event
|
|
688
867
|
// carries it.
|
|
689
868
|
const exitCode = gateExitCode(result.summary);
|
|
690
869
|
|
|
691
|
-
await emitDocument(
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
870
|
+
await emitDocument(
|
|
871
|
+
outDoc,
|
|
872
|
+
parsed,
|
|
873
|
+
{
|
|
874
|
+
protocol: {
|
|
875
|
+
command: "compare",
|
|
876
|
+
exitCode,
|
|
877
|
+
unmatched: result.unmatched,
|
|
878
|
+
...definedFields({ baseGit: base.git, candGit: cand.git }),
|
|
879
|
+
...(parsed.exportJson && { exportedTo: parsed.exportJson }),
|
|
880
|
+
} satisfies MinimalProtocolContext,
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
paint: human.paint,
|
|
884
|
+
compare: {
|
|
885
|
+
thresholds: thresholdsSource ?? "the config",
|
|
886
|
+
baseGit: base.git,
|
|
887
|
+
candGit: cand.git,
|
|
888
|
+
},
|
|
889
|
+
},
|
|
890
|
+
);
|
|
700
891
|
|
|
701
892
|
if (result.summary.matched === 0) {
|
|
702
893
|
await writeCliError(
|
|
@@ -714,11 +905,13 @@ interface ReportArgs extends ConfigArgs {
|
|
|
714
905
|
measurementId?: string;
|
|
715
906
|
outDir?: string;
|
|
716
907
|
help: boolean;
|
|
908
|
+
color?: boolean;
|
|
717
909
|
}
|
|
718
910
|
|
|
719
911
|
const REPORT_FLAGS = {
|
|
720
912
|
...HELP_FLAGS,
|
|
721
|
-
|
|
913
|
+
...COLOR_FLAGS,
|
|
914
|
+
"--format": flag.oneOf("format", REPORT_FORMATS, FORMAT_ALIASES),
|
|
722
915
|
"--measurement": flag.str("measurementId"),
|
|
723
916
|
"--out-dir": flag.str("outDir"),
|
|
724
917
|
};
|
|
@@ -745,7 +938,7 @@ const NO_CPU_EVIDENCE =
|
|
|
745
938
|
|
|
746
939
|
async function renderReport(
|
|
747
940
|
path: string,
|
|
748
|
-
{ format, measurementId, outDir }: ReportArgs,
|
|
941
|
+
{ format, measurementId, outDir, color }: ReportArgs,
|
|
749
942
|
): Promise<number> {
|
|
750
943
|
const viz = VIZ_FORMATS.some((f) => f === format);
|
|
751
944
|
const inapplicable = [
|
|
@@ -772,10 +965,12 @@ async function renderReport(
|
|
|
772
965
|
throw new CliError("no-cpu-evidence", NO_CPU_EVIDENCE);
|
|
773
966
|
}
|
|
774
967
|
|
|
775
|
-
const result =
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
968
|
+
const result =
|
|
969
|
+
format === "table"
|
|
970
|
+
? await renderers.table.render(doc, {
|
|
971
|
+
paint: await paintFor(1, color),
|
|
972
|
+
})
|
|
973
|
+
: await renderers[format].render(doc, definedFields({ measurementId }));
|
|
779
974
|
if (!result.text && (!result.files || result.files.length === 0)) {
|
|
780
975
|
throw new CliError(
|
|
781
976
|
"no-cpu-evidence",
|
|
@@ -790,7 +985,7 @@ async function renderReport(
|
|
|
790
985
|
|
|
791
986
|
async function reportCommand(argv: string[]): Promise<number> {
|
|
792
987
|
const parsed = parseReportArgs(argv);
|
|
793
|
-
if (parsed.help || !parsed.path) return showHelp(
|
|
988
|
+
if (parsed.help || !parsed.path) return showHelp("report", parsed.help);
|
|
794
989
|
return renderReport(parsed.path, parsed);
|
|
795
990
|
}
|
|
796
991
|
|
|
@@ -830,7 +1025,7 @@ function ciFailure(err: unknown): never {
|
|
|
830
1025
|
|
|
831
1026
|
async function ciCommand(argv: string[]): Promise<number> {
|
|
832
1027
|
const parsed = parseCiArgs(argv);
|
|
833
|
-
if (parsed.help) return showHelp(
|
|
1028
|
+
if (parsed.help) return showHelp("ci", true);
|
|
834
1029
|
|
|
835
1030
|
const loaded = await requireConfig("ostia ci", parsed.config);
|
|
836
1031
|
const config: OstiaConfig = parsed.noiseCheck
|
|
@@ -839,6 +1034,7 @@ async function ciCommand(argv: string[]): Promise<number> {
|
|
|
839
1034
|
|
|
840
1035
|
// A saved baseline must be fresh measurements, never a cached run.
|
|
841
1036
|
const full = parsed.full || parsed.saveBaseline;
|
|
1037
|
+
const human = await humanFor(parsed);
|
|
842
1038
|
const { result: outcome, aborted } = await withSigintAbort(
|
|
843
1039
|
"CI run failed",
|
|
844
1040
|
(signal) =>
|
|
@@ -847,12 +1043,18 @@ async function ciCommand(argv: string[]): Promise<number> {
|
|
|
847
1043
|
full,
|
|
848
1044
|
...definedFields({ baselineName: parsed.baseline }),
|
|
849
1045
|
signal,
|
|
850
|
-
|
|
1046
|
+
...(human.progress !== SILENT && {
|
|
1047
|
+
onProgress: (step: string, doneRatio: number) =>
|
|
1048
|
+
human.progress.step(stepText(step), doneRatio),
|
|
1049
|
+
}),
|
|
1050
|
+
})
|
|
1051
|
+
.catch(ciFailure)
|
|
1052
|
+
.finally(() => human.progress.clear()),
|
|
851
1053
|
);
|
|
852
1054
|
const { document, summary } = outcome;
|
|
853
1055
|
if (aborted) {
|
|
854
1056
|
// Partial: no comparison, no gate, never a baseline.
|
|
855
|
-
await emitDocument(document, parsed);
|
|
1057
|
+
await emitDocument(document, parsed, {}, { paint: human.paint });
|
|
856
1058
|
return 130;
|
|
857
1059
|
}
|
|
858
1060
|
const baselineName = parsed.baseline ?? config.baseline;
|
|
@@ -883,10 +1085,23 @@ async function ciCommand(argv: string[]): Promise<number> {
|
|
|
883
1085
|
if (jsonText !== undefined) {
|
|
884
1086
|
await out(jsonText);
|
|
885
1087
|
} else if (parsed.format === "table") {
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
1088
|
+
const ci: NonNullable<TableOptions["ci"]> = {
|
|
1089
|
+
baseline: baselineName,
|
|
1090
|
+
workloads: summary.total,
|
|
1091
|
+
cached: summary.cached,
|
|
1092
|
+
executed: summary.executed,
|
|
1093
|
+
failed: summary.results
|
|
1094
|
+
.filter((r) => r.harnessFailed)
|
|
1095
|
+
.map((r) => workloadLabel(r.workload)),
|
|
1096
|
+
missingBaseline: summary.missingBaseline,
|
|
1097
|
+
};
|
|
1098
|
+
await writeRenderResult(
|
|
1099
|
+
await renderers.table.render(document, {
|
|
1100
|
+
paint: human.paint,
|
|
1101
|
+
elapsedMs: elapsedMsSince(human.startNs),
|
|
1102
|
+
ci,
|
|
1103
|
+
}),
|
|
1104
|
+
);
|
|
890
1105
|
} else if (parsed.format === "markdown") {
|
|
891
1106
|
await out(
|
|
892
1107
|
`## ostia ci\n\nBaseline: \`${baselineName}\` (\`${baselineFile}\`) · ${summary.cached} cached, ${summary.executed} executed\n\n`,
|
|
@@ -980,7 +1195,7 @@ async function baselineSaveCommand(argv: string[]): Promise<number> {
|
|
|
980
1195
|
help,
|
|
981
1196
|
config: configPath,
|
|
982
1197
|
} = parseBaselineArgs(argv, "baseline save", true);
|
|
983
|
-
if (help) return showHelp(
|
|
1198
|
+
if (help) return showHelp("baseline", true);
|
|
984
1199
|
if (name !== undefined) assertBaselineName(name);
|
|
985
1200
|
|
|
986
1201
|
const config = await requireConfig("ostia baseline save", configPath);
|
|
@@ -994,7 +1209,7 @@ async function baselineListCommand(argv: string[]): Promise<number> {
|
|
|
994
1209
|
"baseline list",
|
|
995
1210
|
false,
|
|
996
1211
|
);
|
|
997
|
-
if (help) return showHelp(
|
|
1212
|
+
if (help) return showHelp("baseline", true);
|
|
998
1213
|
|
|
999
1214
|
const config = await requireConfig(undefined, configPath);
|
|
1000
1215
|
const infos = await listBaselines(config);
|
|
@@ -1013,7 +1228,7 @@ async function baselineListCommand(argv: string[]): Promise<number> {
|
|
|
1013
1228
|
|
|
1014
1229
|
async function baselineShowCommand(argv: string[]): Promise<number> {
|
|
1015
1230
|
const [name, ...rest] = argv;
|
|
1016
|
-
if (!name || isHelpArg(name)) return showHelp(
|
|
1231
|
+
if (!name || isHelpArg(name)) return showHelp("baseline", !!name);
|
|
1017
1232
|
assertBaselineName(name);
|
|
1018
1233
|
|
|
1019
1234
|
const parsed = parseFlags<ReportArgs>(rest, {
|
|
@@ -1026,7 +1241,7 @@ async function baselineShowCommand(argv: string[]): Promise<number> {
|
|
|
1026
1241
|
);
|
|
1027
1242
|
},
|
|
1028
1243
|
});
|
|
1029
|
-
if (parsed.help) return showHelp(
|
|
1244
|
+
if (parsed.help) return showHelp("report", true);
|
|
1030
1245
|
|
|
1031
1246
|
const config = await requireConfig(undefined, parsed.config);
|
|
1032
1247
|
const path = baselinePath(config, name);
|
|
@@ -1044,7 +1259,7 @@ async function dispatchSubcommand(
|
|
|
1044
1259
|
sub: string | undefined,
|
|
1045
1260
|
rest: string[],
|
|
1046
1261
|
handlers: Record<string, Handler>,
|
|
1047
|
-
help:
|
|
1262
|
+
help: HelpTopic,
|
|
1048
1263
|
unknownMessage: (sub: string) => string,
|
|
1049
1264
|
commandPrefix = "",
|
|
1050
1265
|
): Promise<number> {
|
|
@@ -1084,14 +1299,24 @@ function baselineCommand(argv: string[]): Promise<number> {
|
|
|
1084
1299
|
list: baselineListCommand,
|
|
1085
1300
|
show: baselineShowCommand,
|
|
1086
1301
|
},
|
|
1087
|
-
|
|
1302
|
+
"baseline",
|
|
1088
1303
|
(s) => `Unknown "ostia baseline ${s}". Run "ostia baseline --help".`,
|
|
1089
1304
|
"baseline ",
|
|
1090
1305
|
);
|
|
1091
1306
|
}
|
|
1092
1307
|
|
|
1093
|
-
|
|
1094
|
-
|
|
1308
|
+
// The commands that take `--format`, so the only ones a default
|
|
1309
|
+
// format can be added to.
|
|
1310
|
+
const FORMATTED = new Set(["time", "bench", "ab", "compare", "report", "ci"]);
|
|
1311
|
+
|
|
1312
|
+
export async function main(): Promise<number> {
|
|
1313
|
+
const [subcommand, ...given] = process.argv.slice(2);
|
|
1314
|
+
let rest = given;
|
|
1315
|
+
if (subcommand !== undefined && FORMATTED.has(subcommand)) {
|
|
1316
|
+
const chosen = withDefaultFormat(given);
|
|
1317
|
+
rest = chosen.argv;
|
|
1318
|
+
if (chosen.notice) await Bun.write(Bun.stderr, chosen.notice);
|
|
1319
|
+
}
|
|
1095
1320
|
return dispatchSubcommand(
|
|
1096
1321
|
subcommand,
|
|
1097
1322
|
rest,
|
|
@@ -1104,7 +1329,7 @@ export function main(): Promise<number> {
|
|
|
1104
1329
|
ci: ciCommand,
|
|
1105
1330
|
baseline: baselineCommand,
|
|
1106
1331
|
},
|
|
1107
|
-
|
|
1332
|
+
"main",
|
|
1108
1333
|
(s) => `Unknown subcommand "${s}". Run "ostia --help".`,
|
|
1109
1334
|
);
|
|
1110
1335
|
}
|