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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eric Liu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,50 +1,14 @@
1
1
  # ostia
2
2
 
3
- ostia is a profiling and benchmarking toolkit for Bun. It times subprocess commands
4
- (like hyperfine) and in-process functions (like mitata), optionally captures CPU
5
- profiles, heap snapshots, JIT tiers, retained heap and peak memory, and writes everything
6
- to one schema-versioned JSON document (`ProfileDocument`). Two documents compare with a
7
- bootstrap confidence interval and a Mann-Whitney test, with the regression threshold
8
- widened by the machine's measured noise and drift. `ostia ab` pairs the working tree against
9
- a git ref in one process, which holds up on machines too noisy for that. `ostia ci` gates
10
- a config file of workloads against a saved baseline, and `--format minimal` gives scripts
11
- and LLM agents a compact JSON line protocol. The CLI is a thin wrapper over the library, so anything
12
- `ostia time`/`ostia bench` do, `time()`/`bench()` do too.
3
+ Fast profiling and benchmarking for Bun.
13
4
 
14
- Zero runtime dependencies. Requires Bun ≥ 1.4.
15
-
16
- ## Install
17
-
18
- ```sh
19
- bun add ostia
20
- ```
21
-
22
- ## Quick start
23
-
24
- ### Time two commands
25
-
26
- ```sh
27
- ostia time --samples 10 "bun fixtures/fast.ts" "bun fixtures/slow.ts"
28
- ```
29
-
30
- ```
31
- Apple M2 · 8 cores · load 3.6 · noise floor 0.5%
32
-
33
- Task Median Spread Range User/Sys Relative
34
- ---------------------------------------------------------------------------------------------------
35
- bun fixtures/fast.ts 9.38 ms 9.52 ms…9.74 ms 9.10 ms…9.76 ms 6.98 ms/3.06 ms 1.00×
36
- bun fixtures/slow.ts 23.2 ms 23.3 ms…23.8 ms 23.0 ms…23.9 ms 20.9 ms/2.89 ms 2.47× slower
37
- ! outliers-detected
38
-
39
- Warnings:
40
- bun fixtures/slow.ts: 1 outlier(s) detected (1 severe, 0 mild).
41
- ```
42
-
43
- The header line shows the machine, its load average, and the noise floor from a ~200ms
44
- reference measurement taken once per run (`--no-noise-check` skips it). Spread is
45
- p75…p99; User/Sys is the median user/system CPU time per trial.
46
-
47
- ### Benchmark a function
5
+ ostia times commands and functions on Bun,
6
+ then tells you whether a change made them slower:
7
+ it compares two runs with statistics that account for how noisy your
8
+ machine is, and `ostia ab` confirms a regression in fresh processes
9
+ before it reports one.
10
+ The CLI and the library do the same things,
11
+ and every result is one JSON document.
48
12
 
49
13
  ```ts
50
14
  // suite.ts
@@ -58,11 +22,8 @@ group("dedupe", () => {
58
22
  })
59
23
  ```
60
24
 
61
- ```sh
62
- ostia bench suite.ts
63
- ```
64
-
65
- ```
25
+ ```console
26
+ $ ostia bench suite.ts
66
27
  Apple M2 · 8 cores · load 3.5 · noise floor 0.4%
67
28
 
68
29
  Task Median Spread Range Relative
@@ -72,16 +33,12 @@ dedupe:
72
33
  Set-based (O(n)) 23.5 µs 24.9 µs…72.5 µs 18.7 µs…208.3 µs 1.00×
73
34
  ```
74
35
 
75
- ### Check a change for regressions
76
-
77
- Commit the suite, then change the code: say the Set-based dedupe becomes
78
- `input.filter((x, i) => input.indexOf(x) === i)`.
79
-
80
- ```sh
81
- ostia ab suite.ts # every task: working tree vs HEAD, paired in one process
82
- ```
36
+ **It tells you when a change made something slower.**
37
+ Change the code, and `ostia ab` runs your suite against `HEAD`
38
+ and the working tree in alternating batches in one process:
83
39
 
84
- ```
40
+ ```console
41
+ $ ostia ab suite.ts
85
42
  A/B: working tree vs HEAD (3945768) · 15 rounds · threshold 10% · geomean threshold 1.5%
86
43
 
87
44
  Task Base Candidate Change p25…p75 Verdict
@@ -93,270 +50,47 @@ dedupe:
93
50
  Geomean +165.4% (threshold 1.5%) · 1 regressed, 0 improved, 1 unchanged of 2 · fail
94
51
  ```
95
52
 
96
- Base and candidate run in alternating ~10ms batches, so machine drift cancels within each
97
- round; a flagged task counts only if two fresh processes agree. Exit 1 on a regression.
98
-
99
- ### Gate CI on a baseline
53
+ Exit 1 on a regression, so CI can gate on it.
54
+ ostia has no dependencies and needs Bun ≥ 1.4.
100
55
 
101
- ```json
102
- // ostia.config.json
103
- {
104
- "samples": 10,
105
- "workloads": [
106
- { "label": "work", "command": ["bun", "fixtures/work.ts"], "inputs": ["fixtures/**"] }
107
- ]
108
- }
109
- ```
56
+ ## Quick start
110
57
 
111
58
  ```sh
112
- ostia baseline save # on known-good code: writes .ostia/baselines/main.json
113
- ostia ci # on your change: exit 1 on a regression
59
+ bun add -d ostia
114
60
  ```
115
61
 
116
- ```
117
- 1 workloads
118
- 0 cached
119
- 1 executed
120
- 0 passed 1 regressed (+44.1% median on work)
121
-
122
- Profile CI: ✗
123
- ...
124
- ✗ work
125
- timing: 14.57 ms -> 21.00 ms, +44.1% median, 95% CI [+41.4%, +45.6%], p<0.001 (regressed)
126
- ```
127
-
128
- Scratch output (cache, artifacts) goes to `node_modules/.cache/ostia`. Baselines go to
129
- `.ostia/baselines/` so they survive reinstalls; add `.ostia/` to `.gitignore`.
130
-
131
- ## Using ostia from an AI agent
132
-
133
- `--format minimal` (on `time`, `bench`, `ab`, `compare`, `report`, `ci`) prints one JSON
134
- object per line on stdout and nothing else. Every line has `event` and
135
- `protocolVersion: 2`. Timing values are in nanoseconds.
62
+ Write a suite with `group()` and `task()`, as above, then:
136
63
 
137
64
  ```sh
138
- ostia time --samples 10 "bun a.ts" --format minimal
139
- ostia compare before.json after.json --format minimal
140
- ostia ci --format minimal; echo $?
65
+ ostia bench suite.ts # time each task
66
+ ostia ab suite.ts # compare the working tree with HEAD
141
67
  ```
142
68
 
143
- | `event` | When | Key fields |
144
- |---|---|---|
145
- | `run` | One per timing measurement, every command | `workloadId`, `task`, `group?`, `params?`, `skipped?`, `unit`, `samples` (0 when no trial produced one), `batch`, `mean`/`median`/`stddev`/`stddevPct`/`min`/`max`/`p75`/`p99`/`mad`, `userNs`/`systemNs` (subprocess only), `retainedBytesPerOp?`/`peakBytes?` (`--alloc`/`--peak-mem`), `relative?`, `noiseFloorPct?`, `warnings[]`, `threw?` (`ab`, a task that threw), on `compare`/`ci`: `delta: { medianPct, meanPct, verdict, pass, ci95?, pValue?, effectiveTimingPct, matched }`, and on `ab`: `paired: { baseMedian, medianRatio, ratioP25, ratioP75, rounds, verdict, flagged?, confirmed?, repeats?, sameOutput, suiteChanged?, retained?, peak? }` |
146
- | `unmatched` | One per workload on only one side of `compare`/`ci`/`ab` | `workloadId`, `task`, `side: "base" \| "cand"` |
147
- | `summary` | Last line of `compare`/`ci`/`ab` only | `command`, `matched`/`regressed`/`improved`/`unchanged`/`unmatched`, `cached`/`executed`/`failed`/`missingBaseline` (`ci`), `geomeanPct`, `effectiveTimingPct`, `noiseFloorPct?`, `baseline?` (`ci`), `base?`/`geomeanThresholdPct?`/`unconfirmed?`/`outputDiffers?`/`notComparable?`/`threw?`/`newSuites?`/`memory?` (`ab`), `git?`, `exportedTo?`, `verdict`, `exitCode` |
148
-
149
- ```
150
- {"event":"run","protocolVersion":2,"schemaVersion":2,"workloadId":"wl_11e8562f3622d528","task":"work","unit":"ns","samples":10,"batch":1,"mean":21012800,"median":20999900,"stddev":231456,"stddevPct":1.1015,"min":20664000,"max":21552300,"warnings":[{"code":"outliers-detected","data":{"mild":1,"severe":0}}],"p75":21086100,"p99":21517600,"mad":126625,"userNs":15519000,"systemNs":6015500,"noiseFloorPct":2.09286,"delta":{"medianPct":44.0989,"meanPct":43.9626,"verdict":"regressed","pass":false,"effectiveTimingPct":10,"matched":true,"ci95":[41.4394,45.5841],"pValue":0.000157103}}
151
- {"event":"summary","protocolVersion":2,"command":"ci","matched":1,"regressed":1,"improved":0,"unchanged":0,"unmatched":0,"geomeanPct":44.098920968212305,"effectiveTimingPct":10,"verdict":"fail","exitCode":1,"cached":1,"executed":0,"failed":0,"missingBaseline":0,"baseline":{"name":"main","path":".ostia/baselines/main.json"},"noiseFloorPct":2.09286}
152
- ```
69
+ Exit status: 0 pass, 1 a regression (`ab`, `compare`, `ci`), 2 an error.
153
70
 
154
- Within `protocolVersion: 2`, keys are only ever added, never renamed or removed.
155
-
156
- Exit codes, the same for every command:
157
-
158
- | Code | Meaning |
159
- |---|---|
160
- | `0` | Pass |
161
- | `1` | At least one workload regressed (`compare`/`ci`/`ab` only; `time`/`bench` never return 1) |
162
- | `2` | Harness error: a command exited non-zero or produced no samples, a suite failed, nothing matched, a bad flag, a missing/invalid config or baseline |
163
- | `130` | Cancelled with Ctrl-C (`time`/`bench`/`ab`/`ci`; partial results are still exported) |
164
-
165
- On exit 2, stderr's last line is `{"event":"error","protocolVersion":2,"code":...,"message":...,"data"?:...}`
166
- when stderr is not a TTY or a machine format (`minimal`/`json`/`jsonl`) was requested.
167
- A person at a terminal sees only the prose message. `code` is one of `invalid-flag`,
168
- `config-missing`, `config-invalid`, `baseline-missing`, `no-matches`, `spawn-failed`, `suite-failed`,
169
- `command-failed`, `timeout`, `time-source-no-match`, `document-load-failed`,
170
- `no-cpu-evidence`, `internal`. Full reference: [docs/agent-protocol.md](docs/agent-protocol.md).
171
-
172
- ## Commands
173
-
174
- Every command takes `--help`. Per-flag detail is in [docs/cli.md](docs/cli.md).
175
-
176
- ### `ostia time`
177
-
178
- Times commands as subprocesses. `--cpu`/`--heap` add one separate instrumented trial each;
179
- the profiler never runs during timing trials.
71
+ ## Common tasks
180
72
 
181
73
  ```sh
74
+ # Time two commands against each other
182
75
  ostia time "bun a.ts" "bun b.ts"
183
- ostia time --samples 25 --cpu --heap "bun src/server.ts"
184
- ostia time --prepare "rm -rf dist" "bun build.ts"
185
- ostia time --time-source "built in (\d+)ms" "bun build.ts"
186
- ```
187
-
188
- - Each command string is whitespace-split into argv, with no shell. Everything after
189
- `--` is one more command's argv, verbatim: `ostia time -- bun -e "console.log('a b')"`.
190
- - Default sampling: 3 warmup trials, then trials until ~3s have elapsed and at least 10
191
- ran. `--samples N` gives an exact count per command; `--budget MS`/`--min-samples N`
192
- tune the loop.
193
- - With 2+ commands, trials round-robin across commands (`--no-interleave` to run them
194
- one after another).
195
- - A command stops at its first non-ignored non-zero exit, and `ostia time` exits 2.
196
- `--ignore-failure[=CODE,...]` treats the listed codes (bare: all) as success.
197
76
 
198
- ### `ostia bench`
199
-
200
- Runs in-process `group()`/`task()` suites. Each suite file runs in its own child process.
201
-
202
- ```sh
203
- ostia bench bench/*.ts
204
- ostia bench bench/*.ts --filter parse --cpu --alloc
205
- ostia bench bench/*.ts --filter large --peak-mem
206
- ostia bench bench/*.ts --isolate
207
- ostia bench --preload ./bench/dom-setup.ts --bun-flags="--conditions=browser" bench/*.ts
208
- ```
209
-
210
- - Each task samples for `--budget` ms (default 500). Fast calls are batched so one trial
211
- spans at least 1µs; the budget-driven loop stops at 20,000 trials.
212
- - `--isolate` runs every task in its own process, isolating JIT state, builtin call-site
213
- feedback (e.g. `Array.prototype.map`) and GC heap from other tasks. Use it when you need
214
- the most comparable numbers.
215
- - `--jobs N|auto` runs suite files in parallel. Faster, but noisier; keep the default of 1
216
- for anything you `compare` or gate in `ci`.
217
- - `--cpu` profiles each task at 100µs for about 2,000 samples (`--cpu-interval` changes
218
- the interval). Inlined helpers count as their callers' self time.
219
- - `--alloc` reports the heap each call *retains* after a full GC: a leak check, not an
220
- allocation count. `--peak-mem` reports how far the task's first call raises RSS,
221
- garbage included, in 3 fresh processes (`OSTIA_PEAK_MEM=1` is set there, so a suite can
222
- skip heavy setup that would peak first).
223
- - With no files, `ostia bench` uses the config's `bench` section. Each flag overrides its
224
- config field; `--no-gc`/`--no-cpu`/`--no-alloc`/`--no-peak-mem`/`--no-isolate` override
225
- a config `true`.
226
-
227
- ### `ostia ab`
228
-
229
- Runs suites on a git ref's committed tree and on the working tree in one process,
230
- alternating short batches, and gates on the per-round time ratio.
231
-
232
- ```sh
233
- ostia ab bench/*.ts # vs HEAD
234
- ostia ab bench/*.ts --base origin/main
235
- ostia ab bench/*.ts --threshold 5 --rounds 21
236
- ```
237
-
238
- - The same suite files as `ostia bench`, unchanged. The ref's tree is extracted once per
239
- commit under `node_modules/.cache/ostia/ab/`; relative imports resolve within each tree,
240
- package imports to the project's `node_modules`.
241
- - Files git doesn't hold (generated or gitignored sources) aren't in the base tree.
242
- `--base-setup "bun scripts/generate.ts"` (or `ab.setup` in the config) builds them once
243
- per tree, with the project's `node_modules` linked in.
244
- - A task is flagged when its median ratio moves past `--threshold` (default 10%) in at
245
- least three quarters of rounds, and counts only if `--confirm` (default 2) fresh
246
- processes agree. Each suite runs once with each side first, since the side that goes
247
- first can run faster. The run also fails when the geometric mean of all ratios is more than
248
- `--geomean-threshold` (default 1.5%) slower.
249
- - Tasks whose first call returns different values on each side are listed (not a
250
- failure). The base side runs the base's copy of each suite, so a task whose suite file
251
- changed is marked `suite-changed`; if its output changed too, it reads `not comparable`
252
- and stays out of the verdict. A task that throws reads `base threw`, `candidate threw` or
253
- `both threw` and isn't timed; one that throws on the candidate side only fails the run.
254
- Exit: `0` pass, `1` regression (time or memory), `2` nothing paired or a harness error.
255
- - `--alloc` and `--peak-mem` compare memory too: retained heap per call, and how far the
256
- first call raises RSS. A reading that grows past `--mem-threshold` (default 10%) and
257
- past its noise floor fails the run.
258
- - Progress goes to stderr on a terminal; `--progress` turns it on in logs and pipes too.
259
- - The 5 most recently used base trees stay cached (`--keep-trees`); `ostia ab --clean`
260
- removes them all.
261
-
262
- ### `ostia compare`
263
-
264
- Matches two documents' workloads by id and reports a verdict per workload.
265
-
266
- ```sh
77
+ # Compare two saved runs
267
78
  ostia compare before.json after.json
268
- ostia compare after.json --baseline .ostia/baselines/main.json
269
- ostia compare before.json after.json --format markdown
270
- ```
271
-
272
- ```
273
- ✗ bun fixtures/work.ts
274
- timing: 31.2 ms -> 38.6 ms, +23.8% median, 95% CI [+18.3%, +30.1%], p<0.001 (regressed)
275
- ```
276
-
277
- `--format json` adds a flat `compared` array, one row per task, for scripts. A task on only
278
- one side is listed under "Not compared"; a renamed suite task still compares when it lists
279
- its old name in `aliases`.
280
-
281
- A regression needs the whole 95% CI above the threshold and a Mann-Whitney p-value below
282
- `alpha` (default 0.01). Thresholds come from the config file when one exists, otherwise
283
- the defaults (`timingPct: 5`). The bootstrap is seeded from the samples, so the same two
284
- documents always give the same verdict. See [docs/statistics.md](docs/statistics.md).
285
- Exit: `0` pass, `1` regression, `2` nothing matched or a load error.
286
-
287
- ### `ostia report`
288
-
289
- Renders a saved document without re-running anything.
290
-
291
- ```sh
292
- ostia report doc.json --format markdown
293
- ostia report doc.json --format minimal
294
- ostia report doc.json --format speedscope --out-dir viz/
295
- ostia report doc.json --format collapsed | flamegraph.pl > flame.svg
296
- ```
297
-
298
- Formats: `table` (default), `json`, `jsonl`, `markdown`, `minimal`, and, for documents
299
- with CPU evidence, `collapsed`, `mermaid`, `speedscope`, `cpuprofile`. `time`, `bench`,
300
- `compare` and `ci` accept only the first five; export a document and use `report` for the
301
- visualization formats.
302
-
303
- ### `ostia ci`
304
79
 
305
- Runs the config's workloads, compares them against a named baseline, and exits 1 on a
306
- regression.
307
-
308
- ```sh
80
+ # Save a baseline on known-good code, then gate CI on it
81
+ ostia baseline save
309
82
  ostia ci
310
- ostia ci --full # ignore the cache
311
- ostia ci --baseline release
312
- ostia ci --save-baseline # after a pass, make this run the new baseline
313
- ```
314
83
 
315
- - Command workloads are cached by their declared `inputs`: no `inputs` field always
316
- reruns; `inputs: []` means "depends on nothing" and caches; otherwise the run is reused
317
- while the matched files' contents are unchanged. `suites` workloads always run.
318
- - `suites` workloads run with the config's `bench` section, the same way `ostia bench`
319
- reads it.
320
- - Exit 2 if any command workload exits non-zero (not ignored) or produces no samples, or
321
- if the baseline file is missing. A baseline that matches none of the configured
322
- workloads is also an error; one missing only some lists them and carries on
323
- (`onMissingBaseline` in the config changes this).
84
+ # Capture a CPU profile while timing
85
+ ostia time "bun a.ts" --cpu
324
86
 
325
- ### `ostia baseline`
326
-
327
- ```sh
328
- ostia baseline save # measure the configured workloads -> .ostia/baselines/main.json
329
- ostia baseline save my-feature
330
- ostia baseline list
331
- ostia baseline show main --format markdown
87
+ # One JSON object per line, for a script or an agent
88
+ ostia bench suite.ts --format minimal
332
89
  ```
333
90
 
334
- `save` uses the same measurement code path as `ci`. `show` accepts `report`'s flags.
335
-
336
- ## Library API
91
+ These docs ship in the package, at `node_modules/ostia/docs/`.
337
92
 
338
- ```ts
339
- import {
340
- time, bench, ab, group, task, sweep, range, run, profile, keep,
341
- compareDocuments, defineConfig, createDocument, loadDocument, saveDocument, renderers,
342
- } from "ostia"
343
- import type { ProfileDocument, MinimalEvent } from "ostia"
344
- ```
345
-
346
- | Export | Does |
347
- |---|---|
348
- | `time(opts)` | Subprocess timing, same as `ostia time`. Returns a `ProfileDocument`. |
349
- | `bench(opts)` | Runs suite files, same as `ostia bench`. |
350
- | `ab(opts)` | Paired A/B of suite files against a git ref, same as `ostia ab`. |
351
- | `group(name, fn, opts?)` / `task(name, fn, opts?)` | Register in-process tasks; `.skip`/`.only` variants. |
352
- | `sweep(dims, fn)` / `range(start, end, mult?)` | Parameter sweeps; tasks inherit the point as `params`. |
353
- | `run(opts?)` | Runs the tasks registered in the current file, in this process (`bun suite.ts`). |
354
- | `profile(fn, opts?)` | In-process CPU capture; `origin: "jsc"` adds JIT tier data. |
355
- | `keep(value)` | Pins an intermediate value against dead-code elimination. |
356
- | `compareDocuments(base, cand, thresholds?)` | Same comparison as `ostia compare`. |
357
- | `defineConfig(config)` | Typing helper for `ostia.config.ts`. |
358
- | `createDocument` / `loadDocument` / `saveDocument` | Build, read (schema v2 only), and write documents. |
359
- | `renderers` | `table`, `markdown`, `json`, `jsonl`, `minimal`, `collapsed`, `mermaid`, `speedscope`, `cpuprofile`. |
93
+ ## From code
360
94
 
361
95
  ```ts
362
96
  const doc = await time({
@@ -378,56 +112,19 @@ if (result.summary.verdict === "fail") process.exitCode = 1
378
112
  const { text } = await renderers.markdown.render(doc, {})
379
113
  ```
380
114
 
381
- Full reference, including task options, hooks, and a mitata/hyperfine migration table:
382
- [docs/library.md](docs/library.md).
383
-
384
- ## Configuration
385
-
386
- `ostia.config.ts` (checked first) or `ostia.config.json`, in the current directory.
387
-
388
- ```ts
389
- // ostia.config.ts
390
- import { defineConfig } from "ostia"
391
-
392
- export default defineConfig({
393
- baseline: "main",
394
- samples: 15, // command workloads; or budgetMs/minSamples
395
- warmup: 3,
396
- thresholds: { timingPct: 5 },
397
- workloads: [
398
- { label: "cold-start", command: ["bun", "src/cli.ts", "--help"], inputs: ["src/**/*.ts"] },
399
- { label: "spawn", command: ["bun", "-e", "1"], inputs: [] },
400
- { label: "build:cold", command: ["bun", "build.ts"], prepare: "rm -rf dist" },
401
- { label: "suites", suites: ["bench/*.ts"] },
402
- ],
403
- bench: { budgetMs: 500, isolate: true, preload: ["bench/setup.ts"] },
404
- })
405
- ```
406
-
407
- A config with a wrong-typed value, or the old `runs` field, fails to load with a message
408
- naming the key (error code `config-invalid`). All fields: [docs/config.md](docs/config.md).
409
-
410
- ## Documentation
411
-
412
- - [docs/cli.md](docs/cli.md): every command and flag
413
- - [docs/config.md](docs/config.md): config file reference
414
- - [docs/library.md](docs/library.md): library API reference
415
- - [docs/agent-protocol.md](docs/agent-protocol.md): `--format minimal`, exit codes, error codes
416
- - [docs/statistics.md](docs/statistics.md): sampling, the comparison test, noise floor
417
- - [docs/document-schema.md](docs/document-schema.md): `ProfileDocument`, workload ids, warnings
418
- - [docs/preload-recipes.md](docs/preload-recipes.md): jsdom, happy-dom and `Bun.plugin()` preloads
419
-
420
- ## Examples
421
-
422
- [`examples/`](examples/) has runnable recipes (they use `../../src` directly, no install):
423
- [`compare-two-commands`](examples/compare-two-commands/),
424
- [`find-a-hotspot`](examples/find-a-hotspot/),
425
- [`heap-usage`](examples/heap-usage/),
426
- [`gate-a-regression`](examples/gate-a-regression/),
427
- [`profile-in-process`](examples/profile-in-process/),
428
- [`benchmark-a-function`](examples/benchmark-a-function/).
429
-
430
- ```sh
431
- cd examples/find-a-hotspot && bun run demo
432
- bun run examples # all of them, from the repo root
433
- ```
115
+ ## Docs
116
+
117
+ - [CLI](https://github.com/metonym/ostia/blob/master/docs/cli.md):
118
+ every command and flag
119
+ - [Library](https://github.com/metonym/ostia/blob/master/docs/library.md):
120
+ `time()`, `bench()`, `ab()`, `profile()`, and documents
121
+ - [Config](https://github.com/metonym/ostia/blob/master/docs/config.md):
122
+ `ostia.config` workloads, thresholds and baselines
123
+ - [Machine-readable output](https://github.com/metonym/ostia/blob/master/docs/agent-protocol.md):
124
+ `--format minimal`, exit codes and error codes, for scripts and agents
125
+ - [Statistics](https://github.com/metonym/ostia/blob/master/docs/statistics.md):
126
+ how a comparison decides, and the noise floor
127
+ - [Document schema](https://github.com/metonym/ostia/blob/master/docs/document-schema.md):
128
+ the JSON a run writes
129
+ - [Preload recipes](https://github.com/metonym/ostia/blob/master/docs/preload-recipes.md):
130
+ DOM, Svelte and other setups a suite needs