Struct PeakMonitor

Struct Documentation

struct PeakMonitor

Hierarchy-wide co-resident memory high-water tracker.

A single PeakMonitor can be wired (via CacheManager::set_peak_monitor) onto the root of a scope-chain of CacheManager instances so every note_working_set() call anywhere in the chain — root cache, per-batch scratch, nested scopes — folds into one running high-water mark, with a hook fired each time that mark advances (so a caller can capture where the current peak was observed, e.g. for a schedule visualizer).

Public Functions

inline void observe(std::size_t bytes, std::size_t op_hash) noexcept

Observe one candidate high-water sample. Advances hwmark_bytes (and fires on_peak) only if bytes exceeds the current mark; a sample at or below the mark is a no-op.

Public Members

std::size_t hwmark_bytes = 0

Running high-water mark (bytes), monotonically non-decreasing.

PeakEvent peak = {}

Location of the current high-water (the event that last advanced hwmark_bytes).

std::function<void(PeakEvent const&)> on_peak = {}

Optional callback fired each time hwmark_bytes advances (i.e. exactly when peak is updated). Empty (default) => no-op.

std::function<void(std::size_t total_bytes, std::vector<PeakLiveEntry> const&)> on_peak_liveset = {}

Diagnostic (analysis-only): optional callback fired &#8212; by CacheManager::note_working_set, before observe advances the mark &#8212; each time a new global high-water is about to be recorded, carrying the total co-resident bytes and the full alive-entry set (chain-wide) at that instant. Empty (default) => note_working_set never enumerates the live set, so the fold costs nothing. Used to decompose a realized peak into its co-resident values.