VLink  2.0.0
A high-performance communication middleware
calculate_sample.h File Reference

Per-publisher gap detection used to expose sample loss statistics to subscribers. More...

#include <cstdint>
#include <shared_mutex>
#include <unordered_map>
#include "../base/macros.h"
Include dependency graph for calculate_sample.h:

Go to the source code of this file.

Classes

class  vlink::CalculateSample
 Tracks expected and lost sample counts grouped by sender GUID. More...
 

Namespaces

 

Detailed Description

Per-publisher gap detection used to expose sample loss statistics to subscribers.

This is an internal implementation header used by the public subscriber / getter templates and their backend NodeImpl classes; it is not part of the user API. CalculateSample inspects the monotonic sequence numbers attached to incoming frames and accumulates how many samples have been expected and how many have been skipped, on a per-sender basis.

Role
Caller What it does with CalculateSample
SubscriberImpl / GetterImpl Owns one instance when latency tracking is on.
Transport backend receive thread Calls update(seq, guid) for every frame.
get_lost() / proxy / discovery layer Reads cumulative counters for reporting.
Sizing summary
Counters are stored per GUID in a hash map, so memory grows linearly with the number of observed senders. Each entry contains three uint64_t values, and the table is guarded by a std::shared_mutex so reads from multiple reader threads do not contend with each other.
Algorithm
  • The first call for a GUID seeds first with the observed sequence number and expected with seq + 1, and records zero loss.
  • Subsequent in-order frames increment expected by one.
  • When seq is ahead of expected by at most UINT32_MAX, the gap is added to lost and expected jumps to seq + 1.
  • A gap strictly greater than UINT32_MAX is treated as a sender restart and the state is re-seeded with no extra loss recorded.
Note
get_total() returns the sum of (expected - first) across all GUIDs; get_lost() returns the sum of lost counters.