Belle II Software  release-05-02-19
ProcessStatistics.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/core/ModuleStatistics.h>
14 #include <framework/pcore/Mergeable.h>
15 #include <framework/core/Module.h>
16 
17 #include <map>
18 #include <vector>
19 
20 namespace Belle2 {
25  class Module;
26 
86  class ProcessStatistics : public Mergeable {
87  public:
91  m_suspendedMemory(0) { }
92 
103  const std::vector<Belle2::ModuleStatistics>* modules = nullptr) const;
104 
106  const ModuleStatistics& getGlobal() const { return m_global; }
107 
109  const std::vector<Belle2::ModuleStatistics>& getAll() const { return m_stats; }
110 
113 
118  {
121  }
122 
124  void resumeGlobal()
125  {
128  }
129 
132  {
136  }
137 
139  void startModule()
140  {
142  }
143 
145  void stopModule(const Module* module, ModuleStatistics::EStatisticCounters type)
146  {
149  if (module && module->hasProperties(Module::c_DontCollectStatistics)) return;
150  m_stats[getIndex(module)].add(type, m_moduleTime, m_moduleMemory);
151  }
152 
156  void initModule(const Module* module);
157 
158 
164  ModuleStatistics& getStatistics(const Module* module)
165  {
166  return m_stats[getIndex(module)];
167  }
168 
170  int getIndex(const Module* module);
171 
173  virtual void merge(const Mergeable* other) override;
174 
176  virtual void clear() override;
177 
179  virtual TObject* Clone(const char* newname = "") const override;
180 
182  std::string getInfoHTML() const;
183 
184  private:
186  ProcessStatistics(const ProcessStatistics&) = default;
189 
191  void appendUnmergedModules(const ProcessStatistics* otherObject);
192 
194  void setTransientCounters(const ProcessStatistics* otherObject);
195 
203  void setCounters(double& time, double& memory,
204  double startTime = 0, double startMemory = 0);
205 
206  ModuleStatistics m_global;
207  std::vector<Belle2::ModuleStatistics> m_stats;
210  std::map<const Module*, int> m_modulesToStatsIndex;
211 
212  //the following are used for the (process-local) time-keeping
213 
215  double m_globalTime;
216 
217  double m_globalMemory;
218 
219  double m_moduleTime;
220 
221  double m_moduleMemory;
222 
226 
230 
232  };
233 
235 } //Belle2 namespace
Belle2::ProcessStatistics::m_globalTime
double m_globalTime
store clock counter for global time consumption
Definition: ProcessStatistics.h:223
Belle2::ProcessStatistics::getAll
const std::vector< Belle2::ModuleStatistics > & getAll() const
Get entire statistics map.
Definition: ProcessStatistics.h:117
Belle2::ProcessStatistics::resumeGlobal
void resumeGlobal()
Resume timer after call to suspendGlobal()
Definition: ProcessStatistics.h:132
Belle2::ProcessStatistics::ClassDefOverride
ClassDefOverride(ProcessStatistics, 2)
(transient)
Belle2::ModuleStatistics::c_Event
@ c_Event
Counting time/calls in event()
Definition: ModuleStatistics.h:45
Belle2::ProcessStatistics::suspendGlobal
void suspendGlobal()
Suspend timer for global measurement, needed for newRun.
Definition: ProcessStatistics.h:125
Belle2::ProcessStatistics::getStatisticsString
std::string getStatisticsString(ModuleStatistics::EStatisticCounters type=ModuleStatistics::c_Event, const std::vector< Belle2::ModuleStatistics > *modules=nullptr) const
Return string with statistics for all modules.
Definition: ProcessStatistics.cc:55
Belle2::ModuleStatistics::EStatisticCounters
EStatisticCounters
Enum to define all counter types.
Definition: ModuleStatistics.h:39
Belle2::ProcessStatistics::appendUnmergedModules
void appendUnmergedModules(const ProcessStatistics *otherObject)
Merge dissimilar objects (mainly loading ProcessStatistics from file).
Definition: ProcessStatistics.cc:102
Belle2::ProcessStatistics::stopModule
void stopModule(const Module *module, ModuleStatistics::EStatisticCounters type)
Stop module counter and attribute values to appropriate module.
Definition: ProcessStatistics.h:153
Belle2::ProcessStatistics::m_globalMemory
double m_globalMemory
(transient)
Definition: ProcessStatistics.h:225
Belle2::ProcessStatistics::m_moduleMemory
double m_moduleMemory
(transient)
Definition: ProcessStatistics.h:229
Belle2::ProcessStatistics::m_stats
std::vector< Belle2::ModuleStatistics > m_stats
module statistics
Definition: ProcessStatistics.h:215
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::ProcessStatistics::Clone
virtual TObject * Clone(const char *newname="") const override
Reimplement TObject::Clone() since we also need m_modulesToStatsIndex.
Definition: ProcessStatistics.cc:194
Belle2::ProcessStatistics::setTransientCounters
void setTransientCounters(const ProcessStatistics *otherObject)
Set transient counters from otherObject.
Definition: ProcessStatistics.cc:171
Belle2::ProcessStatistics::setCounters
void setCounters(double &time, double &memory, double startTime=0, double startMemory=0)
Set counters time and memory to contain the current clock value and memory consumption respectively.
Definition: ProcessStatistics.cc:187
Belle2::ProcessStatistics::m_suspendedMemory
double m_suspendedMemory
(transient)
Definition: ProcessStatistics.h:237
Belle2::ProcessStatistics::startGlobal
void startGlobal()
Start timer for global measurement.
Definition: ProcessStatistics.h:120
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ProcessStatistics::startModule
void startModule()
Start module timer.
Definition: ProcessStatistics.h:147
Belle2::ProcessStatistics::m_modulesToStatsIndex
std::map< const Module *, int > m_modulesToStatsIndex
transient, maps Module* to m_stats index.
Definition: ProcessStatistics.h:218
Belle2::ProcessStatistics::ProcessStatistics
ProcessStatistics()
Constructor.
Definition: ProcessStatistics.h:97
Belle2::ModuleStatistics::add
void add(EStatisticCounters type, value_type time, value_type memory)
Add a time and memory measurment to the counter of a given type.
Definition: ModuleStatistics.h:65
Belle2::ProcessStatistics::getStatistics
ModuleStatistics & getStatistics(const Module *module)
Get statistics for single module.
Definition: ProcessStatistics.h:172
Belle2::ProcessStatistics::stopGlobal
void stopGlobal(ModuleStatistics::EStatisticCounters type)
Stop global timer and add values to the statistic counter.
Definition: ProcessStatistics.h:139
Belle2::ProcessStatistics::initModule
void initModule(const Module *module)
Init module statistics: Set name from module if still empty and remember initialization index for dis...
Definition: ProcessStatistics.cc:41
Belle2::ProcessStatistics::operator=
ProcessStatistics & operator=(ProcessStatistics &)
Prohibit assignment operator.
Belle2::ProcessStatistics::getInfoHTML
std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
Definition: ProcessStatistics.cc:200
Belle2::ProcessStatistics::getIndex
int getIndex(const Module *module)
get m_stats index for given module, inserting it if not found.
Definition: ProcessStatistics.cc:28
Belle2::ProcessStatistics::m_suspendedTime
double m_suspendedTime
(transient)
Definition: ProcessStatistics.h:233
Belle2::ProcessStatistics
Class to collect call statistics for all modules.
Definition: ProcessStatistics.h:94
Belle2::Module::c_DontCollectStatistics
@ c_DontCollectStatistics
No statistics is collected for this module.
Definition: Module.h:86
Belle2::ProcessStatistics::clear
virtual void clear() override
Clear collected statistics but keep names of modules.
Definition: ProcessStatistics.cc:181
Belle2::ProcessStatistics::m_global
ModuleStatistics m_global
Statistics object for global time and memory consumption.
Definition: ProcessStatistics.h:214
Belle2::ProcessStatistics::m_moduleTime
double m_moduleTime
(transient)
Definition: ProcessStatistics.h:227
Belle2::ProcessStatistics::getGlobal
const ModuleStatistics & getGlobal() const
Get global statistics.
Definition: ProcessStatistics.h:114
Belle2::ProcessStatistics::merge
virtual void merge(const Mergeable *other) override
Merge other ProcessStatistics object into this one.
Definition: ProcessStatistics.cc:150
Belle2::ModuleStatistics
Keep track of time and memory consumption during processing.
Definition: ModuleStatistics.h:36