ostia 0.2.12 → 0.3.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/LICENSE +21 -0
- package/README.md +50 -358
- package/docs/agent-protocol.md +210 -0
- package/docs/cli.md +1196 -0
- package/docs/config.md +233 -0
- package/docs/document-schema.md +224 -0
- package/docs/library.md +421 -0
- package/docs/preload-recipes.md +169 -0
- package/docs/statistics.md +218 -0
- package/index.d.ts +894 -677
- package/package.json +16 -14
- package/src/ab/ab-runner.ts +474 -0
- package/src/ab/index.ts +1086 -0
- package/src/baseline/index.ts +75 -0
- package/src/bench/index.ts +462 -0
- package/src/bench/projects.ts +39 -0
- package/src/bench/range.ts +27 -0
- package/src/bench/registry.ts +424 -0
- package/src/bench/run-tasks.ts +176 -0
- package/src/bench/run.ts +51 -0
- package/src/bench/runner.ts +147 -0
- package/src/bench/support.ts +161 -0
- package/src/bench/sweep.ts +39 -0
- package/src/cache/fingerprint.ts +59 -0
- package/src/cache/store.ts +28 -0
- package/src/capture/bunflags.ts +91 -0
- package/src/capture/cpu-parse.ts +119 -0
- package/src/capture/cpu.ts +44 -0
- package/src/capture/frames.ts +54 -0
- package/src/capture/heap-parse.ts +86 -0
- package/src/capture/heap.ts +32 -0
- package/src/capture/inspector.ts +46 -0
- package/src/capture/jsc-parse.ts +167 -0
- package/src/capture/jsc.ts +35 -0
- package/src/capture/sampling.ts +5 -0
- package/src/ci/index.ts +416 -0
- package/src/cli/flags.ts +264 -0
- package/{chunk-9sx15b08.js → src/cli/help.ts} +23 -11
- package/src/cli/main.ts +18 -0
- package/src/cli/output.ts +185 -0
- package/src/cli/run.ts +1110 -0
- package/src/compare/index.ts +617 -0
- package/src/config/index.ts +275 -0
- package/src/config/validate.ts +267 -0
- package/src/errors.ts +8 -0
- package/src/format.ts +36 -0
- package/src/glob.ts +48 -0
- package/src/index.ts +62 -0
- package/src/ir/cpu.ts +10 -0
- package/src/ir/document.ts +471 -0
- package/src/ir/fp.ts +31 -0
- package/src/ir/git.ts +36 -0
- package/src/ir/types.ts +615 -0
- package/src/measure/alloc.ts +57 -0
- package/src/measure/cpu.ts +99 -0
- package/src/measure/environment.ts +41 -0
- package/src/measure/inprocess.ts +191 -0
- package/src/measure/instructions.ts +133 -0
- package/src/measure/loop.ts +57 -0
- package/src/measure/noise.ts +55 -0
- package/src/measure/paired.ts +312 -0
- package/src/measure/peak.ts +202 -0
- package/src/measure/timing.ts +263 -0
- package/src/profile.ts +109 -0
- package/src/renderers/collapsed.ts +35 -0
- package/src/renderers/cpu-tree.ts +183 -0
- package/src/renderers/cpuprofile.ts +43 -0
- package/src/renderers/format.ts +142 -0
- package/src/renderers/index.ts +27 -0
- package/src/renderers/json.ts +10 -0
- package/src/renderers/jsonl.ts +15 -0
- package/src/renderers/markdown.ts +525 -0
- package/src/renderers/mermaid.ts +78 -0
- package/src/renderers/minimal.ts +602 -0
- package/src/renderers/paired.ts +229 -0
- package/src/renderers/relative.ts +64 -0
- package/src/renderers/select.ts +286 -0
- package/src/renderers/speedscope.ts +69 -0
- package/src/renderers/terminal.ts +466 -0
- package/src/renderers/types.ts +27 -0
- package/src/spawn/index.ts +396 -0
- package/src/stats/bootstrap.ts +153 -0
- package/src/stats/index.ts +140 -0
- package/src/stats/mannwhitney.ts +81 -0
- package/src/time.ts +325 -0
- package/src/version.ts +3 -0
- package/ab-runner.ts +0 -8
- package/chunk-05jfst35.js +0 -28
- package/chunk-1g1x9zz2.js +0 -15
- package/chunk-23g2rwrn.js +0 -3
- package/chunk-468h5412.js +0 -25
- package/chunk-4esjfc2m.js +0 -2
- package/chunk-ct2xsezd.js +0 -14
- package/cli.js +0 -3
- package/index.js +0 -2
- package/runner.ts +0 -7
package/package.json
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ostia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Fast profiling and benchmarking for Bun.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Eric Liu (https://github.com/metonym)",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/metonym/ostia.git"
|
|
8
10
|
},
|
|
11
|
+
"homepage": "https://github.com/metonym/ostia",
|
|
12
|
+
"bugs": "https://github.com/metonym/ostia/issues",
|
|
13
|
+
"type": "module",
|
|
9
14
|
"exports": {
|
|
10
15
|
".": {
|
|
11
16
|
"types": "./index.d.ts",
|
|
12
|
-
"default": "./index.
|
|
13
|
-
}
|
|
17
|
+
"default": "./src/index.ts"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
14
20
|
},
|
|
15
21
|
"bin": {
|
|
16
|
-
"ostia": "cli.
|
|
22
|
+
"ostia": "src/cli/main.ts"
|
|
17
23
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
"main": "./index.js",
|
|
23
|
-
"module": "./index.js",
|
|
24
|
-
"types": "./index.d.ts"
|
|
24
|
+
"engines": {
|
|
25
|
+
"bun": ">=1.4.0"
|
|
26
|
+
}
|
|
25
27
|
}
|
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
filterTasks,
|
|
5
|
+
formerTaskIds,
|
|
6
|
+
getRegisteredTasks,
|
|
7
|
+
groupEdges,
|
|
8
|
+
NO_TASKS_HINT,
|
|
9
|
+
type RegisteredTask,
|
|
10
|
+
resetRegistry,
|
|
11
|
+
runGroupHooks,
|
|
12
|
+
selectTasks,
|
|
13
|
+
taskAlloc,
|
|
14
|
+
taskId,
|
|
15
|
+
taskPeakMem,
|
|
16
|
+
} from "../bench/registry.ts";
|
|
17
|
+
import { taskWorkload } from "../bench/run-tasks.ts";
|
|
18
|
+
import {
|
|
19
|
+
configFingerprint,
|
|
20
|
+
createDocument,
|
|
21
|
+
makePairedMeasurement,
|
|
22
|
+
saveDocument,
|
|
23
|
+
} from "../ir/document.ts";
|
|
24
|
+
import { canonicalJSON } from "../ir/fp.ts";
|
|
25
|
+
import type { AbSummary, Measurement, Workload } from "../ir/types.ts";
|
|
26
|
+
import { measureAllocPerOp } from "../measure/alloc.ts";
|
|
27
|
+
import { instructionCounter } from "../measure/instructions.ts";
|
|
28
|
+
import {
|
|
29
|
+
measurePaired,
|
|
30
|
+
pairedEvidence,
|
|
31
|
+
PairedSideError,
|
|
32
|
+
type Side,
|
|
33
|
+
sideLabel,
|
|
34
|
+
} from "../measure/paired.ts";
|
|
35
|
+
import {
|
|
36
|
+
measurePeakMem,
|
|
37
|
+
memorySnapshot,
|
|
38
|
+
type PeakMemResult,
|
|
39
|
+
startRssSampler,
|
|
40
|
+
} from "../measure/peak.ts";
|
|
41
|
+
import { computeTimingStats } from "../stats/index.ts";
|
|
42
|
+
|
|
43
|
+
export interface AbRunnerOpts {
|
|
44
|
+
/** Regex matched against "group/name" task ids. */
|
|
45
|
+
filter?: string;
|
|
46
|
+
/** Measure only these workloads (a fresh-process repeat of flagged ones). */
|
|
47
|
+
workloadIds?: string[];
|
|
48
|
+
rounds: number;
|
|
49
|
+
thresholdPct: number;
|
|
50
|
+
metric: AbSummary["metric"];
|
|
51
|
+
/** Scripts imported, in order, before either suite. */
|
|
52
|
+
preload?: string[];
|
|
53
|
+
/** Send an `AbRunnerProgress` message over IPC before each task. */
|
|
54
|
+
progress?: boolean;
|
|
55
|
+
/** Import, set up and time the candidate first; see `poolOrders`. */
|
|
56
|
+
candFirst?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Suite-wide defaults for the memory readings in `planPath` (task/group
|
|
59
|
+
* options win). */
|
|
60
|
+
alloc?: boolean;
|
|
61
|
+
peakMem?: boolean;
|
|
62
|
+
/** Write an `AbRunnerPlan` here. */
|
|
63
|
+
planPath?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Instead of timing: take this task's memory readings on one side and
|
|
66
|
+
* write an `AbMemoryResult` to the output path. */
|
|
67
|
+
memoryFor?: AbMemoryTask & { side: Side };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A paired task and the memory readings it wants. */
|
|
71
|
+
export interface AbMemoryTask {
|
|
72
|
+
workloadId: string;
|
|
73
|
+
alloc: boolean;
|
|
74
|
+
peakMem: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface AbRunnerPlan {
|
|
78
|
+
memory: AbMemoryTask[];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** One side's memory readings from one fresh process. */
|
|
82
|
+
export interface AbMemoryResult {
|
|
83
|
+
peak?: PeakMemResult;
|
|
84
|
+
alloc?: { bytesPerOp: number; calls: number };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Sent to the parent before each task is measured, when `progress` is
|
|
89
|
+
* set. `task` counts from 1. */
|
|
90
|
+
export interface AbRunnerProgress {
|
|
91
|
+
task: number;
|
|
92
|
+
tasks: number;
|
|
93
|
+
label: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Tasks pair across sides by "group/name" plus `params`, the workload id's
|
|
98
|
+
* identity.
|
|
99
|
+
*/
|
|
100
|
+
function pairKey(t: RegisteredTask, id: string = taskId(t)): string {
|
|
101
|
+
return `${id}\u0000${canonicalJSON(t.params ?? null)}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The task's own key, then one per alias: a base task under any of them
|
|
106
|
+
* pairs.
|
|
107
|
+
*/
|
|
108
|
+
function pairKeys(t: RegisteredTask): string[] {
|
|
109
|
+
return [taskId(t), ...formerTaskIds(t)].map((id) => pairKey(t, id));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function importTasks(suiteFile: string): Promise<RegisteredTask[]> {
|
|
113
|
+
resetRegistry();
|
|
114
|
+
await import(suiteFile);
|
|
115
|
+
return [...getRegisteredTasks()];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const ERROR_LINES = 5;
|
|
119
|
+
|
|
120
|
+
/** An error's message, cut to its first few lines. */
|
|
121
|
+
function errorText(err: unknown): string {
|
|
122
|
+
const text = err instanceof Error ? err.message : String(err);
|
|
123
|
+
return text.split("\n").slice(0, ERROR_LINES).join("\n");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Reports a failure that stops the whole suite: on stderr, and in
|
|
128
|
+
* `<outputPath>.error` (and `.side`, when it's one side's) for `ab()` to
|
|
129
|
+
* put in the error it throws. */
|
|
130
|
+
async function fail(
|
|
131
|
+
outputPath: string,
|
|
132
|
+
message: string,
|
|
133
|
+
side?: Side,
|
|
134
|
+
): Promise<number> {
|
|
135
|
+
process.stderr.write(`ab runner: ${message}\n`);
|
|
136
|
+
await Bun.write(`${outputPath}.error`, message);
|
|
137
|
+
if (side) await Bun.write(`${outputPath}.side`, side);
|
|
138
|
+
return 2;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
type MeasureOutcome =
|
|
142
|
+
| { result: Awaited<ReturnType<typeof measurePaired>> }
|
|
143
|
+
| { threw: NonNullable<Measurement["threw"]> };
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* One pair's `before` hooks, paired timing and `after` hooks. A throw from
|
|
147
|
+
* either side's task or hooks doesn't stop the suite; it's reported with
|
|
148
|
+
* its side instead. Each `before` runs once, in `order`, and a side whose
|
|
149
|
+
* `before` threw isn't timed or torn down. Every side that was set up is
|
|
150
|
+
* torn down once, in reverse order, even when a hook throws. When only one
|
|
151
|
+
* side has thrown, the other side's task is called once more, before
|
|
152
|
+
* teardown and only if that side is set up, to tell whether it throws too
|
|
153
|
+
* (`"both"`). */
|
|
154
|
+
async function measureTask(
|
|
155
|
+
base: RegisteredTask,
|
|
156
|
+
cand: RegisteredTask,
|
|
157
|
+
rounds: number,
|
|
158
|
+
order: Side[],
|
|
159
|
+
): Promise<MeasureOutcome> {
|
|
160
|
+
const tasks = { base, cand };
|
|
161
|
+
// The first error from each side.
|
|
162
|
+
const errors = new Map<Side, unknown>();
|
|
163
|
+
const record = (side: Side, err: unknown) => {
|
|
164
|
+
if (!errors.has(side)) errors.set(side, err);
|
|
165
|
+
};
|
|
166
|
+
const ready = new Set<Side>();
|
|
167
|
+
for (const side of order) {
|
|
168
|
+
try {
|
|
169
|
+
await tasks[side].opts?.before?.();
|
|
170
|
+
ready.add(side);
|
|
171
|
+
} catch (err) {
|
|
172
|
+
record(side, err);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let result: Awaited<ReturnType<typeof measurePaired>> | undefined;
|
|
177
|
+
let internal: { err: unknown } | undefined;
|
|
178
|
+
if (ready.size === 2) {
|
|
179
|
+
try {
|
|
180
|
+
result = await measurePaired(base.fn, cand.fn, {
|
|
181
|
+
rounds,
|
|
182
|
+
candFirst: order[0] === "cand",
|
|
183
|
+
});
|
|
184
|
+
} catch (err) {
|
|
185
|
+
if (err instanceof PairedSideError) record(err.side, err.cause);
|
|
186
|
+
else internal = { err };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (errors.size === 1) {
|
|
191
|
+
const other: Side = errors.has("base") ? "cand" : "base";
|
|
192
|
+
if (ready.has(other)) {
|
|
193
|
+
try {
|
|
194
|
+
await tasks[other].fn();
|
|
195
|
+
} catch (err) {
|
|
196
|
+
record(other, err);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
for (const side of order.toReversed()) {
|
|
202
|
+
if (!ready.has(side)) continue;
|
|
203
|
+
try {
|
|
204
|
+
await tasks[side].opts?.after?.();
|
|
205
|
+
} catch (err) {
|
|
206
|
+
record(side, err);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (internal) throw internal.err;
|
|
211
|
+
const baseErr = errors.get("base");
|
|
212
|
+
const candErr = errors.get("cand");
|
|
213
|
+
if (errors.size === 2) {
|
|
214
|
+
return {
|
|
215
|
+
threw: {
|
|
216
|
+
side: "both",
|
|
217
|
+
message: `base: ${errorText(baseErr)}\ncandidate: ${errorText(candErr)}`,
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
if (errors.has("base")) {
|
|
222
|
+
return { threw: { side: "base", message: errorText(baseErr) } };
|
|
223
|
+
}
|
|
224
|
+
if (errors.has("cand")) {
|
|
225
|
+
return { threw: { side: "cand", message: errorText(candErr) } };
|
|
226
|
+
}
|
|
227
|
+
return { result: result! };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* A `memoryFor` process. Only one side's suite loads, so the other side's
|
|
232
|
+
* setup and the packages both sides share can't move the readings. Peak is
|
|
233
|
+
* the first call; retained follows a warmup batch, as `bench --alloc`
|
|
234
|
+
* follows timing. */
|
|
235
|
+
async function measureMemory(
|
|
236
|
+
suite: string,
|
|
237
|
+
candSuite: string,
|
|
238
|
+
outputPath: string,
|
|
239
|
+
memoryFor: NonNullable<AbRunnerOpts["memoryFor"]>,
|
|
240
|
+
preload: string[],
|
|
241
|
+
): Promise<number> {
|
|
242
|
+
const { workloadId, side } = memoryFor;
|
|
243
|
+
// Baseline for `measurePeakMem`, taken once ostia (which the suite
|
|
244
|
+
// imports) is loaded.
|
|
245
|
+
const sampler = memoryFor.peakMem ? await startRssSampler() : undefined;
|
|
246
|
+
await import("../index.ts");
|
|
247
|
+
const launched = memorySnapshot();
|
|
248
|
+
let t: RegisteredTask | undefined;
|
|
249
|
+
try {
|
|
250
|
+
for (const preloadFile of preload) await import(preloadFile);
|
|
251
|
+
t = (await importTasks(suite)).find(
|
|
252
|
+
(t) => taskWorkload(candSuite, t).id === workloadId,
|
|
253
|
+
);
|
|
254
|
+
} catch (err) {
|
|
255
|
+
return fail(
|
|
256
|
+
outputPath,
|
|
257
|
+
`the ${sideLabel(side)} side failed to load ${suite}: ${errorText(err)}`,
|
|
258
|
+
side,
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
if (!t) {
|
|
262
|
+
return fail(
|
|
263
|
+
outputPath,
|
|
264
|
+
`no task with workload id ${workloadId} in ${suite}.`,
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
const result: AbMemoryResult = {};
|
|
269
|
+
await runGroupHooks(t, "before");
|
|
270
|
+
await t.opts?.before?.();
|
|
271
|
+
if (sampler) result.peak = await measurePeakMem(t.fn, launched, sampler);
|
|
272
|
+
if (memoryFor.alloc) {
|
|
273
|
+
await measureAllocPerOp(t.fn);
|
|
274
|
+
const { memory, calls } = await measureAllocPerOp(t.fn);
|
|
275
|
+
result.alloc = { bytesPerOp: memory.bytesPerOp!, calls };
|
|
276
|
+
}
|
|
277
|
+
await t.opts?.after?.();
|
|
278
|
+
await runGroupHooks(t, "after");
|
|
279
|
+
await Bun.write(outputPath, JSON.stringify(result));
|
|
280
|
+
return 0;
|
|
281
|
+
} catch (err) {
|
|
282
|
+
return fail(
|
|
283
|
+
outputPath,
|
|
284
|
+
`${taskId(t)} threw on the ${sideLabel(side)} side while measuring memory: ${errorText(err)}`,
|
|
285
|
+
side,
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Pairs one suite file's tasks against the same file at the base checkout,
|
|
292
|
+
* in this process. Each side is imported from its own path so its relative
|
|
293
|
+
* imports resolve within its own tree, while bare imports (including
|
|
294
|
+
* `ostia`, hence the shared registry) share `node_modules`. `baseSuite` is
|
|
295
|
+
* "" when the file doesn't exist at the base ref: every task is
|
|
296
|
+
* candidate-only. */
|
|
297
|
+
async function main(): Promise<number> {
|
|
298
|
+
const [candSuite, baseSuite, outputPath, optsJson] = process.argv.slice(2);
|
|
299
|
+
if (!candSuite || baseSuite === undefined || !outputPath || !optsJson) {
|
|
300
|
+
process.stderr.write(
|
|
301
|
+
"ab runner: usage: ab-runner.ts <candSuite> <baseSuite|''> <outputPath> <optsJson>\n",
|
|
302
|
+
);
|
|
303
|
+
return 2;
|
|
304
|
+
}
|
|
305
|
+
const opts: AbRunnerOpts = JSON.parse(optsJson);
|
|
306
|
+
|
|
307
|
+
if (opts.memoryFor) {
|
|
308
|
+
return measureMemory(
|
|
309
|
+
opts.memoryFor.side === "base" ? baseSuite : candSuite,
|
|
310
|
+
candSuite,
|
|
311
|
+
outputPath,
|
|
312
|
+
opts.memoryFor,
|
|
313
|
+
opts.preload ?? [],
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const uncounted =
|
|
318
|
+
opts.metric === "instructions" && instructionCounter().unavailable;
|
|
319
|
+
if (uncounted) {
|
|
320
|
+
return fail(outputPath, `can't count instructions: ${uncounted}`);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
for (const preloadFile of opts.preload ?? []) {
|
|
324
|
+
await import(preloadFile);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const order: Side[] = opts.candFirst ? ["cand", "base"] : ["base", "cand"];
|
|
328
|
+
let baseTasks: RegisteredTask[] = [];
|
|
329
|
+
let candRegistered: RegisteredTask[] = [];
|
|
330
|
+
for (const side of order) {
|
|
331
|
+
const suite = side === "base" ? baseSuite : candSuite;
|
|
332
|
+
if (!suite) continue;
|
|
333
|
+
try {
|
|
334
|
+
const tasks = await importTasks(suite);
|
|
335
|
+
if (side === "base") baseTasks = tasks;
|
|
336
|
+
else candRegistered = tasks;
|
|
337
|
+
} catch (err) {
|
|
338
|
+
return fail(
|
|
339
|
+
outputPath,
|
|
340
|
+
`the ${sideLabel(side)} side failed to load ${suite}: ${errorText(err)}`,
|
|
341
|
+
side,
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (candRegistered.length === 0) {
|
|
346
|
+
return fail(
|
|
347
|
+
outputPath,
|
|
348
|
+
`${candSuite} registered no tasks (no task() calls found).${NO_TASKS_HINT}`,
|
|
349
|
+
"cand",
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
let candTasks: RegisteredTask[];
|
|
354
|
+
try {
|
|
355
|
+
candTasks = selectTasks(
|
|
356
|
+
candRegistered,
|
|
357
|
+
opts.filter,
|
|
358
|
+
candSuite,
|
|
359
|
+
!opts.workloadIds,
|
|
360
|
+
);
|
|
361
|
+
} catch (err) {
|
|
362
|
+
return fail(outputPath, (err as Error).message);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const wanted = opts.workloadIds && new Set(opts.workloadIds);
|
|
366
|
+
const baseByKey = new Map(baseTasks.map((t) => [pairKey(t), t]));
|
|
367
|
+
const candKeys = new Set(candRegistered.flatMap(pairKeys));
|
|
368
|
+
|
|
369
|
+
const workloads: Workload[] = [];
|
|
370
|
+
const pairs: {
|
|
371
|
+
workload: Workload;
|
|
372
|
+
base: RegisteredTask;
|
|
373
|
+
cand: RegisteredTask;
|
|
374
|
+
}[] = [];
|
|
375
|
+
const candOnly: string[] = [];
|
|
376
|
+
for (const cand of candTasks) {
|
|
377
|
+
const workload = taskWorkload(candSuite, cand);
|
|
378
|
+
if (wanted && !wanted.has(workload.id)) continue;
|
|
379
|
+
workloads.push(workload);
|
|
380
|
+
if (cand.skipped) continue;
|
|
381
|
+
const base = pairKeys(cand)
|
|
382
|
+
.map((key) => baseByKey.get(key))
|
|
383
|
+
.find((t) => t !== undefined);
|
|
384
|
+
if (base && !base.skipped) pairs.push({ workload, base, cand });
|
|
385
|
+
else candOnly.push(workload.id);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Keyed by the candidate suite's path so the id is the one it had before
|
|
389
|
+
// removal. A `.only` in the candidate narrows the run, as `--filter` does:
|
|
390
|
+
// tasks removed from the suite aren't part of it.
|
|
391
|
+
const baseOnly: string[] = [];
|
|
392
|
+
if (!wanted && !candRegistered.some((t) => t.only)) {
|
|
393
|
+
for (const base of filterTasks(baseTasks, opts.filter)) {
|
|
394
|
+
if (base.skipped || candKeys.has(pairKey(base))) continue;
|
|
395
|
+
const workload = taskWorkload(candSuite, base);
|
|
396
|
+
workloads.push(workload);
|
|
397
|
+
baseOnly.push(workload.id);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const edges = groupEdges(pairs.map((p) => p.cand));
|
|
402
|
+
|
|
403
|
+
if (opts.planPath) {
|
|
404
|
+
const plan: AbRunnerPlan = {
|
|
405
|
+
memory: pairs
|
|
406
|
+
.map((p) => ({
|
|
407
|
+
workloadId: p.workload.id,
|
|
408
|
+
alloc: taskAlloc(p.cand, opts.alloc ?? false),
|
|
409
|
+
peakMem: taskPeakMem(p.cand, opts.peakMem ?? false),
|
|
410
|
+
}))
|
|
411
|
+
.filter((m) => m.alloc || m.peakMem),
|
|
412
|
+
};
|
|
413
|
+
await Bun.write(opts.planPath, JSON.stringify(plan));
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const cfgFp = configFingerprint({
|
|
417
|
+
rounds: opts.rounds,
|
|
418
|
+
thresholdPct: opts.thresholdPct,
|
|
419
|
+
metric: opts.metric,
|
|
420
|
+
});
|
|
421
|
+
const measurements: Measurement[] = [];
|
|
422
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
423
|
+
const { workload, base, cand } = pairs[i]!;
|
|
424
|
+
const { enter, leave } = edges(i);
|
|
425
|
+
if (opts.progress) {
|
|
426
|
+
process.send?.({
|
|
427
|
+
task: i + 1,
|
|
428
|
+
tasks: pairs.length,
|
|
429
|
+
label: taskId(cand),
|
|
430
|
+
} satisfies AbRunnerProgress);
|
|
431
|
+
}
|
|
432
|
+
const sides = { base, cand };
|
|
433
|
+
for (const side of order) {
|
|
434
|
+
await runGroupHooks(sides[side], "before", enter);
|
|
435
|
+
}
|
|
436
|
+
const measured = await measureTask(base, cand, opts.rounds, order);
|
|
437
|
+
if ("threw" in measured) {
|
|
438
|
+
measurements.push(
|
|
439
|
+
makePairedMeasurement({
|
|
440
|
+
workload,
|
|
441
|
+
configFingerprint: cfgFp,
|
|
442
|
+
threw: measured.threw,
|
|
443
|
+
diagnosticWallNs: 0,
|
|
444
|
+
warnings: [],
|
|
445
|
+
}),
|
|
446
|
+
);
|
|
447
|
+
} else {
|
|
448
|
+
const { result } = measured;
|
|
449
|
+
const timing = computeTimingStats(result.candSamples);
|
|
450
|
+
if (result.batch > 1) timing.batch = result.batch;
|
|
451
|
+
measurements.push(
|
|
452
|
+
makePairedMeasurement({
|
|
453
|
+
workload,
|
|
454
|
+
configFingerprint: cfgFp,
|
|
455
|
+
timing,
|
|
456
|
+
diagnosticWallNs: result.diagnosticWallNs,
|
|
457
|
+
warnings: [],
|
|
458
|
+
paired: pairedEvidence(result, opts.thresholdPct, opts.metric),
|
|
459
|
+
}),
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
for (const side of order.toReversed()) {
|
|
464
|
+
await runGroupHooks(sides[side], "after", leave);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const doc = createDocument(workloads, measurements);
|
|
469
|
+
doc.unmatched = { baseOnly, candOnly };
|
|
470
|
+
await saveDocument(doc, outputPath);
|
|
471
|
+
return 0;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
main().then((code) => process.exit(code));
|