18#include "sparta/statistics/CounterBase.hpp"
23#include "sparta/statistics/Expression.hpp"
25#include "sparta/statistics/dispatch/StatisticSnapshot.hpp"
29 using statistics::expression::Expression;
114 std::vector<const TreeNode*>* used);
156 std::vector<const TreeNode*>& used);
174 return sub_statistics_;
237 initial_.setIsCumulative(
true);
238 std::vector<const StatisticInstance*> stats_in_expr;
240 for (
const auto & stat : stats_in_expr) {
241 stat->accumulateStatistic();
261 return initial_.getValue();
287 bool resolve_subexprs=
true)
const;
301 bool resolve_subexprs=
true)
const;
311 std::string
getDesc(
bool show_stat_node_expressions)
const;
320 void dump(std::ostream& o,
bool show_range=
false)
const;
329 snapshot_loggers_.emplace_back(snapshot);
337 snapshot_loggers_.clear();
425 void getClocks(std::vector<const Clock*>& clocks)
const;
445 scheduler_ = scheduler;
457 double computeValue_()
const;
464 sub_statistics_.emplace_back(creation_info);
479 const StatisticDef* sdef_ =
nullptr;
485 const CounterBase* ctr_ =
nullptr;
491 const ParameterBase* par_ =
nullptr;
518 mutable const Scheduler * scheduler_ =
nullptr;
523 const Scheduler * getScheduler_()
const;
531 class InitialStatValue {
533 InitialStatValue(
const double value) :
534 is_cumulative_(false),
537 if (std::isnan(initial_.
getValue())) {
538 initial_.clearValid();
542 InitialStatValue(
const InitialStatValue & rhp) :
543 is_cumulative_(rhp.is_cumulative_),
544 initial_(rhp.initial_)
547 InitialStatValue & operator=(
const InitialStatValue & rhp) {
548 is_cumulative_ = rhp.is_cumulative_;
549 initial_ = rhp.initial_;
553 void setIsCumulative(
const bool is_cumulative) {
554 is_cumulative_ = is_cumulative;
557 double getValue()
const {
561 void resetValue(
const double initial) {
562 if (is_cumulative_) {
572 bool is_cumulative_ =
false;
573 utils::ValidValue<double> initial_;
579 mutable InitialStatValue initial_{NAN};
589 mutable std::vector<statistics::StatisticSnapshot> snapshot_loggers_;
594 mutable std::vector<StatisticDef::PendingSubStatCreationInfo> sub_statistics_;
599 std::shared_ptr<StatInstCalculator> user_calculated_si_value_;
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.
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),...
StatisticInstance(const StatisticInstance &rhp)
Copy Constructor.
InstrumentationNode::class_t getClass() const
Gets the Class associated with this statistic instance.
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.
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 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.
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(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.
const Clock * getClock() override
Walks up parents (starting with self) until a parent with an associated local clock is found,...
std::weak_ptr< const TreeNode > ConstWeakPtr
Weak pointer to a const TreeNode. Acquire with getWeakPtr.
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.
const value_type & getValue() const
Get the value - const version.
bool isValid() const
Is this value valid.
Macros for handling exponential backoff.
std::ostream & operator<<(std::ostream &o, const SimulationInfo &info)
ostream insertion operator for SimulationInfo