9 #include <framework/modules/profile/ProfileModule.h> 
   10 #include <framework/dataobjects/ProfileInfo.h> 
   11 #include <framework/datastore/StoreObjPtr.h> 
   12 #include <framework/utilities/Utils.h> 
   13 #include <framework/gearbox/Unit.h> 
   33   m_nEvents(0), m_step(1),
 
   34   m_eventInfo(k_maxPoints)
 
   37   setDescription(
"Records execution time and memory usage in ProfileInfo objects for each event. Can also graph memory usage.");
 
   61   profileInfoStartPtr.
create(
true);
 
   64                              profileInfoStartPtr->getRssMemory(),
 
   65                              profileInfoStartPtr->getTimeInSec());
 
   73   profileInfoPtr.
create(
true);
 
   75   B2DEBUG(100, 
"Virtual Memory usage [MB]: " << profileInfoPtr->getVirtualMemory() / 1024);
 
   80                           profileInfoPtr->getRssMemory(),
 
   81                           profileInfoPtr->getTimeInSec());
 
   84                       profileInfoPtr->getRssMemory(),
 
   85                       profileInfoPtr->getTimeInSec());
 
  101                                  profileInfoPtr->getRssMemory(),
 
  102                                  profileInfoPtr->getTimeInSec());
 
  113   double factorMB = 1. / 1024;
 
  114   if (!imgOutput.empty()) {
 
  115     TDirectory* saveDir = gDirectory;
 
  117     auto* can = 
new TCanvas();
 
  118     auto* graph = 
new TGraph(nPoints);
 
  119     for (
int i = 0; i < nPoints; i++) {
 
  122     graph->SetMarkerStyle(kMultiply);
 
  124     TH1* histo = graph->GetHistogram();
 
  126     histo->GetYaxis()->SetTitle(yAxisName.c_str());
 
  127     histo->GetXaxis()->SetTitle(
"Time [s]");
 
  128     can->Print(imgOutput.c_str());
 
  137   profileHistogram->SetDirectory(
nullptr);
 
  138   profileHistogram->SetStats(
false);
 
  139   profileHistogram->GetYaxis()->SetTitle(yAxisName.c_str());
 
  140   profileHistogram->GetXaxis()->SetTitle(
"Event");
 
  141   profileHistogram->SetBinContent(1, lmdMemoryExtract(
m_initializeInfo) * factorMB);
 
  142   for (
int i = 0; i < nPoints; i++) {
 
  143     profileHistogram->SetBinContent(i + 2, lmdMemoryExtract(
m_eventInfo[i]) * factorMB);
 
  151   profileInfoEndPtr.
create(
true);
 
  154                             profileInfoEndPtr->getRssMemory(),
 
  155                             profileInfoEndPtr->getTimeInSec());
 
  168   storeMemoryGraph(
"VirtualMemoryProfile", 
"Virtual Memory usage", 
"Virtual Memory Usage [MB]",
 
  170   storeMemoryGraph(
"RssMemoryProfile", 
"Rss Memory usage", 
"Rss Memory Usage [MB]",
 
@ c_Persistent
Object is available during entire execution time.
void setDescription(const std::string &description)
Sets the description of the module.
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
static const int k_burnIn
number of events before the average time measurement is started
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.
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.
int m_nEvents
event counter
bool assign(TObject *object, bool replace=false)
Assign 'object' to this accessor.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Type-safe access to single objects in the data store.
static const double s
[second]
REG_MODULE(B2BIIConvertBeamParams)
Register the module.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
double getClock()
Return current value of the real-time clock.
Abstract base class for different kinds of events.
An internal struct to store pairs of memory usage and time.
unsigned long virtualMem
virtual memory usage
double time
execution time
unsigned long rssMem
rss memory usage