19 unsigned int len = lenx + leny + lenz;
24 for (
unsigned int i = 1;
i < len; ++
i) {
26 if (
i % (lenx - 1) == 0)
30 if (
i % (lenx + leny - 1) == 0)
32 if (
i % (lenx + leny) == 0)
34 if (
i % (lenx + leny + lenz - 1) == 0)
78 std::ofstream
stream(
"dqm-bin-stats.sql");
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,"
96 " CREATE TABLE files ("
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,"
106 " self_calls INTEGER,"
107 " total_calls INTEGER,"
108 " self_paths INTEGER,"
109 " total_paths INTEGER,"
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,"
120 " CREATE TABLE summary ("
122 " total_count INTEGER,"
123 " total_freq INTEGER,"
126 " CREATE TABLE symbols ("
129 " filename_id INTEGER CONSTRAINT file_id_exists REFERENCES files(id)"
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);"
139 root.files(sql_statement);
140 root.symbols(sql_statement);
141 root.mainrows_cumulative(sql_statement);
142 root.summary(sql_statement);
150 stream << sql_statement << std::endl;
168 size_t subsysStringEnd = 0, subfolderStringBegin = 0, subfolderStringEnd = 0;
170 std::vector<MonitorElement*> melist;
177 for (
auto& it : melist) {
185 subfolderStringBegin = 0;
186 Folder* curr = &dbeFolder;
188 subfolderStringEnd =
path.find(
'/', subfolderStringBegin);
189 if (std::string::npos == subfolderStringEnd) {
190 curr = curr->
cd(
path.substr(subfolderStringBegin,
path.size() - subfolderStringBegin));
193 curr = curr->
cd(
path.substr(subfolderStringBegin, subfolderStringEnd - subfolderStringBegin));
194 subfolderStringBegin = ++subfolderStringEnd <
path.size() ? subfolderStringEnd :
path.size();
201 subsysStringEnd =
path.find(
'/', 0);
202 if (std::string::npos == subsysStringEnd)
203 subsysStringEnd =
path.size();
206 if (
path.substr(0, subsysStringEnd) != subsystemname) {
208 subsystemname =
path.substr(0, subsysStringEnd);
210 dqmStoreStatsTopLevel.push_back(aSubsystem);
215 if (
path.size() == subsysStringEnd) {
219 dqmStoreStatsTopLevel.back().push_back(aSubfolder);
224 subfolderStringEnd =
path.find(
'/', subsysStringEnd + 1);
225 if (std::string::npos == subfolderStringEnd)
226 subfolderStringEnd =
path.size();
229 if (
path.substr(subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1) != subfoldername) {
230 subfoldername =
path.substr(subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1);
233 dqmStoreStatsTopLevel.back().push_back(aSubfolder);
240 switch (it->kind()) {
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));
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));
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));
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));
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));
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));
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));
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));
305 it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(),
306 getEmptyMetric(it->getTH3F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, it->getNbinsZ() + 2));
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));
330 std::cout <<
"==========================================================================================="
332 std::cout <<
"[DQMStoreStats::calcstats] -- Dumping stats results ";
336 std::cout <<
"FOR LUMI PRODUCTS ONLY" << std::endl;
337 std::cout <<
"==========================================================================================="
341 std::cout <<
"------------------------------------------------------------------------------------------"
343 std::cout <<
"Configuration:" << std::endl;
344 std::cout <<
"------------------------------------------------------------------------------------------"
350 std::cout <<
"on lumi end." << std::endl;
354 std::cout <<
"in event loop." << std::endl;
359 std::cout <<
"------------------------------------------------------------------------------------------"
361 std::cout <<
"Top level folder tree:" << std::endl;
362 std::cout <<
"------------------------------------------------------------------------------------------"
364 for (
auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
365 std::cout << it0->subsystemName_ <<
" (subsystem)" << std::endl;
367 for (
auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
368 std::cout <<
" |--> " << it1->subfolderName_ <<
" (subfolder)" << std::endl;
374 unsigned int overallNHistograms = 0, overallNBins = 0, overallNEmptyBins = 0, overallNBytes = 0;
377 std::cout <<
"------------------------------------------------------------------------------------------"
379 std::cout <<
"Detailed ressource usage information ";
383 std::cout <<
"FOR LUMI PRODUCTS ONLY" << std::endl;
384 std::cout <<
"------------------------------------------------------------------------------------------"
386 std::cout <<
"subsystem/folder histograms bins Empty bins Empty/Total "
390 "histogram (total) histogram "
392 std::cout <<
"------------------------------------------------------------------------------------------"
394 for (
auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
395 std::cout << it0->subsystemName_ << std::endl;
397 unsigned int nHistograms = 0,
nBins = 0, nEmptyBins = 0, nBytes = 0;
399 for (
auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
401 std::string thisSubfolderName(it1->subfolderName_);
402 if (thisSubfolderName.size() > 30) {
403 thisSubfolderName.resize(30);
404 thisSubfolderName.replace(thisSubfolderName.size() - 3, 3, 3,
'.');
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_;
415 if (it1->totalHistos_) {
416 std::cout << std::setw(14) << std::right << std::setprecision(3) << it1->totalBins_ /
float(it1->totalHistos_);
418 std::cout << std::setw(14) << std::right <<
"-";
420 std::cout << std::setw(14) << std::right << std::setprecision(3) << it1->totalMemory_ / 1024. / 1024.;
423 if (it1->totalHistos_) {
424 std::cout << std::setw(14) << std::right << std::setprecision(3)
425 << it1->totalMemory_ / 1024. / it1->totalHistos_;
427 std::cout << std::setw(14) << std::right <<
"-";
432 nHistograms += it1->totalHistos_;
433 nBins += it1->totalBins_;
434 nEmptyBins += it1->totalEmptyBins_;
435 nBytes += it1->totalMemory_;
438 overallNHistograms += nHistograms;
439 overallNBins +=
nBins;
440 overallNEmptyBins += nEmptyBins;
441 overallNBytes += nBytes;
444 std::cout <<
" " << std::setw(30) << std::left <<
"SUBSYSTEM TOTAL";
445 std::cout << std::setw(14) << std::right << nHistograms;
447 std::cout << std::setw(14) << std::right << nEmptyBins;
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;
454 std::cout <<
".........................................................................................."
460 std::cout <<
"------------------------------------------------------------------------------------------"
466 std::cout <<
"FOR LUMI PRODUCTS ONLY:" << std::endl;
467 std::cout <<
"------------------------------------------------------------------------------------------"
469 std::cout <<
"Number of subsystems: " << dqmStoreStatsTopLevel.size() << std::endl;
470 std::cout <<
"Total number of histograms: " << overallNHistograms <<
" with: " << overallNBins <<
" bins alltogether"
472 std::cout <<
"Total memory occupied by histograms (excl. overhead): " << overallNBytes / 1024. / 1000. <<
" MB"
476 std::cout <<
"==========================================================================================="
478 std::cout <<
"[DQMStoreStats::calcstats] -- End of output ";
482 std::cout <<
"FOR LUMI PRODUCTS ONLY." << std::endl;
483 std::cout <<
"==========================================================================================="
496 std::map<std::string, std::string> jrInfo;
497 unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
499 jrInfo[
"Source"] =
"DQMServices/Components";
500 jrInfo[
"FileClass"] =
"DQMStoreStats";
502 jrInfo[
"DumpType"] =
"EndRun";
504 jrInfo[
"DumpType"] =
"EndLumi";
506 jrInfo[
"DumpType"] =
"EndJob";
508 jrInfo[
"DumpType"] =
"EventLoop";
510 jrInfo[
"Type"] =
"RunProduct";
512 jrInfo[
"Type"] =
"LumiProduct";
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) {
520 nHistograms += it1->totalHistos_;
521 nBins += it1->totalBins_;
522 nEmptyBins += it1->totalEmptyBins_;
523 nBytes += it1->totalMemory_;
525 overallNHistograms += nHistograms;
526 overallNBins +=
nBins;
527 overallNBytes += nBytes;
528 std::stringstream iss(
"");
530 jrInfo[it0->subsystemName_ +
std::string(
"_h")] = iss.str();
533 jrInfo[it0->subsystemName_ +
std::string(
"_b")] = iss.str();
536 jrInfo[it0->subsystemName_ +
std::string(
"_be")] = iss.str();
539 jrInfo[it0->subsystemName_ +
std::string(
"_fbe")] = iss.str();
542 jrInfo[it0->subsystemName_ +
std::string(
"_b_h")] = iss.str();
544 iss << nBytes / 1024. / 1024.;
545 jrInfo[it0->subsystemName_ +
std::string(
"_MB")] = iss.str();
547 iss << nBytes / 1024. / nHistograms;
548 jrInfo[it0->subsystemName_ +
std::string(
"_Kb_h")] = iss.str();
561 std::cout <<
"------------------------------------------------------------------------------------------"
563 std::cout <<
"Memory profile:" << std::endl;
564 std::cout <<
"------------------------------------------------------------------------------------------"
568 std::pair<time_t, unsigned int> maxItem(0, 0);
570 if (it->second > maxItem.second) {
575 std::stringstream rootOutputFileName;
576 rootOutputFileName <<
"dqmStoreStats_memProfile_" << getpid() <<
".root";
580 TFile
outputFile(rootOutputFileName.str().c_str(),
"RECREATE");
585 TTree memHistoryTree(
"dqmstorestats_memhistory",
"memory history");
586 memHistoryTree.Branch(
"seconds", &aTime,
"seconds/I");
587 memHistoryTree.Branch(
"megabytes", &aMb,
"megabytes/F");
590 aMb = it->second / 1000.;
591 memHistoryTree.Fill();
598 std::cout <<
"Approx. maximum total virtual memory size of job: ";
601 <<
" sec. after constructor called)," << std::endl;
603 <<
" samples)" << std::endl;
605 std::cout <<
"(could not be determined)" << std::endl;
634 unsigned int memSize = 0;
637 while (!procFile.eof()) {
638 procFile >> readBuffer;
646 return std::pair<time_t, unsigned int>(
time(
nullptr), memSize);
649 return std::pair<time_t, unsigned int>(0, 0);
665 if (procFile.good()) {
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;