Belle II Software development
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
18namespace Belle2 {
23 class Module;
24
84 class ProcessStatistics : public Mergeable {
85 public:
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
121
128
136
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 void write_csv(const char* filename = "ProcessStatistics.csv") const;
170
172 int getIndex(const Module* module);
173
175 virtual void merge(const Mergeable* other) override;
176
178 virtual void clear() override;
179
181 virtual TObject* Clone(const char* newname = "") const override;
182
184 std::string getInfoHTML() const;
185
187 void setStatisticsPrintStatus(ModuleStatistics::EStatisticCounters type, bool printStatus) { m_statsPrintStatus[type] = printStatus; }
188
191
192 private:
197
199 void appendUnmergedModules(const ProcessStatistics* otherObject);
200
202 void setTransientCounters(const ProcessStatistics* otherObject);
203
211 void setCounters(double& time, double& memory,
212 double startTime = 0, double startMemory = 0);
213
215 std::vector<Belle2::ModuleStatistics> m_stats;
216
218 std::array < bool, ModuleStatistics::EStatisticCounters::c_Total + 1 > m_statsPrintStatus{};
219
221 std::map<const Module*, int> m_modulesToStatsIndex;
222
223 //the following are used for the (process-local) time-keeping
224
241
243 };
244
246} //Belle2 namespace
Abstract base class for objects that can be merged.
Definition Mergeable.h:31
Keep track of time and memory consumption during processing.
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
bool getStatisticsPrintStatus(ModuleStatistics::EStatisticCounters type)
Get print status of statistics.
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 ModuleStatistics & getGlobal() const
Get global statistics.
const std::vector< Belle2::ModuleStatistics > & getAll() const
Get entire statistics map.
std::array< bool, ModuleStatistics::EStatisticCounters::c_Total+1 > m_statsPrintStatus
array with print status of each statistics counter.
void appendUnmergedModules(const ProcessStatistics *otherObject)
Merge dissimilar objects (mainly loading ProcessStatistics from file).
double m_globalTime
store clock counter for global time consumption
ModuleStatistics & getStatistics(const Module *module)
Get statistics for single module.
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.
void setStatisticsPrintStatus(ModuleStatistics::EStatisticCounters type, bool printStatus)
Set print status of 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.
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.
void stopModule(const Module *module, ModuleStatistics::EStatisticCounters type)
Stop module counter and attribute values to appropriate module.
ProcessStatistics(const ProcessStatistics &)=default
Hide copy constructor.
void write_csv(const char *filename="ProcessStatistics.csv") const
Write process statistics to a csv file.
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)
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)
ProcessStatistics & operator=(ProcessStatistics &)
Prohibit assignment operator.
void setTransientCounters(const ProcessStatistics *otherObject)
Set transient counters from otherObject.
void resumeGlobal()
Resume timer after call to suspendGlobal()
ClassDefOverride(ProcessStatistics, 3)
(transient)
Abstract base class for different kinds of events.