12 #ifndef _H_SST_CORE_STATISTICS_BASE
13 #define _H_SST_CORE_STATISTICS_BASE
17 #include <sst/core/sst_types.h>
18 #include <sst/core/warnmacros.h>
19 #include <sst/core/params.h>
20 #include <sst/core/oneshot.h>
21 #include <sst/core/statapi/statfieldinfo.h>
22 #include <sst/core/eli/elementinfo.h>
23 #include <sst/core/serialization/serializable.h>
29 namespace Statistics {
30 class StatisticOutput;
31 class StatisticProcessingEngine;
41 StatisticInfo(
const std::string &name,
const Params ¶ms) : name(name), params(params) { }
67 typedef enum {STAT_MODE_UNDEFINED, STAT_MODE_COUNT, STAT_MODE_PERIODIC}
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;}
195 const std::string& statSubId,
Params& statParams);
213 void setRegisteredCollectionMode(
StatMode_t mode) {m_registeredCollectionMode = mode;}
216 static std::string buildStatisticFullName(
const char* compName,
const char* statName,
const char* statSubId);
217 static std::string buildStatisticFullName(
const std::string& compName,
const std::string& statName,
const std::string& statSubId);
224 virtual void registerOutputFields(StatisticOutput* statOutput) = 0;
231 virtual void outputStatisticData(StatisticOutput* statOutput,
bool EndOfSimFlag) = 0;
238 virtual bool isStatModeSupported(
StatMode_t UNUSED(mode))
const {
return true;}
241 bool operator==(StatisticBase& checkStat);
244 void initializeStatName(
const char* compName,
const char* statName,
const char* statSubId);
245 void initializeStatName(
const std::string& compName,
const std::string& statName,
const std::string& statSubId);
247 void initializeProperties();
248 void checkEventForOutput();
251 void delayOutputExpiredHandler();
252 void delayCollectionExpiredHandler();
254 const StatisticGroup* getGroup()
const {
return m_group; }
255 void setGroup(
const StatisticGroup *group ) { m_group = group; }
261 BaseComponent* m_component;
262 std::string m_statName;
263 std::string m_statSubId;
264 std::string m_statFullName;
265 std::string m_statTypeName;
268 uint64_t m_currentCollectionCount;
269 uint64_t m_collectionCountLimit;
270 StatisticFieldInfo::fieldType_t m_statDataType;
273 bool m_outputEnabled;
274 bool m_resetCountOnOutput;
275 bool m_clearDataOnOutput;
276 bool m_outputAtEndOfSim;
278 bool m_outputDelayed;
279 bool m_collectionDelayed;
280 bool m_savedStatEnabled;
281 bool m_savedOutputEnabled;
282 OneShot::HandlerBase* m_outputDelayedHandler;
283 OneShot::HandlerBase* m_collectionDelayedHandler;
284 const StatisticGroup* m_group;
294 template <class T, bool F=std::is_fundamental<T>::value>
299 virtual void addData_impl(T data) = 0;
302 template <
class... Args>
304 virtual void addData_impl(Args... args) = 0;
306 template <
class... InArgs>
307 void addData(InArgs&&... args){
308 addData_impl(std::make_tuple(std::forward<InArgs>(args)...));
322 template <
typename T>
327 SST_ELI_DECLARE_INFO(
328 ELI::ProvidesInterface,
338 template <class... InArgs>
344 addData_impl(std::forward<InArgs>(args)...);
351 static fieldType_t fieldId() {
367 const std::string& statSubId,
Params& statParams) :
381 template <
class... Args>
382 using MultiStatistic = Statistic<std::tuple<Args...>>;
387 std::string toString()
const;
389 Statistics::fieldType_t fieldId()
const {
393 const char* fieldName()
const {
397 const char* fieldShortName()
const {
403 field_name_(T::ELI_fieldName()),
404 short_name_(T::ELI_fieldShortName()),
405 field_(T::ELI_registerField(T::ELI_fieldName(), T::ELI_fieldShortName()))
410 const char* field_name_;
411 const char* short_name_;
412 Statistics::fieldType_t field_;
416 #define SST_ELI_DECLARE_STATISTIC_TEMPLATE(cls,lib,name,version,desc,interface) \
417 SST_ELI_DEFAULT_INFO(lib,name,ELI_FORWARD_AS_ONE(version),desc) \
418 SST_ELI_INTERFACE_INFO(interface)
420 #define SST_ELI_REGISTER_CUSTOM_STATISTIC(parent,cls,lib,name,version,desc) \
421 bool ELI_isLoaded() const { \
422 return SST::ELI::InstantiateBuilderInfo<parent,cls>::isLoaded() \
423 && SST::ELI::InstantiateBuilder<parent,cls>::isLoaded(); \
425 SST_ELI_DEFAULT_INFO(lib,name,ELI_FORWARD_AS_ONE(version),desc) \
426 SST_ELI_INTERFACE_INFO(#parent) \
427 static const char* ELI_fieldName(){ return #parent "Data"; } \
428 static const char* ELI_fieldShortName(){ return #parent "Data"; }
430 #define SST_ELI_DECLARE_STATISTIC(cls,field,lib,name,version,desc,interface) \
431 static bool ELI_isLoaded() { \
432 return SST::Statistics::Statistic<field>::template addDerivedInfo<cls>(lib,name) \
433 && SST::Statistics::Statistic<field>::template addDerivedBuilder<cls>(lib,name) \
434 && SST::Statistics::Statistic<field>::template addDerivedInfo<SST::Statistics::NullStatistic<field>>(lib,name) \
435 && SST::Statistics::Statistic<field>::template addDerivedBuilder<SST::Statistics::NullStatistic<field>>(lib,name); \
437 SST_ELI_DEFAULT_INFO(lib,name,ELI_FORWARD_AS_ONE(version),desc) \
438 SST_ELI_INTERFACE_INFO(interface) \
439 static const char* ELI_fieldName(){ return #field; } \
440 static const char* ELI_fieldShortName(){ return #field; }
443 #define SST_ELI_INSTANTIATE_STATISTIC(cls,field) \
444 struct cls##_##field##_##shortName : public cls<field> { \
445 cls##_##field##_##shortName(SST::BaseComponent* bc, const std::string& sn, \
446 const std::string& si, SST::Params& p) : \
447 cls<field>(bc,sn,si,p) {} \
448 static bool ELI_isLoaded() { \
449 return SST::ELI::InstantiateBuilderInfo< \
450 SST::Statistics::Statistic<field>,cls##_##field##_##shortName>::isLoaded() \
451 && SST::ELI::InstantiateBuilder< \
452 SST::Statistics::Statistic<field>,cls##_##field##_##shortName>::isLoaded() \
453 && SST::ELI::InstantiateBuilderInfo< \
454 SST::Statistics::Statistic<field>, \
455 SST::Statistics::NullStatistic<field>>::isLoaded() \
456 && SST::ELI::InstantiateBuilder< \
457 SST::Statistics::Statistic<field>, \
458 SST::Statistics::NullStatistic<field>>::isLoaded(); \
463 #define PP_NARG(...) PP_NARG_(__VA_ARGS__, PP_NSEQ())
464 #define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
465 #define PP_ARG_N(_1,_2,_3,_4,_5,N,...) N
466 #define PP_NSEQ() 5,4,3,2,1,0
468 #define PP_GLUE(X,Y) PP_GLUE_I(X,Y)
469 #define PP_GLUE_I(X,Y) X##Y
471 #define STAT_NAME1(base,a) base##a
472 #define STAT_NAME2(base,a,b) base##a##b
473 #define STAT_NAME3(base,a,b,c) base##a##b##c
474 #define STAT_NAME4(base,a,b,c,d) base##a##b##c##d
476 #define STAT_GLUE_NAME(base,...) PP_GLUE(STAT_NAME,PP_NARG(__VA_ARGS__))(base,__VA_ARGS__)
477 #define STAT_TUPLE(...) std::tuple<__VA_ARGS__>
479 #define MAKE_MULTI_STATISTIC(cls,name,tuple,...) \
480 struct name : public cls<__VA_ARGS__> { \
481 name(SST::BaseComponent* bc, const std::string& sn, \
482 const std::string& si, SST::Params& p) : \
483 cls<__VA_ARGS__>(bc,sn,si,p) {} \
484 bool ELI_isLoaded() const { \
485 return SST::ELI::InstantiateBuilderInfo< \
486 SST::Statistics::Statistic<tuple>,name>::isLoaded() \
487 && SST::ELI::InstantiateBuilder< \
488 SST::Statistics::Statistic<tuple>,name>::isLoaded() \
489 && SST::ELI::InstantiateBuilderInfo< \
490 SST::Statistics::Statistic<tuple>, \
491 SST::Statistics::NullStatistic<tuple>>::isLoaded() \
492 && SST::ELI::InstantiateBuilder< \
493 SST::Statistics::Statistic<tuple>, \
494 SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
498 #define SST_ELI_INSTANTIATE_MULTI_STATISTIC(cls,...) \
499 MAKE_MULTI_STATISTIC(cls,STAT_GLUE_NAME(cls,__VA_ARGS__),STAT_TUPLE(__VA_ARGS__),__VA_ARGS__)
507 #include <sst/core/statapi/statnull.h>
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
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:72
void delayCollection(const char *delayTime)
Delay the statistic from collecting data for a specified delay time.
Definition: statbase.cc:144
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:48
Forms the base class for statistics gathering within SST.
Definition: statbase.h:63
void setStatisticTypeName(const char *typeName)
Set an optional Statistic Type Name.
Definition: statbase.h:207
uint64_t getCollectionCount() const
Return the current collection count.
Definition: statbase.h:149
void enable()
Enable Statistic for collections.
Definition: statbase.h:71
void delayOutput(const char *delayTime)
Delay the statistic from outputting data for a specified delay time.
Definition: statbase.cc:130
StatMode_t getRegisteredCollectionMode() const
Return the collection mode that is registered.
Definition: statbase.h:161
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:43
Definition: serializable.h:110
virtual bool isNullStatistic() const
Indicate if the Statistic is a NullStatistic.
Definition: statbase.h:179
const std::string & getCompName() const
Return the Component Name.
Definition: statbase.cc:50
virtual void incrementCollectionCount()
Increment current collection count.
Definition: statbase.cc:55
virtual void resetCollectionCount()
Set the current collection count to 0.
Definition: statbase.cc:67
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:295
Statistic(BaseComponent *comp, const std::string &statName, const std::string &statSubId, Params &statParams)
Construct a Statistic.
Definition: statbase.h:366
void addData(InArgs &&...args)
Add data to the Statistic This will call the addData_impl() routine in the derived Statistic...
Definition: statbase.h:339
bool getFlagOutputAtEndOfSim() const
Return the OutputAtEndOfSim flag value.
Definition: statbase.h:158
bool getFlagClearDataOnOutput() const
Return the ClearDataOnOutput flag value.
Definition: statbase.h:155
bool isEnabled() const
Return the enable status of the Statistic.
Definition: statbase.h:140
virtual bool isReady() const
Indicate that the Statistic is Ready to be used.
Definition: statbase.h:176
Main component object for the simulation.
Definition: baseComponent.h:52
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:143
Definition: statbase.h:385
StatMode_t
Statistic collection mode.
Definition: statbase.h:67
virtual void clearStatisticData()
Inform the Statistic to clear its data.
Definition: statbase.h:78
void setFlagResetCountOnOutput(bool flag)
Set the Reset Count On Output flag.
Definition: statbase.h:96
Parameter store.
Definition: params.h:45
bool getFlagResetCountOnOutput() const
Return the ResetCountOnOutput flag value.
Definition: statbase.h:152
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:134
Class for instantiating Components, Links and the like out of element libraries.
Definition: factory.h:43
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:61
const char * getStatDataTypeShortName() const
Return the Statistic data type.
Definition: statbase.h:131
Definition: statfieldinfo.h:51
void setStatisticDataType(const StatisticFieldInfo::fieldType_t dataType)
Set the Statistic Data Type.
Definition: statbase.h:204
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.
Definition: statbase.h:201
uint64_t getCollectionCountLimit() const
Return the collection count limit.
Definition: statbase.h:146
BaseComponent * getComponent() const
Return a pointer to the parent Component.
Definition: statbase.h:137
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
StatisticBase(BaseComponent *comp, const std::string &statName, const std::string &statSubId, Params &statParams)
Construct a StatisticBase.
Definition: statbase.cc:28