@ogygia/devtools · Profiler
Configuration
Every option of the profiler with its default and limits, the Server-Timing headers it can add, the environment variables it reads, loading it only on demand, and what it costs a server when nobody is recording.
The profiler takes its options from the profiler key of the devtools() plugin. true means every default, and an object changes only what it names. The options are build-time values: the plugin hands them to the server build, which reads them when the profiler mounts on the first request.
The one setting that isn’t here is where reports are stored. A store is a live object with a database connection, so you set it at runtime in src/hooks.server.ts (Report storage). The ProfilerOptions type lists a store key, but don’t use it: the options are written into the server build as JSON, so a store there passes the build and reaches the server as a plain object like { kind: 'postgres' }, with no methods. Every save to it then fails, and without OGYGIA_PROFILER_DEBUG nothing is printed (#2307). @ogygia/devtools/vite has the types.
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: {
path: '/__profiler',
maxReports: 6,
trap: { over: 800 },
serverTiming: false
}
}),
sveltekit()
]
});Options
| Option | Default | What it does |
|---|---|---|
secret | OGYGIA_PROFILER_SECRET at runtime | The key that opens the profiler in a build, 16 bytes or more. Leave it out and the server reads the variable when the profiler loads, on its first request. Set it here and the value is baked into the server build (Secret). |
path | '/__profiler' | Where the profiler’s pages and routes live. Every route in these docs is under it. |
sampleInterval | 500 | Microseconds between CPU samples in a recording window, 50 to 1,000. Page profiles use their own interval parameter (200 by default), and a header profile samples every 100. (The type’s own description says “for recordings”; it’s this, #2304 item 23.) |
maxReports | 6 | Finished reports kept in this instance’s memory. The oldest goes first. A store keeps up to maxReports × 8, and never fewer than 200. |
recentRequests | 500 | Requests the always-on request log keeps, for the dashboard’s slowest routes and recent requests. |
network | true | Patch fetch and http to attribute outbound calls to the request and line that made them. false skips the patch entirely: wall timing only, and no network view in any report. |
serverTiming | on in dev, off in a build | Add Server-Timing headers to every response. |
heap | true | Sample heap allocations while recording. false leaves out GC attribution and what a render keeps. |
enabled | true | The master switch. false turns the profiler off but keeps it in the build: every request passes straight through. |
onDemand | false | Load the profiler only once someone opens its path (On demand). |
trap | off | { over, interval?, window?, keep?, replay? }: keep a report when a request is slower than over ms (Slow-request trap). |
sample | off | { every?, window?, interval? }: a rolling hot-functions table from short coarse samples (Always-on sampling). |
clientCpu | true | Record the browser’s main-thread CPU on your own visits, in Chromium (Browser CPU). |
sink | off | { url, key?, every? }: post what each instance saw to a URL you own (Site sink). Set key: without it, the profiler’s secret is sent to the sink. |
A trap or sample on a serverless host is ignored, and the dashboard says so under In the background.
On demand
By default the profiler mounts on the server’s first request, and from then on its request log, trap and sampler run from boot. With onDemand: true, its module isn’t even imported until a request for its path arrives. Until then the app pays what an app without a profiler pays: no import on a cold start, no request log and no per-request timing.
After the first request to /__profiler, that instance runs the profiler as usual. The cost is history: the request log, the trap and the sampler start from that first visit, a store set with setProfilerStore() is read then too, and an x-profile request is profiled only by an instance that has already loaded the profiler. Use it on serverless hosts (Lambda, Amplify), where every cold start would otherwise pay the profiler’s import on its first response.
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: { onDemand: true } }),
sveltekit()
]
});Server-Timing
With serverTiming on, every response the profiler sees carries Server-Timing entries, which your browser’s Network panel and the dock’s Record tab read:
| Entry | What it is |
|---|---|
ssr | The request’s wall time on the server. |
cpu | The process’s CPU while the request ran. The rest of ssr is waiting. |
net | The outbound calls’ total time, with their count in its description. Only on attributed requests. |
up1 to up3 | The three slowest outbound calls, by method, host and path, without their query string. |
net and up1 to up3 need the request to be attributed: on the dev server every request is, and in a build only while a page profile runs, and on a request profiled with x-profile. On other requests ssr and cpu are all there is.
serverTiming also makes the server answer a nested trace, which carries upstream URLs with their query strings to any client that asks (Public deploys). All of this is why it’s off in a build by default. Turn it on in a build only where every client is yours, such as a staging host behind your own access control or a service only your own servers call.
Environment variables
| Variable | What it does |
|---|---|
OGYGIA_PROFILER_SECRET | The secret, read when the profiler loads on the first request (with onDemand, the first request to /__profiler), when secret isn’t set in the config. |
OGYGIA_PROFILER_BUDGET_MS | How long a page profile may take, in ms, on a host that cuts requests. Wins over the profiler’s guess from VERCEL, NETLIFY and AWS_LAMBDA_FUNCTION_NAME. |
OGYGIA_PROFILER_DEBUG | Print the failures the profiler otherwise recovers from quietly: a store that failed a write or a read, and GC attribution that couldn’t run. Also logs memory at each step of a recording. |
AWS_LAMBDA_FUNCTION_MEMORY_SIZE | Read, not set: on Lambda the memory countdown uses the function’s size instead of the heap’s limit. |
Overhead
- Idle cost is almost nothing. The CPU is sampled only during a recording. Per request the profiler reads two CPU counters and a clock and pushes one entry into the request log, which takes microseconds. A cold start pays one import of the profiler’s chunk, about 30 ms, unless you set
onDemand. - Network attribution only while recording. In a build, the per-request
AsyncLocalStoragethat ties a call to its request exists only while a recording runs, because on Node 20 every one in flight costs a copy per async hop. Thefetchandhttppatch stays installed;network: falseremoves it. - A recording costs the instance. A page profile renders the page many times on the server you profile; a CPU sample every 200 µs costs a few percent, and the inspector’s start-up scan of compiled code takes hundreds of milliseconds on a big process. The report takes the profiler’s own share out of every number.
- Background windows (the trap and sampling) cost about 1 to 3 percent CPU while they watch.
- Memory holds the last
maxReportsreports, with their raw CPU profile gzipped, and the lastrecentRequestsrequest rows. - The browser side costs visitors nothing. The script that reports a visit goes only into documents served to the profiler’s own logged-in user. Those documents are marked
private, no-store, so no shared cache keeps them.