QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
DataRateTracker Class Reference

#include <DataRateTracker.h>

Public Types

using Clock = std::function< quint64()>
 Monotonic microseconds, injectable for deterministic window tests.
 

Public Member Functions

 DataRateTracker (Clock clock=MonotonicClock::nowUs)
 
void recordBytes (qsizetype bytes)
 Record incoming/outgoing bytes. Call whenever data passes through.
 
void refresh ()
 Advance the rate window without changing cumulative bytes.
 
quint64 totalBytes () const
 Total bytes recorded since construction or last reset.
 
double bytesPerSec () const
 Rate of the last completed window, in bytes/sec.
 
double kBps () const
 Current data rate in KB/s.
 
bool rateUpdated () const
 
void reset ()
 Reset all counters and restart the rate window.
 
void resetRate ()
 Zero the rate and restart its window; cumulative bytes are kept.
 

Detailed Description

Lightweight, non-QObject helper that tracks a windowed data rate.

Call recordBytes() whenever data passes through and refresh() from a periodic UI timer to expire the rate during silence. Completed windows retain their rate until the next refresh or recordBytes call crosses a window boundary.

Thread safety: none — use from a single thread.

Definition at line 16 of file DataRateTracker.h.

Member Typedef Documentation

◆ Clock

using DataRateTracker::Clock = std::function<quint64()>

Monotonic microseconds, injectable for deterministic window tests.

Definition at line 20 of file DataRateTracker.h.

Constructor & Destructor Documentation

◆ DataRateTracker()

DataRateTracker::DataRateTracker ( Clock  clock = MonotonicClock::nowUs)
explicit

Definition at line 5 of file DataRateTracker.cc.

Member Function Documentation

◆ bytesPerSec()

double DataRateTracker::bytesPerSec ( ) const
inline

Rate of the last completed window, in bytes/sec.

Definition at line 33 of file DataRateTracker.h.

Referenced by NTRIPConnectionStats::dataRateBytesPerSec().

◆ kBps()

double DataRateTracker::kBps ( ) const
inline

Current data rate in KB/s.

Definition at line 36 of file DataRateTracker.h.

◆ rateUpdated()

bool DataRateTracker::rateUpdated ( ) const
inline

Whether the rate was recalculated on the last recordBytes()/refresh() call. Useful for the caller to know when to emit signals.

Definition at line 40 of file DataRateTracker.h.

◆ recordBytes()

void DataRateTracker::recordBytes ( qsizetype  bytes)

Record incoming/outgoing bytes. Call whenever data passes through.

Definition at line 11 of file DataRateTracker.cc.

References refresh().

Referenced by NTRIPConnectionStats::recordMessage().

◆ refresh()

void DataRateTracker::refresh ( )

Advance the rate window without changing cumulative bytes.

Definition at line 19 of file DataRateTracker.cc.

Referenced by recordBytes(), and NTRIPConnectionStats::start().

◆ reset()

void DataRateTracker::reset ( )

Reset all counters and restart the rate window.

Definition at line 33 of file DataRateTracker.cc.

References resetRate().

Referenced by NTRIPConnectionStats::reset().

◆ resetRate()

void DataRateTracker::resetRate ( )

Zero the rate and restart its window; cumulative bytes are kept.

Definition at line 39 of file DataRateTracker.cc.

Referenced by reset(), and NTRIPConnectionStats::stop().

◆ totalBytes()

quint64 DataRateTracker::totalBytes ( ) const
inline

Total bytes recorded since construction or last reset.

Definition at line 30 of file DataRateTracker.h.

Referenced by NTRIPConnectionStats::bytesReceived().


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