Belle II Software  release-08-01-10
ModuleStatistics.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/utilities/CalcMeanCov.h>
12 #include <string>
13 
14 namespace Belle2 {
27  public:
41  c_Total
42  };
43 
45  typedef double value_type;
46 
48  explicit ModuleStatistics(const std::string& name = ""): m_index(0), m_name(name) {}
49 
55  void add(EStatisticCounters type, value_type time, value_type memory)
56  {
57  m_stats[type].add(time, memory);
58  if (type != c_Total)
59  m_stats[c_Total].add(time, memory);
60  }
61 
63  void update(const ModuleStatistics& other)
64  {
65  for (int i = c_Init; i <= c_Total; i++) {
66  m_stats[i].add(other.m_stats[i]);
67  }
68  }
69 
71  void setName(const std::string& name) { m_name = name; }
73  void setIndex(int index) { m_index = index; }
74 
76  const std::string& getName() const { return m_name; }
78  int getIndex() const { return m_index; }
79 
82  {
83  return m_stats[type].getEntries();
84  }
85 
88  {
89  return m_stats[type].getSum<0>();
90  }
93  {
94  return m_stats[type].getMean<0>();
95  }
98  {
99  return m_stats[type].getStddev<0>();
100  }
103  {
104  return m_stats[type].getSum<1>();
105  }
108  {
109  return m_stats[type].getMean<1>();
110  }
113  {
114  return m_stats[type].getStddev<1>();
115  }
119  {
120  return m_stats[type].getCorrelation<0, 1>();
121  }
122 
124  bool operator==(const ModuleStatistics& other) const { return m_name == other.m_name; }
126  bool operator!=(const ModuleStatistics& other) const { return !(*this == other); }
127 
129  void clear()
130  {
131  for (auto& stat : m_stats) stat.clear();
132  }
133  private:
135  int m_index;
137  std::string m_name;
140  };
141 
143 } //Belle2 namespace
value_type getCorrelation(int i, int j) const
Return the correlation coefficient between parameters i and j.
Definition: CalcMeanCov.h:130
value_type getStddev(int i) const
Return the standard deviation for parameter i.
Definition: CalcMeanCov.h:139
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
void add(T... values)
Update mean and covariance by adding a new entry.
Definition: CalcMeanCov.h:71
value_type getEntries() const
Return the number of entries.
Definition: CalcMeanCov.h:120
Keep track of time and memory consumption during processing.
value_type getTimeStddev(EStatisticCounters type=c_Total) const
return the stddev of the execution times for a given counter
value_type getCalls(EStatisticCounters type=c_Total) const
return the number of calls for a given counter type
value_type getTimeMemoryCorrelation(EStatisticCounters type=c_Total) const
return the pearson correlation coefficient between execution times and memory consumption changes
int getIndex() const
Return the index.
value_type getMemoryStddev(EStatisticCounters type=c_Total) const
return the stddev of the memory consumption changes per call
bool operator==(const ModuleStatistics &other) const
Check if name is identical.
void setIndex(int index)
Set the index of the module when displaying statistics.
ModuleStatistics(const std::string &name="")
Construct with a given name.
const std::string & getName() const
Return the previously set name.
void add(EStatisticCounters type, value_type time, value_type memory)
Add a time and memory measurment to the counter of a given type.
value_type getMemoryMean(EStatisticCounters type=c_Total) const
return the average memory change per call
void setName(const std::string &name)
Set the name of the module for display.
EStatisticCounters
Enum to define all counter types.
@ 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.
value_type getMemorySum(EStatisticCounters type=c_Total) const
return the total used memory for a given counter
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
double value_type
type of float variable to use for calculations and storage
bool operator!=(const ModuleStatistics &other) const
inequality.
void clear()
Clear all statistics.
CalcMeanCov< 2, value_type > m_stats[c_Total+1]
array with mean/covariance for all counters
int m_index
display index of the module
void update(const ModuleStatistics &other)
Add statistics for each category.
std::string m_name
name of module
Abstract base class for different kinds of events.