Belle II Software light-2406-ragdoll
|
Class to collect call statistics for all modules. More...
#include <ProcessStatistics.h>
Public Member Functions | |
ProcessStatistics () | |
Constructor. | |
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. | |
const std::vector< Belle2::ModuleStatistics > & | getAll () const |
Get entire statistics map. | |
void | startGlobal () |
Start timer for global measurement. | |
void | suspendGlobal () |
Suspend timer for global measurement, needed for newRun. | |
void | resumeGlobal () |
Resume timer after call to suspendGlobal() | |
void | stopGlobal (ModuleStatistics::EStatisticCounters type) |
Stop global timer and add values to the statistic counter. | |
void | startModule () |
Start module timer. | |
void | stopModule (const Module *module, ModuleStatistics::EStatisticCounters type) |
Stop module counter and attribute values to appropriate module. | |
void | initModule (const Module *module) |
Init module statistics: Set name from module if still empty and remember initialization index for display. | |
ModuleStatistics & | getStatistics (const Module *module) |
Get statistics for single module. | |
int | getIndex (const Module *module) |
get m_stats index for given module, inserting it if not found. | |
virtual void | merge (const Mergeable *other) override |
Merge other ProcessStatistics object into this one. | |
virtual void | clear () override |
Clear collected statistics but keep names of modules. | |
virtual TObject * | Clone (const char *newname="") const override |
Reimplement TObject::Clone() since we also need m_modulesToStatsIndex. | |
std::string | getInfoHTML () const |
Return a short summary of this object's contents in HTML format. | |
virtual void | removeSideEffects () |
An ugly little method that is called before event() for input and worker processes. | |
virtual Long64_t | Merge (TCollection *hlist) |
Allow merging using TFileMerger if saved directly to a file. | |
virtual void | Reset () |
Root-like Reset function for "template compatibility" with ROOT objects. | |
virtual void | SetDirectory (TDirectory *) |
Root-like SetDirectory function for "template compatibility" with ROOT objects. | |
Private Member Functions | |
ProcessStatistics (const ProcessStatistics &)=default | |
Hide copy constructor. | |
ProcessStatistics & | operator= (ProcessStatistics &) |
Prohibit assignment operator. | |
void | appendUnmergedModules (const ProcessStatistics *otherObject) |
Merge dissimilar objects (mainly loading ProcessStatistics from file). | |
void | setTransientCounters (const ProcessStatistics *otherObject) |
Set transient counters from otherObject. | |
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. | |
ClassDefOverride (ProcessStatistics, 2) | |
(transient) | |
ClassDef (Mergeable, 0) | |
Abstract base class for objects that can be merged. | |
Private Attributes | |
ModuleStatistics | m_global |
Statistics object for global time and memory consumption. | |
std::vector< Belle2::ModuleStatistics > | m_stats |
module statistics | |
std::map< const Module *, int > | m_modulesToStatsIndex |
transient, maps Module* to m_stats index. | |
double | m_globalTime |
store clock counter for global time consumption | |
double | m_globalMemory |
(transient) | |
double | m_moduleTime |
(transient) | |
double | m_moduleMemory |
(transient) | |
double | m_suspendedTime |
(transient) | |
double | m_suspendedMemory |
(transient) | |
Class to collect call statistics for all modules.
This class is used to collect call and time statistics for all modules. It is implemented as a singleton and will keep track of the number of times a module will be called and the time the module spends in these calls.
Altough this class can be used in C++, its main purpose is to be used in python. In the python environment it is reachable through the "statistics" object in the pybasf2 module. Most simple use is to just print the event statistics after the process loop:
process(...) print(statistics)
Different types of statistics can be printed using
print(statistics(type))
where type can be one of
It is also possible to restrict the event statistics to a list of modules one is interested in
foo = register_module("Foo") bar = register_module("Bar")
...
process(...) print(statistics([foo,bar])) print(statistics([foo,bar],statistics.BEGIN_RUN))
More detailed statistics can be reached by accessing the statistics for all modules directly:
process(...) for stats in statistics.modules: print(stats.name, stats.time(statistics.EVENT), stats.calls(statistics.BEGIN_RUN))
Available attributes/methods for the statistics objects are
The global statistics for the framework can be accessed via statistics.framework
The name shown in the statistics can be modified. This is particular useful if there is more than one instance of a given module in the path
foo = register_module("Foo") statistics.set_name(foo,"Footastic")
Definition at line 84 of file ProcessStatistics.h.
|
inline |
Constructor.
Definition at line 87 of file ProcessStatistics.h.
|
private |
Merge dissimilar objects (mainly loading ProcessStatistics from file).
Definition at line 118 of file ProcessStatistics.cc.
|
private |
(transient)
Class to collect call statistics for all modules.
|
overridevirtual |
Clear collected statistics but keep names of modules.
Implements Mergeable.
Definition at line 197 of file ProcessStatistics.cc.
|
overridevirtual |
Reimplement TObject::Clone() since we also need m_modulesToStatsIndex.
Definition at line 210 of file ProcessStatistics.cc.
|
inline |
|
inline |
int getIndex | ( | const Module * | module | ) |
get m_stats index for given module, inserting it if not found.
Definition at line 26 of file ProcessStatistics.cc.
std::string getInfoHTML | ( | ) | const |
Return a short summary of this object's contents in HTML format.
Definition at line 216 of file ProcessStatistics.cc.
|
inline |
Get statistics for single module.
module | Shared pointer to the Module for which the statistics should be obtained |
Definition at line 163 of file ProcessStatistics.h.
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.
Can be used in steering file with 'print(statistics)'.
type | counter type to use for statistics |
modules | map of modules to use. If NULL, default map will be used |
html | if true return the output as html table instead of an ascii table |
Definition at line 53 of file ProcessStatistics.cc.
void initModule | ( | const Module * | module | ) |
Init module statistics: Set name from module if still empty and remember initialization index for display.
Definition at line 39 of file ProcessStatistics.cc.
|
overridevirtual |
Merge other ProcessStatistics object into this one.
Implements Mergeable.
Definition at line 166 of file ProcessStatistics.cc.
|
virtualinherited |
Allow merging using TFileMerger if saved directly to a file.
Definition at line 14 of file Mergeable.cc.
|
inlinevirtualinherited |
An ugly little method that is called before event() for input and worker processes.
Main use case is to detach any attached TFile from this object. In the output process, it can stay attached (and grow as much as it likes).
Reimplemented in RootMergeable< T >.
Definition at line 58 of file Mergeable.h.
|
inlinevirtualinherited |
Root-like Reset function for "template compatibility" with ROOT objects.
Alias for clear().
Definition at line 66 of file Mergeable.h.
|
inline |
Resume timer after call to suspendGlobal()
Definition at line 123 of file ProcessStatistics.h.
|
private |
Set counters time and memory to contain the current clock value and memory consumption respectively.
time | variable to store clock counter |
memory | variable to store heap size |
startTime | value to subtract from clock counter |
startMemory | value to subtract from heap size |
Definition at line 203 of file ProcessStatistics.cc.
|
inlinevirtualinherited |
Root-like SetDirectory function for "template compatibility" with ROOT objects.
Does nothing.
Definition at line 68 of file Mergeable.h.
|
private |
Set transient counters from otherObject.
Needed since we swap objects inside input modules.
Definition at line 187 of file ProcessStatistics.cc.
|
inline |
|
inline |
Start module timer.
Definition at line 138 of file ProcessStatistics.h.
|
inline |
Stop global timer and add values to the statistic counter.
Definition at line 130 of file ProcessStatistics.h.
|
inline |
Stop module counter and attribute values to appropriate module.
Definition at line 144 of file ProcessStatistics.h.
|
inline |
Suspend timer for global measurement, needed for newRun.
resumeGlobal should be called once endRun/newRun handling is finished
Definition at line 116 of file ProcessStatistics.h.
|
private |
Statistics object for global time and memory consumption.
Definition at line 205 of file ProcessStatistics.h.
|
private |
(transient)
store heap size for global memory consumption in KB
Definition at line 216 of file ProcessStatistics.h.
|
private |
store clock counter for global time consumption
Definition at line 214 of file ProcessStatistics.h.
|
private |
(transient)
store heap size for memory consumption by modules
Definition at line 220 of file ProcessStatistics.h.
|
private |
transient, maps Module* to m_stats index.
Definition at line 209 of file ProcessStatistics.h.
|
private |
(transient)
store clock counter for time consumption by modules
Definition at line 218 of file ProcessStatistics.h.
|
private |
module statistics
Definition at line 206 of file ProcessStatistics.h.
|
private |
(transient)
store heap size for suspended measurement. Generally this would be a stack of values but we know that we need at most one element so we keep it a plain double.
Definition at line 228 of file ProcessStatistics.h.
|
private |
(transient)
store clock counter for suspended measurement. Generally this would be a stack of values but we know that we need at most one element so we keep it a plain double.
Definition at line 224 of file ProcessStatistics.h.