ostia 0.2.12 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +50 -358
- package/docs/agent-protocol.md +210 -0
- package/docs/cli.md +1196 -0
- package/docs/config.md +233 -0
- package/docs/document-schema.md +224 -0
- package/docs/library.md +421 -0
- package/docs/preload-recipes.md +169 -0
- package/docs/statistics.md +218 -0
- package/index.d.ts +894 -677
- package/package.json +16 -14
- package/src/ab/ab-runner.ts +474 -0
- package/src/ab/index.ts +1086 -0
- package/src/baseline/index.ts +75 -0
- package/src/bench/index.ts +462 -0
- package/src/bench/projects.ts +39 -0
- package/src/bench/range.ts +27 -0
- package/src/bench/registry.ts +424 -0
- package/src/bench/run-tasks.ts +176 -0
- package/src/bench/run.ts +51 -0
- package/src/bench/runner.ts +147 -0
- package/src/bench/support.ts +161 -0
- package/src/bench/sweep.ts +39 -0
- package/src/cache/fingerprint.ts +59 -0
- package/src/cache/store.ts +28 -0
- package/src/capture/bunflags.ts +91 -0
- package/src/capture/cpu-parse.ts +119 -0
- package/src/capture/cpu.ts +44 -0
- package/src/capture/frames.ts +54 -0
- package/src/capture/heap-parse.ts +86 -0
- package/src/capture/heap.ts +32 -0
- package/src/capture/inspector.ts +46 -0
- package/src/capture/jsc-parse.ts +167 -0
- package/src/capture/jsc.ts +35 -0
- package/src/capture/sampling.ts +5 -0
- package/src/ci/index.ts +416 -0
- package/src/cli/flags.ts +264 -0
- package/{chunk-9sx15b08.js → src/cli/help.ts} +23 -11
- package/src/cli/main.ts +18 -0
- package/src/cli/output.ts +185 -0
- package/src/cli/run.ts +1110 -0
- package/src/compare/index.ts +617 -0
- package/src/config/index.ts +275 -0
- package/src/config/validate.ts +267 -0
- package/src/errors.ts +8 -0
- package/src/format.ts +36 -0
- package/src/glob.ts +48 -0
- package/src/index.ts +62 -0
- package/src/ir/cpu.ts +10 -0
- package/src/ir/document.ts +471 -0
- package/src/ir/fp.ts +31 -0
- package/src/ir/git.ts +36 -0
- package/src/ir/types.ts +615 -0
- package/src/measure/alloc.ts +57 -0
- package/src/measure/cpu.ts +99 -0
- package/src/measure/environment.ts +41 -0
- package/src/measure/inprocess.ts +191 -0
- package/src/measure/instructions.ts +133 -0
- package/src/measure/loop.ts +57 -0
- package/src/measure/noise.ts +55 -0
- package/src/measure/paired.ts +312 -0
- package/src/measure/peak.ts +202 -0
- package/src/measure/timing.ts +263 -0
- package/src/profile.ts +109 -0
- package/src/renderers/collapsed.ts +35 -0
- package/src/renderers/cpu-tree.ts +183 -0
- package/src/renderers/cpuprofile.ts +43 -0
- package/src/renderers/format.ts +142 -0
- package/src/renderers/index.ts +27 -0
- package/src/renderers/json.ts +10 -0
- package/src/renderers/jsonl.ts +15 -0
- package/src/renderers/markdown.ts +525 -0
- package/src/renderers/mermaid.ts +78 -0
- package/src/renderers/minimal.ts +602 -0
- package/src/renderers/paired.ts +229 -0
- package/src/renderers/relative.ts +64 -0
- package/src/renderers/select.ts +286 -0
- package/src/renderers/speedscope.ts +69 -0
- package/src/renderers/terminal.ts +466 -0
- package/src/renderers/types.ts +27 -0
- package/src/spawn/index.ts +396 -0
- package/src/stats/bootstrap.ts +153 -0
- package/src/stats/index.ts +140 -0
- package/src/stats/mannwhitney.ts +81 -0
- package/src/time.ts +325 -0
- package/src/version.ts +3 -0
- package/ab-runner.ts +0 -8
- package/chunk-05jfst35.js +0 -28
- package/chunk-1g1x9zz2.js +0 -15
- package/chunk-23g2rwrn.js +0 -3
- package/chunk-468h5412.js +0 -25
- package/chunk-4esjfc2m.js +0 -2
- package/chunk-ct2xsezd.js +0 -14
- package/cli.js +0 -3
- package/index.js +0 -2
- package/runner.ts +0 -7
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Machine-readable output
|
|
2
|
+
|
|
3
|
+
`--format minimal` is a line protocol for scripts and LLM agents:
|
|
4
|
+
one JSON object per line on stdout, nothing else.
|
|
5
|
+
It drops the raw sample arrays and prose that make a full
|
|
6
|
+
`ProfileDocument` large.
|
|
7
|
+
It works on `time`, `bench`, `ab`, `compare`, `ci`,
|
|
8
|
+
`report` and `baseline show`.
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
ostia time --samples 10 "bun a.ts" --format minimal
|
|
12
|
+
ostia bench bench/*.ts --format minimal
|
|
13
|
+
ostia ab bench/*.ts --base origin/main --format minimal
|
|
14
|
+
ostia compare before.json after.json --format minimal
|
|
15
|
+
ostia ci --format minimal; echo $?
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`ostia ab` can run for many minutes.
|
|
19
|
+
Add `--progress` to see where it is:
|
|
20
|
+
it writes
|
|
21
|
+
`[ab] suite 4/13 bench/search.bench.ts · task 3/7 search/regex` lines to
|
|
22
|
+
stderr, never stdout, so the protocol stays clean.
|
|
23
|
+
Without the flag, progress only shows when stderr is a terminal.
|
|
24
|
+
|
|
25
|
+
The TypeScript type for a parsed line is exported as `MinimalEvent`;
|
|
26
|
+
narrow on `event`.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import type { MinimalEvent } from "ostia"
|
|
30
|
+
|
|
31
|
+
const events = stdout.trim().split("\n").map((l) => JSON.parse(l) as MinimalEvent)
|
|
32
|
+
const regressed = events.some((e) => e.event === "run" && e.delta?.verdict === "regressed")
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Versioning
|
|
36
|
+
|
|
37
|
+
Every line carries `protocolVersion: 2` (`MINIMAL_PROTOCOL_VERSION`).
|
|
38
|
+
Within version 2, keys are only added, never renamed or removed,
|
|
39
|
+
so a consumer that reads the fields it knows keeps working.
|
|
40
|
+
Version 2 renamed `paired.p25`/`paired.p75` (`ab` runs) to
|
|
41
|
+
`ratioP25`/`ratioP75`, so they can't be mistaken for the ns percentiles
|
|
42
|
+
`p75`/`p99`, and added `"error"` to the `summary` `verdict` values
|
|
43
|
+
(it was `"fail"` for every non-zero exit code).
|
|
44
|
+
`run` lines also carry the document's `schemaVersion` (currently 2).
|
|
45
|
+
|
|
46
|
+
## Events
|
|
47
|
+
|
|
48
|
+
### `run`
|
|
49
|
+
|
|
50
|
+
One per timing measurement, for every command;
|
|
51
|
+
for `ab`, one per paired task, with the candidate's stats.
|
|
52
|
+
Times are in nanoseconds (`unit: "ns"`),
|
|
53
|
+
rounded to 6 significant digits.
|
|
54
|
+
|
|
55
|
+
| Field | Present | Meaning |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| `workloadId` | always | Join key to `Workload.id`; stable across runs of the same workload. |
|
|
58
|
+
| `task` | always | Display name: the workload's label (the `group/name` task id for `bench` tasks), else its command line, else its task id. |
|
|
59
|
+
| `group`, `description`, `groupDescription`, `params` | when set | From `group()`/`task()`/`sweep()`. |
|
|
60
|
+
| `skipped` | skipped tasks | `true` for `task.skip()`; no stats fields follow. |
|
|
61
|
+
| `threw` | `ab`, a task that threw | `{ side, message, repeat? }`: `side` is `"base"`, `"cand"` or `"both"`, `message` the error's first lines, and `repeat` (from 1) is set when it threw in a confirmation repeat. No stats or `paired` follow. |
|
|
62
|
+
| `unit` | measured | `"ns"`. |
|
|
63
|
+
| `samples` | measured, or `0` | Number of timing samples. `0`, with no other stats fields, when every trial timed out or missed the `--time-source` pattern; `warnings` says which. |
|
|
64
|
+
| `batch` | always | Calls per timed trial for batched in-process tasks; 1 otherwise. |
|
|
65
|
+
| `mean`, `median`, `stddev`, `min`, `max` | measured | Per-call statistics. |
|
|
66
|
+
| `stddevPct` | measured | `stddev / mean` in percent. |
|
|
67
|
+
| `p75`, `p99`, `mad` | measured | 75th and 99th percentile; median absolute deviation. |
|
|
68
|
+
| `userNs`, `systemNs` | subprocess commands | Median user / system CPU time per trial. |
|
|
69
|
+
| `retainedBytesPerOp` | `--alloc` | Heap each call keeps alive after a full GC, whole bytes. |
|
|
70
|
+
| `peakBytes` | `--peak-mem` | How far the task's first call raised RSS, bytes (median of 3 fresh processes). A `peak-hidden` warning says when it may read low. |
|
|
71
|
+
| `instructions` | in-process tasks, where the machine counts them | Median instructions retired per call, on the thread that ran the task; for `ab`, the candidate's. |
|
|
72
|
+
| `relative` | 2+ runs | Median over the group's reference (its `baseline: true` task, else its fastest). |
|
|
73
|
+
| `baseline` | when set | `true` for the group's reference task. |
|
|
74
|
+
| `noiseFloorPct` | noise check ran | The machine's noise floor for this document. |
|
|
75
|
+
| `warnings` | always | `[{ code, data? }]`: the measurement's warnings, plus CPU-capture, memory and comparison warnings for the same workload. Codes are listed in [document-schema.md](document-schema.md#warnings). |
|
|
76
|
+
| `delta` | `compare`/`ci` | See below. |
|
|
77
|
+
| `paired` | `ab` | See below. |
|
|
78
|
+
|
|
79
|
+
`delta`:
|
|
80
|
+
|
|
81
|
+
| Field | Meaning |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `baseMedian` | The base's median, ns; the line's own `median` is the candidate's. |
|
|
84
|
+
| `medianPct`, `meanPct` | Change of the candidate against the baseline, percent. |
|
|
85
|
+
| `verdict` | `"regressed"`, `"improved"` or `"unchanged"` (timing only). |
|
|
86
|
+
| `pass` | `false` when the comparison failed, including on CPU frame or heap type thresholds. |
|
|
87
|
+
| `ci95` | 95% bootstrap CI on the median change, percent. Absent for thin comparisons (<5 samples per side). |
|
|
88
|
+
| `pValue` | Mann-Whitney p-value. Same absence rule. |
|
|
89
|
+
| `effectiveTimingPct` | The threshold actually applied, after noise-floor and drift widening. |
|
|
90
|
+
| `matched` | Always `true`. |
|
|
91
|
+
| `renamedFrom` | The base task's name, when it was matched through the task's `aliases`. |
|
|
92
|
+
|
|
93
|
+
`paired` (`ab` only; ratios are candidate/base, so above 1 is slower):
|
|
94
|
+
|
|
95
|
+
| Field | Meaning |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `baseMedian` | The base side's median per-call time, ns. |
|
|
98
|
+
| `medianRatio`, `ratioP25`, `ratioP75` | Median and quartiles of the per-round time ratios. |
|
|
99
|
+
| `rounds` | Rounds measured. |
|
|
100
|
+
| `verdict` | `"regressed"`, `"improved"` or `"unchanged"`, after confirmation. |
|
|
101
|
+
| `flagged` | What the first process saw, when it crossed the threshold. |
|
|
102
|
+
| `confirmed` | With `flagged`: whether every fresh-process repeat flagged the same way. |
|
|
103
|
+
| `repeats` | With `flagged`: each repeat's median ratio, by the summary's `metric`. |
|
|
104
|
+
| `instructions` | Where the machine counts them: `{ baseMedian, medianRatio, ratioP25, ratioP75 }`, the base's median instructions per call and the per-round instruction ratios. The `run` line's `instructions` is the candidate's. |
|
|
105
|
+
| `sameOutput` | Whether the first call returned deep-equal values on both sides. |
|
|
106
|
+
| `suiteChanged` | `true` when the suite file differs from the base's copy. With `sameOutput: false`, the task is not comparable: `verdict` is `"unchanged"` and it's left out of `geomeanPct`. |
|
|
107
|
+
| `retained` | `--alloc`: `{ base, cand, verdict, floor }`, retained heap per call on each side, bytes, each the median of 3 fresh processes. `verdict` is `"regressed"`, `"improved"` or `"unchanged"`; `floor` is the smallest change that counts. The `run` line's `retainedBytesPerOp` is `cand`. |
|
|
108
|
+
| `peak` | `--peak-mem`: the same shape, for each side's first-call RSS rise. The `run` line's `peakBytes` is `cand`. |
|
|
109
|
+
|
|
110
|
+
### `unmatched`
|
|
111
|
+
|
|
112
|
+
`compare`/`ci`/`ab` only.
|
|
113
|
+
One per workload present in only one of the two documents.
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{"event":"unmatched","protocolVersion":2,"workloadId":"wl_…","task":"old-task","side":"base"}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### `summary`
|
|
120
|
+
|
|
121
|
+
`compare`/`ci`/`ab` only; always the last line.
|
|
122
|
+
Never emitted for `time`, `bench` or `report`.
|
|
123
|
+
|
|
124
|
+
| Field | Meaning |
|
|
125
|
+
|---|---|
|
|
126
|
+
| `command` | `"compare"`, `"ci"` or `"ab"`. |
|
|
127
|
+
| `matched`, `regressed`, `improved`, `unchanged` | Counts over matched workloads (timing verdicts; for `ab`, confirmed verdicts). |
|
|
128
|
+
| `unmatched` | Count of `unmatched` events. |
|
|
129
|
+
| `cached`, `executed`, `failed`, `missingBaseline` | `ci` only. `failed` counts harness failures. |
|
|
130
|
+
| `geomeanPct` | Geometric mean of candidate/base median ratios, as a signed percent; `null` when there were no timing comparisons. |
|
|
131
|
+
| `effectiveTimingPct` | Threshold after noise-floor and drift widening; for `ab`, `--threshold` as given. |
|
|
132
|
+
| `driftPct` | `compare`/`ci`, when both runs measured their noise floor: the machine drift added to the threshold. |
|
|
133
|
+
| `base` | `ab` only: `{ ref, sha }` the working tree was paired against. |
|
|
134
|
+
| `metric` | `ab` only: `"time"` or `"instructions"`, the ratios that verdicts and `geomeanPct` judge. |
|
|
135
|
+
| `geomeanThresholdPct` | `ab` only: the run fails when `geomeanPct` exceeds it. |
|
|
136
|
+
| `unconfirmed` | `ab` only: flagged in the first process, not reproduced by the repeats; counted in `unchanged`. |
|
|
137
|
+
| `outputDiffers` | `ab` only: tasks whose first call returned different values on each side. |
|
|
138
|
+
| `notComparable` | `ab` only: tasks whose suite file and output both changed; counted in `unchanged`, left out of `geomeanPct`. |
|
|
139
|
+
| `threw` | `ab` only: tasks that threw on either side, so weren't timed; not in `matched`. |
|
|
140
|
+
| `newSuites` | `ab` only, when any: suite files that don't exist at the base ref. Their tasks are `unmatched` with `side: "cand"`. |
|
|
141
|
+
| `memory` | `ab` only, with `--alloc` or `--peak-mem`: `{ thresholdPct, regressed, improved }`, tasks whose memory regressed (on either reading) or improved. A memory regression makes `verdict` `"fail"`. |
|
|
142
|
+
| `noiseFloorPct` | When the candidate document has one. |
|
|
143
|
+
| `baseline` | `ci` only: `{ name, path }`. |
|
|
144
|
+
| `git` | `{ base?, cand? }`, each `{ sha, branch, dirty }`, when available. |
|
|
145
|
+
| `exportedTo` | The `--export-json` path, when given. |
|
|
146
|
+
| `verdict` | `"pass"` when `exitCode` is 0, `"fail"` when it is 1 (a regression), `"error"` otherwise: exit 2 (harness error) or 130 (cancelled), where no verdict was reached. |
|
|
147
|
+
| `exitCode` | The process's exit code. |
|
|
148
|
+
|
|
149
|
+
Example (`ostia ci --format minimal` after a regression):
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
{"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}}
|
|
153
|
+
{"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}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Exit codes
|
|
157
|
+
|
|
158
|
+
The same across commands:
|
|
159
|
+
|
|
160
|
+
| Code | Meaning |
|
|
161
|
+
|---|---|
|
|
162
|
+
| `0` | Pass. |
|
|
163
|
+
| `1` | At least one workload failed its comparison (`compare`, `ci`), or a confirmed regression, a task that threw on the candidate side only, or the geomean over its threshold (`ab`). `time` and `bench` never return 1. |
|
|
164
|
+
| `2` | Harness error: the numbers couldn't be produced or compared. |
|
|
165
|
+
| `130` | Cancelled with Ctrl-C (`time`, `bench`, `ab`, `ci`). |
|
|
166
|
+
|
|
167
|
+
`--help` exits 0; a missing required argument prints the help
|
|
168
|
+
and exits 2.
|
|
169
|
+
|
|
170
|
+
## Errors
|
|
171
|
+
|
|
172
|
+
On exit 2, stderr gets a prose message.
|
|
173
|
+
When stderr is not a TTY, or `--format` is `minimal`, `json` or `jsonl`,
|
|
174
|
+
one more line follows it as the last line of stderr:
|
|
175
|
+
|
|
176
|
+
```json
|
|
177
|
+
{"event":"error","protocolVersion":2,"code":"command-failed","message":"One or more commands failed to produce a clean measurement; see the report above for details."}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
`message` is the first line of the prose message;
|
|
181
|
+
`data` is included when there is structured detail.
|
|
182
|
+
stdout stays pure JSON for the machine formats.
|
|
183
|
+
|
|
184
|
+
| `code` | Cause |
|
|
185
|
+
|---|---|
|
|
186
|
+
| `invalid-flag` | Unknown flag or subcommand, bad flag value, bad `--time-source` regex, wrong number of `--prepare` hooks, invalid baseline name, a surplus positional or a flag with nothing to act on (`--time-unit` without `--time-source`, `report --out-dir` with a non-visualization format), a `suites` glob in `ci` that matches no files, `ab` outside a git repository or with a `--base` that isn't a commit. |
|
|
187
|
+
| `config-missing` | No `ostia.config.ts`/`ostia.config.json` (or the file named by `--config`), or no `workloads` (`ci`, `baseline`). |
|
|
188
|
+
| `config-invalid` | The config file can't be loaded: invalid JSON, an `ostia.config.ts` that throws on import or has no default export, a renamed field (e.g. `runs`, now `samples`), or a value of the wrong type (the message names the key). |
|
|
189
|
+
| `baseline-missing` | No baseline file (`ci`, `baseline show`), or the baseline doesn't cover the configured workloads (`onMissingBaseline`). |
|
|
190
|
+
| `no-matches` | `compare` found no workload id in both documents; `ab` found no task on both sides. |
|
|
191
|
+
| `spawn-failed` | A run threw: a command couldn't start, a `prepare` hook failed or timed out, a suite failed or timed out. |
|
|
192
|
+
| `suite-failed` | `ab`: one side's suite failed outside any task: it threw on import, registered no tasks, or a task threw while its memory was measured. `data.side` is `"base"` or `"cand"`. |
|
|
193
|
+
| `command-failed` | A command had a non-ignored non-zero exit (`time`, `ci`), or produced no samples for another reason; an `ab` setup command (`--base-setup`) failed. |
|
|
194
|
+
| `timeout` | `time`: a command produced no samples because its trials timed out. |
|
|
195
|
+
| `time-source-no-match` | `time`: a command produced no samples because no trial's output matched `--time-source`. |
|
|
196
|
+
| `document-load-failed` | `compare`/`report` couldn't read a document (missing file, invalid JSON, unsupported schema version). |
|
|
197
|
+
| `no-cpu-evidence` | A visualization format was requested for a document with no CPU measurement. |
|
|
198
|
+
| `internal` | An unexpected error (a bug in ostia); the message carries the stack. |
|
|
199
|
+
|
|
200
|
+
## `--format jsonl`
|
|
201
|
+
|
|
202
|
+
For the full document rather than the condensed protocol:
|
|
203
|
+
a `kind: "document"` header line (the document minus `measurements`),
|
|
204
|
+
then one `kind: "measurement"` line per measurement,
|
|
205
|
+
including raw samples and trials.
|
|
206
|
+
|
|
207
|
+
## `--format json`
|
|
208
|
+
|
|
209
|
+
The whole document, byte-identical to what `--export-json` writes.
|
|
210
|
+
Schema: [document-schema.md](document-schema.md).
|