The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::StatisticInstance Class Referencefinal

Instance of either a StatisticDef or CounterBase or an Expression. Has a sample window (simulator ticks) over which it will compute the value of the contained expression/counter for that range. More...

#include <StatisticInstance.hpp>

Public Member Functions

StatisticInstanceoperator= (const StatisticInstance &rhp)
 Assignment Operator.
 
void setContext (const TreeNode *context)
 Set the context of this StatisticInstance (sets the scheduler) based on a TreeNode.
 
void setContext (const Scheduler *scheduler)
 Set the Scheduler context of this StatisticInstance.
 
Construction
 StatisticInstance (statistics::expression::Expression &&expr)
 Construction with a predefined expression.
 
 StatisticInstance (const TreeNode *node)
 Construct with a StatisticDef or Counter as a TreeNode*.
 
 StatisticInstance (const TreeNode *node, std::vector< const TreeNode * > &used)
 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)
 
 StatisticInstance (const StatisticInstance &rhp)
 Copy Constructor.
 
 StatisticInstance (StatisticInstance &&rhp)
 Move Constructor.
 
 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 underlying counter/parameter/etc. for these values.
 
 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 StatInstCalculator which can retrieve the SI value on demand from another source (such as a database file).
 
 ~StatisticInstance ()
 Non-Virtual destructor.
 
const std::vector< StatisticDef::PendingSubStatCreationInfo > & getSubStatistics () const
 Get this statistic instance's list of pending substatistic information (TreeNode* and stat name), if any.
 
Computation Window
void start ()
 Start the computation window for this instance.
 
void end ()
 Ends the window for this instance. Computes and caches the result of the statistic.
 
Scheduler::Tick getStart () const
 Returns the time at which this computation window was started. If started multiple times, returns the most recent start tick.
 
Scheduler::Tick getEnd () const
 Returns the time at which ths computation window was ended.
 
Value
void accumulateStatistic () const
 Tell this statistic to continually accumulate statistic values, always subtracting out the statistic value that was present when the 'start()' method was first called.
 
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 StatisticInstance/Report objects temporarily. These placeholders can be cloned into "realized" versions of themselves later on.
 
void realizeSIValueDirectLookup (const StatInstRowIterator &si_row_iterator)
 Our StatInstValueLookup placeholder object needs to bind itself to a StatInstRowIterator object, since these two classes go hand in hand. Now that we're being given the row iterator, we can use it to "realize" our "SI direct value lookup" object now.
 
bool isSIValueDirectLookupValid () const
 If this SI is using a StatInstValueLookup object to get its SI values, ask if this direct-lookup object can be used to get the current SI value.
 
double getValue () const
 Returns the value computed for this statistic instance at the current time.
 
double getInitial () const
 Returns the initial value of this instance at start_tick_.
 
double getRawLatest () const
 Returns the Raw latest value of the this instance for whatever statistic or counter it contains. This could fiffer from getValue() since it disregards the computation window.
 
bool supportsCompression () const
 
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.
 
std::string getExpressionString (bool show_range=true, bool resolve_subexprs=true) const
 Returns a string containing the expression that this statistic will evaluate.
 
std::string getDesc (bool show_stat_node_expressions) const
 Returns a string that describes the statistic instance If this instance points to a TreeNode, result is that node's description. If it points to a free expression, returns the expression.
 
void dump (std::ostream &o, bool show_range=false) 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. These loggers are given the current SI value with each call to getValue()
 
void disableSnapshotLogging () const
 Remove any SI value loggers we may have been given.
 
Source Data
std::string getLocation () const
 Get the location associated with this statistic instance.
 
StatisticDef::ValueSemantic getValueSemantic () const
 Gets the statistic value semantic associated with this statistic instance.
 
InstrumentationNode::visibility_t getVisibility () const
 Gets the visibility associated with this statistic instance.
 
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 writers need this metadata, and others may need it as well.
 
const StatisticDefgetStatisticDef ()
 Returns the StatisticDef used to compute this statistic.
 
const StatisticDefgetStatisticDef () const
 
const ExpressiongetStatisticExpression () const
 Get the underlying expression representing this SI.
 
const CounterBasegetCounter ()
 
const CounterBasegetCounter () const
 
const ParameterBasegetParameter ()
 
const ParameterBasegetParameter () const
 
void getClocks (std::vector< const Clock * > &clocks) const
 Gets all clocks associated with this Statistic instance (if any) whether it points to a StatisticDef, a Counter or an anonymous Expression.
 

Detailed Description

Instance of either a StatisticDef or CounterBase or an Expression. Has a sample window (simulator ticks) over which it will compute the value of the contained expression/counter for that range.

A StatisticInstance refers to a StatisticDef, CounterBase and uses said definition to determine inputs and evalute it's statistic function.

The overhead of distinguishing between StatisticDef and CounterBase is done here, since it is external to simulation and introduces no overhead unless this StatisticInstance is being evaluated

Internally, a StatisticInstance will store spapshot values of counters such that it can compute deltas for evaluating the statistic over the desired sample range.

Definition at line 96 of file StatisticInstance.hpp.

Constructor & Destructor Documentation

◆ StatisticInstance() [1/4]

sparta::StatisticInstance::StatisticInstance ( statistics::expression::Expression &&  expr)
inlineexplicit

Construction with a predefined expression.

Parameters
exprExpression reference to move
Note
You must set the context (setContext) after this call. The Expression might or might not know the context for the Scheduler

Definition at line 131 of file StatisticInstance.hpp.

◆ StatisticInstance() [2/4]

sparta::StatisticInstance::StatisticInstance ( const TreeNode node)
inlineexplicit

Construct with a StatisticDef or Counter as a TreeNode*.

Parameters
nodeMust be an interface to a StatisticDef or a Counter

Definition at line 139 of file StatisticInstance.hpp.

◆ StatisticInstance() [3/4]

sparta::StatisticInstance::StatisticInstance ( const TreeNode node,
std::vector< const TreeNode * > &  used 
)
inline

Construct with a StatisticDef or Counter as a TreeNode*.

Parameters
nodeMust be an interface to a StatisticDef or a Counter

Definition at line 147 of file StatisticInstance.hpp.

◆ StatisticInstance() [4/4]

sparta::StatisticInstance::StatisticInstance ( std::shared_ptr< StatInstCalculator > &  calculator,
std::vector< const TreeNode * > &  used 
)

Construct with a StatInstCalculator function (wrapper around a SpartaHandler)

Parameters
calculatorMust be a StatInstCalculator with a non-null tree node attached to it (its 'getNode()' method will be evaluated in this constructor)

◆ ~StatisticInstance()

sparta::StatisticInstance::~StatisticInstance ( )
inline

Non-Virtual destructor.

Definition at line 197 of file StatisticInstance.hpp.

Member Function Documentation

◆ accumulateStatistic()

void sparta::StatisticInstance::accumulateStatistic ( ) const
inline

Tell this statistic to continually accumulate statistic values, always subtracting out the statistic value that was present when the 'start()' method was first called.

Definition at line 266 of file StatisticInstance.hpp.

Here is the call graph for this function:

◆ addSnapshotLogger()

void sparta::StatisticInstance::addSnapshotLogger ( statistics::StatisticSnapshot snapshot) const
inline

Allow this statistic instance to emit statistic value snapshots for observation purposes. These loggers are given the current SI value with each call to getValue()

Definition at line 389 of file StatisticInstance.hpp.

◆ disableSnapshotLogging()

void sparta::StatisticInstance::disableSnapshotLogging ( ) const
inline

Remove any SI value loggers we may have been given.

Definition at line 397 of file StatisticInstance.hpp.

◆ dump()

void sparta::StatisticInstance::dump ( std::ostream &  o,
bool  show_range = false 
) const

Renders this StatisticInstance to a string containing computation window, source, and current value.

Parameters
oostream to which this stat instance is rendered \oaram show_range Should range information for this instance be written to o?

◆ end()

void sparta::StatisticInstance::end ( )

Ends the window for this instance. Computes and caches the result of the statistic.

Note
Re-ending (two calls to end at different times withiout a start call between them) IS supported
Exceptions
SpartaExceptionif node reference is expired (and there is a node reference)

◆ getClocks()

void sparta::StatisticInstance::getClocks ( std::vector< const Clock * > &  clocks) const

Gets all clocks associated with this Statistic instance (if any) whether it points to a StatisticDef, a Counter or an anonymous Expression.

Parameters
clocksVector of clocks to which all found clocsk will be appended. This vector will not be cleared
Exceptions
SpartaExceptionif this StatisticInstance refers to an expired TreeNode.

◆ getCounter() [1/2]

const CounterBase * sparta::StatisticInstance::getCounter ( )
inline

\Returns the counter used to compute this statistic

Definition at line 470 of file StatisticInstance.hpp.

◆ getCounter() [2/2]

const CounterBase * sparta::StatisticInstance::getCounter ( ) const
inline

Definition at line 473 of file StatisticInstance.hpp.

◆ getDesc()

std::string sparta::StatisticInstance::getDesc ( bool  show_stat_node_expressions) const

Returns a string that describes the statistic instance If this instance points to a TreeNode, result is that node's description. If it points to a free expression, returns the expression.

Parameters
show_stat_node_expressionsIf true, also shows expressions for nodes which are StatisticDefs

◆ getEnd()

Scheduler::Tick sparta::StatisticInstance::getEnd ( ) const
inline

Returns the time at which ths computation window was ended.

If ended once or multiple times, returns the most recent ending tick. If never ended, returns Scheduler::INDEFINITE

Definition at line 250 of file StatisticInstance.hpp.

◆ getExpressionString()

std::string sparta::StatisticInstance::getExpressionString ( bool  show_range = true,
bool  resolve_subexprs = true 
) const

Returns a string containing the expression that this statistic will evaluate.

Note
This could be a simple counter identifier or a full arithmetic expression
Parameters
show_rangeShould the range be shown in any subexpression nodes.
resolve_subexprsShould any referenced statistic defs be expanded to their full expressions so that this becomes an expression containing only counters.

◆ getInitial()

double sparta::StatisticInstance::getInitial ( ) const
inline

Returns the initial value of this instance at start_tick_.

Definition at line 322 of file StatisticInstance.hpp.

◆ getLocation()

std::string sparta::StatisticInstance::getLocation ( ) const

Get the location associated with this statistic instance.

For counters, returns the counter node's location. For statistic defs, returns the stat def node's location. For expression, returns "<expression>". If any referenced node is expired, returns "<expired>".

◆ getMetadata()

const std::vector< std::pair< std::string, std::string > > & sparta::StatisticInstance::getMetadata ( ) const
inline

Give the reporting infrastructure access to all metadata that has been set. The database report writers need this metadata, and others may need it as well.

Definition at line 445 of file StatisticInstance.hpp.

◆ getParameter() [1/2]

const ParameterBase * sparta::StatisticInstance::getParameter ( )
inline

\Returns the parameter used to compute this statistic

Definition at line 480 of file StatisticInstance.hpp.

◆ getParameter() [2/2]

const ParameterBase * sparta::StatisticInstance::getParameter ( ) const
inline

Definition at line 483 of file StatisticInstance.hpp.

◆ getStart()

Scheduler::Tick sparta::StatisticInstance::getStart ( ) const
inline

Returns the time at which this computation window was started. If started multiple times, returns the most recent start tick.

Definition at line 241 of file StatisticInstance.hpp.

◆ getStatisticDef() [1/2]

const StatisticDef * sparta::StatisticInstance::getStatisticDef ( )
inline

Returns the StatisticDef used to compute this statistic.

Definition at line 452 of file StatisticInstance.hpp.

◆ getStatisticDef() [2/2]

const StatisticDef * sparta::StatisticInstance::getStatisticDef ( ) const
inline

Definition at line 455 of file StatisticInstance.hpp.

◆ getStatisticExpression()

const Expression & sparta::StatisticInstance::getStatisticExpression ( ) const
inline

Get the underlying expression representing this SI.

Returns
Expression

Definition at line 463 of file StatisticInstance.hpp.

◆ getSubStatistics()

const std::vector< StatisticDef::PendingSubStatCreationInfo > & sparta::StatisticInstance::getSubStatistics ( ) const
inline

Get this statistic instance's list of pending substatistic information (TreeNode* and stat name), if any.

Definition at line 203 of file StatisticInstance.hpp.

◆ getValue()

double sparta::StatisticInstance::getValue ( ) const

Returns the value computed for this statistic instance at the current time.

Returns
Computed value (current if instance has not been ended and cached if previously ended)
Exceptions
ReversedStatisticRangeif end tick is less than start tick
FutureStatisticRangeStatisticRange if the end tick is finite (not Scheduler::INDEFINITE) and it is greater than the current scheduler tick (Scheduler::getCurrentTick)

◆ getValueSemantic()

StatisticDef::ValueSemantic sparta::StatisticInstance::getValueSemantic ( ) const

Gets the statistic value semantic associated with this statistic instance.

For counters and expressions, returns StatisticDef::VS_INVALID. For expired node references, returns StatisticDef::VS_INVALID

◆ setContext() [1/2]

void sparta::StatisticInstance::setContext ( const Scheduler scheduler)
inline

Set the Scheduler context of this StatisticInstance.

Parameters
schedulerThe Scheduler this SI should use

Definition at line 515 of file StatisticInstance.hpp.

◆ setContext() [2/2]

void sparta::StatisticInstance::setContext ( const TreeNode context)
inline

Set the context of this StatisticInstance (sets the scheduler) based on a TreeNode.

Parameters
contextThe context of this StatisticInstance based on a TreeNode

Definition at line 505 of file StatisticInstance.hpp.

Here is the call graph for this function:

◆ setSIValueDirectLookupPlaceholder()

void sparta::StatisticInstance::setSIValueDirectLookupPlaceholder ( const std::shared_ptr< sparta::StatInstValueLookup > &  direct_lookup)

During SimDB->report generation, there is a notion of "placeholder" objects which get set on StatisticInstance/Report objects temporarily. These placeholders can be cloned into "realized" versions of themselves later on.

This method lets SimDB-recreated Report objects set placeholders this SI will soon use to get SI data values directly from a SimDB blob (not from an actual simulation).

◆ start()

void sparta::StatisticInstance::start ( )

Start the computation window for this instance.

Note
This is implicitly called at construction
Postcondition
Clears cached result values
Resets any initial values
Exceptions
SpartaExceptionif node reference is expired (and there is a node reference)

◆ stringize()

std::string sparta::StatisticInstance::stringize ( bool  show_range = true,
bool  resolve_subexprs = true 
) const

Renders this StatisticInstance to a string containing computation window, source, and current value.

Note
This does evaluate the expression
Parameters
show_rangeShould the range be shown in any subexpression nodes.
resolve_subexprsShould any referenced statistic defs be expanded to their full expressions so that this becomes an expression containing only counters.

◆ supportsCompression()

bool sparta::StatisticInstance::supportsCompression ( ) const

Does this StatisticInstance support compression (database)?


The documentation for this class was generated from the following file: