Module Algostream_infrastructure_event_bus.Memory_monitor

Memory usage sampler for the event bus.

Periodically polls Gc.quick_stat from a background thread and exposes the most recent reading. Cheap; intended to run continuously alongside a long-lived event bus.

For deeper allocation tracing, set the MEMTRACE environment variable to a writable path before launching; init_memtrace will start memtrace tracing on first call (no-op if the env var is unset).

type sample = {
  1. timestamp_ns : int64;
  2. minor_words : float;
  3. promoted_words : float;
  4. major_words : float;
  5. heap_words : int;
  6. live_words : int;
  7. free_words : int;
  8. stack_size : int;
}
type t
val create : unit -> t

Allocate a monitor; does not start sampling.

val start : ?interval_ms:int -> t -> unit

Spawn a sampler thread that polls every interval_ms ms (default 1000).

val stop : t -> unit

Signal the sampler thread to exit. Safe to call twice.

val latest : t -> sample option

Most recent sample, or None if the sampler hasn't taken one yet.

val pp_sample : sample -> string
val init_memtrace : unit -> unit

One-shot init: if MEMTRACE is set in the environment, call Memtrace.start_tracing writing a CTF trace to that path (sampling rate 1e-4). Otherwise no-op. Safe to call from anywhere; idempotent.