SST 16.0.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 void setStatisticTypeName(const char* type_name) { stat_type_name_ = type_name; }
225
226private:
227 friend class SST::BaseComponent;
228
229 /** Set the Registered Collection Mode */
230 void setRegisteredCollectionMode(bool is_periodic) { registered_collection_mode_ = is_periodic; }
231
232 /** Construct a full name of the statistic */
233 static std::string buildStatisticFullName(const char* comp_name, const char* stat_name, const char* stat_sub_id);
234 static std::string buildStatisticFullName(
235 const std::string& comp_name, const std::string& stat_name, const std::string& stat_sub_id);
236
237 // Required Virtual Methods:
238 /** Called by the system to tell the Statistic to register its output fields.
239 * by calling statOutput->registerField(...)
240 * @param stat_output - Pointer to the statistic output
241 */
242 virtual void registerOutputFields(StatisticFieldsOutput* stat_output) = 0;
243
244 /** Called by the system to tell the Statistic to send its data to the
245 * StatisticOutput to be output.
246 * @param stat_output - Pointer to the statistic output
247 * @param end_of_sim_flag - Indicates that the output is occurring at the end of simulation.
248 */
249 virtual void outputStatisticFields(StatisticFieldsOutput* stat_output, bool end_of_sim_flag) = 0;
250
251 /** Indicate if the Statistic Mode is supported.
252 * This allows Statistics to support STAT_MODE_COUNT and STAT_MODE_PERIODIC modes.
253 * by default, both modes are supported.
254 * @param mode - Mode to test
255 */
256 virtual bool isStatModeSupported(bool UNUSED(periodic)) const { return true; } // Default is to accept all modes
257
258 /** Verify that the statistic names match */
259 bool operator==(StatisticBase& check_stat);
260
261 void checkEventForOutput();
262
263 const StatisticGroup* getGroup() const { return group_; }
264 void setGroup(const StatisticGroup* group) { group_ = group; }
265
266
267protected:
268 StatisticBase() {} // For serialization only
269
270private:
271 enum Flag : uint8_t {
272 StartAt = 1, // bit 0
273 StopAt = 2, // bit 1
274 OutputRate = 4, // bit 2
275 };
276
277 std::string stat_name_ = ""; // Name of stat, matches ELI
278 std::string stat_sub_id_ = ""; // Sub ID for this instance of the stat (default="")
279 std::string stat_type_name_ = ""; // DEPRECATED (remove SST 16.0) - override 'getStatTypeName()' instead
280 std::string stat_mod_name_ =
281 ""; // Modifier for component name, temporary until we figure out a nameable base class for elements
282
283 uint8_t flags_ = 0; // Flags for checkpoint output
284 bool stat_enabled_ = true; // Whether stat is currently collecting data
285 bool registered_collection_mode_ = true; // True if periodic, false if event-based
286 uint64_t current_collection_count_ = 0;
287 uint64_t output_collection_count_ = 0; // Relevant for STAT_MODE_COUNT
288 uint64_t collection_count_limit_ = 0; // Relevant for STAT_MODE_COUNT
289
290 const StatisticGroup* group_ = nullptr; // Group that stat belongs to
291
292 bool reset_count_on_output_ = false; // Whether to clear current_collection_count_ on output
293 bool clear_data_on_output_ = false; // Whether to reset data on output
294 bool output_at_end_of_sim_ = true; // Whether to output stat at end of sim
295
296 BaseComponent* component_;
297 StatisticFieldInfo::fieldType_t stat_data_type_;
298};
299
300/**
301 \class StatisticCollector
302 * Base type that creates the virtual addData(...) interface
303 * Used for distinguishing arithmetic types (collected by value)
304 * and composite struct types (collected by reference)
305 */
306template <class T, bool = std::is_arithmetic_v<T>>
308
309template <class T>
310struct StatisticCollector<T, true>
311{
312 virtual void addData_impl(T data) = 0;
313
314 /**
315 * @brief addData_impl_Ntimes Add the same data N times in a row
316 * By default, this just calls the addData function N times
317 * @param N The number of consecutive times
318 * @param args The arguments to pass in
319 */
320 virtual void addData_impl_Ntimes(uint64_t N, T data)
321 {
322 for ( uint64_t i = 0; i < N; ++i ) {
323 addData_impl(data);
324 }
325 }
326
327 virtual ~StatisticCollector() = default;
328};
329
330template <class... Args>
331struct StatisticCollector<std::tuple<Args...>, false>
332{
333 virtual void addData_impl(Args... args) = 0;
334
335 /**
336 * @brief addData_impl_Ntimes Add the same data N times in a row
337 * By default, this just calls the addData function N times
338 * @param N The number of consecutive times
339 * @param args The arguments to pass in
340 */
341 virtual void addData_impl_Ntimes(uint64_t N, Args... args)
342 {
343 for ( uint64_t i = 0; i < N; ++i ) {
344 addData_impl(args...);
345 }
346 }
347
348 template <class... InArgs>
349 void addData(InArgs&&... args)
350 {
351 addData_impl(std::make_tuple(std::forward<InArgs>(args)...));
352 }
353
354 virtual ~StatisticCollector() = default;
355};
356
357////////////////////////////////////////////////////////////////////////////////
358
359/**
360 \class Statistic
361
362 Forms the template defined base class for statistics gathering within SST.
363
364 @tparam T A template for the basic numerical data stored by this Statistic
365*/
366
367template <typename T>
369{
370public:
371 SST_ELI_DECLARE_BASE(Statistic<T>)
372 SST_ELI_DECLARE_INFO(
375 SST_ELI_DECLARE_CTOR(BaseComponent*, const std::string&, const std::string&, SST::Params&)
376
377 SST_ELI_DOCUMENT_PARAMS(
378 {"rate", "Frequency at which to output statistic. Must include units. 0ns = output at end of simulation only.", "0ns" },
379 {"startat", "Time at which to enable data collection in this statistic. Must include units. 0ns = always enabled.", "0ns"},
380 {"stopat", "Time at which to disable data collection in this statistic. 0ns = always enabled.", "0ns"},
381 {"resetOnOutput", "Whether to reset the statistic's values after each output.", "False"}
382 )
383
384 using Datum = T;
385 using StatisticCollector<T>::addData_impl;
386 using StatisticCollector<T>::addData_impl_Ntimes;
387
388 // The main method to add data to the statistic
389 /** Add data to the Statistic
390 * This will call the addData_impl() routine in the derived Statistic.
391 */
392 template <class... InArgs> // use a universal reference here
393 void addData(InArgs&&... args)
394 {
395 // Call the Derived Statistic's implementation
396 // of addData and increment the count
397 if ( isEnabled() ) {
398 addData_impl(std::forward<InArgs>(args)...);
400 }
401 }
402
403 template <class... InArgs> // use a universal reference here
404 void addDataNTimes(uint64_t N, InArgs&&... args)
405 {
406 // Call the Derived Statistic's implementation
407 // of addData and increment the count
408 if ( isEnabled() ) {
409 addData_impl_Ntimes(N, std::forward<InArgs>(args)...);
411 }
412 }
413
414 static fieldType_t fieldId() { return StatisticFieldType<T>::id(); }
415
420
421protected:
422 friend class SST::Factory;
423 friend class SST::BaseComponent;
424 /** Construct a Statistic
425 * @param comp - Pointer to the parent constructor.
426 * @param stat_name - Name of the statistic to be registered. This name must
427 * match the name in the ElementInfoStatistic.
428 * @param stat_sub_id - Additional name of the statistic
429 * @param stat_params - The parameters for this statistic
430 */
431
432 Statistic(BaseComponent* comp, const std::string& stat_name, const std::string& stat_sub_id, Params& stat_params) :
433 StatisticBase(comp, stat_name, stat_sub_id, stat_params)
434 {
435 setStatisticDataType(StatisticFieldInfo::getFieldTypeFromTemplate<T>());
436 }
437
438 virtual ~Statistic() {}
439
440private:
441 Statistic() {} // For serialization only
442};
443
444/**
445 * void Statistic has special meaning in that it does not collect fields
446 * in the usual way through the addData function. It has to use custom functions.
447 */
448template <>
449class Statistic<void> : public StatisticBase
450{
451public:
452 SST_ELI_DECLARE_BASE(Statistic<void>)
453 SST_ELI_DECLARE_INFO(
456 SST_ELI_DECLARE_CTOR(BaseComponent*, const std::string&, const std::string&, SST::Params&)
457
458 void registerOutputFields(StatisticFieldsOutput* stat_output) override;
459
460 void outputStatisticFields(StatisticFieldsOutput* stat_output, bool end_of_sim_flag) override;
461
462protected:
463 friend class SST::Factory;
464 friend class SST::BaseComponent;
465 /** Construct a Statistic
466 * @param comp - Pointer to the parent constructor.
467 * @param stat_name - Name of the statistic to be registered. This name must
468 * match the name in the ElementInfoStatistic.
469 * @param stat_sub_id - Additional name of the statistic
470 * @param stat_params - The parameters for this statistic
471 */
472
473 Statistic(BaseComponent* comp, const std::string& stat_name, const std::string& stat_sub_id, Params& stat_params) :
474 StatisticBase(comp, stat_name, stat_sub_id, stat_params)
475 {}
476
477 virtual ~Statistic() {}
478
479private:
480 Statistic() {} // For serialization only
481};
482
483using CustomStatistic = Statistic<void>;
484
485template <class... Args>
486using MultiStatistic = Statistic<std::tuple<Args...>>;
487
488struct ImplementsStatFields
489{
490public:
491 std::string toString() const;
492
493 Statistics::fieldType_t fieldId() const { return field_; }
494
495 const char* fieldName() const { return field_name_; }
496
497 const char* fieldShortName() const { return short_name_; }
498
499protected:
500 template <class T>
501 explicit ImplementsStatFields(T* UNUSED(t)) :
502 field_name_(T::ELI_fieldName()),
503 short_name_(T::ELI_fieldShortName()),
504 field_(T::ELI_registerField(T::ELI_fieldName(), T::ELI_fieldShortName()))
505 {}
506
507private:
508 const char* field_name_;
509 const char* short_name_;
510 Statistics::fieldType_t field_;
511};
512
513
514#define SST_ELI_DECLARE_STATISTIC_TEMPLATE(cls, lib, name, version, desc, interface) \
515 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
516 SST_ELI_INTERFACE_INFO(interface) \
517 virtual std::string getELIName() const override \
518 { \
519 return std::string(lib) + "." + (name); \
520 }
521
522#define SST_ELI_DECLARE_STATISTIC_TEMPLATE_DERIVED(cls, field, lib, name, version, desc, interface) \
523 using SST::Statistics::Statistic<field>::__EliBaseLevel; \
524 using typename SST::Statistics::Statistic<field>::__LocalEliBase; \
525 using typename SST::Statistics::Statistic<field>::__ParentEliBase; \
526 [[maybe_unused]] \
527 static constexpr int __EliDerivedLevel = \
528 std::is_same_v<SST::Statistics::Statistic<field>, cls<field>> ? __EliBaseLevel : __EliBaseLevel + 1; \
529 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
530 SST_ELI_INTERFACE_INFO(interface) \
531 virtual std::string getELIName() const override \
532 { \
533 return std::string(lib) + "." + name; \
534 }
535
536#define SST_ELI_REGISTER_CUSTOM_STATISTIC(cls, lib, name, version, desc) \
537 SST_ELI_REGISTER_DERIVED(SST::Statistics::CustomStatistic,cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
538 SST_ELI_INTERFACE_INFO("CustomStatistic")
539
540#define SST_ELI_DECLARE_STATISTIC(cls, field, lib, name, version, desc, interface) \
541 static bool ELI_isLoaded() \
542 { \
543 return SST::Statistics::Statistic<field>::template addDerivedInfo<cls>(lib, name) && \
544 SST::Statistics::Statistic<field>::template addDerivedBuilder<cls>(lib, name) && \
545 SST::Statistics::Statistic<field>::template addDerivedInfo<SST::Statistics::NullStatistic<field>>( \
546 lib, name) && \
547 SST::Statistics::Statistic<field>::template addDerivedBuilder<SST::Statistics::NullStatistic<field>>( \
548 lib, name); \
549 } \
550 SST_ELI_DEFAULT_INFO(lib, name, ELI_FORWARD_AS_ONE(version), desc) \
551 SST_ELI_INTERFACE_INFO(interface) \
552 static const char* ELI_fieldName() \
553 { \
554 return #field; \
555 } \
556 static const char* ELI_fieldShortName() \
557 { \
558 return #field; \
559 }
560
561#ifdef __INTEL_COMPILER
562#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
563 bool force_instantiate_##cls##_##field = \
564 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
565 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, cls<field>>::isLoaded() && \
566 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
567 SST::Statistics::NullStatistic<field>>::isLoaded() && \
568 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
569 SST::Statistics::NullStatistic<field>>::isLoaded();
570#else
571#define SST_ELI_INSTANTIATE_STATISTIC(cls, field) \
572 struct cls##_##field##_##shortName : public cls<field> \
573 { \
574 cls##_##field##_##shortName( \
575 SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
576 cls<field>(bc, sn, si, p) \
577 {} \
578 static bool ELI_isLoaded() \
579 { \
580 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
581 cls##_##field##_##shortName>::isLoaded() && \
582 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
583 cls##_##field##_##shortName>::isLoaded() && \
584 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<field>, \
585 SST::Statistics::NullStatistic<field>>::isLoaded() && \
586 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<field>, \
587 SST::Statistics::NullStatistic<field>>::isLoaded(); \
588 } \
589 };
590#endif
591
592#define PP_NARG(...) PP_NARG_(__VA_ARGS__, PP_NSEQ())
593#define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
594#define PP_ARG_N(_1, _2, _3, _4, _5, N, ...) N
595#define PP_NSEQ() 5, 4, 3, 2, 1, 0
596
597#define PP_GLUE(X, Y) PP_GLUE_I(X, Y)
598#define PP_GLUE_I(X, Y) X##Y
599
600#define STAT_NAME1(base, a) base##a
601#define STAT_NAME2(base, a, b) base##a##b
602#define STAT_NAME3(base, a, b, c) base##a##b##c
603#define STAT_NAME4(base, a, b, c, d) base##a##b##c##d
604
605#define STAT_GLUE_NAME(base, ...) PP_GLUE(STAT_NAME, PP_NARG(__VA_ARGS__))(base, __VA_ARGS__)
606#define STAT_TUPLE(...) std::tuple<__VA_ARGS__>
607
608#ifdef __INTEL_COMPILER
609#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
610 bool force_instantiate_stat_name = \
611 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
612 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, cls<__VA_ARGS__>>::isLoaded() && \
613 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, \
614 SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
615 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, \
616 SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
617 } \
618 } \
619 ;
620#else
621#define MAKE_MULTI_STATISTIC(cls, name, tuple, ...) \
622 struct name : public cls<__VA_ARGS__> \
623 { \
624 name(SST::BaseComponent* bc, const std::string& sn, const std::string& si, SST::Params& p) : \
625 cls<__VA_ARGS__>(bc, sn, si, p) \
626 {} \
627 bool ELI_isLoaded() const \
628 { \
629 return SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
630 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, name>::isLoaded() && \
631 SST::ELI::InstantiateBuilderInfo<SST::Statistics::Statistic<tuple>, \
632 SST::Statistics::NullStatistic<tuple>>::isLoaded() && \
633 SST::ELI::InstantiateBuilder<SST::Statistics::Statistic<tuple>, \
634 SST::Statistics::NullStatistic<tuple>>::isLoaded(); \
635 } \
636 };
637#endif
638
639#define SST_ELI_INSTANTIATE_MULTI_STATISTIC(cls, ...) \
640 MAKE_MULTI_STATISTIC(cls, STAT_GLUE_NAME(cls, __VA_ARGS__), STAT_TUPLE(__VA_ARGS__), __VA_ARGS__)
641
642} // namespace Statistics
643
644namespace Stat::pvt {
645
646/** Helper function for re-registering statistics during simulation restart */
647void registerStatWithEngineOnRestart(
648 SST::Statistics::StatisticBase* stat, SimTime_t start_factor, SimTime_t stop_factor, SimTime_t output_factor);
649
650} // namespace Stat::pvt
651
652namespace Core::Serialization {
653
654template <class T>
655class serialize_impl<Statistics::Statistic<T>*>
656{
657 void operator()(Statistics::Statistic<T>*& s, serializer& ser, ser_opt_t UNUSED(options))
658 {
659 // For sizer and pack, need to get the information needed
660 // to create a new statistic of the correct type on unpack.
661 switch ( ser.mode() ) {
662 case serializer::SIZER:
663 case serializer::PACK:
664 {
665 std::string stat_eli_type = s->getELIName();
666 SST_SER(stat_eli_type);
667
668 if ( !s->isNullStatistic() ) {
669 s->serializeStat(ser);
670 }
671 break;
672 }
673 case serializer::UNPACK:
674 {
675 std::string stat_eli_type;
676 Params params;
677 params.insert("type", stat_eli_type);
678
679 SST_SER(stat_eli_type);
680
681 if ( stat_eli_type == "sst.NullStatistic" ) {
682 static Statistics::Statistic<T>* nullstat =
683 Factory::getFactory()->CreateWithParams<Statistics::Statistic<T>>(
684 stat_eli_type, params, nullptr, "", "", params);
685 s = nullstat;
686 }
687 else {
688
689 BaseComponent* comp = s->deserializeComponentPtr(ser);
690 std::string stat_name;
691 std::string stat_id;
692 SimTime_t output_rate_factor;
693
694 SimTime_t start_at_factor = 0;
695 SimTime_t stop_at_factor = 0;
696
697 SST_SER(stat_name);
698 SST_SER(stat_id);
699 SST_SER(output_rate_factor);
700
701 s = Factory::getFactory()->CreateWithParams<Statistics::Statistic<T>>(
702 stat_eli_type, params, comp, stat_name, stat_id, params);
703
704 s->serialize_order(ser);
705
706 // Need to reconstruct time parameters for engine
707 if ( s->getStartAtFlag() ) {
708 SST_SER(start_at_factor);
709 }
710 if ( s->getStopAtFlag() ) {
711 SST_SER(stop_at_factor);
712 }
713 SST::Stat::pvt::registerStatWithEngineOnRestart(s, start_at_factor, stop_at_factor, output_rate_factor);
714 }
715 break;
716 }
717 case serializer::MAP:
718 {
719 // Mapping mode not supported for stats
720 break;
721 }
722 }
723 }
724
725 SST_FRIEND_SERIALIZE();
726};
727
728} // namespace Core::Serialization
729
730} // namespace SST
731
732// we need to make sure null stats are instantiated for whatever types we use
733#include "sst/core/statapi/statnull.h"
734
735#endif // SST_CORE_STATAPI_STATBASE_H
Main component object for the simulation.
Definition baseComponent.h:67
Base serialize class.
Definition serialize.h:132
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).
Definition statbase.h:224
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:473
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:369
Statistic(BaseComponent *comp, const std::string &stat_name, const std::string &stat_sub_id, Params &stat_params)
Construct a Statistic.
Definition statbase.h:432
void addData(InArgs &&... args)
Add data to the Statistic This will call the addData_impl() routine in the derived Statistic.
Definition statbase.h:393
virtual void serialize_order(SST::Core::Serialization::serializer &ser) override
Serialization.
Definition statbase.h:416
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:320
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:341
Base type that creates the virtual addData(...) interface Used for distinguishing arithmetic types (c...
Definition statbase.h:307