SST  10.1.0
StructuralSimulationToolkit
statengine.h
1 // Copyright 2009-2020 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-2020, 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 _H_SST_CORE_STATISTICS_ENGINE
13 #define _H_SST_CORE_STATISTICS_ENGINE
14 
15 #include "sst/core/sst_types.h"
16 #include "sst/core/statapi/statfieldinfo.h"
17 #include "sst/core/statapi/statgroup.h"
18 #include "sst/core/statapi/statbase.h"
19 #include "sst/core/statapi/statnull.h"
20 #include "sst/core/unitAlgebra.h"
21 #include "sst/core/clock.h"
22 #include "sst/core/oneshot.h"
23 #include "sst/core/threadsafe.h"
24 #include "sst/core/factory.h"
25 
26 /* Forward declare for Friendship */
27 extern int main(int argc, char **argv);
28 extern void finalize_statEngineConfig(void);
29 
30 
31 namespace SST {
32 class BaseComponent;
33 class Simulation;
34 class ConfigGraph;
35 class ConfigStatGroup;
36 class ConfigStatOutput;
37 class Params;
38 
39 namespace Statistics {
40 
41 //template<typename T> class Statistic;
42 //class StatisticBase;
43 class StatisticOutput;
44 
45 /**
46  \class StatisticProcessingEngine
47 
48  An SST core component that handles timing and event processing informing
49  all registered Statistics to generate their outputs at desired rates.
50 */
51 
53 {
54  static StatisticProcessingEngine* instance;
55 
56 public:
57  static StatisticProcessingEngine* getInstance() { return instance; }
58 
59 
60  /** Called by the Components and Subcomponent to perform a statistic Output.
61  * @param stat - Pointer to the statistic.
62  * @param EndOfSimFlag - Indicates that the output is occurring at the end of simulation.
63  */
64  void performStatisticOutput(StatisticBase* stat, bool endOfSimFlag = false);
65 
66  /** Called by the Components and Subcomponent to perform a global statistic Output.
67  * This routine will force ALL Components and Subcomponents to output their statistic information.
68  * This may lead to unexpected results if the statistic counts or data is reset on output.
69  * @param endOfSimFlag - Indicates that the output is occurring at the end of simulation.
70  */
71  void performGlobalStatisticOutput(bool endOfSimFlag = false);
72 
73  template <class T>
74  Statistic<T>* createStatistic(BaseComponent *comp, const std::string& type,
75  const std::string& statName, const std::string& statSubId,
76  Params &params)
77  {
78 
79  return Factory::getFactory()->Create<Statistic<T>>(type, params, comp, statName, statSubId, params);
80  }
81 
82  bool registerStatisticWithEngine(StatisticBase* stat, fieldType_t fieldType, uint8_t comp_stat_level)
83  {
84  bool ok;
85  if ((ok = registerStatisticCore(stat,comp_stat_level))) {
86  addStatisticToCompStatMap(stat, fieldType);
87  }
88  return ok;
89  }
90 
91  StatisticBase* isStatisticRegisteredWithEngine(const std::string& compName, const ComponentId_t& compId,
92  const std::string& statName, const std::string& statSubId,
93  fieldType_t fieldId)
94  {
95  return isStatisticInCompStatMap(compName, compId, statName, statSubId, fieldId);
96  }
97 
98  const std::vector<StatisticOutput*>& getStatOutputs() const { return m_statOutputs; }
99 
100 private:
101  friend class SST::Simulation;
102  friend int ::main(int argc, char **argv);
103  friend void ::finalize_statEngineConfig(void);
104 
106  void setup(ConfigGraph *graph);
108 
109  static void init(ConfigGraph *graph);
110 
111  StatisticOutput* createStatisticOutput(const ConfigStatOutput &cfg);
112 
113  bool registerStatisticCore(StatisticBase* stat, uint8_t comp_stat_level);
114 
115  StatisticOutput* getOutputForStatistic(const StatisticBase *stat) const;
116  StatisticGroup& getGroupForStatistic(const StatisticBase *stat) const;
117  bool addPeriodicBasedStatistic(const UnitAlgebra& freq, StatisticBase* Stat);
118  bool addEventBasedStatistic(const UnitAlgebra& count, StatisticBase* Stat);
119  bool addEndOfSimStatistic(StatisticBase* Stat);
120  UnitAlgebra getParamTime(StatisticBase *stat, const std::string& pName) const;
121  void setStatisticStartTime(StatisticBase* Stat);
122  void setStatisticStopTime(StatisticBase* Stat);
123 
124  void finalizeInitialization(); /* Called when performWireUp() finished */
125  void startOfSimulation();
126  void endOfSimulation();
127 
128 
129  void performStatisticOutputImpl(StatisticBase* stat, bool endOfSimFlag);
130  void performStatisticGroupOutputImpl(StatisticGroup& group, bool endOfSimFlag);
131 
132  bool handleStatisticEngineClockEvent(Cycle_t CycleNum, SimTime_t timeFactor);
133  bool handleGroupClockEvent(Cycle_t CycleNum, StatisticGroup* group);
134  void handleStatisticEngineStartTimeEvent(SimTime_t timeFactor);
135  void handleStatisticEngineStopTimeEvent(SimTime_t timeFactor);
136  StatisticBase* isStatisticInCompStatMap(const std::string& compName, const ComponentId_t& compId,
137  const std::string& statName, const std::string& statSubId,
138  StatisticFieldInfo::fieldType_t fieldType);
139  void addStatisticToCompStatMap(StatisticBase* Stat, StatisticFieldInfo::fieldType_t fieldType);
140  void castError(const std::string& type, const std::string& statName, const std::string& fieldName);
141 
142 private:
143  typedef std::vector<StatisticBase*> StatArray_t; /*!< Array of Statistics */
144  typedef std::map<SimTime_t, StatArray_t*> StatMap_t; /*!< Map of simtimes to Statistic Arrays */
145  typedef std::map<ComponentId_t, StatArray_t*> CompStatMap_t; /*!< Map of ComponentId's to StatInfo Arrays */
146 
147  StatArray_t m_EventStatisticArray; /*!< Array of Event Based Statistics */
148  StatMap_t m_PeriodicStatisticMap; /*!< Map of Array's of Periodic Based Statistics */
149  StatMap_t m_StartTimeMap; /*!< Map of Array's of Statistics that are started at a sim time */
150  StatMap_t m_StopTimeMap; /*!< Map of Array's of Statistics that are stopped at a sim time */
151  CompStatMap_t m_CompStatMap; /*!< Map of Arrays of Statistics tied to Component Id's */
152  bool m_SimulationStarted; /*!< Flag showing if Simulation has started */
153 
154  Output & m_output;
155  uint8_t m_statLoadLevel;
156  std::vector<StatisticOutput*> m_statOutputs;
157  StatisticGroup m_defaultGroup;
158  std::vector<StatisticGroup> m_statGroups;
159  Core::ThreadSafe::Barrier m_barrier;
160 
161 };
162 
163 } //namespace Statistics
164 } //namespace SST
165 
166 #endif
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:54
Main control class for a SST Simulation.
Definition: simulation.h:73
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:49
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:321
void performStatisticOutput(StatisticBase *stat, bool endOfSimFlag=false)
Called by the Components and Subcomponent to perform a statistic Output.
Definition: statengine.cc:445
Forms the base class for statistics gathering within SST.
Definition: statbase.h:64
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:42
void setup()
Perform the setup() and run phases of the simulation.
Definition: simulation.cc:493
Main component object for the simulation.
Definition: baseComponent.h:52
Parameter store.
Definition: params.h:44
Definition: configGraph.h:168
void performGlobalStatisticOutput(bool endOfSimFlag=false)
Called by the Components and Subcomponent to perform a global statistic Output.
Definition: statengine.cc:509
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:52
Definition: statgroup.h:29
Performs Unit math in full precision.
Definition: unitAlgebra.h:107
Definition: threadsafe.h:50