11 #include <framework/modules/profile/ProfileModule.h>
12 #include <framework/dataobjects/ProfileInfo.h>
13 #include <framework/datastore/StoreObjPtr.h>
14 #include <framework/utilities/Utils.h>
15 #include <framework/gearbox/Unit.h>
35 m_nEvents(0), m_step(1),
36 m_eventInfo(k_maxPoints)
39 setDescription(
"Records execution time and memory usage in ProfileInfo objects for each event. Can also graph memory usage.");
40 addParam(
"outputFileName", m_outputFileName,
"File name of virtual memory usage plot.", std::string(
""));
41 addParam(
"rssOutputFileName", m_rssOutputFileName,
"File name of rss memory usage plot.", std::string(
""));
56 profileInfoPtr.registerInDataStore();
57 profileInfoStartPtr.registerInDataStore();
58 profileInfoEndPtr.registerInDataStore();
59 virtprofileHistogram.registerInDataStore();
60 rssProfileHistogram.registerInDataStore();
63 profileInfoStartPtr.create(
true);
66 profileInfoStartPtr->getRssMemory(),
67 profileInfoStartPtr->getTimeInSec());
75 profileInfoPtr.create(
true);
77 B2DEBUG(100,
"Virtual Memory usage [MB]: " << profileInfoPtr->getVirtualMemory() / 1024);
82 profileInfoPtr->getRssMemory(),
83 profileInfoPtr->getTimeInSec());
86 profileInfoPtr->getRssMemory(),
87 profileInfoPtr->getTimeInSec());
103 profileInfoPtr->getRssMemory(),
104 profileInfoPtr->getTimeInSec());
115 double factorMB = 1. / 1024;
116 if (!imgOutput.empty()) {
117 TDirectory* saveDir = gDirectory;
119 auto* can =
new TCanvas();
120 auto* graph =
new TGraph(nPoints);
121 for (
int i = 0; i < nPoints; i++) {
124 graph->SetMarkerStyle(kMultiply);
126 TH1* histo = graph->GetHistogram();
128 histo->GetYaxis()->SetTitle(yAxisName.c_str());
129 histo->GetXaxis()->SetTitle(
"Time [s]");
130 can->Print(imgOutput.c_str());
138 profileHistogram.assign(
new TH1D(name.c_str(), title.c_str(), nPoints + 1, 0 - 0.5 *
m_step,
m_nEvents + 0.5 *
m_step),
true);
139 profileHistogram->SetDirectory(
nullptr);
140 profileHistogram->SetStats(
false);
141 profileHistogram->GetYaxis()->SetTitle(yAxisName.c_str());
142 profileHistogram->GetXaxis()->SetTitle(
"Event");
143 profileHistogram->SetBinContent(1, lmdMemoryExtract(
m_initializeInfo) * factorMB);
144 for (
int i = 0; i < nPoints; i++) {
145 profileHistogram->SetBinContent(i + 2, lmdMemoryExtract(
m_eventInfo[i]) * factorMB);
153 profileInfoEndPtr.create(
true);
156 profileInfoEndPtr->getRssMemory(),
157 profileInfoEndPtr->getTimeInSec());
170 storeMemoryGraph(
"VirtualMemoryProfile",
"Virtual Memory usage",
"Virtual Memory Usage [MB]",
172 storeMemoryGraph(
"RssMemoryProfile",
"Rss Memory usage",
"Rss Memory Usage [MB]",