Module Algostream_infrastructure_event_bus.Instrumentation

Latency instrumentation for the event bus.

Reuses Time_utils.LatencyMonitor for sliding-window stats and SLA violation tracking; adds three named hookpoints:

All recording goes through record; producers compute the duration themselves from Clock.now_monotonic_ns timestamps to keep the hot path free of monad allocations.

type t
val create : ?window_size:int -> ?sla_ns:int64 -> unit -> t

create ?window_size ?sla_ns () sets up per-phase monitors with the given sliding-window length (default 4096) and SLA violation threshold (default 5_000_000 ns = 5ms).

type phase =
  1. | Publish_to_enqueue
  2. | Enqueue_to_dispatch
  3. | Dispatch_to_handler
  4. | End_to_end
val phase_to_string : phase -> string
val record : t -> phase -> int64 -> unit

Record a duration sample for phase. Cheap; no-op when instrumentation is disabled.

val set_enabled : t -> bool -> unit

Toggle the instrumentation gate at runtime.

val is_enabled : t -> bool
type phase_stats = {
  1. count : int;
  2. avg_ns : int64;
  3. max_ns : int64;
  4. violations : int;
}
type stats = {
  1. publish_to_enqueue : phase_stats;
  2. enqueue_to_dispatch : phase_stats;
  3. dispatch_to_handler : phase_stats;
  4. end_to_end : phase_stats;
}
val snapshot : t -> stats
val pp_stats : stats -> string