Skip to main content

Module perf

Module perf 

Source
Expand description

Request timing instrumentation — opt-in, off by default.

Set CMS_PERF_LOG=1 to get one log line per request with the total wall time plus a breakdown of the phases the handler recorded:

PERF GET /getting-started -> 303 in 3512.4ms | tenant=181.2 locale=182.0
     resolve=543.9 restriction=362.1 render=0.0

The point is attribution. A slow page is nearly always slow for one of two reasons — too many sequential round-trips, or one expensive phase — and a single total tells you neither.

Phases are recorded through a task-local, so mark is a no-op outside a request (tests, CLI commands) and costs an atomic load when the feature is off.

Functions§

enabled
CMS_PERF_LOG=1 — read once; this is on the hot path.
instrument
Wrap router in the timing middleware when profiling is enabled.
mark
Record name as having taken the time since t. No-op unless CMS_PERF_LOG is set.
start
Start a timer. Pair with mark, or drop it to record nothing.
timing_middleware
Axum middleware: time the whole request and emit the breakdown.