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
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var cn=`ostia time [flags] <command...>
|
|
1
|
+
export const TIME_HELP = `ostia time [flags] <command...>
|
|
3
2
|
ostia time [flags] -- <argv...>
|
|
4
3
|
|
|
5
4
|
Time commands as subprocesses. Each <command> is whitespace-split into argv (no shell);
|
|
@@ -35,7 +34,9 @@ Examples:
|
|
|
35
34
|
ostia time --prepare "rm -rf dist" "bun build.ts"
|
|
36
35
|
ostia time --time-source "built in (\\d+)ms" "bun build.ts"
|
|
37
36
|
ostia time -- bun -e "console.log('a b')"
|
|
38
|
-
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
export const BENCH_HELP = `ostia bench [flags] <suite.ts...>
|
|
39
40
|
|
|
40
41
|
Run in-process group()/task() suites, each file in its own child process. With no files,
|
|
41
42
|
uses ostia.config's "bench" section; each flag overrides its config field.
|
|
@@ -72,7 +73,9 @@ Examples:
|
|
|
72
73
|
ostia bench bench/*.ts
|
|
73
74
|
ostia bench bench/*.ts --filter parse --cpu --alloc
|
|
74
75
|
ostia bench --preload ./bench/dom-setup.ts --bun-flags="--conditions=browser" bench/*.ts
|
|
75
|
-
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
export const AB_HELP = `ostia ab [flags] <suite.ts...>
|
|
76
79
|
|
|
77
80
|
Pair every task on a git ref's committed tree (base) against the working tree (candidate), in
|
|
78
81
|
one process, alternating ~10ms batches, and gate on the per-round time ratio. Drift between
|
|
@@ -128,7 +131,9 @@ Examples:
|
|
|
128
131
|
ostia ab bench/*.ts --metric instructions --threshold 3
|
|
129
132
|
ostia ab bench/*.ts --base-setup "bun scripts/generate.ts"
|
|
130
133
|
ostia ab bench/paint.bench.ts --alloc --peak-mem
|
|
131
|
-
|
|
134
|
+
`;
|
|
135
|
+
|
|
136
|
+
export const COMPARE_HELP = `ostia compare <base.json> <candidate.json>
|
|
132
137
|
ostia compare <candidate.json> --baseline <base.json>
|
|
133
138
|
|
|
134
139
|
Compare two ProfileDocuments by workload id (or a task's former names, from its
|
|
@@ -146,7 +151,9 @@ Flags:
|
|
|
146
151
|
|
|
147
152
|
Exactly two document paths (one with --baseline); anything more is an error.
|
|
148
153
|
Exit codes: 0 pass, 1 a workload regressed, 2 nothing matched or a harness error.
|
|
149
|
-
|
|
154
|
+
`;
|
|
155
|
+
|
|
156
|
+
export const REPORT_HELP = `ostia report <document.json> [flags]
|
|
150
157
|
|
|
151
158
|
Render a saved ProfileDocument. Files, not a GUI for the visualization formats -
|
|
152
159
|
hand the output to speedscope.app, flamegraph.pl, or a Mermaid renderer.
|
|
@@ -174,7 +181,9 @@ Examples:
|
|
|
174
181
|
ostia report doc.json --format markdown
|
|
175
182
|
ostia report doc.json --format speedscope --out-dir node_modules/.cache/ostia/viz
|
|
176
183
|
ostia report doc.json --format collapsed | flamegraph.pl > flame.svg
|
|
177
|
-
|
|
184
|
+
`;
|
|
185
|
+
|
|
186
|
+
export const CI_HELP = `ostia ci [flags]
|
|
178
187
|
|
|
179
188
|
Run ostia.config's workloads (reusing cached runs whose declared inputs are unchanged),
|
|
180
189
|
compare against a saved baseline, and gate on regressions.
|
|
@@ -194,7 +203,9 @@ Flags:
|
|
|
194
203
|
Exit codes: 0 pass, 1 regression, 2 harness error (missing config/baseline, a workload
|
|
195
204
|
failed or produced no samples, or an onMissingBaseline "fail" mismatch), 130 Ctrl-C (the
|
|
196
205
|
partial document is exported; nothing is compared or saved).
|
|
197
|
-
|
|
206
|
+
`;
|
|
207
|
+
|
|
208
|
+
export const BASELINE_HELP = `ostia baseline <save|list|show> [args]
|
|
198
209
|
|
|
199
210
|
Manage the baseline ProfileDocuments "ostia ci" gates against and "ostia compare --baseline"
|
|
200
211
|
reads.
|
|
@@ -217,7 +228,9 @@ Examples:
|
|
|
217
228
|
ostia baseline list
|
|
218
229
|
ostia baseline show main
|
|
219
230
|
ostia baseline show main --format markdown
|
|
220
|
-
|
|
231
|
+
`;
|
|
232
|
+
|
|
233
|
+
export const MAIN_HELP = `ostia - profiling and benchmarking for Bun
|
|
221
234
|
|
|
222
235
|
Commands:
|
|
223
236
|
time Time commands N times and report timing/CPU/heap
|
|
@@ -228,6 +241,5 @@ Commands:
|
|
|
228
241
|
ci Run configured workloads against a baseline, gate on regressions
|
|
229
242
|
baseline Manage baseline ProfileDocuments (save/list/show)
|
|
230
243
|
|
|
231
|
-
Run "ostia <command> --help" for details.
|
|
244
|
+
Run "ostia <command> --help" for details, "ostia --version" for the version.
|
|
232
245
|
`;
|
|
233
|
-
export{cn,Ke,qe,Ye,Ze,un,re,mn};
|
package/src/cli/main.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
export {};
|
|
3
|
+
|
|
4
|
+
// Help and the version are answered before loading the commands, so they
|
|
5
|
+
// stay fast.
|
|
6
|
+
const first = process.argv[2];
|
|
7
|
+
if (first === "--version" || first === "-v") {
|
|
8
|
+
const { TOOL_VERSION } = await import("../version.ts");
|
|
9
|
+
await Bun.write(Bun.stdout, `${TOOL_VERSION}\n`);
|
|
10
|
+
process.exit(0);
|
|
11
|
+
}
|
|
12
|
+
if (first === undefined || first === "--help" || first === "-h") {
|
|
13
|
+
const { MAIN_HELP } = await import("./help.ts");
|
|
14
|
+
await Bun.write(Bun.stdout, MAIN_HELP);
|
|
15
|
+
process.exit(first === undefined ? 2 : 0);
|
|
16
|
+
}
|
|
17
|
+
const { main } = await import("./run.ts");
|
|
18
|
+
process.exit(await main());
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { errorMessage, OstiaUsageError } from "../errors.ts";
|
|
2
|
+
import {
|
|
3
|
+
saveDocument,
|
|
4
|
+
saveDocumentText,
|
|
5
|
+
serializeDocument,
|
|
6
|
+
} from "../ir/document.ts";
|
|
7
|
+
import type { ProfileDocument } from "../ir/types.ts";
|
|
8
|
+
import type { FormatName, RenderResult } from "../renderers/index.ts";
|
|
9
|
+
import { renderers } from "../renderers/index.ts";
|
|
10
|
+
import {
|
|
11
|
+
MINIMAL_PROTOCOL_VERSION,
|
|
12
|
+
type MinimalRenderOptions,
|
|
13
|
+
} from "../renderers/minimal.ts";
|
|
14
|
+
|
|
15
|
+
// Bun.write skips process.stdout/stderr's Node stream setup, which costs
|
|
16
|
+
// startup time.
|
|
17
|
+
export const out = (text: string) => Bun.write(Bun.stdout, text);
|
|
18
|
+
const errOut = (text: string) => Bun.write(Bun.stderr, text);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* One per distinct exit-2 cause, as the `code` of the machine-readable
|
|
22
|
+
* `error` event.
|
|
23
|
+
*/
|
|
24
|
+
export type CliErrorCode =
|
|
25
|
+
| "invalid-flag"
|
|
26
|
+
| "config-missing"
|
|
27
|
+
| "config-invalid"
|
|
28
|
+
| "baseline-missing"
|
|
29
|
+
| "no-matches"
|
|
30
|
+
| "spawn-failed"
|
|
31
|
+
| "suite-failed"
|
|
32
|
+
| "command-failed"
|
|
33
|
+
| "timeout"
|
|
34
|
+
| "time-source-no-match"
|
|
35
|
+
| "document-load-failed"
|
|
36
|
+
| "no-cpu-evidence"
|
|
37
|
+
| "internal";
|
|
38
|
+
|
|
39
|
+
/** Thrown to abort a command with exit 2; the dispatcher reports it. */
|
|
40
|
+
export class CliError extends Error {
|
|
41
|
+
constructor(
|
|
42
|
+
readonly code: CliErrorCode,
|
|
43
|
+
message: string,
|
|
44
|
+
/** Structured detail for the `error` event's `data`. */
|
|
45
|
+
readonly data?: Record<string, unknown>,
|
|
46
|
+
) {
|
|
47
|
+
super(message);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Runs `run`, turning any failure into a `CliError` of `code` with
|
|
53
|
+
* `message` as a prefix.
|
|
54
|
+
*/
|
|
55
|
+
export async function orFail<T>(
|
|
56
|
+
code: CliErrorCode,
|
|
57
|
+
message: string,
|
|
58
|
+
run: () => Promise<T>,
|
|
59
|
+
): Promise<T> {
|
|
60
|
+
try {
|
|
61
|
+
return await run();
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if (err instanceof CliError) throw err;
|
|
64
|
+
if (err instanceof OstiaUsageError) {
|
|
65
|
+
throw new CliError("invalid-flag", `${message}: ${err.message}`);
|
|
66
|
+
}
|
|
67
|
+
throw new CliError(code, `${message}: ${errorMessage(err)}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const MACHINE_FORMATS = new Set(["minimal", "json", "jsonl"]);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Machine errors are for scripts and agents: stderr isn't a terminal, or a
|
|
75
|
+
* machine `--format` was asked for.
|
|
76
|
+
*/
|
|
77
|
+
async function wantsMachineErrors(): Promise<boolean> {
|
|
78
|
+
// Imported lazily: loading node:tty up front costs every invocation ~15ms.
|
|
79
|
+
const { isatty } = await import("node:tty");
|
|
80
|
+
if (!isatty(2)) return true;
|
|
81
|
+
const argv = process.argv.slice(2);
|
|
82
|
+
return argv.some(
|
|
83
|
+
(arg, i) =>
|
|
84
|
+
(arg === "--format" && MACHINE_FORMATS.has(argv[i + 1] ?? "")) ||
|
|
85
|
+
(arg.startsWith("--format=") &&
|
|
86
|
+
MACHINE_FORMATS.has(arg.slice("--format=".length))),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Writes `message` to stderr, then for a machine reader one JSON `error`
|
|
92
|
+
* line (first line of `message` only). Never touches stdout.
|
|
93
|
+
*/
|
|
94
|
+
export async function writeCliError(
|
|
95
|
+
code: CliErrorCode,
|
|
96
|
+
message: string,
|
|
97
|
+
data?: Record<string, unknown>,
|
|
98
|
+
): Promise<void> {
|
|
99
|
+
await errOut(message.endsWith("\n") ? message : `${message}\n`);
|
|
100
|
+
if (!(await wantsMachineErrors())) return;
|
|
101
|
+
await errOut(
|
|
102
|
+
`${JSON.stringify({
|
|
103
|
+
event: "error",
|
|
104
|
+
protocolVersion: MINIMAL_PROTOCOL_VERSION,
|
|
105
|
+
code,
|
|
106
|
+
message: message.split("\n")[0],
|
|
107
|
+
...(data && { data }),
|
|
108
|
+
})}\n`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Prints help and returns the exit code: 0 when asked for, 2 when shown
|
|
114
|
+
* for missing input.
|
|
115
|
+
*/
|
|
116
|
+
export async function showHelp(text: string, requested: boolean) {
|
|
117
|
+
await out(text);
|
|
118
|
+
return requested ? 0 : 2;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function writeRenderResult(
|
|
122
|
+
result: RenderResult,
|
|
123
|
+
outDir?: string,
|
|
124
|
+
): Promise<void> {
|
|
125
|
+
if (result.text) await out(result.text);
|
|
126
|
+
|
|
127
|
+
if (!result.files || result.files.length === 0) return;
|
|
128
|
+
|
|
129
|
+
if (outDir) {
|
|
130
|
+
for (const f of result.files) {
|
|
131
|
+
const path = f.path ? `${outDir}/${f.path}` : outDir;
|
|
132
|
+
await Bun.write(path, f.content);
|
|
133
|
+
await out(`wrote ${path}\n`);
|
|
134
|
+
}
|
|
135
|
+
} else if (result.files.length === 1) {
|
|
136
|
+
await out(result.files[0]!.content);
|
|
137
|
+
} else {
|
|
138
|
+
for (const f of result.files) {
|
|
139
|
+
await out(`--- ${f.path ?? "(unnamed)"} ---\n${f.content}\n`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface OutputOptions {
|
|
145
|
+
exportJson?: string;
|
|
146
|
+
format: FormatName;
|
|
147
|
+
quiet: boolean;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Honors `--export-json`; returns the JSON text when `--format json` will
|
|
152
|
+
* print it (the json renderer's output is exactly this, so serialize
|
|
153
|
+
* once).
|
|
154
|
+
*/
|
|
155
|
+
export async function exportDocument(
|
|
156
|
+
doc: ProfileDocument,
|
|
157
|
+
{ exportJson, format, quiet }: OutputOptions,
|
|
158
|
+
): Promise<string | undefined> {
|
|
159
|
+
const jsonText =
|
|
160
|
+
format === "json" && !quiet ? serializeDocument(doc) : undefined;
|
|
161
|
+
if (exportJson) {
|
|
162
|
+
if (jsonText !== undefined) await saveDocumentText(jsonText, exportJson);
|
|
163
|
+
else await saveDocument(doc, exportJson);
|
|
164
|
+
}
|
|
165
|
+
return jsonText;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Shared tail of time/bench/ab/compare: `--export-json`, then the report
|
|
170
|
+
* unless `--quiet`. `rendererOptions` reaches the renderer verbatim.
|
|
171
|
+
*/
|
|
172
|
+
export async function emitDocument(
|
|
173
|
+
doc: ProfileDocument,
|
|
174
|
+
args: OutputOptions,
|
|
175
|
+
rendererOptions: MinimalRenderOptions = {},
|
|
176
|
+
): Promise<void> {
|
|
177
|
+
const jsonText = await exportDocument(doc, args);
|
|
178
|
+
if (args.quiet) return;
|
|
179
|
+
if (jsonText !== undefined) await out(jsonText);
|
|
180
|
+
else {
|
|
181
|
+
await writeRenderResult(
|
|
182
|
+
await renderers[args.format].render(doc, rendererOptions),
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|