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/params.h"
18#include "sst/core/serialization/serialize_impl_fwd.h"
19#include "sst/core/sst_types.h"
20#include "sst/core/statapi/statfieldinfo.h"
21#include "sst/core/unitAlgebra.h"
22#include "sst/core/warnmacros.h"
55 void enable() { stat_enabled_ =
true; }
82 static const std::vector<ElementInfoParam>& ELI_getParams();
98 void setPortModName(std::string& port,
size_t index) { stat_mod_name_ =
"." + port +
"." + std::to_string(index); }
105 inline const std::string&
getStatName()
const {
return stat_name_; }
108 inline const std::string&
getStatSubId()
const {
return stat_sub_id_; }
113 std::string stat_full_name_rtn =
getCompName() +
"." + stat_name_;
114 if ( stat_sub_id_ !=
"" ) stat_full_name_rtn +=
"." + stat_sub_id_;
115 return stat_full_name_rtn;
127 inline const StatisticFieldInfo::fieldType_t&
getStatDataType()
const {
return stat_data_type_; }
132 return StatisticFieldInfo::getFieldTypeShortName(stat_data_type_);
138 return StatisticFieldInfo::getFieldTypeFullName(stat_data_type_);
151 void setStartAtFlag() { flags_ |= Flag::StartAt; }
152 void unsetStartAtFlag() { flags_ &= (~Flag::StartAt); }
156 void setStopAtFlag() { flags_ |= Flag::StopAt; }
157 void unsetStopAtFlag() { flags_ &= (~Flag::StopAt); }
161 void setOutputRateFlag() { flags_ |= Flag::OutputRate; }
162 void unsetOutputRateFlag() { flags_ &= (~Flag::OutputRate); }
165 SimTime_t getStartAtFactor();
166 SimTime_t getStopAtFactor();
167 SimTime_t getOutputRateFactor();
186 bool isOutputEventBased()
const {
return !registered_collection_mode_; }
215 BaseComponent* comp,
const std::string& stat_name,
const std::string& stat_sub_id,
Params& stat_params);
226 [[deprecated(
"setStatisticTypeName() has been deprecated and will be removed in SST 17.0. Override "
227 "getStatTypeName() instead.")]]
230 stat_type_name_ = type_name;
237 void setRegisteredCollectionMode(
bool is_periodic) { registered_collection_mode_ = is_periodic; }
240 static std::string buildStatisticFullName(
const char* comp_name,
const char* stat_name,
const char* stat_sub_id);
241 static std::string buildStatisticFullName(
242 const std::string& comp_name,
const std::string& stat_name,
const std::string& stat_sub_id);
249 virtual void registerOutputFields(StatisticFieldsOutput* stat_output) = 0;
256 virtual void outputStatisticFields(StatisticFieldsOutput* stat_output,
bool end_of_sim_flag) = 0;
263 virtual bool isStatModeSupported(
bool UNUSED(periodic))
const {
return true; }
268 void checkEventForOutput();
270 const StatisticGroup* getGroup()
const {
return group_; }
271 void setGroup(
const StatisticGroup* group) { group_ = group; }
278 enum Flag : uint8_t {
284 std::string stat_name_ =
"";
285 std::string stat_sub_id_ =
"";
286 std::string stat_type_name_ =
"";
287 std::string stat_mod_name_ =
291 bool stat_enabled_ =
true;
292 bool registered_collection_mode_ =
true;
293 uint64_t current_collection_count_ = 0;
294 uint64_t output_collection_count_ = 0;
295 uint64_t collection_count_limit_ = 0;
297 const StatisticGroup* group_ =
nullptr;
299 bool reset_count_on_output_ =
false;
300 bool clear_data_on_output_ =
false;
301 bool output_at_end_of_sim_ =
true;
303 BaseComponent* component_;
304 StatisticFieldInfo::fieldType_t stat_data_type_;
313template <
class T,
bool = std::is_arithmetic_v<T>>
319 virtual void addData_impl(T data) = 0;
329 for ( uint64_t i = 0; i < N; ++i ) {
337template <
class... Args>
340 virtual void addData_impl(Args... args) = 0;
350 for ( uint64_t i = 0; i < N; ++i ) {
351 addData_impl(args...);
355 template <
class... InArgs>
356 void addData(InArgs&&... args)
358 addData_impl(std::make_tuple(std::forward<InArgs>(args)...));
361 virtual ~StatisticCollector() =
default;
379 SST_ELI_DECLARE_INFO(
382 SST_ELI_DECLARE_CTOR(BaseComponent*,
const std::string&,
const std::string&,
SST::Params&)
384 SST_ELI_DOCUMENT_PARAMS(
385 {
"rate",
"Frequency at which to output statistic. Must include units. 0ns = output at end of simulation only.",
"0ns" },
386 {
"startat",
"Time at which to enable data collection in this statistic. Must include units. 0ns = always enabled.",
"0ns"},
387 {
"stopat",
"Time at which to disable data collection in this statistic. 0ns = always enabled.",
"0ns"},
388 {
"resetOnOutput",
"Whether to reset the statistic's values after each output.",
"False"}
399 template <
class... InArgs>
405 addData_impl(std::forward<InArgs>(args)...);
410 template <
class... InArgs>
411 void addDataNTimes(uint64_t N, InArgs&&... args)
416 addData_impl_Ntimes(N, std::forward<InArgs>(args)...);
421 static fieldType_t fieldId() {
return StatisticFieldType<T>::id(); }
439 Statistic(BaseComponent* comp,
const std::string& stat_name,
const std::string& stat_sub_id,
Params& stat_params) :
460 SST_ELI_DECLARE_INFO(
463 SST_ELI_DECLARE_CTOR(BaseComponent*,
const std::string&,
const std::string&,
SST::Params&)
465 void registerOutputFields(StatisticFieldsOutput* stat_output)
override;
480 Statistic(BaseComponent* comp,
const std::string& stat_name,
const std::string& stat_sub_id,
Params& stat_params) :
492template <
class... Args>
493using MultiStatistic =
Statistic<std::tuple<Args...>>;
495struct ImplementsStatFields
498 std::string toString()
const;
500 Statistics::fieldType_t fieldId()
const {
return field_; }
502 const char* fieldName()
const {
return field_name_; }
504 const char* fieldShortName()
const {
return short_name_; }
508 explicit ImplementsStatFields(T* UNUSED(t)) :
509 field_name_(T::ELI_fieldName()),
510 short_name_(T::ELI_fieldShortName()),
511 field_(T::ELI_registerField(T::ELI_fieldName(), T::ELI_fieldShortName()))
515 const char* field_name_;
516 const char* short_name_;
517 Statistics::fieldType_t field_;
521#define SST_ELI_DECLARE_STATISTIC_TEMPLATE(cls, lib, name, version, desc, interface) \
522 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
523 SST_ELI_INTERFACE_INFO(interface) \
524 virtual std::string getELIName() const override \
526 return std::string(lib) + "." + (name); \
529#define SST_ELI_DECLARE_STATISTIC_TEMPLATE_DERIVED(cls, field, lib, name, version, desc, interface) \
530 using SST::Statistics::Statistic<field>::__EliBaseLevel; \
531 using typename SST::Statistics::Statistic<field>::__LocalEliBase; \
532 using typename SST::Statistics::Statistic<field>::__ParentEliBase; \
534 static constexpr int __EliDerivedLevel = \
535 std::is_same_v<SST::Statistics::Statistic<field>, cls<field>> ? __EliBaseLevel : __EliBaseLevel + 1; \
536 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
537 SST_ELI_INTERFACE_INFO(interface) \
538 virtual std::string getELIName() const override \
540 return std::string(lib) + "." + name; \
543#define SST_ELI_REGISTER_CUSTOM_STATISTIC(cls, lib, name, version, desc) \
544 SST_ELI_REGISTER_DERIVED(SST::Statistics::CustomStatistic,cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
545 SST_ELI_INTERFACE_INFO("CustomStatistic")
547#define SST_ELI_DECLARE_STATISTIC(cls, field, lib, name, version, desc, interface) \
548 static bool ELI_isLoaded() \
550 return SST::Statistics::Statistic<field>::template addDerivedInfo<cls>(lib, name) && \
551 SST::Statistics::Statistic<field>::template addDerivedBuilder<cls>(lib, name) && \
552 SST::Statistics::Statistic<field>::template addDerivedInfo<SST::Statistics::NullStatistic<field>>( \
554 SST::Statistics::Statistic<field>::template addDerivedBuilder<SST::Statistics::NullStatistic<field>>( \
557 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
558 SST_ELI_INTERFACE_INFO(interface) \
559 static const char* ELI_fieldName() \
563 static const char* ELI_fieldShortName() \
568#ifdef __INTEL_COMPILER
569#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
570 bool force_instantiate_##cls##_##field = \
571 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
572 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
573 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
574 SST::Statistics::NullStatistic<field>>::isLoaded() && \
575 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
576 SST::Statistics::NullStatistic<field>>::isLoaded();
578#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
579 struct cls##_##field##_##shortName : public cls<field> \
581 cls##_##field##_##shortName( \
582 SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
583 cls<field>(bc, sn, si, p) \
585 static bool ELI_isLoaded() \
587 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
588 cls##_##field##_##shortName>::isLoaded() && \
589 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
590 cls##_##field##_##shortName>::isLoaded() && \
591 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
592 SST::Statistics::NullStatistic<field>>::isLoaded() && \
593 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
594 SST::Statistics::NullStatistic<field>>::isLoaded(); \
599#define PP_NARG(...) PP_NARG_(__VA_ARGS__, PP_NSEQ())
600#define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
601#define PP_ARG_N(_1, _2, _3, _4, _5, N, ...) N
602#define PP_NSEQ() 5, 4, 3, 2, 1, 0
604#define PP_GLUE(X, Y) PP_GLUE_I(X, Y)
605#define PP_GLUE_I(X, Y) X##Y
607#define STAT_NAME1(base, a) base##a
608#define STAT_NAME2(base, a, b) base##a##b
609#define STAT_NAME3(base, a, b, c) base##a##b##c
610#define STAT_NAME4(base, a, b, c, d) base##a##b##c##d
612#define STAT_GLUE_NAME(base, ...) PP_GLUE(STAT_NAME, PP_NARG(__VA_ARGS__))(base, __VA_ARGS__)
613#define STAT_TUPLE(...) std::tuple<__VA_ARGS__>
615#ifdef __INTEL_COMPILER
616#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
617 bool force_instantiate_stat_name = \
618 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
619 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
620 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, \
621 SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
622 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, \
623 SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
628#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
629 struct name : public cls<__VA_ARGS__> \
631 name(SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
632 cls<__VA_ARGS__>(bc, sn, si, p) \
634 bool ELI_isLoaded() const \
636 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
637 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
638 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, \
639 SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
640 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, \
641 SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
646#define SST_ELI_INSTANTIATE_MULTI_STATISTIC(cls, ...) \
647 MAKE_MULTI_STATISTIC(cls, STAT_GLUE_NAME(cls, __VA_ARGS__), STAT_TUPLE(__VA_ARGS__), __VA_ARGS__)
654void registerStatWithEngineOnRestart(
659namespace Core::Serialization {
668 switch ( ser.mode() ) {
669 case serializer::SIZER:
670 case serializer::PACK:
673 SST_SER(stat_eli_type);
676 s->serializeStat(ser);
680 case serializer::UNPACK:
682 std::string stat_eli_type;
684 params.
insert(
"type", stat_eli_type);
686 SST_SER(stat_eli_type);
688 if ( stat_eli_type ==
"sst.NullStatistic" ) {
691 stat_eli_type, params,
nullptr,
"",
"", params);
697 std::string stat_name;
699 SimTime_t output_rate_factor;
701 SimTime_t start_at_factor = 0;
702 SimTime_t stop_at_factor = 0;
706 SST_SER(output_rate_factor);
709 stat_eli_type, params, comp, stat_name, stat_id, params);
715 SST_SER(start_at_factor);
718 SST_SER(stop_at_factor);
720 SST::Stat::pvt::registerStatWithEngineOnRestart(s, start_at_factor, stop_at_factor, output_rate_factor);
724 case serializer::MAP:
732 SST_FRIEND_SERIALIZE();
740#include "sst/core/statapi/statnull.h"
Main component object for the simulation.
Definition baseComponent.h:98
Base serialize class.
Definition serialize.h:133
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Definition interfaceInfo.h:22
Definition paramsInfo.h:41
Class for instantiating Components, Links and the like out of element libraries.
Definition factory.h:56
Parameter store.
Definition params.h:65
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:171
Forms the base class for statistics gathering within SST.
Definition statbase.h:51
bool getStopAtFlag()
Manage StopAt flag.
Definition statbase.h:155
BaseComponent * getComponent() const
Return a pointer to the parent Component.
Definition statbase.h:142
virtual void resetCollectionCount()
Set the current collection count to 0.
Definition statbase.cc:100
void enable()
Enable Statistic for collections.
Definition statbase.h:55
bool getStartAtFlag()
Return the rate at which the statistic should be output.
Definition statbase.h:150
bool getOutputRateFlag()
Manage OutputRate flag.
Definition statbase.h:160
void setFlagOutputAtEndOfSim(bool flag)
Set the Output At End Of Sim flag.
Definition statbase.h:93
void setFlagClearDataOnOutput(bool flag)
Set the Clear Data On Output flag.
Definition statbase.h:88
const std::string & getStatName() const
Return the Statistic Name.
Definition statbase.h:105
virtual bool isReady() const
Indicate that the Statistic is Ready to be used.
Definition statbase.h:190
virtual void setCollectionCount(uint64_t new_count)
Set the current collection count to a defined value.
Definition statbase.cc:92
bool getFlagOutputAtEndOfSim() const
Return the OutputAtEndOfSim flag value.
Definition statbase.h:182
virtual const std::string & getStatTypeName() const
Return the Statistic type name.
Definition statbase.h:124
const StatisticFieldInfo::fieldType_t & getStatDataType() const
Return the Statistic data type.
Definition statbase.h:127
virtual void setCollectionCountLimit(uint64_t new_limit)
Set the collection count limit to a defined value.
Definition statbase.cc:106
bool isOutputPeriodic() const
Return the collection mode that is registered.
Definition statbase.h:185
void setFlagResetCountOnOutput(bool flag)
Set the Reset Count On Output flag.
Definition statbase.h:80
bool getFlagClearDataOnOutput() const
Return the ClearDataOnOutput flag value.
Definition statbase.h:179
const std::string getCompName() const
Return the Component Name.
Definition statbase.cc:60
uint64_t getCollectionCountLimit() const
Return the collection count limit.
Definition statbase.h:170
const std::string & getStatSubId() const
Return the Statistic SubId.
Definition statbase.h:108
virtual bool isNullStatistic() const
Indicate if the Statistic is a NullStatistic.
Definition statbase.h:193
virtual void clearStatisticData()
Inform the Statistic to clear its data.
Definition statbase.h:62
void setPortModName(std::string &port, size_t index)
Set port name if stat is owned by a port module Temporary field until a common base class for element...
Definition statbase.h:98
virtual void incrementCollectionCount(uint64_t increment)
Increment current collection count.
Definition statbase.cc:84
const char * getStatDataTypeShortName() const
Return the Statistic data type.
Definition statbase.h:130
uint64_t getCollectionCount() const
Return the current collection count.
Definition statbase.h:173
void disable()
Disable Statistic for collections.
Definition statbase.h:58
StatisticBase(BaseComponent *comp, const std::string &stat_name, const std::string &stat_sub_id, Params &stat_params)
Construct a StatisticBase.
Definition statbase.cc:40
const std::string getFullStatName() const
Return the full Statistic name of component.stat_name.sub_id.
Definition statbase.h:111
const char * getStatDataTypeFullName() const
Return the Statistic data type.
Definition statbase.h:136
bool isEnabled() const
Return the enable status of the Statistic.
Definition statbase.h:145
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:169
void setStatisticTypeName(const char *type_name)
Set an optional Statistic Type Name (for output) DEPRECATED: will be removed in SST 17....
Definition statbase.h:228
bool getFlagResetCountOnOutput() const
Return the ResetCountOnOutput flag value.
Definition statbase.h:176
void setStatisticDataType(const StatisticFieldInfo::fieldType_t data_type)
Set the Statistic Data Type.
Definition statbase.h:221
Definition statoutput.h:172
Definition statgroup.h:32
Forms the base class for statistics output generation within the SST core.
Definition statoutput.h:54
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition statengine.h:55
Statistic(BaseComponent *comp, const std::string &stat_name, const std::string &stat_sub_id, Params &stat_params)
Construct a Statistic.
Definition statbase.h:480
void outputStatisticFields(StatisticFieldsOutput *stat_output, bool end_of_sim_flag) override
Called by the system to tell the Statistic to send its data to the StatisticOutput to be output.
Definition statbase.cc:67
Forms the template defined base class for statistics gathering within SST.
Definition statbase.h:376
Statistic(BaseComponent *comp, const std::string &stat_name, const std::string &stat_sub_id, Params &stat_params)
Construct a Statistic.
Definition statbase.h:439
void addData(InArgs &&... args)
Add data to the Statistic This will call the addData_impl() routine in the derived Statistic.
Definition statbase.h:400
virtual void serialize_order(SST::Core::Serialization::serializer &ser) override
Serialization.
Definition statbase.h:423
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:327
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:348
Base type that creates the virtual addData(...) interface Used for distinguishing arithmetic types (c...
Definition statbase.h:314