Belle II Software  release-05-02-19
ProfileModule.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2011 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Kuhr *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/core/Module.h>
14 #include <vector>
15 #include <functional>
16 
17 namespace Belle2 {
43  class ProfileModule : public Module {
44 
45  public:
46 
52 
57  virtual void initialize() override;
58 
63  virtual void event() override;
64 
69  virtual void terminate() override;
70 
71  private:
72 
77  std::string m_outputFileName;
78 
83  std::string m_rssOutputFileName;
84 
85  static const int k_burnIn = 1;
86  static const int k_maxPoints = 100;
91  struct MemTime {
95  MemTime(unsigned long vm = 0, unsigned long rssm = 0, double t = 0) : virtualMem(vm), rssMem(rssm), time(t) {};
96  unsigned long virtualMem;
97  unsigned long rssMem;
98  double time;
99  };
100 
107  typedef std::function< unsigned long (MemTime const&) > MemoryExtractLambda;
108 
112  const MemoryExtractLambda m_extractVirtualMem = [](MemTime const& m) { return m.virtualMem;};
113 
117  const MemoryExtractLambda m_extractRssMem = [](MemTime const& m) { return m.rssMem;};
118 
131  void storeMemoryGraph(const std::string& name, const std::string& title, const std::string& xAxisName, const std::string& imgOutput,
132  const MemoryExtractLambda& lmdMemoryExtract);
133 
134  double m_timeOffset;
135  MemTime m_initializeInfo;
136  MemTime m_terminateInfo;
137  int m_nEvents;
138  int m_step;
139  std::vector<MemTime> m_eventInfo;
140  MemTime m_startInfo;
141  MemTime m_endInfo;
143  };
145 }
Belle2::ProfileModule::MemTime::time
double time
execution time
Definition: ProfileModule.h:106
Belle2::ProfileModule::MemTime::virtualMem
unsigned long virtualMem
virtual memory usage
Definition: ProfileModule.h:103
Belle2::ProfileModule::m_rssOutputFileName
std::string m_rssOutputFileName
Name for rss image output file.
Definition: ProfileModule.h:91
Belle2::ProfileModule::m_initializeInfo
MemTime m_initializeInfo
memory usage and time at initialization
Definition: ProfileModule.h:143
Belle2::ProfileModule::terminate
virtual void terminate() override
Terminate the Module.
Definition: ProfileModule.cc:149
Belle2::ProfileModule::MemTime::MemTime
MemTime(unsigned long vm=0, unsigned long rssm=0, double t=0)
Constructor with initialization of memory usage and time to zero.
Definition: ProfileModule.h:103
Belle2::ProfileModule::m_endInfo
MemTime m_endInfo
memory usage and time at end of event loop
Definition: ProfileModule.h:149
Belle2::ProfileModule::m_nEvents
int m_nEvents
event counter
Definition: ProfileModule.h:145
Belle2::ProfileModule::m_extractVirtualMem
const MemoryExtractLambda m_extractVirtualMem
Lambda expression to return the virtual memory from a MemTime data structure.
Definition: ProfileModule.h:120
Belle2::ProfileModule::MemTime
An internal struct to store pairs of memory usage and time.
Definition: ProfileModule.h:99
Belle2::ProfileModule::ProfileModule
ProfileModule()
Constructor.
Definition: ProfileModule.cc:34
Belle2::ProfileModule::k_burnIn
static const int k_burnIn
number of events before the average time measurement is started
Definition: ProfileModule.h:93
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ProfileModule::m_startInfo
MemTime m_startInfo
memory usage and time at start of event loop + burn in
Definition: ProfileModule.h:148
Belle2::ProfileModule::initialize
virtual void initialize() override
Initializes the Module.
Definition: ProfileModule.cc:44
Belle2::ProfileModule::m_outputFileName
std::string m_outputFileName
Name for image output file.
Definition: ProfileModule.h:85
Belle2::ProfileModule::m_timeOffset
double m_timeOffset
time at module creation
Definition: ProfileModule.h:142
Belle2::ProfileModule::m_step
int m_step
number of events between profile points
Definition: ProfileModule.h:146
Belle2::ProfileModule::event
virtual void event() override
Event profiling.
Definition: ProfileModule.cc:71
Belle2::ProfileModule::m_eventInfo
std::vector< MemTime > m_eventInfo
memory usage and time at individual events
Definition: ProfileModule.h:147
Belle2::ProfileModule::k_maxPoints
static const int k_maxPoints
maximal number of profile points
Definition: ProfileModule.h:94
Belle2::ProfileModule::MemTime::rssMem
unsigned long rssMem
rss memory usage
Definition: ProfileModule.h:105
Belle2::ProfileModule::m_extractRssMem
const MemoryExtractLambda m_extractRssMem
Lambda expression to return the Rss memory from a MemTime data structure.
Definition: ProfileModule.h:125
Belle2::ProfileModule::storeMemoryGraph
void storeMemoryGraph(const std::string &name, const std::string &title, const std::string &xAxisName, const std::string &imgOutput, const MemoryExtractLambda &lmdMemoryExtract)
Stores the memory usage of the application over time in plots.
Definition: ProfileModule.cc:110
Belle2::ProfileModule::MemoryExtractLambda
std::function< unsigned long(MemTime const &) > MemoryExtractLambda
Signature of the lambda functions, which are used to extract the memory usage from teh MemTime struct...
Definition: ProfileModule.h:115
Belle2::ProfileModule::m_terminateInfo
MemTime m_terminateInfo
memory usage and time at termination
Definition: ProfileModule.h:144