15#include "sparta/statistics/CounterBase.hpp"
50 "Statistic and Counter Set")
65 virtual std::string
stringize(
bool pretty=
false)
const override {
68 ss <<
'<' <<
getLocation() <<
' ' << (stats_.size()) <<
" stats, "
69 << (ctrs_.size()) <<
" counters>";
97 return getChildAs<StatisticDef>(name);
118 template<
typename... _Args>
121 throw SpartaException(
"Cannot create a new StatisticDef once a StatisticSet is finalized. "
125 owned_stats_.emplace_back(
new StatisticDef(
this, __args...));
126 return *(
static_cast<StatisticDef *
>(owned_stats_.back().get()));
162 return getChildAs<CounterBase>(name);
174 return getChildAs<CounterBase>(name);
185 template<
class CounterT>
187 return getChildAs<CounterT>(name);
198 template<
class CounterT>
200 return getChildAs<CounterT>(name);
224 template<
class CounterT,
typename... _Args>
227 throw SpartaException(
"Cannot create a new Counter once a StatisticSet is finalized. "
231 owned_ctrs_.emplace_back(
new CounterT(
this, __args...));
232 return *((CounterT *)owned_ctrs_.back().get());
250 virtual void onAddingChild_(
TreeNode* child)
override {
252 throw SpartaException(
"Cannot add a child Counter once a StatisticSet is finalized. "
257 StatisticDef* stat =
dynamic_cast<StatisticDef*
>(child);
260 stats_.push_back(stat);
264 CounterBase* ctr =
dynamic_cast<CounterBase*
>(child);
267 ctrs_.push_back(ctr);
271 throw SpartaException(
"Cannot add TreeNode child ")
273 <<
" because the child is not a CounterBase or StatisticDef";
279 typedef std::vector<std::unique_ptr<StatisticDef>> OwnedStatisticVector;
285 OwnedStatisticVector owned_stats_;
296 typedef std::vector<std::unique_ptr<CounterBase>> OwnedCounterVector;
302 OwnedCounterVector owned_ctrs_;
Set of macros for Sparta assertions. Caught by the framework.
Exception class for all of Sparta.
Contains a statistic definition (some useful information which can be computed)
The base class for all Counters.
virtual bool isFinalized() const
Is this node (and thus the entire tree above it) "finalized".
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Contains a statistic definition (some useful information which can be computed)
Set of StatisticDef and CounterBase-derived objects for visiblility through a sparta Tree.
CounterBase * getCounter(const std::string &name)
Retrieves a child that is a Counter with the given dotted path.
std::vector< StatisticDef * > StatisticVector
Type for holding stat defs.
static constexpr char NODE_NAME[]
Name of all StatisticSet nodes.
~StatisticSet()
Destructor.
StatisticDef & createStatisticDef(_Args &&... __args)
Allocates a StatisticDef which is owned by this StatisticSet and deleted at its destruction.
std::vector< CounterBase * > CounterVector
Type for holding Counters.
CounterT & createCounter(_Args &&... __args)
Allocates a Counter which is owned by this StatisticSet and deleted at its destruction.
const CounterBase * getCounter(const std::string &name) const
Retrieves a child that is a Counter with the given dotted path.
const CounterT * getCounterAs(const std::string &name) const
Retrieves a child that is a Counter with the given dotted path.
virtual std::string stringize(bool pretty=false) const override
Create a string representation of this node.
CounterT * getCounterAs(const std::string &name)
Retrieves a child that is a Counter with the given dotted path (non-const).
const StatisticVector & getStatisticDefs() const
Gets the vector of StatisticDefs contained by this set.
uint32_t getNumCounters() const
Gets the number of counters in this Set.
StatisticSet(TreeNode *parent)
Constructor.
const CounterVector & getCounters() const
Gets the vector of Counters contained by this set.
uint32_t getNumStatisticDefs() const
Gets the number of counters in this Set.
StatisticDef * getStatisticDef(const std::string &name)
Retrieves a child that is a StatisticDef with the given dotted path.
Node in a composite tree representing a sparta Tree item.
static const group_idx_type GROUP_IDX_NONE
GroupIndex indicating that a node has no group index because it belongs to no group.
std::string getLocation() const override final
static constexpr char GROUP_NAME_BUILTIN[]
Reserved name for built-in nodes.
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.