Mads
Multi-Agent Distributed System
Loading...
Searching...
No Matches
Mads::TopicStats Class Reference

Thread-safe sliding-window aggregator of per-topic msg/s and bytes/s, fed by record() and read back via snapshot(). More...

#include <topic_stats.hpp>

Public Member Functions

 TopicStats (std::chrono::milliseconds window=std::chrono::seconds(5))
 
void record (const std::string &topic, size_t bytes, std::string sample=std::string(), std::chrono::steady_clock::time_point now=std::chrono::steady_clock::now())
 Records one observed message for topic.
 
std::vector< TopicStatsnapshot (std::chrono::steady_clock::time_point now=std::chrono::steady_clock::now()) const
 Snapshot of every topic seen so far, as of now.
 
void set_window (std::chrono::milliseconds window)
 Changes the trailing window used by future record()/snapshot() calls.
 
std::chrono::milliseconds window () const
 
void clear ()
 

Detailed Description

Thread-safe sliding-window aggregator of per-topic msg/s and bytes/s, fed by record() and read back via snapshot().

Only events within the trailing window (relative to the timestamp passed to record()/snapshot()) count toward the rate; total_messages/last_seen/ last_size/last_sample are lifetime bookkeeping that the window never discards. record() prunes each topic's own expired events as it appends, so memory stays bounded by (window duration x that topic's historical peak rate); a topic that goes silent simply stops growing.

Definition at line 64 of file topic_stats.hpp.

Constructor & Destructor Documentation

◆ TopicStats()

Mads::TopicStats::TopicStats ( std::chrono::milliseconds  window = std::chrono::seconds(5))
explicit

Member Function Documentation

◆ clear()

void Mads::TopicStats::clear ( )

Forgets every topic. Not used by mads top today; exposed for tests and completeness.

◆ record()

void Mads::TopicStats::record ( const std::string &  topic,
size_t  bytes,
std::string  sample = std::string(),
std::chrono::steady_clock::time_point  now = std::chrono::steady_clock::now() 
)

Records one observed message for topic.

Parameters
topicThe message's topic.
bytesSize of the message in bytes.
sampleOptional short preview of the payload; when empty, the previous last_sample (if any) is left unchanged.
nowTimestamp of the observation. Defaults to steady_clock::now() for production use; tests pass synthetic, monotonically-nondecreasing-per-topic values for determinism.

◆ set_window()

void Mads::TopicStats::set_window ( std::chrono::milliseconds  window)

Changes the trailing window used by future record()/snapshot() calls.

◆ snapshot()

std::vector< TopicStat > Mads::TopicStats::snapshot ( std::chrono::steady_clock::time_point  now = std::chrono::steady_clock::now()) const

Snapshot of every topic seen so far, as of now.

Read-only: does not mutate any retained state (pruning of long-expired events happens lazily, on the next record() for that topic). Sorted by topic name for a stable, diff-friendly table.

Parameters
nowInstant the trailing window is measured back from. Defaults to steady_clock::now(); tests pass a synthetic value.

◆ window()

std::chrono::milliseconds Mads::TopicStats::window ( ) const

The documentation for this class was generated from the following file: