Belle II Software development
ProfileModule.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/core/Module.h>
12#include <vector>
13#include <functional>
14
15namespace Belle2 {
41 class ProfileModule : public Module {
42
43 public:
44
50
55 virtual void initialize() override;
56
61 virtual void event() override;
62
67 virtual void terminate() override;
68
69 private:
70
75 std::string m_outputFileName;
76
82
83 static const int k_burnIn = 1;
84 static const int k_maxPoints = 100;
89 struct MemTime {
93 MemTime(unsigned long vm = 0, unsigned long rssm = 0, double t = 0) : virtualMem(vm), rssMem(rssm), time(t) {};
94 unsigned long virtualMem;
95 unsigned long rssMem;
96 double time;
97 };
98
105 typedef std::function< unsigned long (MemTime const&) > MemoryExtractLambda;
106
110 const MemoryExtractLambda m_extractVirtualMem = [](MemTime const& m) { return m.virtualMem;};
111
115 const MemoryExtractLambda m_extractRssMem = [](MemTime const& m) { return m.rssMem;};
116
129 void storeMemoryGraph(const std::string& name, const std::string& title, const std::string& xAxisName, const std::string& imgOutput,
130 const MemoryExtractLambda& lmdMemoryExtract);
131
136 int m_step;
137 std::vector<MemTime> m_eventInfo;
141 };
143}
Base class for Modules.
Definition: Module.h:72
A module that measures the execution time and memory usage per event.
Definition: ProfileModule.h:41
const MemoryExtractLambda m_extractVirtualMem
Lambda expression to return the virtual memory from a MemTime data structure.
MemTime m_startInfo
memory usage and time at start of event loop + burn in
static const int k_maxPoints
maximal number of profile points
Definition: ProfileModule.h:84
static const int k_burnIn
number of events before the average time measurement is started
Definition: ProfileModule.h:83
virtual void initialize() override
Initializes the Module.
MemTime m_endInfo
memory usage and time at end of event loop
virtual void event() override
Event profiling.
std::function< unsigned long(MemTime const &) > MemoryExtractLambda
Signature of the lambda functions, which are used to extract the memory usage from teh MemTime struct...
virtual void terminate() override
Terminate the Module.
int m_step
number of events between profile points
std::vector< MemTime > m_eventInfo
memory usage and time at individual events
const MemoryExtractLambda m_extractRssMem
Lambda expression to return the Rss memory from a MemTime data structure.
MemTime m_terminateInfo
memory usage and time at termination
ProfileModule()
Constructor.
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.
std::string m_rssOutputFileName
Name for rss image output file.
Definition: ProfileModule.h:81
double m_timeOffset
time at module creation
MemTime m_initializeInfo
memory usage and time at initialization
std::string m_outputFileName
Name for image output file.
Definition: ProfileModule.h:75
int m_nEvents
event counter
Abstract base class for different kinds of events.
An internal struct to store pairs of memory usage and time.
Definition: ProfileModule.h:89
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:93
unsigned long virtualMem
virtual memory usage
Definition: ProfileModule.h:94
double time
execution time
Definition: ProfileModule.h:96
unsigned long rssMem
rss memory usage
Definition: ProfileModule.h:95