ostia 0.2.12 → 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/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 +923 -679
- package/package.json +16 -14
- package/src/ab/ab-runner.ts +487 -0
- package/src/ab/index.ts +1160 -0
- package/src/baseline/index.ts +69 -0
- package/src/bench/index.ts +516 -0
- package/src/bench/projects.ts +43 -0
- package/src/bench/range.ts +27 -0
- package/src/bench/registry.ts +426 -0
- package/src/bench/run-tasks.ts +179 -0
- package/src/bench/run.ts +52 -0
- package/src/bench/runner.ts +162 -0
- package/src/bench/support.ts +161 -0
- package/src/bench/sweep.ts +41 -0
- package/src/cache/fingerprint.ts +62 -0
- package/src/cache/store.ts +40 -0
- package/src/capture/bunflags.ts +92 -0
- package/src/capture/cpu-parse.ts +131 -0
- package/src/capture/cpu.ts +47 -0
- package/src/capture/frames.ts +60 -0
- package/src/capture/heap-parse.ts +111 -0
- package/src/capture/heap.ts +36 -0
- package/src/capture/inspector.ts +47 -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 +440 -0
- package/src/cli/flags.ts +263 -0
- package/{chunk-9sx15b08.js → src/cli/help.ts} +23 -11
- package/src/cli/main.ts +18 -0
- package/src/cli/output.ts +179 -0
- package/src/cli/run.ts +1110 -0
- package/src/compare/index.ts +624 -0
- package/src/config/env.ts +13 -0
- package/src/config/index.ts +283 -0
- package/src/config/validate.ts +273 -0
- package/src/errors.ts +8 -0
- package/src/format.ts +35 -0
- package/src/glob.ts +45 -0
- package/src/index.ts +60 -0
- package/src/ir/cpu.ts +10 -0
- package/src/ir/defined.ts +12 -0
- package/src/ir/document.ts +491 -0
- package/src/ir/fp.ts +28 -0
- package/src/ir/git.ts +37 -0
- package/src/ir/types.ts +615 -0
- package/src/measure/alloc.ts +56 -0
- package/src/measure/cpu.ts +91 -0
- package/src/measure/environment.ts +38 -0
- package/src/measure/inprocess.ts +191 -0
- package/src/measure/instructions.ts +139 -0
- package/src/measure/loop.ts +64 -0
- package/src/measure/noise.ts +55 -0
- package/src/measure/paired.ts +304 -0
- package/src/measure/peak.ts +201 -0
- package/src/measure/timing.ts +263 -0
- package/src/profile.ts +110 -0
- package/src/renderers/collapsed.ts +42 -0
- package/src/renderers/cpu-tree.ts +191 -0
- package/src/renderers/cpuprofile.ts +43 -0
- package/src/renderers/format.ts +132 -0
- package/src/renderers/index.ts +37 -0
- package/src/renderers/json.ts +10 -0
- package/src/renderers/jsonl.ts +19 -0
- package/src/renderers/markdown.ts +543 -0
- package/src/renderers/mermaid.ts +90 -0
- package/src/renderers/minimal.ts +602 -0
- package/src/renderers/paired.ts +223 -0
- package/src/renderers/relative.ts +60 -0
- package/src/renderers/select.ts +264 -0
- package/src/renderers/speedscope.ts +73 -0
- package/src/renderers/terminal.ts +470 -0
- package/src/renderers/types.ts +27 -0
- package/src/spawn/index.ts +387 -0
- package/src/stats/bootstrap.ts +151 -0
- package/src/stats/index.ts +144 -0
- package/src/stats/mannwhitney.ts +82 -0
- package/src/time.ts +337 -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,132 @@
|
|
|
1
|
+
import { type DurationUnit, formatDuration } from "../format.ts";
|
|
2
|
+
import type {
|
|
3
|
+
CpuEvidence,
|
|
4
|
+
Environment,
|
|
5
|
+
Frame,
|
|
6
|
+
GitMetadata,
|
|
7
|
+
HeapEvidence,
|
|
8
|
+
Measurement,
|
|
9
|
+
Workload,
|
|
10
|
+
} from "../ir/types.ts";
|
|
11
|
+
import { percentile, sortedCopy } from "../stats/index.ts";
|
|
12
|
+
|
|
13
|
+
export function formatSpan(lo: number, hi: number, unit: DurationUnit): string {
|
|
14
|
+
return `${formatDuration(lo, unit)}…${formatDuration(hi, unit)}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function formatNsAsMs(ns: number): string {
|
|
18
|
+
return (ns / 1e6).toFixed(3);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function formatUsAsMs(us: number): string {
|
|
22
|
+
return (us / 1000).toFixed(2);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// invariant: every byte count ostia prints is 1024-based.
|
|
26
|
+
export function formatBytes(bytes: number): string {
|
|
27
|
+
if (bytes < 1024) return `${bytes.toFixed(0)}B`;
|
|
28
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)}KiB`;
|
|
29
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)}MiB`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function formatInstructions(count: number): string {
|
|
33
|
+
if (count < 1e3) return count.toFixed(0);
|
|
34
|
+
const [divisor, suffix] =
|
|
35
|
+
count >= 1e9 ? [1e9, "G"] : count >= 1e6 ? [1e6, "M"] : [1e3, "K"];
|
|
36
|
+
const value = count / divisor;
|
|
37
|
+
return `${value.toFixed(value < 10 ? 2 : 1)}${suffix}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function frameName(frame: Frame | undefined): string {
|
|
41
|
+
return frame?.name || "(anonymous)";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// `cpu.totals` is pre-sorted by self time, so the first `limit` are the
|
|
45
|
+
// heaviest.
|
|
46
|
+
export function topSelfFrames(
|
|
47
|
+
cpu: CpuEvidence,
|
|
48
|
+
limit: number,
|
|
49
|
+
): {
|
|
50
|
+
frame: Frame | undefined;
|
|
51
|
+
selfUs: number;
|
|
52
|
+
totalUs: number;
|
|
53
|
+
pct: string;
|
|
54
|
+
}[] {
|
|
55
|
+
const totalSelfUs = cpu.totals.reduce((s, t) => s + t.selfUs, 0) || 1;
|
|
56
|
+
return cpu.totals.slice(0, limit).map((t) => ({
|
|
57
|
+
frame: cpu.frames[t.frameIx],
|
|
58
|
+
selfUs: t.selfUs,
|
|
59
|
+
totalUs: t.totalUs,
|
|
60
|
+
pct: ((t.selfUs / totalSelfUs) * 100).toFixed(1),
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function formatHeapSummary(heap: HeapEvidence): string {
|
|
65
|
+
return `${heap.objectCount ?? "?"} objects, ${formatBytes(heap.heapSizeBytes ?? 0)}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function formatEnvironmentLine(env: Environment): string {
|
|
69
|
+
return `${env.cpuModel} · ${env.cores} cores · load ${env.loadAvg1.toFixed(1)} · noise floor ${env.noise.floorPct.toFixed(1)}%`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function formatGit(git: GitMetadata): string {
|
|
73
|
+
return `${git.sha} (${git.branch}${git.dirty ? ", dirty" : ""})`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function workloadLabel(w: Workload): string {
|
|
77
|
+
return w.label ?? w.command?.join(" ") ?? w.entry?.task ?? w.id;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function labelOrId(w: Workload | undefined, id: string): string {
|
|
81
|
+
return w ? workloadLabel(w) : id;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function formatRelative(relative: number, baseline: boolean): string {
|
|
85
|
+
if (relative === 1) return baseline ? "1.00× (baseline)" : "1.00×";
|
|
86
|
+
if (relative > 1) return `${relative.toFixed(2)}× slower`;
|
|
87
|
+
return `${(1 / relative).toFixed(2)}× faster`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// So a name can't break a GFM table row.
|
|
91
|
+
export function escapeMdCell(s: string): string {
|
|
92
|
+
return s
|
|
93
|
+
.replace(/\|/g, "\\|")
|
|
94
|
+
.replace(/</g, "<")
|
|
95
|
+
.replace(/>/g, ">")
|
|
96
|
+
.replace(/`/g, "\\`")
|
|
97
|
+
.replace(/\r\n|\r|\n/g, "<br>");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Median per trial; in-process measurements have no CPU times, so
|
|
101
|
+
// undefined.
|
|
102
|
+
export function cpuTimes(
|
|
103
|
+
run: Pick<Measurement, "trials">,
|
|
104
|
+
): { userNs: number; systemNs: number } | undefined {
|
|
105
|
+
const user: number[] = [];
|
|
106
|
+
const system: number[] = [];
|
|
107
|
+
for (const t of run.trials) {
|
|
108
|
+
if (t.timedOut || t.timeSourceNoMatch) continue;
|
|
109
|
+
if (t.userNs === undefined || t.systemNs === undefined) continue;
|
|
110
|
+
user.push(t.userNs);
|
|
111
|
+
system.push(t.systemNs);
|
|
112
|
+
}
|
|
113
|
+
if (user.length === 0) return undefined;
|
|
114
|
+
return {
|
|
115
|
+
userNs: percentile(sortedCopy(user), 0.5),
|
|
116
|
+
systemNs: percentile(sortedCopy(system), 0.5),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function formatCpuTimes(times: {
|
|
121
|
+
userNs: number;
|
|
122
|
+
systemNs: number;
|
|
123
|
+
}): string {
|
|
124
|
+
return `${formatDuration(times.userNs)}/${formatDuration(times.systemNs)}`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// A delta that rounds to zero prints unsigned, never `-0.0%`.
|
|
128
|
+
export function formatSignedPct(pct: number): string {
|
|
129
|
+
const text = pct.toFixed(1);
|
|
130
|
+
if (Number(text) === 0) return "0.0%";
|
|
131
|
+
return `${pct > 0 ? "+" : ""}${text}%`;
|
|
132
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { collapsedRenderer } from "./collapsed.ts";
|
|
2
|
+
import { cpuprofileRenderer } from "./cpuprofile.ts";
|
|
3
|
+
import { jsonRenderer } from "./json.ts";
|
|
4
|
+
import { jsonlRenderer } from "./jsonl.ts";
|
|
5
|
+
import { markdownRenderer } from "./markdown.ts";
|
|
6
|
+
import { type MermaidOptions, mermaidRenderer } from "./mermaid.ts";
|
|
7
|
+
import { minimalRenderer, type MinimalRenderOptions } from "./minimal.ts";
|
|
8
|
+
import { speedscopeRenderer } from "./speedscope.ts";
|
|
9
|
+
import { terminalRenderer } from "./terminal.ts";
|
|
10
|
+
import type { FormatName, Renderer, VizOptions } from "./types.ts";
|
|
11
|
+
|
|
12
|
+
/** Each format's renderer, typed with its own options. `Renderer<never>` is
|
|
13
|
+
* the top type, so `satisfies` checks every format is present without
|
|
14
|
+
* widening the options. */
|
|
15
|
+
export const renderers: {
|
|
16
|
+
table: Renderer;
|
|
17
|
+
json: Renderer;
|
|
18
|
+
markdown: Renderer;
|
|
19
|
+
jsonl: Renderer;
|
|
20
|
+
minimal: Renderer<MinimalRenderOptions>;
|
|
21
|
+
collapsed: Renderer<VizOptions>;
|
|
22
|
+
mermaid: Renderer<MermaidOptions>;
|
|
23
|
+
speedscope: Renderer<VizOptions>;
|
|
24
|
+
cpuprofile: Renderer<VizOptions>;
|
|
25
|
+
} = {
|
|
26
|
+
table: terminalRenderer,
|
|
27
|
+
json: jsonRenderer,
|
|
28
|
+
markdown: markdownRenderer,
|
|
29
|
+
jsonl: jsonlRenderer,
|
|
30
|
+
minimal: minimalRenderer,
|
|
31
|
+
collapsed: collapsedRenderer,
|
|
32
|
+
mermaid: mermaidRenderer,
|
|
33
|
+
speedscope: speedscopeRenderer,
|
|
34
|
+
cpuprofile: cpuprofileRenderer,
|
|
35
|
+
} satisfies Record<FormatName, Renderer<never>>;
|
|
36
|
+
|
|
37
|
+
export type { FormatName, Renderer, RenderResult } from "./types.ts";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { serializeDocument } from "../ir/document.ts";
|
|
2
|
+
import type { ProfileDocument } from "../ir/types.ts";
|
|
3
|
+
import type { Renderer, RenderResult } from "./types.ts";
|
|
4
|
+
|
|
5
|
+
export const jsonRenderer: Renderer = {
|
|
6
|
+
name: "json",
|
|
7
|
+
render(doc: ProfileDocument): Promise<RenderResult> {
|
|
8
|
+
return Promise.try(() => ({ text: serializeDocument(doc) }));
|
|
9
|
+
},
|
|
10
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { canonicalJSON } from "../ir/fp.ts";
|
|
2
|
+
import type { ProfileDocument } from "../ir/types.ts";
|
|
3
|
+
import type { Renderer, RenderResult } from "./types.ts";
|
|
4
|
+
|
|
5
|
+
export const jsonlRenderer: Renderer = {
|
|
6
|
+
name: "jsonl",
|
|
7
|
+
render(doc: ProfileDocument): Promise<RenderResult> {
|
|
8
|
+
return Promise.try(() => {
|
|
9
|
+
const { measurements, ...header } = doc;
|
|
10
|
+
const lines = [
|
|
11
|
+
canonicalJSON({ kind: "document", ...header }),
|
|
12
|
+
...measurements.map((r) =>
|
|
13
|
+
canonicalJSON({ kind: "measurement", ...r }),
|
|
14
|
+
),
|
|
15
|
+
];
|
|
16
|
+
return { text: `${lines.join("\n")}\n` };
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
};
|