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.0The 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
routerin the timing middleware when profiling is enabled. - mark
- Record
nameas having taken the time sincet. No-op unlessCMS_PERF_LOGis 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.