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);
230 void setRegisteredCollectionMode(
bool is_periodic) { registered_collection_mode_ = is_periodic; }
233 static std::string buildStatisticFullName(
const char* comp_name,
const char* stat_name,
const char* stat_sub_id);
234 static std::string buildStatisticFullName(
235 const std::string& comp_name,
const std::string& stat_name,
const std::string& stat_sub_id);
242 virtual void registerOutputFields(StatisticFieldsOutput* stat_output) = 0;
249 virtual void outputStatisticFields(StatisticFieldsOutput* stat_output,
bool end_of_sim_flag) = 0;
256 virtual bool isStatModeSupported(
bool UNUSED(periodic))
const {
return true; }
261 void checkEventForOutput();
263 const StatisticGroup* getGroup()
const {
return group_; }
264 void setGroup(
const StatisticGroup* group) { group_ = group; }
271 enum Flag : uint8_t {
277 std::string stat_name_ =
"";
278 std::string stat_sub_id_ =
"";
279 std::string stat_type_name_ =
"";
280 std::string stat_mod_name_ =
284 bool stat_enabled_ =
true;
285 bool registered_collection_mode_ =
true;
286 uint64_t current_collection_count_ = 0;
287 uint64_t output_collection_count_ = 0;
288 uint64_t collection_count_limit_ = 0;
290 const StatisticGroup* group_ =
nullptr;
292 bool reset_count_on_output_ =
false;
293 bool clear_data_on_output_ =
false;
294 bool output_at_end_of_sim_ =
true;
296 BaseComponent* component_;
297 StatisticFieldInfo::fieldType_t stat_data_type_;
306template <
class T,
bool = std::is_arithmetic_v<T>>
312 virtual void addData_impl(T data) = 0;
322 for ( uint64_t i = 0; i < N; ++i ) {
330template <
class... Args>
333 virtual void addData_impl(Args... args) = 0;
343 for ( uint64_t i = 0; i < N; ++i ) {
344 addData_impl(args...);
348 template <
class... InArgs>
349 void addData(InArgs&&... args)
351 addData_impl(std::make_tuple(std::forward<InArgs>(args)...));
354 virtual ~StatisticCollector() =
default;
372 SST_ELI_DECLARE_INFO(
375 SST_ELI_DECLARE_CTOR(BaseComponent*,
const std::string&,
const std::string&,
SST::Params&)
377 SST_ELI_DOCUMENT_PARAMS(
378 {
"rate",
"Frequency at which to output statistic. Must include units. 0ns = output at end of simulation only.",
"0ns" },
379 {
"startat",
"Time at which to enable data collection in this statistic. Must include units. 0ns = always enabled.",
"0ns"},
380 {
"stopat",
"Time at which to disable data collection in this statistic. 0ns = always enabled.",
"0ns"},
381 {
"resetOnOutput",
"Whether to reset the statistic's values after each output.",
"False"}
392 template <
class... InArgs>
398 addData_impl(std::forward<InArgs>(args)...);
403 template <
class... InArgs>
404 void addDataNTimes(uint64_t N, InArgs&&... args)
409 addData_impl_Ntimes(N, std::forward<InArgs>(args)...);
414 static fieldType_t fieldId() {
return StatisticFieldType<T>::id(); }
432 Statistic(BaseComponent* comp,
const std::string& stat_name,
const std::string& stat_sub_id,
Params& stat_params) :
453 SST_ELI_DECLARE_INFO(
456 SST_ELI_DECLARE_CTOR(BaseComponent*,
const std::string&,
const std::string&,
SST::Params&)
458 void registerOutputFields(StatisticFieldsOutput* stat_output)
override;
473 Statistic(BaseComponent* comp,
const std::string& stat_name,
const std::string& stat_sub_id,
Params& stat_params) :
485template <
class... Args>
486using MultiStatistic =
Statistic<std::tuple<Args...>>;
488struct ImplementsStatFields
491 std::string toString()
const;
493 Statistics::fieldType_t fieldId()
const {
return field_; }
495 const char* fieldName()
const {
return field_name_; }
497 const char* fieldShortName()
const {
return short_name_; }
501 explicit ImplementsStatFields(T* UNUSED(t)) :
502 field_name_(T::ELI_fieldName()),
503 short_name_(T::ELI_fieldShortName()),
504 field_(T::ELI_registerField(T::ELI_fieldName(), T::ELI_fieldShortName()))
508 const char* field_name_;
509 const char* short_name_;
510 Statistics::fieldType_t field_;
514#define SST_ELI_DECLARE_STATISTIC_TEMPLATE(cls, lib, name, version, desc, interface) \
515 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
516 SST_ELI_INTERFACE_INFO(interface) \
517 virtual std::string getELIName() const override \
519 return std::string(lib) + "." + (name); \
522#define SST_ELI_DECLARE_STATISTIC_TEMPLATE_DERIVED(cls, field, lib, name, version, desc, interface) \
523 using SST::Statistics::Statistic<field>::__EliBaseLevel; \
524 using typename SST::Statistics::Statistic<field>::__LocalEliBase; \
525 using typename SST::Statistics::Statistic<field>::__ParentEliBase; \
527 static constexpr int __EliDerivedLevel = \
528 std::is_same_v<SST::Statistics::Statistic<field>, cls<field>> ? __EliBaseLevel : __EliBaseLevel + 1; \
529 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
530 SST_ELI_INTERFACE_INFO(interface) \
531 virtual std::string getELIName() const override \
533 return std::string(lib) + "." + name; \
536#define SST_ELI_REGISTER_CUSTOM_STATISTIC(cls, lib, name, version, desc) \
537 SST_ELI_REGISTER_DERIVED(SST::Statistics::CustomStatistic,cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
538 SST_ELI_INTERFACE_INFO("CustomStatistic")
540#define SST_ELI_DECLARE_STATISTIC(cls, field, lib, name, version, desc, interface) \
541 static bool ELI_isLoaded() \
543 return SST::Statistics::Statistic<field>::template addDerivedInfo<cls>(lib, name) && \
544 SST::Statistics::Statistic<field>::template addDerivedBuilder<cls>(lib, name) && \
545 SST::Statistics::Statistic<field>::template addDerivedInfo<SST::Statistics::NullStatistic<field>>( \
547 SST::Statistics::Statistic<field>::template addDerivedBuilder<SST::Statistics::NullStatistic<field>>( \
550 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
551 SST_ELI_INTERFACE_INFO(interface) \
552 static const char* ELI_fieldName() \
556 static const char* ELI_fieldShortName() \
561#ifdef __INTEL_COMPILER
562#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
563 bool force_instantiate_##cls##_##field = \
564 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
565 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
566 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
567 SST::Statistics::NullStatistic<field>>::isLoaded() && \
568 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
569 SST::Statistics::NullStatistic<field>>::isLoaded();
571#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
572 struct cls##_##field##_##shortName : public cls<field> \
574 cls##_##field##_##shortName( \
575 SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
576 cls<field>(bc, sn, si, p) \
578 static bool ELI_isLoaded() \
580 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
581 cls##_##field##_##shortName>::isLoaded() && \
582 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
583 cls##_##field##_##shortName>::isLoaded() && \
584 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
585 SST::Statistics::NullStatistic<field>>::isLoaded() && \
586 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
587 SST::Statistics::NullStatistic<field>>::isLoaded(); \
592#define PP_NARG(...) PP_NARG_(__VA_ARGS__, PP_NSEQ())
593#define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
594#define PP_ARG_N(_1, _2, _3, _4, _5, N, ...) N
595#define PP_NSEQ() 5, 4, 3, 2, 1, 0
597#define PP_GLUE(X, Y) PP_GLUE_I(X, Y)
598#define PP_GLUE_I(X, Y) X##Y
600#define STAT_NAME1(base, a) base##a
601#define STAT_NAME2(base, a, b) base##a##b
602#define STAT_NAME3(base, a, b, c) base##a##b##c
603#define STAT_NAME4(base, a, b, c, d) base##a##b##c##d
605#define STAT_GLUE_NAME(base, ...) PP_GLUE(STAT_NAME, PP_NARG(__VA_ARGS__))(base, __VA_ARGS__)
606#define STAT_TUPLE(...) std::tuple<__VA_ARGS__>
608#ifdef __INTEL_COMPILER
609#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
610 bool force_instantiate_stat_name = \
611 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
612 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
613 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, \
614 SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
615 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, \
616 SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
621#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
622 struct name : public cls<__VA_ARGS__> \
624 name(SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
625 cls<__VA_ARGS__>(bc, sn, si, p) \
627 bool ELI_isLoaded() const \
629 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
630 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
631 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, \
632 SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
633 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, \
634 SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
639#define SST_ELI_INSTANTIATE_MULTI_STATISTIC(cls, ...) \
640 MAKE_MULTI_STATISTIC(cls, STAT_GLUE_NAME(cls, __VA_ARGS__), STAT_TUPLE(__VA_ARGS__), __VA_ARGS__)
647void registerStatWithEngineOnRestart(
652namespace Core::Serialization {
661 switch ( ser.mode() ) {
662 case serializer::SIZER:
663 case serializer::PACK:
666 SST_SER(stat_eli_type);
669 s->serializeStat(ser);
673 case serializer::UNPACK:
675 std::string stat_eli_type;
677 params.
insert(
"type", stat_eli_type);
679 SST_SER(stat_eli_type);
681 if ( stat_eli_type ==
"sst.NullStatistic" ) {
684 stat_eli_type, params,
nullptr,
"",
"", params);
690 std::string stat_name;
692 SimTime_t output_rate_factor;
694 SimTime_t start_at_factor = 0;
695 SimTime_t stop_at_factor = 0;
699 SST_SER(output_rate_factor);
702 stat_eli_type, params, comp, stat_name, stat_id, params);
708 SST_SER(start_at_factor);
711 SST_SER(stop_at_factor);
713 SST::Stat::pvt::registerStatWithEngineOnRestart(s, start_at_factor, stop_at_factor, output_rate_factor);
717 case serializer::MAP:
725 SST_FRIEND_SERIALIZE();
733#include "sst/core/statapi/statnull.h"
Main component object for the simulation.
Definition baseComponent.h:67
Base serialize class.
Definition serialize.h:132
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).
Definition statbase.h:224
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:473
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:369
Statistic(BaseComponent *comp, const std::string &stat_name, const std::string &stat_sub_id, Params &stat_params)
Construct a Statistic.
Definition statbase.h:432
void addData(InArgs &&... args)
Add data to the Statistic This will call the addData_impl() routine in the derived Statistic.
Definition statbase.h:393
virtual void serialize_order(SST::Core::Serialization::serializer &ser) override
Serialization.
Definition statbase.h:416
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:320
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:341
Base type that creates the virtual addData(...) interface Used for distinguishing arithmetic types (c...
Definition statbase.h:307