ostia 0.4.0 → 0.5.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/README.md +4 -4
- package/docs/agent-protocol.md +13 -9
- package/docs/cli.md +90 -73
- package/docs/config.md +2 -2
- package/docs/document-schema.md +14 -12
- package/docs/library.md +17 -15
- package/docs/preload-recipes.md +4 -4
- package/docs/statistics.md +10 -10
- package/index.d.ts +128 -58
- package/package.json +1 -1
- package/src/ab/ab-runner.ts +6 -6
- package/src/ab/index.ts +15 -6
- package/src/bench/index.ts +12 -3
- package/src/bench/registry.ts +6 -4
- package/src/bench/run-tasks.ts +2 -2
- package/src/bench/runner.ts +2 -2
- package/src/bench/support.ts +8 -4
- package/src/bench/sweep.ts +2 -2
- package/src/cache/fingerprint.ts +2 -2
- package/src/capture/bunflags.ts +2 -2
- package/src/capture/cpu.ts +2 -2
- package/src/capture/heap-parse.ts +2 -2
- package/src/ci/index.ts +7 -6
- package/src/cli/agent.ts +54 -0
- package/src/cli/flags.ts +50 -9
- package/src/cli/help.ts +29 -11
- package/src/cli/output.ts +6 -3
- package/src/cli/run.ts +29 -5
- package/src/compare/index.ts +4 -4
- package/src/config/index.ts +14 -10
- package/src/config/validate.ts +4 -4
- package/src/glob.ts +2 -2
- package/src/ir/document.ts +2 -2
- package/src/ir/types.ts +47 -24
- package/src/measure/alloc.ts +2 -2
- package/src/measure/cpu.ts +2 -2
- package/src/measure/environment.ts +11 -6
- package/src/measure/inprocess.ts +14 -10
- package/src/measure/instructions.ts +2 -2
- package/src/measure/noise.ts +51 -13
- package/src/measure/paired.ts +2 -2
- package/src/measure/peak.ts +4 -4
- package/src/measure/timing.ts +18 -3
- package/src/profile.ts +6 -4
- package/src/renderers/collapsed.ts +2 -2
- package/src/renderers/concise.ts +148 -0
- package/src/renderers/format.ts +13 -4
- package/src/renderers/index.ts +6 -0
- package/src/renderers/markdown.ts +2 -2
- package/src/renderers/mermaid.ts +2 -2
- package/src/renderers/minimal.ts +8 -7
- package/src/renderers/relative.ts +2 -2
- package/src/renderers/select.ts +2 -2
- package/src/renderers/terminal.ts +6 -3
- package/src/renderers/types.ts +3 -0
- package/src/spawn/index.ts +47 -14
- package/src/stats/bootstrap.ts +2 -2
- package/src/stats/index.ts +2 -2
- package/src/time.ts +75 -10
package/src/bench/sweep.ts
CHANGED
|
@@ -25,9 +25,9 @@ export function sweep<T extends Record<string, readonly unknown[]>>(
|
|
|
25
25
|
const key = keys[index];
|
|
26
26
|
if (key === undefined) {
|
|
27
27
|
withCurrentParams(
|
|
28
|
-
// eslint-disable-next-line typescript/consistent-type-assertions
|
|
28
|
+
// eslint-disable-next-line typescript/consistent-type-assertions -- `dims` may hold any value, and params carry the point as given
|
|
29
29
|
point as Record<string, string | number | boolean>,
|
|
30
|
-
// eslint-disable-next-line typescript/consistent-type-assertions
|
|
30
|
+
// eslint-disable-next-line typescript/consistent-type-assertions -- every key of `dims` is set by now, which TS can't follow through a mapped type
|
|
31
31
|
() => fn(point as SweepPoint<T>),
|
|
32
32
|
);
|
|
33
33
|
return;
|
package/src/cache/fingerprint.ts
CHANGED
|
@@ -45,8 +45,8 @@ export async function computeInputsDigest(
|
|
|
45
45
|
const k = next++;
|
|
46
46
|
const path = paths[k];
|
|
47
47
|
if (path === undefined) continue;
|
|
48
|
-
// `resolve`, not a join, since absolute patterns scan to
|
|
49
|
-
// paths.
|
|
48
|
+
// `resolve`, not a join, since absolute patterns scan to
|
|
49
|
+
// absolute paths.
|
|
50
50
|
const buf = await Bun.file(resolve(cwd, path)).arrayBuffer();
|
|
51
51
|
entries[k] = {
|
|
52
52
|
path,
|
package/src/capture/bunflags.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { processEnv } from "../config/env.ts";
|
|
|
2
2
|
import type { Warning } from "../ir/types.ts";
|
|
3
3
|
|
|
4
4
|
// BUN_OPTIONS is split on whitespace; a backslash escapes a space or quote
|
|
5
|
-
// (Bun doesn't honour quoting, and a literal backslash can't
|
|
6
|
-
// expressed).
|
|
5
|
+
// (Bun doesn't honour quoting, and a literal backslash can't
|
|
6
|
+
// be expressed).
|
|
7
7
|
function escapeBunOption(flag: string): string {
|
|
8
8
|
return flag.replace(/[\s"']/g, "\\$&");
|
|
9
9
|
}
|
package/src/capture/cpu.ts
CHANGED
|
@@ -14,8 +14,8 @@ interface CpuCaptureResult {
|
|
|
14
14
|
warnings: Warning[];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
// BUN_CPU_PROFILE is documented but doesn't work on Bun 1.4.0,
|
|
18
|
-
// flags/BUN_OPTIONS.
|
|
17
|
+
// BUN_CPU_PROFILE is documented but doesn't work on Bun 1.4.0,
|
|
18
|
+
// hence flags/BUN_OPTIONS.
|
|
19
19
|
export async function runCpuCapture(
|
|
20
20
|
opts: CpuCaptureOptions,
|
|
21
21
|
): Promise<CpuCaptureResult> {
|
|
@@ -12,8 +12,8 @@ export interface RawHeapSnapshot {
|
|
|
12
12
|
strings: string[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
// Checks only the arrays `parseHeapSnapshot` walks and the count
|
|
16
|
-
// reports.
|
|
15
|
+
// Checks only the arrays `parseHeapSnapshot` walks and the count
|
|
16
|
+
// it reports.
|
|
17
17
|
export function isRawHeapSnapshot(value: unknown): value is RawHeapSnapshot {
|
|
18
18
|
if (typeof value !== "object" || value === null) return false;
|
|
19
19
|
if (!("nodes" in value) || !Array.isArray(value.nodes)) return false;
|
package/src/ci/index.ts
CHANGED
|
@@ -38,8 +38,9 @@ interface CiOptions {
|
|
|
38
38
|
/**
|
|
39
39
|
* Abort kills in-flight trials and suite processes and stops scheduling
|
|
40
40
|
* workloads. `runCi` then resolves with `aborted: true`: the document
|
|
41
|
-
* holds what completed, nothing is compared, and no run is written to
|
|
42
|
-
* cache.
|
|
41
|
+
* holds what completed, nothing is compared, and no run is written to
|
|
42
|
+
* the cache.
|
|
43
|
+
*/
|
|
43
44
|
signal?: AbortSignal;
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -83,8 +84,8 @@ interface CiSummary {
|
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
|
-
* Base of the two baseline errors, so the CLI reports either
|
|
87
|
-
* `baseline-missing`.
|
|
87
|
+
* Base of the two baseline errors, so the CLI reports either
|
|
88
|
+
* as `baseline-missing`.
|
|
88
89
|
*/
|
|
89
90
|
export class BaselineError extends OstiaUsageError {}
|
|
90
91
|
|
|
@@ -145,8 +146,8 @@ async function measureSuiteWorkloads(
|
|
|
145
146
|
`Workload suites ${JSON.stringify(suites)} matched no files.`,
|
|
146
147
|
);
|
|
147
148
|
}
|
|
148
|
-
// Same CLI-over-config resolution as `ostia bench`; only the
|
|
149
|
-
// differ.
|
|
149
|
+
// Same CLI-over-config resolution as `ostia bench`; only the
|
|
150
|
+
// defaults differ.
|
|
150
151
|
const benchOpts = await resolveBenchOptions(
|
|
151
152
|
{ suites: suiteFiles, preload: [], bunFlags: [], noiseCheck: false },
|
|
152
153
|
config.bench,
|
package/src/cli/agent.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { processEnv } from "../config/env.ts";
|
|
2
|
+
|
|
3
|
+
// The variables a coding agent sets, as svelte-typecheck and svelte-lint
|
|
4
|
+
// read them, after `bun check`: `AGENT` and `CLAUDECODE`, `AI_AGENT`, the
|
|
5
|
+
// shared name, and Codex's `CODEX_CI` and `CODEX_THREAD_ID`. Kept the same
|
|
6
|
+
// so the three tools agree on what an agent is (metonym/ostia#53).
|
|
7
|
+
const AGENT_ENV = [
|
|
8
|
+
"AGENT",
|
|
9
|
+
"AI_AGENT",
|
|
10
|
+
"CLAUDECODE",
|
|
11
|
+
"CODEX_CI",
|
|
12
|
+
"CODEX_THREAD_ID",
|
|
13
|
+
] as const;
|
|
14
|
+
|
|
15
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
16
|
+
|
|
17
|
+
// The first agent variable set to anything but empty or `0`, which a
|
|
18
|
+
// person sets to say "not an agent" without unsetting it.
|
|
19
|
+
export function agentVariable(env: Env = processEnv()): string | undefined {
|
|
20
|
+
return AGENT_ENV.find((name) => {
|
|
21
|
+
const value = env[name];
|
|
22
|
+
return value !== undefined && value !== "" && value !== "0";
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function asksForFormat(argv: readonly string[]): boolean {
|
|
27
|
+
return argv.some(
|
|
28
|
+
(arg) =>
|
|
29
|
+
arg === "--format" ||
|
|
30
|
+
arg.startsWith("--format=") ||
|
|
31
|
+
arg === "--json" ||
|
|
32
|
+
arg.startsWith("--json="),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// `argv` with the format to use when it names none: `OSTIA_FORMAT` when
|
|
37
|
+
// set, else `concise` for a coding agent, with a line saying so, so a
|
|
38
|
+
// person reading the agent's log knows why the table is missing.
|
|
39
|
+
export function withDefaultFormat(
|
|
40
|
+
argv: readonly string[],
|
|
41
|
+
env: Env = processEnv(),
|
|
42
|
+
): { argv: string[]; notice?: string } {
|
|
43
|
+
if (asksForFormat(argv)) return { argv: [...argv] };
|
|
44
|
+
const chosen = env.OSTIA_FORMAT;
|
|
45
|
+
if (chosen !== undefined && chosen !== "") {
|
|
46
|
+
return { argv: [...argv, "--format", chosen] };
|
|
47
|
+
}
|
|
48
|
+
const agent = agentVariable(env);
|
|
49
|
+
if (agent === undefined) return { argv: [...argv] };
|
|
50
|
+
return {
|
|
51
|
+
argv: [...argv, "--format", "concise"],
|
|
52
|
+
notice: `ostia: ${agent} is set, so --format concise; pass --format or set OSTIA_FORMAT for another.\n`,
|
|
53
|
+
};
|
|
54
|
+
}
|
package/src/cli/flags.ts
CHANGED
|
@@ -13,9 +13,18 @@ const DOCUMENT_FORMATS = [
|
|
|
13
13
|
"json",
|
|
14
14
|
"jsonl",
|
|
15
15
|
"markdown",
|
|
16
|
-
"
|
|
16
|
+
"events",
|
|
17
|
+
"concise",
|
|
17
18
|
] as const;
|
|
18
19
|
|
|
20
|
+
// The names a format went by, or shares with another tool: `minimal` was
|
|
21
|
+
// `events`' name until 0.5.0, and svelte-typecheck and svelte-lint call
|
|
22
|
+
// their agent format `agent`.
|
|
23
|
+
export const FORMAT_ALIASES: Readonly<Record<string, string>> = {
|
|
24
|
+
minimal: "events",
|
|
25
|
+
agent: "concise",
|
|
26
|
+
};
|
|
27
|
+
|
|
19
28
|
export const VIZ_FORMATS = [
|
|
20
29
|
"collapsed",
|
|
21
30
|
"mermaid",
|
|
@@ -63,7 +72,12 @@ type FlagSpec =
|
|
|
63
72
|
| { kind: "int"; min?: number; allowAuto?: boolean }
|
|
64
73
|
| { kind: "number"; min: number }
|
|
65
74
|
| { kind: "bool"; value: boolean }
|
|
66
|
-
| {
|
|
75
|
+
| {
|
|
76
|
+
kind: "enum";
|
|
77
|
+
values: readonly string[];
|
|
78
|
+
aliases?: Readonly<Record<string, string>>;
|
|
79
|
+
}
|
|
80
|
+
| { kind: "const"; value: string }
|
|
67
81
|
| { kind: "list" }
|
|
68
82
|
| { kind: "words" }
|
|
69
83
|
| { kind: "exitCodes" };
|
|
@@ -85,8 +99,15 @@ export const flag = {
|
|
|
85
99
|
def(dest, { kind: "number", min }),
|
|
86
100
|
on: (dest: string): FlagDef => def(dest, { kind: "bool", value: true }),
|
|
87
101
|
off: (dest: string): FlagDef => def(dest, { kind: "bool", value: false }),
|
|
88
|
-
oneOf: (
|
|
89
|
-
|
|
102
|
+
oneOf: (
|
|
103
|
+
dest: string,
|
|
104
|
+
values: readonly string[],
|
|
105
|
+
aliases?: Readonly<Record<string, string>>,
|
|
106
|
+
): FlagDef =>
|
|
107
|
+
def(dest, { kind: "enum", values, ...(aliases && { aliases }) }),
|
|
108
|
+
/** Sets `dest` to `value`; `--flag=false` leaves it, as `--json=false`. */
|
|
109
|
+
is: (dest: string, value: string): FlagDef =>
|
|
110
|
+
def(dest, { kind: "const", value }),
|
|
90
111
|
/** Repeatable; each occurrence appends one value. */
|
|
91
112
|
list: (dest: string): FlagDef => def(dest, { kind: "list" }),
|
|
92
113
|
/** Repeatable; each occurrence is whitespace-split and appended. */
|
|
@@ -104,6 +125,7 @@ export interface OutputArgs {
|
|
|
104
125
|
|
|
105
126
|
export interface RunArgs extends OutputArgs {
|
|
106
127
|
noiseCheck: boolean;
|
|
128
|
+
noiseBudgetMs?: number;
|
|
107
129
|
}
|
|
108
130
|
|
|
109
131
|
export const OUTPUT_DEFAULTS = {
|
|
@@ -124,7 +146,8 @@ export const HELP_FLAGS: FlagTable = {
|
|
|
124
146
|
export const OUTPUT_FLAGS: FlagTable = {
|
|
125
147
|
...HELP_FLAGS,
|
|
126
148
|
"--export-json": flag.str("exportJson"),
|
|
127
|
-
"--format": flag.oneOf("format", DOCUMENT_FORMATS),
|
|
149
|
+
"--format": flag.oneOf("format", DOCUMENT_FORMATS, FORMAT_ALIASES),
|
|
150
|
+
"--json": flag.is("format", "json"),
|
|
128
151
|
"--quiet": flag.on("quiet"),
|
|
129
152
|
};
|
|
130
153
|
|
|
@@ -132,6 +155,12 @@ export const NOISE_CHECK_FLAGS: FlagTable = {
|
|
|
132
155
|
"--no-noise-check": flag.off("noiseCheck"),
|
|
133
156
|
};
|
|
134
157
|
|
|
158
|
+
// Apart from NOISE_CHECK_FLAGS, since `ci` takes those but its noise
|
|
159
|
+
// check follows the config, so it must reject this one.
|
|
160
|
+
const NOISE_BUDGET_FLAGS: FlagTable = {
|
|
161
|
+
"--noise-budget": flag.int("noiseBudgetMs"),
|
|
162
|
+
};
|
|
163
|
+
|
|
135
164
|
export const CONFIG_FLAGS: FlagTable = {
|
|
136
165
|
"--config": flag.str("config"),
|
|
137
166
|
};
|
|
@@ -145,6 +174,7 @@ export interface ConfigArgs {
|
|
|
145
174
|
export const RUN_FLAGS: FlagTable = {
|
|
146
175
|
...OUTPUT_FLAGS,
|
|
147
176
|
...NOISE_CHECK_FLAGS,
|
|
177
|
+
...NOISE_BUDGET_FLAGS,
|
|
148
178
|
"--timeout": flag.int("timeoutMs"),
|
|
149
179
|
"--out-dir": flag.str("outDir"),
|
|
150
180
|
};
|
|
@@ -174,8 +204,8 @@ interface ParseSpec<T> {
|
|
|
174
204
|
/** Receives each bare word; omitted, a bare word is an unknown-flag error. */
|
|
175
205
|
positional?: (arg: string, args: T) => void;
|
|
176
206
|
/**
|
|
177
|
-
* Receives everything after a `--`, verbatim; omitted, `--` is an
|
|
178
|
-
* flag.
|
|
207
|
+
* Receives everything after a `--`, verbatim; omitted, `--` is an
|
|
208
|
+
* unknown flag.
|
|
179
209
|
*/
|
|
180
210
|
rest?: (rest: string[], args: T) => void;
|
|
181
211
|
}
|
|
@@ -249,12 +279,23 @@ export function parseFlags<T extends object>(
|
|
|
249
279
|
break;
|
|
250
280
|
case "enum": {
|
|
251
281
|
const raw = value();
|
|
252
|
-
|
|
282
|
+
const resolved = spec.aliases?.[raw] ?? raw;
|
|
283
|
+
if (!spec.values.includes(resolved)) {
|
|
253
284
|
throw new CliUsageError(
|
|
254
285
|
`Invalid ${name} "${raw}": expected one of: ${spec.values.join(", ")}`,
|
|
255
286
|
);
|
|
256
287
|
}
|
|
257
|
-
set(dest,
|
|
288
|
+
set(dest, resolved);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
case "const": {
|
|
292
|
+
const raw = eq > 0 ? arg.slice(eq + 1) : "true";
|
|
293
|
+
if (raw !== "true" && raw !== "false") {
|
|
294
|
+
throw new CliUsageError(
|
|
295
|
+
`Invalid ${name} "${raw}": expected true or false`,
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
if (raw === "true") set(dest, spec.value);
|
|
258
299
|
break;
|
|
259
300
|
}
|
|
260
301
|
}
|
package/src/cli/help.ts
CHANGED
|
@@ -11,6 +11,9 @@ Flags:
|
|
|
11
11
|
--warmup N discarded warmup trials (default: 3)
|
|
12
12
|
--no-interleave run commands one after another instead of round-robin
|
|
13
13
|
--prepare CMD run before every trial, unmeasured; once, or once per command
|
|
14
|
+
--shell SH run each command, and --prepare, as SH -c CMD (sh, bash)
|
|
15
|
+
--save-output DIR save each trial's output as DIR/<command>/trial-N.log
|
|
16
|
+
--show-output pass each trial's output to stderr
|
|
14
17
|
--time-source REGEX take each trial's time from capture group 1 in the command's output
|
|
15
18
|
--time-unit UNIT unit of --time-source: ns | us | ms | s (default: ms); needs --time-source
|
|
16
19
|
--cpu capture one extra CPU-profile trial
|
|
@@ -19,9 +22,12 @@ Flags:
|
|
|
19
22
|
--timeout MS kill a trial or --prepare hook after MS
|
|
20
23
|
--ignore-failure[=CODE,...] treat these exit codes (bare: all) as success
|
|
21
24
|
--out-dir PATH artifact directory (default: node_modules/.cache/ostia)
|
|
22
|
-
--no-noise-check skip the
|
|
25
|
+
--no-noise-check skip the noise-floor checks (50 to 75 ms in all)
|
|
26
|
+
--noise-budget MS sample the noise floor for exactly MS, start and end
|
|
23
27
|
--export-json PATH write the ProfileDocument to PATH
|
|
24
|
-
--format FORMAT table | json | jsonl | markdown
|
|
28
|
+
--format FORMAT table | concise | events | json | jsonl | markdown (default: table,
|
|
29
|
+
concise under a coding agent; OSTIA_FORMAT sets another)
|
|
30
|
+
--json same as --format json
|
|
25
31
|
--quiet don't print the report
|
|
26
32
|
--help show this message
|
|
27
33
|
|
|
@@ -60,9 +66,12 @@ Flags:
|
|
|
60
66
|
--timeout MS kill a suite (or isolated task) process after MS
|
|
61
67
|
--out-dir PATH scratch directory (default: node_modules/.cache/ostia)
|
|
62
68
|
--config PATH read this config file instead of ostia.config.ts/.json
|
|
63
|
-
--no-noise-check skip the
|
|
69
|
+
--no-noise-check skip the noise-floor checks (50 to 75 ms in all)
|
|
70
|
+
--noise-budget MS sample the noise floor for exactly MS, start and end
|
|
64
71
|
--export-json PATH write the ProfileDocument to PATH
|
|
65
|
-
--format FORMAT table | json | jsonl | markdown
|
|
72
|
+
--format FORMAT table | concise | events | json | jsonl | markdown (default: table,
|
|
73
|
+
concise under a coding agent; OSTIA_FORMAT sets another)
|
|
74
|
+
--json same as --format json
|
|
66
75
|
--quiet don't print the report
|
|
67
76
|
--help show this message
|
|
68
77
|
|
|
@@ -106,9 +115,12 @@ Flags:
|
|
|
106
115
|
--keep-trees N base trees to keep cached, least recently used go first (default: 5)
|
|
107
116
|
--clean remove every cached base tree, then exit
|
|
108
117
|
--config PATH read this config file instead of ostia.config.ts/.json
|
|
109
|
-
--no-noise-check skip the
|
|
118
|
+
--no-noise-check skip the noise-floor checks (50 to 75 ms in all)
|
|
119
|
+
--noise-budget MS sample the noise floor for exactly MS, start and end
|
|
110
120
|
--export-json PATH write the ProfileDocument to PATH
|
|
111
|
-
--format FORMAT table | json | jsonl | markdown
|
|
121
|
+
--format FORMAT table | concise | events | json | jsonl | markdown (default: table,
|
|
122
|
+
concise under a coding agent; OSTIA_FORMAT sets another)
|
|
123
|
+
--json same as --format json
|
|
112
124
|
--progress print progress to stderr (default: when stderr is a terminal and not
|
|
113
125
|
--quiet); --no-progress turns it off
|
|
114
126
|
--quiet don't print the report
|
|
@@ -127,7 +139,7 @@ unknown ref, a failed setup or suite), 130 Ctrl-C.
|
|
|
127
139
|
Examples:
|
|
128
140
|
ostia ab bench/parse.bench.ts
|
|
129
141
|
ostia ab bench/*.ts --base origin/main --rounds 21
|
|
130
|
-
ostia ab bench/*.ts --filter parse --format
|
|
142
|
+
ostia ab bench/*.ts --filter parse --format events
|
|
131
143
|
ostia ab bench/*.ts --metric instructions --threshold 3
|
|
132
144
|
ostia ab bench/*.ts --base-setup "bun scripts/generate.ts"
|
|
133
145
|
ostia ab bench/paint.bench.ts --alloc --peak-mem
|
|
@@ -145,7 +157,9 @@ Flags:
|
|
|
145
157
|
--baseline PATH the base document, when only the candidate is positional
|
|
146
158
|
--config PATH read thresholds from this config file instead of ostia.config.ts/.json
|
|
147
159
|
--export-json PATH write the candidate document with comparisons to PATH
|
|
148
|
-
--format FORMAT table | json | jsonl | markdown
|
|
160
|
+
--format FORMAT table | concise | events | json | jsonl | markdown (default: table,
|
|
161
|
+
concise under a coding agent; OSTIA_FORMAT sets another)
|
|
162
|
+
--json same as --format json
|
|
149
163
|
--quiet don't print the report
|
|
150
164
|
--help show this message
|
|
151
165
|
|
|
@@ -163,7 +177,9 @@ Formats:
|
|
|
163
177
|
json pretty JSON document
|
|
164
178
|
jsonl one metadata line, then one line per measurement
|
|
165
179
|
markdown agent- and human-readable report
|
|
166
|
-
|
|
180
|
+
concise one line per task, then its warnings (alias: agent)
|
|
181
|
+
events one compact JSON object per timing measurement, for scripts and CI
|
|
182
|
+
(alias: minimal)
|
|
167
183
|
collapsed folded stacks: "root;a;b 42" - flamegraph.pl and most flame tooling
|
|
168
184
|
mermaid call tree, top-15 frames by total time (never the whole profile)
|
|
169
185
|
speedscope sampled profile JSON for speedscope.app
|
|
@@ -194,9 +210,11 @@ Flags:
|
|
|
194
210
|
--save-baseline after a pass, save this run as the new baseline (always measures
|
|
195
211
|
fresh: the cache is not used)
|
|
196
212
|
--config PATH read this config file instead of ostia.config.ts/.json
|
|
197
|
-
--no-noise-check skip the
|
|
213
|
+
--no-noise-check skip the noise-floor checks (50 to 75 ms in all)
|
|
198
214
|
--export-json PATH write the candidate document with comparisons to PATH
|
|
199
|
-
--format FORMAT table | json | jsonl | markdown
|
|
215
|
+
--format FORMAT table | concise | events | json | jsonl | markdown (default: table,
|
|
216
|
+
concise under a coding agent; OSTIA_FORMAT sets another)
|
|
217
|
+
--json same as --format json
|
|
200
218
|
--quiet don't print the report
|
|
201
219
|
--help show this message
|
|
202
220
|
|
package/src/cli/output.ts
CHANGED
|
@@ -69,7 +69,8 @@ export async function orFail<T>(
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
// `minimal` too, since this reads argv before the alias resolves.
|
|
73
|
+
const MACHINE_FORMATS = new Set(["events", "minimal", "json", "jsonl"]);
|
|
73
74
|
|
|
74
75
|
// Machine errors are for scripts and agents: stderr isn't a terminal, or a
|
|
75
76
|
// machine `--format` was asked for.
|
|
@@ -81,6 +82,8 @@ async function wantsMachineErrors(): Promise<boolean> {
|
|
|
81
82
|
const argv = process.argv.slice(2);
|
|
82
83
|
return argv.some(
|
|
83
84
|
(arg, i) =>
|
|
85
|
+
arg === "--json" ||
|
|
86
|
+
arg === "--json=true" ||
|
|
84
87
|
(arg === "--format" && MACHINE_FORMATS.has(argv[i + 1] ?? "")) ||
|
|
85
88
|
(arg.startsWith("--format=") &&
|
|
86
89
|
MACHINE_FORMATS.has(arg.slice("--format=".length))),
|
|
@@ -146,8 +149,8 @@ interface OutputOptions {
|
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
// Honors `--export-json`; returns the JSON text when `--format json` will
|
|
149
|
-
// print it (the json renderer's output is exactly this, so
|
|
150
|
-
// once).
|
|
152
|
+
// print it (the json renderer's output is exactly this, so
|
|
153
|
+
// serialize once).
|
|
151
154
|
export async function exportDocument(
|
|
152
155
|
doc: ProfileDocument,
|
|
153
156
|
{ exportJson, format, quiet }: OutputOptions,
|
package/src/cli/run.ts
CHANGED
|
@@ -40,11 +40,13 @@ import { formatGit, workloadLabel } from "../renderers/format.ts";
|
|
|
40
40
|
import { type FormatName, renderers } from "../renderers/index.ts";
|
|
41
41
|
import type { MinimalProtocolContext } from "../renderers/minimal.ts";
|
|
42
42
|
import type { TimeSource, TimeUnit } from "../spawn/index.ts";
|
|
43
|
+
import { withDefaultFormat } from "./agent.ts";
|
|
43
44
|
import {
|
|
44
45
|
CliUsageError,
|
|
45
46
|
CONFIG_FLAGS,
|
|
46
47
|
type ConfigArgs,
|
|
47
48
|
flag,
|
|
49
|
+
FORMAT_ALIASES,
|
|
48
50
|
HELP_FLAGS,
|
|
49
51
|
NOISE_CHECK_FLAGS,
|
|
50
52
|
OUTPUT_DEFAULTS,
|
|
@@ -150,8 +152,8 @@ const TIME_UNITS: readonly TimeUnit[] = ["ns", "us", "ms", "s"];
|
|
|
150
152
|
interface TimeArgs extends RunArgs {
|
|
151
153
|
commands: string[];
|
|
152
154
|
/**
|
|
153
|
-
* Everything after `--`: one more command, whose argv is
|
|
154
|
-
* whitespace-split.
|
|
155
|
+
* Everything after `--`: one more command, whose argv is
|
|
156
|
+
* never whitespace-split.
|
|
155
157
|
*/
|
|
156
158
|
argvCommand: string[];
|
|
157
159
|
/** One entry applies to every command; otherwise one per command. */
|
|
@@ -169,6 +171,9 @@ interface TimeArgs extends RunArgs {
|
|
|
169
171
|
timeoutMs?: number;
|
|
170
172
|
ignoreExitCodes: number[];
|
|
171
173
|
outDir?: string;
|
|
174
|
+
shell?: string;
|
|
175
|
+
saveOutput?: string;
|
|
176
|
+
showOutput?: boolean;
|
|
172
177
|
}
|
|
173
178
|
|
|
174
179
|
const TIME_FLAGS = {
|
|
@@ -179,6 +184,9 @@ const TIME_FLAGS = {
|
|
|
179
184
|
"--warmup": flag.int("warmup", 0),
|
|
180
185
|
"--no-interleave": flag.off("interleave"),
|
|
181
186
|
"--prepare": flag.list("prepare"),
|
|
187
|
+
"--shell": flag.str("shell"),
|
|
188
|
+
"--save-output": flag.str("saveOutput"),
|
|
189
|
+
"--show-output": flag.on("showOutput"),
|
|
182
190
|
"--time-source": flag.str("timeSource"),
|
|
183
191
|
"--time-unit": flag.oneOf("timeUnit", TIME_UNITS),
|
|
184
192
|
"--cpu": flag.on("cpu"),
|
|
@@ -284,6 +292,10 @@ async function timeCommand(argv: string[]): Promise<number> {
|
|
|
284
292
|
ignoreExitCodes: parsed.ignoreExitCodes,
|
|
285
293
|
outDir: parsed.outDir,
|
|
286
294
|
noiseCheck: parsed.noiseCheck,
|
|
295
|
+
noiseBudgetMs: parsed.noiseBudgetMs,
|
|
296
|
+
shell: parsed.shell,
|
|
297
|
+
saveOutput: parsed.saveOutput,
|
|
298
|
+
showOutput: parsed.showOutput,
|
|
287
299
|
}),
|
|
288
300
|
signal,
|
|
289
301
|
}),
|
|
@@ -514,6 +526,7 @@ async function abCommand(argv: string[]): Promise<number> {
|
|
|
514
526
|
timeoutMs,
|
|
515
527
|
outDir,
|
|
516
528
|
noiseCheck,
|
|
529
|
+
noiseBudgetMs,
|
|
517
530
|
} = await resolveBenchOptions(parsed, config?.bench);
|
|
518
531
|
if (suites.length === 0) return showHelp(AB_HELP, false);
|
|
519
532
|
|
|
@@ -553,6 +566,7 @@ async function abCommand(argv: string[]): Promise<number> {
|
|
|
553
566
|
outDir,
|
|
554
567
|
keepTrees: parsed.keepTrees ?? config?.ab?.keepTrees,
|
|
555
568
|
noiseCheck,
|
|
569
|
+
noiseBudgetMs,
|
|
556
570
|
}),
|
|
557
571
|
signal,
|
|
558
572
|
...definedFields({ onProgress: progress?.onProgress }),
|
|
@@ -718,7 +732,7 @@ interface ReportArgs extends ConfigArgs {
|
|
|
718
732
|
|
|
719
733
|
const REPORT_FLAGS = {
|
|
720
734
|
...HELP_FLAGS,
|
|
721
|
-
"--format": flag.oneOf("format", REPORT_FORMATS),
|
|
735
|
+
"--format": flag.oneOf("format", REPORT_FORMATS, FORMAT_ALIASES),
|
|
722
736
|
"--measurement": flag.str("measurementId"),
|
|
723
737
|
"--out-dir": flag.str("outDir"),
|
|
724
738
|
};
|
|
@@ -1090,8 +1104,18 @@ function baselineCommand(argv: string[]): Promise<number> {
|
|
|
1090
1104
|
);
|
|
1091
1105
|
}
|
|
1092
1106
|
|
|
1093
|
-
|
|
1094
|
-
|
|
1107
|
+
// The commands that take `--format`, so the only ones a default
|
|
1108
|
+
// format can be added to.
|
|
1109
|
+
const FORMATTED = new Set(["time", "bench", "ab", "compare", "report", "ci"]);
|
|
1110
|
+
|
|
1111
|
+
export async function main(): Promise<number> {
|
|
1112
|
+
const [subcommand, ...given] = process.argv.slice(2);
|
|
1113
|
+
let rest = given;
|
|
1114
|
+
if (subcommand !== undefined && FORMATTED.has(subcommand)) {
|
|
1115
|
+
const chosen = withDefaultFormat(given);
|
|
1116
|
+
rest = chosen.argv;
|
|
1117
|
+
if (chosen.notice) await Bun.write(Bun.stderr, chosen.notice);
|
|
1118
|
+
}
|
|
1095
1119
|
return dispatchSubcommand(
|
|
1096
1120
|
subcommand,
|
|
1097
1121
|
rest,
|
package/src/compare/index.ts
CHANGED
|
@@ -43,8 +43,8 @@ export const DEFAULT_THRESHOLDS: Thresholds = {
|
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
// Below this many samples on either side, fall back to the point-estimate
|
|
46
|
-
// rule (with a `thin-comparison` warning), because CI and p-value are
|
|
47
|
-
// noisy.
|
|
46
|
+
// rule (with a `thin-comparison` warning), because CI and p-value are
|
|
47
|
+
// too noisy.
|
|
48
48
|
const MIN_SAMPLES_FOR_TEST = 5;
|
|
49
49
|
|
|
50
50
|
function pctDelta(base: number, cand: number): number {
|
|
@@ -257,8 +257,8 @@ export function createComparer(
|
|
|
257
257
|
unmatched,
|
|
258
258
|
compared(matched) {
|
|
259
259
|
// A candidate workload whose base has no measurement of it (a base
|
|
260
|
-
// `task.skip()`) has no comparison either, so it's missing its
|
|
261
|
-
// too.
|
|
260
|
+
// `task.skip()`) has no comparison either, so it's missing its
|
|
261
|
+
// base too.
|
|
262
262
|
const compared = new Set(matched.map(([id]) => id));
|
|
263
263
|
const candOnly = cand.workloads.filter((w) => !compared.has(w.id));
|
|
264
264
|
const { baseOnly } = unmatched();
|
package/src/config/index.ts
CHANGED
|
@@ -31,18 +31,21 @@ export interface WorkloadConfig {
|
|
|
31
31
|
/**
|
|
32
32
|
* `command`: kills a trial (or prepare hook) after this many ms.
|
|
33
33
|
* `suites`: kills a suite file's (or isolated task's) process after this
|
|
34
|
-
* many ms, overriding `bench.timeoutMs`. Overrides `ostia ci`'s
|
|
35
|
-
* default.
|
|
34
|
+
* many ms, overriding `bench.timeoutMs`. Overrides `ostia ci`'s
|
|
35
|
+
* 10-minute default.
|
|
36
|
+
*/
|
|
36
37
|
timeoutMs?: number;
|
|
37
38
|
/**
|
|
38
|
-
* `command` only. Exit codes to treat as success;
|
|
39
|
-
* `TimeOptions.ignoreExitCodes`.
|
|
39
|
+
* `command` only. Exit codes to treat as success;
|
|
40
|
+
* see `TimeOptions.ignoreExitCodes`.
|
|
41
|
+
*/
|
|
40
42
|
ignoreExitCodes?: number[];
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
|
-
* Launch settings for the suite files matching `suites`;
|
|
45
|
-
* `BenchOptions.projects`.
|
|
46
|
+
* Launch settings for the suite files matching `suites`;
|
|
47
|
+
* see `BenchOptions.projects`.
|
|
48
|
+
*/
|
|
46
49
|
export interface BenchProject {
|
|
47
50
|
/**
|
|
48
51
|
* Globs against the current directory. A suite file takes the first
|
|
@@ -103,8 +106,9 @@ export interface AbConfig {
|
|
|
103
106
|
* `--base-setup` replaces this list. */
|
|
104
107
|
setup?: string | string[];
|
|
105
108
|
/**
|
|
106
|
-
* Base trees to keep cached; see `AbOptions.keepTrees`.
|
|
107
|
-
* overrides. Default: 5.
|
|
109
|
+
* Base trees to keep cached; see `AbOptions.keepTrees`.
|
|
110
|
+
* `--keep-trees` overrides. Default: 5.
|
|
111
|
+
*/
|
|
108
112
|
keepTrees?: number;
|
|
109
113
|
/**
|
|
110
114
|
* Judge rounds by `"time"` or `"instructions"`; see `AbOptions.metric`.
|
|
@@ -153,8 +157,8 @@ export interface OstiaConfig {
|
|
|
153
157
|
noiseCheck?: boolean;
|
|
154
158
|
}
|
|
155
159
|
|
|
156
|
-
// Partial is shallow, so `thresholds` needs its own Partial to
|
|
157
|
-
// field-by-field.
|
|
160
|
+
// Partial is shallow, so `thresholds` needs its own Partial to
|
|
161
|
+
// merge field-by-field.
|
|
158
162
|
export type OstiaConfigInput = Omit<Partial<OstiaConfig>, "thresholds"> & {
|
|
159
163
|
thresholds?: Partial<Thresholds>;
|
|
160
164
|
};
|
package/src/config/validate.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { errorMessage } from "../errors.ts";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A config file that exists but can't be used; the CLI reports it
|
|
5
|
-
* `config-invalid`.
|
|
4
|
+
* A config file that exists but can't be used; the CLI reports it
|
|
5
|
+
* as `config-invalid`.
|
|
6
6
|
*/
|
|
7
7
|
export class ConfigError extends Error {}
|
|
8
8
|
|
|
@@ -222,8 +222,8 @@ function checkWorkload(
|
|
|
222
222
|
|
|
223
223
|
// Throws `ConfigError` naming the offending key for a wrong type or value;
|
|
224
224
|
// `warn` gets keys that are unknown (or inapplicable) and so ignored.
|
|
225
|
-
// `raw` is the already-object-checked config with `undefined` values
|
|
226
|
-
// present.
|
|
225
|
+
// `raw` is the already-object-checked config with `undefined` values
|
|
226
|
+
// still present.
|
|
227
227
|
export function validateConfig(
|
|
228
228
|
raw: Record<string, unknown>,
|
|
229
229
|
file: string,
|
package/src/glob.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
|
|
3
3
|
const SKIPPED_DIRS = ["node_modules", ".git"];
|
|
4
|
-
// Wildcards skip it because `ostia ab` extracts copies of the
|
|
5
|
-
// there.
|
|
4
|
+
// Wildcards skip it because `ostia ab` extracts copies of the
|
|
5
|
+
// project there.
|
|
6
6
|
const AB_TREES = ".ostia/ab";
|
|
7
7
|
// compat: `@(` and `+(` open extglobs since Bun 1.4.4; a bare `(` isn't a
|
|
8
8
|
// glob character, so `app/(marketing)` stays literal.
|
package/src/ir/document.ts
CHANGED
|
@@ -76,8 +76,8 @@ interface SubprocessWorkloadOptions {
|
|
|
76
76
|
|
|
77
77
|
// `prepare` and `timeSource` join the id only when given, so commands
|
|
78
78
|
// without them keep their old id. A function `prepare` hashes by source
|
|
79
|
-
// text. The id excludes `process.cwd()` so baselines match
|
|
80
|
-
// checkouts.
|
|
79
|
+
// text. The id excludes `process.cwd()` so baselines match
|
|
80
|
+
// across checkouts.
|
|
81
81
|
export function makeSubprocessWorkload(
|
|
82
82
|
command: string[],
|
|
83
83
|
label?: string,
|