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