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