ostia 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -26
- package/docs/cli.md +84 -53
- package/docs/document-schema.md +1 -0
- package/docs/library.md +15 -6
- package/docs/statistics.md +4 -3
- package/index.d.ts +74 -2
- package/package.json +1 -1
- package/src/ab/index.ts +41 -0
- package/src/ab/unpaired.ts +54 -0
- package/src/bench/index.ts +28 -0
- package/src/bench/run-tasks.ts +14 -0
- package/src/bench/runner.ts +8 -1
- package/src/ci/index.ts +32 -42
- package/src/cli/flags.ts +20 -3
- package/src/cli/help.ts +670 -263
- package/src/cli/main.ts +2 -3
- package/src/cli/output.ts +11 -11
- package/src/cli/run.ts +289 -88
- package/src/index.ts +3 -2
- package/src/ir/types.ts +2 -0
- package/src/measure/timing.ts +9 -3
- package/src/renderers/human.ts +402 -0
- package/src/renderers/index.ts +3 -2
- package/src/renderers/terminal.ts +1177 -385
- package/src/terminal.ts +321 -0
- package/src/time.ts +49 -10
package/src/bench/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { stampDrift } from "../measure/environment.ts";
|
|
|
15
15
|
import type { PeakMemResult } from "../measure/peak.ts";
|
|
16
16
|
import { assertSamplingOptions } from "../measure/timing.ts";
|
|
17
17
|
import { type SuiteLaunch, suiteLauncher } from "./projects.ts";
|
|
18
|
+
import type { TaskProgress } from "./run-tasks.ts";
|
|
18
19
|
import type { RunnerOpts } from "./runner.ts";
|
|
19
20
|
import {
|
|
20
21
|
absolutePath,
|
|
@@ -106,6 +107,20 @@ export interface BenchOptions {
|
|
|
106
107
|
* `aborted` warning on the last measurement. A suite killed mid-run is
|
|
107
108
|
* dropped entirely: it only writes its result once, at the end. */
|
|
108
109
|
signal?: AbortSignal;
|
|
110
|
+
/** Called before each task is measured, for a progress line. */
|
|
111
|
+
onProgress?: (progress: BenchProgress) => void;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** What `bench()` is doing, for `onProgress`. Counts start at 1. */
|
|
115
|
+
export interface BenchProgress {
|
|
116
|
+
suite: number;
|
|
117
|
+
suites: number;
|
|
118
|
+
/** The suite file, as given. */
|
|
119
|
+
file: string;
|
|
120
|
+
/** The task, among the ones its process measures. */
|
|
121
|
+
task: number;
|
|
122
|
+
tasks: number;
|
|
123
|
+
label: string;
|
|
109
124
|
}
|
|
110
125
|
|
|
111
126
|
const RUNNER_PATH = new URL("./runner.ts", import.meta.url).pathname;
|
|
@@ -301,6 +316,8 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
|
|
|
301
316
|
noiseCheck: false,
|
|
302
317
|
};
|
|
303
318
|
const filter = opts.filter !== undefined && { filter: opts.filter };
|
|
319
|
+
const onProgress = opts.onProgress;
|
|
320
|
+
const progress = onProgress !== undefined && { progress: true };
|
|
304
321
|
|
|
305
322
|
const outPath = (tag: string, suite: Suite, ...rest: unknown[]) =>
|
|
306
323
|
`${tmpDir}/${fp(tag, suite.path, ...rest)}.json`;
|
|
@@ -338,6 +355,15 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
|
|
|
338
355
|
timeoutMs: opts.timeoutMs,
|
|
339
356
|
signal: opts.signal,
|
|
340
357
|
inFlight,
|
|
358
|
+
...(job.runnerOpts.progress && {
|
|
359
|
+
ipc: (message: TaskProgress) =>
|
|
360
|
+
onProgress?.({
|
|
361
|
+
suite: suites.indexOf(job.suite) + 1,
|
|
362
|
+
suites: suites.length,
|
|
363
|
+
file: job.suite.given,
|
|
364
|
+
...message,
|
|
365
|
+
}),
|
|
366
|
+
}),
|
|
341
367
|
},
|
|
342
368
|
);
|
|
343
369
|
if (!ran) return;
|
|
@@ -371,6 +397,7 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
|
|
|
371
397
|
...measureOpts,
|
|
372
398
|
...filter,
|
|
373
399
|
...(opts.isolate !== undefined && { isolate: opts.isolate }),
|
|
400
|
+
...progress,
|
|
374
401
|
preload: p.suite.preload,
|
|
375
402
|
planPath: p.planPath,
|
|
376
403
|
},
|
|
@@ -414,6 +441,7 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
|
|
|
414
441
|
runnerOpts: {
|
|
415
442
|
...measureOpts,
|
|
416
443
|
workloadIds: [item.task.workloadId],
|
|
444
|
+
...progress,
|
|
417
445
|
preload: item.suite.preload,
|
|
418
446
|
markIsolated: true,
|
|
419
447
|
},
|
package/src/bench/run-tasks.ts
CHANGED
|
@@ -77,12 +77,22 @@ export function taskWorkload(
|
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Sent before each task is measured, for a progress line. `task` counts
|
|
82
|
+
* the measured tasks from 1; skipped ones aren't counted. */
|
|
83
|
+
export interface TaskProgress {
|
|
84
|
+
task: number;
|
|
85
|
+
tasks: number;
|
|
86
|
+
label: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
80
89
|
// The caller has already selected `tasks` and handled isolation, so
|
|
81
90
|
// neither happens here.
|
|
82
91
|
export async function measureTasks(
|
|
83
92
|
suiteFile: string,
|
|
84
93
|
tasks: readonly RegisteredTask[],
|
|
85
94
|
opts: MeasureTasksOpts,
|
|
95
|
+
onTask?: (progress: TaskProgress) => void,
|
|
86
96
|
): Promise<ProfileDocument> {
|
|
87
97
|
const willMeasure = tasks.some((t) => !t.skipped);
|
|
88
98
|
const { environment, noiseWarning } = captureRunEnvironment(
|
|
@@ -92,11 +102,15 @@ export async function measureTasks(
|
|
|
92
102
|
|
|
93
103
|
const workloads: Workload[] = [];
|
|
94
104
|
const measurements: Measurement[] = [];
|
|
105
|
+
const measuredCount = tasks.filter((t) => !t.skipped).length;
|
|
106
|
+
let started = 0;
|
|
95
107
|
for (const [idx, t] of tasks.entries()) {
|
|
96
108
|
const workload = taskWorkload(suiteFile, t, opts.markIsolated);
|
|
97
109
|
workloads.push(workload);
|
|
98
110
|
|
|
99
111
|
if (t.skipped) continue;
|
|
112
|
+
started++;
|
|
113
|
+
onTask?.({ task: started, tasks: measuredCount, label: taskIdOf(t) });
|
|
100
114
|
|
|
101
115
|
const { enter, leave } = edges(idx);
|
|
102
116
|
await runGroupHooks(t, "before", enter);
|
package/src/bench/runner.ts
CHANGED
|
@@ -55,6 +55,8 @@ export interface RunnerOpts extends MeasureTasksOpts {
|
|
|
55
55
|
* Scripts imported, in order, before the suite file, in this same process
|
|
56
56
|
* (so globals or `Bun.plugin()` loaders they install reach the suite). */
|
|
57
57
|
preload?: string[];
|
|
58
|
+
/** Send a `TaskProgress` message over IPC before each task. */
|
|
59
|
+
progress?: boolean;
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
// The parent serializes a `RunnerOpts`; only that it's an object
|
|
@@ -154,7 +156,12 @@ async function main(): Promise<number> {
|
|
|
154
156
|
? tasks
|
|
155
157
|
: tasks.filter((t) => !taskIsolate(t, opts.isolate ?? false));
|
|
156
158
|
|
|
157
|
-
const doc = await measureTasks(
|
|
159
|
+
const doc = await measureTasks(
|
|
160
|
+
suiteFile,
|
|
161
|
+
toRun,
|
|
162
|
+
opts,
|
|
163
|
+
opts.progress ? (progress) => process.send?.(progress) : undefined,
|
|
164
|
+
);
|
|
158
165
|
await saveDocument(doc, outputPath);
|
|
159
166
|
return 0;
|
|
160
167
|
}
|
package/src/ci/index.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
bench,
|
|
3
|
+
type BenchProgress,
|
|
4
|
+
resolveBenchOptions,
|
|
5
|
+
} from "../bench/index.ts";
|
|
2
6
|
import { captureRunEnvironment } from "../bench/support.ts";
|
|
3
7
|
import { computeCacheKey, computeInputsDigest } from "../cache/fingerprint.ts";
|
|
4
8
|
import { readCachedRun, writeCachedRun } from "../cache/store.ts";
|
|
@@ -27,7 +31,6 @@ import type {
|
|
|
27
31
|
} from "../ir/types.ts";
|
|
28
32
|
import { stampDrift } from "../measure/environment.ts";
|
|
29
33
|
import { isHarnessFailure, runTimingPhase } from "../measure/timing.ts";
|
|
30
|
-
import { formatSignedPct, workloadLabel } from "../renderers/format.ts";
|
|
31
34
|
import { abortedWarning } from "../time.ts";
|
|
32
35
|
import { TOOL_VERSION } from "../version.ts";
|
|
33
36
|
|
|
@@ -42,8 +45,13 @@ interface CiOptions {
|
|
|
42
45
|
* the cache.
|
|
43
46
|
*/
|
|
44
47
|
signal?: AbortSignal;
|
|
48
|
+
/** Called as each workload (and each suite task) starts. */
|
|
49
|
+
onProgress?: CiProgress;
|
|
45
50
|
}
|
|
46
51
|
|
|
52
|
+
/** A progress line's step text, and how far the run is, 0 to 1. */
|
|
53
|
+
type CiProgress = (step: string, doneRatio: number) => void;
|
|
54
|
+
|
|
47
55
|
// So a hung workload times out instead of blocking a CI job;
|
|
48
56
|
// `WorkloadConfig.timeoutMs` / `BenchConfig.timeoutMs` override this.
|
|
49
57
|
const DEFAULT_CI_TIMEOUT_MS = 600_000;
|
|
@@ -136,6 +144,7 @@ async function measureSuiteWorkloads(
|
|
|
136
144
|
suites: string[],
|
|
137
145
|
noiseWarning: Warning | undefined,
|
|
138
146
|
signal: AbortSignal | undefined,
|
|
147
|
+
onProgress?: (progress: BenchProgress) => void,
|
|
139
148
|
): Promise<MeasuredWorkload[]> {
|
|
140
149
|
// Always executes: a suite file's task ids (so its cache keys) are unknown
|
|
141
150
|
// without importing it.
|
|
@@ -157,6 +166,7 @@ async function measureSuiteWorkloads(
|
|
|
157
166
|
outDir: benchOpts.outDir ?? config.outDir,
|
|
158
167
|
timeoutMs: wc.timeoutMs ?? benchOpts.timeoutMs ?? DEFAULT_CI_TIMEOUT_MS,
|
|
159
168
|
...(signal && { signal }),
|
|
169
|
+
...(onProgress && { onProgress }),
|
|
160
170
|
});
|
|
161
171
|
const results: MeasuredWorkload[] = [];
|
|
162
172
|
for (const workload of doc.workloads) {
|
|
@@ -256,14 +266,21 @@ export async function measureConfigWorkloads(
|
|
|
256
266
|
config: OstiaConfig,
|
|
257
267
|
full: boolean,
|
|
258
268
|
signal?: AbortSignal,
|
|
269
|
+
onProgress?: CiProgress,
|
|
259
270
|
): Promise<MeasureConfigWorkloadsResult> {
|
|
260
271
|
// Stamped on every measurement taken now, never on a cached one.
|
|
261
272
|
const { environment, noiseWarning } = captureRunEnvironment(
|
|
262
273
|
config.noiseCheck,
|
|
263
274
|
);
|
|
264
275
|
const results: MeasuredWorkload[] = [];
|
|
265
|
-
|
|
276
|
+
const count = config.workloads.length;
|
|
277
|
+
for (const [i, wc] of config.workloads.entries()) {
|
|
266
278
|
if (signal?.aborted) break;
|
|
279
|
+
const step = `ci ${i + 1} of ${count}`;
|
|
280
|
+
onProgress?.(
|
|
281
|
+
`${step} · ${wc.label ?? wc.command?.join(" ") ?? wc.suites?.join(", ") ?? ""}`,
|
|
282
|
+
i / count,
|
|
283
|
+
);
|
|
267
284
|
if (wc.suites) {
|
|
268
285
|
results.push(
|
|
269
286
|
...(await measureSuiteWorkloads(
|
|
@@ -272,6 +289,12 @@ export async function measureConfigWorkloads(
|
|
|
272
289
|
wc.suites,
|
|
273
290
|
noiseWarning,
|
|
274
291
|
signal,
|
|
292
|
+
onProgress &&
|
|
293
|
+
((p) =>
|
|
294
|
+
onProgress(
|
|
295
|
+
`${step} · ${p.label}`,
|
|
296
|
+
(i + (p.suite - 1 + (p.task - 1) / p.tasks) / p.suites) / count,
|
|
297
|
+
)),
|
|
275
298
|
)),
|
|
276
299
|
);
|
|
277
300
|
} else if (wc.command) {
|
|
@@ -321,7 +344,12 @@ export async function runCi(opts: CiOptions): Promise<{
|
|
|
321
344
|
results: measured,
|
|
322
345
|
environment,
|
|
323
346
|
aborted,
|
|
324
|
-
} = await measureConfigWorkloads(
|
|
347
|
+
} = await measureConfigWorkloads(
|
|
348
|
+
config,
|
|
349
|
+
opts.full,
|
|
350
|
+
opts.signal,
|
|
351
|
+
opts.onProgress,
|
|
352
|
+
);
|
|
325
353
|
const results: CiWorkloadResult[] = measured.map((m) => ({ ...m }));
|
|
326
354
|
const executed = results.filter((r) => r.status === "executed").length;
|
|
327
355
|
const candidateDoc = createDocument(
|
|
@@ -401,41 +429,3 @@ export async function runCi(opts: CiOptions): Promise<{
|
|
|
401
429
|
aborted: false,
|
|
402
430
|
};
|
|
403
431
|
}
|
|
404
|
-
|
|
405
|
-
export function renderCiReport(summary: CiSummary): string {
|
|
406
|
-
const lines = [
|
|
407
|
-
`${summary.total} workloads`,
|
|
408
|
-
`${summary.cached} cached`,
|
|
409
|
-
`${summary.executed} executed`,
|
|
410
|
-
];
|
|
411
|
-
if (summary.missingBaseline > 0) {
|
|
412
|
-
lines.push(
|
|
413
|
-
`${summary.missingBaseline} skipped (no matching baseline workload)`,
|
|
414
|
-
);
|
|
415
|
-
}
|
|
416
|
-
if (summary.failed > 0) {
|
|
417
|
-
const failedLabels = summary.results
|
|
418
|
-
.filter((r) => r.harnessFailed)
|
|
419
|
-
.map((r) => workloadLabel(r.workload));
|
|
420
|
-
lines.push(
|
|
421
|
-
`${summary.failed} failed (harness error, a command exited non-zero or produced no samples: ${failedLabels.join(", ")})`,
|
|
422
|
-
);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
const regressionDetails = summary.results
|
|
426
|
-
.filter((r) => r.comparison?.verdict === "fail")
|
|
427
|
-
.map((r) => {
|
|
428
|
-
const t = r.comparison?.timing;
|
|
429
|
-
const label = workloadLabel(r.workload);
|
|
430
|
-
return t
|
|
431
|
-
? `${formatSignedPct(t.medianDeltaPct)} median on ${label}`
|
|
432
|
-
: label;
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
lines.push(
|
|
436
|
-
`${summary.passed} passed ${summary.regressed} regressed${regressionDetails.length > 0 ? ` (${regressionDetails.join(", ")})` : ""}`,
|
|
437
|
-
"",
|
|
438
|
-
`Profile CI: ${summary.regressed > 0 || summary.failed > 0 ? "✗" : "✓"}`,
|
|
439
|
-
);
|
|
440
|
-
return `${lines.join("\n")}\n`;
|
|
441
|
-
}
|
package/src/cli/flags.ts
CHANGED
|
@@ -121,6 +121,8 @@ export interface OutputArgs {
|
|
|
121
121
|
format: FormatName;
|
|
122
122
|
quiet: boolean;
|
|
123
123
|
help: boolean;
|
|
124
|
+
/** `--color` or `--no-color`; absent, color follows the terminal. */
|
|
125
|
+
color?: boolean;
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
export interface RunArgs extends OutputArgs {
|
|
@@ -143,8 +145,14 @@ export const HELP_FLAGS: FlagTable = {
|
|
|
143
145
|
"-h": flag.on("help"),
|
|
144
146
|
};
|
|
145
147
|
|
|
148
|
+
export const COLOR_FLAGS: FlagTable = {
|
|
149
|
+
"--color": flag.on("color"),
|
|
150
|
+
"--no-color": flag.off("color"),
|
|
151
|
+
};
|
|
152
|
+
|
|
146
153
|
export const OUTPUT_FLAGS: FlagTable = {
|
|
147
154
|
...HELP_FLAGS,
|
|
155
|
+
...COLOR_FLAGS,
|
|
148
156
|
"--export-json": flag.str("exportJson"),
|
|
149
157
|
"--format": flag.oneOf("format", DOCUMENT_FORMATS, FORMAT_ALIASES),
|
|
150
158
|
"--json": flag.is("format", "json"),
|
|
@@ -226,7 +234,7 @@ export function parseFlags<T extends object>(
|
|
|
226
234
|
const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
|
|
227
235
|
const name = eq > 0 ? arg.slice(0, eq) : arg;
|
|
228
236
|
const flagDef = Object.hasOwn(flags, name) ? flags[name] : undefined;
|
|
229
|
-
if (!flagDef
|
|
237
|
+
if (!flagDef) {
|
|
230
238
|
if (arg.startsWith("-") || !positional) {
|
|
231
239
|
throw new CliUsageError(
|
|
232
240
|
`Unknown flag "${arg}" for "ostia ${command}".`,
|
|
@@ -261,9 +269,18 @@ export function parseFlags<T extends object>(
|
|
|
261
269
|
set(dest, n);
|
|
262
270
|
break;
|
|
263
271
|
}
|
|
264
|
-
case "bool":
|
|
265
|
-
|
|
272
|
+
case "bool": {
|
|
273
|
+
// --flag=true and --flag=false, as a script that passes a variable
|
|
274
|
+
// writes them; false inverts, so --no-color=false turns color on.
|
|
275
|
+
const raw = eq > 0 ? arg.slice(eq + 1) : "true";
|
|
276
|
+
if (raw !== "true" && raw !== "false") {
|
|
277
|
+
throw new CliUsageError(
|
|
278
|
+
`Invalid ${name} "${raw}": expected true or false`,
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
set(dest, raw === "true" ? spec.value : !spec.value);
|
|
266
282
|
break;
|
|
283
|
+
}
|
|
267
284
|
case "list":
|
|
268
285
|
listAt(args, dest).push(value());
|
|
269
286
|
break;
|