pub struct StatsTable { /* private fields */ }Expand description
The table. Feed it samples; read it per key or in aggregate.
Bounded. A CLI runs for --for seconds and exits, so an unbounded
map was fine; a GUI left open overnight on a bus carrying content-addressed
or per-request keys would grow one entry per key forever. The table
therefore keeps at most DEFAULT_MAX_KEYS entries, evicting the
least-recently-seen first — the keys that stopped publishing are the ones a
live view has least use for — and counts every eviction, so a shrinking
key set is never mistaken for a quiet bus (RFC 09 §5.1).
The keys are Arc<str> rather than String so that
rows — the copy the ingest lock is held for (#330) — is a
refcount bump per key and not a per-key allocation. Lookups still borrow:
Arc<str>: Borrow<str>, so get(&str) allocates nothing on the hot hit
path.
Implementations§
Source§impl StatsTable
impl StatsTable
pub fn new() -> Self
Sourcepub fn with_capacity(max_keys: usize) -> Self
pub fn with_capacity(max_keys: usize) -> Self
A table bounded at max_keys entries.
Sourcepub fn unwatched(&self) -> u64
pub fn unwatched(&self) -> u64
Keys retired because no active watch covers them any more
(retire_unwatched).
The third O6 category, deliberately distinct from
evicted (“chose to forget under the bound”) and the
broadcast’s dropped (“could not keep up”): this one is “stopped
looking, by request” — and a key set that shrinks because the user
unwatched a subtree must say so, or it reads as a quieting bus.
Sourcepub fn retire_unwatched(&mut self, gone: &str, kept: &[String]) -> usize
pub fn retire_unwatched(&mut self, gone: &str, kept: &[String]) -> usize
Retire every key that gone covers and no selector in kept still
covers, counting them under unwatched. Returns
how many were retired. Selectors that fail to parse as key
expressions cover nothing (gone) / keep nothing (kept).
Sourcepub fn record(
&mut self,
key: &str,
payload_len: usize,
sn: Option<u32>,
now: Instant,
latency: Option<(i64, StampClass)>,
stamper: Option<TimestampId>,
)
pub fn record( &mut self, key: &str, payload_len: usize, sn: Option<u32>, now: Instant, latency: Option<(i64, StampClass)>, stamper: Option<TimestampId>, )
Record one sample. now is injected for deterministic tests;
latency is the pre-computed skewed latency (#119) with the class of
clock that produced it (#213) — None for an unstamped sample, which
is counted, not defaulted. stamper names a third-party stamping node
when there was one.
pub fn get(&self, key: &str) -> Option<&KeyStats>
pub fn iter(&self) -> impl Iterator<Item = (&str, &KeyStats)>
Sourcepub fn rows(&self) -> TreeRows
pub fn rows(&self) -> TreeRows
The compact rows a KeyTreeSnapshot is
folded from, plus the table’s own O6 counters (#330).
This is the whole of what the tree needs, and it is deliberately a
copy: MonitorCore::tick holds the ingest
mutex for exactly this call and folds afterwards, so the network
callback thread waits on an O(keys) walk of Copy fields and one
refcount bump per key — never on the O(keys × chunks) BTreeMap
descent with a String allocation per new node that the fold is.
Before the split, four ticks a second each held the lock for the whole
rebuild, and Monitor::watch’s promise that a slow UI cannot push
back into the network layer was false for as long as each one took.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Debug for StatsTable
impl Debug for StatsTable
Auto Trait Implementations§
impl Freeze for StatsTable
impl RefUnwindSafe for StatsTable
impl Send for StatsTable
impl Sync for StatsTable
impl Unpin for StatsTable
impl UnsafeUnpin for StatsTable
impl UnwindSafe for StatsTable
Blanket Implementations§
Source§impl<Source> AccessAs for Source
impl<Source> AccessAs for Source
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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