Belle II Software development
ModuleStatistics Class Reference

Keep track of time and memory consumption during processing. More...

#include <ModuleStatistics.h>

Public Types

enum  EStatisticCounters {
  c_Init ,
  c_BeginRun ,
  c_Event ,
  c_EndRun ,
  c_Term ,
  c_Total
}
 Enum to define all counter types. More...
 
typedef double value_type
 type of float variable to use for calculations and storage
 

Public Member Functions

 ModuleStatistics (const std::string &name="")
 Construct with a given name.
 
void add (EStatisticCounters type, value_type time, value_type memory)
 Add a time and memory measurment to the counter of a given type.
 
void update (const ModuleStatistics &other)
 Add statistics for each category.
 
void setName (const std::string &name)
 Set the name of the module for display.
 
void setIndex (int index)
 Set the index of the module when displaying statistics.
 
const std::string & getName () const
 Return the previously set name.
 
int getIndex () const
 Return the index.
 
value_type getCalls (EStatisticCounters type=c_Total) const
 return the number of calls for a given counter type
 
value_type getTimeSum (EStatisticCounters type=c_Total) const
 return the sum of all execution times for a given counter
 
value_type getTimeMean (EStatisticCounters type=c_Total) const
 return the mean execution time for a given counter
 
value_type getTimeStddev (EStatisticCounters type=c_Total) const
 return the stddev of the execution times for a given counter
 
value_type getMemorySum (EStatisticCounters type=c_Total) const
 return the total used memory for a given counter
 
value_type getMemoryMean (EStatisticCounters type=c_Total) const
 return the average memory change per call
 
value_type getMemoryStddev (EStatisticCounters type=c_Total) const
 return the stddev of the memory consumption changes per call
 
value_type getTimeMemoryCorrelation (EStatisticCounters type=c_Total) const
 return the pearson correlation coefficient between execution times and memory consumption changes
 
void csv_header (std::ostream &output) const
 write csv header to the given stream
 
void csv (std::ostream &output) const
 write data to the given stream in csv format
 
bool operator== (const ModuleStatistics &other) const
 Check if name is identical.
 
bool operator!= (const ModuleStatistics &other) const
 inequality.
 
void clear ()
 Clear all statistics.
 

Private Attributes

int m_index
 display index of the module
 
std::string m_name
 name of module
 
CalcMeanCov< 2, value_typem_stats [c_Total+1]
 array with mean/covariance for all counters
 

Detailed Description

Keep track of time and memory consumption during processing.

This class offers a counter for time and memory consumption for all processing steps (initialize, beginRun, event, endRun, terminate and total). It will automatically calculate a running mean, stddev and correlation factor between time and memory consumption.

Definition at line 27 of file ModuleStatistics.h.

Member Typedef Documentation

◆ value_type

typedef double value_type

type of float variable to use for calculations and storage

Definition at line 46 of file ModuleStatistics.h.

Member Enumeration Documentation

◆ EStatisticCounters

Enum to define all counter types.

Enumerator
c_Init 

Counting time/calls in initialize()

c_BeginRun 

Counting time/calls in beginRun()

c_Event 

Counting time/calls in event()

c_EndRun 

Counting time/calls in endRun()

c_Term 

Counting time/calls in terminate()

c_Total 

Sum of the above.

Definition at line 30 of file ModuleStatistics.h.

30 {
32 c_Init,
36 c_Event,
40 c_Term,
43 };
@ c_Init
Counting time/calls in initialize()
@ c_EndRun
Counting time/calls in endRun()
@ c_Term
Counting time/calls in terminate()
@ c_BeginRun
Counting time/calls in beginRun()
@ c_Event
Counting time/calls in event()
@ c_Total
Sum of the above.

Constructor & Destructor Documentation

◆ ModuleStatistics()

ModuleStatistics ( const std::string &  name = "")
inlineexplicit

Construct with a given name.

Definition at line 49 of file ModuleStatistics.h.

49: m_index(0), m_name(name) {}
int m_index
display index of the module
std::string m_name
name of module

Member Function Documentation

◆ add()

void add ( EStatisticCounters  type,
value_type  time,
value_type  memory 
)
inline

Add a time and memory measurment to the counter of a given type.

Parameters
typeType of counter to add the value to
timetime used during execution
memorymemory size change during execution

Definition at line 56 of file ModuleStatistics.h.

57 {
58 m_stats[type].add(time, memory);
59 if (type != c_Total)
60 m_stats[c_Total].add(time, memory);
61 }
void add(T... values)
Update mean and covariance by adding a new entry.
Definition: CalcMeanCov.h:71
CalcMeanCov< 2, value_type > m_stats[c_Total+1]
array with mean/covariance for all counters

◆ clear()

void clear ( )
inline

Clear all statistics.

Definition at line 135 of file ModuleStatistics.h.

136 {
137 for (auto& stat : m_stats) stat.clear();
138 }

◆ csv()

void csv ( std::ostream &  output) const

write data to the given stream in csv format

Definition at line 25 of file ModuleStatistics.cc.

26{
27 output << m_name;
28
29 for (EStatisticCounters type = c_Init; type <= c_Total; type = EStatisticCounters(type + 1)) {
30 output << "," << m_stats[type].getSum<0>();
31 }
32 output << "," << m_stats[c_Event].getMean<0>() << "," << m_stats[c_Event].getStddev<0>();
33
34 for (EStatisticCounters type = c_Init; type <= c_Total; type = EStatisticCounters(type + 1)) {
35 output << "," << m_stats[type].getSum<1>();
36 }
37 output << "," << m_stats[c_Event].getMean<1>() << "," << m_stats[c_Event].getStddev<1>();
38
39 output << std::endl;
40}
value_type getMean(int i) const
Return the mean for parameter i.
Definition: CalcMeanCov.h:122
value_type getSum(int i) const
Return the weighted sum values for parameter i.
Definition: CalcMeanCov.h:141
EStatisticCounters
Enum to define all counter types.

◆ csv_header()

void csv_header ( std::ostream &  output) const

write csv header to the given stream

Definition at line 13 of file ModuleStatistics.cc.

14{
15 output << "name";
16 for (auto resource : {"time", "memory"}) {
17 for (auto type : {"init", "begin_run", "event", "end_run", "term", "total"}) {
18 output << "," << resource << " " << type;
19 }
20 output << "," << resource << " mean" << "," << resource << " stddev";
21 }
22 output << std::endl;
23}

◆ getCalls()

value_type getCalls ( EStatisticCounters  type = c_Total) const
inline

return the number of calls for a given counter type

Definition at line 82 of file ModuleStatistics.h.

83 {
84 return m_stats[type].getEntries();
85 }
value_type getEntries() const
Return the number of entries.
Definition: CalcMeanCov.h:120

◆ getIndex()

int getIndex ( ) const
inline

Return the index.

Definition at line 79 of file ModuleStatistics.h.

79{ return m_index; }

◆ getMemoryMean()

value_type getMemoryMean ( EStatisticCounters  type = c_Total) const
inline

return the average memory change per call

Definition at line 108 of file ModuleStatistics.h.

109 {
110 return m_stats[type].getMean<1>();
111 }

◆ getMemoryStddev()

value_type getMemoryStddev ( EStatisticCounters  type = c_Total) const
inline

return the stddev of the memory consumption changes per call

Definition at line 113 of file ModuleStatistics.h.

114 {
115 return m_stats[type].getStddev<1>();
116 }
value_type getStddev(int i) const
Return the standard deviation for parameter i.
Definition: CalcMeanCov.h:139

◆ getMemorySum()

value_type getMemorySum ( EStatisticCounters  type = c_Total) const
inline

return the total used memory for a given counter

Definition at line 103 of file ModuleStatistics.h.

104 {
105 return m_stats[type].getSum<1>();
106 }

◆ getName()

const std::string & getName ( ) const
inline

Return the previously set name.

Definition at line 77 of file ModuleStatistics.h.

77{ return m_name; }

◆ getTimeMean()

value_type getTimeMean ( EStatisticCounters  type = c_Total) const
inline

return the mean execution time for a given counter

Definition at line 93 of file ModuleStatistics.h.

94 {
95 return m_stats[type].getMean<0>();
96 }

◆ getTimeMemoryCorrelation()

value_type getTimeMemoryCorrelation ( EStatisticCounters  type = c_Total) const
inline

return the pearson correlation coefficient between execution times and memory consumption changes

Definition at line 119 of file ModuleStatistics.h.

120 {
121 return m_stats[type].getCorrelation<0, 1>();
122 }
value_type getCorrelation(int i, int j) const
Return the correlation coefficient between parameters i and j.
Definition: CalcMeanCov.h:130

◆ getTimeStddev()

value_type getTimeStddev ( EStatisticCounters  type = c_Total) const
inline

return the stddev of the execution times for a given counter

Definition at line 98 of file ModuleStatistics.h.

99 {
100 return m_stats[type].getStddev<0>();
101 }

◆ getTimeSum()

value_type getTimeSum ( EStatisticCounters  type = c_Total) const
inline

return the sum of all execution times for a given counter

Definition at line 88 of file ModuleStatistics.h.

89 {
90 return m_stats[type].getSum<0>();
91 }

◆ operator!=()

bool operator!= ( const ModuleStatistics other) const
inline

inequality.

Definition at line 132 of file ModuleStatistics.h.

132{ return !(*this == other); }

◆ operator==()

bool operator== ( const ModuleStatistics other) const
inline

Check if name is identical.

Definition at line 130 of file ModuleStatistics.h.

130{ return m_name == other.m_name; }

◆ setIndex()

void setIndex ( int  index)
inline

Set the index of the module when displaying statistics.

Definition at line 74 of file ModuleStatistics.h.

74{ m_index = index; }

◆ setName()

void setName ( const std::string &  name)
inline

Set the name of the module for display.

Definition at line 72 of file ModuleStatistics.h.

72{ m_name = name; }

◆ update()

void update ( const ModuleStatistics other)
inline

Add statistics for each category.

Definition at line 64 of file ModuleStatistics.h.

65 {
66 for (int i = c_Init; i <= c_Total; i++) {
67 m_stats[i].add(other.m_stats[i]);
68 }
69 }

Member Data Documentation

◆ m_index

int m_index
private

display index of the module

Definition at line 141 of file ModuleStatistics.h.

◆ m_name

std::string m_name
private

name of module

Definition at line 143 of file ModuleStatistics.h.

◆ m_stats

CalcMeanCov<2, value_type> m_stats[c_Total+1]
private

array with mean/covariance for all counters

Definition at line 145 of file ModuleStatistics.h.


The documentation for this class was generated from the following files: