25#include "sparta/utils/StringManager.hpp"
26#include "sparta/statistics/Expression.hpp"
31class ContextCounterTrigger;
69 expr_str(rhp.expr_str)
72 std::unique_ptr<sparta::statistics::expression::Expression> expr_obj;
137 prebuilt_expr_(std::move(rhp.prebuilt_expr_)),
138 expr_str_(rhp.expr_str_),
139 context_(rhp.context_),
140 semantic_(rhp.semantic_)
145 if(parent !=
nullptr){
172 const std::string& name,
173 const std::string& group,
175 const std::string& desc,
186 prebuilt_expr_(std::move(expression.expr_obj)),
187 expr_str_(std::move(expression.expr_str)),
194 "Cannot construct a StatisticDef with VS_INVALID value semantic");
196 if(prebuilt_expr_ !=
nullptr){
197 expr_str_ = prebuilt_expr_->stringize();
199 if(context_ ==
nullptr){
201 <<
getLocation() <<
" context must not be nullptr. It must be a TreeNode which "
202 "will be used to look up any Node names found in the expression";
207 <<
getLocation() <<
" without a prebuilt expression, the expression string "
208 "must not be \"\". It must be a non-empty string containing an arithmetic "
209 "expression referring to nodes relative to the context \""
214 ensureParentIsStatisticSet_(parent);
228 const std::string& group,
230 const std::string& desc,
256 const std::string& name,
257 const std::string& desc,
283 const std::string& desc,
308 const std::string& name,
309 const std::string& group,
311 const std::string& desc,
331 const std::string& group,
333 const std::string& desc,
355 const std::string& name,
356 const std::string& desc,
378 const std::string& desc,
396 const std::string& name,
397 const std::string& group,
399 const std::string& desc,
420 const std::string& group,
422 const std::string& desc,
446 const std::string& name,
447 const std::string& desc,
471 const std::string& desc,
508 const std::string & stat_name) :
509 stat_node_(stat_node),
510 stat_name_(stat_name)
515 const std::string & getName()
const {
519 const TreeNode * stat_node_ =
nullptr;
520 std::string stat_name_;
523 inline const std::vector<PendingSubStatCreationInfo> & getSubStatistics()
const {
524 return sub_statistics_;
544 void deregisterAggregationFcnUponDestruction_()
const {
551 if (auto_cc_deregister_ ==
nullptr) {
552 auto_cc_deregister_.reset(
new AutoContextCounterDeregistration(
this));
569 const std::string & stat_name)
const {
570 sub_statistics_.emplace_back(stat_node, stat_name);
596 return *prebuilt_expr_;
619 virtual std::string
stringize(
bool pretty=
false)
const override {
621 std::stringstream ss;
639 void ensureParentIsStatisticSet_(
TreeNode*);
645 virtual void validateNode_()
const override {
651 }
catch(SpartaException &ex){
652 throw SpartaException(
"Failed to validate StatisticDef: \"") <<
getLocation()
653 <<
"\": " << ex.what();
663 std::unique_ptr<sparta::statistics::expression::Expression> prebuilt_expr_;
672 std::string expr_str_;
688 mutable std::vector<PendingSubStatCreationInfo> sub_statistics_;
695 class AutoContextCounterDeregistration {
697 explicit AutoContextCounterDeregistration(
const StatisticDef * sd);
698 ~AutoContextCounterDeregistration();
700 const StatisticDef *
const sd_;
703 mutable std::unique_ptr<AutoContextCounterDeregistration> auto_cc_deregister_;
Virtual interface node for simulator instrumentation (e.g. counters, stats, nontifications).
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.
Exception class for all of Sparta.
Basic Node framework in sparta device tree composite pattern.
@ TYPE_STATISTICDEF
Statisitic definition.
uint32_t visibility_t
Continuous visibility level. Several key points along continum are indicated within Visibility.
static constexpr visibility_t DEFAULT_VISIBILITY
Default node visibility.
visibility_t getVisibility() const
Gets the visibility hint of this node. This is invariant after construction.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
This helper class serves as a placeholder for substatistic creation.
Contains a statistic definition (some useful information which can be computed)
virtual std::string stringize(bool pretty=false) const override
Create a string representation of this node.
std::string getExpression() const
Returns a reference to the expression string which this node was constructed with or a rendering of t...
friend class trigger::ContextCounterTrigger
StatisticDef(const std::string &name, const std::string &group, group_idx_type group_idx, const std::string &desc, TreeNode *context, ExpressionArg expression, ValueSemantic semantic)
Constructor.
sparta::statistics::expression::Expression realizeExpression(std::vector< const TreeNode * > &used) const
Returns a unique Expression for this StatisticInstance given a set of substitutions that the expressi...
StatisticDef(const std::string &name, const std::string &desc, TreeNode *context, ExpressionArg expression)
TreeNode constructor with no parent node or group information.
StatisticDef(const StatisticDef &)=delete
Not copy-constructable.
StatisticDef(TreeNode *parent, const std::string &name, const std::string &group, group_idx_type group_idx, const std::string &desc, TreeNode *context, ExpressionArg expression, ValueSemantic semantic, visibility_t visibility)
Constructor with string expression.
void addSubStatistic_(const TreeNode *stat_node, const std::string &stat_name) const
Allow subclasses to forward along substatistic information to this stat definition....
StatisticDef(TreeNode *parent, const std::string &name, const std::string &group, group_idx_type group_idx, const std::string &desc, TreeNode *context, ExpressionArg expression, ValueSemantic semantic)
Constructor.
ValueSemantic getValueSemantic() const
Retuns the value-semantic associated with this node at construction.
StatisticDef & operator=(const StatisticDef &)=delete
Not assign-constructable.
StatisticDef(const StatisticDef &&)=delete
Not move-constructable (too complicated)
StatisticDef(TreeNode *parent, const std::string &name, const std::string &desc, TreeNode *context, ExpressionArg expression, ValueSemantic semantic, visibility_t visibility)
Constructor.
StatisticDef(const std::string &name, const std::string &group, group_idx_type group_idx, const std::string &desc, TreeNode *context, ExpressionArg expression, ValueSemantic semantic, visibility_t visibility)
Constructor.
ValueSemantic
How should the value of this statistic be interpreted Certain outputters (e.g. report formatters) may...
@ VS_INVALID
Invalid semantic. No StatisticDef should have this value semantic.
@ VS_FRACTIONAL
A fractional number. This value should be in the range [0,1]. Some report formatters could show this ...
@ VS_PERCENTAGE
A percentage. This value should be in the range [0,100]. Some report formatters may add a '' when dis...
@ VS_ABSOLUTE
An absolute number having no units (typical default)
StatisticDef(TreeNode *parent, const std::string &name, const std::string &desc, TreeNode *context, ExpressionArg expression)
Constructor.
StatisticDef(const std::string &name, const std::string &desc, TreeNode *context, ExpressionArg expression, ValueSemantic semantic)
TreeNode constructor with no parent node or group information.
std::string getContextLocation() const
Get the TreeNode location where this StatisticDef lives. Returns an empty string if the TreeNode* giv...
StatisticDef(const std::string &name, const std::string &desc, TreeNode *context, ExpressionArg expression, ValueSemantic semantic, visibility_t visibility)
TreeNode constructor with no parent node or group information.
StatisticDef(const std::string &name, const std::string &group, group_idx_type group_idx, const std::string &desc, TreeNode *context, ExpressionArg expression)
Constructor.
StatisticDef(TreeNode *parent, const std::string &name, const std::string &desc, TreeNode *context, ExpressionArg expression, ValueSemantic semantic)
Constructor.
StatisticDef(StatisticDef &&rhp)
Move constructor.
StatisticDef(TreeNode *parent, const std::string &name, const std::string &group, group_idx_type group_idx, const std::string &desc, TreeNode *context, ExpressionArg expression)
Constructor.
virtual ~StatisticDef()
Virtual destructor.
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_NONE[]
Group name indicating that a node belongs to no group.
TreeNode()=delete
Not default-constructable.
void addChild(TreeNode *child, bool inherit_phase=true)
Adds a TreeNode to this node as a child.
virtual TreeNode * getParent()
Gets immediate parent of this node if one exists.
uint32_t group_idx_type
Index within a group.
void stringizeTags(std::stringstream &ss) const
Render tags to a string in the form: " tags:[tag0, tag1]" If there are any tags. The leading space ma...
void setExpectedParent_(const TreeNode *parent)
Tracks a node as an expected parent without actually adding this node as a child. This is used almost...
Expression container/builder. Contains a single ExpressionNode representing the root of an expression...
Macros for handling exponential backoff.
Intermediate type for minimizing the number of distinct constructors that must be created for this cl...