Skip to main content

Module bench_instrument

Module bench_instrument 

Source
Expand description

Benchmark timing injection for YAML-loaded routes.

When BENCH_LATENCY_FILE env var is set, every top-level BuilderStep::To(_) in each route definition is wrapped with two processors:

  1. Pre: stores Arc<Instant::now()> in exchange.extensions["BenchStart"]
  2. Post: reads it back, computes elapsed().as_nanos(), writes BENCH_LATENCY <id> <duration_ns> to the shared file.

Per-pair Arc<AtomicU64> counter guarantees coherent ids. The latency file is opened once at injection time and shared via Arc<Mutex<File>> (no per-tick reopen). When the env var is unset, this module is a no-op.

Only top-level To steps are wrapped — nested steps inside Choice, Split, Filter etc. are left untouched (wrapping those would measure per-sub-message latency, not per-tick bridge tax).

Functions§

maybe_instrument_routes
If BENCH_LATENCY_FILE is set, instrument each route by wrapping top-level To steps with timing processors. Returns defs unchanged when the env var is absent (zero-cost no-op).