@ogygia/devtools · Profiler
Recording
Every way to capture a profile. Profile a page by its path, one live request with a header, a window of requests you start and stop, or the slow request you can't reproduce with the trap.
On this page
A recording samples the process’s CPU through the V8 inspector and logs every outbound call, wait and allocation while it runs. There are four ways to start one, each for a different question:
| You know | Use | What it records |
|---|---|---|
| which page is slow | a page profile | the page rendered several times in a row |
| which request is slow, right now | the x-profile header | that one request |
| which actions are slow | a window | every request between a start and a stop |
| only that something is sometimes slow | the trap or sampling | short coarse windows in the background, kept as a report when a request was slow (trap), or folded into a rolling hot-functions table (sampling) |
The usual one is the page profile. On the dashboard, type a path and press Profile, or ask for it from a script:
curl -X POST 'http://localhost:5173/__profiler/page?p=/products&runs=5&format=json'Page profiles
A page profile renders one path through your real server several times in a row and profiles only those renders. Everything the page depends on (a session, cookies your request carried, a load) runs exactly as it does for a visitor, because the profiler asks Kit to render it the way a browser navigation does.
In order, one page profile:
- Follows redirects. It renders the path once, follows up to five redirects (a trailing slash, an i18n redirect, a prerendered meta refresh), and profiles the final address. The report says where it came from.
- Profiles the cold render. That first render is recorded on its own as a light window, so the report can show what loading modules and filling caches cost, per file (Cold starts). Pass
cold=0to skip it. - Times the runs. It renders the page
runstimes under the full recorder. A render another visitor’s request for the same path overlapped is set aside, and when fewer than two ran clean it renders up to twice as many to find some. - Adds the extra renders. One with V8’s inlining off counts calls (the
×Non each row). One under a live-objects sampler, followed by a full collection, finds what a render keeps, and up to six more confirm whether it’s a leak. Up to three more serve the answers that came back the same each time from memory, to measure caching. - Weighs the page. In a build, it fetches every file the HTML names to weigh the JS, CSS and fonts for the page score.
Then it answers with a redirect (303) to the report.
The dashboard form goes through GET /__profiler/run?p=/products&runs=5, a page that shows progress and opens the report when it’s done. Add against=<report id> and it opens the new report compared with that one, which is how you check a fix in one click. A link to /run from another site opens it waiting for a click rather than starting on its own.
Page profile parameters
POST /__profiler/page takes its settings in the query string. A GET answers 405, because a recording changes the profiler’s state.
| Parameter | Default | What it does |
|---|---|---|
p | required | The path to profile, starting with /, with its query if any. Anything else answers 400. |
runs | 5 | Timed renders, 1 to 50. Use 5 or more when you compare numbers. |
interval | 200 | Microseconds between CPU samples, 50 to 10,000. |
cold | on | cold=0 skips profiling the first render on its own. |
gc | on | gc=0 records without GC attribution, the cheaper recording. |
weigh | budgeted | weigh=full weighs every file the page loads (up to 2,000), however long it takes, so the totals don’t vary from run to run. By default weighing stops after a few seconds. |
format | redirect | json answers the JSON report. ogp answers the encrypted .ogp file. keep answers { id, url, dump } for a browser to keep. |
fields | all | With format=json, only these top-level keys (comma-separated), plus the ones that name the report. |
An Accept: application/json header does the same as format=json. In a build, send the secret in the x-profiler-key header, as Scripts and CI shows.
Single requests
Send any request with the header x-profile: <secret> and you get a profile of exactly that request. The report’s address comes back in the x-profile-report response header:
On the dev server any value works. In a build it must be the secret, and a wrong one counts against the login limit. While your address is locked out, even the right secret gets the request answered without a profile.
The profile starts with the request, samples every 100 µs, and adds the profiler’s start-up cost to that request’s latency. That makes it the right tool for catching one specific request (a logged-in user’s, a tenant’s) and the wrong one for steady numbers.
Only one recording runs at a time. When another one holds the recorder, the request is answered unprofiled and no x-profile-report comes back. With the trap or sampling on, a background window holds the recorder most of the time, so a header profile usually misses (#2304, item 15). Turn them off while you use the header, or use a page profile, which waits for them.
curl -sD - 'https://example.com/slow/page' -H "x-profile: $OGYGIA_PROFILER_SECRET" | grep x-profile-reportRecording windows
A window records every request between a start and a stop: the CPU across all of them, their outbound calls, and the requests themselves. It’s what the dock’s Record tab and @ogygia/testing use to put a server side on a session of clicks.
POST /__profiler/window/start answers { ok, id, header, shared, max_ms }. Drive the app, then POST /__profiler/window/stop answers the window’s JSON report with a window field: how long it ran, every request it saw, and how many instances served them. The first finding, window-requests, names the slowest requests and splits each into CPU and waiting.
A window is capped at 60 seconds (max_ms), so a forgotten stop can’t hold the recorder. Only one runs at a time: a second start answers 409. In a build a window needs the secret, because its id is signed with it.
header is x-og-window. Send it with the window’s id on each request when your requests can land on different instances. With a store that keeps visit rows (shared: true), every instance writes each such request to the store before it answers, and the stop, on whichever instance, gathers them. The CPU profile stays the starting instance’s, because sampling is per process.
const origin = 'http://localhost:4173';
const key = {
'x-profiler-key': process.env.OGYGIA_PROFILER_SECRET ?? ''
};
const start = await fetch(`${origin}/__profiler/window/start`, {
method: 'POST',
headers: key
});
const { id, header } = (await start.json()) as {
id: string;
header: string;
};
// the requests to measure; the header lets any instance file them under this window
await fetch(`${origin}/products`, {
headers: { [header]: id }
});
await fetch(`${origin}/cart`, { headers: { [header]: id } });
const stop = await fetch(`${origin}/__profiler/window/stop`, {
method: 'POST',
headers: { ...key, [header]: id }
});
const report = (await stop.json()) as {
window: { requests: { path: string; ms: number }[] };
};
console.log(report.window.requests);Slow-request trap
A page profile only helps with a page you already suspect. The p99 request you can’t reproduce needs the profiler to be watching when it happens. Turn on the trap:
A coarse sampler then runs in rolling windows, and a window is kept only when a request inside it took longer than over ms. The report is labelled caught on the dashboard, its timeline is the slowest such request’s, and the findings that name the slow step still work.
| Option | Default | What it does |
|---|---|---|
over | required | The threshold, ms. The trap is off when it’s 0 or less. |
interval | 10 | Milliseconds between CPU samples. |
window | 5000 | The length of one window, ms. |
keep | 3 | How many reports to keep before the trap stops. |
replay | none | Request headers to keep with a caught request, so a replay carries them. Never cookies unless you name them. |
The trap stays cheap: a 10 ms interval, no per-request context (the request is matched to the window by time), no stacks on calls and no heap sampling, about 1 to 3 percent CPU while it watches. It’s off on a serverless host, where an instance lives for one request. If one of its windows fails (another debugger holds the inspector, usually), the trap stops, the dashboard says why, and the server prints devtools_profiler_background_stopped.
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { devtools } from '@ogygia/devtools/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
ogygia(),
devtools({
profiler: {
trap: {
over: 800,
replay: ['accept-language', 'x-tenant']
}
}
}),
sveltekit()
]
});Always-on sampling
sample: { every: 60, window: 2000 } takes one 2-second coarse sample every 60 seconds and folds it into a rolling hot functions table on the dashboard, over the last 60 windows (an hour at the defaults). Its accuracy comes from volume: a function that’s hot across sixty windows is hot in real traffic, whatever a single recording of a single page shows.
| Option | Default | What it does |
|---|---|---|
every | 60 | Seconds between windows. |
window | 2000 | The length of one window, ms. |
interval | 10 | Milliseconds between CPU samples. |
It costs what the trap costs, since the two share the recorder and take turns, and it’s off on serverless hosts too. The same failure rule applies.
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { devtools } from '@ogygia/devtools/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
ogygia(),
devtools({
profiler: {
sample: { every: 60, window: 2000 }
}
}),
sveltekit()
]
});Request replay
A report from the trap (marked caught) and a report you took with the header both carry a replay button. It sends POST /__profiler/replay/<id>, which runs a full page profile of the same path with the same query and the headers trap.replay named, then opens the new report. That turns the p99 request the trap caught with its coarse sampler into a proper profile with stacks, calls and heap, as long as the request is reproducible. A report with no request to replay answers 404.
Concurrency
The V8 inspector is one per process, so only one recording runs at a time:
- A page profile waits up to 8 seconds for a background window (the trap, sampling, or a window you started) to give the recorder back. When another page profile holds it, it answers
409withretry-after: 2and says who holds it. The run page retries for you. - A header profile never waits: it’s answered unprofiled.
- A window start waits for the trap or sampling, and answers
409when a page profile or another window holds the recorder.
GET /__profiler/status.json answers { recording, inflight, rss_mb, reports }, cheaply, for a script that wants to know. When a recording is stuck (its request died before it cleaned up), Reset on the dashboard (POST /__profiler/reset) frees the recorder and ends any window.
Limits
A recording renders your page many times and can’t be allowed to take the server down. These limits apply to every page profile:
- The heap. When the heap is 75% full or more, a page profile refuses to start (
503) and says what to fix. During the runs it stops rendering at 85%, and it skips the extra renders past 70%. The report says what it left out (heap-near-limit). - One render. A render that doesn’t answer within 15 seconds ends the runs; the report keeps the runs it has. When none answered, the profile fails with
504. - One recording. A recording never runs longer than 30 seconds, on any host, because it holds the network attribution open for the whole site. The report says how many runs fit (
budget). - Serverless budgets. On a host that cuts requests, the runs fit inside the host’s limit less 5 seconds for the analysis: 300 seconds on Vercel, 10 on Netlify, 30 on AWS Lambda and Amplify. Set
OGYGIA_PROFILER_BUDGET_MSwhen you raised or lowered your function’s timeout. - Recorded calls. Up to 100 outbound calls per request and 2,000 per window, and up to 2,000 spans per request.
A runtime that can’t record answers 501 (Requirements). Any other failure answers 500 with its message.
Moved sections
These sections used to be on this page. Each now lives on its own page:
- JSON reports, in Scripts and CI
- Reports in code, in Scripts and CI
- CI budgets and the first bad commit, in Scripts and CI
- Serverless hosts, in Production
- Login, in Production
- Source maps, in Production
- Dev server, in SSR profiler
- Overhead, in Configuration
- Options, in Configuration
- Browser copies, in Report storage
- Stores, in Report storage
- Bundled stores, in Report storage
- Custom stores, in Report storage
- Site sink, in Report storage