@ogygia/devtools · Profiler
Report storage
Where a finished report lives and how it moves. Memory, your browser, a shared SQLite, Redis or Postgres store, exported files and share links.
On this page
A finished report lives in the memory of the instance that recorded it. On one long-lived server that’s all you need. It falls short in two common setups: on a serverless host, the instance that recorded a report is often gone before you open it, and behind a load balancer, the request for the report page can land on an instance that never saw the recording.
The profiler handles both in layers. Your browser keeps a copy of every report you open. A store gives every instance one shared list. And every report exports to a file that any profiler can open.
import * as ogygia from 'ogygia/server';
import { setProfilerStore } from '@ogygia/devtools/profiler/storage';
import { PostgresStore } from '@ogygia/devtools/profiler/storage/postgres';
setProfilerStore(
new PostgresStore(process.env.DATABASE_URL ?? '')
); +++
export const handle = ogygia.handle();Browser copies
A serverless instance lives for seconds and forgets everything it measured. So the server captures inside one request and hands the result over, and the browser keeps it, in IndexedDB on the app’s origin (database ogygia-profiler, up to 40 reports):
- Profile a page answers the run page with the report’s dump (
format=keep), and the browser stores it before opening the report. A report page the server no longer holds renders from the browser’s copy. - Every report page stores itself when the browser is idle, if you opened it some other way (a header profile’s link, a trap catch). Restarting a long-lived server loses nothing you’ve looked at.
- Visits your browser reports go into the same store, with each island’s markup before and after hydration, so the one-clock timeline and DOM time travel work whether or not the instance that rendered the report still exists.
The dashboard lists the reports this browser kept, and two kept reports of the same page can be compared in the browser. Nothing is shared between browsers. In a private window, or with storage blocked, the browser keeps nothing and the profiler works as before.
Stores
A store gives every instance one list. Set it in src/hooks.server.ts, as above. From then on every finished report is written to it and read back from it, so a report outlives the instance that recorded it, survives a restart, and shows in the dashboard of every instance.
The store goes in the hooks file rather than in the plugin’s options because it’s a live object holding a connection, while the options in vite.config.ts are build-time values. Call setProfilerStore() at the top level of the module: the profiler reads it once, when it loads on the first request (with onDemand, the first request to /__profiler), and ignores a later call.
Memory stays the fast path. A report is kept in memory and also written to the store; a report that isn’t in memory is read from the store and cached. A page profile waits up to 3 seconds for its write before it answers, so a serverless host doesn’t freeze the process mid-write. A store that fails never breaks a recording: a failed write leaves the report in memory only, and a store whose init() throws is skipped with devtools_profiler_store_init_failed and tried again on its next use.
After each write the profiler trims the store to its newest maxReports × 8 reports, and never to fewer than 200. The store also keeps a window’s requests, which is how a session recorded across several instances comes back whole.
Bundled stores
Each store is a class in its own entry point, so the database client you don’t use is never loaded:
| Entry point | Class | What it is |
|---|---|---|
@ogygia/devtools/profiler/storage | new MemoryStore(cap = 50) | An in-process map of the newest cap reports. It adds nothing to the default; it’s for tests and a model for your own store. |
@ogygia/devtools/profiler/storage/sqlite | new SqliteStore(filename = '.ogygia/profiles.db') | One SQLite file (relative to the working directory, its folder created for you), or ':memory:'. Needs Node 22.5 or later (node:sqlite) or the better-sqlite3 package. Survives a restart, on one machine. |
@ogygia/devtools/profiler/storage/redis | new RedisStore(client, { ttlSeconds, prefix = 'og:' }) | A Redis URL (it imports redis, else ioredis) or a client you already connected. ttlSeconds expires reports on their own. Keeps at most 1,000 reports. |
@ogygia/devtools/profiler/storage/postgres | new PostgresStore(client, { schema, table = 'ogygia' }) | A connection string (it imports pg) or a pg pool. Creates <table>_reports and <table>_visits on first use, inside schema when you name one. Reports are jsonb, so you can query inside them. |
The database clients (better-sqlite3, redis or ioredis, pg) aren’t dependencies of @ogygia/devtools, so install the one your store needs. On a serverless host pick Redis or Postgres, since every instance has to reach the same store. SQLite suits one long-lived server. SQLite, Redis and Postgres each keep the newest 2,000 visit rows per window.
Nothing in a store is encrypted. A store is infrastructure you run, so treat its contents like the profiler’s own pages: they hold source paths, component names, outbound URLs and the lines of your code.
Custom stores
A store is any object that satisfies ProfilerStore from @ogygia/devtools/profiler/storage. Every method may return a value or a promise, so a network backend fits as well as a local one:
| Member | Required | What it does |
|---|---|---|
kind | yes | A name for the store, such as 'kv'. |
putReport(record) | yes | Writes a report, or overwrites the one with the same id. |
getReport(id) | yes | Returns the report’s dump string, or null when there is none. |
listReports(limit?) | yes | Returns the newest reports first, as records without their dump. |
deleteReport(id) | yes | Removes a report. |
init() | no | Runs once before first use: connect, create tables. |
prune(keep) | no | Keeps the newest keep reports and drops the rest. Called after each write. |
putVisit(visit) · listVisits(page, limit?) | no | Write and read a window’s requests. Without them, a window sees only its own instance’s requests. |
close() | no | Releases connections. |
A record (ProfilerRecord) has summary fields for the list (id, created in epoch ms, page, trigger, label and median) plus dump: the report’s portable JSON as a string, the same data the .ogp export carries. recordColumns(record) from the same entry point returns the summary fields alone, which is what listReports answers. A visit row (ProfilerVisitRecord) is { key, page, at, visit }, where page groups the rows listVisits returns together and visit is a JSON string. A window asks for up to 2,000 rows under one page, so keep at least that many.
import * as ogygia from 'ogygia/server';
import { setProfilerStore } from '@ogygia/devtools/profiler/storage';
import { RedisStore } from '@ogygia/devtools/profiler/storage/redis';
setProfilerStore(
new RedisStore(
process.env.REDIS_URL ?? 'redis://localhost:6379',
{ ttlSeconds: 7 * 24 * 3600 }
)
);
export const handle = ogygia.handle();import {
recordColumns,
type ProfilerRecord,
type ProfilerStore,
type ProfilerSummary
} from '@ogygia/devtools/profiler/storage';
/** The smallest store: a Map. Swap it for your key-value client's get, set, delete and scan. */
export class KvStore implements ProfilerStore {
readonly kind = 'kv';
#kv: Map<string, ProfilerRecord>;
constructor(kv: Map<string, ProfilerRecord>) {
this.#kv = kv;
}
putReport(record: ProfilerRecord): void {
this.#kv.set(record.id, record);
}
getReport(id: string): string | null {
return this.#kv.get(id)?.dump ?? null;
}
listReports(limit = 30): ProfilerSummary[] {
return [...this.#kv.values()]
.sort((a, b) => b.created - a.created)
.slice(0, limit)
.map(recordColumns);
}
deleteReport(id: string): void {
this.#kv.delete(id);
}
}Exports
The row of actions at the top of a report page, and the links under it:
| Action | What you get |
|---|---|
| Profile again & compare | On a page report: the same page profiled again, opened as a comparison with this one. |
| Export .ogp | The report as one file, Brotli-compressed and encrypted (AES-256-GCM, its key derived from the profiler’s secret with scrypt). On the dev server, with no secret, a fixed dev key, so dev exports open in any dev profiler. |
| Share link | A password-protected link that carries the report itself (Share links). |
| Download .html | One self-contained file that opens from disk (Standalone HTML). |
| Import .ogp | Open a file on this profiler. |
| JSON (link) | The JSON report an agent reads. |
| .cpuprofile (link) | The raw V8 CPU profile, for Chrome DevTools’ Performance panel or speedscope.app. |
Export .ogp and Share link show only when the page carries its own .ogp copy or your browser kept one. Beside them, a status says whether this browser has kept the report; it keeps it on its own.
From a script, POST /__profiler/page?…&format=ogp answers the .ogp at once, and GET /__profiler/report/<id>.dump answers the plain dump: the report’s portable JSON, which @ogygia/devtools/report reads.
These actions work on a serverless host too, where the instance that made the report is rarely the one that answers. The button sends the report along with its request, either as the page’s own .ogp copy or as this browser’s kept copy, gzipped (never as raw JSON, which would pass a host’s request size limit), and whichever instance answers builds the file from that copy. The .cpuprofile is the exception: the raw profile isn’t part of the portable report, so only the instance that recorded it can serve it.
Opening a file
Import .ogp (/__profiler/view) opens an .ogp on any instance of any app with the profiler on. Give it the file and its export key; leave the key blank and it tries this profiler’s own secret. A file moved through a text channel (a prepended BOM, or the whole file base64-encoded by a chat) is recovered before it’s read. A wrong key, or a file that isn’t a report, is refused, and so is one over 32 MB or one that unpacks past 256 MB (devtools_profiler_upload_too_large).
To read an .ogp with no server at all, use ogp_decode() or the ogygia_profile_open MCP tool.
Share links
Share link turns the report into a URL with the report itself in its #fragment, encrypted with a password you choose (AES-GCM, its key from PBKDF2 with 210,000 rounds). The fragment never reaches a server, so nothing is stored anywhere: the recipient opens the link, types the password, and the report renders in their browser without a login.
Links are up to about 1.5 MB. Safari and iOS cap URLs much lower, so the button is off there, and a link past about 56,000 characters opens only in Chromium and Firefox. Send the password separately from the link.
Standalone HTML
Download .html writes a single file with everything inlined: the styles, the runtime and every island chunk the page reaches, as an import map of data: URLs. It opens from disk or an email attachment with the tables sortable and the flame graph and timeline interactive.
It needs a built app (vite build with preview, or a deploy). On the dev server the page’s code is hundreds of unbundled modules, so it answers 400; export the .ogp there instead and build the file on a built server.
Site sink
The site view needs rows from many instances over days. On a long-lived host the instance’s own memory has them. On a short-lived one, give each instance somewhere to post them:
Each instance posts NDJSON (content-type: application/x-ndjson): one small row per request (path, route, ms, CPU, waiting and status), one summary per sampling window (its hot functions), and a caught request with its dump. key goes as a bearer token in authorization. Without one it defaults to the profiler’s secret, which then travels in every post to whoever runs the sink and their request logs, and that secret opens every profiler route. Always give the sink its own key (#2304, item 24). Like secret, key is read where the app builds and baked into the server build: if the variable is missing there, key is left out and the sink gets the profiler’s secret instead, with no message. Set it in the build environment. A long-lived host posts every every ms (10 seconds by default, 1 second at least); a serverless one posts after each request. Up to 512 KB waits in memory between posts, oldest request rows dropped first.
Posts go one at a time, in order, each with an idempotency-key header so the sink can drop a copy it already stored. A failed post is tried four times over about 30 seconds; after that its rows are dropped and the server prints devtools_profiler_sink_undelivered. The site page shows the sink’s last answer.
Serve the collected rows (the same NDJSON, concatenated) from any URL the browser can read, and paste it into Whole site, or open /__profiler/site?from=<url>.
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: {
sink: {
url: 'https://example.com/profiler-rows',
key: process.env.PROFILER_SINK_KEY,
every: 10_000
}
}
}),
sveltekit()
]
});