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,142 @@
|
|
|
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
|
+
/** `lo…hi` in one shared unit. */
|
|
14
|
+
export function formatSpan(lo: number, hi: number, unit: DurationUnit): string {
|
|
15
|
+
return `${formatDuration(lo, unit)}…${formatDuration(hi, unit)}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function formatNsAsMs(ns: number): string {
|
|
19
|
+
return (ns / 1e6).toFixed(3);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function formatUsAsMs(us: number): string {
|
|
23
|
+
return (us / 1000).toFixed(2);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `512B`, `2.00KiB`, `14.90MiB`: every byte count ostia prints is
|
|
28
|
+
* 1024-based.
|
|
29
|
+
*/
|
|
30
|
+
export function formatBytes(bytes: number): string {
|
|
31
|
+
if (bytes < 1024) return `${bytes.toFixed(0)}B`;
|
|
32
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)}KiB`;
|
|
33
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)}MiB`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** An instruction count: `840`, `12.4K`, `3.02M`, `1.25G`. */
|
|
37
|
+
export function formatInstructions(count: number): string {
|
|
38
|
+
if (count < 1e3) return count.toFixed(0);
|
|
39
|
+
const [divisor, suffix] =
|
|
40
|
+
count >= 1e9 ? [1e9, "G"] : count >= 1e6 ? [1e6, "M"] : [1e3, "K"];
|
|
41
|
+
const value = count / divisor;
|
|
42
|
+
return `${value.toFixed(value < 10 ? 2 : 1)}${suffix}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function frameName(frame: Frame | undefined): string {
|
|
46
|
+
return frame?.name || "(anonymous)";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The `limit` heaviest frames by self time (`cpu.totals` is pre-sorted),
|
|
51
|
+
* with each one's share of all self time as a one-decimal percent string.
|
|
52
|
+
* */
|
|
53
|
+
export function topSelfFrames(cpu: CpuEvidence, limit: number) {
|
|
54
|
+
const totalSelfUs = cpu.totals.reduce((s, t) => s + t.selfUs, 0) || 1;
|
|
55
|
+
return cpu.totals.slice(0, limit).map((t) => ({
|
|
56
|
+
frame: cpu.frames[t.frameIx],
|
|
57
|
+
selfUs: t.selfUs,
|
|
58
|
+
totalUs: t.totalUs,
|
|
59
|
+
pct: ((t.selfUs / totalSelfUs) * 100).toFixed(1),
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** `1200 objects, 3.42MiB` */
|
|
64
|
+
export function formatHeapSummary(heap: HeapEvidence): string {
|
|
65
|
+
return `${heap.objectCount ?? "?"} objects, ${formatBytes(heap.heapSizeBytes ?? 0)}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** `Apple M2 Pro · 12 cores · load 2.1 · noise floor 1.8%` */
|
|
69
|
+
export function formatEnvironmentLine(env: Environment): string {
|
|
70
|
+
return `${env.cpuModel} · ${env.cores} cores · load ${env.loadAvg1.toFixed(1)} · noise floor ${env.noise.floorPct.toFixed(1)}%`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** `abc1234 (main, dirty)` */
|
|
74
|
+
export function formatGit(git: GitMetadata): string {
|
|
75
|
+
return `${git.sha} (${git.branch}${git.dirty ? ", dirty" : ""})`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function workloadLabel(w: Workload): string {
|
|
79
|
+
return w.label ?? w.command?.join(" ") ?? w.entry?.task ?? w.id;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The workload's label, or its raw id when the document has no such
|
|
84
|
+
* workload.
|
|
85
|
+
*/
|
|
86
|
+
export function labelOrId(w: Workload | undefined, id: string): string {
|
|
87
|
+
return w ? workloadLabel(w) : id;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** `1.00× (baseline)` / `1.00×` / `2.43× slower` / `1.95× faster` */
|
|
91
|
+
export function formatRelative(relative: number, baseline: boolean): string {
|
|
92
|
+
if (relative === 1) return baseline ? "1.00× (baseline)" : "1.00×";
|
|
93
|
+
if (relative > 1) return `${relative.toFixed(2)}× slower`;
|
|
94
|
+
return `${(1 / relative).toFixed(2)}× faster`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Escapes `|`, `<`, `>`, backticks and newlines so a name can't break a
|
|
99
|
+
* GFM table row. */
|
|
100
|
+
export function escapeMdCell(s: string): string {
|
|
101
|
+
return s
|
|
102
|
+
.replace(/\|/g, "\\|")
|
|
103
|
+
.replace(/</g, "<")
|
|
104
|
+
.replace(/>/g, ">")
|
|
105
|
+
.replace(/`/g, "\\`")
|
|
106
|
+
.replace(/\r\n|\r|\n/g, "<br>");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Median user/system CPU time per trial of a subprocess measurement;
|
|
111
|
+
* undefined for in-process ones. */
|
|
112
|
+
export function cpuTimes(
|
|
113
|
+
run: Pick<Measurement, "trials">,
|
|
114
|
+
): { userNs: number; systemNs: number } | undefined {
|
|
115
|
+
const user: number[] = [];
|
|
116
|
+
const system: number[] = [];
|
|
117
|
+
for (const t of run.trials) {
|
|
118
|
+
if (t.timedOut || t.timeSourceNoMatch) continue;
|
|
119
|
+
if (t.userNs === undefined || t.systemNs === undefined) continue;
|
|
120
|
+
user.push(t.userNs);
|
|
121
|
+
system.push(t.systemNs);
|
|
122
|
+
}
|
|
123
|
+
if (user.length === 0) return undefined;
|
|
124
|
+
return {
|
|
125
|
+
userNs: percentile(sortedCopy(user), 0.5),
|
|
126
|
+
systemNs: percentile(sortedCopy(system), 0.5),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function formatCpuTimes(times: {
|
|
131
|
+
userNs: number;
|
|
132
|
+
systemNs: number;
|
|
133
|
+
}): string {
|
|
134
|
+
return `${formatDuration(times.userNs)}/${formatDuration(times.systemNs)}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** `+3.2%`, `-1.5%`; a delta that rounds to zero is `0.0%`, unsigned. */
|
|
138
|
+
export function formatSignedPct(pct: number): string {
|
|
139
|
+
const text = pct.toFixed(1);
|
|
140
|
+
if (Number(text) === 0) return "0.0%";
|
|
141
|
+
return `${pct > 0 ? "+" : ""}${text}%`;
|
|
142
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { mermaidRenderer } from "./mermaid.ts";
|
|
7
|
+
import { minimalRenderer } from "./minimal.ts";
|
|
8
|
+
import { speedscopeRenderer } from "./speedscope.ts";
|
|
9
|
+
import { terminalRenderer } from "./terminal.ts";
|
|
10
|
+
import type { FormatName, Renderer } 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: terminalRenderer,
|
|
17
|
+
json: jsonRenderer,
|
|
18
|
+
markdown: markdownRenderer,
|
|
19
|
+
jsonl: jsonlRenderer,
|
|
20
|
+
minimal: minimalRenderer,
|
|
21
|
+
collapsed: collapsedRenderer,
|
|
22
|
+
mermaid: mermaidRenderer,
|
|
23
|
+
speedscope: speedscopeRenderer,
|
|
24
|
+
cpuprofile: cpuprofileRenderer,
|
|
25
|
+
} satisfies Record<FormatName, Renderer<never>>;
|
|
26
|
+
|
|
27
|
+
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
|
+
async render(doc: ProfileDocument): Promise<RenderResult> {
|
|
8
|
+
return { text: serializeDocument(doc) };
|
|
9
|
+
},
|
|
10
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
async render(doc: ProfileDocument): Promise<RenderResult> {
|
|
8
|
+
const { measurements, ...header } = doc;
|
|
9
|
+
const lines = [
|
|
10
|
+
canonicalJSON({ kind: "document", ...header }),
|
|
11
|
+
...measurements.map((r) => canonicalJSON({ kind: "measurement", ...r })),
|
|
12
|
+
];
|
|
13
|
+
return { text: `${lines.join("\n")}\n` };
|
|
14
|
+
},
|
|
15
|
+
};
|