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/warnmacros.h" 30 namespace Statistics {
31 class StatisticOutput;
32 class StatisticFieldsOutput;
33 class StatisticProcessingEngine;
49 typedef enum { STAT_MODE_UNDEFINED, STAT_MODE_COUNT, STAT_MODE_PERIODIC, STAT_MODE_DUMP_AT_END }
StatMode_t;
53 void enable() { m_statEnabled =
true; }
80 static const std::vector<ElementInfoParam>& ELI_getParams();
98 inline const std::string&
getStatName()
const {
return m_statName; }
110 inline const StatisticFieldInfo::fieldType_t&
getStatDataType()
const {
return m_statDataType; }
115 return StatisticFieldInfo::getFieldTypeShortName(m_statDataType);
121 return StatisticFieldInfo::getFieldTypeFullName(m_statDataType);
208 void setRegisteredCollectionMode(
StatMode_t mode) { m_registeredCollectionMode = mode; }
211 static std::string buildStatisticFullName(
const char* compName,
const char* statName,
const char* statSubId);
213 buildStatisticFullName(
const std::string& compName,
const std::string& statName,
const std::string& statSubId);
220 virtual void registerOutputFields(StatisticFieldsOutput* statOutput) = 0;
227 virtual void outputStatisticFields(StatisticFieldsOutput* statOutput,
bool EndOfSimFlag) = 0;
234 virtual bool isStatModeSupported(
StatMode_t UNUSED(mode))
const {
return true; }
237 bool operator==(StatisticBase& checkStat);
240 void initializeStatName(
const char* compName,
const char* statName,
const char* statSubId);
241 void initializeStatName(
const std::string& compName,
const std::string& statName,
const std::string& statSubId);
243 void initializeProperties();
244 void checkEventForOutput();
247 void delayOutputExpiredHandler();
248 void delayCollectionExpiredHandler();
250 const StatisticGroup* getGroup()
const {
return m_group; }
251 void setGroup(
const StatisticGroup* group) { m_group = group; }
257 BaseComponent* m_component;
258 std::string m_statName;
259 std::string m_statSubId;
260 std::string m_statFullName;
261 std::string m_statTypeName;
264 uint64_t m_currentCollectionCount;
265 uint64_t m_outputCollectionCount;
266 uint64_t m_collectionCountLimit;
267 StatisticFieldInfo::fieldType_t m_statDataType;
270 bool m_outputEnabled;
271 bool m_resetCountOnOutput;
272 bool m_clearDataOnOutput;
273 bool m_outputAtEndOfSim;
275 bool m_outputDelayed;
276 bool m_collectionDelayed;
277 bool m_savedStatEnabled;
278 bool m_savedOutputEnabled;
279 const StatisticGroup* m_group;
289 template <class T, bool F = std::is_fundamental<T>::value>
296 virtual void addData_impl(T data) = 0;
306 for ( uint64_t i = 0; i < N; ++i ) {
312 template <
class... Args>
315 virtual void addData_impl(Args... args) = 0;
325 for ( uint64_t i = 0; i < N; ++i ) {
326 addData_impl(args...);
330 template <
class... InArgs>
331 void addData(InArgs&&... args)
333 addData_impl(std::make_tuple(std::forward<InArgs>(args)...));
347 template <
typename T>
348 class Statistic :
public StatisticBase,
public StatisticCollector<T>
351 SST_ELI_DECLARE_BASE(Statistic)
352 SST_ELI_DECLARE_INFO(
353 ELI::ProvidesInterface,
355 SST_ELI_DECLARE_CTOR(BaseComponent*,
const std::string&,
const std::string&,
SST::Params&)
358 using StatisticCollector<T>::addData_impl;
359 using StatisticCollector<T>::addData_impl_Ntimes;
365 template <
class... InArgs>
371 addData_impl(std::forward<InArgs>(args)...);
376 template <
class... InArgs>
377 void addDataNTimes(uint64_t N, InArgs&&... args)
382 addData_impl_Ntimes(N, std::forward<InArgs>(args)...);
387 static fieldType_t fieldId() {
return StatisticFieldType<T>::id(); }
426 SST_ELI_DECLARE_INFO(
456 using CustomStatistic = Statistic<void>;
458 template <
class... Args>
459 using MultiStatistic = Statistic<std::tuple<Args...>>;
464 std::string toString()
const;
466 Statistics::fieldType_t fieldId()
const {
return field_; }
468 const char* fieldName()
const {
return field_name_; }
470 const char* fieldShortName()
const {
return short_name_; }
475 field_name_(T::ELI_fieldName()),
476 short_name_(T::ELI_fieldShortName()),
477 field_(T::ELI_registerField(T::ELI_fieldName(), T::ELI_fieldShortName()))
481 const char* field_name_;
482 const char* short_name_;
483 Statistics::fieldType_t field_;
487 #define SST_ELI_DECLARE_STATISTIC_TEMPLATE(cls, lib, name, version, desc, interface) \ 488 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \ 489 SST_ELI_INTERFACE_INFO(interface) 491 #define SST_ELI_REGISTER_CUSTOM_STATISTIC(cls, lib, name, version, desc) \ 492 SST_ELI_REGISTER_DERIVED(SST::Statistics::CustomStatistic,cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \ 493 SST_ELI_INTERFACE_INFO("CustomStatistic") 495 #define SST_ELI_DECLARE_STATISTIC(cls, field, lib, name, version, desc, interface) \ 496 static bool ELI_isLoaded() \ 498 return SST::Statistics::Statistic<field>::template addDerivedInfo<cls>(lib, name) && \ 499 SST::Statistics::Statistic<field>::template addDerivedBuilder<cls>(lib, name) && \ 500 SST::Statistics::Statistic<field>::template addDerivedInfo<SST::Statistics::NullStatistic<field>>( \ 502 SST::Statistics::Statistic<field>::template addDerivedBuilder<SST::Statistics::NullStatistic<field>>( \ 505 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \ 506 SST_ELI_INTERFACE_INFO(interface) \ 507 static const char* ELI_fieldName() { return #field; } \ 508 static const char* ELI_fieldShortName() { return #field; } 510 #ifdef __INTEL_COMPILER 511 #define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \ 512 bool force_instantiate_##cls##_##field = \ 513 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \ 514 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \ 515 SST::ELI::InstantiateBuilderInfo< \ 516 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded() && \ 517 SST::ELI::InstantiateBuilder< \ 518 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded(); 520 #define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \ 521 struct cls##_##field##_##shortName : public cls<field> \ 523 cls##_##field##_##shortName( \ 524 SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \ 525 cls<field>(bc, sn, si, p) \ 527 static bool ELI_isLoaded() \ 529 return SST::ELI::InstantiateBuilderInfo< \ 530 SST::Statistics::Statistic<field>, cls##_##field##_##shortName>::isLoaded() && \ 531 SST::ELI::InstantiateBuilder< \ 532 SST::Statistics::Statistic<field>, cls##_##field##_##shortName>::isLoaded() && \ 533 SST::ELI::InstantiateBuilderInfo< \ 534 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded() && \ 535 SST::ELI::InstantiateBuilder< \ 536 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded(); \ 541 #define PP_NARG(...) PP_NARG_(__VA_ARGS__, PP_NSEQ()) 542 #define PP_NARG_(...) PP_ARG_N(__VA_ARGS__) 543 #define PP_ARG_N(_1, _2, _3, _4, _5, N, ...) N 544 #define PP_NSEQ() 5, 4, 3, 2, 1, 0 546 #define PP_GLUE(X, Y) PP_GLUE_I(X, Y) 547 #define PP_GLUE_I(X, Y) X##Y 549 #define STAT_NAME1(base, a) base##a 550 #define STAT_NAME2(base, a, b) base##a##b 551 #define STAT_NAME3(base, a, b, c) base##a##b##c 552 #define STAT_NAME4(base, a, b, c, d) base##a##b##c##d 554 #define STAT_GLUE_NAME(base, ...) PP_GLUE(STAT_NAME, PP_NARG(__VA_ARGS__))(base, __VA_ARGS__) 555 #define STAT_TUPLE(...) std::tuple<__VA_ARGS__> 557 #ifdef __INTEL_COMPILER 558 #define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \ 559 bool force_instantiate_stat_name = \ 560 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \ 561 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \ 562 SST::ELI::InstantiateBuilderInfo< \ 563 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded() && \ 564 SST::ELI::InstantiateBuilder< \ 565 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded(); \ 570 #define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \ 571 struct name : public cls<__VA_ARGS__> \ 573 name(SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \ 574 cls<__VA_ARGS__>(bc, sn, si, p) \ 576 bool ELI_isLoaded() const \ 578 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \ 579 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \ 580 SST::ELI::InstantiateBuilderInfo< \ 581 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded() && \ 582 SST::ELI::InstantiateBuilder< \ 583 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded(); \ 588 #define SST_ELI_INSTANTIATE_MULTI_STATISTIC(cls, ...) \ 589 MAKE_MULTI_STATISTIC(cls, STAT_GLUE_NAME(cls, __VA_ARGS__), STAT_TUPLE(__VA_ARGS__), __VA_ARGS__) 603 namespace Serialization {
614 switch ( ser.mode() ) {
615 case serializer::SIZER:
616 case serializer::PACK:
620 if ( stattype ==
"NULL" )
621 stattype =
"sst.NullStatistic";
623 stattype = params.
find<std::string>(
"type",
"sst.AccumulatorStatistic");
631 case serializer::UNPACK:
634 std::string stattype;
640 stattype, params, comp,
"",
"", params);
642 if ( stattype !=
"sst.NullStatistic" ) { SST::Stat::pvt::registerStatWithEngineOnRestart(s); }
645 case serializer::MAP:
664 #include "sst/core/statapi/statnull.h" 666 #endif // SST_CORE_STATAPI_STATBASE_H This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
void setFlagOutputAtEndOfSim(bool flag)
Set the Output At End Of Sim flag.
Definition: statbase.h:91
virtual void setCollectionCountLimit(uint64_t newLimit)
Set the collection count limit to a defined value.
Definition: statbase.cc:108
bool isOutputEnabled() const
Return the enable status of the Statistic's ability to output data.
Definition: statbase.h:131
void delayCollection(const char *delayTime)
Delay the statistic from collecting data for a specified delay time.
Definition: statbase.cc:190
void setFlagClearDataOnOutput(bool flag)
Set the Clear Data On Output flag.
Definition: statbase.h:86
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:50
void addData(InArgs &&... args)
Add data to the Statistic This will call the addData_impl() routine in the derived Statistic...
Definition: statbase.h:366
const StatisticFieldInfo::fieldType_t & getStatDataType() const
Return the Statistic data type.
Definition: statbase.h:110
Base serialize class.
Definition: serialize.h:45
Forms the base class for statistics gathering within SST.
Definition: statbase.h:45
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:304
const std::string & getStatName() const
Return the Statistic Name.
Definition: statbase.h:98
void setStatisticTypeName(const char *typeName)
Set an optional Statistic Type Name.
Definition: statbase.h:202
const char * getStatDataTypeFullName() const
Return the Statistic data type.
Definition: statbase.h:119
void enable()
Enable Statistic for collections.
Definition: statbase.h:53
bool getFlagResetCountOnOutput() const
Return the ResetCountOnOutput flag value.
Definition: statbase.h:140
void delayOutput(const char *delayTime)
Delay the statistic from outputting data for a specified delay time.
Definition: statbase.cc:172
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:45
Statistic(BaseComponent *comp, const std::string &statName, const std::string &statSubId, Params &statParams)
Construct a Statistic.
Definition: statbase.h:446
const std::string & getCompName() const
Return the Component Name.
Definition: statbase.cc:64
bool getFlagClearDataOnOutput() const
Return the ClearDataOnOutput flag value.
Definition: statbase.h:143
uint64_t getCollectionCountLimit() const
Return the collection count limit.
Definition: statbase.h:134
BaseComponent * getComponent() const
Return a pointer to the parent Component.
Definition: statbase.h:125
Serialization "gateway" object.
Definition: serialize.h:133
virtual void resetCollectionCount()
Set the current collection count to 0.
Definition: statbase.cc:102
Base type that creates the virtual addData(...) interface Used for distinguishing fundamental types...
Definition: statbase.h:290
bool getFlagOutputAtEndOfSim() const
Return the OutputAtEndOfSim flag value.
Definition: statbase.h:146
Statistic(BaseComponent *comp, const std::string &statName, const std::string &statSubId, Params &statParams)
Construct a Statistic.
Definition: statbase.h:405
Definition: paramsInfo.h:40
const char * getStatDataTypeShortName() const
Return the Statistic data type.
Definition: statbase.h:113
virtual void incrementCollectionCount(uint64_t increment)
Increment current collection count.
Definition: statbase.cc:86
Definition: statoutput.h:162
virtual bool isNullStatistic() const
Indicate if the Statistic is a NullStatistic.
Definition: statbase.h:167
bool isEnabled() const
Return the enable status of the Statistic.
Definition: statbase.h:128
Main component object for the simulation.
Definition: baseComponent.h:62
void disable()
Disable Statistic for collections.
Definition: statbase.h:56
const std::string & getStatTypeName() const
Return the Statistic type name.
Definition: statbase.h:107
Definition: statbase.h:461
StatMode_t
Statistic collection mode.
Definition: statbase.h:49
virtual void clearStatisticData()
Inform the Statistic to clear its data.
Definition: statbase.h:60
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:323
const std::string & getStatSubId() const
Return the Statistic SubId.
Definition: statbase.h:101
std::enable_if< not std::is_same< std::string, T >::value, T >::type find(const std::string &k, T default_value, bool &found) const
Find a Parameter value in the set, and return its value as a type T.
Definition: params.h:321
void setFlagResetCountOnOutput(bool flag)
Set the Reset Count On Output flag.
Definition: statbase.h:78
Parameter store.
Definition: params.h:55
Class for instantiating Components, Links and the like out of element libraries.
Definition: factory.h:43
virtual void setCollectionCount(uint64_t newCount)
Set the current collection count to a defined value.
Definition: statbase.cc:94
void setStatisticDataType(const StatisticFieldInfo::fieldType_t dataType)
Set the Statistic Data Type.
Definition: statbase.h:199
virtual void serialize_order(SST::Core::Serialization::serializer &ser) override
Serialization.
Definition: statbase.h:389
StatMode_t getRegisteredCollectionMode() const
Return the collection mode that is registered.
Definition: statbase.h:149
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:52
Definition: statgroup.h:29
Params & getParams()
Return the Statistic Parameters NOTE: This must be public so that it is accessible to the serialize_i...
Definition: statbase.h:173
virtual void serialize_order(SST::Core::Serialization::serializer &ser)
Serialization.
Definition: statbase.cc:223
Definition: interfaceInfo.h:18
virtual bool isReady() const
Indicate that the Statistic is Ready to be used.
Definition: statbase.h:164
StatisticBase(BaseComponent *comp, const std::string &statName, const std::string &statSubId, Params &statParams)
Construct a StatisticBase.
Definition: statbase.cc:43
const std::string & getFullStatName() const
Return the full Statistic name of Component.StatName.SubId.
Definition: statbase.h:104
uint64_t getCollectionCount() const
Return the current collection count.
Definition: statbase.h:137