SST 15.0
Structural Simulation Toolkit
statbase.h
1// Copyright 2009-2025 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2025, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_STATAPI_STATBASE_H
13#define SST_CORE_STATAPI_STATBASE_H
14
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/unitAlgebra.h"
23#include "sst/core/warnmacros.h"
24
25#include <string>
26#include <tuple>
27#include <vector>
28
29namespace SST {
30class BaseComponent;
31class Factory;
32
33namespace Statistics {
34class StatisticOutput;
37class StatisticGroup;
38
39/**
40 \class StatisticBase
41
42 Forms the base class for statistics gathering within SST. Statistics are
43 gathered and processed into various (extensible) output forms. Statistics
44 are expected to be named so that they can be located in the simulation
45 output files.
46*/
47
49{
50public:
51 /** Statistic collection mode
52 * STAT_MODE_UNDEFINED - unknown mode
53 * STAT_MODE_COUNT - generating statistic output when the statistic has been added to a certain number of times
54 * STAT_MODE_PERIODIC - generating statistic output on a periodic time basis
55 * STAT_MODE_DUMP_AT_END - generating statistic output only at end of simulation
56 */
57 enum StatMode_t { STAT_MODE_UNDEFINED, STAT_MODE_COUNT, STAT_MODE_PERIODIC, STAT_MODE_DUMP_AT_END };
58
59 // Enable/Disable of Statistic
60 /** Enable Statistic for collections */
61 void enable() { info_->stat_enabled_ = true; }
62
63 /** Disable Statistic for collections */
64 void disable() { info_->stat_enabled_ = false; }
65
66 // Handling of Collection Counts and Data
67 /** Inform the Statistic to clear its data */
68 virtual void clearStatisticData() {}
69
70 /** Set the current collection count to 0 */
71 virtual void resetCollectionCount();
72
73 /** Increment current collection count */
74 virtual void incrementCollectionCount(uint64_t increment);
75
76 /** Set the current collection count to a defined value */
77 virtual void setCollectionCount(uint64_t new_count);
78
79 /** Set the collection count limit to a defined value */
80 virtual void setCollectionCountLimit(uint64_t new_limit);
81
82 // Control Statistic Operation Flags
83 /** Set the Reset Count On Output flag.
84 * If Set, the collection count will be reset when statistic is output.
85 */
86 void setFlagResetCountOnOutput(bool flag) { info_->reset_count_on_output_ = flag; }
87
88 static const std::vector<ElementInfoParam>& ELI_getParams();
89
90 /** Set the Clear Data On Output flag.
91 * If Set, the data in the statistic will be cleared by calling
92 * clearStatisticData().
93 */
94 void setFlagClearDataOnOutput(bool flag) { info_->clear_data_on_output_ = flag; }
95
96 /** Set the Output At End Of Sim flag.
97 * If Set, the statistic will perform an output at the end of simulation.
98 */
99 void setFlagOutputAtEndOfSim(bool flag) { info_->output_at_end_of_sim_ = flag; }
100
101 // Get Data & Information on Statistic
102 /** Return the Component Name */
103 const std::string& getCompName() const;
104
105 /** Return the Statistic Name */
106 inline const std::string& getStatName() const { return info_->stat_name_; }
107
108 /** Return the Statistic SubId */
109 inline const std::string& getStatSubId() const { return info_->stat_sub_id_; }
110
111 /** Return the full Statistic name of component.stat_name.sub_id */
112 inline const std::string& getFullStatName() const
113 {
114 return info_->stat_full_name_;
115 } // Return comp_name.stat_name.sub_id
116
117 /** Return the ELI type of the statistic
118 * The ELI registration macro creates this function automatically for child classes.
119 */
120 virtual std::string getELIName() const = 0;
121
122 /** Return the Statistic type name */
123 virtual const std::string& getStatTypeName() const { return info_->stat_type_name_; }
124
125 /** Return the Statistic data type */
126 inline const StatisticFieldInfo::fieldType_t& getStatDataType() const { return stat_data_type_; }
127
128 /** Return the Statistic data type */
129 inline const char* getStatDataTypeShortName() const
130 {
131 return StatisticFieldInfo::getFieldTypeShortName(stat_data_type_);
132 }
133
134 /** Return the Statistic data type */
135 inline const char* getStatDataTypeFullName() const
136 {
137 return StatisticFieldInfo::getFieldTypeFullName(stat_data_type_);
138 }
139
140 /** Return a pointer to the parent Component */
141 BaseComponent* getComponent() const { return component_; }
142
143 /** Return the enable status of the Statistic */
144 bool isEnabled() const { return info_->stat_enabled_; }
145
146 /** Return the enable status of the Statistic's ability to output data */
147 bool isOutputEnabled() const { return info_->output_enabled_; }
148
149 /** Return the rate at which the statistic should be output */
150 UnitAlgebra& getCollectionRate() const { return info_->collection_rate_; }
151
152 /** Return the time at which the statistic should be enabled */
153 UnitAlgebra& getStartAtTime() const { return info_->start_at_time_; }
154
155 /** Return the time at which the statistic should be disabled */
156 UnitAlgebra& getStopAtTime() const { return info_->stop_at_time_; }
157
158 /** Return the collection count limit */
159 uint64_t getCollectionCountLimit() const { return info_->collection_count_limit_; }
160
161 /** Return the current collection count */
162 uint64_t getCollectionCount() const { return info_->current_collection_count_; }
163
164 /** Return the ResetCountOnOutput flag value */
165 bool getFlagResetCountOnOutput() const { return info_->reset_count_on_output_; }
166
167 /** Return the ClearDataOnOutput flag value */
168 bool getFlagClearDataOnOutput() const { return info_->clear_data_on_output_; }
169
170 /** Return the OutputAtEndOfSim flag value */
171 bool getFlagOutputAtEndOfSim() const { return info_->output_at_end_of_sim_; }
172
173 /** Return the collection mode that is registered */
174 StatMode_t getRegisteredCollectionMode() const { return info_->registered_collection_mode_; }
175
176 // Status of Statistic
177 /** Indicate that the Statistic is Ready to be used */
178 virtual bool isReady() const { return true; }
179
180 /** Indicate if the Statistic is a NullStatistic */
181 virtual bool isNullStatistic() const { return false; }
182
183 /** Serialization */
185
186protected:
191
192 /** Construct a StatisticBase
193 * @param comp - Pointer to the parent constructor.
194 * @param stat_name - Name of the statistic to be registered. This name must
195 * match the name in the ElementInfoStatistic.
196 * @param stat_sub_id - Additional name of the statistic
197 * @param stat_params - The parameters for this statistic
198 * @param null_stat - True if the statistic is null (not enabled). Defaults to False.
199 */
200 // Constructors:
201 StatisticBase(BaseComponent* comp, const std::string& stat_name, const std::string& stat_sub_id,
202 Params& stat_params, bool null_stat);
203
204 // Destructor
205 virtual ~StatisticBase() {}
206
207protected:
208 /** Set the Statistic Data Type */
209 void setStatisticDataType(const StatisticFieldInfo::fieldType_t data_type) { stat_data_type_ = data_type; }
210
211 /** Set an optional Statistic Type Name (for output) */
212 void setStatisticTypeName(const char* type_name) { info_->stat_type_name_ = type_name; }
213
214private:
215 friend class SST::BaseComponent;
216
217 /** Set the Registered Collection Mode */
218 void setRegisteredCollectionMode(StatMode_t mode) { info_->registered_collection_mode_ = mode; }
219
220 /** Construct a full name of the statistic */
221 static std::string buildStatisticFullName(const char* comp_name, const char* stat_name, const char* stat_sub_id);
222 static std::string buildStatisticFullName(
223 const std::string& comp_name, const std::string& stat_name, const std::string& stat_sub_id);
224
225 // Required Virtual Methods:
226 /** Called by the system to tell the Statistic to register its output fields.
227 * by calling statOutput->registerField(...)
228 * @param stat_output - Pointer to the statistic output
229 */
230 virtual void registerOutputFields(StatisticFieldsOutput* stat_output) = 0;
231
232 /** Called by the system to tell the Statistic to send its data to the
233 * StatisticOutput to be output.
234 * @param stat_output - Pointer to the statistic output
235 * @param end_of_sim_flag - Indicates that the output is occurring at the end of simulation.
236 */
237 virtual void outputStatisticFields(StatisticFieldsOutput* stat_output, bool end_of_sim_flag) = 0;
238
239 /** Indicate if the Statistic Mode is supported.
240 * This allows Statistics to support STAT_MODE_COUNT and STAT_MODE_PERIODIC modes.
241 * by default, both modes are supported.
242 * @param mode - Mode to test
243 */
244 virtual bool isStatModeSupported(StatMode_t UNUSED(mode)) const { return true; } // Default is to accept all modes
245
246 /** Verify that the statistic names match */
247 bool operator==(StatisticBase& check_stat);
248
249 void checkEventForOutput();
250
251 const StatisticGroup* getGroup() const { return info_->group_; }
252 void setGroup(const StatisticGroup* group) { info_->group_ = group; }
253
254protected:
255 StatisticBase(); // For serialization only
256
257private:
258 /* Class to hold information about a statistic
259 * This limits the size of StatisticBase for NullStatistic
260 */
261 class StatisticInfo
262 {
263 public:
264 StatisticInfo();
265
266 void serialize_order(SST::Core::Serialization::serializer& ser);
267
268 std::string stat_name_; // Name of stat, matches ELI
269 std::string stat_sub_id_; // Sub ID for this instance of the stat (default="")
270 std::string stat_type_name_; // DEPRECATED - override 'getStatTypeName()' instead
271
272 std::string stat_full_name_; // Fully-qualified name of the stat
273 bool stat_enabled_; // Whether stat is currently collecting data
274 StatMode_t registered_collection_mode_;
275 uint64_t current_collection_count_;
276 uint64_t output_collection_count_;
277 uint64_t collection_count_limit_;
278
279 const StatisticGroup* group_; // Group that stat belongs to
280
281 SST::UnitAlgebra start_at_time_;
282 SST::UnitAlgebra stop_at_time_;
283 SST::UnitAlgebra collection_rate_;
284
285 bool output_enabled_;
286 bool reset_count_on_output_;
287 bool clear_data_on_output_;
288 bool output_at_end_of_sim_;
289 bool output_delayed_;
290 bool collection_delayed_;
291 bool saved_stat_enabled_;
292 bool saved_output_enabled_;
293 };
294
295 BaseComponent* component_;
296 StatisticFieldInfo::fieldType_t stat_data_type_;
297
298 StatisticInfo* info_;
299
300 // Instance of StatisticInfo for null stats
301 static StatisticInfo null_info_;
302};
303
304/**
305 \class StatisticCollector
306 * Base type that creates the virtual addData(...) interface
307 * Used for distinguishing arithmetic types (collected by value)
308 * and composite struct types (collected by reference)
309 */
310template <class T, bool = std::is_arithmetic_v<T>>
312
313template <class T>
314struct StatisticCollector<T, true>
315{
316 virtual void addData_impl(T data) = 0;
317
318 /**
319 * @brief addData_impl_Ntimes Add the same data N times in a row
320 * By default, this just calls the addData function N times
321 * @param N The number of consecutive times
322 * @param args The arguments to pass in
323 */
324 virtual void addData_impl_Ntimes(uint64_t N, T data)
325 {
326 for ( uint64_t i = 0; i < N; ++i ) {
327 addData_impl(data);
328 }
329 }
330
331 virtual ~StatisticCollector() = default;
332};
333
334template <class... Args>
335struct StatisticCollector<std::tuple<Args...>, false>
336{
337 virtual void addData_impl(Args... args) = 0;
338
339 /**
340 * @brief addData_impl_Ntimes Add the same data N times in a row
341 * By default, this just calls the addData function N times
342 * @param N The number of consecutive times
343 * @param args The arguments to pass in
344 */
345 virtual void addData_impl_Ntimes(uint64_t N, Args... args)
346 {
347 for ( uint64_t i = 0; i < N; ++i ) {
348 addData_impl(args...);
349 }
350 }
351
352 template <class... InArgs>
353 void addData(InArgs&&... args)
354 {
355 addData_impl(std::make_tuple(std::forward<InArgs>(args)...));
356 }
357
358 virtual ~StatisticCollector() = default;
359};
360
361////////////////////////////////////////////////////////////////////////////////
362
363/**
364 \class Statistic
365
366 Forms the template defined base class for statistics gathering within SST.
367
368 @tparam T A template for the basic numerical data stored by this Statistic
369*/
370
371template <typename T>
373{
374public:
375 SST_ELI_DECLARE_BASE(Statistic)
376 SST_ELI_DECLARE_INFO(
379 SST_ELI_DECLARE_CTOR(BaseComponent*, const std::string&, const std::string&, SST::Params&)
380
381 SST_ELI_DOCUMENT_PARAMS(
382 {"rate", "Frequency at which to output statistic. Must include units. 0ns = output at end of simulation only.", "0ns" },
383 {"startat", "Time at which to enable data collection in this statistic. Must include units. 0ns = always enabled.", "0ns"},
384 {"stopat", "Time at which to disable data collection in this statistic. 0ns = always enabled.", "0ns"},
385 {"resetOnOutput", "Whether to reset the statistic's values after each output.", "False"}
386 )
387
388 using Datum = T;
389 using StatisticCollector<T>::addData_impl;
390 using StatisticCollector<T>::addData_impl_Ntimes;
391
392 // The main method to add data to the statistic
393 /** Add data to the Statistic
394 * This will call the addData_impl() routine in the derived Statistic.
395 */
396 template <class... InArgs> // use a universal reference here
397 void addData(InArgs&&... args)
398 {
399 // Call the Derived Statistic's implementation
400 // of addData and increment the count
401 if ( isEnabled() ) {
402 addData_impl(std::forward<InArgs>(args)...);
404 }
405 }
406
407 template <class... InArgs> // use a universal reference here
408 void addDataNTimes(uint64_t N, InArgs&&... args)
409 {
410 // Call the Derived Statistic's implementation
411 // of addData and increment the count
412 if ( isEnabled() ) {
413 addData_impl_Ntimes(N, std::forward<InArgs>(args)...);
415 }
416 }
417
418 static fieldType_t fieldId() { return StatisticFieldType<T>::id(); }
419
424
425protected:
426 friend class SST::Factory;
427 friend class SST::BaseComponent;
428 /** Construct a Statistic
429 * @param comp - Pointer to the parent constructor.
430 * @param stat_name - Name of the statistic to be registered. This name must
431 * match the name in the ElementInfoStatistic.
432 * @param stat_sub_id - Additional name of the statistic
433 * @param stat_params - The parameters for this statistic
434 * @param null_stat - True if the statistic is null (not enabled). Defaults to False.
435 */
436
437 Statistic(BaseComponent* comp, const std::string& stat_name, const std::string& stat_sub_id, Params& stat_params,
438 bool null_stat = false) :
439 StatisticBase(comp, stat_name, stat_sub_id, stat_params, null_stat)
440 {
441 setStatisticDataType(StatisticFieldInfo::getFieldTypeFromTemplate<T>());
442 }
443
444 virtual ~Statistic() {}
445
446private:
447 Statistic() {} // For serialization only
448};
449
450/**
451 * void Statistic has special meaning in that it does not collect fields
452 * in the usual way through the addData function. It has to use custom functions.
453 */
454template <>
455class Statistic<void> : public StatisticBase
456{
457public:
458 SST_ELI_DECLARE_BASE(Statistic)
459 SST_ELI_DECLARE_INFO(
460 ELI::ProvidesInterface,
461 ELI::ProvidesParams)
462 SST_ELI_DECLARE_CTOR(BaseComponent*, const std::string&, const std::string&, SST::Params&)
463
464 void registerOutputFields(StatisticFieldsOutput* stat_output) override;
465
466 void outputStatisticFields(StatisticFieldsOutput* stat_output, bool end_of_sim_flag) override;
467
468protected:
469 friend class SST::Factory;
470 friend class SST::BaseComponent;
471 /** Construct a Statistic
472 * @param comp - Pointer to the parent constructor.
473 * @param stat_name - Name of the statistic to be registered. This name must
474 * match the name in the ElementInfoStatistic.
475 * @param stat_sub_id - Additional name of the statistic
476 * @param stat_params - The parameters for this statistic
477 * @param null_stat - True if the statistic is null (not enabled). Defaults to False.
478 */
479
480 Statistic(BaseComponent* comp, const std::string& stat_name, const std::string& stat_sub_id, Params& stat_params,
481 bool null_stat = false) :
482 StatisticBase(comp, stat_name, stat_sub_id, stat_params, null_stat)
483 {}
484
485 virtual ~Statistic() {}
486
487private:
488 Statistic() {} // For serialization only
489};
490
491using CustomStatistic = Statistic<void>;
492
493template <class... Args>
494using MultiStatistic = Statistic<std::tuple<Args...>>;
495
496struct ImplementsStatFields
497{
498public:
499 std::string toString() const;
500
501 Statistics::fieldType_t fieldId() const { return field_; }
502
503 const char* fieldName() const { return field_name_; }
504
505 const char* fieldShortName() const { return short_name_; }
506
507protected:
508 template <class T>
509 explicit ImplementsStatFields(T* UNUSED(t)) :
510 field_name_(T::ELI_fieldName()),
511 short_name_(T::ELI_fieldShortName()),
512 field_(T::ELI_registerField(T::ELI_fieldName(), T::ELI_fieldShortName()))
513 {}
514
515private:
516 const char* field_name_;
517 const char* short_name_;
518 Statistics::fieldType_t field_;
519};
520
521
522#define SST_ELI_DECLARE_STATISTIC_TEMPLATE(cls, lib, name, version, desc, interface) \
523 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
524 SST_ELI_INTERFACE_INFO(interface) \
525 virtual std::string getELIName() const override \
526 { \
527 return std::string(lib) + "." + name; \
528 }
529
530#define SST_ELI_REGISTER_CUSTOM_STATISTIC(cls, lib, name, version, desc) \
531 SST_ELI_REGISTER_DERIVED(SST::Statistics::CustomStatistic,cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
532 SST_ELI_INTERFACE_INFO("CustomStatistic")
533
534#define SST_ELI_DECLARE_STATISTIC(cls, field, lib, name, version, desc, interface) \
535 static bool ELI_isLoaded() \
536 { \
537 return SST::Statistics::Statistic<field>::template addDerivedInfo<cls>(lib, name) && \
538 SST::Statistics::Statistic<field>::template addDerivedBuilder<cls>(lib, name) && \
539 SST::Statistics::Statistic<field>::template addDerivedInfo<SST::Statistics::NullStatistic<field>>( \
540 lib, name) && \
541 SST::Statistics::Statistic<field>::template addDerivedBuilder<SST::Statistics::NullStatistic<field>>( \
542 lib, name); \
543 } \
544 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
545 SST_ELI_INTERFACE_INFO(interface) \
546 static const char* ELI_fieldName() \
547 { \
548 return #field; \
549 } \
550 static const char* ELI_fieldShortName() \
551 { \
552 return #field; \
553 }
554
555#ifdef __INTEL_COMPILER
556#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
557 bool force_instantiate_##cls##_##field = \
558 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
559 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
560 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
561 SST::Statistics::NullStatistic<field>>::isLoaded() && \
562 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
563 SST::Statistics::NullStatistic<field>>::isLoaded();
564#else
565#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
566 struct cls##_##field##_##shortName : public cls<field> \
567 { \
568 cls##_##field##_##shortName( \
569 SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
570 cls<field>(bc, sn, si, p) \
571 {} \
572 static bool ELI_isLoaded() \
573 { \
574 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
575 cls##_##field##_##shortName>::isLoaded() && \
576 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
577 cls##_##field##_##shortName>::isLoaded() && \
578 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
579 SST::Statistics::NullStatistic<field>>::isLoaded() && \
580 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
581 SST::Statistics::NullStatistic<field>>::isLoaded(); \
582 } \
583 };
584#endif
585
586#define PP_NARG(...) PP_NARG_(__VA_ARGS__, PP_NSEQ())
587#define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
588#define PP_ARG_N(_1, _2, _3, _4, _5, N, ...) N
589#define PP_NSEQ() 5, 4, 3, 2, 1, 0
590
591#define PP_GLUE(X, Y) PP_GLUE_I(X, Y)
592#define PP_GLUE_I(X, Y) X##Y
593
594#define STAT_NAME1(base, a) base##a
595#define STAT_NAME2(base, a, b) base##a##b
596#define STAT_NAME3(base, a, b, c) base##a##b##c
597#define STAT_NAME4(base, a, b, c, d) base##a##b##c##d
598
599#define STAT_GLUE_NAME(base, ...) PP_GLUE(STAT_NAME, PP_NARG(__VA_ARGS__))(base, __VA_ARGS__)
600#define STAT_TUPLE(...) std::tuple<__VA_ARGS__>
601
602#ifdef __INTEL_COMPILER
603#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
604 bool force_instantiate_stat_name = \
605 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
606 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
607 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, \
608 SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
609 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, \
610 SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
611 } \
612 } \
613 ;
614#else
615#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
616 struct name : public cls<__VA_ARGS__> \
617 { \
618 name(SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
619 cls<__VA_ARGS__>(bc, sn, si, p) \
620 {} \
621 bool ELI_isLoaded() const \
622 { \
623 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
624 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
625 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, \
626 SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
627 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, \
628 SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
629 } \
630 };
631#endif
632
633#define SST_ELI_INSTANTIATE_MULTI_STATISTIC(cls, ...) \
634 MAKE_MULTI_STATISTIC(cls, STAT_GLUE_NAME(cls, __VA_ARGS__), STAT_TUPLE(__VA_ARGS__), __VA_ARGS__)
635
636} // namespace Statistics
637
638namespace Stat::pvt {
639
640/** Helper function for re-registering statistics during simulation restart */
641void registerStatWithEngineOnRestart(SST::Statistics::StatisticBase* s);
642
643} // namespace Stat::pvt
644
645namespace Core::Serialization {
646
647template <class T>
648class serialize_impl<Statistics::Statistic<T>*>
649{
650 void operator()(Statistics::Statistic<T>*& s, serializer& ser, ser_opt_t UNUSED(options))
651 {
652 // For sizer and pack, need to get the information needed
653 // to create a new statistic of the correct type on unpack.
654 switch ( ser.mode() ) {
655 case serializer::SIZER:
656 case serializer::PACK:
657 {
658 std::string stat_eli_type = s->getELIName();
659 std::string stat_name = s->getStatName();
660 std::string stat_id = s->getStatSubId();
661 BaseComponent* comp = s->getComponent();
662 SST_SER(stat_eli_type);
663 SST_SER(comp);
664 SST_SER(stat_name);
665 SST_SER(stat_id);
666 s->serialize_order(ser);
667 break;
668 }
669 case serializer::UNPACK:
670 {
671 std::string stat_eli_type;
672 BaseComponent* comp;
673 std::string stat_name;
674 std::string stat_id;
675 SST_SER(stat_eli_type);
676 SST_SER(comp);
677 SST_SER(stat_name);
678 SST_SER(stat_id);
679 Params params;
680 params.insert("type", stat_eli_type);
681 s = Factory::getFactory()->CreateWithParams<Statistics::Statistic<T>>(
682 stat_eli_type, params, comp, stat_name, stat_id, params);
683 s->serialize_order(ser);
684 if ( stat_eli_type != "sst.NullStatistic" ) {
685 SST::Stat::pvt::registerStatWithEngineOnRestart(s);
686 }
687 break;
688 }
689 case serializer::MAP:
690 {
691 // Mapping mode not supported for stats
692 break;
693 }
694 }
695 }
696
697 SST_FRIEND_SERIALIZE();
698};
699
700} // namespace Core::Serialization
701
702} // namespace SST
703
704// we need to make sure null stats are instantiated for whatever types we use
705#include "sst/core/statapi/statnull.h"
706
707#endif // SST_CORE_STATAPI_STATBASE_H
Main component object for the simulation.
Definition baseComponent.h:62
Base serialize class.
Definition serialize.h:110
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:45
Definition interfaceInfo.h:21
Definition paramsInfo.h:39
Class for instantiating Components, Links and the like out of element libraries.
Definition factory.h:48
Parameter store.
Definition params.h:58
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:166
Forms the base class for statistics gathering within SST.
Definition statbase.h:49
const std::string & getCompName() const
Return the Component Name.
Definition statbase.cc:112
UnitAlgebra & getStartAtTime() const
Return the time at which the statistic should be enabled.
Definition statbase.h:153
BaseComponent * getComponent() const
Return a pointer to the parent Component.
Definition statbase.h:141
virtual void resetCollectionCount()
Set the current collection count to 0.
Definition statbase.cc:150
void enable()
Enable Statistic for collections.
Definition statbase.h:61
UnitAlgebra & getStopAtTime() const
Return the time at which the statistic should be disabled.
Definition statbase.h:156
void setFlagOutputAtEndOfSim(bool flag)
Set the Output At End Of Sim flag.
Definition statbase.h:99
void setFlagClearDataOnOutput(bool flag)
Set the Clear Data On Output flag.
Definition statbase.h:94
const std::string & getStatName() const
Return the Statistic Name.
Definition statbase.h:106
virtual bool isReady() const
Indicate that the Statistic is Ready to be used.
Definition statbase.h:178
virtual void setCollectionCount(uint64_t new_count)
Set the current collection count to a defined value.
Definition statbase.cc:142
StatMode_t getRegisteredCollectionMode() const
Return the collection mode that is registered.
Definition statbase.h:174
bool getFlagOutputAtEndOfSim() const
Return the OutputAtEndOfSim flag value.
Definition statbase.h:171
virtual const std::string & getStatTypeName() const
Return the Statistic type name.
Definition statbase.h:123
StatMode_t
Statistic collection mode STAT_MODE_UNDEFINED - unknown mode STAT_MODE_COUNT - generating statistic o...
Definition statbase.h:57
const StatisticFieldInfo::fieldType_t & getStatDataType() const
Return the Statistic data type.
Definition statbase.h:126
virtual void setCollectionCountLimit(uint64_t new_limit)
Set the collection count limit to a defined value.
Definition statbase.cc:156
UnitAlgebra & getCollectionRate() const
Return the rate at which the statistic should be output.
Definition statbase.h:150
void setFlagResetCountOnOutput(bool flag)
Set the Reset Count On Output flag.
Definition statbase.h:86
bool getFlagClearDataOnOutput() const
Return the ClearDataOnOutput flag value.
Definition statbase.h:168
uint64_t getCollectionCountLimit() const
Return the collection count limit.
Definition statbase.h:159
const std::string & getStatSubId() const
Return the Statistic SubId.
Definition statbase.h:109
virtual bool isNullStatistic() const
Indicate if the Statistic is a NullStatistic.
Definition statbase.h:181
virtual void clearStatisticData()
Inform the Statistic to clear its data.
Definition statbase.h:68
const char * getStatDataTypeShortName() const
Return the Statistic data type.
Definition statbase.h:129
uint64_t getCollectionCount() const
Return the current collection count.
Definition statbase.h:162
void disable()
Disable Statistic for collections.
Definition statbase.h:64
bool isOutputEnabled() const
Return the enable status of the Statistic's ability to output data.
Definition statbase.h:147
const std::string & getFullStatName() const
Return the full Statistic name of component.stat_name.sub_id.
Definition statbase.h:112
const char * getStatDataTypeFullName() const
Return the Statistic data type.
Definition statbase.h:135
bool isEnabled() const
Return the enable status of the Statistic.
Definition statbase.h:144
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:201
void setStatisticTypeName(const char *type_name)
Set an optional Statistic Type Name (for output)
Definition statbase.h:212
StatisticBase(BaseComponent *comp, const std::string &stat_name, const std::string &stat_sub_id, Params &stat_params, bool null_stat)
Construct a StatisticBase.
Definition statbase.cc:40
virtual void incrementCollectionCount(uint64_t increment)
Increment current collection count.
Definition statbase.cc:134
bool getFlagResetCountOnOutput() const
Return the ResetCountOnOutput flag value.
Definition statbase.h:165
void setStatisticDataType(const StatisticFieldInfo::fieldType_t data_type)
Set the Statistic Data Type.
Definition statbase.h:209
Definition statoutput.h:170
Definition statgroup.h:31
Forms the base class for statistics output generation within the SST core.
Definition statoutput.h:52
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition statengine.h:58
Forms the template defined base class for statistics gathering within SST.
Definition statbase.h:373
Statistic(BaseComponent *comp, const std::string &stat_name, const std::string &stat_sub_id, Params &stat_params, bool null_stat=false)
Construct a Statistic.
Definition statbase.h:437
void addData(InArgs &&... args)
Add data to the Statistic This will call the addData_impl() routine in the derived Statistic.
Definition statbase.h:397
virtual void serialize_order(SST::Core::Serialization::serializer &ser) override
Serialization.
Definition statbase.h:420
Performs Unit math in full precision.
Definition unitAlgebra.h:107
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:324
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:345
Base type that creates the virtual addData(...) interface Used for distinguishing arithmetic types (c...
Definition statbase.h:311