12#include "sparta/statistics/Counter.hpp"
41template<
typename BucketT,
bool ASSERT_ON_UNDERFLOW=false>
53 const std::string &name,
54 const std::string &desc,
55 const std::vector<BucketT> &buckets) :
58 sparta_assert(std::is_sorted(buckets.begin(), buckets.end()),
"Buckets must be sorted");
60 const auto bucket_size = bucket_vals_.size();
61 ctrs_.reserve(bucket_size);
64 for (
unsigned i = 0; i < bucket_size; ++i)
66 auto &v = bucket_vals_[i];
67 std::ostringstream os_name;
70 os_name << name <<
"_n" << -v;
74 os_name << name <<
'_' << v;
77 std::ostringstream os_desc;
80 os_desc << desc <<
" with values less than or equal to " << v;
84 os_desc << desc <<
" with values greater than " << bucket_vals_[i-1] <<
" and less than or equal to " << v;
106 auto bucket = std::upper_bound(bucket_vals_.begin(), bucket_vals_.end(), val);
109 if (bucket == bucket_vals_.begin())
111 sparta_assert(!ASSERT_ON_UNDERFLOW,
"Value below first bucket");
116 auto off = bucket - bucket_vals_.begin() - 1;
127 std::vector<BucketT> bucket_vals_;
128 std::vector<sparta::Counter> ctrs_;
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
BasicHistogram(sparta::StatisticSet &sset, const std::string &name, const std::string &desc, const std::vector< BucketT > &buckets)
Construct a BasicHistogram.
~BasicHistogram()
Destroy, non-virtual.
void addValue(const BucketT &val)
Charge a bucket where the given val falls.
BasicHistogram(const BasicHistogram &)=delete
Disallow copies/assignment/move.
@ COUNT_NORMAL
Counter counts the number of times something happens like one would expect. This is a weakly monotoni...
Set of StatisticDef and CounterBase-derived objects for visiblility through a sparta Tree.
Macros for handling exponential backoff.