18#include "sparta/statistics/CounterBase.hpp"
23#include "sparta/statistics/Expression.hpp"
25#include "sparta/statistics/dispatch/StatisticSnapshot.hpp"
30 class StatInstValueLookup;
31 class StatInstRowIterator;
32 using statistics::expression::Expression;
117 std::vector<const TreeNode*>* used);
159 std::vector<const TreeNode*>& used);
173 const std::string & description,
174 const std::string & expression_str,
178 const std::vector<std::pair<std::string, std::string>> & metadata = {});
187 const std::string & location,
188 const std::string & description,
189 const std::shared_ptr<StatInstCalculator> & calculator,
192 const std::vector<std::pair<std::string, std::string>> & metadata = {});
204 return sub_statistics_;
267 initial_.setIsCumulative(
true);
268 std::vector<const StatisticInstance*> stats_in_expr;
270 for (
const auto & stat : stats_in_expr) {
271 stat->accumulateStatistic();
288 const std::shared_ptr<sparta::StatInstValueLookup> & direct_lookup);
298 const StatInstRowIterator & si_row_iterator);
323 return initial_.getValue();
349 bool resolve_subexprs=
true)
const;
363 bool resolve_subexprs=
true)
const;
373 std::string
getDesc(
bool show_stat_node_expressions)
const;
382 void dump(std::ostream& o,
bool show_range=
false)
const;
391 snapshot_loggers_.emplace_back(snapshot);
399 snapshot_loggers_.clear();
445 const std::vector<std::pair<std::string, std::string>> &
getMetadata()
const {
446 return provided_metadata_;
496 void getClocks(std::vector<const Clock*>& clocks)
const;
516 scheduler_ = scheduler;
528 double computeValue_()
const;
541 double getCurrentValueFromDirectLookup_()
const;
548 sub_statistics_.emplace_back(creation_info);
563 const StatisticDef* sdef_ =
nullptr;
569 const CounterBase* ctr_ =
nullptr;
575 const ParameterBase* par_ =
nullptr;
602 mutable const Scheduler * scheduler_ =
nullptr;
607 const Scheduler * getScheduler_()
const;
615 class InitialStatValue {
617 InitialStatValue(
const double value) :
618 is_cumulative_(false),
621 if (std::isnan(initial_.getValue())) {
622 initial_.clearValid();
626 InitialStatValue(
const InitialStatValue & rhp) :
627 is_cumulative_(rhp.is_cumulative_),
628 initial_(rhp.initial_)
631 InitialStatValue & operator=(
const InitialStatValue & rhp) {
632 is_cumulative_ = rhp.is_cumulative_;
633 initial_ = rhp.initial_;
637 void setIsCumulative(
const bool is_cumulative) {
638 is_cumulative_ = is_cumulative;
641 double getValue()
const {
642 return initial_.isValid() ? initial_.getValue() : 0;
645 void resetValue(
const double initial) {
646 if (is_cumulative_) {
647 if (!initial_.isValid()) {
656 bool is_cumulative_ =
false;
657 utils::ValidValue<double> initial_;
663 mutable InitialStatValue initial_{NAN};
673 mutable std::vector<statistics::StatisticSnapshot> snapshot_loggers_;
678 mutable std::vector<StatisticDef::PendingSubStatCreationInfo> sub_statistics_;
683 std::shared_ptr<StatInstCalculator> user_calculated_si_value_;
694 std::shared_ptr<sparta::StatInstValueLookup> direct_lookup_si_value_;
707 utils::ValidValue<std::string> provided_location_;
708 utils::ValidValue<std::string> provided_description_;
709 utils::ValidValue<std::string> provided_expr_string_;
710 utils::ValidValue<StatisticDef::ValueSemantic> provided_value_semantic_;
711 utils::ValidValue<InstrumentationNode::visibility_t> provided_visibility_;
712 utils::ValidValue<InstrumentationNode::class_t> provided_class_;
713 std::vector<std::pair<std::string, std::string>> provided_metadata_;
File that defines the Clock class.
Individual Parameter interface base class, container class, and global helpers methods.
A simple time-based, event precedence based scheduler.
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.
Contains a statistic definition (some useful information which can be computed)
Scheduler * getScheduler() const
The base class for all Counters.
Exception indicating that the range of a StatisticInstance starts or ends in the future (probably cau...
FutureStatisticRange(const std::string &reason)
Construct with a default string.
virtual ~FutureStatisticRange() noexcept
Destructor.
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.
static constexpr class_t DEFAULT_CLASS
Default node class.
uint32_t class_t
Continuous Class level. Several key points along continum are indicated within Class.
Non-templated base class for generic parameter access and iteration.
Exception indicating that the range of a StatisticInstance was reversed when it was accessed (probabl...
ReversedStatisticRange(const std::string &reason)
Construct with a default string.
virtual ~ReversedStatisticRange() noexcept
Destructor.
A class that lets you schedule events now and in the future.
uint64_t Tick
Typedef for our unit of time.
static const Tick INDEFINITE
Constant for infinite tick count.
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)
ValueSemantic
How should the value of this statistic be interpreted Certain outputters (e.g. report formatters) may...
Instance of either a StatisticDef or CounterBase or an Expression. Has a sample window (simulator tic...
void accumulateStatistic() const
Tell this statistic to continually accumulate statistic values, always subtracting out the statistic ...
const std::vector< StatisticDef::PendingSubStatCreationInfo > & getSubStatistics() const
Get this statistic instance's list of pending substatistic information (TreeNode* and stat name),...
bool isSIValueDirectLookupValid() const
If this SI is using a StatInstValueLookup object to get its SI values, ask if this direct-lookup obje...
StatisticInstance(const StatisticInstance &rhp)
Copy Constructor.
InstrumentationNode::class_t getClass() const
Gets the Class associated with this statistic instance.
const std::vector< std::pair< std::string, std::string > > & getMetadata() const
Give the reporting infrastructure access to all metadata that has been set. The database report write...
StatisticInstance(const TreeNode *node, std::vector< const TreeNode * > &used)
Construct with a StatisticDef or Counter as a TreeNode*.
const CounterBase * getCounter()
std::string getExpressionString(bool show_range=true, bool resolve_subexprs=true) const
Returns a string containing the expression that this statistic will evaluate.
StatisticInstance(const std::string &location, const std::string &description, const std::string &expression_str, const StatisticDef::ValueSemantic value_semantic, const InstrumentationNode::visibility_t visibility, const InstrumentationNode::class_t cls, const std::vector< std::pair< std::string, std::string > > &metadata={})
Construct a StatisticInstance with its metadata values set directly, as opposed to this SI asking its...
void dump(std::ostream &o, bool show_range=false) const
Renders this StatisticInstance to a string containing computation window, source, and current value.
std::string stringize(bool show_range=true, bool resolve_subexprs=true) const
Renders this StatisticInstance to a string containing computation window, source, and current value.
void addSnapshotLogger(statistics::StatisticSnapshot &snapshot) const
Allow this statistic instance to emit statistic value snapshots for observation purposes....
const ParameterBase * getParameter()
StatisticInstance(StatisticInstance &&rhp)
Move Constructor.
void start()
Start the computation window for this instance.
double getInitial() const
Returns the initial value of this instance at start_tick_.
void setSIValueDirectLookupPlaceholder(const std::shared_ptr< sparta::StatInstValueLookup > &direct_lookup)
During SimDB->report generation, there is a notion of "placeholder" objects which get set on Statisti...
void getClocks(std::vector< const Clock * > &clocks) const
Gets all clocks associated with this Statistic instance (if any) whether it points to a StatisticDef,...
~StatisticInstance()
Non-Virtual destructor.
Scheduler::Tick getEnd() const
Returns the time at which ths computation window was ended.
StatisticInstance & operator=(const StatisticInstance &rhp)
Assignment Operator.
void setContext(const TreeNode *context)
Set the context of this StatisticInstance (sets the scheduler) based on a TreeNode.
const Expression & getStatisticExpression() const
Get the underlying expression representing this SI.
void end()
Ends the window for this instance. Computes and caches the result of the statistic.
void disableSnapshotLogging() const
Remove any SI value loggers we may have been given.
std::string getDesc(bool show_stat_node_expressions) const
Returns a string that describes the statistic instance If this instance points to a TreeNode,...
double getRawLatest() const
Returns the Raw latest value of the this instance for whatever statistic or counter it contains....
StatisticDef::ValueSemantic getValueSemantic() const
Gets the statistic value semantic associated with this statistic instance.
void realizeSIValueDirectLookup(const StatInstRowIterator &si_row_iterator)
Our StatInstValueLookup placeholder object needs to bind itself to a StatInstRowIterator object,...
const StatisticDef * getStatisticDef()
Returns the StatisticDef used to compute this statistic.
StatisticInstance(statistics::expression::Expression &&expr)
Construction with a predefined expression.
double getValue() const
Returns the value computed for this statistic instance at the current time.
InstrumentationNode::visibility_t getVisibility() const
Gets the visibility associated with this statistic instance.
std::string getLocation() const
Get the location associated with this statistic instance.
StatisticInstance(const TreeNode *node)
Construct with a StatisticDef or Counter as a TreeNode*.
StatisticInstance(const std::string &location, const std::string &description, const std::shared_ptr< StatInstCalculator > &calculator, const InstrumentationNode::visibility_t visibility=InstrumentationNode::DEFAULT_VISIBILITY, const InstrumentationNode::class_t cls=InstrumentationNode::DEFAULT_CLASS, const std::vector< std::pair< std::string, std::string > > &metadata={})
Construct a StatisticInstance with its location and description set directly, along with a StatInstCa...
StatisticInstance(std::shared_ptr< StatInstCalculator > &calculator, std::vector< const TreeNode * > &used)
Construct with a StatInstCalculator function (wrapper around a SpartaHandler)
void setContext(const Scheduler *scheduler)
Set the Scheduler context of this StatisticInstance.
bool supportsCompression() const
Scheduler::Tick getStart() const
Returns the time at which this computation window was started. If started multiple times,...
Node in a composite tree representing a sparta Tree item.
std::weak_ptr< const TreeNode > ConstWeakPtr
Weak pointer to a const TreeNode. Acquire with getWeakPtr.
const Clock * getClock() override
Walks up parents (starting with self) until a parent with an associated local clock is found,...
User-friendly wrapper around a double reference. This is like a std::reference_wrapper that connects ...
Expression container/builder. Contains a single ExpressionNode representing the root of an expression...
uint32_t getStats(std::vector< const StatisticInstance * > &results) const
Gets the statistics present in this expression.
Macros for handling exponential backoff.
std::ostream & operator<<(std::ostream &o, const SimulationInfo &info)
ostream insertion operator for SimulationInfo