CMS 3D CMS Logo

DQMStoreStats.cc
Go to the documentation of this file.
1 /*
2  * \file DQMStoreStats.cc
3  * \author Andreas Meyer
4  * Last Update:
5  *
6  * Description: Print out statistics of histograms in DQMStore
7 */
8 
9 #include "DQMStoreStats.h"
12 
13 using namespace std;
14 using namespace edm;
15 
16 template <class T>
17 static unsigned int getEmptyMetric(T* array, int lenx, int leny, int lenz) {
18  // len{x,y,z} MUST include under/overflow bins.
19  unsigned int len = lenx + leny + lenz;
20  unsigned int result = 0;
21  // start from 1 to exclude underflow bin. The comparison is accurate
22  // since it takes properly into account under/overflow bins, for all
23  // kind of histograms.
24  for (unsigned int i = 1; i < len; ++i) {
25  // get rid of under/overflow bins for x,y,z axis, to have a correct statistics.
26  if (i % (lenx - 1) == 0)
27  continue;
28  if (i % lenx == 0)
29  continue;
30  if (i % (lenx + leny - 1) == 0)
31  continue;
32  if (i % (lenx + leny) == 0)
33  continue;
34  if (i % (lenx + leny + lenz - 1) == 0)
35  continue;
36 
37  if (array[i] == 0)
38  result += 1;
39  }
40 
41  return result;
42 }
43 
44 //==================================================================//
45 //================= Constructor and Destructor =====================//
46 //==================================================================//
48  : subsystem_(""),
49  subfolder_(""),
50  nbinsglobal_(0),
51  nbinssubsys_(0),
52  nmeglobal_(0),
53  nmesubsys_(0),
54  maxbinsglobal_(0),
55  maxbinssubsys_(0),
56  maxbinsmeglobal_(""),
57  maxbinsmesubsys_(""),
58  statsdepth_(1),
59  pathnamematch_(""),
60  verbose_(0) {
61  parameters_ = ps;
63  statsdepth_ = ps.getUntrackedParameter<int>("statsDepth", statsdepth_);
64  verbose_ = ps.getUntrackedParameter<int>("verbose", verbose_);
65  dumpMemHistory_ = ps.getUntrackedParameter<bool>("dumpMemoryHistory", false);
66  runonendrun_ = ps.getUntrackedParameter<bool>("runOnEndRun", true);
67  runonendjob_ = ps.getUntrackedParameter<bool>("runOnEndJob", false);
68  runonendlumi_ = ps.getUntrackedParameter<bool>("runOnEndLumi", false);
69  runineventloop_ = ps.getUntrackedParameter<bool>("runInEventLoop", false);
70  dumpToFWJR_ = ps.getUntrackedParameter<bool>("dumpToFWJR", false);
71 
72  startingTime_ = time(nullptr);
73 }
74 
76 
78  std::ofstream stream("dqm-bin-stats.sql");
79  stream << ""
80  " PRAGMA journal_mode=OFF;"
81  " PRAGMA count_changes=OFF;"
82  " DROP TABLE IF EXISTS files;"
83  " DROP TABLE IF EXISTS symbols;"
84  " DROP TABLE IF EXISTS mainrows;"
85  " DROP TABLE IF EXISTS children;"
86  " DROP TABLE IF EXISTS parents;"
87  " DROP TABLE IF EXISTS summary;"
88  " CREATE TABLE children ("
89  " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id),"
90  " parent_id INTEGER CONSTRAINT parent_exists REFERENCES mainrows(id),"
91  " from_parent_count INTEGER,"
92  " from_parent_calls INTEGER,"
93  " from_parent_paths INTEGER,"
94  " pct REAL"
95  " );"
96  " CREATE TABLE files ("
97  " id,"
98  " name TEXT"
99  " );"
100  " CREATE TABLE mainrows ("
101  " id INTEGER PRIMARY KEY,"
102  " symbol_id INTEGER CONSTRAINT symbol_id_exists REFERENCES symbols(id),"
103  " self_count INTEGER,"
104  " cumulative_count INTEGER,"
105  " kids INTEGER,"
106  " self_calls INTEGER,"
107  " total_calls INTEGER,"
108  " self_paths INTEGER,"
109  " total_paths INTEGER,"
110  " pct REAL"
111  " );"
112  " CREATE TABLE parents ("
113  " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id),"
114  " child_id INTEGER CONSTRAINT child_exists REFERENCES mainrows(id),"
115  " to_child_count INTEGER,"
116  " to_child_calls INTEGER,"
117  " to_child_paths INTEGER,"
118  " pct REAL"
119  " );"
120  " CREATE TABLE summary ("
121  " counter TEXT,"
122  " total_count INTEGER,"
123  " total_freq INTEGER,"
124  " tick_period REAL"
125  " );"
126  " CREATE TABLE symbols ("
127  " id,"
128  " name TEXT,"
129  " filename_id INTEGER CONSTRAINT file_id_exists REFERENCES files(id)"
130  " );"
131  " CREATE UNIQUE INDEX fileIndex ON files (id);"
132  " CREATE INDEX selfCountIndex ON mainrows(self_count);"
133  " CREATE UNIQUE INDEX symbolsIndex ON symbols (id);"
134  " CREATE INDEX totalCountIndex ON mainrows(cumulative_count);"
135  << std::endl;
136 
137  std::string sql_statement("");
138 
139  root.files(sql_statement);
140  root.symbols(sql_statement);
141  root.mainrows_cumulative(sql_statement);
142  root.summary(sql_statement);
143  VIterator<Folder*> subsystems = root.CreateIterator();
144  size_t ii = 0;
145  for (subsystems.First(); !subsystems.IsDone(); subsystems.Next(), ++ii) {
146  subsystems.CurrentItem()->mainrows(sql_statement);
147  subsystems.CurrentItem()->parents(sql_statement);
148  subsystems.CurrentItem()->children(sql_statement);
149  }
150  stream << sql_statement << std::endl;
151 }
152 
161  nbinsglobal_ = 0;
162  nbinssubsys_ = 0;
163  maxbinsglobal_ = 0;
164  maxbinssubsys_ = 0;
165  std::string path = "";
166  std::string subsystemname = "";
167  std::string subfoldername = "";
168  size_t subsysStringEnd = 0, subfolderStringBegin = 0, subfolderStringEnd = 0;
169 
170  std::vector<MonitorElement*> melist;
172 
173  Folder dbeFolder("root");
174  DQMStoreStatsTopLevel dqmStoreStatsTopLevel;
175 
176  // loop all ME
177  for (auto& it : melist) {
178  // consider only ME with getLumiFlag() == true ?
179  if (mode == DQMStoreStats::considerOnlyLumiProductME && !(it->getLumiFlag()))
180  continue;
181 
182  // figure out subsystem/subfolder names
183  const std::string& path = it->getPathname();
184 
185  subfolderStringBegin = 0;
186  Folder* curr = &dbeFolder;
187  while (true) {
188  subfolderStringEnd = path.find('/', subfolderStringBegin);
189  if (std::string::npos == subfolderStringEnd) {
190  curr = curr->cd(path.substr(subfolderStringBegin, path.size() - subfolderStringBegin));
191  break;
192  }
193  curr = curr->cd(path.substr(subfolderStringBegin, subfolderStringEnd - subfolderStringBegin));
194  subfolderStringBegin = ++subfolderStringEnd < path.size() ? subfolderStringEnd : path.size();
195  }
196 
197  // protection against ghost ME with empty paths
198  if (path.empty())
199  continue;
200 
201  subsysStringEnd = path.find('/', 0);
202  if (std::string::npos == subsysStringEnd)
203  subsysStringEnd = path.size(); // no subfolder
204 
205  // new subsystem?
206  if (path.substr(0, subsysStringEnd) != subsystemname) {
207  DQMStoreStatsSubsystem aSubsystem;
208  subsystemname = path.substr(0, subsysStringEnd);
209  aSubsystem.subsystemName_ = subsystemname;
210  dqmStoreStatsTopLevel.push_back(aSubsystem);
211  subfoldername = "";
212  }
213 
214  // get subfolder name (if there is one..)
215  if (path.size() == subsysStringEnd) {
216  // no subfolders in subsystem, make dummy
217  DQMStoreStatsSubfolder aSubfolder;
218  aSubfolder.subfolderName_ = subsystemname; // <-- for tagging this case
219  dqmStoreStatsTopLevel.back().push_back(aSubfolder);
220  }
221 
222  else {
223  // there is a subfolder, get its name
224  subfolderStringEnd = path.find('/', subsysStringEnd + 1);
225  if (std::string::npos == subfolderStringEnd)
226  subfolderStringEnd = path.size();
227 
228  // new subfolder?
229  if (path.substr(subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1) != subfoldername) {
230  subfoldername = path.substr(subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1);
231  DQMStoreStatsSubfolder aSubfolder;
232  aSubfolder.subfolderName_ = subfoldername;
233  dqmStoreStatsTopLevel.back().push_back(aSubfolder);
234  }
235  }
236 
237  // shortcut
238  DQMStoreStatsSubfolder& currentSubfolder = dqmStoreStatsTopLevel.back().back();
239 
240  switch (it->kind()) {
241  // one-dim ME
243  currentSubfolder.AddBinsF(it->getNbinsX(), getEmptyMetric(it->getTH1F()->GetArray(), it->getTH1F()->fN, 0, 0));
244  curr->update(it->getNbinsX(),
245  getEmptyMetric(it->getTH1F()->GetArray(), it->getTH1F()->fN, 0, 0),
246  it->getNbinsX() * sizeof(float));
247  break;
249  currentSubfolder.AddBinsS(it->getNbinsX(), getEmptyMetric(it->getTH1S()->GetArray(), it->getTH1S()->fN, 0, 0));
250  curr->update(it->getNbinsX(),
251  getEmptyMetric(it->getTH1S()->GetArray(), it->getTH1S()->fN, 0, 0),
252  it->getNbinsX() * sizeof(short));
253  break;
255  currentSubfolder.AddBinsD(it->getNbinsX(), getEmptyMetric(it->getTH1D()->GetArray(), it->getTH1D()->fN, 0, 0));
256  curr->update(it->getNbinsX(),
257  getEmptyMetric(it->getTH1D()->GetArray(), it->getTH1D()->fN, 0, 0),
258  it->getNbinsX() * sizeof(double));
259  break;
261  currentSubfolder.AddBinsD(it->getNbinsX(),
262  getEmptyMetric(it->getTProfile()->GetArray(), it->getTProfile()->fN, 0, 0));
263  curr->update(it->getNbinsX(),
264  getEmptyMetric(it->getTProfile()->GetArray(), it->getTProfile()->fN, 0, 0),
265  it->getNbinsX() * sizeof(double));
266  break;
267 
268  // two-dim ME
270  currentSubfolder.AddBinsF(
271  it->getNbinsX() * it->getNbinsY(),
272  getEmptyMetric(it->getTH2F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
273  curr->update(it->getNbinsX() * it->getNbinsY(),
274  getEmptyMetric(it->getTH2F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
275  it->getNbinsX() * it->getNbinsY() * sizeof(float));
276  break;
278  currentSubfolder.AddBinsS(
279  it->getNbinsX() * it->getNbinsY(),
280  getEmptyMetric(it->getTH2S()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
281  curr->update(it->getNbinsX() * it->getNbinsY(),
282  getEmptyMetric(it->getTH2S()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
283  it->getNbinsX() * it->getNbinsY() * sizeof(short));
284  break;
286  currentSubfolder.AddBinsD(
287  it->getNbinsX() * it->getNbinsY(),
288  getEmptyMetric(it->getTH2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
289  curr->update(it->getNbinsX() * it->getNbinsY(),
290  getEmptyMetric(it->getTH2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
291  it->getNbinsX() * it->getNbinsY() * sizeof(double));
292  break;
294  currentSubfolder.AddBinsD(
295  it->getNbinsX() * it->getNbinsY(),
296  getEmptyMetric(it->getTProfile2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
297  curr->update(it->getNbinsX() * it->getNbinsY(),
298  getEmptyMetric(it->getTProfile2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
299  it->getNbinsX() * it->getNbinsY() * sizeof(double));
300  break;
301 
302  // three-dim ME
304  currentSubfolder.AddBinsF(
305  it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(),
306  getEmptyMetric(it->getTH3F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, it->getNbinsZ() + 2));
307  curr->update(
308  it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(),
309  getEmptyMetric(it->getTH3F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, it->getNbinsZ() + 2),
310  it->getNbinsX() * it->getNbinsY() * it->getNbinsZ() * sizeof(float));
311  break;
312 
313  default: {
314  }
315  // here we have a DQM_KIND_INVALID, DQM_KIND_INT, DQM_KIND_REAL or DQM_KIND_STRING
316  // which we don't care much about. Alternatively:
317 
318  // std::cerr << "[DQMStoreStats::calcstats] ** WARNING: monitor element of kind: "
319  // << (*it)->kind() << ", name: \"" << (*it)->getName() << "\"\n"
320  // << " in path: \"" << path << "\" not considered." << std::endl;
321  }
322  }
323 
325  calcIgProfDump(dbeFolder);
326 
327  // OUTPUT
328 
329  std::cout << endl;
330  std::cout << "==========================================================================================="
331  << std::endl;
332  std::cout << "[DQMStoreStats::calcstats] -- Dumping stats results ";
334  std::cout << "FOR ALL ME" << std::endl;
336  std::cout << "FOR LUMI PRODUCTS ONLY" << std::endl;
337  std::cout << "==========================================================================================="
338  << std::endl;
339  std::cout << endl;
340 
341  std::cout << "------------------------------------------------------------------------------------------"
342  << std::endl;
343  std::cout << "Configuration:" << std::endl;
344  std::cout << "------------------------------------------------------------------------------------------"
345  << std::endl;
346  std::cout << " > running ";
347  if (runonendrun_)
348  std::cout << "on run end." << std::endl;
349  if (runonendlumi_)
350  std::cout << "on lumi end." << std::endl;
351  if (runonendjob_)
352  std::cout << "on job end." << std::endl;
353  if (runineventloop_)
354  std::cout << "in event loop." << std::endl;
355  std::cout << " > pathNameMatch = \"" << pathnamematch_ << "\"" << std::endl;
356  std::cout << std::endl;
357 
358  // dump folder structure
359  std::cout << "------------------------------------------------------------------------------------------"
360  << std::endl;
361  std::cout << "Top level folder tree:" << std::endl;
362  std::cout << "------------------------------------------------------------------------------------------"
363  << std::endl;
364  for (auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
365  std::cout << it0->subsystemName_ << " (subsystem)" << std::endl;
366 
367  for (auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
368  std::cout << " |--> " << it1->subfolderName_ << " (subfolder)" << std::endl;
369  }
370  }
371 
372  // dump mem/bin table
373 
374  unsigned int overallNHistograms = 0, overallNBins = 0, overallNEmptyBins = 0, overallNBytes = 0;
375 
376  std::cout << std::endl;
377  std::cout << "------------------------------------------------------------------------------------------"
378  << std::endl;
379  std::cout << "Detailed ressource usage information ";
381  std::cout << "FOR ALL ME" << std::endl;
383  std::cout << "FOR LUMI PRODUCTS ONLY" << std::endl;
384  std::cout << "------------------------------------------------------------------------------------------"
385  << std::endl;
386  std::cout << "subsystem/folder histograms bins Empty bins Empty/Total "
387  "bins per MB kB per"
388  << std::endl;
389  std::cout << " (total) (total) (total) "
390  "histogram (total) histogram "
391  << std::endl;
392  std::cout << "------------------------------------------------------------------------------------------"
393  << std::endl;
394  for (auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
395  std::cout << it0->subsystemName_ << std::endl;
396 
397  unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
398 
399  for (auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
400  // fixed-size working copy
401  std::string thisSubfolderName(it1->subfolderName_);
402  if (thisSubfolderName.size() > 30) {
403  thisSubfolderName.resize(30);
404  thisSubfolderName.replace(thisSubfolderName.size() - 3, 3, 3, '.');
405  }
406 
407  std::cout << " -> " << std::setw(30) << std::left << thisSubfolderName;
408  std::cout << std::setw(14) << std::right << it1->totalHistos_;
409  std::cout << std::setw(14) << std::right << it1->totalBins_;
410  std::cout << std::setw(14) << std::right << it1->totalEmptyBins_;
411  std::cout << std::setw(14) << std::right << std::setprecision(3)
412  << (float)it1->totalEmptyBins_ / (float)it1->totalBins_;
413 
414  // bins/histogram, need to catch nan if histos=0
415  if (it1->totalHistos_) {
416  std::cout << std::setw(14) << std::right << std::setprecision(3) << it1->totalBins_ / float(it1->totalHistos_);
417  } else
418  std::cout << std::setw(14) << std::right << "-";
419 
420  std::cout << std::setw(14) << std::right << std::setprecision(3) << it1->totalMemory_ / 1024. / 1024.;
421 
422  // mem/histogram, need to catch nan if histos=0
423  if (it1->totalHistos_) {
424  std::cout << std::setw(14) << std::right << std::setprecision(3)
425  << it1->totalMemory_ / 1024. / it1->totalHistos_;
426  } else
427  std::cout << std::setw(14) << std::right << "-";
428 
429  std::cout << std::endl;
430 
431  // collect totals
432  nHistograms += it1->totalHistos_;
433  nBins += it1->totalBins_;
434  nEmptyBins += it1->totalEmptyBins_;
435  nBytes += it1->totalMemory_;
436  }
437 
438  overallNHistograms += nHistograms;
439  overallNBins += nBins;
440  overallNEmptyBins += nEmptyBins;
441  overallNBytes += nBytes;
442 
443  // display totals
444  std::cout << " " << std::setw(30) << std::left << "SUBSYSTEM TOTAL";
445  std::cout << std::setw(14) << std::right << nHistograms;
446  std::cout << std::setw(14) << std::right << nBins;
447  std::cout << std::setw(14) << std::right << nEmptyBins;
448  std::cout << std::setw(14) << std::right << (float)nEmptyBins / (float)nBins;
449  std::cout << std::setw(14) << std::right << std::setprecision(3) << nBins / float(nHistograms);
450  std::cout << std::setw(14) << std::right << std::setprecision(3) << nBytes / 1024. / 1000.;
451  std::cout << std::setw(14) << std::right << std::setprecision(3) << nBytes / 1024. / nHistograms;
452  std::cout << std::endl;
453 
454  std::cout << ".........................................................................................."
455  << std::endl;
456  }
457 
458  // dump total
459  std::cout << std::endl;
460  std::cout << "------------------------------------------------------------------------------------------"
461  << std::endl;
462  std::cout << "Grand total ";
464  std::cout << "FOR ALL ME:" << std::endl;
466  std::cout << "FOR LUMI PRODUCTS ONLY:" << std::endl;
467  std::cout << "------------------------------------------------------------------------------------------"
468  << std::endl;
469  std::cout << "Number of subsystems: " << dqmStoreStatsTopLevel.size() << std::endl;
470  std::cout << "Total number of histograms: " << overallNHistograms << " with: " << overallNBins << " bins alltogether"
471  << std::endl;
472  std::cout << "Total memory occupied by histograms (excl. overhead): " << overallNBytes / 1024. / 1000. << " MB"
473  << std::endl;
474 
475  std::cout << endl;
476  std::cout << "==========================================================================================="
477  << std::endl;
478  std::cout << "[DQMStoreStats::calcstats] -- End of output ";
480  std::cout << "FOR ALL ME." << std::endl;
482  std::cout << "FOR LUMI PRODUCTS ONLY." << std::endl;
483  std::cout << "==========================================================================================="
484  << std::endl;
485  std::cout << endl;
486 
487  // Put together a simplified version of the complete dump that is
488  // sent to std::cout. Just dump the very basic information,
489  // i.e. summary for each folder, both for run and LS products.
490  if (dumpToFWJR_) {
492  // Do not even try if the FWJR service is not available.
493  if (!jr.isAvailable())
494  return 0;
495  // Prepare appropriate map to store FWJR output.
496  std::map<std::string, std::string> jrInfo;
497  unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
498 
499  jrInfo["Source"] = "DQMServices/Components";
500  jrInfo["FileClass"] = "DQMStoreStats";
501  if (runonendrun_)
502  jrInfo["DumpType"] = "EndRun";
503  if (runonendlumi_)
504  jrInfo["DumpType"] = "EndLumi";
505  if (runonendjob_)
506  jrInfo["DumpType"] = "EndJob";
507  if (runineventloop_)
508  jrInfo["DumpType"] = "EventLoop";
510  jrInfo["Type"] = "RunProduct";
512  jrInfo["Type"] = "LumiProduct";
513 
514  jrInfo["pathNameMatch"] = pathnamematch_;
515 
516  for (auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
517  unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
518  for (auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
519  // collect totals
520  nHistograms += it1->totalHistos_;
521  nBins += it1->totalBins_;
522  nEmptyBins += it1->totalEmptyBins_;
523  nBytes += it1->totalMemory_;
524  }
525  overallNHistograms += nHistograms;
526  overallNBins += nBins;
527  overallNBytes += nBytes;
528  std::stringstream iss("");
529  iss << nHistograms;
530  jrInfo[it0->subsystemName_ + std::string("_h")] = iss.str();
531  iss.str("");
532  iss << nBins;
533  jrInfo[it0->subsystemName_ + std::string("_b")] = iss.str();
534  iss.str("");
535  iss << nEmptyBins;
536  jrInfo[it0->subsystemName_ + std::string("_be")] = iss.str();
537  iss.str("");
538  iss << ((float)nEmptyBins / (float)nBins);
539  jrInfo[it0->subsystemName_ + std::string("_fbe")] = iss.str();
540  iss.str("");
541  iss << ((float)nBins / (float)nHistograms);
542  jrInfo[it0->subsystemName_ + std::string("_b_h")] = iss.str();
543  iss.str("");
544  iss << nBytes / 1024. / 1024.;
545  jrInfo[it0->subsystemName_ + std::string("_MB")] = iss.str();
546  iss.str("");
547  iss << nBytes / 1024. / nHistograms;
548  jrInfo[it0->subsystemName_ + std::string("_Kb_h")] = iss.str();
549  }
550  jr->reportAnalysisFile("DQMStatsReport", jrInfo);
551  }
552 
553  return 0;
554 }
555 
560  std::cout << std::endl;
561  std::cout << "------------------------------------------------------------------------------------------"
562  << std::endl;
563  std::cout << "Memory profile:" << std::endl;
564  std::cout << "------------------------------------------------------------------------------------------"
565  << std::endl;
566 
567  // determine virtual memory maximum
568  std::pair<time_t, unsigned int> maxItem(0, 0);
569  for (auto it = memoryHistoryVector_.begin(); it < memoryHistoryVector_.end(); ++it) {
570  if (it->second > maxItem.second) {
571  maxItem = *it;
572  }
573  }
574 
575  std::stringstream rootOutputFileName;
576  rootOutputFileName << "dqmStoreStats_memProfile_" << getpid() << ".root";
577 
578  // dump memory history to root file
580  TFile outputFile(rootOutputFileName.str().c_str(), "RECREATE");
581 
582  int aTime;
583  float aMb;
584 
585  TTree memHistoryTree("dqmstorestats_memhistory", "memory history");
586  memHistoryTree.Branch("seconds", &aTime, "seconds/I");
587  memHistoryTree.Branch("megabytes", &aMb, "megabytes/F");
588  for (auto it = memoryHistoryVector_.begin(); it < memoryHistoryVector_.end(); ++it) {
589  aTime = it->first - startingTime_;
590  aMb = it->second / 1000.;
591  memHistoryTree.Fill();
592  }
593 
594  outputFile.Write();
595  outputFile.Close();
596  }
597 
598  std::cout << "Approx. maximum total virtual memory size of job: ";
600  std::cout << maxItem.second / 1000. << " MB (reached " << maxItem.first - startingTime_
601  << " sec. after constructor called)," << std::endl;
602  std::cout << " memory history written to: " << rootOutputFileName.str() << " (" << memoryHistoryVector_.size()
603  << " samples)" << std::endl;
604  } else {
605  std::cout << "(could not be determined)" << std::endl;
606  }
607 
608  std::cout << std::endl << std::endl;
609 }
610 
615  // subsystem info printout
616  std::cout << " ---------- " << subsystem_ << " ---------- " << std::endl;
617  std::cout << " " << subfolder_ << ": ";
618  std::cout << nmesubsys_ << " histograms with " << nbinssubsys_ << " bins. ";
619  if (nmesubsys_ > 0)
620  std::cout << nbinssubsys_ / nmesubsys_ << " bins/histogram ";
621  std::cout << std::endl;
622  std::cout << " Largest histogram: " << maxbinsmesubsys_ << " with " << maxbinssubsys_ << " bins." << std::endl;
623 }
624 
628 std::pair<unsigned int, unsigned int> DQMStoreStats::readMemoryEntry() const {
629  // see if initial test reading was successful
631  std::ifstream procFile(procFileName_.str().c_str(), ios::in);
632 
633  std::string readBuffer("");
634  unsigned int memSize = 0;
635 
636  // scan procfile
637  while (!procFile.eof()) {
638  procFile >> readBuffer;
639  if (std::string("VmSize:") == readBuffer) {
640  procFile >> memSize;
641  break;
642  }
643  }
644 
645  procFile.close();
646  return std::pair<time_t, unsigned int>(time(nullptr), memSize);
647  }
648 
649  return std::pair<time_t, unsigned int>(0, 0);
650 }
651 
652 //==================================================================//
653 //========================= beginJob ===============================//
654 //==================================================================//
657  dbe_ = Service<DQMStore>().operator->();
658 
659  // access the proc/ folder for memory information
660  procFileName_ << "/proc/" << getpid() << "/status";
661 
662  // open for a test
663  std::ifstream procFile(procFileName_.str().c_str(), ios::in);
664 
665  if (procFile.good()) {
667  } else {
668  std::cerr << " [DQMStoreStats::beginJob] ** WARNING: could not open file: " << procFileName_.str() << std::endl;
669  std::cerr << " Total memory profile will not be available." << std::endl;
671  }
672 
673  procFile.close();
674 }
675 
676 //==================================================================//
677 //========================= beginRun ===============================//
678 //==================================================================//
679 void DQMStoreStats::beginRun(const edm::Run& r, const EventSetup& context) {}
680 
681 //==================================================================//
682 //==================== analyse (takes each event) ==================//
683 //==================================================================//
684 void DQMStoreStats::analyze(const Event& iEvent, const EventSetup& iSetup) {
685  //now read virtual memory size from proc folder
686  memoryHistoryVector_.emplace_back(readMemoryEntry());
687 
688  if (runineventloop_) {
692  }
693 }
694 
695 //==================================================================//
696 //========================= endLuminosityBlock =====================//
697 //==================================================================//
698 void DQMStoreStats::endLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
699  if (runonendlumi_) {
703  }
704 }
705 
706 //==================================================================//
707 //============================= endRun =============================//
708 //==================================================================//
709 void DQMStoreStats::endRun(const Run& r, const EventSetup& context) {
710  if (runonendrun_) {
714  }
715 }
716 
717 //==================================================================//
718 //============================= endJob =============================//
719 //==================================================================//
721  if (runonendjob_) {
725  }
726 }
DQMStoreStats::dumpMemHistory_
bool dumpMemHistory_
Definition: DQMStoreStats.h:359
DQMStoreStats::readMemoryEntry
std::pair< unsigned int, unsigned int > readMemoryEntry() const
Definition: DQMStoreStats.cc:628
DQMStoreStats::dbe_
DQMStore * dbe_
Definition: DQMStoreStats.h:332
mps_fire.i
i
Definition: mps_fire.py:355
VIterator::First
void First() override
Definition: DQMStoreStats.h:111
DQMStoreStats::endJob
void endJob() override
Definition: DQMStoreStats.cc:720
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
DQMStoreStats::~DQMStoreStats
~DQMStoreStats() override
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
MonitorElementData::Kind::TH1S
edm::Run
Definition: Run.h:45
MonitorElementData::Kind::TH1F
edm
HLT enums.
Definition: AlignableModifier.h:19
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
Folder::cd
Folder * cd(const std::string &name)
Definition: DQMStoreStats.h:155
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DQMStoreStats::subsystem_
std::string subsystem_
Definition: DQMStoreStats.h:335
edm::JobReport::reportAnalysisFile
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:473
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
DQMStoreStats.h
DQMStoreStats::endRun
void endRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: DQMStoreStats.cc:709
DQMStoreStats::memoryHistoryVector_
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
Definition: DQMStoreStats.h:350
mps_check.array
array
Definition: mps_check.py:216
DQMStoreStatsSubfolder::AddBinsF
void AddBinsF(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:54
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
DQMStoreStats::beginJob
void beginJob() override
Definition: DQMStoreStats.cc:655
dqm::implementation::IGetter::getAllContents
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
Definition: DQMStore.cc:609
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
VIterator::IsDone
bool IsDone() const override
Definition: DQMStoreStats.h:116
MonitorElementData::Kind::TH2D
DQMStoreStats::startingTime_
time_t startingTime_
Definition: DQMStoreStats.h:351
DQMStoreStats::endLuminosityBlock
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
Definition: DQMStoreStats.cc:698
DQMStoreStatsSubfolder
Definition: DQMStoreStats.h:41
MonitorElementData::Kind::TH2F
DQMStoreStatsTopLevel
Definition: DQMStoreStats.h:88
DQMStoreStats::DQMStoreStats
DQMStoreStats(const edm::ParameterSet &)
Definition: DQMStoreStats.cc:47
VIterator
Definition: DQMStoreStats.h:107
download_sqlite_cfg.outputFile
outputFile
Definition: download_sqlite_cfg.py:5
DQMStoreStatsSubsystem
Definition: DQMStoreStats.h:78
Service.h
DQMStoreStats::considerOnlyLumiProductME
Definition: DQMStoreStats.h:304
DQMStoreStats::isOpenProcFileSuccessful_
bool isOpenProcFileSuccessful_
Definition: DQMStoreStats.h:352
DQMStoreStats::runineventloop_
bool runineventloop_
Definition: DQMStoreStats.h:358
DQMStoreStats::analyze
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: DQMStoreStats.cc:684
seedmultiplicitymonitor_newtracking_cfi.nBins
nBins
Definition: seedmultiplicitymonitor_newtracking_cfi.py:8
DQMStoreStatsSubfolder::subfolderName_
std::string subfolderName_
Definition: DQMStoreStats.h:49
DQMStoreStats::pathnamematch_
std::string pathnamematch_
Definition: DQMStoreStats.h:347
DQMStoreStats::dumpToFWJR_
bool dumpToFWJR_
Definition: DQMStoreStats.h:360
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DQMStoreStats::maxbinsmesubsys_
std::string maxbinsmesubsys_
Definition: DQMStoreStats.h:344
DQMStoreStats::print
void print()
Definition: DQMStoreStats.cc:614
DQMStoreStats::runonendjob_
bool runonendjob_
Definition: DQMStoreStats.h:356
Folder::parents
void parents(std::string &sql_statement)
Definition: DQMStoreStats.h:238
DQMStoreStats::maxbinsglobal_
int maxbinsglobal_
Definition: DQMStoreStats.h:341
Folder::mainrows
void mainrows(std::string &sql_statement)
Definition: DQMStoreStats.h:216
edm::ParameterSet
Definition: ParameterSet.h:36
Folder::children
void children(std::string &sql_statement)
Definition: DQMStoreStats.h:249
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
recoMuon::in
Definition: RecoMuonEnumerators.h:6
DQMStoreStats::calcstats
int calcstats(int)
Definition: DQMStoreStats.cc:159
Folder
Definition: DQMStoreStats.h:134
DQMStoreStats::verbose_
int verbose_
Definition: DQMStoreStats.h:348
DQMStoreStats::considerAllME
Definition: DQMStoreStats.h:304
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
DQMStoreStats::beginRun
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: DQMStoreStats.cc:679
DQMStoreStats::runonendrun_
bool runonendrun_
Definition: DQMStoreStats.h:355
root
Definition: RooFitFunction.h:10
DQMStoreStatsSubfolder::AddBinsS
void AddBinsS(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:60
DQMStoreStats::maxbinssubsys_
int maxbinssubsys_
Definition: DQMStoreStats.h:342
edm::EventSetup
Definition: EventSetup.h:57
DQMStoreStats::statsdepth_
int statsdepth_
Definition: DQMStoreStats.h:346
MonitorElementData::Kind::TH1D
DQMStoreStats::procFileName_
std::stringstream procFileName_
Definition: DQMStoreStats.h:353
DQMStoreStats::nbinsglobal_
int nbinsglobal_
Definition: DQMStoreStats.h:337
alignCSCRings.r
r
Definition: alignCSCRings.py:93
DQMStoreStatsSubfolder::AddBinsD
void AddBinsD(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:66
DQMStoreStats::subfolder_
std::string subfolder_
Definition: DQMStoreStats.h:336
DQMStoreStats::nmesubsys_
int nmesubsys_
Definition: DQMStoreStats.h:340
MonitorElementData::Kind::TH2S
std
Definition: JetResolutionObject.h:76
MonitorElementData::Kind::TPROFILE2D
MonitorElementData::Kind::TH3F
VIterator::Next
void Next() override
Definition: DQMStoreStats.h:112
T
long double T
Definition: Basic3DVectorLD.h:48
DQMStoreStats::calcIgProfDump
void calcIgProfDump(Folder &)
Definition: DQMStoreStats.cc:77
DQMStoreStatsSubsystem::subsystemName_
std::string subsystemName_
Definition: DQMStoreStats.h:81
VIterator::CurrentItem
Item CurrentItem() const override
Definition: DQMStoreStats.h:122
DQMStoreStats::nbinssubsys_
int nbinssubsys_
Definition: DQMStoreStats.h:338
mps_fire.result
result
Definition: mps_fire.py:303
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
JobReport.h
ntuplemaker.time
time
Definition: ntuplemaker.py:310
getEmptyMetric
static unsigned int getEmptyMetric(T *array, int lenx, int leny, int lenz)
Definition: DQMStoreStats.cc:17
edm::Event
Definition: Event.h:73
DQMStoreStats::parameters_
edm::ParameterSet parameters_
Definition: DQMStoreStats.h:333
DQMStoreStats::dumpMemoryProfile
void dumpMemoryProfile()
Definition: DQMStoreStats.cc:559
MonitorElementData::Kind::TPROFILE
cuy.ii
ii
Definition: cuy.py:590
Folder::update
void update(unsigned int bins, unsigned int empty, unsigned int memory)
Definition: DQMStoreStats.h:200
DQMStoreStats::runonendlumi_
bool runonendlumi_
Definition: DQMStoreStats.h:357