Create a trackable version of a function. Calls go through track(),
so nested trackables attach to their caller.
Turn tracking off: tracked functions become plain pass-through calls
Disable silent mode (allow console output)
This instance for chaining
Turn tracking on
Enable silent mode (no console output)
This instance for chaining
Render an execution tree in the browser output format
Statistics as a text table, slowest total first
Per-label statistics (ms): count, errors, total, mean, min, max, p50/p95/p99 and mean self time.
Per-label statistics (ms): count, errors, total, mean, min, max, p50/p95/p99 and mean self time.
Get the current tracking mode
Whether tracking is on
Call listener with every finished top-level execution tree (even when
silent or below threshold). Returns an unsubscribe function.
Call listener for every finished call (nested ones included) that
took at least threshold ms. Pass a number, or per-label thresholds
with an optional '*' default:
tp.onSlow(200, (call, root) => logger.warn(${call.label} took ${call.duration}ms in ${root.label}));
tp.onSlow({ 'db.query': 50, 'GET /search': 500, '*': 1000 }, alert);
Works in every tracking mode and when silent. Returns an unsubscribe function.
Print the statistics table to the console
Register a module for tracking
The module or object containing methods to track
Tracking options
Modified module with tracked methods
Reset the tracker state (in-flight executions and statistics)
This instance for chaining
Clear collected statistics
Set configuration options
Configuration to update
Current configuration after update
Set the sampling rate
Sampling rate between 0.0 and 1.0
This instance for chaining
Set the tracking mode
Tracking mode from TrackingMode enum
This instance for chaining
Start a manually-ended execution (a span), e.g. for a request:
const span = tp.start('GET /users'); span.run(() => next()); // tracked calls inside become children res.on('finish', () => span.end());
Start recording finished calls for a Chrome/Perfetto trace.
const recording = tp.startTrace(); await work(); fs.writeFileSync('trace.json', JSON.stringify(recording.stop()));
Open the file in https://ui.perfetto.dev or chrome://tracing.
Method decorator. Works with TypeScript 5 / TC39 standard decorators and
with legacy experimentalDecorators. The label defaults to
"ClassName.method".
class UserService { @tp.traced() async getUser(id: string) { ... } }
Track a function execution
The function to track
Tracking options
Result of the tracked function
Track every method of an object or class instance, including methods
inherited from its prototype, without copying it. Returns a proxy:
state changes go to the original object, and methods run with the
original object as this (so private #fields keep working).
Register a plugin (exporter, custom sink). Returns an unsubscribe function.
Browser-compatible TracePerf instance.
Shares the core tracker with the Node.js entry (same nesting, statistics, hooks, exporters and options) and adds console-style logging methods. Output uses the browser format:
Execution Flow: → parent (12.34ms) → child (10.01ms)