@ogygia/devtools · Profiler
Scripts and CI
Reading the profiler without its pages. Authenticate with a header, get any report as JSON, call every route, open a downloaded report in Node, give an AI agent the profiler over MCP, and fail CI on a performance budget or find the commit that made a page slower.
Everything the profiler’s pages show is also data. A script can profile a page and read the analyzed result in one request, an agent can do the same through MCP, and a CI job can turn it into a budget that fails a pull request.
curl -s -X POST 'http://localhost:4173/__profiler/page?p=/products&runs=5&format=json' \
-H "x-profiler-key: $OGYGIA_PROFILER_SECRET" | jq '.findings[] | select(.severity == "warn")'Authentication
On the dev server every route is open. In a build, send the secret in the x-profiler-key header on every request. There’s no query parameter for it, because a secret in a URL ends up in logs and caches.
A request without a valid key is redirected to the login page with a 303 (in a build with a secret), so a script that follows redirects gets the login page’s HTML with a 200: check the status before you parse. In a build without a secret it’s answered 404. Wrong keys count against the login form’s limit: after ten from one address in 15 minutes, every key from that address is refused, the right one included, until the window passes. The login form then answers 429; a header request is still just redirected to the login.
JSON reports
Every report is also curated JSON: the analyzed result, not the raw V8 profile. Get an existing one with GET /__profiler/report/<id>.json, or profile a page and get it back in the same response with POST /__profiler/page?p=…&format=json (or an Accept: application/json header). The second also adds since (what changed since this page’s previous profile) and shared (its fixes that speed up other pages too).
The payload describes itself with schema, version and units, so an agent can read it without other context:
| Key | What it holds |
|---|---|
id, created, kind, links | The report’s id, when it was made, how (page, request, window or trap), and the URLs of its HTML, JSON and .cpuprofile. |
node, dev, sourcemapped | The Node version, whether it ran on the dev server, and whether frames were mapped to source. |
target | The page, each run’s time (runs, and runs_measured before the profiler’s own share came out), the warm-up, status, bytes and cache headers. |
summary | The window, CPU busy, idle and GC time, verdict (waiting, compute-bound or mixed), the event loop’s delay, and overhead. |
score | The page score: score, grade, categories, and what’s missing. |
findings | Every finding: severity (warn or info), a stable code, message, fix, and file/line when it’s about one place. |
forecast, patterns, ledger | The forecast, the slow patterns with their sites, and the hot lines. |
timeline, steps, stacks, drill | One render’s phases and waits, its steps, the folded sample index, and the line-level breakdown. |
components, hot_functions, paths, files | The CPU tables, with path, column and stacks on each row. |
network, waiting, spans, span_values, user_timings | Outbound calls, non-HTTP waits, your spans, and performance.measure() entries. |
memory, retained, growth, alloc, deopts, sync_io, promises, memo_candidates | The memory sections. |
ogygia, kit, lineage, river, strip, assets | Islands, seed and props, Kit’s own costs, page data, the document’s bytes and the weighed files. |
browser, cold, contention, replay, requests, budget | The browser metrics, the cold render, other requests in the window, the replay inputs, the requests seen, and the time budget bar. |
Sections the recording had nothing for are null or empty. A window’s stop adds window. To keep a CI run light, ask for a few sections with fields: format=json&fields=summary,findings,score answers those keys plus the ones that name the report (schema, version, engine, kind, id, created, target, links).
/__profiler/report/<id>.dump answers the plain dump instead: { kind: 'ogygia-profiler-dump', version, meta, analysis, extras }, the portable form a store and the .ogp export carry, and what report_json() below turns into this JSON.
{
"schema": "ogygia-profiler-report",
"version": 1,
"kind": "page",
"units": { "time": "ms", "size": "bytes", "memory_suffix_mb": true },
"summary": { "window_ms": 699, "busy_pct": 100, "verdict": "compute-bound" },
"findings": [{ "severity": "warn", "code": "sequential-awaits", "message": "…", "fix": "…" }],
"components": [{ "name": "PrimeSieve", "file": "src/lib/PrimeSieve.svelte", "self_ms": 296, "total_ms": 296 }],
"network": { "count": 3, "total_ms": 412, "sequential_ms": 0, "hosts": [], "calls": [] },
"memory": { "growth_mb": 195, "gc": { "max_ms": 2.2 }, "allocators": [] }
}Routes
Every route sits under the profiler’s path (/__profiler by default) and, except where noted, needs the login or x-profiler-key in a build. A route that changes state takes POST only, and a GET to it answers 405.
| Route | Method | What it does |
|---|---|---|
/ | GET | The dashboard. ?by=<tag> splits the slowest routes by a tag (only requests made while a recording ran carry tags). |
/run?p=&runs=&format=&against= | GET | The progress page that runs a page profile and opens its report. |
/page?p=… | POST | A page profile. |
/window/start, /window/stop | POST | A recording window. |
/replay/<id> | POST | Profile a caught request again. |
/reset | POST | Free a wedged recording. |
/status.json | GET | { recording, inflight, rss_mb, reports }. |
/reports.json | GET | The reports the store holds, newest 20: [{ id, label, page, created }]. Empty with no store. |
/report/<id> | GET | The report page. Open without a login, for share links; its data needs one. |
/report/<id>.json | GET, POST | The JSON report. A POST carries the report in its body, so any instance can answer. |
/report/<id>.dump | GET, POST | The plain dump. |
/report/<id>.html | GET, POST | The standalone HTML (a build only). |
/report/<id>.ogp | POST | The encrypted .ogp, built from the report the request carries. |
/report/<id>/raw | GET | The raw .cpuprofile, from the instance that recorded it. |
/compare/<a>/<b> | GET | Two reports side by side. |
/site?from=<url> | GET | The site view. |
/view | GET, POST | Import an .ogp. The POST takes the file’s bytes and an x-ogp-key header. |
/login | GET, POST | The login page and form. Always reachable. |
/logout | POST | End the session. Always reachable. |
/amondin | POST | Where your browser posts its visits (Browser metrics). |
/source?p=&l=&to= | GET | A few lines of a source file, for an opened row. Dev only, and only files inside the project. |
A POST with a report in its body (.json, .dump, .html, .ogp) takes either the report’s .ogp bytes (content-type: application/octet-stream, which only this server’s secret opens) or its dump as gzipped JSON (x-og-encoding: gzip), up to 32 MB.
Reports in code
@ogygia/devtools/report reads a saved report in Node, outside the profiler. It’s what ogygia mcp loads from your app to open a downloaded report, and you can use it in your own tooling, such as a CI step that checks an exported report:
is_ogp(bytes)says whether a file is an exported.ogprather than a plain JSON dump.ogp_decode(bytes, secret)decrypts and unpacks an.ogpwith the secret it was exported under (no secret: the dev key, so dev exports open in dev). It throws on a wrong key or a changed file, and stops unpacking past 256 MB.is_dump(value)checks that a value is a report dump, with itsmeta,analysisandextras.report_json(analysis, meta, base, extras)builds the same JSON that/report/<id>.jsonanswers.baseis the profiler’s path, used in the report’s links.fix_impact(patterns, render_ms, renders?, wait_ms?)adds up what fixing a report’s patterns would take off the render, capped at 90 percent. It’s the sum behind “about 326 ms off the 741 ms render”.
@ogygia/devtools/report has the signatures.
import { readFile } from 'node:fs/promises';
import {
is_ogp,
ogp_decode,
is_dump,
report_json
} from '@ogygia/devtools/report';
const bytes = await readFile('slow-page.ogp');
const dump: unknown = is_ogp(bytes)
? await ogp_decode(bytes, process.env.OGYGIA_PROFILER_SECRET)
: JSON.parse(bytes.toString('utf8'));
if (is_dump(dump)) {
const report = report_json(
dump.analysis,
dump.meta,
'/__profiler',
dump.extras
);
for (const f of report.findings)
if (f.severity === 'warn') console.log(f.code, f.message);
}MCP
The MCP server of npx ogygia mcp gives an AI agent the profiler as two tools: ogygia_profile profiles a URL on your running app, and ogygia_profile_open opens a downloaded .ogp with its export key. Both return a digest that leads with the same three fixes and running totals as the report’s first section. Tools lists their arguments.
CI budgets
ogygia perf from @ogygia/cli renders a list of pages under this profiler on a running build, writes a snapshot, judges it against a baseline under a budget file, writes a PR comment, and exits with 1 when a page misses its budget. The build lists the profiler and has a secret. Perf budgets is the full guide: the CI workflow, the snapshot, every budget key with its default, the verdict and the comment.
First bad commit
ogygia bisect finds the commit that made a page slower: it builds and profiles commits between a good one and a bad one in a binary search, each in its own git worktree. First bad commit shows a run and the servers it starts.
npx ogygia perf --url http://127.0.0.1:4173 --pages /,/products --key "$OGYGIA_PROFILER_SECRET" \
--baseline perf-baseline.json --budget perf-budget.json --md perf-comment.mdTests
@ogygia/testing reads the same reports inside Playwright: ogygia.profile(path) returns a page’s report for matchers like toMeetBudget(), and ogygia.record(actions, { server: true }) puts a window around a test’s actions.