![]() |
Mads
Multi-Agent Distributed System
|
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< TopicStat > | snapshot (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 () |
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.
|
explicit |
| void Mads::TopicStats::clear | ( | ) |
Forgets every topic. Not used by mads top today; exposed for tests and completeness.
| 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.
| topic | The message's topic. |
| bytes | Size of the message in bytes. |
| sample | Optional short preview of the payload; when empty, the previous last_sample (if any) is left unchanged. |
| now | Timestamp of the observation. Defaults to steady_clock::now() for production use; tests pass synthetic, monotonically-nondecreasing-per-topic values for determinism. |
| void Mads::TopicStats::set_window | ( | std::chrono::milliseconds | window | ) |
Changes the trailing window used by future record()/snapshot() calls.
| 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.
| now | Instant the trailing window is measured back from. Defaults to steady_clock::now(); tests pass a synthetic value. |
| std::chrono::milliseconds Mads::TopicStats::window | ( | ) | const |