8 _windowStartedUs = _clock();
13 _windowBytes += bytes;
14 _totalBytes +=
static_cast<quint64
>(bytes);
21 const quint64 now = _clock();
22 const quint64 elapsed = now >= _windowStartedUs ? now - _windowStartedUs : 0;
23 if (elapsed >= kWindowUs) {
24 _currentRate =
static_cast<double>(_windowBytes) /
static_cast<double>(elapsed) * 1000000.0;
27 _windowStartedUs = now;
44 _windowStartedUs = _clock();
void reset()
Reset all counters and restart the rate window.
DataRateTracker(Clock clock=MonotonicClock::nowUs)
std::function< quint64()> Clock
Monotonic microseconds, injectable for deterministic window tests.
void recordBytes(qsizetype bytes)
Record incoming/outgoing bytes. Call whenever data passes through.
void refresh()
Advance the rate window without changing cumulative bytes.
void resetRate()
Zero the rate and restart its window; cumulative bytes are kept.