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"
31class StatisticFieldsOutput;
32class 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_outputCollectionCount;
277 uint64_t m_collectionCountLimit;
278 StatisticFieldInfo::fieldType_t m_statDataType;
281 bool m_outputEnabled;
282 bool m_resetCountOnOutput;
283 bool m_clearDataOnOutput;
284 bool m_outputAtEndOfSim;
286 bool m_outputDelayed;
287 bool m_collectionDelayed;
288 bool m_savedStatEnabled;
289 bool m_savedOutputEnabled;
292 const StatisticGroup* m_group;
301template <class T, bool F = std::is_fundamental<T>::value>
308 virtual void addData_impl(T data) = 0;
318 for ( uint64_t i = 0; i < N; ++i ) {
324template <
class... Args>
327 virtual void addData_impl(Args... args) = 0;
337 for ( uint64_t i = 0; i < N; ++i ) {
338 addData_impl(args...);
342 template <
class... InArgs>
343 void addData(InArgs&&... args)
345 addData_impl(std::make_tuple(std::forward<InArgs>(args)...));
364 SST_ELI_DECLARE_INFO(
375 template <
class... InArgs>
381 addData_impl(std::forward<InArgs>(args)...);
386 template <
class... InArgs>
387 void addDataNTimes(uint64_t N, InArgs&&... args)
392 addData_impl_Ntimes(N, std::forward<InArgs>(args)...);
397 static fieldType_t fieldId() {
return StatisticFieldType<T>::id(); }
431 SST_ELI_DECLARE_INFO(
461using CustomStatistic = Statistic<void>;
463template <
class... Args>
464using MultiStatistic = Statistic<std::tuple<Args...>>;
469 std::string toString()
const;
471 Statistics::fieldType_t fieldId()
const {
return field_; }
473 const char* fieldName()
const {
return field_name_; }
475 const char* fieldShortName()
const {
return short_name_; }
480 field_name_(T::ELI_fieldName()),
481 short_name_(T::ELI_fieldShortName()),
482 field_(T::ELI_registerField(T::ELI_fieldName(), T::ELI_fieldShortName()))
486 const char* field_name_;
487 const char* short_name_;
488 Statistics::fieldType_t field_;
491#define SST_ELI_DECLARE_STATISTIC_TEMPLATE(cls, lib, name, version, desc, interface) \
492 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
493 SST_ELI_INTERFACE_INFO(interface)
495#define SST_ELI_REGISTER_CUSTOM_STATISTIC(cls, lib, name, version, desc) \
496 SST_ELI_REGISTER_DERIVED(SST::Statistics::CustomStatistic,cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
497 SST_ELI_INTERFACE_INFO("CustomStatistic")
499#define SST_ELI_DECLARE_STATISTIC(cls, field, lib, name, version, desc, interface) \
500 static bool ELI_isLoaded() \
502 return SST::Statistics::Statistic<field>::template addDerivedInfo<cls>(lib, name) && \
503 SST::Statistics::Statistic<field>::template addDerivedBuilder<cls>(lib, name) && \
504 SST::Statistics::Statistic<field>::template addDerivedInfo<SST::Statistics::NullStatistic<field>>( \
506 SST::Statistics::Statistic<field>::template addDerivedBuilder<SST::Statistics::NullStatistic<field>>( \
509 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
510 SST_ELI_INTERFACE_INFO(interface) \
511 static const char* ELI_fieldName() { return #field; } \
512 static const char* ELI_fieldShortName() { return #field; }
514#ifdef __INTEL_COMPILER
515#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
516 bool force_instantiate_##cls##_##field = \
517 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
518 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
519 SST::ELI::InstantiateBuilderInfo< \
520 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded() && \
521 SST::ELI::InstantiateBuilder< \
522 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded();
524#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
525 struct cls##_##field##_##shortName : public cls<field> \
527 cls##_##field##_##shortName( \
528 SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
529 cls<field>(bc, sn, si, p) \
531 static bool ELI_isLoaded() \
533 return SST::ELI::InstantiateBuilderInfo< \
534 SST::Statistics::Statistic<field>, cls##_##field##_##shortName>::isLoaded() && \
535 SST::ELI::InstantiateBuilder< \
536 SST::Statistics::Statistic<field>, cls##_##field##_##shortName>::isLoaded() && \
537 SST::ELI::InstantiateBuilderInfo< \
538 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded() && \
539 SST::ELI::InstantiateBuilder< \
540 SST::Statistics::Statistic<field>, SST::Statistics::NullStatistic<field>>::isLoaded(); \
545#define PP_NARG(...) PP_NARG_(__VA_ARGS__, PP_NSEQ())
546#define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
547#define PP_ARG_N(_1, _2, _3, _4, _5, N, ...) N
548#define PP_NSEQ() 5, 4, 3, 2, 1, 0
550#define PP_GLUE(X, Y) PP_GLUE_I(X, Y)
551#define PP_GLUE_I(X, Y) X##Y
553#define STAT_NAME1(base, a) base##a
554#define STAT_NAME2(base, a, b) base##a##b
555#define STAT_NAME3(base, a, b, c) base##a##b##c
556#define STAT_NAME4(base, a, b, c, d) base##a##b##c##d
558#define STAT_GLUE_NAME(base, ...) PP_GLUE(STAT_NAME, PP_NARG(__VA_ARGS__))(base, __VA_ARGS__)
559#define STAT_TUPLE(...) std::tuple<__VA_ARGS__>
561#ifdef __INTEL_COMPILER
562#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
563 bool force_instantiate_stat_name = \
564 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
565 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
566 SST::ELI::InstantiateBuilderInfo< \
567 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
568 SST::ELI::InstantiateBuilder< \
569 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
574#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
575 struct name : public cls<__VA_ARGS__> \
577 name(SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
578 cls<__VA_ARGS__>(bc, sn, si, p) \
580 bool ELI_isLoaded() const \
582 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
583 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
584 SST::ELI::InstantiateBuilderInfo< \
585 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
586 SST::ELI::InstantiateBuilder< \
587 SST::Statistics::Statistic<tuple>, SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
592#define SST_ELI_INSTANTIATE_MULTI_STATISTIC(cls, ...) \
593 MAKE_MULTI_STATISTIC(cls, STAT_GLUE_NAME(cls, __VA_ARGS__), STAT_TUPLE(__VA_ARGS__), __VA_ARGS__)
599#include "sst/core/statapi/statnull.h"
Main component object for the simulation.
Definition: baseComponent.h:51
Definition: serializable.h:119
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
Definition: interfaceInfo.h:19
Definition: paramsInfo.h:41
Class for instantiating Components, Links and the like out of element libraries.
Definition: factory.h:43
SSTHandlerBaseNoArgs< void > HandlerBase
Base handler for OneShot callbacks.
Definition: oneshot.h:38
Parameter store.
Definition: params.h:56
Forms the base class for statistics gathering within SST.
Definition: statbase.h:64
virtual void setCollectionCount(uint64_t newCount)
Set the current collection count to a defined value.
Definition: statbase.cc:80
const std::string & getCompName() const
Return the Component Name.
Definition: statbase.cc:50
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:175
BaseComponent * getComponent() const
Return a pointer to the parent Component.
Definition: statbase.h:143
StatisticBase(BaseComponent *comp, const std::string &statName, const std::string &statSubId, Params &statParams)
Construct a StatisticBase.
Definition: statbase.cc:29
virtual void resetCollectionCount()
Set the current collection count to 0.
Definition: statbase.cc:88
void enable()
Enable Statistic for collections.
Definition: statbase.h:71
const std::string & getStatTypeName() const
Return the Statistic type name.
Definition: statbase.h:125
void setFlagOutputAtEndOfSim(bool flag)
Set the Output At End Of Sim flag.
Definition: statbase.h:109
void setFlagClearDataOnOutput(bool flag)
Set the Clear Data On Output flag.
Definition: statbase.h:104
const std::string & getStatName() const
Return the Statistic Name.
Definition: statbase.h:116
virtual bool isReady() const
Indicate that the Statistic is Ready to be used.
Definition: statbase.h:182
StatMode_t getRegisteredCollectionMode() const
Return the collection mode that is registered.
Definition: statbase.h:167
bool getFlagOutputAtEndOfSim() const
Return the OutputAtEndOfSim flag value.
Definition: statbase.h:164
StatMode_t
Statistic collection mode.
Definition: statbase.h:67
const StatisticFieldInfo::fieldType_t & getStatDataType() const
Return the Statistic data type.
Definition: statbase.h:128
void delayOutput(const char *delayTime)
Delay the statistic from outputting data for a specified delay time.
Definition: statbase.cc:160
void setStatisticTypeName(const char *typeName)
Set an optional Statistic Type Name.
Definition: statbase.h:213
void setFlagResetCountOnOutput(bool flag)
Set the Reset Count On Output flag.
Definition: statbase.h:96
bool getFlagClearDataOnOutput() const
Return the ClearDataOnOutput flag value.
Definition: statbase.h:161
uint64_t getCollectionCountLimit() const
Return the collection count limit.
Definition: statbase.h:152
void setStatisticDataType(const StatisticFieldInfo::fieldType_t dataType)
Set the Statistic Data Type.
Definition: statbase.h:210
const std::string & getStatSubId() const
Return the Statistic SubId.
Definition: statbase.h:119
virtual bool isNullStatistic() const
Indicate if the Statistic is a NullStatistic.
Definition: statbase.h:185
virtual void clearStatisticData()
Inform the Statistic to clear its data.
Definition: statbase.h:78
Params & getParams()
Return the Statistic Parameters.
Definition: statbase.h:207
const char * getStatDataTypeShortName() const
Return the Statistic data type.
Definition: statbase.h:131
uint64_t getCollectionCount() const
Return the current collection count.
Definition: statbase.h:155
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
const std::string & getFullStatName() const
Return the full Statistic name of Component.StatName.SubId.
Definition: statbase.h:122
const char * getStatDataTypeFullName() const
Return the Statistic data type.
Definition: statbase.h:137
bool isEnabled() const
Return the enable status of the Statistic.
Definition: statbase.h:146
virtual void incrementCollectionCount(uint64_t increment)
Increment current collection count.
Definition: statbase.cc:72
bool getFlagResetCountOnOutput() const
Return the ResetCountOnOutput flag value.
Definition: statbase.h:158
Definition: statoutput.h:143
Definition: statgroup.h:28
Definition: statbase.h:36
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:50
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:52
Statistic(BaseComponent *comp, const std::string &statName, const std::string &statSubId, Params &statParams)
Construct a Statistic.
Definition: statbase.h:451
Forms the template defined base class for statistics gathering within SST.
Definition: statbase.h:361
Statistic(BaseComponent *comp, const std::string &statName, const std::string &statSubId, Params &statParams)
Construct a Statistic.
Definition: statbase.h:410
void addData(InArgs &&... args)
Add data to the Statistic This will call the addData_impl() routine in the derived Statistic.
Definition: statbase.h:376
Definition: statbase.h:467
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:316
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:335
Base type that creates the virtual addData(...) interface Used for distinguishing fundamental types (...
Definition: statbase.h:303