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/oneshot.h"
17 #include "sst/core/params.h"
18 #include "sst/core/serialization/serializable.h"
19 #include "sst/core/sst_types.h"
20 #include "sst/core/statapi/statfieldinfo.h"
21 #include "sst/core/warnmacros.h"
29 namespace Statistics {
30 class StatisticOutput;
31 class StatisticFieldsOutput;
32 class StatisticProcessingEngine;
42 StatisticInfo(
const std::string& name,
const Params& params) : name(name), params(params) {}
67 typedef enum { STAT_MODE_UNDEFINED, STAT_MODE_COUNT, STAT_MODE_PERIODIC, STAT_MODE_DUMP_AT_END }
StatMode_t;
71 void enable() { m_statEnabled =
true; }
98 static const std::vector<ElementInfoParam>& ELI_getParams();
116 inline const std::string&
getStatName()
const {
return m_statName; }
128 inline const StatisticFieldInfo::fieldType_t&
getStatDataType()
const {
return m_statDataType; }
133 return StatisticFieldInfo::getFieldTypeShortName(m_statDataType);
139 return StatisticFieldInfo::getFieldTypeFullName(m_statDataType);
219 void setRegisteredCollectionMode(
StatMode_t mode) { m_registeredCollectionMode = mode; }
222 static std::string buildStatisticFullName(
const char* compName,
const char* statName,
const char* statSubId);
224 buildStatisticFullName(
const std::string& compName,
const std::string& statName,
const std::string& statSubId);
231 virtual void registerOutputFields(StatisticFieldsOutput* statOutput) = 0;
238 virtual void outputStatisticFields(StatisticFieldsOutput* statOutput,
bool EndOfSimFlag) = 0;
245 virtual bool isStatModeSupported(
StatMode_t UNUSED(mode))
const {
return true; }
248 bool operator==(StatisticBase& checkStat);
251 void initializeStatName(
const char* compName,
const char* statName,
const char* statSubId);
252 void initializeStatName(
const std::string& compName,
const std::string& statName,
const std::string& statSubId);
254 void initializeProperties();
255 void checkEventForOutput();
258 void delayOutputExpiredHandler();
259 void delayCollectionExpiredHandler();
261 const StatisticGroup* getGroup()
const {
return m_group; }
262 void setGroup(
const StatisticGroup* group) { m_group = group; }
268 BaseComponent* m_component;
269 std::string m_statName;
270 std::string m_statSubId;
271 std::string m_statFullName;
272 std::string m_statTypeName;
275 uint64_t m_currentCollectionCount;
276 uint64_t m_collectionCountLimit;
277 StatisticFieldInfo::fieldType_t m_statDataType;
280 bool m_outputEnabled;
281 bool m_resetCountOnOutput;
282 bool m_clearDataOnOutput;
283 bool m_outputAtEndOfSim;
285 bool m_outputDelayed;
286 bool m_collectionDelayed;
287 bool m_savedStatEnabled;
288 bool m_savedOutputEnabled;
291 const StatisticGroup* m_group;
300 template <class T, bool F = std::is_fundamental<T>::value>
307 virtual void addData_impl(T data) = 0;
317 for ( uint64_t i = 0; i < N; ++i ) {
323 template <
class... Args>
326 virtual void addData_impl(Args... args) = 0;
336 for ( uint64_t i = 0; i < N; ++i ) {
337 addData_impl(args...);
341 template <
class... InArgs>
342 void addData(InArgs&&... args)
344 addData_impl(std::make_tuple(std::forward<InArgs>(args)...));
358 template <
typename T>
359 class Statistic :
public StatisticBase,
public StatisticCollector<T>
362 SST_ELI_DECLARE_BASE(Statistic)
363 SST_ELI_DECLARE_INFO(
364 ELI::ProvidesInterface,
366 SST_ELI_DECLARE_CTOR(BaseComponent*, const std::
string&, const std::
string&, SST::Params&)
369 using StatisticCollector<T>::addData_impl;
374 template <class... InArgs>
380 addData_impl(std::forward<InArgs>(args)...);
385 template <
class... InArgs>
386 void addDataNTimes(uint64_t N, InArgs&&... args)
391 addData_impl_Ntimes(N, std::forward<InArgs>(args)...);
396 static fieldType_t fieldId() {
return StatisticFieldType<T>::id(); }
430 SST_ELI_DECLARE_INFO(
460 using CustomStatistic = Statistic<void>;
462 template <
class... Args>
463 using MultiStatistic = Statistic<std::tuple<Args...>>;
468 std::string toString()
const;
470 Statistics::fieldType_t fieldId()
const {
return field_; }
472 const char* fieldName()
const {
return field_name_; }
474 const char* fieldShortName()
const {
return short_name_; }
479 field_name_(T::ELI_fieldName()),
480 short_name_(T::ELI_fieldShortName()),
481 field_(T::ELI_registerField(T::ELI_fieldName(), T::ELI_fieldShortName()))
485 const char* field_name_;
486 const char* short_name_;
487 Statistics::fieldType_t field_;
490 #define SST_ELI_DECLARE_STATISTIC_TEMPLATE(cls, lib, name, version, desc, interface) \
491 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
492 SST_ELI_INTERFACE_INFO(interface)
494 #define SST_ELI_REGISTER_CUSTOM_STATISTIC(cls, lib, name, version, desc) \
495 SST_ELI_REGISTER_DERIVED(SST::Statistics::CustomStatistic,cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
496 SST_ELI_INTERFACE_INFO("CustomStatistic")
498 #define SST_ELI_DECLARE_STATISTIC(cls, field, lib, name, version, desc, interface) \
499 static bool ELI_isLoaded() \
501 return SST::Statistics::Statistic<field>::template addDerivedInfo<cls>(lib, name) && \
502 SST::Statistics::Statistic<field>::template addDerivedBuilder<cls>(lib, name) && \
503 SST::Statistics::Statistic<field>::template addDerivedInfo<SST::Statistics::NullStatistic<field>>( \
505 SST::Statistics::Statistic<field>::template addDerivedBuilder<SST::Statistics::NullStatistic<field>>( \
508 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
509 SST_ELI_INTERFACE_INFO(interface) \
510 static const char* ELI_fieldName() { return #field; } \
511 static const char* ELI_fieldShortName() { return #field; }
513 #ifdef __INTEL_COMPILER
514 #define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
515 bool force_instantiate_##cls##_##field = \
516 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
517 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
518 SST::ELI::InstantiateBuilderInfo< \
519 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded() && \
520 SST::ELI::InstantiateBuilder< \
521 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded();
523 #define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
524 struct cls##_##field##_##shortName : public cls<field> \
526 cls##_##field##_##shortName( \
527 SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
528 cls<field>(bc, sn, si, p) \
530 static bool ELI_isLoaded() \
532 return SST::ELI::InstantiateBuilderInfo< \
533 SST::Statistics::Statistic<field>, cls##_##field##_##shortName>::isLoaded() && \
534 SST::ELI::InstantiateBuilder< \
535 SST::Statistics::Statistic<field>, cls##_##field##_##shortName>::isLoaded() && \
536 SST::ELI::InstantiateBuilderInfo< \
537 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded() && \
538 SST::ELI::InstantiateBuilder< \
539 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded(); \
544 #define PP_NARG(...) PP_NARG_(__VA_ARGS__, PP_NSEQ())
545 #define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
546 #define PP_ARG_N(_1, _2, _3, _4, _5, N, ...) N
547 #define PP_NSEQ() 5, 4, 3, 2, 1, 0
549 #define PP_GLUE(X, Y) PP_GLUE_I(X, Y)
550 #define PP_GLUE_I(X, Y) X##Y
552 #define STAT_NAME1(base, a) base##a
553 #define STAT_NAME2(base, a, b) base##a##b
554 #define STAT_NAME3(base, a, b, c) base##a##b##c
555 #define STAT_NAME4(base, a, b, c, d) base##a##b##c##d
557 #define STAT_GLUE_NAME(base, ...) PP_GLUE(STAT_NAME, PP_NARG(__VA_ARGS__))(base, __VA_ARGS__)
558 #define STAT_TUPLE(...) std::tuple<__VA_ARGS__>
560 #ifdef __INTEL_COMPILER
561 #define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
562 bool force_instantiate_stat_name = \
563 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
564 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
565 SST::ELI::InstantiateBuilderInfo< \
566 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
567 SST::ELI::InstantiateBuilder< \
568 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
573 #define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
574 struct name : public cls<__VA_ARGS__> \
576 name(SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
577 cls<__VA_ARGS__>(bc, sn, si, p) \
579 bool ELI_isLoaded() const \
581 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
582 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
583 SST::ELI::InstantiateBuilderInfo< \
584 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
585 SST::ELI::InstantiateBuilder< \
586 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
591 #define SST_ELI_INSTANTIATE_MULTI_STATISTIC(cls, ...) \
592 MAKE_MULTI_STATISTIC(cls, STAT_GLUE_NAME(cls, __VA_ARGS__), STAT_TUPLE(__VA_ARGS__), __VA_ARGS__)
598 #include "sst/core/statapi/statnull.h"
600 #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:34
void setFlagOutputAtEndOfSim(bool flag)
Set the Output At End Of Sim flag.
Definition: statbase.h:109
virtual void setCollectionCountLimit(uint64_t newLimit)
Set the collection count limit to a defined value.
Definition: statbase.cc:94
void delayCollection(const char *delayTime)
Delay the statistic from collecting data for a specified delay time.
Definition: statbase.cc:174
void setFlagClearDataOnOutput(bool flag)
Set the Clear Data On Output flag.
Definition: statbase.h:104
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:49
Forms the base class for statistics gathering within SST.
Definition: statbase.h:63
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:315
void setStatisticTypeName(const char *typeName)
Set an optional Statistic Type Name.
Definition: statbase.h:213
uint64_t getCollectionCount() const
Return the current collection count.
Definition: statbase.h:155
void enable()
Enable Statistic for collections.
Definition: statbase.h:71
SSTHandlerBaseNoArgs< void, false > HandlerBase
Base handler for OneShot callbacks.
Definition: oneshot.h:38
void delayOutput(const char *delayTime)
Delay the statistic from outputting data for a specified delay time.
Definition: statbase.cc:159
StatMode_t getRegisteredCollectionMode() const
Return the collection mode that is registered.
Definition: statbase.h:167
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:42
Statistic(BaseComponent *comp, const std::string &statName, const std::string &statSubId, Params &statParams)
Construct a Statistic.
Definition: statbase.h:450
Definition: serializable.h:118
virtual bool isNullStatistic() const
Indicate if the Statistic is a NullStatistic.
Definition: statbase.h:185
const std::string & getCompName() const
Return the Component Name.
Definition: statbase.cc:52
virtual void resetCollectionCount()
Set the current collection count to 0.
Definition: statbase.cc:88
const StatisticFieldInfo::fieldType_t & getStatDataType() const
Return the Statistic data type.
Definition: statbase.h:128
Base type that creates the virtual addData(...) interface Used for distinguishing fundamental types (...
Definition: statbase.h:301
Statistic(BaseComponent *comp, const std::string &statName, const std::string &statSubId, Params &statParams)
Construct a Statistic.
Definition: statbase.h:409
void addData(InArgs &&...args)
Add data to the Statistic This will call the addData_impl() routine in the derived Statistic...
Definition: statbase.h:375
Definition: paramsInfo.h:40
bool getFlagOutputAtEndOfSim() const
Return the OutputAtEndOfSim flag value.
Definition: statbase.h:164
bool getFlagClearDataOnOutput() const
Return the ClearDataOnOutput flag value.
Definition: statbase.h:161
virtual void incrementCollectionCount(uint64_t increment)
Increment current collection count.
Definition: statbase.cc:74
bool isEnabled() const
Return the enable status of the Statistic.
Definition: statbase.h:146
Definition: statoutput.h:142
virtual bool isReady() const
Indicate that the Statistic is Ready to be used.
Definition: statbase.h:182
Main component object for the simulation.
Definition: baseComponent.h:51
void disable()
Disable Statistic for collections.
Definition: statbase.h:74
bool isOutputEnabled() const
Return the enable status of the Statistic's ability to output data.
Definition: statbase.h:149
Definition: statbase.h:465
StatMode_t
Statistic collection mode.
Definition: statbase.h:67
virtual void clearStatisticData()
Inform the Statistic to clear its data.
Definition: statbase.h:78
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:334
void setFlagResetCountOnOutput(bool flag)
Set the Reset Count On Output flag.
Definition: statbase.h:96
Parameter store.
Definition: params.h:43
bool getFlagResetCountOnOutput() const
Return the ResetCountOnOutput flag value.
Definition: statbase.h:158
const std::string & getStatSubId() const
Return the Statistic SubId.
Definition: statbase.h:119
Definition: statbase.h:35
const char * getStatDataTypeFullName() const
Return the Statistic data type.
Definition: statbase.h:137
Class for instantiating Components, Links and the like out of element libraries.
Definition: factory.h:42
const std::string & getFullStatName() const
Return the full Statistic name of Component.StatName.SubId.
Definition: statbase.h:122
virtual void setCollectionCount(uint64_t newCount)
Set the current collection count to a defined value.
Definition: statbase.cc:81
const char * getStatDataTypeShortName() const
Return the Statistic data type.
Definition: statbase.h:131
void setStatisticDataType(const StatisticFieldInfo::fieldType_t dataType)
Set the Statistic Data Type.
Definition: statbase.h:210
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:51
Definition: statgroup.h:27
Params & getParams()
Return the Statistic Parameters.
Definition: statbase.h:207
uint64_t getCollectionCountLimit() const
Return the collection count limit.
Definition: statbase.h:152
BaseComponent * getComponent() const
Return a pointer to the parent Component.
Definition: statbase.h:143
const std::string & getStatTypeName() const
Return the Statistic type name.
Definition: statbase.h:125
const std::string & getStatName() const
Return the Statistic Name.
Definition: statbase.h:116
Definition: interfaceInfo.h:18
StatisticBase(BaseComponent *comp, const std::string &statName, const std::string &statSubId, Params &statParams)
Construct a StatisticBase.
Definition: statbase.cc:30