20 static_assert(std::is_unsigned_v<T>,
"wrap-safe deltas need unsigned arithmetic");
26 const T delta =
static_cast<T
>(total - prev_);
36template <
typename T>
constexpr T
window_avg(T sum, T count) {
return count ?
static_cast<T
>(sum / count) : T{0}; }
41 return whole ?
static_cast<unsigned>(part * 100 / whole) : 0u;
Remembers the previous reading of a free-running unsigned counter; sample() returns the delta since.
Definition windowed_counter.h:19
T sample(T total)
Record total as the new reading and return how much it grew since the previous call (0 first).
Definition windowed_counter.h:24
constexpr unsigned window_percent(uint64_t part, uint64_t whole)
100 * part / whole as an integer percent, or 0 when whole is 0 (an empty window).
Definition windowed_counter.h:39
constexpr T window_avg(T sum, T count)
sum / count, or 0 when count is 0 (an empty window).
Definition windowed_counter.h:36