ostia 0.3.0 → 0.3.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/index.d.ts +62 -35
- package/package.json +1 -1
- package/src/ab/ab-runner.ts +57 -44
- package/src/ab/index.ts +186 -112
- package/src/baseline/index.ts +3 -9
- package/src/bench/index.ts +177 -123
- package/src/bench/projects.ts +14 -10
- package/src/bench/registry.ts +68 -66
- package/src/bench/run-tasks.ts +26 -23
- package/src/bench/run.ts +2 -1
- package/src/bench/runner.ts +20 -5
- package/src/bench/support.ts +26 -26
- package/src/bench/sweep.ts +6 -4
- package/src/cache/fingerprint.ts +9 -6
- package/src/cache/store.ts +17 -5
- package/src/capture/bunflags.ts +12 -11
- package/src/capture/cpu-parse.ts +36 -24
- package/src/capture/cpu.ts +7 -4
- package/src/capture/frames.ts +7 -1
- package/src/capture/heap-parse.ts +30 -5
- package/src/capture/heap.ts +9 -5
- package/src/capture/inspector.ts +8 -7
- package/src/capture/jsc-parse.ts +8 -8
- package/src/capture/jsc.ts +4 -4
- package/src/ci/index.ts +64 -40
- package/src/cli/flags.ts +42 -43
- package/src/cli/output.ts +29 -35
- package/src/cli/run.ts +95 -95
- package/src/compare/index.ts +39 -32
- package/src/config/env.ts +13 -0
- package/src/config/index.ts +31 -23
- package/src/config/validate.ts +33 -27
- package/src/format.ts +5 -6
- package/src/glob.ts +9 -12
- package/src/index.ts +1 -3
- package/src/ir/cpu.ts +2 -2
- package/src/ir/defined.ts +12 -0
- package/src/ir/document.ts +93 -73
- package/src/ir/fp.ts +7 -10
- package/src/ir/git.ts +4 -3
- package/src/measure/alloc.ts +7 -8
- package/src/measure/cpu.ts +12 -20
- package/src/measure/environment.ts +5 -8
- package/src/measure/inprocess.ts +15 -15
- package/src/measure/instructions.ts +22 -16
- package/src/measure/loop.ts +24 -17
- package/src/measure/noise.ts +8 -8
- package/src/measure/paired.ts +39 -47
- package/src/measure/peak.ts +20 -21
- package/src/measure/timing.ts +23 -23
- package/src/profile.ts +2 -1
- package/src/renderers/collapsed.ts +28 -21
- package/src/renderers/cpu-tree.ts +43 -35
- package/src/renderers/format.ts +16 -26
- package/src/renderers/index.ts +14 -4
- package/src/renderers/json.ts +2 -2
- package/src/renderers/jsonl.ts +11 -7
- package/src/renderers/markdown.ts +54 -36
- package/src/renderers/mermaid.ts +43 -31
- package/src/renderers/minimal.ts +12 -12
- package/src/renderers/paired.ts +31 -37
- package/src/renderers/relative.ts +10 -14
- package/src/renderers/select.ts +17 -39
- package/src/renderers/speedscope.ts +52 -48
- package/src/renderers/terminal.ts +37 -33
- package/src/spawn/index.ts +38 -47
- package/src/stats/bootstrap.ts +56 -58
- package/src/stats/index.ts +16 -12
- package/src/stats/mannwhitney.ts +11 -10
- package/src/time.ts +51 -39
package/src/bench/index.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type { Measurement, ProfileDocument, Workload } from "../ir/types.ts";
|
|
|
14
14
|
import { stampDrift } from "../measure/environment.ts";
|
|
15
15
|
import type { PeakMemResult } from "../measure/peak.ts";
|
|
16
16
|
import { assertSamplingOptions } from "../measure/timing.ts";
|
|
17
|
-
import {
|
|
17
|
+
import { type SuiteLaunch, suiteLauncher } from "./projects.ts";
|
|
18
18
|
import type { RunnerOpts } from "./runner.ts";
|
|
19
19
|
import {
|
|
20
20
|
absolutePath,
|
|
@@ -108,7 +108,6 @@ export interface BenchOptions {
|
|
|
108
108
|
|
|
109
109
|
const RUNNER_PATH = new URL("./runner.ts", import.meta.url).pathname;
|
|
110
110
|
|
|
111
|
-
/** Logical CPUs available to this process, for `--jobs auto`. */
|
|
112
111
|
export function availableJobs(): number {
|
|
113
112
|
return Math.max(1, navigator.hardwareConcurrency || 1);
|
|
114
113
|
}
|
|
@@ -136,13 +135,11 @@ export interface BenchCliOverrides {
|
|
|
136
135
|
timeoutMs?: number;
|
|
137
136
|
}
|
|
138
137
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
* `suites` plus whatever its `projects` match. A CLI `preload` /
|
|
145
|
-
* `bunFlags` also replaces that field in every project. */
|
|
138
|
+
// A CLI value wins per field, then the config's, then `bench()`'s own
|
|
139
|
+
// defaults (left undefined). `suites`, `preload` and `bunFlags` are
|
|
140
|
+
// replaced wholesale, never merged. With no CLI suites, the files to run
|
|
141
|
+
// are the config's `suites` plus whatever its `projects` match. A CLI
|
|
142
|
+
// `preload` / `bunFlags` also replaces that field in every project.
|
|
146
143
|
export async function resolveBenchOptions(
|
|
147
144
|
cli: BenchCliOverrides,
|
|
148
145
|
config: BenchConfig | undefined,
|
|
@@ -159,30 +156,41 @@ export async function resolveBenchOptions(
|
|
|
159
156
|
? await scanGlobs(globs, cwd)
|
|
160
157
|
: [];
|
|
161
158
|
|
|
159
|
+
const budgetMs = cli.budgetMs ?? config?.budgetMs;
|
|
160
|
+
const samples = cli.samples ?? config?.samples;
|
|
161
|
+
const minSamples = cli.minSamples ?? config?.minSamples;
|
|
162
|
+
const jobs =
|
|
163
|
+
cli.jobs ?? (config?.jobs === "auto" ? availableJobs() : config?.jobs);
|
|
164
|
+
const cpuIntervalUs = cli.cpuIntervalUs ?? config?.cpuIntervalUs;
|
|
165
|
+
const filter = cli.filter ?? config?.filter;
|
|
166
|
+
const projects = config?.projects?.map(
|
|
167
|
+
({ preload, bunFlags, ...project }) => ({
|
|
168
|
+
...project,
|
|
169
|
+
...(cli.preload.length === 0 && preload !== undefined && { preload }),
|
|
170
|
+
...(cli.bunFlags.length === 0 && bunFlags !== undefined && { bunFlags }),
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
const outDir = cli.outDir ?? config?.outDir;
|
|
174
|
+
const timeoutMs = cli.timeoutMs ?? config?.timeoutMs;
|
|
162
175
|
return {
|
|
163
176
|
suites,
|
|
164
|
-
budgetMs
|
|
165
|
-
samples
|
|
166
|
-
minSamples
|
|
167
|
-
jobs
|
|
168
|
-
cli.jobs ?? (config?.jobs === "auto" ? availableJobs() : config?.jobs),
|
|
177
|
+
...(budgetMs !== undefined && { budgetMs }),
|
|
178
|
+
...(samples !== undefined && { samples }),
|
|
179
|
+
...(minSamples !== undefined && { minSamples }),
|
|
180
|
+
...(jobs !== undefined && { jobs }),
|
|
169
181
|
gc: cli.gc ?? config?.gc ?? false,
|
|
170
182
|
cpu: cli.cpu ?? config?.cpu ?? false,
|
|
171
|
-
cpuIntervalUs
|
|
183
|
+
...(cpuIntervalUs !== undefined && { cpuIntervalUs }),
|
|
172
184
|
alloc: cli.alloc ?? config?.alloc ?? false,
|
|
173
185
|
peakMem: cli.peakMem ?? config?.peakMem ?? false,
|
|
174
|
-
filter
|
|
186
|
+
...(filter !== undefined && { filter }),
|
|
175
187
|
isolate: cli.isolate ?? config?.isolate ?? false,
|
|
176
188
|
preload: cli.preload.length > 0 ? cli.preload : (config?.preload ?? []),
|
|
177
189
|
bunFlags: cli.bunFlags.length > 0 ? cli.bunFlags : (config?.bunFlags ?? []),
|
|
178
|
-
projects
|
|
179
|
-
|
|
180
|
-
...(cli.preload.length > 0 && { preload: undefined }),
|
|
181
|
-
...(cli.bunFlags.length > 0 && { bunFlags: undefined }),
|
|
182
|
-
})),
|
|
183
|
-
outDir: cli.outDir ?? config?.outDir,
|
|
190
|
+
...(projects !== undefined && { projects }),
|
|
191
|
+
...(outDir !== undefined && { outDir }),
|
|
184
192
|
noiseCheck: cli.noiseCheck,
|
|
185
|
-
timeoutMs
|
|
193
|
+
...(timeoutMs !== undefined && { timeoutMs }),
|
|
186
194
|
cwd,
|
|
187
195
|
};
|
|
188
196
|
}
|
|
@@ -213,12 +221,37 @@ function peakMeasurement(
|
|
|
213
221
|
];
|
|
214
222
|
}
|
|
215
223
|
|
|
224
|
+
interface Suite extends SuiteLaunch {
|
|
225
|
+
// As the caller wrote it, for messages.
|
|
226
|
+
given: string;
|
|
227
|
+
path: string;
|
|
228
|
+
}
|
|
229
|
+
|
|
216
230
|
interface RunnerJob {
|
|
217
|
-
|
|
231
|
+
suite: Suite;
|
|
218
232
|
outPath: string;
|
|
219
233
|
runnerOpts: RunnerOpts;
|
|
220
234
|
}
|
|
221
235
|
|
|
236
|
+
function isPlan(value: unknown): value is { tasks: PlannedTask[] } {
|
|
237
|
+
return (
|
|
238
|
+
typeof value === "object" &&
|
|
239
|
+
value !== null &&
|
|
240
|
+
"tasks" in value &&
|
|
241
|
+
Array.isArray(value.tasks)
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function isPeakMemResult(value: unknown): value is PeakMemResult {
|
|
246
|
+
return (
|
|
247
|
+
typeof value === "object" &&
|
|
248
|
+
value !== null &&
|
|
249
|
+
"peakBytes" in value &&
|
|
250
|
+
typeof value.peakBytes === "number"
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Measures the tasks each of `suites` registers, one subprocess per file. */
|
|
222
255
|
export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
|
|
223
256
|
assertSamplingOptions("bench", opts);
|
|
224
257
|
const jobs = opts.jobs ?? 1;
|
|
@@ -227,35 +260,41 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
|
|
|
227
260
|
}
|
|
228
261
|
|
|
229
262
|
const cwd = opts.cwd ?? process.cwd();
|
|
230
|
-
//
|
|
231
|
-
//
|
|
263
|
+
// Resolved against `cwd` because the runner subprocesses write there;
|
|
264
|
+
// this process's own cwd may differ.
|
|
232
265
|
const tmpDir = uniqueTmpDir(
|
|
233
266
|
absolutePath(cwd, opts.outDir ?? DEFAULT_OUT_DIR),
|
|
234
267
|
"bench",
|
|
235
268
|
);
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
assertSuiteExists(opts.suites[i]!, suite);
|
|
269
|
+
for (const given of opts.suites) {
|
|
270
|
+
assertSuiteExists(given, absolutePath(cwd, given));
|
|
239
271
|
}
|
|
240
|
-
const
|
|
272
|
+
const launch = suiteLauncher(cwd, opts, opts.projects);
|
|
273
|
+
const suites = opts.suites.map((given): Suite => {
|
|
274
|
+
const path = absolutePath(cwd, given);
|
|
275
|
+
return { given, path, ...launch(path) };
|
|
276
|
+
});
|
|
241
277
|
const { environment, noiseWarning } = captureRunEnvironment(opts.noiseCheck);
|
|
242
278
|
|
|
243
|
-
const measureOpts = {
|
|
244
|
-
budgetMs: opts.budgetMs,
|
|
245
|
-
samples: opts.samples,
|
|
246
|
-
minSamples: opts.minSamples,
|
|
247
|
-
gc: opts.gc,
|
|
248
|
-
cpu: opts.cpu,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
279
|
+
const measureOpts: RunnerOpts = {
|
|
280
|
+
...(opts.budgetMs !== undefined && { budgetMs: opts.budgetMs }),
|
|
281
|
+
...(opts.samples !== undefined && { samples: opts.samples }),
|
|
282
|
+
...(opts.minSamples !== undefined && { minSamples: opts.minSamples }),
|
|
283
|
+
...(opts.gc !== undefined && { gc: opts.gc }),
|
|
284
|
+
...(opts.cpu !== undefined && { cpu: opts.cpu }),
|
|
285
|
+
...(opts.cpuIntervalUs !== undefined && {
|
|
286
|
+
cpuIntervalUs: opts.cpuIntervalUs,
|
|
287
|
+
}),
|
|
288
|
+
...(opts.alloc !== undefined && { alloc: opts.alloc }),
|
|
289
|
+
...(opts.peakMem !== undefined && { peakMem: opts.peakMem }),
|
|
252
290
|
// Measured once here: every runner repeating the ~200ms reference
|
|
253
291
|
// measurement only to have all but the first discarded cost seconds.
|
|
254
292
|
noiseCheck: false,
|
|
255
293
|
};
|
|
294
|
+
const filter = opts.filter !== undefined && { filter: opts.filter };
|
|
256
295
|
|
|
257
|
-
const outPath = (tag: string,
|
|
258
|
-
`${tmpDir}/${fp(tag,
|
|
296
|
+
const outPath = (tag: string, suite: Suite, ...rest: unknown[]) =>
|
|
297
|
+
`${tmpDir}/${fp(tag, suite.path, ...rest)}.json`;
|
|
259
298
|
|
|
260
299
|
// `jobs` workers pull from a shared cursor. The first failure stops the
|
|
261
300
|
// pool: queued jobs are skipped and in-flight children killed, so a broken
|
|
@@ -269,25 +308,22 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
|
|
|
269
308
|
let failure: Error | undefined;
|
|
270
309
|
|
|
271
310
|
const worker = async (): Promise<void> => {
|
|
272
|
-
while (
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
next < list.length
|
|
276
|
-
) {
|
|
277
|
-
const job = list[next++]!;
|
|
311
|
+
while (failure === undefined && !opts.signal?.aborted) {
|
|
312
|
+
const job = list[next++];
|
|
313
|
+
if (job === undefined) return;
|
|
278
314
|
try {
|
|
279
315
|
const ran = await runRunnerProcess(
|
|
280
316
|
[
|
|
281
317
|
"bun",
|
|
282
|
-
...
|
|
318
|
+
...job.suite.bunFlags,
|
|
283
319
|
RUNNER_PATH,
|
|
284
|
-
|
|
320
|
+
job.suite.path,
|
|
285
321
|
job.outPath,
|
|
286
322
|
JSON.stringify(job.runnerOpts),
|
|
287
323
|
],
|
|
288
324
|
{
|
|
289
325
|
label: "Bench suite",
|
|
290
|
-
name:
|
|
326
|
+
name: job.suite.given,
|
|
291
327
|
cwd,
|
|
292
328
|
env,
|
|
293
329
|
timeoutMs: opts.timeoutMs,
|
|
@@ -313,88 +349,99 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
|
|
|
313
349
|
// Phase 1: import each suite once. The same process records the plan
|
|
314
350
|
// (each task's effective isolate/peakMem) and runs the non-isolated
|
|
315
351
|
// tasks, so module-scope setup never runs twice just to learn the plan.
|
|
316
|
-
const primaries = suites.map((
|
|
317
|
-
|
|
318
|
-
|
|
352
|
+
const primaries = suites.map((suite) => ({
|
|
353
|
+
suite,
|
|
354
|
+
planPath: outPath("bench-plan", suite),
|
|
355
|
+
outPath: outPath("bench-primary", suite),
|
|
319
356
|
}));
|
|
320
357
|
await runPool(
|
|
321
|
-
primaries.map((p
|
|
322
|
-
|
|
358
|
+
primaries.map((p) => ({
|
|
359
|
+
suite: p.suite,
|
|
323
360
|
outPath: p.outPath,
|
|
324
361
|
runnerOpts: {
|
|
325
362
|
...measureOpts,
|
|
326
|
-
filter
|
|
327
|
-
isolate: opts.isolate,
|
|
328
|
-
preload:
|
|
363
|
+
...filter,
|
|
364
|
+
...(opts.isolate !== undefined && { isolate: opts.isolate }),
|
|
365
|
+
preload: p.suite.preload,
|
|
329
366
|
planPath: p.planPath,
|
|
330
367
|
},
|
|
331
368
|
})),
|
|
332
369
|
);
|
|
333
370
|
|
|
334
|
-
// A suite killed mid-run wrote neither file
|
|
335
|
-
const
|
|
336
|
-
primaries.map(async (p) =>
|
|
337
|
-
(await Bun.file(p.planPath).exists())
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
:
|
|
341
|
-
|
|
371
|
+
// A suite killed mid-run wrote neither file, so it contributes no tasks.
|
|
372
|
+
const planTasks = await Promise.all(
|
|
373
|
+
primaries.map(async (p): Promise<PlannedTask[]> => {
|
|
374
|
+
if (!(await Bun.file(p.planPath).exists())) return [];
|
|
375
|
+
const plan: unknown = await Bun.file(p.planPath).json();
|
|
376
|
+
if (!isPlan(plan)) {
|
|
377
|
+
throw new Error(`bench: unreadable plan for ${p.suite.given}`);
|
|
378
|
+
}
|
|
379
|
+
return plan.tasks;
|
|
380
|
+
}),
|
|
342
381
|
);
|
|
343
382
|
const primaryDocs = await Promise.all(
|
|
344
383
|
primaries.map((p) => loadIfExists(p.outPath)),
|
|
345
384
|
);
|
|
385
|
+
const plans = primaries.map((p, i) => ({
|
|
386
|
+
suite: p.suite,
|
|
387
|
+
tasks: planTasks[i] ?? [],
|
|
388
|
+
doc: primaryDocs[i],
|
|
389
|
+
}));
|
|
346
390
|
|
|
347
|
-
// Phase 2: each isolated task in its own subprocess
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
.map((task) => ({ task,
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
391
|
+
// Phase 2: each isolated task in its own subprocess, so its JIT state
|
|
392
|
+
// and heap are its own.
|
|
393
|
+
const isolated = plans
|
|
394
|
+
.flatMap(({ suite, tasks }) =>
|
|
395
|
+
tasks.filter((task) => task.isolate).map((task) => ({ task, suite })),
|
|
396
|
+
)
|
|
397
|
+
.map((item, i) => ({
|
|
398
|
+
...item,
|
|
399
|
+
outPath: outPath("bench-item", item.suite, i),
|
|
400
|
+
}));
|
|
356
401
|
await runPool(
|
|
357
|
-
isolated.map((item
|
|
358
|
-
|
|
359
|
-
outPath:
|
|
402
|
+
isolated.map((item) => ({
|
|
403
|
+
suite: item.suite,
|
|
404
|
+
outPath: item.outPath,
|
|
360
405
|
runnerOpts: {
|
|
361
406
|
...measureOpts,
|
|
362
407
|
workloadIds: [item.task.workloadId],
|
|
363
|
-
preload:
|
|
408
|
+
preload: item.suite.preload,
|
|
364
409
|
markIsolated: true,
|
|
365
410
|
},
|
|
366
411
|
})),
|
|
367
412
|
);
|
|
368
413
|
const isolatedDocs = new Map<PlannedTask, ProfileDocument>();
|
|
369
414
|
await Promise.all(
|
|
370
|
-
isolated.map(async (item
|
|
371
|
-
const doc = await loadIfExists(
|
|
415
|
+
isolated.map(async (item) => {
|
|
416
|
+
const doc = await loadIfExists(item.outPath);
|
|
372
417
|
if (doc) isolatedDocs.set(item.task, doc);
|
|
373
418
|
}),
|
|
374
419
|
);
|
|
375
420
|
|
|
376
421
|
// Phase 3: each `peakMem` task's first call, alone in a fresh process,
|
|
377
|
-
//
|
|
378
|
-
const peakRuns = plans
|
|
379
|
-
tasks
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
422
|
+
// since memory an earlier call freed would hide part of its peak.
|
|
423
|
+
const peakRuns = plans
|
|
424
|
+
.flatMap(({ suite, tasks }) =>
|
|
425
|
+
tasks
|
|
426
|
+
.filter((task) => task.peakMem)
|
|
427
|
+
.flatMap((task) =>
|
|
428
|
+
Array.from({ length: PEAK_MEM_PROCESSES }, () => ({
|
|
429
|
+
workloadId: task.workloadId,
|
|
430
|
+
suite,
|
|
431
|
+
})),
|
|
432
|
+
),
|
|
433
|
+
)
|
|
434
|
+
.map((run, i) => ({
|
|
435
|
+
...run,
|
|
436
|
+
outPath: outPath("bench-peak", run.suite, i),
|
|
437
|
+
}));
|
|
391
438
|
await runPool(
|
|
392
|
-
peakRuns.map((run
|
|
393
|
-
|
|
394
|
-
outPath:
|
|
439
|
+
peakRuns.map((run) => ({
|
|
440
|
+
suite: run.suite,
|
|
441
|
+
outPath: run.outPath,
|
|
395
442
|
runnerOpts: {
|
|
396
|
-
filter
|
|
397
|
-
preload:
|
|
443
|
+
...filter,
|
|
444
|
+
preload: run.suite.preload,
|
|
398
445
|
peakMemFor: run.workloadId,
|
|
399
446
|
},
|
|
400
447
|
})),
|
|
@@ -403,49 +450,56 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
|
|
|
403
450
|
{ OSTIA_PEAK_MEM: "1" },
|
|
404
451
|
);
|
|
405
452
|
const peakReadings = new Map<string, PeakMemResult[]>();
|
|
406
|
-
for (
|
|
407
|
-
const file = Bun.file(
|
|
453
|
+
for (const run of peakRuns) {
|
|
454
|
+
const file = Bun.file(run.outPath);
|
|
408
455
|
if (!(await file.exists())) continue;
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
456
|
+
const reading: unknown = await file.json();
|
|
457
|
+
if (!isPeakMemResult(reading)) {
|
|
458
|
+
throw new Error(
|
|
459
|
+
`bench: unreadable peak-memory reading: ${run.outPath}`,
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
const readings = peakReadings.get(run.workloadId) ?? [];
|
|
463
|
+
readings.push(reading);
|
|
464
|
+
peakReadings.set(run.workloadId, readings);
|
|
413
465
|
}
|
|
414
466
|
|
|
415
467
|
// Plan order (registration order, filtered) within a suite, suites in
|
|
416
468
|
// command-line order. Measurements are matched by workload id, not
|
|
417
|
-
// position
|
|
469
|
+
// position, because a task.skip()'d task has a workload but no
|
|
470
|
+
// measurement.
|
|
418
471
|
const workloads: Workload[] = [];
|
|
419
472
|
const measurements: Measurement[] = [];
|
|
420
|
-
|
|
473
|
+
for (const { suite, tasks, doc: sharedDoc } of plans) {
|
|
421
474
|
// A cancelled suite wrote nothing and is absent, not empty.
|
|
422
|
-
|
|
423
|
-
if (!sharedDoc) return;
|
|
475
|
+
if (!sharedDoc) continue;
|
|
424
476
|
const sharedByWorkload = Map.groupBy(
|
|
425
477
|
sharedDoc.measurements,
|
|
426
478
|
(m) => m.workloadId,
|
|
427
479
|
);
|
|
428
|
-
|
|
480
|
+
const sharedWorkloads = sharedDoc.workloads.values();
|
|
429
481
|
for (const task of tasks) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
if (
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
own = sharedByWorkload.get(workload.id) ?? [];
|
|
482
|
+
const doc = task.isolate ? isolatedDocs.get(task) : sharedDoc;
|
|
483
|
+
// Cancelled before its subprocess finished: drop just this task.
|
|
484
|
+
if (!doc) continue;
|
|
485
|
+
const workload = task.isolate
|
|
486
|
+
? doc.workloads[0]
|
|
487
|
+
: sharedWorkloads.next().value;
|
|
488
|
+
if (workload === undefined) {
|
|
489
|
+
throw new Error(
|
|
490
|
+
`bench: ${suite.given} wrote fewer workloads than its plan`,
|
|
491
|
+
);
|
|
441
492
|
}
|
|
493
|
+
const own = task.isolate
|
|
494
|
+
? doc.measurements.filter((m) => m.workloadId === workload.id)
|
|
495
|
+
: (sharedByWorkload.get(workload.id) ?? []);
|
|
442
496
|
workloads.push(workload);
|
|
443
497
|
measurements.push(
|
|
444
498
|
...own,
|
|
445
499
|
...peakMeasurement(workload, peakReadings.get(workload.id)),
|
|
446
500
|
);
|
|
447
501
|
}
|
|
448
|
-
}
|
|
502
|
+
}
|
|
449
503
|
|
|
450
504
|
stampRunWarnings(
|
|
451
505
|
measurements,
|
package/src/bench/projects.ts
CHANGED
|
@@ -9,21 +9,15 @@ export interface SuiteLaunch {
|
|
|
9
9
|
bunFlags: string[];
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
* globs match the file (against its path relative to `cwd`) overrides the
|
|
14
|
-
* top-level `preload` / `bunFlags` field by field; a field the project
|
|
15
|
-
* leaves unset, or a file no project matches, keeps the top-level value.
|
|
16
|
-
* */
|
|
17
|
-
export function resolveSuiteLaunches(
|
|
18
|
-
suites: string[],
|
|
12
|
+
export function suiteLauncher(
|
|
19
13
|
cwd: string,
|
|
20
14
|
base: { preload?: string[]; bunFlags?: string[] },
|
|
21
15
|
projects: BenchProject[] = [],
|
|
22
|
-
): SuiteLaunch
|
|
16
|
+
): (file: string) => SuiteLaunch {
|
|
23
17
|
const matchers = projects.map((project) =>
|
|
24
18
|
project.suites.map((pattern) => new Bun.Glob(pattern)),
|
|
25
19
|
);
|
|
26
|
-
return
|
|
20
|
+
return (file) => {
|
|
27
21
|
const rel = relative(cwd, absolutePath(cwd, file));
|
|
28
22
|
const index = matchers.findIndex((globs) =>
|
|
29
23
|
globs.some((g) => g.match(rel)),
|
|
@@ -35,5 +29,15 @@ export function resolveSuiteLaunches(
|
|
|
35
29
|
),
|
|
36
30
|
bunFlags: project?.bunFlags ?? base.bunFlags ?? [],
|
|
37
31
|
};
|
|
38
|
-
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function resolveSuiteLaunches(
|
|
36
|
+
suites: string[],
|
|
37
|
+
cwd: string,
|
|
38
|
+
base: { preload?: string[]; bunFlags?: string[] },
|
|
39
|
+
projects: BenchProject[] = [],
|
|
40
|
+
): SuiteLaunch[] {
|
|
41
|
+
const launch = suiteLauncher(cwd, base, projects);
|
|
42
|
+
return suites.map((file) => launch(file));
|
|
39
43
|
}
|