14#include "sparta/utils/MathUtils.hpp"
17#include "sparta/statistics/Counter.hpp"
36template <
class EnumType>
40 typedef EnumType value_type;
77 std::string histogram_name,
78 std::string description
82 lower_val_(static_cast<uint64_t>(EnumType::__FIRST)),
83 upper_val_(static_cast<uint64_t>(EnumType::__LAST ) - 1),
88 "Total values added to the histogram",
96 "Histogram: upper value must be greater than lower value");
98 "Histogram: num_vals_per_bin must be power of 2");
99 idx_shift_amount_ = utils::floor_log2(num_vals_per_bin_);
100 double actual_num_bins = (upper_val_ - lower_val_)/num_vals_per_bin_ + 1;
101 num_bins_ = (uint64_t) actual_num_bins;
103 "Histogram: Actual number of bins (" << actual_num_bins
104 <<
") is not an integer");
107 bin_.reserve(num_bins_);
114 "Probability of underflow",
117 uint64_t start_val = lower_val_;
118 uint64_t end_val = start_val + num_vals_per_bin_ - 1;
119 for (uint32_t i=0; i<num_bins_; ++i) {
120 if (end_val > upper_val_)
121 end_val = upper_val_;
122 std::stringstream str;
126 str.str() +
" histogram bin",
129 str.str() +
"_probability",
130 str.str() +
" bin probability",
132 str.str() +
"/total"));
133 start_val = end_val + 1;
134 end_val += num_vals_per_bin_;
141 "Probability of overflow",
158 uint64_t val =
static_cast<uint64_t
>(enum_val);
161 if (val < lower_val_) {
162 ++ (*underflow_bin_);
164 else if (val > upper_val_) {
168 uint32_t idx = (val - lower_val_) >> idx_shift_amount_;
173 uint64_t getHistogramUpperValue()
const {
return upper_val_; }
174 uint64_t getHistogramLowerValue()
const {
return lower_val_; }
175 uint32_t getNumBins()
const {
return num_bins_; }
176 uint32_t getNumValuesPerBin()
const {
return num_vals_per_bin_; }
184 std::stringstream str;
186 uint64_t running_sum = *underflow_bin_;
187 str <<
"\t" <<
getName() <<
"[ UF ] = " << running_sum << std::endl;
188 uint64_t start_val = lower_val_;
189 uint64_t end_val = start_val + num_vals_per_bin_ - 1;
190 for (uint32_t i=0; i<num_bins_; ++i) {
191 if (end_val > upper_val_)
192 end_val = upper_val_;
193 running_sum += (bin_[i]);
197 << running_sum << std::endl;
198 end_val += num_vals_per_bin_;
200 running_sum += *overflow_bin_;
201 str <<
"\t" <<
getName() <<
"[ OF ] = " << running_sum << std::endl;
206 const uint64_t lower_val_;
207 const uint64_t upper_val_;
208 const uint32_t num_vals_per_bin_;
214 std::vector<sparta::Counter> bin_;
215 std::unique_ptr<sparta::StatisticDef> underflow_probability_;
216 std::unique_ptr<sparta::StatisticDef> overflow_probability_;
217 std::vector<std::unique_ptr<sparta::StatisticDef>> probabilities_;
224 uint32_t idx_shift_amount_;
File that defines the Resource class. Consider using sparta::Unit instead.
#define sparta_assert_context(e, insertions)
Check condition and throw a sparta exception if condition evaluates to false or 0....
Set of macros for Sparta assertions. Caught by the framework.
Contains a statistic definition (some useful information which can be computed)
File that defines the StatisticSet class.
Basic Node framework in sparta device tree composite pattern.
@ COUNT_NORMAL
Counter counts the number of times something happens like one would expect. This is a weakly monotoni...
Represents a counter of type counter_type (uint64_t). 2 and greater than 0 with a ceiling specified....
EnumHistogram class for sparta::utils::Enum.
EnumHistogram(EnumHistogram &&)=delete
Not move-constructable.
void addValue(EnumType enum_val)
Add a value to histogram.
void operator=(const EnumHistogram &)=delete
Not assignable.
std::string getDisplayStringCumulative() const
Render the cumulative values of this histogram for use in standalone model.
EnumHistogram(const EnumHistogram &)=delete
Not copy-constructable.
EnumHistogram(TreeNode *parent_treenode, std::string histogram_name, std::string description)
EnumHistogram constructor.
EnumHistogram()=delete
Not default constructable.
Contains a statistic definition (some useful information which can be computed)
Set of StatisticDef and CounterBase-derived objects for visiblility through a sparta Tree.
CounterT & createCounter(_Args &&... __args)
Allocates a Counter which is owned by this StatisticSet and deleted at its destruction.
Node in a composite tree representing a sparta Tree item.
void addChild(TreeNode *child, bool inherit_phase=true)
Adds a TreeNode to this node as a child.
const std::string & getName() const override
Gets the name of this node.
void setExpectedParent_(const TreeNode *parent)
Tracks a node as an expected parent without actually adding this node as a child. This is used almost...
Macros for handling exponential backoff.