Belle II Software  release-08-01-10
ProcessStatistics.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <framework/core/ModuleStatistics.h>
12 #include <framework/pcore/Mergeable.h>
13 #include <framework/core/Module.h>
14 
15 #include <map>
16 #include <vector>
17 
18 namespace Belle2 {
23  class Module;
24 
84  class ProcessStatistics : public Mergeable {
85  public:
89  m_suspendedMemory(0) { }
90 
102  const std::vector<Belle2::ModuleStatistics>* modules = nullptr, bool html = false) const;
103 
105  const ModuleStatistics& getGlobal() const { return m_global; }
106 
108  const std::vector<Belle2::ModuleStatistics>& getAll() const { return m_stats; }
109 
112 
117  {
120  }
121 
124  {
127  }
128 
131  {
135  }
136 
138  void startModule()
139  {
141  }
142 
145  {
148  if (module && module->hasProperties(Module::c_DontCollectStatistics)) return;
149  m_stats[getIndex(module)].add(type, m_moduleTime, m_moduleMemory);
150  }
151 
155  void initModule(const Module* module);
156 
157 
164  {
165  return m_stats[getIndex(module)];
166  }
167 
169  int getIndex(const Module* module);
170 
172  virtual void merge(const Mergeable* other) override;
173 
175  virtual void clear() override;
176 
178  virtual TObject* Clone(const char* newname = "") const override;
179 
181  std::string getInfoHTML() const;
182 
183  private:
188 
190  void appendUnmergedModules(const ProcessStatistics* otherObject);
191 
193  void setTransientCounters(const ProcessStatistics* otherObject);
194 
202  void setCounters(double& time, double& memory,
203  double startTime = 0, double startMemory = 0);
204 
206  std::vector<Belle2::ModuleStatistics> m_stats;
209  std::map<const Module*, int> m_modulesToStatsIndex;
210 
211  //the following are used for the (process-local) time-keeping
212 
214  double m_globalTime;
216  double m_globalMemory;
218  double m_moduleTime;
220  double m_moduleMemory;
229 
231  };
232 
234 } //Belle2 namespace
Abstract base class for objects that can be merged.
Definition: Mergeable.h:31
Keep track of time and memory consumption during processing.
void add(EStatisticCounters type, value_type time, value_type memory)
Add a time and memory measurment to the counter of a given type.
EStatisticCounters
Enum to define all counter types.
@ c_Event
Counting time/calls in event()
Base class for Modules.
Definition: Module.h:72
@ c_DontCollectStatistics
No statistics is collected for this module.
Definition: Module.h:84
Class to collect call statistics for all modules.
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.
ModuleStatistics m_global
Statistics object for global time and memory consumption.
void stopGlobal(ModuleStatistics::EStatisticCounters type)
Stop global timer and add values to the statistic counter.
const std::vector< Belle2::ModuleStatistics > & getAll() const
Get entire statistics map.
void appendUnmergedModules(const ProcessStatistics *otherObject)
Merge dissimilar objects (mainly loading ProcessStatistics from file).
double m_globalTime
store clock counter for global time consumption
std::string getStatisticsString(ModuleStatistics::EStatisticCounters type=ModuleStatistics::c_Event, const std::vector< Belle2::ModuleStatistics > *modules=nullptr, bool html=false) const
Return string with statistics for all modules.
const ModuleStatistics & getGlobal() const
Get global statistics.
void startModule()
Start module timer.
int getIndex(const Module *module)
get m_stats index for given module, inserting it if not found.
double m_suspendedMemory
(transient)
void initModule(const Module *module)
Init module statistics: Set name from module if still empty and remember initialization index for dis...
virtual void merge(const Mergeable *other) override
Merge other ProcessStatistics object into this one.
std::map< const Module *, int > m_modulesToStatsIndex
transient, maps Module* to m_stats index.
ClassDefOverride(ProcessStatistics, 2)
(transient)
virtual TObject * Clone(const char *newname="") const override
Reimplement TObject::Clone() since we also need m_modulesToStatsIndex.
void suspendGlobal()
Suspend timer for global measurement, needed for newRun.
ModuleStatistics & getStatistics(const Module *module)
Get statistics for single module.
ProcessStatistics & operator=(ProcessStatistics &)
Prohibit assignment operator.
void stopModule(const Module *module, ModuleStatistics::EStatisticCounters type)
Stop module counter and attribute values to appropriate module.
ProcessStatistics(const ProcessStatistics &)=default
Hide copy constructor.
std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
std::vector< Belle2::ModuleStatistics > m_stats
module statistics
double m_suspendedTime
(transient)
double m_moduleTime
(transient)
void startGlobal()
Start timer for global measurement.
virtual void clear() override
Clear collected statistics but keep names of modules.
double m_globalMemory
(transient)
double m_moduleMemory
(transient)
void setTransientCounters(const ProcessStatistics *otherObject)
Set transient counters from otherObject.
void resumeGlobal()
Resume timer after call to suspendGlobal()
Abstract base class for different kinds of events.