Belle II Software  release-05-02-19
ModuleStatistics.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/utilities/CalcMeanCov.h>
14 #include <string>
15 
16 namespace Belle2 {
28  class ModuleStatistics {
29  public:
31  enum EStatisticCounters {
33  c_Init,
35  c_BeginRun,
37  c_Event,
44  };
45 
47  typedef double value_type;
48 
50  explicit ModuleStatistics(const std::string& name = ""): m_index(0), m_name(name) {}
51 
57  void add(EStatisticCounters type, value_type time, value_type memory)
58  {
59  m_stats[type].add(time, memory);
60  if (type != c_Total)
61  m_stats[c_Total].add(time, memory);
62  }
63 
65  void update(const ModuleStatistics& other)
66  {
67  for (int i = c_Init; i <= c_Total; i++) {
68  m_stats[i].add(other.m_stats[i]);
69  }
70  }
71 
73  void setName(const std::string& name) { m_name = name; }
75  void setIndex(int index) { m_index = index; }
76 
78  const std::string& getName() const { return m_name; }
80  int getIndex() const { return m_index; }
81 
84  {
85  return m_stats[type].getEntries();
86  }
87 
90  {
91  return m_stats[type].getSum<0>();
92  }
95  {
96  return m_stats[type].getMean<0>();
97  }
100  {
101  return m_stats[type].getStddev<0>();
102  }
105  {
106  return m_stats[type].getSum<1>();
107  }
110  {
111  return m_stats[type].getMean<1>();
112  }
115  {
116  return m_stats[type].getStddev<1>();
117  }
121  {
122  return m_stats[type].getCorrelation<0, 1>();
123  }
124 
126  bool operator==(const ModuleStatistics& other) const { return m_name == other.m_name; }
128  bool operator!=(const ModuleStatistics& other) const { return !(*this == other); }
129 
131  void clear()
132  {
133  for (auto& stat : m_stats) stat.clear();
134  }
135  private:
137  int m_index;
139  std::string m_name;
142  };
143 
145 } //Belle2 namespace
Belle2::ModuleStatistics::operator!=
bool operator!=(const ModuleStatistics &other) const
inequality.
Definition: ModuleStatistics.h:136
Belle2::ModuleStatistics::m_index
int m_index
display index of the module
Definition: ModuleStatistics.h:145
Belle2::CalcMeanCov::getCorrelation
value_type getCorrelation(int i, int j) const
Return the correlation coefficient between parameters i and j.
Definition: CalcMeanCov.h:140
Belle2::CalcMeanCov::add
void add(T... values)
Update mean and covariance by adding a new entry.
Definition: CalcMeanCov.h:81
Belle2::ModuleStatistics::c_Event
@ c_Event
Counting time/calls in event()
Definition: ModuleStatistics.h:45
Belle2::ModuleStatistics::c_EndRun
@ c_EndRun
Counting time/calls in endRun()
Definition: ModuleStatistics.h:47
Belle2::CalcMeanCov::getEntries
value_type getEntries() const
Return the number of entries.
Definition: CalcMeanCov.h:130
Belle2::ModuleStatistics::EStatisticCounters
EStatisticCounters
Enum to define all counter types.
Definition: ModuleStatistics.h:39
Belle2::ModuleStatistics::getMemorySum
value_type getMemorySum(EStatisticCounters type=c_Total) const
return the total used memory for a given counter
Definition: ModuleStatistics.h:112
Belle2::ModuleStatistics::ModuleStatistics
ModuleStatistics(const std::string &name="")
Construct with a given name.
Definition: ModuleStatistics.h:58
Belle2::ModuleStatistics::clear
void clear()
Clear all statistics.
Definition: ModuleStatistics.h:139
Belle2::ModuleStatistics::update
void update(const ModuleStatistics &other)
Add statistics for each category.
Definition: ModuleStatistics.h:73
Belle2::ModuleStatistics::m_stats
CalcMeanCov< 2, value_type > m_stats[c_Total+1]
array with mean/covariance for all counters
Definition: ModuleStatistics.h:149
Belle2::ModuleStatistics::m_name
std::string m_name
name of module
Definition: ModuleStatistics.h:147
Belle2::ModuleStatistics::c_Term
@ c_Term
Counting time/calls in terminate()
Definition: ModuleStatistics.h:49
Belle2::ModuleStatistics::c_Total
@ c_Total
Sum of the above.
Definition: ModuleStatistics.h:51
Belle2::CalcMeanCov::getMean
value_type getMean(int i) const
Return the mean for parameter i.
Definition: CalcMeanCov.h:132
Belle2::ModuleStatistics::getMemoryStddev
value_type getMemoryStddev(EStatisticCounters type=c_Total) const
return the stddev of the memory consumption changes per call
Definition: ModuleStatistics.h:122
Belle2::ModuleStatistics::getName
const std::string & getName() const
Return the previously set name.
Definition: ModuleStatistics.h:86
Belle2::ModuleStatistics::setIndex
void setIndex(int index)
Set the index of the module when displaying statistics.
Definition: ModuleStatistics.h:83
Belle2::ModuleStatistics::setName
void setName(const std::string &name)
Set the name of the module for display.
Definition: ModuleStatistics.h:81
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ModuleStatistics::add
void add(EStatisticCounters type, value_type time, value_type memory)
Add a time and memory measurment to the counter of a given type.
Definition: ModuleStatistics.h:65
Belle2::ModuleStatistics::getIndex
int getIndex() const
Return the index.
Definition: ModuleStatistics.h:88
Belle2::ModuleStatistics::getMemoryMean
value_type getMemoryMean(EStatisticCounters type=c_Total) const
return the average memory change per call
Definition: ModuleStatistics.h:117
Belle2::CalcMeanCov::getSum
value_type getSum(int i) const
Return the weighted sum values for parameter i.
Definition: CalcMeanCov.h:151
Belle2::ModuleStatistics::value_type
double value_type
type of float variable to use for calculations and storage
Definition: ModuleStatistics.h:55
Belle2::ModuleStatistics::c_BeginRun
@ c_BeginRun
Counting time/calls in beginRun()
Definition: ModuleStatistics.h:43
Belle2::ModuleStatistics::operator==
bool operator==(const ModuleStatistics &other) const
Check if name is identical.
Definition: ModuleStatistics.h:134
Belle2::CalcMeanCov< 2, value_type >
Belle2::CalcMeanCov::getStddev
value_type getStddev(int i) const
Return the standard deviation for parameter i.
Definition: CalcMeanCov.h:149
Belle2::ModuleStatistics::getTimeMemoryCorrelation
value_type getTimeMemoryCorrelation(EStatisticCounters type=c_Total) const
return the pearson correlation coefficient between execution times and memory consumption changes
Definition: ModuleStatistics.h:128
Belle2::ModuleStatistics::getCalls
value_type getCalls(EStatisticCounters type=c_Total) const
return the number of calls for a given counter type
Definition: ModuleStatistics.h:91
Belle2::ModuleStatistics::getTimeMean
value_type getTimeMean(EStatisticCounters type=c_Total) const
return the mean execution time for a given counter
Definition: ModuleStatistics.h:102
Belle2::ModuleStatistics::getTimeStddev
value_type getTimeStddev(EStatisticCounters type=c_Total) const
return the stddev of the execution times for a given counter
Definition: ModuleStatistics.h:107
Belle2::ModuleStatistics::getTimeSum
value_type getTimeSum(EStatisticCounters type=c_Total) const
return the sum of all execution times for a given counter
Definition: ModuleStatistics.h:97
Belle2::ModuleStatistics
Keep track of time and memory consumption during processing.
Definition: ModuleStatistics.h:36
Belle2::ModuleStatistics::c_Init
@ c_Init
Counting time/calls in initialize()
Definition: ModuleStatistics.h:41