Skip to main content

MonitorCore

Struct MonitorCore 

Source
pub struct MonitorCore { /* private fields */ }
Expand description

The monitor’s shareable core: ingest on one side, events + snapshots on the other. Session wiring lives in Monitor; the core is pure and deterministically testable.

Implementations§

Source§

impl MonitorCore

Source

pub fn new(capacity: usize) -> Arc<MonitorCore>

Source

pub fn bounded(capacity: usize, max_keys: usize) -> Arc<MonitorCore>

A core whose statistics table is bounded at max_keys distinct keys.

Source

pub fn ingest(&self, view: SampleView, sn: Option<u32>)

Ingest one sample: stats update + retention + broadcast. Hot path — two short locks, no tree work (that happens on the tick).

Source

pub fn ingest_at( &self, view: Arc<SampleView>, sn: Option<u32>, now: Instant, wall: SystemTime, )

MonitorCore::ingest with both clocks injected (#217).

Replay rebuilds feed this with the capture clock — the row’s t offset from the load epoch, on both axes: now for the monotonic fold, wall for the skewed-latency subtraction — rather than the live clocks, which is what makes a rebuild deterministic down to the EWMA rates and the latency window: the same rows at the same instants fold to bit-identical statistics, however fast the rebuild loop runs. (Before wall was threaded, the latency read the live wall clock even under an injected now, so a rebuild folded arrival-time garbage — deep-review D2.)

Source

pub fn node_event(&self, key: String, up: bool)

Source

pub fn tick(&self)

Rebuild the snapshot from the stats and announce it.

Two phases, and the split is the whole point (#330). The stats mutex is the one ingest takes on zenoh’s network callback thread, so whatever this holds it for, the network layer waits for. It therefore holds it for the O(keys) row copy (StatsTable::rows) and folds the tree — O(keys × chunks) of BTreeMap descents, a String per new node, ~300 000 map operations at the 50 000-key bound — after releasing it. Four times a second the old shape held the lock for the whole rebuild, which made Monitor::watch’s promise that a slow UI cannot exert backpressure into the network layer false four times a second.

The fold still runs on the calling thread here. The periodic tick takes tick_off_runtime instead, which puts it on the blocking pool where that much CPU belongs.

Source

pub async fn tick_off_runtime(&self)

tick with the fold on the blocking pool (#330): the copy is taken here, the CPU is spent on a blocking thread, and the runtime’s workers stay free for the drains they exist for. Used by the stats-tick task; tick remains the synchronous form for the paths that publish a snapshot as part of another operation (a seed boundary, an unwatch).

Source

pub fn tree(&self) -> Arc<KeyTreeSnapshot>

The latest immutable snapshot (lock-free pull).

Source

pub fn with_stats<R>(&self, f: impl FnOnce(&StatsTable) -> R) -> R

Read access to the raw stats (hz/bw commands).

Source

pub fn with_stats_mut<R>(&self, f: impl FnOnce(&mut StatsTable) -> R) -> R

Mutable access — watch retirement and tests.

Source

pub fn keys_unwatched(&self) -> u64

Keys retired from the table because their watch was released (RFC 09 §5.1 O6 — see crate::model::stats::StatsTable::unwatched).

Source

pub fn dropped(&self) -> u64

Total events dropped across all lagging receivers so far.

Source

pub fn keys_evicted(&self) -> u64

Distinct keys dropped from the statistics table to stay within its bound. Non-zero means the key set on display is partial — report it rather than letting a shrinking tree read as a quieting bus (RFC 09 §5.1).

Source

pub fn retained(&self) -> Arc<[Arc<SampleView>]>

The retained window, oldest first (#217): Arc clones of every sample still inside both retention budgets. This is what the GUI’s retained scrub rebuilds panes from, and what “save window as .zrec” writes — the same rows either way.

Covers only watched keys by construction: the ring sits on the ingest path, and nothing unwatched is ever ingested. A consumer that presents this window MUST say so (RFC 09 §5.1 O5 — a retained window over three watches is not a retained window over the bus).

What this read costs the network thread (#331): the retain mutex is ingest’s, taken on zenoh’s callback thread, so a read that walked the window blocked the network layer for as long as the window was long — 64 MiB of 256-byte samples is ~260 000 refcount atomics, and zengui calls this from update(). The ring is chunked instead (crate::model::retain): under the lock this clones the sealed chunks’ pointers and the open tail — bounded by window / 1024 + 1024, independent of payload — and the flatten into the returned slice happens after the guard is dropped. The result is an Arc<[_]> so passing the window on costs nothing again.

Source

pub fn retention(&self) -> RetentionStats

The retained window’s account of itself: budget in force, what it holds, and what each bound cost — evicted (byte budget) apart from expired (age), both apart from MonitorCore::dropped, MonitorCore::keys_evicted and MonitorCore::keys_unwatched (RFC 09 §5.1 O6; v1.18 R1 forbids folding the kinds).

Source

pub fn set_retention_budget(&self, budget: RetentionBudget)

Change the retention budget in force; applied from the next push or read. The default (RetentionBudget::default) is 64 MiB / 2 min.

Source

pub fn events(self: &Arc<Self>) -> EventStream

Subscribe to the event stream.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<Source> AccessAs for Source

Source§

fn ref_as<T>(&self) -> <Source as IGuardRef<T>>::Guard<'_>
where Source: IGuardRef<T>, T: ?Sized,

Provides immutable access to a type as if it were its ABI-unstable equivalent.
Source§

fn mut_as<T>(&mut self) -> <Source as IGuardMut<T>>::GuardMut<'_>
where Source: IGuardMut<T>, T: ?Sized,

Provides mutable access to a type as if it were its ABI-unstable equivalent.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsNode<T> for T

Source§

fn as_node(&self) -> &T

Source§

impl<T> AsNodeMut<T> for T

Source§

fn as_node_mut(&mut self) -> &mut T

Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, As> IGuardMut<As> for T
where T: Into<As>, As: Into<T>,

Source§

type GuardMut<'a> = MutAs<'a, T, As> where T: 'a

The type of the guard which will clean up the temporary after applying its changes to the original.
Source§

fn guard_mut_inner(&mut self) -> <T as IGuardMut<As>>::GuardMut<'_>

Construct the temporary and guard it through a mutable reference.
Source§

impl<T, As> IGuardRef<As> for T
where T: Into<As>, As: Into<T>,

Source§

type Guard<'a> = RefAs<'a, T, As> where T: 'a

The type of the guard which will clean up the temporary.
Source§

fn guard_ref_inner(&self) -> <T as IGuardRef<As>>::Guard<'_>

Construct the temporary and guard it through an immutable reference.
Source§

impl<T> Includes<End> for T

Source§

type Output = End

The result
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more