14#include "sparta/utils/MathUtils.hpp"
17#include "sparta/statistics/Counter.hpp"
18#include "sparta/statistics/CycleCounter.hpp"
38template <
class StateEnumType>
74 std::string histogram_name,
75 std::string description,
76 const StateEnumType idle_value = StateEnumType::__FIRST) :
77 TreeNode(histogram_name, description),
78 lower_val_(static_cast<uint64_t>(StateEnumType::__FIRST)),
79 upper_val_(static_cast<uint64_t>(StateEnumType::__LAST) - 1),
80 idle_value_(static_cast<uint64_t>(idle_value)),
88 "StateHistogram: upper value must be greater than lower value");
89 num_bins_ = upper_val_ - lower_val_ + 1;
92 bin_.reserve(num_bins_);
94 uint64_t val = lower_val_;
95 std::string total_str;
97 for (uint32_t i = 0; i < num_bins_; ++i) {
98 std::stringstream str;
103 str.str() +
" histogram bin",
108 str.str() +
"_probability",
109 str.str() +
" bin probability",
111 str.str() +
"/total"));
114 if (total_str ==
"") {
115 total_str += str.str();
117 total_str +=
" + " + str.str();
132 startCounting_(idle_value_);
142 void setState(
const StateEnumType new_state)
144 uint32_t new_val =
static_cast<uint32_t
>(new_state);
145 if (new_val != curr_value_) {
146 stopCounting_(curr_value_);
147 startCounting_(new_val);
151 void setNextState(
const StateEnumType new_state)
153 uint32_t new_val =
static_cast<uint32_t
>(new_state);
154 if (new_val != curr_value_) {
155 stopCounting_(curr_value_, 1);
156 startCounting_(new_val, 1);
160 StateEnumType getState()
const
162 return static_cast<StateEnumType
>(curr_value_);
168 uint64_t getHistogramUpperValue()
const {
return upper_val_; }
169 uint64_t getHistogramLowerValue()
const {
return lower_val_; }
170 uint32_t getNumBins()
const {
return num_bins_; }
171 uint32_t getNumValuesPerBin()
const {
return 1; }
179 std::stringstream str;
181 uint64_t val = lower_val_;
182 for (uint32_t i = 0; i < num_bins_; ++i) {
185 << bin_[i] << std::endl;
199 void startCounting_(uint32_t val, uint32_t delay = 0) {
203 uint32_t idx = val - lower_val_;
205 (bin_.at(idx)).startCounting(delay);
218 void stopCounting_(uint32_t val, uint32_t delay = 0) {
222 uint32_t idx = val - lower_val_;
224 (bin_.at(idx)).stopCounting(delay);
227 const uint64_t lower_val_;
228 const uint64_t upper_val_;
229 const uint32_t idle_value_;
232 std::unique_ptr<sparta::StatisticDef> total_;
233 std::vector<sparta::CycleCounter> bin_;
234 std::vector<std::unique_ptr<sparta::StatisticDef>> probabilities_;
237 uint32_t curr_value_ = 0;
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.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
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 cycle counter.
StateHistogram class for uint64_t values.
StateHistogram()=delete
Not default constructable.
StateHistogram(const StateHistogram &)=delete
Not copy-constructable.
StateHistogram(StateHistogram &&)=delete
Not move-constructable.
StateHistogram(TreeNode *parent_treenode, std::string histogram_name, std::string description, const StateEnumType idle_value=StateEnumType::__FIRST)
StateHistogram constructor.
std::string getDisplayStringCumulative() const
Render the cumulative values of this histogram for use in standalone model.
void operator=(const StateHistogram &)=delete
Not assignable.
Contains a statistic definition (some useful information which can be computed)
Set of StatisticDef and CounterBase-derived objects for visiblility through a sparta Tree.
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 Clock * getClock() override
Walks up parents (starting with self) until a parent with an associated local clock is found,...
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.