Skip to content

@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.

On this page

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

OptionDefaultWhat it does
secretOGYGIA_PROFILER_SECRET at runtimeThe 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.
sampleInterval500Microseconds 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.)
maxReports6Finished reports kept in this instance’s memory. The oldest goes first. A store keeps up to maxReports × 8, and never fewer than 200.
recentRequests500Requests the always-on request log keeps, for the dashboard’s slowest routes and recent requests.
networktruePatch 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.
serverTimingon in dev, off in a buildAdd Server-Timing headers to every response.
heaptrueSample heap allocations while recording. false leaves out GC attribution and what a render keeps.
enabledtrueThe master switch. false turns the profiler off but keeps it in the build: every request passes straight through.
onDemandfalseLoad the profiler only once someone opens its path (On demand).
trapoff{ over, interval?, window?, keep?, replay? }: keep a report when a request is slower than over ms (Slow-request trap).
sampleoff{ every?, window?, interval? }: a rolling hot-functions table from short coarse samples (Always-on sampling).
clientCputrueRecord the browser’s main-thread CPU on your own visits, in Chromium (Browser CPU).
sinkoff{ 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:

EntryWhat it is
ssrThe request’s wall time on the server.
cpuThe process’s CPU while the request ran. The rest of ssr is waiting.
netThe outbound calls’ total time, with their count in its description. Only on attributed requests.
up1 to up3The 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

VariableWhat it does
OGYGIA_PROFILER_SECRETThe 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_MSHow 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_DEBUGPrint 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_SIZERead, 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 AsyncLocalStorage that 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. The fetch and http patch stays installed; network: false removes 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 maxReports reports, with their raw CPU profile gzipped, and the last recentRequests request 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.