ostia 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +62 -35
- package/package.json +1 -1
- package/src/ab/ab-runner.ts +57 -44
- package/src/ab/index.ts +186 -112
- package/src/baseline/index.ts +3 -9
- package/src/bench/index.ts +177 -123
- package/src/bench/projects.ts +14 -10
- package/src/bench/registry.ts +68 -66
- package/src/bench/run-tasks.ts +26 -23
- package/src/bench/run.ts +2 -1
- package/src/bench/runner.ts +20 -5
- package/src/bench/support.ts +26 -26
- package/src/bench/sweep.ts +6 -4
- package/src/cache/fingerprint.ts +9 -6
- package/src/cache/store.ts +17 -5
- package/src/capture/bunflags.ts +12 -11
- package/src/capture/cpu-parse.ts +36 -24
- package/src/capture/cpu.ts +7 -4
- package/src/capture/frames.ts +7 -1
- package/src/capture/heap-parse.ts +30 -5
- package/src/capture/heap.ts +9 -5
- package/src/capture/inspector.ts +8 -7
- package/src/capture/jsc-parse.ts +8 -8
- package/src/capture/jsc.ts +4 -4
- package/src/ci/index.ts +64 -40
- package/src/cli/flags.ts +42 -43
- package/src/cli/output.ts +29 -35
- package/src/cli/run.ts +95 -95
- package/src/compare/index.ts +39 -32
- package/src/config/env.ts +13 -0
- package/src/config/index.ts +31 -23
- package/src/config/validate.ts +33 -27
- package/src/format.ts +5 -6
- package/src/glob.ts +9 -12
- package/src/index.ts +1 -3
- package/src/ir/cpu.ts +2 -2
- package/src/ir/defined.ts +12 -0
- package/src/ir/document.ts +93 -73
- package/src/ir/fp.ts +7 -10
- package/src/ir/git.ts +4 -3
- package/src/measure/alloc.ts +7 -8
- package/src/measure/cpu.ts +12 -20
- package/src/measure/environment.ts +5 -8
- package/src/measure/inprocess.ts +15 -15
- package/src/measure/instructions.ts +22 -16
- package/src/measure/loop.ts +24 -17
- package/src/measure/noise.ts +8 -8
- package/src/measure/paired.ts +39 -47
- package/src/measure/peak.ts +20 -21
- package/src/measure/timing.ts +23 -23
- package/src/profile.ts +2 -1
- package/src/renderers/collapsed.ts +28 -21
- package/src/renderers/cpu-tree.ts +43 -35
- package/src/renderers/format.ts +16 -26
- package/src/renderers/index.ts +14 -4
- package/src/renderers/json.ts +2 -2
- package/src/renderers/jsonl.ts +11 -7
- package/src/renderers/markdown.ts +54 -36
- package/src/renderers/mermaid.ts +43 -31
- package/src/renderers/minimal.ts +12 -12
- package/src/renderers/paired.ts +31 -37
- package/src/renderers/relative.ts +10 -14
- package/src/renderers/select.ts +17 -39
- package/src/renderers/speedscope.ts +52 -48
- package/src/renderers/terminal.ts +37 -33
- package/src/spawn/index.ts +38 -47
- package/src/stats/bootstrap.ts +56 -58
- package/src/stats/index.ts +16 -12
- package/src/stats/mannwhitney.ts +11 -10
- package/src/time.ts +51 -39
package/src/cli/flags.ts
CHANGED
|
@@ -23,12 +23,11 @@ export const VIZ_FORMATS = [
|
|
|
23
23
|
"cpuprofile",
|
|
24
24
|
] as const;
|
|
25
25
|
|
|
26
|
-
export const REPORT_FORMATS
|
|
26
|
+
export const REPORT_FORMATS: readonly [
|
|
27
|
+
...typeof DOCUMENT_FORMATS,
|
|
28
|
+
...typeof VIZ_FORMATS,
|
|
29
|
+
] = [...DOCUMENT_FORMATS, ...VIZ_FORMATS] as const;
|
|
27
30
|
|
|
28
|
-
/**
|
|
29
|
-
* Integer flag value >= `opts.min` (default 1); `opts.allowAuto` also
|
|
30
|
-
* accepts "auto" as the available job count.
|
|
31
|
-
*/
|
|
32
31
|
export function parseIntFlag(
|
|
33
32
|
name: string,
|
|
34
33
|
raw: string | undefined,
|
|
@@ -78,25 +77,22 @@ type FlagTable = Record<string, FlagDef>;
|
|
|
78
77
|
|
|
79
78
|
const def = (dest: string, spec: FlagSpec): FlagDef => ({ dest, spec });
|
|
80
79
|
|
|
81
|
-
/**
|
|
82
|
-
* Builders for `FlagTable` entries; `dest` is the property set on the
|
|
83
|
-
* parsed args.
|
|
84
|
-
*/
|
|
85
80
|
export const flag = {
|
|
86
|
-
str: (dest: string) => def(dest, { kind: "string" }),
|
|
87
|
-
int: (dest: string, min = 1, allowAuto = false) =>
|
|
81
|
+
str: (dest: string): FlagDef => def(dest, { kind: "string" }),
|
|
82
|
+
int: (dest: string, min: number = 1, allowAuto: boolean = false): FlagDef =>
|
|
88
83
|
def(dest, { kind: "int", min, allowAuto }),
|
|
89
|
-
num: (dest: string, min: number)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
num: (dest: string, min: number): FlagDef =>
|
|
85
|
+
def(dest, { kind: "number", min }),
|
|
86
|
+
on: (dest: string): FlagDef => def(dest, { kind: "bool", value: true }),
|
|
87
|
+
off: (dest: string): FlagDef => def(dest, { kind: "bool", value: false }),
|
|
88
|
+
oneOf: (dest: string, values: readonly string[]): FlagDef =>
|
|
93
89
|
def(dest, { kind: "enum", values }),
|
|
94
90
|
/** Repeatable; each occurrence appends one value. */
|
|
95
|
-
list: (dest: string) => def(dest, { kind: "list" }),
|
|
91
|
+
list: (dest: string): FlagDef => def(dest, { kind: "list" }),
|
|
96
92
|
/** Repeatable; each occurrence is whitespace-split and appended. */
|
|
97
|
-
words: (dest: string) => def(dest, { kind: "words" }),
|
|
93
|
+
words: (dest: string): FlagDef => def(dest, { kind: "words" }),
|
|
98
94
|
/** `--flag[=CODE,...]`: bare means every non-zero exit code. */
|
|
99
|
-
exitCodes: (dest: string) => def(dest, { kind: "exitCodes" }),
|
|
95
|
+
exitCodes: (dest: string): FlagDef => def(dest, { kind: "exitCodes" }),
|
|
100
96
|
};
|
|
101
97
|
|
|
102
98
|
export interface OutputArgs {
|
|
@@ -116,7 +112,9 @@ export const OUTPUT_DEFAULTS = {
|
|
|
116
112
|
help: false,
|
|
117
113
|
} as const;
|
|
118
114
|
|
|
119
|
-
export const RUN_DEFAULTS
|
|
115
|
+
export const RUN_DEFAULTS: typeof OUTPUT_DEFAULTS & {
|
|
116
|
+
readonly noiseCheck: true;
|
|
117
|
+
} = { ...OUTPUT_DEFAULTS, noiseCheck: true } as const;
|
|
120
118
|
|
|
121
119
|
export const HELP_FLAGS: FlagTable = {
|
|
122
120
|
"--help": flag.on("help"),
|
|
@@ -134,10 +132,6 @@ export const NOISE_CHECK_FLAGS: FlagTable = {
|
|
|
134
132
|
"--no-noise-check": flag.off("noiseCheck"),
|
|
135
133
|
};
|
|
136
134
|
|
|
137
|
-
/**
|
|
138
|
-
* `--config PATH`: for the commands that read a config file (bench, ab,
|
|
139
|
-
* compare, ci, baseline).
|
|
140
|
-
*/
|
|
141
135
|
export const CONFIG_FLAGS: FlagTable = {
|
|
142
136
|
"--config": flag.str("config"),
|
|
143
137
|
};
|
|
@@ -146,10 +140,8 @@ export interface ConfigArgs {
|
|
|
146
140
|
config?: string;
|
|
147
141
|
}
|
|
148
142
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
* per-run flags).
|
|
152
|
-
*/
|
|
143
|
+
// Every command that runs measurements takes these, except `ci`, which
|
|
144
|
+
// doesn't take per-run flags.
|
|
153
145
|
export const RUN_FLAGS: FlagTable = {
|
|
154
146
|
...OUTPUT_FLAGS,
|
|
155
147
|
...NOISE_CHECK_FLAGS,
|
|
@@ -157,7 +149,6 @@ export const RUN_FLAGS: FlagTable = {
|
|
|
157
149
|
"--out-dir": flag.str("outDir"),
|
|
158
150
|
};
|
|
159
151
|
|
|
160
|
-
/** Flags shared by `bench` and `ab`. */
|
|
161
152
|
export const SUITE_FLAGS: FlagTable = {
|
|
162
153
|
...RUN_FLAGS,
|
|
163
154
|
...CONFIG_FLAGS,
|
|
@@ -166,6 +157,16 @@ export const SUITE_FLAGS: FlagTable = {
|
|
|
166
157
|
"--bun-flags": flag.words("bunFlags"),
|
|
167
158
|
};
|
|
168
159
|
|
|
160
|
+
// invariant: a repeatable flag's `dest` starts as an array in the
|
|
161
|
+
// command's defaults.
|
|
162
|
+
function listAt(args: object, dest: string): unknown[] {
|
|
163
|
+
const list: unknown = Reflect.get(args, dest);
|
|
164
|
+
if (!Array.isArray(list)) {
|
|
165
|
+
throw new TypeError(`ostia: flag destination "${dest}" isn't an array`);
|
|
166
|
+
}
|
|
167
|
+
return list;
|
|
168
|
+
}
|
|
169
|
+
|
|
169
170
|
interface ParseSpec<T> {
|
|
170
171
|
command: string;
|
|
171
172
|
flags: FlagTable;
|
|
@@ -179,17 +180,15 @@ interface ParseSpec<T> {
|
|
|
179
180
|
rest?: (rest: string[], args: T) => void;
|
|
180
181
|
}
|
|
181
182
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
* value`. Throws `CliUsageError`.
|
|
185
|
-
*/
|
|
183
|
+
// Throws only `CliUsageError`, so the dispatcher can print a `--help`
|
|
184
|
+
// pointer for any parse failure. `--flag=value` equals `--flag value`.
|
|
186
185
|
export function parseFlags<T extends object>(
|
|
187
186
|
argv: string[],
|
|
188
187
|
{ command, flags, args, positional, rest }: ParseSpec<T>,
|
|
189
188
|
): T {
|
|
190
|
-
const
|
|
189
|
+
const set = (dest: string, value: unknown) => Reflect.set(args, dest, value);
|
|
191
190
|
for (let i = 0; i < argv.length; i++) {
|
|
192
|
-
const arg = argv[i]
|
|
191
|
+
const arg = argv[i] ?? "";
|
|
193
192
|
if (arg === "--" && rest) {
|
|
194
193
|
rest(argv.slice(i + 1), args);
|
|
195
194
|
break;
|
|
@@ -211,15 +210,15 @@ export function parseFlags<T extends object>(
|
|
|
211
210
|
if (i + 1 >= argv.length) {
|
|
212
211
|
throw new CliUsageError(`Missing value for ${name}.`);
|
|
213
212
|
}
|
|
214
|
-
return argv[++i]
|
|
213
|
+
return argv[++i] ?? "";
|
|
215
214
|
};
|
|
216
215
|
const { dest, spec } = flagDef;
|
|
217
216
|
switch (spec.kind) {
|
|
218
217
|
case "string":
|
|
219
|
-
|
|
218
|
+
set(dest, value());
|
|
220
219
|
break;
|
|
221
220
|
case "int":
|
|
222
|
-
|
|
221
|
+
set(dest, parseIntFlag(name, value(), spec));
|
|
223
222
|
break;
|
|
224
223
|
case "number": {
|
|
225
224
|
const raw = value();
|
|
@@ -229,20 +228,20 @@ export function parseFlags<T extends object>(
|
|
|
229
228
|
`Invalid ${name} "${raw}": expected a number ≥ ${spec.min}`,
|
|
230
229
|
);
|
|
231
230
|
}
|
|
232
|
-
|
|
231
|
+
set(dest, n);
|
|
233
232
|
break;
|
|
234
233
|
}
|
|
235
234
|
case "bool":
|
|
236
|
-
|
|
235
|
+
set(dest, spec.value);
|
|
237
236
|
break;
|
|
238
237
|
case "list":
|
|
239
|
-
(
|
|
238
|
+
listAt(args, dest).push(value());
|
|
240
239
|
break;
|
|
241
240
|
case "words":
|
|
242
|
-
(
|
|
241
|
+
listAt(args, dest).push(...splitCommand(value()));
|
|
243
242
|
break;
|
|
244
243
|
case "exitCodes":
|
|
245
|
-
(
|
|
244
|
+
listAt(args, dest).push(
|
|
246
245
|
...(eq > 0
|
|
247
246
|
? parseExitCodes(name, arg.slice(eq + 1))
|
|
248
247
|
: Array.from({ length: 255 }, (_, n) => n + 1)),
|
|
@@ -255,7 +254,7 @@ export function parseFlags<T extends object>(
|
|
|
255
254
|
`Invalid ${name} "${raw}": expected one of: ${spec.values.join(", ")}`,
|
|
256
255
|
);
|
|
257
256
|
}
|
|
258
|
-
|
|
257
|
+
set(dest, raw);
|
|
259
258
|
break;
|
|
260
259
|
}
|
|
261
260
|
}
|
package/src/cli/output.ts
CHANGED
|
@@ -12,9 +12,10 @@ import {
|
|
|
12
12
|
type MinimalRenderOptions,
|
|
13
13
|
} from "../renderers/minimal.ts";
|
|
14
14
|
|
|
15
|
-
// Bun.write skips
|
|
16
|
-
// startup
|
|
17
|
-
export const out = (text: string) =>
|
|
15
|
+
// Bun.write, because it skips the Node stream setup process.stdout and
|
|
16
|
+
// process.stderr cost at startup.
|
|
17
|
+
export const out = (text: string): Promise<number> =>
|
|
18
|
+
Bun.write(Bun.stdout, text);
|
|
18
19
|
const errOut = (text: string) => Bun.write(Bun.stderr, text);
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -38,20 +39,20 @@ export type CliErrorCode =
|
|
|
38
39
|
|
|
39
40
|
/** Thrown to abort a command with exit 2; the dispatcher reports it. */
|
|
40
41
|
export class CliError extends Error {
|
|
42
|
+
readonly code: CliErrorCode;
|
|
43
|
+
// Structured detail for the `error` event's `data`.
|
|
44
|
+
readonly data?: Record<string, unknown> | undefined;
|
|
41
45
|
constructor(
|
|
42
|
-
|
|
46
|
+
code: CliErrorCode,
|
|
43
47
|
message: string,
|
|
44
|
-
|
|
45
|
-
readonly data?: Record<string, unknown>,
|
|
48
|
+
data?: Record<string, unknown>,
|
|
46
49
|
) {
|
|
47
50
|
super(message);
|
|
51
|
+
this.code = code;
|
|
52
|
+
this.data = data;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
/**
|
|
52
|
-
* Runs `run`, turning any failure into a `CliError` of `code` with
|
|
53
|
-
* `message` as a prefix.
|
|
54
|
-
*/
|
|
55
56
|
export async function orFail<T>(
|
|
56
57
|
code: CliErrorCode,
|
|
57
58
|
message: string,
|
|
@@ -70,12 +71,11 @@ export async function orFail<T>(
|
|
|
70
71
|
|
|
71
72
|
const MACHINE_FORMATS = new Set(["minimal", "json", "jsonl"]);
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
* machine `--format` was asked for.
|
|
76
|
-
*/
|
|
74
|
+
// Machine errors are for scripts and agents: stderr isn't a terminal, or a
|
|
75
|
+
// machine `--format` was asked for.
|
|
77
76
|
async function wantsMachineErrors(): Promise<boolean> {
|
|
78
|
-
//
|
|
77
|
+
// perf: imported lazily, since loading node:tty up front costs every
|
|
78
|
+
// invocation ~15ms.
|
|
79
79
|
const { isatty } = await import("node:tty");
|
|
80
80
|
if (!isatty(2)) return true;
|
|
81
81
|
const argv = process.argv.slice(2);
|
|
@@ -87,10 +87,8 @@ async function wantsMachineErrors(): Promise<boolean> {
|
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
* line (first line of `message` only). Never touches stdout.
|
|
93
|
-
*/
|
|
90
|
+
// Writes `message` to stderr, then for a machine reader one JSON `error`
|
|
91
|
+
// line (first line of `message` only). Never touches stdout.
|
|
94
92
|
export async function writeCliError(
|
|
95
93
|
code: CliErrorCode,
|
|
96
94
|
message: string,
|
|
@@ -109,11 +107,10 @@ export async function writeCliError(
|
|
|
109
107
|
);
|
|
110
108
|
}
|
|
111
109
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
export async function showHelp(text: string, requested: boolean) {
|
|
110
|
+
export async function showHelp(
|
|
111
|
+
text: string,
|
|
112
|
+
requested: boolean,
|
|
113
|
+
): Promise<0 | 2> {
|
|
117
114
|
await out(text);
|
|
118
115
|
return requested ? 0 : 2;
|
|
119
116
|
}
|
|
@@ -126,14 +123,15 @@ export async function writeRenderResult(
|
|
|
126
123
|
|
|
127
124
|
if (!result.files || result.files.length === 0) return;
|
|
128
125
|
|
|
126
|
+
const only = result.files.length === 1 ? result.files[0] : undefined;
|
|
129
127
|
if (outDir) {
|
|
130
128
|
for (const f of result.files) {
|
|
131
129
|
const path = f.path ? `${outDir}/${f.path}` : outDir;
|
|
132
130
|
await Bun.write(path, f.content);
|
|
133
131
|
await out(`wrote ${path}\n`);
|
|
134
132
|
}
|
|
135
|
-
} else if (
|
|
136
|
-
await out(
|
|
133
|
+
} else if (only) {
|
|
134
|
+
await out(only.content);
|
|
137
135
|
} else {
|
|
138
136
|
for (const f of result.files) {
|
|
139
137
|
await out(`--- ${f.path ?? "(unnamed)"} ---\n${f.content}\n`);
|
|
@@ -147,11 +145,9 @@ interface OutputOptions {
|
|
|
147
145
|
quiet: boolean;
|
|
148
146
|
}
|
|
149
147
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
* once).
|
|
154
|
-
*/
|
|
148
|
+
// Honors `--export-json`; returns the JSON text when `--format json` will
|
|
149
|
+
// print it (the json renderer's output is exactly this, so serialize
|
|
150
|
+
// once).
|
|
155
151
|
export async function exportDocument(
|
|
156
152
|
doc: ProfileDocument,
|
|
157
153
|
{ exportJson, format, quiet }: OutputOptions,
|
|
@@ -165,10 +161,8 @@ export async function exportDocument(
|
|
|
165
161
|
return jsonText;
|
|
166
162
|
}
|
|
167
163
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
* unless `--quiet`. `rendererOptions` reaches the renderer verbatim.
|
|
171
|
-
*/
|
|
164
|
+
// Shared tail of time/bench/ab/compare: `--export-json`, then the report
|
|
165
|
+
// unless `--quiet`. `rendererOptions` reaches the renderer verbatim.
|
|
172
166
|
export async function emitDocument(
|
|
173
167
|
doc: ProfileDocument,
|
|
174
168
|
args: OutputOptions,
|