12#ifndef SST_CORE_STATAPI_STATBASE_H
13#define SST_CORE_STATAPI_STATBASE_H
15#include "sst/core/eli/elementinfo.h"
16#include "sst/core/factory.h"
17#include "sst/core/oneshot.h"
18#include "sst/core/params.h"
19#include "sst/core/serialization/serialize_impl_fwd.h"
20#include "sst/core/sst_types.h"
21#include "sst/core/statapi/statfieldinfo.h"
22#include "sst/core/unitAlgebra.h"
23#include "sst/core/warnmacros.h"
57 enum StatMode_t { STAT_MODE_UNDEFINED, STAT_MODE_COUNT, STAT_MODE_PERIODIC, STAT_MODE_DUMP_AT_END };
61 void enable() { info_->stat_enabled_ =
true; }
64 void disable() { info_->stat_enabled_ =
false; }
88 static const std::vector<ElementInfoParam>& ELI_getParams();
106 inline const std::string&
getStatName()
const {
return info_->stat_name_; }
109 inline const std::string&
getStatSubId()
const {
return info_->stat_sub_id_; }
114 return info_->stat_full_name_;
126 inline const StatisticFieldInfo::fieldType_t&
getStatDataType()
const {
return stat_data_type_; }
131 return StatisticFieldInfo::getFieldTypeShortName(stat_data_type_);
137 return StatisticFieldInfo::getFieldTypeFullName(stat_data_type_);
202 Params& stat_params,
bool null_stat);
218 void setRegisteredCollectionMode(
StatMode_t mode) { info_->registered_collection_mode_ = mode; }
221 static std::string buildStatisticFullName(
const char* comp_name,
const char* stat_name,
const char* stat_sub_id);
222 static std::string buildStatisticFullName(
223 const std::string& comp_name,
const std::string& stat_name,
const std::string& stat_sub_id);
230 virtual void registerOutputFields(StatisticFieldsOutput* stat_output) = 0;
237 virtual void outputStatisticFields(StatisticFieldsOutput* stat_output,
bool end_of_sim_flag) = 0;
244 virtual bool isStatModeSupported(
StatMode_t UNUSED(mode))
const {
return true; }
247 bool operator==(StatisticBase& check_stat);
249 void checkEventForOutput();
251 const StatisticGroup* getGroup()
const {
return info_->group_; }
252 void setGroup(
const StatisticGroup* group) { info_->group_ = group; }
266 void serialize_order(SST::Core::Serialization::serializer& ser);
268 std::string stat_name_;
269 std::string stat_sub_id_;
270 std::string stat_type_name_;
272 std::string stat_full_name_;
275 uint64_t current_collection_count_;
276 uint64_t output_collection_count_;
277 uint64_t collection_count_limit_;
279 const StatisticGroup* group_;
281 SST::UnitAlgebra start_at_time_;
282 SST::UnitAlgebra stop_at_time_;
283 SST::UnitAlgebra collection_rate_;
285 bool output_enabled_;
286 bool reset_count_on_output_;
287 bool clear_data_on_output_;
288 bool output_at_end_of_sim_;
289 bool output_delayed_;
290 bool collection_delayed_;
291 bool saved_stat_enabled_;
292 bool saved_output_enabled_;
295 BaseComponent* component_;
296 StatisticFieldInfo::fieldType_t stat_data_type_;
298 StatisticInfo* info_;
301 static StatisticInfo null_info_;
310template <
class T,
bool = std::is_arithmetic_v<T>>
316 virtual void addData_impl(T data) = 0;
326 for ( uint64_t i = 0; i < N; ++i ) {
334template <
class... Args>
337 virtual void addData_impl(Args... args) = 0;
347 for ( uint64_t i = 0; i < N; ++i ) {
348 addData_impl(args...);
352 template <
class... InArgs>
353 void addData(InArgs&&... args)
355 addData_impl(std::make_tuple(std::forward<InArgs>(args)...));
358 virtual ~StatisticCollector() =
default;
376 SST_ELI_DECLARE_INFO(
379 SST_ELI_DECLARE_CTOR(BaseComponent*,
const std::string&,
const std::string&,
SST::Params&)
381 SST_ELI_DOCUMENT_PARAMS(
382 {
"rate",
"Frequency at which to output statistic. Must include units. 0ns = output at end of simulation only.",
"0ns" },
383 {
"startat",
"Time at which to enable data collection in this statistic. Must include units. 0ns = always enabled.",
"0ns"},
384 {
"stopat",
"Time at which to disable data collection in this statistic. 0ns = always enabled.",
"0ns"},
385 {
"resetOnOutput",
"Whether to reset the statistic's values after each output.",
"False"}
396 template <
class... InArgs>
402 addData_impl(std::forward<InArgs>(args)...);
407 template <
class... InArgs>
408 void addDataNTimes(uint64_t N, InArgs&&... args)
413 addData_impl_Ntimes(N, std::forward<InArgs>(args)...);
418 static fieldType_t fieldId() {
return StatisticFieldType<T>::id(); }
437 Statistic(BaseComponent* comp,
const std::string& stat_name,
const std::string& stat_sub_id,
Params& stat_params,
438 bool null_stat =
false) :
439 StatisticBase(comp, stat_name, stat_sub_id, stat_params, null_stat)
459 SST_ELI_DECLARE_INFO(
460 ELI::ProvidesInterface,
462 SST_ELI_DECLARE_CTOR(BaseComponent*,
const std::string&,
const std::string&, SST::Params&)
464 void registerOutputFields(StatisticFieldsOutput* stat_output)
override;
466 void outputStatisticFields(StatisticFieldsOutput* stat_output,
bool end_of_sim_flag)
override;
469 friend class SST::Factory;
470 friend class SST::BaseComponent;
480 Statistic(BaseComponent* comp,
const std::string& stat_name,
const std::string& stat_sub_id, Params& stat_params,
481 bool null_stat =
false) :
482 StatisticBase(comp, stat_name, stat_sub_id, stat_params, null_stat)
493template <
class... Args>
494using MultiStatistic =
Statistic<std::tuple<Args...>>;
496struct ImplementsStatFields
499 std::string toString()
const;
501 Statistics::fieldType_t fieldId()
const {
return field_; }
503 const char* fieldName()
const {
return field_name_; }
505 const char* fieldShortName()
const {
return short_name_; }
509 explicit ImplementsStatFields(T* UNUSED(t)) :
510 field_name_(T::ELI_fieldName()),
511 short_name_(T::ELI_fieldShortName()),
512 field_(T::ELI_registerField(T::ELI_fieldName(), T::ELI_fieldShortName()))
516 const char* field_name_;
517 const char* short_name_;
518 Statistics::fieldType_t field_;
522#define SST_ELI_DECLARE_STATISTIC_TEMPLATE(cls, lib, name, version, desc, interface) \
523 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
524 SST_ELI_INTERFACE_INFO(interface) \
525 virtual std::string getELIName() const override \
527 return std::string(lib) + "." + name; \
530#define SST_ELI_REGISTER_CUSTOM_STATISTIC(cls, lib, name, version, desc) \
531 SST_ELI_REGISTER_DERIVED(SST::Statistics::CustomStatistic,cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
532 SST_ELI_INTERFACE_INFO("CustomStatistic")
534#define SST_ELI_DECLARE_STATISTIC(cls, field, lib, name, version, desc, interface) \
535 static bool ELI_isLoaded() \
537 return SST::Statistics::Statistic<field>::template addDerivedInfo<cls>(lib, name) && \
538 SST::Statistics::Statistic<field>::template addDerivedBuilder<cls>(lib, name) && \
539 SST::Statistics::Statistic<field>::template addDerivedInfo<SST::Statistics::NullStatistic<field>>( \
541 SST::Statistics::Statistic<field>::template addDerivedBuilder<SST::Statistics::NullStatistic<field>>( \
544 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
545 SST_ELI_INTERFACE_INFO(interface) \
546 static const char* ELI_fieldName() \
550 static const char* ELI_fieldShortName() \
555#ifdef __INTEL_COMPILER
556#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
557 bool force_instantiate_##cls##_##field = \
558 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
559 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
560 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
561 SST::Statistics::NullStatistic<field>>::isLoaded() && \
562 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
563 SST::Statistics::NullStatistic<field>>::isLoaded();
565#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
566 struct cls##_##field##_##shortName : public cls<field> \
568 cls##_##field##_##shortName( \
569 SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
570 cls<field>(bc, sn, si, p) \
572 static bool ELI_isLoaded() \
574 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
575 cls##_##field##_##shortName>::isLoaded() && \
576 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
577 cls##_##field##_##shortName>::isLoaded() && \
578 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
579 SST::Statistics::NullStatistic<field>>::isLoaded() && \
580 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
581 SST::Statistics::NullStatistic<field>>::isLoaded(); \
586#define PP_NARG(...) PP_NARG_(__VA_ARGS__, PP_NSEQ())
587#define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
588#define PP_ARG_N(_1, _2, _3, _4, _5, N, ...) N
589#define PP_NSEQ() 5, 4, 3, 2, 1, 0
591#define PP_GLUE(X, Y) PP_GLUE_I(X, Y)
592#define PP_GLUE_I(X, Y) X##Y
594#define STAT_NAME1(base, a) base##a
595#define STAT_NAME2(base, a, b) base##a##b
596#define STAT_NAME3(base, a, b, c) base##a##b##c
597#define STAT_NAME4(base, a, b, c, d) base##a##b##c##d
599#define STAT_GLUE_NAME(base, ...) PP_GLUE(STAT_NAME, PP_NARG(__VA_ARGS__))(base, __VA_ARGS__)
600#define STAT_TUPLE(...) std::tuple<__VA_ARGS__>
602#ifdef __INTEL_COMPILER
603#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
604 bool force_instantiate_stat_name = \
605 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
606 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
607 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, \
608 SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
609 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, \
610 SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
615#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
616 struct name : public cls<__VA_ARGS__> \
618 name(SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
619 cls<__VA_ARGS__>(bc, sn, si, p) \
621 bool ELI_isLoaded() const \
623 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
624 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
625 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, \
626 SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
627 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, \
628 SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
633#define SST_ELI_INSTANTIATE_MULTI_STATISTIC(cls, ...) \
634 MAKE_MULTI_STATISTIC(cls, STAT_GLUE_NAME(cls, __VA_ARGS__), STAT_TUPLE(__VA_ARGS__), __VA_ARGS__)
645namespace Core::Serialization {
654 switch ( ser.mode() ) {
655 case serializer::SIZER:
656 case serializer::PACK:
662 SST_SER(stat_eli_type);
669 case serializer::UNPACK:
671 std::string stat_eli_type;
673 std::string stat_name;
675 SST_SER(stat_eli_type);
680 params.
insert(
"type", stat_eli_type);
682 stat_eli_type, params, comp, stat_name, stat_id, params);
684 if ( stat_eli_type !=
"sst.NullStatistic" ) {
685 SST::Stat::pvt::registerStatWithEngineOnRestart(s);
689 case serializer::MAP:
697 SST_FRIEND_SERIALIZE();
705#include "sst/core/statapi/statnull.h"
Main component object for the simulation.
Definition baseComponent.h:62
Base serialize class.
Definition serialize.h:110
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:45
Definition interfaceInfo.h:21
Definition paramsInfo.h:39
Class for instantiating Components, Links and the like out of element libraries.
Definition factory.h:48
Parameter store.
Definition params.h:58
void insert(const std::string &key, const std::string &value, bool overwrite=true)
Add a key/value pair into the param object.
Definition params.cc:166
Forms the base class for statistics gathering within SST.
Definition statbase.h:49
const std::string & getCompName() const
Return the Component Name.
Definition statbase.cc:112
UnitAlgebra & getStartAtTime() const
Return the time at which the statistic should be enabled.
Definition statbase.h:153
BaseComponent * getComponent() const
Return a pointer to the parent Component.
Definition statbase.h:141
virtual void resetCollectionCount()
Set the current collection count to 0.
Definition statbase.cc:150
void enable()
Enable Statistic for collections.
Definition statbase.h:61
UnitAlgebra & getStopAtTime() const
Return the time at which the statistic should be disabled.
Definition statbase.h:156
void setFlagOutputAtEndOfSim(bool flag)
Set the Output At End Of Sim flag.
Definition statbase.h:99
void setFlagClearDataOnOutput(bool flag)
Set the Clear Data On Output flag.
Definition statbase.h:94
const std::string & getStatName() const
Return the Statistic Name.
Definition statbase.h:106
virtual bool isReady() const
Indicate that the Statistic is Ready to be used.
Definition statbase.h:178
virtual void setCollectionCount(uint64_t new_count)
Set the current collection count to a defined value.
Definition statbase.cc:142
StatMode_t getRegisteredCollectionMode() const
Return the collection mode that is registered.
Definition statbase.h:174
bool getFlagOutputAtEndOfSim() const
Return the OutputAtEndOfSim flag value.
Definition statbase.h:171
virtual const std::string & getStatTypeName() const
Return the Statistic type name.
Definition statbase.h:123
StatMode_t
Statistic collection mode STAT_MODE_UNDEFINED - unknown mode STAT_MODE_COUNT - generating statistic o...
Definition statbase.h:57
const StatisticFieldInfo::fieldType_t & getStatDataType() const
Return the Statistic data type.
Definition statbase.h:126
virtual void setCollectionCountLimit(uint64_t new_limit)
Set the collection count limit to a defined value.
Definition statbase.cc:156
UnitAlgebra & getCollectionRate() const
Return the rate at which the statistic should be output.
Definition statbase.h:150
void setFlagResetCountOnOutput(bool flag)
Set the Reset Count On Output flag.
Definition statbase.h:86
bool getFlagClearDataOnOutput() const
Return the ClearDataOnOutput flag value.
Definition statbase.h:168
uint64_t getCollectionCountLimit() const
Return the collection count limit.
Definition statbase.h:159
const std::string & getStatSubId() const
Return the Statistic SubId.
Definition statbase.h:109
virtual bool isNullStatistic() const
Indicate if the Statistic is a NullStatistic.
Definition statbase.h:181
virtual void clearStatisticData()
Inform the Statistic to clear its data.
Definition statbase.h:68
const char * getStatDataTypeShortName() const
Return the Statistic data type.
Definition statbase.h:129
uint64_t getCollectionCount() const
Return the current collection count.
Definition statbase.h:162
void disable()
Disable Statistic for collections.
Definition statbase.h:64
bool isOutputEnabled() const
Return the enable status of the Statistic's ability to output data.
Definition statbase.h:147
const std::string & getFullStatName() const
Return the full Statistic name of component.stat_name.sub_id.
Definition statbase.h:112
const char * getStatDataTypeFullName() const
Return the Statistic data type.
Definition statbase.h:135
bool isEnabled() const
Return the enable status of the Statistic.
Definition statbase.h:144
virtual std::string getELIName() const =0
Return the ELI type of the statistic The ELI registration macro creates this function automatically f...
virtual void serialize_order(SST::Core::Serialization::serializer &ser)
Serialization.
Definition statbase.cc:201
void setStatisticTypeName(const char *type_name)
Set an optional Statistic Type Name (for output)
Definition statbase.h:212
StatisticBase(BaseComponent *comp, const std::string &stat_name, const std::string &stat_sub_id, Params &stat_params, bool null_stat)
Construct a StatisticBase.
Definition statbase.cc:40
virtual void incrementCollectionCount(uint64_t increment)
Increment current collection count.
Definition statbase.cc:134
bool getFlagResetCountOnOutput() const
Return the ResetCountOnOutput flag value.
Definition statbase.h:165
void setStatisticDataType(const StatisticFieldInfo::fieldType_t data_type)
Set the Statistic Data Type.
Definition statbase.h:209
Definition statoutput.h:170
Definition statgroup.h:31
Forms the base class for statistics output generation within the SST core.
Definition statoutput.h:52
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition statengine.h:58
Forms the template defined base class for statistics gathering within SST.
Definition statbase.h:373
Statistic(BaseComponent *comp, const std::string &stat_name, const std::string &stat_sub_id, Params &stat_params, bool null_stat=false)
Construct a Statistic.
Definition statbase.h:437
void addData(InArgs &&... args)
Add data to the Statistic This will call the addData_impl() routine in the derived Statistic.
Definition statbase.h:397
virtual void serialize_order(SST::Core::Serialization::serializer &ser) override
Serialization.
Definition statbase.h:420
Performs Unit math in full precision.
Definition unitAlgebra.h:107
virtual void addData_impl_Ntimes(uint64_t N, T data)
addData_impl_Ntimes Add the same data N times in a row By default, this just calls the addData functi...
Definition statbase.h:324
virtual void addData_impl_Ntimes(uint64_t N, Args... args)
addData_impl_Ntimes Add the same data N times in a row By default, this just calls the addData functi...
Definition statbase.h:345
Base type that creates the virtual addData(...) interface Used for distinguishing arithmetic types (c...
Definition statbase.h:311