175 static_assert(std::is_integral_v<value_t> && std::is_signed_v<value_t>,
176 "Histogram_counter shall support negative outcomes albeit only integer ones.");
345 template<
typename Recorded_duration,
typename Duration>
543 static_assert(
sizeof(
count_t) >= 8,
544 "We must use 64+-bit counters, so as to not need to contend with overflow.");
546 if constexpr(
sizeof(
count_t) <= 4)
548 if (count != std::numeric_limits<count_t>::max())
560template<
typename Recorded_duration,
typename Duration>
563 record_value(boost::chrono::round<Recorded_duration>(val).count());
Stats counter: tracks a histogram that summarizes, cumulatively, the numeric outcome of an event that...
count_t count_for_bucket(size_t idx) const
Returns the event count accumulated so far in the bucket with the given index.
void record_period(Duration val)
Convenience wrapper for record_value() that records a duration in the units specified as the mandator...
size_t idx_of_outcome(value_t val) const
Which index into m_per_bucket_counts points to the appropriate bucket for record_value(val)?
Histogram_counter & operator-=(const Histogram_counter &src)
Delta: bucket-by-bucket, makes *this bucket's count decremented by src's corresponding bucket's count...
std::vector< std::atomic< count_t > > m_per_bucket_counts
The data.
Histogram_counter & operator=(const Histogram_counter &src)
Straightforward copy assignment.
Histogram_counter & operator/=(count_t divisor)
Scaler: bucket-by-bucket, makes this->count_for_bucket(idx) equal to v / divisor, where v is its pre-...
void record_value(T val)
Record event outcome.
value_t m_bucket_n_sz
Bucket structure: an addendum to m_bucket_val0s, this is the positive width of the last of size() buc...
value_t m_linear_bucket_sz_or_0
If size() == 2, or the non-bookend buckets are not all of the same width, this is zero; else the (pos...
uint64_t count_t
The count type.
size_t size() const
Returns the number of buckets in the histogram, as supplied to ctor as n_buckets.
int64_t value_t
Each event outcome recorded by record_value() must fit in the range of this type.
void clear()
Returns *this to the state as-if just-cted with the current bucket structure. Uses stat::store() x N.
Histogram_counter & operator+=(const Histogram_counter &src)
Aggregator: bucket-by-bucket, makes *this bucket's count incremented by src's corresponding bucket's ...
void to_ostream(std::ostream *os) const
Prints string representation to the given ostream.
Histogram_counter(size_t n_buckets, value_t bucket0_sz, value_t bucket_sz=1, value_t bucket0_val0=0)
Allocates the histogram data structure (linear-scale: bucket widths [ABBB...]) and initializes each b...
void overwrite_count_for_bucket(size_t idx, count_t new_count)
Set a bucket-value so that count_for_bucket(idx) == new_count.
std::vector< value_t > m_bucket_val0s
General bucket structure (except the last bucket's width): in strictly increasing order,...
count_t count_for_bucket_containing_outcome(T val) const
Returns count_for_bucket(idx), where idx is the index of the bucket into which val would fall,...
Fine_duration Duration
Short-hand for a high-precision boost.chrono duration, formally equivalent to flow::Fine_duration.
Sub-module of flow::util providing lightweight facilities for working with simple structs of stat cou...
const T & load(const T &val)
Default load(stats.m_val) that simply return stats.m_val.
void fetch_add(T *target_val, const boost::type_identity_t< T > &addend_val)
Default fetch_add(&target_stats.m_val, addend_val) that simply applies *target_val += addend_val.