ostia 0.2.11 → 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.
Files changed (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -353
  3. package/docs/agent-protocol.md +210 -0
  4. package/docs/cli.md +1196 -0
  5. package/docs/config.md +233 -0
  6. package/docs/document-schema.md +224 -0
  7. package/docs/library.md +421 -0
  8. package/docs/preload-recipes.md +169 -0
  9. package/docs/statistics.md +218 -0
  10. package/index.d.ts +942 -642
  11. package/package.json +16 -14
  12. package/src/ab/ab-runner.ts +474 -0
  13. package/src/ab/index.ts +1086 -0
  14. package/src/baseline/index.ts +75 -0
  15. package/src/bench/index.ts +462 -0
  16. package/src/bench/projects.ts +39 -0
  17. package/src/bench/range.ts +27 -0
  18. package/src/bench/registry.ts +424 -0
  19. package/src/bench/run-tasks.ts +176 -0
  20. package/src/bench/run.ts +51 -0
  21. package/src/bench/runner.ts +147 -0
  22. package/src/bench/support.ts +161 -0
  23. package/src/bench/sweep.ts +39 -0
  24. package/src/cache/fingerprint.ts +59 -0
  25. package/src/cache/store.ts +28 -0
  26. package/src/capture/bunflags.ts +91 -0
  27. package/src/capture/cpu-parse.ts +119 -0
  28. package/src/capture/cpu.ts +44 -0
  29. package/src/capture/frames.ts +54 -0
  30. package/src/capture/heap-parse.ts +86 -0
  31. package/src/capture/heap.ts +32 -0
  32. package/src/capture/inspector.ts +46 -0
  33. package/src/capture/jsc-parse.ts +167 -0
  34. package/src/capture/jsc.ts +35 -0
  35. package/src/capture/sampling.ts +5 -0
  36. package/src/ci/index.ts +416 -0
  37. package/src/cli/flags.ts +264 -0
  38. package/{chunk-scvezzm9.js → src/cli/help.ts} +31 -15
  39. package/src/cli/main.ts +18 -0
  40. package/src/cli/output.ts +185 -0
  41. package/src/cli/run.ts +1110 -0
  42. package/src/compare/index.ts +617 -0
  43. package/src/config/index.ts +275 -0
  44. package/src/config/validate.ts +267 -0
  45. package/src/errors.ts +8 -0
  46. package/src/format.ts +36 -0
  47. package/src/glob.ts +48 -0
  48. package/src/index.ts +62 -0
  49. package/src/ir/cpu.ts +10 -0
  50. package/src/ir/document.ts +471 -0
  51. package/src/ir/fp.ts +31 -0
  52. package/src/ir/git.ts +36 -0
  53. package/src/ir/types.ts +615 -0
  54. package/src/measure/alloc.ts +57 -0
  55. package/src/measure/cpu.ts +99 -0
  56. package/src/measure/environment.ts +41 -0
  57. package/src/measure/inprocess.ts +191 -0
  58. package/src/measure/instructions.ts +133 -0
  59. package/src/measure/loop.ts +57 -0
  60. package/src/measure/noise.ts +55 -0
  61. package/src/measure/paired.ts +312 -0
  62. package/src/measure/peak.ts +202 -0
  63. package/src/measure/timing.ts +263 -0
  64. package/src/profile.ts +109 -0
  65. package/src/renderers/collapsed.ts +35 -0
  66. package/src/renderers/cpu-tree.ts +183 -0
  67. package/src/renderers/cpuprofile.ts +43 -0
  68. package/src/renderers/format.ts +142 -0
  69. package/src/renderers/index.ts +27 -0
  70. package/src/renderers/json.ts +10 -0
  71. package/src/renderers/jsonl.ts +15 -0
  72. package/src/renderers/markdown.ts +525 -0
  73. package/src/renderers/mermaid.ts +78 -0
  74. package/src/renderers/minimal.ts +602 -0
  75. package/src/renderers/paired.ts +229 -0
  76. package/src/renderers/relative.ts +64 -0
  77. package/src/renderers/select.ts +286 -0
  78. package/src/renderers/speedscope.ts +69 -0
  79. package/src/renderers/terminal.ts +466 -0
  80. package/src/renderers/types.ts +27 -0
  81. package/src/spawn/index.ts +396 -0
  82. package/src/stats/bootstrap.ts +153 -0
  83. package/src/stats/index.ts +140 -0
  84. package/src/stats/mannwhitney.ts +81 -0
  85. package/src/time.ts +325 -0
  86. package/src/version.ts +3 -0
  87. package/ab-runner.ts +0 -8
  88. package/chunk-5m601yfv.js +0 -15
  89. package/chunk-82vs1rw1.js +0 -2
  90. package/chunk-dvqggjkn.js +0 -14
  91. package/chunk-fc36fd0b.js +0 -3
  92. package/chunk-pdv5zb3w.js +0 -27
  93. package/chunk-r6hwb84z.js +0 -25
  94. package/cli.js +0 -3
  95. package/index.js +0 -2
  96. package/runner.ts +0 -7
package/index.d.ts CHANGED
@@ -1,132 +1,138 @@
1
- export declare function defineConfig(config: OstiaConfigInput): OstiaConfigInput;
2
-
3
- export interface WorkloadConfig {
4
- label?: string;
5
- command?: string[];
6
- suites?: string[];
7
- /** `command` only. Globs of the files the timing depends on: `ostia ci`
8
- * reuses a cached run while their contents are unchanged. Omitted, the
9
- * workload always reruns; `[]` caches until the command or config changes. */
10
- inputs?: string[];
11
- /** `command` only. Runs before every trial (warmup included), unmeasured:
12
- * a command string / argv array, or in `ostia.config.ts` a function. A
13
- * function makes the workload uncacheable for `ostia ci`. */
14
- prepare?: PrepareHook;
15
- /** `command` only. Take timing from a number in the command's own output
16
- * instead of its wall clock; see `TimeSource`. */
17
- timeSource?: TimeSource;
18
- /** `command`: kills a trial (or prepare hook) after this many ms.
19
- * `suites`: kills a suite file's (or isolated task's) process after this
20
- * many ms, overriding `bench.timeoutMs`. Overrides `ostia ci`'s 10-minute
21
- * default. */
22
- timeoutMs?: number;
23
- /** `command` only. Exit codes to treat as success; see
24
- * `TimeOptions.ignoreExitCodes`. */
25
- ignoreExitCodes?: number[];
26
- }
27
-
28
- interface BenchConfig {
29
- /** Suite file globs, resolved against the config's directory (e.g.
30
- * "bench/**\/*.bench.ts"). Suite files given on the command line replace
31
- * this list. */
32
- suites?: string[];
1
+ export interface AbOptions {
2
+ suites: string[];
3
+ /** Git ref whose committed tree is the base side (default: `"HEAD"`); the
4
+ * candidate is the working tree, uncommitted changes included. */
5
+ base?: string;
6
+ /** Rounds per workload, each one base batch and one candidate batch of
7
+ * about 10ms (default: 15). */
8
+ rounds?: number;
9
+ /** What to judge each round by: the candidate/base time ratio
10
+ * (`"time"`, the default), or the ratio of instructions each side retired
11
+ * per call (`"instructions"`), which a loaded machine barely moves, so a
12
+ * lower `thresholdPct` holds. Instructions are recorded either way where
13
+ * the machine counts them (see `PairedEvidence.instructions`); asking to
14
+ * judge by them where it can't throws an `OstiaUsageError`. */
15
+ metric?: "time" | "instructions";
16
+ /** Flag a workload whose median candidate/base ratio moves past this many
17
+ * percent (default: 10). */
18
+ thresholdPct?: number;
19
+ /** Fail when the geometric mean of all workloads' ratios is slower than
20
+ * this many percent (default: 1.5): a broad slowdown too small to flag any
21
+ * one workload. */
22
+ geomeanThresholdPct?: number;
23
+ /** Fresh-process repeats of each flagged workload, which only counts when
24
+ * every repeat flags it the same way (default: 2; 0 trusts the first). */
25
+ confirm?: number;
26
+ filter?: string;
33
27
  preload?: string[];
34
- /** Extra flags for the `bun` process that runs each suite file; see
35
- * `BenchOptions.bunFlags`. `--bun-flags` replaces this list. */
36
28
  bunFlags?: string[];
37
- jobs?: number | "auto";
38
- budgetMs?: number;
39
- samples?: number;
40
- minSamples?: number;
41
- gc?: boolean;
42
- cpu?: boolean;
43
- cpuIntervalUs?: number;
44
- alloc?: boolean;
45
- peakMem?: boolean;
46
- filter?: string;
47
- isolate?: boolean;
29
+ /** Per-suite `preload` / `bunFlags`; see `BenchOptions.projects`. */
30
+ projects?: BenchProject[];
48
31
  outDir?: string;
49
- /** Kills a suite file's (or isolated task's) subprocess after this many
50
- * ms; overrides `ostia ci`'s 10-minute default. */
51
- timeoutMs?: number;
52
- }
53
-
54
- export interface AbConfig {
55
- /** Shell command(s) run once in a freshly extracted base tree, e.g. to
56
- * build gitignored files the suites import; see `AbOptions.baseSetup`.
57
- * `--base-setup` replaces this list. */
58
- setup?: string | string[];
59
- /** Base trees to keep cached; see `AbOptions.keepTrees`. `--keep-trees`
60
- * overrides. Default: 5. */
61
- keepTrees?: number;
62
- /** Compare retained heap per call; see `AbOptions.alloc`. `--alloc` /
63
- * `--no-alloc` override. `bench.alloc` doesn't apply to `ab`. */
32
+ cwd?: string;
33
+ noiseCheck?: boolean;
34
+ /** Also compare each side's retained heap per call (see
35
+ * `bench({ alloc })`) and how far its first call raises RSS (see
36
+ * `bench({ peakMem })`), each the median of 3 fresh processes per side.
37
+ * Task/group options override these. */
64
38
  alloc?: boolean;
65
- /** Compare peak RSS of the first call; see `AbOptions.peakMem`.
66
- * `--peak-mem` / `--no-peak-mem` override. `bench.peakMem` doesn't apply
67
- * to `ab`. */
68
39
  peakMem?: boolean;
69
- /** Memory verdict threshold, percent; see `AbOptions.memThresholdPct`.
70
- * `--mem-threshold` overrides. Default: 10. */
40
+ /** Flag a memory reading that moves past this many percent of the base's
41
+ * and past its noise floor (default: 10). A memory regression fails the
42
+ * run. */
71
43
  memThresholdPct?: number;
44
+ /** Shell commands run once, in order, in a freshly extracted base tree
45
+ * before it's used: to build what the suites import but git doesn't hold
46
+ * (generated or gitignored files). Each runs with its cwd at the tree's
47
+ * counterpart of `cwd`, the project's `node_modules` linked in, and
48
+ * `OSTIA_AB_SHA` / `OSTIA_AB_CANDIDATE_DIR` (the working tree's `cwd`) in
49
+ * its environment. The tree is cached per commit and command list. */
50
+ baseSetup?: string | string[];
51
+ /** Base trees to keep under `.ostia/ab`, counting this run's: after a
52
+ * run, older ones go, least recently used first, unless one was used in
53
+ * the last hour (another run may still need it). Default: 5. */
54
+ keepTrees?: number;
55
+ /** SIGKILLs a runner process (one suite file or repeat), or a `baseSetup`
56
+ * command, after this many ms. */
57
+ timeoutMs?: number;
58
+ /** Aborting kills the running process and resolves with the suites that
59
+ * had finished, plus an `aborted` warning; unrun repeats leave their
60
+ * workloads unconfirmed. */
61
+ signal?: AbortSignal;
62
+ /** Called as each setup command, task, confirmation repeat and memory
63
+ * process starts. */
64
+ onProgress?: (progress: AbProgress) => void;
72
65
  }
73
-
74
- export interface OstiaConfig {
75
- /** `command` workloads: exact trial count; see `time()`. */
76
- samples?: number;
77
- /** `command` workloads: sampling budget in ms; see `time()`. */
78
- budgetMs?: number;
79
- /** `command` workloads: floor on trials; see `time()`. */
80
- minSamples?: number;
81
- warmup: number;
82
- outDir: string;
83
- baselineDir: string;
84
- baseline: string;
85
- thresholds: Thresholds;
86
- workloads: WorkloadConfig[];
87
- bench?: BenchConfig;
88
- ab?: AbConfig;
89
- /** `ostia ci`'s policy for a workload with no matching baseline row (by
90
- * workload id): `"fail"` exits 2 naming the baseline file, `"warn"` lists
91
- * it in the report. Unset: `"fail"` when every workload is missing (a
92
- * stale or wrong baseline), `"warn"` otherwise. */
93
- onMissingBaseline?: "warn" | "fail";
94
- /** Measure the machine's noise floor once per `ostia ci` run (default
95
- * true) and stamp it on the candidate document, so `compare` widens its
96
- * thresholds accordingly. `--no-noise-check` overrides this per run. */
97
- noiseCheck?: boolean;
66
+ /**
67
+ * Launch settings for the suite files matching `suites`; see
68
+ * `BenchOptions.projects`. */
69
+ export interface BenchProject {
70
+ /**
71
+ * Globs against the current directory. A suite file takes the first
72
+ * project one of these matches; `ostia bench` with no files also runs
73
+ * every file they expand to. */
74
+ suites: string[];
75
+ /**
76
+ * Replaces the top-level `preload` for these files; `[]` runs them with
77
+ * none. Unset: the top-level list applies. */
78
+ preload?: string[];
79
+ /** Replaces the top-level `bunFlags` for these files, as `preload` does. */
80
+ bunFlags?: string[];
98
81
  }
99
-
100
- export type OstiaConfigInput = Omit<Partial<OstiaConfig>, "thresholds"> & {
101
- thresholds?: Partial<Thresholds>;
82
+ /** What `ab()` is doing, for `onProgress`. Counts start at 1. */
83
+ export type AbProgress = {
84
+ phase: "setup";
85
+ command: string;
86
+ } | {
87
+ phase: "measure";
88
+ suite: number;
89
+ suites: number;
90
+ file: string;
91
+ /** Each suite runs twice, once with each side first. */
92
+ pass: number;
93
+ passes: number;
94
+ task: number;
95
+ tasks: number;
96
+ label: string;
97
+ } | {
98
+ phase: "confirm";
99
+ repeat: number;
100
+ repeats: number;
101
+ label: string;
102
+ } | {
103
+ phase: "memory";
104
+ run: number;
105
+ runs: number;
106
+ side: Side;
107
+ label: string;
102
108
  };
103
-
104
- export interface Thresholds {
105
- timingPct: number;
106
- frameSelfPct: number;
107
- heapTypePct: number;
108
- minFrameSelfUs: number;
109
- /** A `regressed` / `improved` verdict also requires Mann-Whitney `pValue < alpha`. */
110
- alpha: number;
111
- /** Bootstrap resample rounds for the timing CI. */
112
- bootstrapIterations: number;
109
+ type Side = "base" | "cand";
110
+ /** `ab()` can't run: not in a git repository, or `base` isn't a commit. */
111
+ export declare class AbBaseError extends OstiaUsageError {
113
112
  }
114
-
115
- export declare const DEFAULT_THRESHOLDS: Thresholds;
116
-
117
- export interface CompareResult {
118
- comparisons: Comparison[];
119
- unmatched: {
120
- baseOnly: Workload[];
121
- candOnly: Workload[];
122
- };
123
- /** Every task on either side; see `ProfileDocument.compared`. */
124
- compared: ComparedTask[];
125
- summary: ComparisonSummary;
113
+ /** The caller's input can't be run as given (missing suite, bad ref, absent
114
+ * baseline): the CLI reports it as a usage error (exit 2) rather than an
115
+ * internal failure. */
116
+ declare class OstiaUsageError extends Error {
126
117
  }
127
-
128
- export declare function compareDocuments(base: ProfileDocument, cand: ProfileDocument, thresholds?: Thresholds): CompareResult;
129
-
118
+ /** A `baseSetup` command exited non-zero or timed out. The message names
119
+ * the command and ends with the tail of its output. */
120
+ export declare class AbSetupError extends Error {
121
+ }
122
+ /** One side's suite failed outside any task: on import, with no tasks, or
123
+ * while a task's memory was measured. */
124
+ export declare class AbSuiteError extends Error {
125
+ readonly side: Side;
126
+ constructor(message: string, side: Side);
127
+ }
128
+ /** Paired A/B timing of suite files against a git ref: every task runs on
129
+ * the ref's committed tree (base) and the working tree (candidate) in one
130
+ * process, alternating short batches, and is judged on the per-round time
131
+ * ratio. Drift between two runs minutes apart cancels within a round. What
132
+ * pairing can't cancel is how the JIT compiled each side in that process,
133
+ * so every flagged workload is re-measured in `confirm` fresh processes
134
+ * and only counts when they all agree. */
135
+ export declare function ab(opts: AbOptions): Promise<ProfileDocument>;
130
136
  export interface ProfileDocument {
131
137
  schemaVersion: 2;
132
138
  toolVersion: string;
@@ -142,76 +148,60 @@ export interface ProfileDocument {
142
148
  comparisons?: Comparison[];
143
149
  /** Aggregate across `comparisons`; present wherever `comparisons` is. */
144
150
  comparisonSummary?: ComparisonSummary;
145
- /** Workload ids on only one side of the comparison; present wherever
151
+ /**
152
+ * Workload ids on only one side of the comparison; present wherever
146
153
  * `comparisons` is. */
147
154
  unmatched?: {
148
155
  baseOnly: string[];
149
156
  candOnly: string[];
150
157
  };
151
- /** Every task on either side of the comparison, one entry each: what
158
+ /**
159
+ * Every task on either side of the comparison, one entry each: what
152
160
  * `--format markdown` prints, flat for scripts. Present wherever
153
161
  * `comparisons` is. */
154
162
  compared?: ComparedTask[];
155
- /** Machine conditions at measurement time; absent when the noise check was
163
+ /**
164
+ * Machine conditions at measurement time; absent when the noise check was
156
165
  * skipped. */
157
166
  environment?: Environment;
158
- /** Run-level result of `ostia ab` / `ab()`, whose measurements are
167
+ /**
168
+ * Run-level result of `ostia ab` / `ab()`, whose measurements are
159
169
  * `phase: "paired"`. */
160
170
  ab?: AbSummary;
161
- /** Repo state of the process's cwd; absent outside a git repo. Never part of
162
- * an id or fingerprint, so a commit or dirty tree doesn't orphan a baseline. */
171
+ /**
172
+ * Repo state of the process's cwd; absent outside a git repo. Never part
173
+ * of an id or fingerprint, so a commit or dirty tree doesn't orphan a
174
+ * baseline. */
163
175
  git?: GitMetadata;
164
176
  }
165
-
166
- interface GitMetadata {
167
- sha: string;
168
- branch: string;
169
- dirty: boolean;
170
- }
171
-
172
- interface NoiseFloor {
173
- /** `mad / median` of a reference workload, percent: how noisy the machine is
174
- * right now, independent of what's measured. */
175
- floorPct: number;
176
- referenceMedianNs: number;
177
- samples: number;
178
- /** How much slower (positive) the reference ran at the end of the run than
179
- * at the start, percent: the machine's drift over the run. Absent when the
180
- * run didn't re-measure it (`profile()`, older documents). */
181
- driftPct?: number;
182
- }
183
-
184
- interface Environment {
185
- cpuModel: string;
186
- cores: number;
187
- loadAvg1: number;
188
- loadAvg5: number;
189
- noise: NoiseFloor;
190
- }
191
-
192
177
  export interface Workload {
193
- /** Identifies what is measured, not where or when. Subprocess: a hash of
194
- * argv, `prepare` and `timeSource`, excluding `process.cwd()`. In-process: a
195
- * hash of the function source, or for a registry entry the file, task name
196
- * and `params`. Annotations (`label`, `description`, `baseline`) never
197
- * affect it. */
178
+ /**
179
+ * Identifies what is measured, not where or when. Subprocess: a hash of
180
+ * argv, `prepare` and `timeSource`, excluding `process.cwd()`. In-process:
181
+ * a hash of the function source, or for a registry entry the file, task
182
+ * name and `params`. Annotations (`label`, `description`, `baseline`)
183
+ * never affect it. */
198
184
  id: string;
199
185
  kind: "subprocess" | "inprocess";
200
186
  label?: string;
201
187
  command?: string[];
202
- /** Command-form `prepare` hook run before every trial; part of the id. A
203
- * function-form hook isn't serializable and is omitted (its source is still
204
- * hashed into the id). */
188
+ /**
189
+ * Command-form `prepare` hook run before every trial; part of the id. A
190
+ * function-form hook isn't serializable and is omitted (its source is
191
+ * still hashed into the id). */
205
192
  prepare?: string[];
206
- /** Takes samples from a number in the command's own output instead of the
193
+ /**
194
+ * Takes samples from a number in the command's own output instead of the
207
195
  * wall clock; part of the id. */
208
196
  timeSource?: {
209
197
  pattern: string;
210
198
  group?: number;
211
199
  unit?: "ns" | "us" | "ms" | "s";
212
200
  };
213
- /** `task` is the registry's "group/name" id; `group` is the enclosing
214
- * `group()` name. Renderers prefer `group` over splitting `task` on "/". */
201
+ /**
202
+ * `task` is the registry's "group/name" id; `group` is the enclosing
203
+ * `group()` name. Renderers prefer `group` over splitting `task` on "/".
204
+ * */
215
205
  entry?: {
216
206
  file: string;
217
207
  task: string;
@@ -225,21 +215,21 @@ export interface Workload {
225
215
  groupDescription?: string;
226
216
  /** Ran in a subprocess of its own rather than sharing its suite file's. */
227
217
  isolated?: boolean;
228
- /** From `task(..., { params })` or a `sweep()` point. Part of the id, so
218
+ /**
219
+ * From `task(..., { params })` or a `sweep()` point. Part of the id, so
229
220
  * points sharing a task name don't collide. */
230
221
  params?: Record<string, string | number | boolean>;
231
- /** Ids this task had under its former names (`task(..., { aliases })`), so
222
+ /**
223
+ * Ids this task had under its former names (`task(..., { aliases })`), so
232
224
  * `compare` and `ab` match a base measured before a rename. Never part of
233
225
  * the id. */
234
226
  formerIds?: string[];
235
- /** From `task.skip()` / `group.skip()`: never measured, so no `Measurement`.
236
- * Renderers print a "- skipped" row; `compare` treats it as `unchanged` with
237
- * a `skipped` warning. */
227
+ /**
228
+ * From `task.skip()` / `group.skip()`: never measured, so no
229
+ * `Measurement`. Renderers print a "- skipped" row; `compare` treats it as
230
+ * `unchanged` with a `skipped` warning. */
238
231
  skipped?: boolean;
239
232
  }
240
-
241
- type Phase = "timing" | "cpu" | "heap" | "memstats" | "paired";
242
-
243
233
  interface Measurement {
244
234
  id: string;
245
235
  workloadId: string;
@@ -253,9 +243,14 @@ interface Measurement {
253
243
  heap?: HeapEvidence;
254
244
  memory?: MemoryEvidence;
255
245
  jit?: JitTierBreakdown;
246
+ /**
247
+ * In-process timing, where the machine counts them: instructions the
248
+ * task retired per call, one sample per trial (see `InstructionStats`). */
249
+ instructions?: InstructionStats;
256
250
  /** `phase: "paired"` only; `timing` is then the candidate side. */
257
251
  paired?: PairedEvidence;
258
- /** `phase: "paired"` only: the task threw on one side or both
252
+ /**
253
+ * `phase: "paired"` only: the task threw on one side or both
259
254
  * (`"both"`). Usually instead of `timing`/`paired`; when it threw in a
260
255
  * confirmation repeat, `repeat` (from 1) says which, and `timing`/`paired`
261
256
  * stay as the first process measured them. Either way the task isn't in
@@ -267,15 +262,17 @@ interface Measurement {
267
262
  };
268
263
  warnings: Warning[];
269
264
  artifacts: ArtifactRef[];
270
- /** Trials ran round-robin with the other commands of the same `time()` call,
271
- * so drift over the run hits every command equally. */
265
+ /**
266
+ * Trials ran round-robin with the other commands of the same `time()`
267
+ * call, so drift over the run hits every command equally. */
272
268
  interleaved?: boolean;
273
269
  }
274
-
270
+ type Phase = "timing" | "cpu" | "heap" | "memstats" | "paired";
275
271
  interface Trial {
276
272
  i: number;
277
273
  wallNs: number;
278
- /** The command's self-reported time (ns) under a `timeSource`; these, not
274
+ /**
275
+ * The command's self-reported time (ns) under a `timeSource`; these, not
279
276
  * `wallNs`, are then the `timing.samples`. */
280
277
  reportedNs?: number;
281
278
  exitCode?: number;
@@ -284,11 +281,11 @@ interface Trial {
284
281
  maxRssBytes?: number;
285
282
  /** Killed by `timeoutMs`; `exitCode` is absent. Contributes no sample. */
286
283
  timedOut?: true;
287
- /** Output didn't match the `timeSource` pattern; `reportedNs` is absent
284
+ /**
285
+ * Output didn't match the `timeSource` pattern; `reportedNs` is absent
288
286
  * (never a `wallNs` fallback). Contributes no sample. */
289
287
  timeSourceNoMatch?: true;
290
288
  }
291
-
292
289
  interface TimingStats {
293
290
  unit: "ns";
294
291
  samples: number[];
@@ -307,14 +304,26 @@ interface TimingStats {
307
304
  p75: number;
308
305
  /** 99th percentile, ns. */
309
306
  p99: number;
310
- /** Median absolute deviation, ns: a spread measure that, unlike stddev, the
307
+ /**
308
+ * Median absolute deviation, ns: a spread measure that, unlike stddev, the
311
309
  * long right tail of wall-clock timings doesn't skew. */
312
310
  mad: number;
313
- /** Calls batched into one timed block; absent (read as 1) unless batching
311
+ /**
312
+ * Calls batched into one timed block; absent (read as 1) unless batching
314
313
  * occurred, and always absent for subprocess timing. */
315
314
  batch?: number;
316
315
  }
317
-
316
+ interface CpuEvidence {
317
+ origin: "cpu-prof" | "inspector" | "jsc-profile";
318
+ samplingIntervalUs: number;
319
+ frames: Frame[];
320
+ nodes: CallNode[];
321
+ totals: FrameTotal[];
322
+ samples?: {
323
+ nodeIds: number[];
324
+ timeDeltasUs: number[];
325
+ };
326
+ }
318
327
  interface Frame {
319
328
  key: string;
320
329
  name: string;
@@ -322,32 +331,17 @@ interface Frame {
322
331
  line?: number;
323
332
  col?: number;
324
333
  }
325
-
326
334
  interface CallNode {
327
335
  id: number;
328
336
  frameIx: number;
329
337
  children: number[];
330
338
  }
331
-
332
339
  interface FrameTotal {
333
340
  frameIx: number;
334
341
  selfUs: number;
335
342
  totalUs: number;
336
343
  samples: number;
337
344
  }
338
-
339
- interface CpuEvidence {
340
- origin: "cpu-prof" | "inspector" | "jsc-profile";
341
- samplingIntervalUs: number;
342
- frames: Frame[];
343
- nodes: CallNode[];
344
- totals: FrameTotal[];
345
- samples?: {
346
- nodeIds: number[];
347
- timeDeltasUs: number[];
348
- };
349
- }
350
-
351
345
  interface HeapEvidence {
352
346
  origin: "heap-prof";
353
347
  heapSizeBytes?: number;
@@ -358,27 +352,30 @@ interface HeapEvidence {
358
352
  retainedBytes?: number;
359
353
  }[];
360
354
  }
361
-
362
355
  interface MemoryEvidence {
363
356
  origin: "resourceUsage" | "heapStats";
364
- /** `memstats` only: `"retained"` (`--alloc`, `bytesPerOp`) or `"peak"`
365
- * (`--peak-mem`, `peakBytes`). Absent means `"retained"` on older documents. */
357
+ /**
358
+ * `memstats` only: `"retained"` (`--alloc`, `bytesPerOp`) or `"peak"`
359
+ * (`--peak-mem`, `peakBytes`). Absent means `"retained"` on older
360
+ * documents. */
366
361
  kind?: "retained" | "peak";
367
362
  /** Largest `Trial.maxRssBytes` across a timing measurement's trials. */
368
363
  maxRssBytes?: number;
369
- /** `--alloc`: heap growth per call across one batch bracketed by full GCs,
364
+ /**
365
+ * `--alloc`: heap growth per call across one batch bracketed by full GCs,
370
366
  * so what the calls keep alive (a leak check), not what they allocate. */
371
367
  bytesPerOp?: number;
372
- /** `--peak-mem`: how far one call raised RSS, garbage included; median over
368
+ /**
369
+ * `--peak-mem`: how far one call raised RSS, garbage included; median over
373
370
  * 3 fresh processes. A `peak-hidden` warning says when it may read low. */
374
371
  peakBytes?: number;
375
- /** In-process timing: the JS heap's size as of its last collection, just
372
+ /**
373
+ * In-process timing: the JS heap's size as of its last collection, just
376
374
  * before the task's warmup and just after its last trial. Read without
377
375
  * forcing a GC, so it never perturbs the timing. */
378
376
  heapUsedBeforeBytes?: number;
379
377
  heapUsedAfterBytes?: number;
380
378
  }
381
-
382
379
  interface JitTierBreakdown {
383
380
  origin: "jsc-profile";
384
381
  tiers: {
@@ -393,13 +390,26 @@ interface JitTierBreakdown {
393
390
  samples: number;
394
391
  }[];
395
392
  }
396
-
393
+ /**
394
+ * Instructions retired per call on the thread that ran the task, in user
395
+ * mode: a system call's kernel work and other threads' (JIT compiler, GC
396
+ * helpers, I/O pool) don't count. Unlike time, another process taking the
397
+ * CPU doesn't move it. Includes the timing loop's own few hundred
398
+ * instructions per batch. */
399
+ interface InstructionStats {
400
+ samples: number[];
401
+ median: number;
402
+ }
403
+ /**
404
+ * Evidence of a `phase: "paired"` measurement: base and candidate
405
+ * alternate in batches in one process, so drift cancels in the ratio. */
397
406
  interface PairedEvidence {
398
407
  /** One base batch and one candidate batch per round, alternating order. */
399
408
  rounds: number;
400
409
  /** Calls per side per round. */
401
410
  batch: number;
402
- /** Base per-call time for each round, ns; `ratios[i]` pairs with
411
+ /**
412
+ * Base per-call time for each round, ns; `ratios[i]` pairs with
403
413
  * `baseSamples[i]` and the candidate's `timing.samples[i]`. */
404
414
  baseSamples: number[];
405
415
  baseMedianNs: number;
@@ -409,104 +419,109 @@ interface PairedEvidence {
409
419
  /** 25th/75th percentile of `ratios`. */
410
420
  ratioP25: number;
411
421
  ratioP75: number;
412
- /** Median ratio past `1 ± threshold` and on the same side of 1 in at least
413
- * three quarters of rounds. */
422
+ /**
423
+ * Instructions retired per call on each side, where the machine counts
424
+ * them; what `AbSummary.metric: "instructions"` judges. */
425
+ instructions?: PairedInstructions;
426
+ /**
427
+ * `AbSummary.metric`'s median ratio past `1 ± threshold` and on the same
428
+ * side of 1 in at least three quarters of rounds. */
414
429
  flagged?: "regressed" | "improved";
415
- /** Each fresh-process re-measurement of a flagged workload. */
430
+ /**
431
+ * Each fresh-process re-measurement of a flagged workload; `flagged` by
432
+ * `AbSummary.metric`. */
416
433
  repeats?: {
417
434
  medianRatio: number;
418
435
  ratioP25: number;
419
436
  ratioP75: number;
437
+ instructions?: {
438
+ medianRatio: number;
439
+ ratioP25: number;
440
+ ratioP75: number;
441
+ };
420
442
  flagged?: "regressed" | "improved";
421
443
  }[];
422
444
  /** Set when `flagged` is: whether every repeat flagged the same way. */
423
445
  confirmed?: boolean;
424
446
  /** `flagged` when confirmed, else `"unchanged"`. */
425
447
  verdict: "regressed" | "improved" | "unchanged";
426
- /** First call's return values were deep-equal on both sides; informational,
448
+ /**
449
+ * First call's return values were deep-equal on both sides; informational,
427
450
  * never a failure. */
428
451
  sameOutput: boolean;
429
- /** Set when the suite file's text differs from the base ref's copy, so
452
+ /**
453
+ * Set when the suite file's text differs from the base ref's copy, so
430
454
  * each side may run a different benchmark (a fixed fixture, a changed
431
455
  * input). With `sameOutput: false` too, the task is "not comparable": its
432
456
  * verdict is `"unchanged"` and it's left out of the geomean. */
433
457
  suiteChanged?: true;
434
- /** `--alloc`: heap each call keeps alive after a full GC, per side, after
458
+ /**
459
+ * `--alloc`: heap each call keeps alive after a full GC, per side, after
435
460
  * a warmup batch; each the median of 3 fresh processes. */
436
461
  retained?: MemoryChange;
437
- /** `--peak-mem`: how far the task's first call raises RSS, per side,
462
+ /**
463
+ * `--peak-mem`: how far the task's first call raises RSS, per side,
438
464
  * each the median of 3 fresh processes. */
439
465
  peak?: MemoryChange;
440
466
  }
441
-
467
+ /**
468
+ * Instructions a paired task retired per call (see `InstructionStats`),
469
+ * from the same rounds as `PairedEvidence`'s times. */
470
+ interface PairedInstructions {
471
+ /** Per round, index-aligned with `PairedEvidence.baseSamples`. */
472
+ baseSamples: number[];
473
+ candSamples: number[];
474
+ baseMedian: number;
475
+ candMedian: number;
476
+ /** Candidate/base instructions per round. */
477
+ ratios: number[];
478
+ medianRatio: number;
479
+ ratioP25: number;
480
+ ratioP75: number;
481
+ }
482
+ /** One memory reading on both sides of an `ab()` task, bytes. */
442
483
  interface MemoryChange {
443
484
  baseBytes: number;
444
485
  candBytes: number;
445
- /** Past both `AbSummary.memory.thresholdPct` of the base and
486
+ /**
487
+ * Past both `AbSummary.memory.thresholdPct` of the base and
446
488
  * `floorBytes`; always `"unchanged"` on a not-comparable task. */
447
489
  verdict: "regressed" | "improved" | "unchanged";
448
- /** The smallest change that counts, bytes: 16 KiB over the batch's calls
490
+ /**
491
+ * The smallest change that counts, bytes: 16 KiB over the batch's calls
449
492
  * for `retained`; for `peak`, 1 MiB, or the freed memory a `peak-hidden`
450
493
  * warning reports. */
451
494
  floorBytes: number;
452
495
  }
453
-
454
- interface AbSummary {
455
- base: {
456
- ref: string;
457
- sha: string;
458
- };
459
- /** Suite files, as given, that don't exist at the base ref: their tasks
460
- * are all candidate-only. */
461
- newSuites?: string[];
462
- rounds: number;
463
- thresholdPct: number;
464
- geomeanThresholdPct: number;
465
- /** Workloads measured on both sides. */
466
- matched: number;
467
- /** Confirmed verdicts. */
468
- regressed: number;
469
- improved: number;
470
- unchanged: number;
471
- /** Flagged in-process, but a fresh-process repeat disagreed; counted in
472
- * `unchanged`. */
473
- unconfirmed: number;
474
- /** Workloads whose first call returned different values on each side. */
475
- outputDiffers: number;
476
- /** Workloads whose suite file and output both changed (see
477
- * `PairedEvidence.suiteChanged`); counted in `unchanged`, left out of
478
- * `geomeanPct`. */
479
- notComparable: number;
480
- /** Workloads that threw on either side or both, and so weren't timed;
481
- * not counted in `matched`. */
482
- threw: number;
483
- /** Present when any task had a memory reading (`--alloc`, `--peak-mem`):
484
- * how many tasks' memory regressed or improved, on either reading. */
485
- memory?: {
486
- thresholdPct: number;
487
- regressed: number;
488
- improved: number;
489
- };
490
- /** Geometric mean of the workloads' median ratios, signed percent (negative:
491
- * candidate faster); a flagged workload contributes its median over its main
492
- * run and repeats. `null` when nothing was paired. */
493
- geomeanPct: number | null;
494
- /** `"fail"` when any workload regressed (confirmed), threw on the
495
- * candidate side only, or `geomeanPct` exceeds `geomeanThresholdPct`, or
496
- * any task's memory regressed. */
497
- verdict: "pass" | "fail";
498
- }
499
-
500
- declare const WARNING_CODES: readonly ["slow-first-run", "outliers-detected", "fast-command", "nonzero-exit", "artifact-missing", "empty-profile", "low-sample-count", "thin-comparison", "noisy-machine", "skipped", "jit-cold", "timeout", "aborted", "time-source-no-match", "environment-mismatch", "peak-hidden", "suite-changed"];
501
-
502
- export type WarningCode = (typeof WARNING_CODES)[number];
503
-
504
496
  export interface Warning {
505
497
  code: WarningCode;
506
498
  message: string;
507
499
  data?: Record<string, unknown>;
508
500
  }
509
-
501
+ export type WarningCode = (typeof WARNING_CODES)[number];
502
+ /**
503
+ * Every `Warning.code`. A runtime array so a test can assert each is
504
+ * emitted.
505
+ */
506
+ declare const WARNING_CODES: readonly [
507
+ "slow-first-run",
508
+ "outliers-detected",
509
+ "fast-command",
510
+ "nonzero-exit",
511
+ "artifact-missing",
512
+ "empty-profile",
513
+ "low-sample-count",
514
+ "thin-comparison",
515
+ "noisy-machine",
516
+ "skipped",
517
+ "jit-cold",
518
+ "timeout",
519
+ "aborted",
520
+ "time-source-no-match",
521
+ "environment-mismatch",
522
+ "peak-hidden",
523
+ "suite-changed"
524
+ ];
510
525
  interface ArtifactRef {
511
526
  id: string;
512
527
  kind: "cpuprofile" | "heapsnapshot";
@@ -514,7 +529,6 @@ interface ArtifactRef {
514
529
  sha256: string;
515
530
  bytes: number;
516
531
  }
517
-
518
532
  export interface Comparison {
519
533
  id: string;
520
534
  baselineMeasurementId: string;
@@ -522,7 +536,8 @@ export interface Comparison {
522
536
  timing?: {
523
537
  medianDeltaPct: number;
524
538
  meanDeltaPct: number;
525
- /** 95% bootstrap CI on the difference of medians, percent of the baseline
539
+ /**
540
+ * 95% bootstrap CI on the difference of medians, percent of the baseline
526
541
  * median. Absent below 5 samples a side (`thin-comparison`). */
527
542
  ci95?: [number, number];
528
543
  /** Two-sided Mann-Whitney U p-value; absent whenever `ci95` is. */
@@ -531,7 +546,10 @@ export interface Comparison {
531
546
  seed?: number;
532
547
  verdict: "improved" | "regressed" | "unchanged";
533
548
  };
534
- /** Caveats about this comparison, e.g. a thin-sample point-estimate verdict. */
549
+ /**
550
+ * Caveats about this comparison, e.g. a thin-sample point-estimate
551
+ * verdict.
552
+ */
535
553
  warnings?: Warning[];
536
554
  frames?: {
537
555
  frameKey: string;
@@ -555,25 +573,31 @@ export interface Comparison {
555
573
  minFrameSelfUs: number;
556
574
  alpha: number;
557
575
  bootstrapIterations: number;
558
- /** `max(timingPct, both documents' noise floors)`: what timing was tested against. */
576
+ /**
577
+ * `max(timingPct, both documents' noise floors)`: what timing was tested
578
+ * against.
579
+ */
559
580
  effectiveTimingPct: number;
560
581
  };
561
582
  verdict: "pass" | "fail";
562
583
  }
563
-
584
+ /** Aggregate view over a `compareDocuments` call's `Comparison[]`. */
564
585
  interface ComparisonSummary {
565
586
  /** `comparisons.length`. */
566
587
  matched: number;
567
588
  regressed: number;
568
589
  improved: number;
569
590
  unchanged: number;
570
- /** Geometric mean of `cand/base` median ratios, signed percent (negative:
591
+ /**
592
+ * Geometric mean of `cand/base` median ratios, signed percent (negative:
571
593
  * candidate faster). `null` when no comparison had a finite ratio. */
572
594
  geomeanPct: number | null;
573
- /** `Comparison.thresholds.effectiveTimingPct`, which is the same for the
595
+ /**
596
+ * `Comparison.thresholds.effectiveTimingPct`, which is the same for the
574
597
  * whole document pair. */
575
598
  effectiveTimingPct: number;
576
- /** The machine's drift, percent, added to the timing threshold: the
599
+ /**
600
+ * The machine's drift, percent, added to the timing threshold: the
577
601
  * largest of each run's own drift (`NoiseFloor.driftPct`) and how far the
578
602
  * reference loop's speed moved between the two runs. Absent when either
579
603
  * document lacks a noise check. */
@@ -581,24 +605,30 @@ interface ComparisonSummary {
581
605
  /** `"fail"` when any comparison's verdict is `"fail"`. */
582
606
  verdict: "pass" | "fail";
583
607
  }
584
-
608
+ /**
609
+ * One task of a `compare`/`ci` run: matched on both sides, or present on
610
+ * only one (`missing-base`: new, or renamed without an alias;
611
+ * `missing-cand`: removed, or renamed). Times in ns, memory in bytes. */
585
612
  interface ComparedTask {
586
613
  /** The candidate's workload id; the base's on a `missing-cand` task. */
587
614
  workloadId: string;
588
615
  /** Display name: the label, else the command, else the id. */
589
616
  task: string;
590
617
  group?: string;
591
- /** Set when the base was matched through one of the task's `aliases`: the
618
+ /**
619
+ * Set when the base was matched through one of the task's `aliases`: the
592
620
  * base's workload id and display name. */
593
621
  renamedFrom?: {
594
622
  workloadId: string;
595
623
  task: string;
596
624
  };
597
625
  verdict: "improved" | "unchanged" | "regressed" | "missing-base" | "missing-cand";
598
- /** The `Comparison` holding this task's frame and heap-type deltas and
626
+ /**
627
+ * The `Comparison` holding this task's frame and heap-type deltas and
599
628
  * warnings; absent on a one-sided task. */
600
629
  comparisonId?: string;
601
- /** Whether the comparison passed the gate (timing, frames, heap types);
630
+ /**
631
+ * Whether the comparison passed the gate (timing, frames, heap types);
602
632
  * absent on a one-sided task, which never fails it. */
603
633
  pass?: boolean;
604
634
  /** Absent on a one-sided or skipped task. */
@@ -619,9 +649,10 @@ interface ComparedTask {
619
649
  /** Memory readings present on both sides; informational, never gated. */
620
650
  memory?: MemoryDelta[];
621
651
  }
622
-
652
+ /** One memory reading of a task on both sides of a `compare`/`ci`, bytes. */
623
653
  interface MemoryDelta {
624
- /** `heapUsedBefore`/`heapUsedAfter`: in-process heap around the timing
654
+ /**
655
+ * `heapUsedBefore`/`heapUsedAfter`: in-process heap around the timing
625
656
  * run; `retained`: `--alloc`; `peak`: `--peak-mem`; `maxRss`: subprocess
626
657
  * timing. */
627
658
  reading: "heapUsedBefore" | "heapUsedAfter" | "retained" | "peak" | "maxRss";
@@ -629,126 +660,88 @@ interface MemoryDelta {
629
660
  candBytes: number;
630
661
  deltaPct: number;
631
662
  }
632
-
633
- export interface PrepareRun {
634
- phase: "warmup" | "timing" | "cpu" | "heap";
635
- index: number;
636
- }
637
-
638
- export type PrepareFn = (run: PrepareRun) => unknown;
639
-
640
- export type PrepareHook = string | string[] | PrepareFn;
641
-
642
- export type TimeUnit = "ns" | "us" | "ms" | "s";
643
-
644
- export interface TimeSource {
645
- pattern: string | RegExp;
646
- group?: number;
647
- unit?: TimeUnit;
648
- }
649
-
650
- export type AbProgress = {
651
- phase: "setup";
652
- command: string;
653
- } | {
654
- phase: "measure";
655
- suite: number;
656
- suites: number;
657
- file: string;
658
- /** Each suite runs twice, once with each side first. */
659
- pass: number;
660
- passes: number;
661
- task: number;
662
- tasks: number;
663
- label: string;
664
- } | {
665
- phase: "confirm";
666
- repeat: number;
667
- repeats: number;
668
- label: string;
669
- } | {
670
- phase: "memory";
671
- run: number;
672
- runs: number;
673
- side: Side;
674
- label: string;
675
- };
676
-
677
- export interface AbOptions {
678
- suites: string[];
679
- /** Git ref whose committed tree is the base side (default: `"HEAD"`); the
680
- * candidate is the working tree, uncommitted changes included. */
681
- base?: string;
682
- /** Rounds per workload, each one base batch and one candidate batch of
683
- * about 10ms (default: 15). */
684
- rounds?: number;
685
- /** Flag a workload whose median candidate/base ratio moves past this many
686
- * percent (default: 10). */
687
- thresholdPct?: number;
688
- /** Fail when the geometric mean of all workloads' ratios is slower than
689
- * this many percent (default: 1.5): a broad slowdown too small to flag any
690
- * one workload. */
691
- geomeanThresholdPct?: number;
692
- /** Fresh-process repeats of each flagged workload, which only counts when
693
- * every repeat flags it the same way (default: 2; 0 trusts the first). */
694
- confirm?: number;
695
- filter?: string;
696
- preload?: string[];
697
- bunFlags?: string[];
698
- outDir?: string;
699
- cwd?: string;
700
- noiseCheck?: boolean;
701
- /** Also compare each side's retained heap per call (see
702
- * `bench({ alloc })`) and how far its first call raises RSS (see
703
- * `bench({ peakMem })`), each the median of 3 fresh processes per side.
704
- * Task/group options override these. */
705
- alloc?: boolean;
706
- peakMem?: boolean;
707
- /** Flag a memory reading that moves past this many percent of the base's
708
- * and past its noise floor (default: 10). A memory regression fails the
709
- * run. */
710
- memThresholdPct?: number;
711
- /** Shell commands run once, in order, in a freshly extracted base tree
712
- * before it's used: to build what the suites import but git doesn't hold
713
- * (generated or gitignored files). Each runs with its cwd at the tree's
714
- * counterpart of `cwd`, the project's `node_modules` linked in, and
715
- * `OSTIA_AB_SHA` / `OSTIA_AB_CANDIDATE_DIR` (the working tree's `cwd`) in
716
- * its environment. The tree is cached per commit and command list. */
717
- baseSetup?: string | string[];
718
- /** Base trees to keep under `<outDir>/ab`, counting this run's: after a
719
- * run, older ones go, least recently used first, unless one was used in
720
- * the last hour (another run may still need it). Default: 5. */
721
- keepTrees?: number;
722
- /** SIGKILLs a runner process (one suite file or repeat), or a `baseSetup`
723
- * command, after this many ms. */
724
- timeoutMs?: number;
725
- /** Aborting kills the running process and resolves with the suites that
726
- * had finished, plus an `aborted` warning; unrun repeats leave their
727
- * workloads unconfirmed. */
728
- signal?: AbortSignal;
729
- /** Called as each setup command, task, confirmation repeat and memory
730
- * process starts. */
731
- onProgress?: (progress: AbProgress) => void;
732
- }
733
-
734
- export declare class AbBaseError extends OstiaUsageError {
663
+ interface Environment {
664
+ cpuModel: string;
665
+ cores: number;
666
+ loadAvg1: number;
667
+ loadAvg5: number;
668
+ noise: NoiseFloor;
735
669
  }
736
-
737
- export declare class AbSuiteError extends Error {
738
- readonly side: Side;
739
- constructor(message: string, side: Side);
670
+ interface NoiseFloor {
671
+ /**
672
+ * `mad / median` of a reference workload, percent: how noisy the machine
673
+ * is right now, independent of what's measured. */
674
+ floorPct: number;
675
+ referenceMedianNs: number;
676
+ samples: number;
677
+ /**
678
+ * How much slower (positive) the reference ran at the end of the run than
679
+ * at the start, percent: the machine's drift over the run. Absent when the
680
+ * run didn't re-measure it (`profile()`, older documents). */
681
+ driftPct?: number;
740
682
  }
741
-
742
- export declare class AbSetupError extends Error {
683
+ /** Run-level result of `ab()`, stamped on the document as `ab`. */
684
+ interface AbSummary {
685
+ base: {
686
+ ref: string;
687
+ sha: string;
688
+ };
689
+ /**
690
+ * Suite files, as given, that don't exist at the base ref: their tasks
691
+ * are all candidate-only. */
692
+ newSuites?: string[];
693
+ rounds: number;
694
+ /**
695
+ * What verdicts, confirmation and `geomeanPct` judge: each round's time
696
+ * ratio, or its instruction ratio (`PairedEvidence.instructions`). */
697
+ metric: "time" | "instructions";
698
+ thresholdPct: number;
699
+ geomeanThresholdPct: number;
700
+ /** Workloads measured on both sides. */
701
+ matched: number;
702
+ /** Confirmed verdicts. */
703
+ regressed: number;
704
+ improved: number;
705
+ unchanged: number;
706
+ /**
707
+ * Flagged in-process, but a fresh-process repeat disagreed; counted in
708
+ * `unchanged`. */
709
+ unconfirmed: number;
710
+ /** Workloads whose first call returned different values on each side. */
711
+ outputDiffers: number;
712
+ /**
713
+ * Workloads whose suite file and output both changed (see
714
+ * `PairedEvidence.suiteChanged`); counted in `unchanged`, left out of
715
+ * `geomeanPct`. */
716
+ notComparable: number;
717
+ /**
718
+ * Workloads that threw on either side or both, and so weren't timed;
719
+ * not counted in `matched`. */
720
+ threw: number;
721
+ /**
722
+ * Present when any task had a memory reading (`--alloc`, `--peak-mem`):
723
+ * how many tasks' memory regressed or improved, on either reading. */
724
+ memory?: {
725
+ thresholdPct: number;
726
+ regressed: number;
727
+ improved: number;
728
+ };
729
+ /**
730
+ * Geometric mean of the workloads' median `metric` ratios, signed
731
+ * percent (negative: candidate faster); a flagged workload contributes its
732
+ * median over its main run and repeats. `null` when nothing was paired. */
733
+ geomeanPct: number | null;
734
+ /**
735
+ * `"fail"` when any workload regressed (confirmed), threw on the
736
+ * candidate side only, or `geomeanPct` exceeds `geomeanThresholdPct`, or
737
+ * any task's memory regressed. */
738
+ verdict: "pass" | "fail";
743
739
  }
744
-
745
- export declare function ab(opts: AbOptions): Promise<ProfileDocument>;
746
-
747
- declare class OstiaUsageError extends Error {
740
+ interface GitMetadata {
741
+ sha: string;
742
+ branch: string;
743
+ dirty: boolean;
748
744
  }
749
-
750
- type Side = "base" | "cand";
751
-
752
745
  export interface BenchOptions {
753
746
  suites: string[];
754
747
  /** Wall-clock sampling budget per task, ms (default 500). */
@@ -757,178 +750,224 @@ export interface BenchOptions {
757
750
  samples?: number;
758
751
  minSamples?: number;
759
752
  gc?: boolean;
760
- /** Capture one extra `phase: "cpu"` measurement per task (the task looped
753
+ /**
754
+ * Capture one extra `phase: "cpu"` measurement per task (the task looped
761
755
  * under the JSC sampling profiler for ~2,000 samples, JIT tiers included),
762
756
  * never mixed into the timing numbers. Task/group `cpu` overrides this. */
763
757
  cpu?: boolean;
764
- /** `cpu`'s sampling interval, µs (default: 100). A coarser interval
758
+ /**
759
+ * `cpu`'s sampling interval, µs (default: 100). A coarser interval
765
760
  * lengthens the capture to keep the sample count, up to 10s per task. */
766
761
  cpuIntervalUs?: number;
767
- /** Capture one extra `phase: "memstats"` measurement per task: retained
762
+ /**
763
+ * Capture one extra `phase: "memstats"` measurement per task: retained
768
764
  * heap growth per call, from a batch with `Bun.gc(true)` on both sides.
769
765
  * What the calls keep alive, not what they allocate. Task/group `alloc`
770
766
  * overrides this. */
771
767
  alloc?: boolean;
772
- /** Capture one extra `phase: "memstats"` measurement per task: how far the
768
+ /**
769
+ * Capture one extra `phase: "memstats"` measurement per task: how far the
773
770
  * task's first call raises RSS, garbage included. Median of 3 fresh
774
771
  * processes, each run with `OSTIA_PEAK_MEM=1` in its environment (see
775
772
  * `measurePeakMem`). Task/group `peakMem` overrides this. */
776
773
  peakMem?: boolean;
777
774
  filter?: string;
778
- /** Suite files (or isolated tasks) to run at once, each in its own child
775
+ /**
776
+ * Suite files (or isolated tasks) to run at once, each in its own child
779
777
  * process (default: 1). Concurrent CPU-bound processes contend for cores,
780
778
  * caches and turbo headroom, so timings under `jobs > 1` are noisier and
781
779
  * not like-for-like with a baseline measured at 1. */
782
780
  jobs?: number;
783
781
  outDir?: string;
784
782
  cwd?: string;
785
- /** Give every task its own subprocess instead of sharing its suite file's,
783
+ /**
784
+ * Give every task its own subprocess instead of sharing its suite file's,
786
785
  * isolating JIT tier state, inline caches and heap shape between tasks.
787
786
  * Task/group `isolate` overrides this. Multiplies spawn overhead by task
788
787
  * count instead of file count. */
789
788
  isolate?: boolean;
790
- /** Scripts run, in order, before each suite file loads, in the same
789
+ /**
790
+ * Scripts run, in order, before each suite file loads, in the same
791
791
  * subprocess: install globals (jsdom) or a `Bun.plugin()` loader ahead of
792
792
  * the suite's top-level code. */
793
793
  preload?: string[];
794
- /** Extra flags for the `bun` invocation that runs each suite file (e.g.
794
+ /**
795
+ * Extra flags for the `bun` invocation that runs each suite file (e.g.
795
796
  * `["--conditions", "browser"]`), placed before the runner script path. */
796
797
  bunFlags?: string[];
797
- /** Measure this machine's noise floor once, before any suite runs
798
+ /**
799
+ * Per-suite `preload` / `bunFlags`: the first project whose `suites` globs
800
+ * match a suite file (by its path relative to `cwd`) replaces those two
801
+ * fields for that file, so suites that need no setup don't pay for the
802
+ * others'. A field a project leaves unset keeps the top-level value above;
803
+ * `[]` clears it. */
804
+ projects?: BenchProject[];
805
+ /**
806
+ * Measure this machine's noise floor once, before any suite runs
798
807
  * (default: true), and stamp it on the document as `environment`. */
799
808
  noiseCheck?: boolean;
800
- /** SIGKILLs a suite file's subprocess (or, under `isolate`, one task's) that
801
- * hasn't finished after this many ms. No default. */
809
+ /**
810
+ * SIGKILLs a suite file's subprocess (or, under `isolate`, one task's)
811
+ * that hasn't finished after this many ms. No default. */
802
812
  timeoutMs?: number;
803
- /** Aborting kills in-flight subprocesses, starts no new ones, and resolves
813
+ /**
814
+ * Aborting kills in-flight subprocesses, starts no new ones, and resolves
804
815
  * (never rejects) with whatever suites/tasks had finished, plus an
805
816
  * `aborted` warning on the last measurement. A suite killed mid-run is
806
817
  * dropped entirely: it only writes its result once, at the end. */
807
818
  signal?: AbortSignal;
808
819
  }
809
-
810
820
  export declare function bench(opts: BenchOptions): Promise<ProfileDocument>;
811
-
821
+ /**
822
+ * Geometric sweep points from `start` to `end`, growing by `multiplier`
823
+ * each step and always ending on `end` even if the last step overshot it.
824
+ * Mirrors mitata's `.range(name, start, end, multiplier)` point generation
825
+ * exactly, minus the name templating - build the task name yourself in the
826
+ * loop:
827
+ *
828
+ * for (const size of range(100, 10_000)) {
829
+ * const input = buildInput(size)
830
+ * task(`${size} items`, () => parse(input))
831
+ * }
832
+ *
833
+ * range(100, 10_000) -> [100, 800, 6400, 10000]
834
+ * range(100, 100_000) -> [100, 800, 6400, 51200, 100000]
835
+ */
812
836
  export declare function range(start: number, end: number, multiplier?: number): number[];
813
-
837
+ export interface GroupOptions {
838
+ /**
839
+ * What this group measures and why. Flows into `Workload.groupDescription`
840
+ * on every task in the group. */
841
+ description?: string;
842
+ /**
843
+ * Default `isolate` for every task in this group, unless a task overrides
844
+ * it with its own `TaskOptions.isolate`. */
845
+ isolate?: boolean;
846
+ /**
847
+ * Default `gc` for every task in this group, unless a task overrides it
848
+ * with its own `TaskOptions.gc`. */
849
+ gc?: boolean;
850
+ /**
851
+ * Default `cpu` for every task in this group, unless a task overrides it
852
+ * with its own `TaskOptions.cpu`. */
853
+ cpu?: boolean;
854
+ /**
855
+ * Default `alloc` for every task in this group, unless a task overrides
856
+ * it with its own `TaskOptions.alloc`. */
857
+ alloc?: boolean;
858
+ /**
859
+ * Default `peakMem` for every task in this group, unless a task
860
+ * overrides it with its own `TaskOptions.peakMem`. */
861
+ peakMem?: boolean;
862
+ /**
863
+ * Runs once, unmeasured, before the group's first task's warmup (not
864
+ * before every task) - in whichever process runs that task, so it works
865
+ * with `isolate`. */
866
+ before?: Hook;
867
+ /** Runs once, unmeasured, after the group's last task's last trial. */
868
+ after?: Hook;
869
+ }
814
870
  type Hook = () => unknown | Promise<unknown>;
815
-
816
871
  export interface TaskOptions {
817
- /** Marks this task as the Relative reference for its group in the table
872
+ /**
873
+ * Marks this task as the Relative reference for its group in the table
818
874
  * renderer, mirroring mitata's `baseline()`. At most one per group. */
819
875
  baseline?: boolean;
820
876
  /** Per-task time budget; overrides the suite-wide `--budget` / `budgetMs`. */
821
877
  budgetMs?: number;
822
- /** Per-task exact trial count; overrides the suite-wide `--samples` /
878
+ /**
879
+ * Per-task exact trial count; overrides the suite-wide `--samples` /
823
880
  * `samples`. When set, the budget is ignored for this task. */
824
881
  samples?: number;
825
- /** Per-task hard floor on trials; overrides the suite-wide `--min-samples` /
826
- * `minSamples`. */
882
+ /**
883
+ * Per-task hard floor on trials; overrides the suite-wide `--min-samples`
884
+ * / `minSamples`. */
827
885
  minSamples?: number;
828
- /** Former names of this task in the same group, so `compare` and `ab`
886
+ /**
887
+ * Former names of this task in the same group, so `compare` and `ab`
829
888
  * match a base measured before a rename instead of reporting the old name
830
889
  * as removed and the new one as new. */
831
890
  aliases?: string[];
832
- /** What this task measures and why. Flows into `Workload.description` so the
833
- * intent travels with the numbers instead of living only in a source comment. */
891
+ /**
892
+ * What this task measures and why. Flows into `Workload.description` so
893
+ * the intent travels with the numbers instead of living only in a source
894
+ * comment. */
834
895
  description?: string;
835
- /** Give this task its own subprocess instead of sharing its suite file's,
896
+ /**
897
+ * Give this task its own subprocess instead of sharing its suite file's,
836
898
  * isolating its JIT tier state and heap shape from every other task in the
837
899
  * run. Overrides the group's and the suite-wide `bench({ isolate })` /
838
900
  * `--isolate` default for this task only. */
839
901
  isolate?: boolean;
840
- /** Overrides the suite-wide `bench({ gc })` / `--gc` (and any
902
+ /**
903
+ * Overrides the suite-wide `bench({ gc })` / `--gc` (and any
841
904
  * `GroupOptions.gc`) for this task only. */
842
905
  gc?: boolean;
843
- /** Overrides the suite-wide `bench({ cpu })` / `--cpu` (and any
906
+ /**
907
+ * Overrides the suite-wide `bench({ cpu })` / `--cpu` (and any
844
908
  * `GroupOptions.cpu`) for this task only: after the timing measurement,
845
909
  * capture one extra `phase: "cpu"` measurement (JIT tiers included) on
846
910
  * the same workload, never mixed into the timing numbers. */
847
911
  cpu?: boolean;
848
- /** Overrides the suite-wide `bench({ alloc })` / `--alloc` (and any
912
+ /**
913
+ * Overrides the suite-wide `bench({ alloc })` / `--alloc` (and any
849
914
  * `GroupOptions.alloc`) for this task only: after the timing measurement,
850
915
  * capture one extra `phase: "memstats"` measurement of the heap each call
851
916
  * retains (what survives a full GC, not what it allocates). */
852
917
  alloc?: boolean;
853
- /** Overrides the suite-wide `bench({ peakMem })` / `--peak-mem` (and any
918
+ /**
919
+ * Overrides the suite-wide `bench({ peakMem })` / `--peak-mem` (and any
854
920
  * `GroupOptions.peakMem`) for this task only: capture one extra
855
921
  * `phase: "memstats"` measurement of how far one call raises the
856
922
  * process's peak RSS, in fresh processes. */
857
923
  peakMem?: boolean;
858
- /** Structured parameters this task represents (e.g. `{ size: 800, impl:
924
+ /**
925
+ * Structured parameters this task represents (e.g. `{ size: 800, impl:
859
926
  * "fast" }`), written to `Workload.params` and folded into the workload id
860
927
  * so points with the same task name don't collide. Inside `sweep()`, the
861
928
  * current point is inherited automatically; an explicit `params` here
862
929
  * merges over it (explicit keys win). */
863
930
  params?: Record<string, string | number | boolean>;
864
- /** Runs once, unmeasured, immediately before this task's warmup - in the
931
+ /**
932
+ * Runs once, unmeasured, immediately before this task's warmup - in the
865
933
  * task's own process, so it works with `isolate`. No per-trial hook: that
866
934
  * would defeat batching. Use `gc` (Bun.gc between trials) or `isolate`
867
935
  * (a fresh process per task) for per-trial concerns instead. */
868
936
  before?: Hook;
869
- /** Runs once, unmeasured, immediately after this task's last trial. Same
937
+ /**
938
+ * Runs once, unmeasured, immediately after this task's last trial. Same
870
939
  * process/no-per-trial caveats as `before`. */
871
940
  after?: Hook;
872
941
  }
873
-
874
- export interface GroupOptions {
875
- /** What this group measures and why. Flows into `Workload.groupDescription`
876
- * on every task in the group. */
877
- description?: string;
878
- /** Default `isolate` for every task in this group, unless a task overrides
879
- * it with its own `TaskOptions.isolate`. */
880
- isolate?: boolean;
881
- /** Default `gc` for every task in this group, unless a task overrides it
882
- * with its own `TaskOptions.gc`. */
883
- gc?: boolean;
884
- /** Default `cpu` for every task in this group, unless a task overrides it
885
- * with its own `TaskOptions.cpu`. */
886
- cpu?: boolean;
887
- /** Default `alloc` for every task in this group, unless a task overrides
888
- * it with its own `TaskOptions.alloc`. */
889
- alloc?: boolean;
890
- /** Default `peakMem` for every task in this group, unless a task
891
- * overrides it with its own `TaskOptions.peakMem`. */
892
- peakMem?: boolean;
893
- /** Runs once, unmeasured, before the group's first task's warmup (not
894
- * before every task) - in whichever process runs that task, so it works
895
- * with `isolate`. */
896
- before?: Hook;
897
- /** Runs once, unmeasured, after the group's last task's last trial. */
898
- after?: Hook;
899
- }
900
-
901
- type GroupRegistrar = (name: string, fn: () => void, opts?: GroupOptions) => void;
902
-
942
+ export declare const group: GroupFn;
903
943
  interface GroupFn extends GroupRegistrar {
904
- /** Registers every task inside as skipped: the runner never measures
944
+ /**
945
+ * Registers every task inside as skipped: the runner never measures
905
946
  * them, but the document still carries their workloads (marked
906
947
  * `Workload.skipped`). */
907
948
  skip: GroupRegistrar;
908
- /** When any task or group in the suite uses `.only`, the runner restricts
949
+ /**
950
+ * When any task or group in the suite uses `.only`, the runner restricts
909
951
  * the whole suite file to only those tasks (before `--filter` narrows
910
952
  * further) and prints a one-line notice to stderr. */
911
953
  only: GroupRegistrar;
912
954
  }
913
-
914
- export declare const group: GroupFn;
915
-
916
- type TaskRegistrar = (name: string, fn: () => unknown | Promise<unknown>, opts?: TaskOptions) => void;
917
-
955
+ type GroupRegistrar = (name: string, fn: () => void, opts?: GroupOptions) => void;
956
+ export declare const task: TaskFn;
918
957
  interface TaskFn extends TaskRegistrar {
919
- /** Registers the task as skipped: the runner never measures it, but the
958
+ /**
959
+ * Registers the task as skipped: the runner never measures it, but the
920
960
  * document still carries its workload (marked `Workload.skipped`) so a
921
961
  * renderer or `compare` can say so explicitly instead of the task simply
922
962
  * being absent. */
923
963
  skip: TaskRegistrar;
924
- /** When any task or group in the suite uses `.only`, the runner restricts
964
+ /**
965
+ * When any task or group in the suite uses `.only`, the runner restricts
925
966
  * the whole suite file to only those tasks (before `--filter` narrows
926
967
  * further) and prints a one-line notice to stderr. */
927
968
  only: TaskRegistrar;
928
969
  }
929
-
930
- export declare const task: TaskFn;
931
-
970
+ type TaskRegistrar = (name: string, fn: () => unknown | Promise<unknown>, opts?: TaskOptions) => void;
932
971
  export interface RunOptions extends MeasureTasksOpts {
933
972
  /** Regex matched against "group/name" task ids, as in `bench({ filter })`. */
934
973
  filter?: string;
@@ -937,45 +976,24 @@ export interface RunOptions extends MeasureTasksOpts {
937
976
  /** Renderer used for the printed report (default: `"table"`). */
938
977
  format?: FormatName;
939
978
  }
940
-
941
- export declare function run(opts?: RunOptions): Promise<ProfileDocument>;
942
-
943
- type FormatName = "table" | "json" | "markdown" | "jsonl" | "minimal" | "collapsed" | "mermaid" | "speedscope" | "cpuprofile";
944
-
945
- export interface VizOptions {
946
- /** Render this measurement only, instead of every CPU measurement. */
947
- measurementId?: string;
948
- }
949
-
950
- interface RenderResult {
951
- text?: string;
952
- files?: {
953
- path?: string;
954
- content: string;
955
- }[];
956
- }
957
-
958
- interface Renderer<O = unknown> {
959
- name: FormatName;
960
- render(doc: ProfileDocument, options: O): Promise<RenderResult>;
961
- }
962
-
963
979
  interface MeasureTasksOpts extends InprocessTimingOptions {
964
- /** Suite-wide default for capturing an extra `phase: "cpu"` measurement per
980
+ /**
981
+ * Suite-wide default for capturing an extra `phase: "cpu"` measurement per
965
982
  * task (task/group `cpu` still wins). */
966
983
  cpu?: boolean;
967
984
  /** `cpu`'s sampling interval, µs (default: 100). */
968
985
  cpuIntervalUs?: number;
969
- /** Suite-wide default for capturing an extra `phase: "memstats"`
986
+ /**
987
+ * Suite-wide default for capturing an extra `phase: "memstats"`
970
988
  * measurement per task (task/group `alloc` still wins). */
971
989
  alloc?: boolean;
972
990
  /** Stamped onto every workload: it ran in a subprocess dedicated to it. */
973
991
  markIsolated?: boolean;
974
- /** Measure this machine's noise floor before the first task (default:
992
+ /**
993
+ * Measure this machine's noise floor before the first task (default:
975
994
  * true) and stamp it on the document as `environment`. */
976
995
  noiseCheck?: boolean;
977
996
  }
978
-
979
997
  interface InprocessTimingOptions {
980
998
  /** Wall-clock budget for the sampling loop, per task (default: 500). */
981
999
  budgetMs?: number;
@@ -985,61 +1003,273 @@ interface InprocessTimingOptions {
985
1003
  * the floor is cost-aware (see `defaultSampleFloor`). */
986
1004
  minSamples?: number;
987
1005
  /** Warmup budget as a fraction of `budgetMs` (default: 0.1); unlike
988
- * `time()`'s `warmup`, which is a trial count. Always runs at least one call. */
1006
+ * `time()`'s `warmup`, which is a trial count. Always runs at least one
1007
+ * call. */
989
1008
  warmup?: number;
990
1009
  gc?: boolean;
991
1010
  }
992
-
993
- export declare function keep(value: unknown): void;
994
-
1011
+ type FormatName = "table" | "json" | "markdown" | "jsonl" | "minimal" | "collapsed" | "mermaid" | "speedscope" | "cpuprofile";
1012
+ /** In-file entrypoint: call at the bottom of a suite file run directly with
1013
+ * `bun suite.ts` to measure every registered `group()`/`task()`, print a
1014
+ * report, and return the document.
1015
+ *
1016
+ * Everything runs in the current process, so `TaskOptions.isolate` is
1017
+ * ignored. Prefer `ostia bench`/`bench()` for numbers you'll
1018
+ * `compare`/`ci` against. */
1019
+ export declare function run(opts?: RunOptions): Promise<ProfileDocument>;
1020
+ /** Cartesian product over `dims`, calling `fn` once per point. Inside `fn`,
1021
+ * `task()` calls automatically inherit the point as their params (an
1022
+ * explicit `TaskOptions.params` merges over it, explicit keys win):
1023
+ *
1024
+ * group("parse", () => {
1025
+ * sweep({ size: range(100, 10_000), impl: ["current", "fast"] }, ({ size, impl }) => {
1026
+ * const input = build(size)
1027
+ * task(`${impl}`, () => impls[impl](input))
1028
+ * })
1029
+ * })
1030
+ */
1031
+ export declare function sweep<T extends Record<string, readonly unknown[]>>(dims: T, fn: (point: SweepPoint<T>) => void): void;
995
1032
  type SweepPoint<T extends Record<string, readonly unknown[]>> = {
996
1033
  [K in keyof T]: T[K][number];
997
1034
  };
998
-
999
- export declare function sweep<T extends Record<string, readonly unknown[]>>(dims: T, fn: (point: SweepPoint<T>) => void): void;
1000
-
1001
- export declare function createDocument(workloads: Workload[], measurements: Measurement[], environment?: Environment): ProfileDocument;
1002
-
1003
- export declare function saveDocument(doc: ProfileDocument, path: string): Promise<void>;
1004
-
1005
- export declare class OstiaDocumentError extends Error {
1006
- readonly code: "invalid-json" | "not-a-document" | "unsupported-schema";
1007
- readonly path?: string;
1008
- readonly schemaVersion?: unknown;
1009
- constructor(code: OstiaDocumentError["code"], message: string, opts?: {
1010
- path?: string;
1011
- schemaVersion?: unknown;
1012
- });
1035
+ export interface CompareResult {
1036
+ comparisons: Comparison[];
1037
+ unmatched: {
1038
+ baseOnly: Workload[];
1039
+ candOnly: Workload[];
1040
+ };
1041
+ /** Every task on either side; see `ProfileDocument.compared`. */
1042
+ compared: ComparedTask[];
1043
+ summary: ComparisonSummary;
1013
1044
  }
1014
-
1015
- export declare function loadDocument(path: string): Promise<ProfileDocument>;
1016
-
1017
- export interface ProfileOptions {
1018
- /** Sampling interval in µs; default 1000. Named like `time()`'s and
1019
- * `bench()`'s option, the config key and `--cpu-interval`. */
1045
+ export interface Thresholds {
1046
+ timingPct: number;
1047
+ frameSelfPct: number;
1048
+ heapTypePct: number;
1049
+ minFrameSelfUs: number;
1050
+ /**
1051
+ * A `regressed` / `improved` verdict also requires Mann-Whitney `pValue <
1052
+ * alpha`.
1053
+ */
1054
+ alpha: number;
1055
+ /** Bootstrap resample rounds for the timing CI. */
1056
+ bootstrapIterations: number;
1057
+ }
1058
+ /**
1059
+ * Compares every `cand.workloads` entry that has a match in `base` (in
1060
+ * candidate order, as `ostia ci` does), and reports what matched only one
1061
+ * side in `unmatched` rather than dropping it. */
1062
+ export declare function compareDocuments(base: ProfileDocument, cand: ProfileDocument, thresholds?: Thresholds): CompareResult;
1063
+ export declare const DEFAULT_THRESHOLDS: Thresholds;
1064
+ /**
1065
+ * Settings for `ostia ab` only; it reads the rest (suites, filter,
1066
+ * preload, ...) from `bench`. */
1067
+ export interface AbConfig {
1068
+ /**
1069
+ * Shell command(s) run once in a freshly extracted base tree, e.g. to
1070
+ * build gitignored files the suites import; see `AbOptions.baseSetup`.
1071
+ * `--base-setup` replaces this list. */
1072
+ setup?: string | string[];
1073
+ /**
1074
+ * Base trees to keep cached; see `AbOptions.keepTrees`. `--keep-trees`
1075
+ * overrides. Default: 5. */
1076
+ keepTrees?: number;
1077
+ /**
1078
+ * Judge rounds by `"time"` or `"instructions"`; see `AbOptions.metric`.
1079
+ * `--metric` overrides. Default: `"time"`. */
1080
+ metric?: "time" | "instructions";
1081
+ /**
1082
+ * Compare retained heap per call; see `AbOptions.alloc`. `--alloc` /
1083
+ * `--no-alloc` override. `bench.alloc` doesn't apply to `ab`. */
1084
+ alloc?: boolean;
1085
+ /**
1086
+ * Compare peak RSS of the first call; see `AbOptions.peakMem`.
1087
+ * `--peak-mem` / `--no-peak-mem` override. `bench.peakMem` doesn't apply
1088
+ * to `ab`. */
1089
+ peakMem?: boolean;
1090
+ /**
1091
+ * Memory verdict threshold, percent; see `AbOptions.memThresholdPct`.
1092
+ * `--mem-threshold` overrides. Default: 10. */
1093
+ memThresholdPct?: number;
1094
+ }
1095
+ export interface OstiaConfig {
1096
+ /** `command` workloads: exact trial count; see `time()`. */
1097
+ samples?: number;
1098
+ /** `command` workloads: sampling budget in ms; see `time()`. */
1099
+ budgetMs?: number;
1100
+ /** `command` workloads: floor on trials; see `time()`. */
1101
+ minSamples?: number;
1102
+ warmup: number;
1103
+ outDir: string;
1104
+ baselineDir: string;
1105
+ baseline: string;
1106
+ thresholds: Thresholds;
1107
+ workloads: WorkloadConfig[];
1108
+ bench?: BenchConfig;
1109
+ ab?: AbConfig;
1110
+ /**
1111
+ * `ostia ci`'s policy for a workload with no matching baseline row (by
1112
+ * workload id): `"fail"` exits 2 naming the baseline file, `"warn"` lists
1113
+ * it in the report. Unset: `"fail"` when every workload is missing (a
1114
+ * stale or wrong baseline), `"warn"` otherwise. */
1115
+ onMissingBaseline?: "warn" | "fail";
1116
+ /**
1117
+ * Measure the machine's noise floor once per `ostia ci` run (default
1118
+ * true) and stamp it on the candidate document, so `compare` widens its
1119
+ * thresholds accordingly. `--no-noise-check` overrides this per run. */
1120
+ noiseCheck?: boolean;
1121
+ }
1122
+ /**
1123
+ * Exactly one of `command` (a subprocess to time) / `suites` (in-process
1124
+ * `group()`/`task()` suite file globs, run via `bench()`, each task gated
1125
+ * individually) must be given. */
1126
+ export interface WorkloadConfig {
1127
+ label?: string;
1128
+ command?: string[];
1129
+ suites?: string[];
1130
+ /**
1131
+ * `command` only. Globs of the files the timing depends on: `ostia ci`
1132
+ * reuses a cached run while their contents are unchanged. Omitted, the
1133
+ * workload always reruns; `[]` caches until the command or config changes.
1134
+ * */
1135
+ inputs?: string[];
1136
+ /**
1137
+ * `command` only. Runs before every trial (warmup included), unmeasured:
1138
+ * a command string / argv array, or in `ostia.config.ts` a function. A
1139
+ * function makes the workload uncacheable for `ostia ci`. */
1140
+ prepare?: PrepareHook;
1141
+ /**
1142
+ * `command` only. Take timing from a number in the command's own output
1143
+ * instead of its wall clock; see `TimeSource`. */
1144
+ timeSource?: TimeSource;
1145
+ /**
1146
+ * `command`: kills a trial (or prepare hook) after this many ms.
1147
+ * `suites`: kills a suite file's (or isolated task's) process after this
1148
+ * many ms, overriding `bench.timeoutMs`. Overrides `ostia ci`'s 10-minute
1149
+ * default. */
1150
+ timeoutMs?: number;
1151
+ /**
1152
+ * `command` only. Exit codes to treat as success; see
1153
+ * `TimeOptions.ignoreExitCodes`. */
1154
+ ignoreExitCodes?: number[];
1155
+ }
1156
+ /**
1157
+ * Runs unmeasured before every trial of a command, in its `cwd`/`env`
1158
+ * (hyperfine's `--prepare`): a shell-less command (string,
1159
+ * whitespace-split, or argv array) that must exit 0 or the run aborts, or
1160
+ * a function. */
1161
+ export type PrepareHook = string | string[] | PrepareFn;
1162
+ /** Return value ignored; a returned promise is awaited. */
1163
+ export type PrepareFn = (run: PrepareRun) => unknown;
1164
+ /**
1165
+ * `index` counts from 0 within each phase, so "first run" logic checks
1166
+ * `phase === "warmup" && index === 0` (or `phase === "timing"` when warmup
1167
+ * is 0). */
1168
+ export interface PrepareRun {
1169
+ phase: "warmup" | "timing" | "cpu" | "heap";
1170
+ index: number;
1171
+ }
1172
+ /**
1173
+ * Take a command's timing from a number in its own stdout/stderr instead
1174
+ * of the wall clock (e.g. a build tool's `built in 342ms` line). `pattern`
1175
+ * is matched against stdout, then stderr; `group` (default 1) holds the
1176
+ * number; `unit` defaults to "ms". A trial that doesn't match contributes
1177
+ * no sample (`time-source-no-match` warning); if every trial misses, the
1178
+ * workload has no timing stats. A `RegExp` pattern must not carry the `g`,
1179
+ * `y`, or `d` flag: it is reused across trials, and `lastIndex` would make
1180
+ * it alternate match/no-match. */
1181
+ export interface TimeSource {
1182
+ pattern: string | RegExp;
1183
+ group?: number;
1184
+ unit?: TimeUnit;
1185
+ }
1186
+ export type TimeUnit = "ns" | "us" | "ms" | "s";
1187
+ interface BenchConfig {
1188
+ /**
1189
+ * Suite file globs, resolved against the config's directory (e.g.
1190
+ * "bench/**\/*.bench.ts"). Suite files given on the command line replace
1191
+ * this list. */
1192
+ suites?: string[];
1193
+ /**
1194
+ * Per-suite `preload`/`bunFlags`, so one tier (e.g. DOM-dependent suites)
1195
+ * can pay for a setup the others don't need. The first project whose
1196
+ * `suites` match a file wins; a file no project matches gets the top-level
1197
+ * `preload`/`bunFlags`. `--preload` / `--bun-flags` replace the matching
1198
+ * field for every file. */
1199
+ projects?: BenchProject[];
1200
+ preload?: string[];
1201
+ /**
1202
+ * Extra flags for the `bun` process that runs each suite file; see
1203
+ * `BenchOptions.bunFlags`. `--bun-flags` replaces this list. */
1204
+ bunFlags?: string[];
1205
+ jobs?: number | "auto";
1206
+ budgetMs?: number;
1207
+ samples?: number;
1208
+ minSamples?: number;
1209
+ gc?: boolean;
1210
+ cpu?: boolean;
1211
+ cpuIntervalUs?: number;
1212
+ alloc?: boolean;
1213
+ peakMem?: boolean;
1214
+ filter?: string;
1215
+ isolate?: boolean;
1216
+ outDir?: string;
1217
+ /**
1218
+ * Kills a suite file's (or isolated task's) subprocess after this many
1219
+ * ms; overrides `ostia ci`'s 10-minute default. */
1220
+ timeoutMs?: number;
1221
+ }
1222
+ export type OstiaConfigInput = Omit<Partial<OstiaConfig>, "thresholds"> & {
1223
+ thresholds?: Partial<Thresholds>;
1224
+ };
1225
+ export declare function createDocument(workloads: Workload[], measurements: Measurement[], environment?: Environment): ProfileDocument;
1226
+ export declare function loadDocument(path: string): Promise<ProfileDocument>;
1227
+ export declare class OstiaDocumentError extends Error {
1228
+ readonly code: "invalid-json" | "not-a-document" | "unsupported-schema";
1229
+ readonly path?: string;
1230
+ readonly schemaVersion?: unknown;
1231
+ constructor(code: OstiaDocumentError["code"], message: string, opts?: {
1232
+ path?: string;
1233
+ schemaVersion?: unknown;
1234
+ });
1235
+ }
1236
+ export declare function saveDocument(doc: ProfileDocument, path: string): Promise<void>;
1237
+ /** Pins `value` against dead-code elimination for an intermediate inside a
1238
+ * task body. A task's own return value is already pinned by the timing
1239
+ * loop. */
1240
+ export declare function keep(value: unknown): void;
1241
+ export interface ProfileOptions {
1242
+ /**
1243
+ * Sampling interval in µs; default 1000. Named like `time()`'s and
1244
+ * `bench()`'s option, the config key and `--cpu-interval`. */
1020
1245
  cpuIntervalUs?: number;
1021
- /** Names the workload: it becomes the label and, instead of the function's
1246
+ /**
1247
+ * Names the workload: it becomes the label and, instead of the function's
1022
1248
  * name and source, what the id hashes, so closures that differ only in
1023
- * captured values get distinct ids and the id survives editing the function. */
1249
+ * captured values get distinct ids and the id survives editing the
1250
+ * function. */
1024
1251
  name?: string;
1025
- /** `"inspector"` (default) captures through CDP and writes a portable
1026
- * .cpuprofile; `"jsc"` uses `bun:jsc.profile` and adds LLInt/Baseline/DFG/FTL
1027
- * tier data. */
1252
+ /**
1253
+ * `"inspector"` (default) captures through CDP and writes a portable
1254
+ * .cpuprofile; `"jsc"` uses `bun:jsc.profile` and adds
1255
+ * LLInt/Baseline/DFG/FTL tier data. */
1028
1256
  origin?: "inspector" | "jsc";
1029
- /** There's no child to kill, so an already-aborted signal skips the profiler,
1030
- * calls `fn` plain (still returning its `result`) and records an `aborted`
1031
- * warning instead of CPU evidence. It can't interrupt a running `fn`. */
1257
+ /**
1258
+ * There's no child to kill, so an already-aborted signal skips the
1259
+ * profiler, calls `fn` plain (still returning its `result`) and records an
1260
+ * `aborted` warning instead of CPU evidence. It can't interrupt a running
1261
+ * `fn`. */
1032
1262
  signal?: AbortSignal;
1033
1263
  }
1034
-
1035
1264
  export interface ProfileResult<T> {
1036
1265
  result: T;
1037
1266
  measurement: Measurement;
1038
1267
  document: ProfileDocument;
1039
1268
  }
1040
-
1041
1269
  export declare function profile<T>(fn: () => T | Promise<T>, opts?: ProfileOptions): Promise<ProfileResult<T>>;
1042
-
1270
+ /** Each format's renderer, typed with its own options. `Renderer<never>` is
1271
+ * the top type, so `satisfies` checks every format is present without
1272
+ * widening the options. */
1043
1273
  export declare const renderers: {
1044
1274
  table: Renderer<unknown>;
1045
1275
  json: Renderer<unknown>;
@@ -1051,67 +1281,61 @@ export declare const renderers: {
1051
1281
  speedscope: Renderer<VizOptions>;
1052
1282
  cpuprofile: Renderer<VizOptions>;
1053
1283
  };
1054
-
1055
- export declare const MINIMAL_PROTOCOL_VERSION: 2;
1056
-
1057
- interface MinimalWarning {
1058
- code: string;
1059
- data?: Record<string, unknown>;
1284
+ export interface MinimalRenderOptions {
1285
+ protocol?: MinimalProtocolContext;
1060
1286
  }
1061
-
1062
- interface MinimalDelta {
1063
- /** The base's median, ns: the row's own `median` is the candidate's. */
1064
- baseMedian?: number;
1065
- medianPct: number;
1066
- meanPct: number;
1067
- verdict: "improved" | "regressed" | "unchanged";
1068
- pass: boolean;
1069
- /** 95% bootstrap CI on the difference of medians; absent (with `pValue`)
1070
- * on a thin (<5 samples/side) comparison. */
1071
- ci95?: [number, number];
1072
- pValue?: number;
1073
- /** The threshold actually tested against, after machine noise widened it. */
1074
- effectiveTimingPct: number;
1075
- matched: true;
1076
- /** The base task's name, when it was matched through an alias. */
1077
- renamedFrom?: string;
1287
+ /**
1288
+ * What the `unmatched`/`summary` events need beyond one `ProfileDocument`.
1289
+ * The CLI builds it for `compare`/`ci`/`ab`; without it `minimal` emits
1290
+ * only `run` lines. `exitCode` is inline because the CLI decides it after
1291
+ * rendering. */
1292
+ export interface MinimalProtocolContext {
1293
+ command: "compare" | "ci" | "ab";
1294
+ exitCode: number;
1295
+ unmatched?: {
1296
+ baseOnly: Workload[];
1297
+ candOnly: Workload[];
1298
+ };
1299
+ baseGit?: GitMetadata;
1300
+ candGit?: GitMetadata;
1301
+ baseline?: {
1302
+ name: string;
1303
+ path: string;
1304
+ };
1305
+ cached?: number;
1306
+ executed?: number;
1307
+ failed?: number;
1308
+ missingBaseline?: number;
1309
+ exportedTo?: string;
1078
1310
  }
1079
-
1080
- interface MinimalPaired {
1081
- /** Base side's median per-call time, ns. */
1082
- baseMedian: number;
1083
- medianRatio: number;
1084
- ratioP25: number;
1085
- ratioP75: number;
1086
- rounds: number;
1087
- /** `flagged` when fresh processes confirmed it, else `"unchanged"`. */
1088
- verdict: "regressed" | "improved" | "unchanged";
1089
- /** What the first process saw, before confirmation. */
1090
- flagged?: "regressed" | "improved";
1091
- confirmed?: boolean;
1092
- /** Median ratio of each fresh-process repeat. */
1093
- repeats?: number[];
1094
- sameOutput: boolean;
1095
- /** The suite file differs from the base's copy. */
1096
- suiteChanged?: true;
1097
- /** `--alloc`: retained heap per call on each side. */
1098
- retained?: MinimalMemoryChange;
1099
- /** `--peak-mem`: first-call RSS rise on each side. */
1100
- peak?: MinimalMemoryChange;
1311
+ export interface VizOptions {
1312
+ /** Render this measurement only, instead of every CPU measurement. */
1313
+ measurementId?: string;
1101
1314
  }
1102
-
1103
- interface MinimalMemoryChange {
1104
- base: number;
1105
- cand: number;
1106
- verdict: "regressed" | "improved" | "unchanged";
1107
- floor: number;
1315
+ export interface MermaidOptions extends VizOptions {
1316
+ topN?: number;
1108
1317
  }
1109
-
1318
+ interface Renderer<O = unknown> {
1319
+ name: FormatName;
1320
+ render(doc: ProfileDocument, options: O): Promise<RenderResult>;
1321
+ }
1322
+ interface RenderResult {
1323
+ text?: string;
1324
+ files?: {
1325
+ path?: string;
1326
+ content: string;
1327
+ }[];
1328
+ }
1329
+ export type MinimalEvent = MinimalRunLine | MinimalUnmatchedLine | MinimalSummaryLine;
1330
+ /**
1331
+ * One per timing run, for piping into an agent's context in place of the
1332
+ * full `ProfileDocument`. Numbers stay in the IR's units (ns). */
1110
1333
  interface MinimalRunLine {
1111
1334
  event: "run";
1112
1335
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
1113
1336
  schemaVersion: ProfileDocument["schemaVersion"];
1114
- /** Join key to `Workload.id` / `Comparison.candidateMeasurementId`; unlike
1337
+ /**
1338
+ * Join key to `Workload.id` / `Comparison.candidateMeasurementId`; unlike
1115
1339
  * `task`, stable across invocations. */
1116
1340
  workloadId: string;
1117
1341
  task: string;
@@ -1119,10 +1343,14 @@ interface MinimalRunLine {
1119
1343
  description?: string;
1120
1344
  groupDescription?: string;
1121
1345
  params?: Record<string, string | number | boolean>;
1122
- /** `task.skip()` / `group.skip()`: no measurement, so every stats field is absent. */
1346
+ /**
1347
+ * `task.skip()` / `group.skip()`: no measurement, so every stats field is
1348
+ * absent.
1349
+ */
1123
1350
  skipped?: true;
1124
1351
  unit?: "ns";
1125
- /** 0, with every stats field absent, when no trial produced a sample (all
1352
+ /**
1353
+ * 0, with every stats field absent, when no trial produced a sample (all
1126
1354
  * timed out or missed the `timeSource` pattern); see `warnings`. */
1127
1355
  samples?: number;
1128
1356
  /** In-process trials batched into one timed block; 1 when never batched. */
@@ -1144,18 +1372,25 @@ interface MinimalRunLine {
1144
1372
  retainedBytesPerOp?: number;
1145
1373
  /** `--peak-mem`: how far the task's first call raised RSS, bytes. */
1146
1374
  peakBytes?: number;
1147
- /** Median over the group's reference median (its baseline task, else its
1375
+ /**
1376
+ * In-process tasks, where the machine counts them: median instructions
1377
+ * retired per call (`ab`: the candidate's). */
1378
+ instructions?: number;
1379
+ /**
1380
+ * Median over the group's reference median (its baseline task, else its
1148
1381
  * fastest); only when the document has more than one timing run. */
1149
1382
  relative?: number;
1150
1383
  baseline?: true;
1151
- /** The machine's noise floor from `document.environment`; absent when the
1384
+ /**
1385
+ * The machine's noise floor from `document.environment`; absent when the
1152
1386
  * noise check was skipped. */
1153
1387
  noiseFloorPct?: number;
1154
1388
  warnings: MinimalWarning[];
1155
1389
  /** The change against the baseline document (`compare` / `ci`). */
1156
1390
  delta?: MinimalDelta;
1157
1391
  paired?: MinimalPaired;
1158
- /** `ab` only, instead of stats and `paired`: the task threw on one side
1392
+ /**
1393
+ * `ab` only, instead of stats and `paired`: the task threw on one side
1159
1394
  * (`"base"`/`"cand"`) or both, so it isn't judged on time. `message` is
1160
1395
  * the error's first lines; `repeat` (from 1) is set when it threw in a
1161
1396
  * confirmation repeat. */
@@ -1165,7 +1400,75 @@ interface MinimalRunLine {
1165
1400
  repeat?: number;
1166
1401
  };
1167
1402
  }
1168
-
1403
+ /**
1404
+ * Bumped only on a breaking change to the event shapes (a key renamed or
1405
+ * removed); new keys are additive. Every line carries it. */
1406
+ export declare const MINIMAL_PROTOCOL_VERSION: 2;
1407
+ interface MinimalWarning {
1408
+ code: string;
1409
+ data?: Record<string, unknown>;
1410
+ }
1411
+ interface MinimalDelta {
1412
+ /** The base's median, ns: the row's own `median` is the candidate's. */
1413
+ baseMedian?: number;
1414
+ medianPct: number;
1415
+ meanPct: number;
1416
+ verdict: "improved" | "regressed" | "unchanged";
1417
+ pass: boolean;
1418
+ /**
1419
+ * 95% bootstrap CI on the difference of medians; absent (with `pValue`)
1420
+ * on a thin (<5 samples/side) comparison. */
1421
+ ci95?: [number, number];
1422
+ pValue?: number;
1423
+ /** The threshold actually tested against, after machine noise widened it. */
1424
+ effectiveTimingPct: number;
1425
+ matched: true;
1426
+ /** The base task's name, when it was matched through an alias. */
1427
+ renamedFrom?: string;
1428
+ }
1429
+ /**
1430
+ * `ab` only: the base side and per-round candidate/base ratios behind a
1431
+ * `run` line whose stats are the candidate's. Ratios above 1 mean slower.
1432
+ * */
1433
+ interface MinimalPaired {
1434
+ /** Base side's median per-call time, ns. */
1435
+ baseMedian: number;
1436
+ medianRatio: number;
1437
+ ratioP25: number;
1438
+ ratioP75: number;
1439
+ rounds: number;
1440
+ /** `flagged` when fresh processes confirmed it, else `"unchanged"`. */
1441
+ verdict: "regressed" | "improved" | "unchanged";
1442
+ /** What the first process saw, before confirmation. */
1443
+ flagged?: "regressed" | "improved";
1444
+ confirmed?: boolean;
1445
+ /** Median ratio of each fresh-process repeat, by the summary's `metric`. */
1446
+ repeats?: number[];
1447
+ /**
1448
+ * Where the machine counts them: the base's median instructions per call
1449
+ * and the candidate/base instruction ratios. */
1450
+ instructions?: {
1451
+ baseMedian: number;
1452
+ medianRatio: number;
1453
+ ratioP25: number;
1454
+ ratioP75: number;
1455
+ };
1456
+ sameOutput: boolean;
1457
+ /** The suite file differs from the base's copy. */
1458
+ suiteChanged?: true;
1459
+ /** `--alloc`: retained heap per call on each side. */
1460
+ retained?: MinimalMemoryChange;
1461
+ /** `--peak-mem`: first-call RSS rise on each side. */
1462
+ peak?: MinimalMemoryChange;
1463
+ }
1464
+ /** `ab` only: one memory reading on both sides, bytes. */
1465
+ interface MinimalMemoryChange {
1466
+ base: number;
1467
+ cand: number;
1468
+ verdict: "regressed" | "improved" | "unchanged";
1469
+ floor: number;
1470
+ }
1471
+ /** A workload present on only one side of a `compare`/`ci` run. */
1169
1472
  interface MinimalUnmatchedLine {
1170
1473
  event: "unmatched";
1171
1474
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
@@ -1173,7 +1476,9 @@ interface MinimalUnmatchedLine {
1173
1476
  task: string;
1174
1477
  side: "base" | "cand";
1175
1478
  }
1176
-
1479
+ /**
1480
+ * The last line of a `compare`/`ci`/`ab` run; never emitted for a bare
1481
+ * `time`/`bench` document. */
1177
1482
  interface MinimalSummaryLine {
1178
1483
  event: "summary";
1179
1484
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
@@ -1203,16 +1508,27 @@ interface MinimalSummaryLine {
1203
1508
  ref: string;
1204
1509
  sha: string;
1205
1510
  };
1511
+ /**
1512
+ * `ab` only: what the verdicts and `geomeanPct` judge, each round's time
1513
+ * or instruction ratio. */
1514
+ metric?: "time" | "instructions";
1206
1515
  /** `ab` only: the gate on `geomeanPct`. */
1207
1516
  geomeanThresholdPct?: number;
1208
- /** `ab` only: flagged in the first process but not reproduced; counted in `unchanged`. */
1517
+ /**
1518
+ * `ab` only: flagged in the first process but not reproduced; counted in
1519
+ * `unchanged`.
1520
+ */
1209
1521
  unconfirmed?: number;
1210
- /** `ab` only: workloads whose first call returned different values on the two sides. */
1522
+ /**
1523
+ * `ab` only: workloads whose first call returned different values on the
1524
+ * two sides.
1525
+ */
1211
1526
  outputDiffers?: number;
1212
1527
  notComparable?: number;
1213
1528
  threw?: number;
1214
1529
  newSuites?: string[];
1215
- /** `ab` only, with `--alloc` or `--peak-mem`: tasks whose memory
1530
+ /**
1531
+ * `ab` only, with `--alloc` or `--peak-mem`: tasks whose memory
1216
1532
  * regressed or improved, and the threshold, percent. */
1217
1533
  memory?: {
1218
1534
  thresholdPct: number;
@@ -1224,42 +1540,16 @@ interface MinimalSummaryLine {
1224
1540
  cand?: GitMetadata;
1225
1541
  };
1226
1542
  exportedTo?: string;
1227
- /** `pass` (exit 0), `fail` (exit 1: a regression), else `error` (exit 2, or
1543
+ /**
1544
+ * `pass` (exit 0), `fail` (exit 1: a regression), else `error` (exit 2, or
1228
1545
  * 130 when cancelled): no verdict was reached. */
1229
1546
  verdict: "pass" | "fail" | "error";
1230
1547
  exitCode: number;
1231
1548
  }
1232
-
1233
- export type MinimalEvent = MinimalRunLine | MinimalUnmatchedLine | MinimalSummaryLine;
1234
-
1235
- export interface MinimalProtocolContext {
1236
- command: "compare" | "ci" | "ab";
1237
- exitCode: number;
1238
- unmatched?: {
1239
- baseOnly: Workload[];
1240
- candOnly: Workload[];
1241
- };
1242
- baseGit?: GitMetadata;
1243
- candGit?: GitMetadata;
1244
- baseline?: {
1245
- name: string;
1246
- path: string;
1247
- };
1248
- cached?: number;
1249
- executed?: number;
1250
- failed?: number;
1251
- missingBaseline?: number;
1252
- exportedTo?: string;
1253
- }
1254
-
1255
- export interface MinimalRenderOptions {
1256
- protocol?: MinimalProtocolContext;
1257
- }
1258
-
1259
- export interface MermaidOptions extends VizOptions {
1260
- topN?: number;
1261
- }
1262
-
1549
+ /**
1550
+ * One command for `time()`: a string (whitespace-split, no shell), an argv
1551
+ * array, or an object with per-command settings, which is how one command
1552
+ * becomes several labeled workloads (e.g. warm vs cold `prepare`). */
1263
1553
  export interface CommandSpec {
1264
1554
  command: string | string[];
1265
1555
  label?: string;
@@ -1272,25 +1562,29 @@ export interface CommandSpec {
1272
1562
  /** Overrides `TimeOptions.ignoreExitCodes` for this command. */
1273
1563
  ignoreExitCodes?: number[];
1274
1564
  }
1275
-
1276
1565
  export interface TimeOptions {
1277
1566
  commands: (string | string[] | CommandSpec)[];
1278
- /** Runs unmeasured before every trial (warmup and instrumented included), in
1279
- * `cwd`/`env`: a command spawned and awaited, or a function. */
1567
+ /**
1568
+ * Runs unmeasured before every trial (warmup and instrumented included),
1569
+ * in `cwd`/`env`: a command spawned and awaited, or a function. */
1280
1570
  prepare?: PrepareHook;
1281
- /** Take timing from a number in each command's own output (e.g. a build
1571
+ /**
1572
+ * Take timing from a number in each command's own output (e.g. a build
1282
1573
  * tool's `built in 342ms`) instead of its wall clock. */
1283
1574
  timeSource?: TimeSource;
1284
1575
  /** Exact trial count; when set, `budgetMs` is ignored. */
1285
1576
  samples?: number;
1286
- /** Wall-clock budget for the sampling loop, ms. Default: ~3s when neither
1577
+ /**
1578
+ * Wall-clock budget for the sampling loop, ms. Default: ~3s when neither
1287
1579
  * `samples` nor `budgetMs` is given. */
1288
1580
  budgetMs?: number;
1289
1581
  /** Floor on trials when no exact `samples` is given. */
1290
1582
  minSamples?: number;
1291
1583
  warmup?: number;
1292
- /** Round-robin trials across commands instead of finishing each command
1293
- * first, so drift hits every command equally. Default: true with 2+ commands. */
1584
+ /**
1585
+ * Round-robin trials across commands instead of finishing each command
1586
+ * first, so drift hits every command equally. Default: true with 2+
1587
+ * commands. */
1294
1588
  interleave?: boolean;
1295
1589
  cwd?: string;
1296
1590
  env?: Record<string, string>;
@@ -1298,19 +1592,25 @@ export interface TimeOptions {
1298
1592
  heap?: boolean;
1299
1593
  cpuIntervalUs?: number;
1300
1594
  outDir?: string;
1301
- /** Measure the machine's noise floor first (default true, ~200ms) and stamp
1595
+ /**
1596
+ * Measure the machine's noise floor first (default true, ~200ms) and stamp
1302
1597
  * it on the document as `environment`. */
1303
1598
  noiseCheck?: boolean;
1304
- /** SIGKILLs a trial (or prepare hook) still running after this many ms. No
1599
+ /**
1600
+ * SIGKILLs a trial (or prepare hook) still running after this many ms. No
1305
1601
  * default. A timed-out trial contributes no sample. */
1306
1602
  timeoutMs?: number;
1307
- /** Abort kills in-flight trials, schedules no more, and resolves (never
1308
- * rejects) with the completed measurements plus an `aborted` warning on the
1309
- * last one. */
1603
+ /**
1604
+ * Abort kills in-flight trials, schedules no more, and resolves (never
1605
+ * rejects) with the completed measurements plus an `aborted` warning on
1606
+ * the last one. */
1310
1607
  signal?: AbortSignal;
1311
- /** Exit codes to treat as success (hyperfine's `--ignore-failure`): the
1312
- * trial still contributes its sample and gets no `nonzero-exit` warning. */
1608
+ /**
1609
+ * Exit codes to treat as success (hyperfine's `--ignore-failure`): the
1610
+ * trial still contributes its sample and gets no `nonzero-exit` warning.
1611
+ * */
1313
1612
  ignoreExitCodes?: number[];
1314
1613
  }
1315
-
1316
1614
  export declare function time(opts: TimeOptions): Promise<ProfileDocument>;
1615
+ /** Identity function that types an `ostia.config.ts` default export. */
1616
+ export declare function defineConfig(config: OstiaConfigInput): OstiaConfigInput;