25#include "sparta/utils/StringManager.hpp"
26#include "sparta/statistics/Expression.hpp"
32 class ContextCounterTrigger;
70 expr_str(rhp.expr_str)
73 std::unique_ptr<sparta::statistics::expression::Expression> expr_obj;
163 class ValueSemanticDetailed
181 const InstrumentationNode::MetadataPairs & meta_data) :
183 meta_data_(meta_data)
190 const InstrumentationNode::MetadataPairs &
getMetadata()
const {
196 const InstrumentationNode::MetadataPairs meta_data_;
218 prebuilt_expr_(std::move(rhp.prebuilt_expr_)),
219 expr_str_(rhp.expr_str_),
220 context_(rhp.context_),
221 semantic_(rhp.semantic_)
225 if(parent !=
nullptr){
252 const std::string& name,
253 const std::string& group,
255 const std::string& desc,
266 prebuilt_expr_(std::move(expression.expr_obj)),
267 expr_str_(std::move(expression.expr_str)),
274 "Cannot construct a StatisticDef with VS_INVALID value semantic");
276 if(prebuilt_expr_ !=
nullptr){
277 expr_str_ = prebuilt_expr_->stringize();
279 if(context_ ==
nullptr){
281 <<
getLocation() <<
" context must not be nullptr. It must be a TreeNode which "
282 "will be used to look up any Node names found in the expression";
287 <<
getLocation() <<
" without a prebuilt expression, the expression string "
288 "must not be \"\". It must be a non-empty string containing an arithmetic "
289 "expression referring to nodes relative to the context \""
294 ensureParentIsStatisticSet_(parent);
305 semantic.getMetadata().begin(),
306 semantic.getMetadata().end());
313 const std::string& group,
315 const std::string& desc,
317 ExpressionArg expression,
318 ValueSemanticDetailed semantic,
341 const std::string& name,
342 const std::string& desc,
344 ExpressionArg expression,
345 ValueSemanticDetailed semantic,
368 const std::string& desc,
370 ExpressionArg expression,
371 ValueSemanticDetailed semantic,
393 const std::string& name,
394 const std::string& group,
396 const std::string& desc,
398 ExpressionArg expression) :
416 const std::string& group,
418 const std::string& desc,
420 ExpressionArg expression) :
440 const std::string& name,
441 const std::string& desc,
443 ExpressionArg expression) :
463 const std::string& desc,
465 ExpressionArg expression) :
481 const std::string& name,
482 const std::string& group,
484 const std::string& desc,
486 ExpressionArg expression,
487 ValueSemanticDetailed semantic) :
505 const std::string& group,
507 const std::string& desc,
509 ExpressionArg expression,
510 ValueSemanticDetailed semantic) :
531 const std::string& name,
532 const std::string& desc,
534 ExpressionArg expression,
535 ValueSemanticDetailed semantic) :
556 const std::string& desc,
558 ExpressionArg expression,
559 ValueSemanticDetailed semantic) :
589 class PendingSubStatCreationInfo
592 PendingSubStatCreationInfo(
const TreeNode * stat_node,
593 const std::string & stat_name) :
594 stat_node_(stat_node),
595 stat_name_(stat_name)
600 const std::string & getName()
const {
604 const TreeNode * stat_node_ =
nullptr;
605 std::string stat_name_;
608 inline const std::vector<PendingSubStatCreationInfo> & getSubStatistics()
const {
609 return sub_statistics_;
629 void deregisterAggregationFcnUponDestruction_()
const {
636 if (auto_cc_deregister_ ==
nullptr) {
637 auto_cc_deregister_.reset(
new AutoContextCounterDeregistration(
this));
654 const std::string & stat_name)
const {
655 sub_statistics_.emplace_back(stat_node, stat_name);
681 return *prebuilt_expr_;
704 virtual std::string
stringize(
bool pretty=
false)
const override {
706 std::stringstream ss;
724 void ensureParentIsStatisticSet_(
TreeNode*);
730 virtual void validateNode_()
const override {
736 }
catch(SpartaException &ex){
737 throw SpartaException(
"Failed to validate StatisticDef: \"") <<
getLocation()
738 <<
"\": " << ex.what();
748 std::unique_ptr<sparta::statistics::expression::Expression> prebuilt_expr_;
757 std::string expr_str_;
767 const ValueSemanticDetailed semantic_;
773 mutable std::vector<PendingSubStatCreationInfo> sub_statistics_;
780 class AutoContextCounterDeregistration {
782 explicit AutoContextCounterDeregistration(
const StatisticDef * sd);
783 ~AutoContextCounterDeregistration();
788 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.
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.
uint32_t visibility_t
Continuous visibility level. Several key points along continum are indicated within Visibility.
MetadataPairs meta_data_
Add any arbitrary metadata as strings to this object. Used to add extra information to statistics rep...
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Wrapper class to add meta information to a statistic definition.
const InstrumentationNode::MetadataPairs & getMetadata() const
Get the meta data provided by the user.
ValueSemanticDetailed(ValueSemantic semantic)
Construct a ValueSemanticDetailed without meta data.
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
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 StatisticDef &)=delete
Not copy-constructable.
void addSubStatistic_(const TreeNode *stat_node, const std::string &stat_name) const
Allow subclasses to forward along substatistic information to this stat definition....
ValueSemantic getValueSemantic() const
Retuns the value-semantic associated with this node at construction.
StatisticDef & operator=(const StatisticDef &)=delete
Not assign-constructable.
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)
std::string getContextLocation() const
Get the TreeNode location where this StatisticDef lives. Returns an empty string if the TreeNode* giv...
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.
uint32_t group_idx_type
Index within a group.
virtual TreeNode * getParent()
Gets immediate parent of this node if one exists.
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...