Skip to main content

Module boot_timing

Module boot_timing 

Source
Expand description

Per-step timing for srv’s boot path, logged once as a single summary line when AGENTMUXSRV-ESTART is emitted.

WHY. docs/specs/SPEC_FAST_STARTUP_UPGRADE_OWNS_MIGRATIONS_AND_UPDATES_2026_09_15.md §3 inventories the boot path and finds several passes that run on every boot and have never been individually timed — the registry session_id catch-up backfill, the transcript backfill, the snapshot-source gap repair, and the agent auto-seed. The splash’s backend stage reports one number covering all of them together, so there is currently no way to say which of them (if any) is worth moving off the critical path. §6 of that spec asks for measurement before relocation; this is the instrument.

Deliberately tracing, not the srv_stderr splash protocol (agentmux_common::srv_stderr) the per-migration rows use: the direction of travel is fewer splash rows, not more (docs/reports/REPORT_SPLASH_MIGRATION_ROW_OVERFLOW_AND_SUMMARY_2026_09_15.md), and these numbers are for whoever is profiling a boot, not for the user watching one. Read them with muxlog srv grep boot_timing.

The global recorder is a process-lifetime singleton because the steps it wraps are scattered through the long boot functions in crates/srv/src/bootstrap/stores.rs and crates/srv/src/main.rs; threading a &mut BootTimings through all of them would be a much larger diff than the measurement is worth. BootTimings itself is a plain value type with no global state, which is what the tests below exercise.

Structs§

BootTimings
One boot’s worth of step timings.

Constants§

SLOW_STEP
How long a step_if_slow runs before it is worth a splash row.

Traits§

StepOutcome
Whether a step’s result means it worked, so a failed step’s end line says so and the splash shows it failed, not done.

Functions§

init
Start timing this boot. Called once from main, after logging is up.
log_summary
Log the one summary line. Called once, where the boot path ends.
step
A data-preparation step the splash shows: copying the previous version’s data, a snapshot, the backup. Writes AGENTMUXSRV-STEP-BEGIN/-END on stderr around f (the launcher shows a sub-row of “Backend startup”; the same lines report agentmux-srv migrate --prepare’s steps) and records the time like time, so the splash and the boot summary come from one call.
step_if_slow
A step that is usually instant and only sometimes waits (another process’s migration lock): its begin line is written once it has run for SLOW_STEP, while it is still running, and then its end line with the outcome. A fast one writes nothing.
time
Run f, recording its duration under step if init has been called.
time_async
time, for an async step. Same no-lock-across-the-work property.