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);
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.
AddBinsI(it->getNbinsX(),
getEmptyMetric(it->getTH1I()->GetArray(), it->getTH1I()->fN, 0, 0));
262 curr->
update(it->getNbinsX(),
263 getEmptyMetric(it->getTH1I()->GetArray(), it->getTH1I()->fN, 0, 0),
264 it->getNbinsX() *
sizeof(int));
267 currentSubfolder.
AddBinsD(it->getNbinsX(),
268 getEmptyMetric(it->getTProfile()->GetArray(), it->getTProfile()->fN, 0, 0));
269 curr->
update(it->getNbinsX(),
270 getEmptyMetric(it->getTProfile()->GetArray(), it->getTProfile()->fN, 0, 0),
271 it->getNbinsX() *
sizeof(double));
277 it->getNbinsX() * it->getNbinsY(),
278 getEmptyMetric(it->getTH2F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
279 curr->
update(it->getNbinsX() * it->getNbinsY(),
280 getEmptyMetric(it->getTH2F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
281 it->getNbinsX() * it->getNbinsY() *
sizeof(float));
285 it->getNbinsX() * it->getNbinsY(),
286 getEmptyMetric(it->getTH2S()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
287 curr->
update(it->getNbinsX() * it->getNbinsY(),
288 getEmptyMetric(it->getTH2S()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
289 it->getNbinsX() * it->getNbinsY() *
sizeof(short));
293 it->getNbinsX() * it->getNbinsY(),
294 getEmptyMetric(it->getTH2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
295 curr->
update(it->getNbinsX() * it->getNbinsY(),
296 getEmptyMetric(it->getTH2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
297 it->getNbinsX() * it->getNbinsY() *
sizeof(double));
301 it->getNbinsX() * it->getNbinsY(),
302 getEmptyMetric(it->getTH2I()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
303 curr->
update(it->getNbinsX() * it->getNbinsY(),
304 getEmptyMetric(it->getTH2I()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
305 it->getNbinsX() * it->getNbinsY() *
sizeof(int));
309 it->getNbinsX() * it->getNbinsY(),
310 getEmptyMetric(it->getTProfile2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
311 curr->
update(it->getNbinsX() * it->getNbinsY(),
312 getEmptyMetric(it->getTProfile2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
313 it->getNbinsX() * it->getNbinsY() *
sizeof(double));
319 it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(),
320 getEmptyMetric(it->getTH3F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, it->getNbinsZ() + 2));
322 it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(),
323 getEmptyMetric(it->getTH3F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, it->getNbinsZ() + 2),
324 it->getNbinsX() * it->getNbinsY() * it->getNbinsZ() *
sizeof(float));
344 std::cout <<
"==========================================================================================="
346 std::cout <<
"[DQMStoreStats::calcstats] -- Dumping stats results ";
350 std::cout <<
"FOR LUMI PRODUCTS ONLY" << std::endl;
351 std::cout <<
"==========================================================================================="
355 std::cout <<
"------------------------------------------------------------------------------------------"
357 std::cout <<
"Configuration:" << std::endl;
358 std::cout <<
"------------------------------------------------------------------------------------------"
364 std::cout <<
"on lumi end." << std::endl;
368 std::cout <<
"in event loop." << std::endl;
373 std::cout <<
"------------------------------------------------------------------------------------------"
375 std::cout <<
"Top level folder tree:" << std::endl;
376 std::cout <<
"------------------------------------------------------------------------------------------"
378 for (
auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
379 std::cout << it0->subsystemName_ <<
" (subsystem)" << std::endl;
381 for (
auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
382 std::cout <<
" |--> " << it1->subfolderName_ <<
" (subfolder)" << std::endl;
388 unsigned int overallNHistograms = 0, overallNBins = 0, overallNEmptyBins = 0, overallNBytes = 0;
391 std::cout <<
"------------------------------------------------------------------------------------------"
393 std::cout <<
"Detailed ressource usage information ";
397 std::cout <<
"FOR LUMI PRODUCTS ONLY" << std::endl;
398 std::cout <<
"------------------------------------------------------------------------------------------"
400 std::cout <<
"subsystem/folder histograms bins Empty bins Empty/Total "
404 "histogram (total) histogram "
406 std::cout <<
"------------------------------------------------------------------------------------------"
408 for (
auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
409 std::cout << it0->subsystemName_ << std::endl;
411 unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
413 for (
auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
415 std::string thisSubfolderName(it1->subfolderName_);
416 if (thisSubfolderName.size() > 30) {
417 thisSubfolderName.resize(30);
418 thisSubfolderName.replace(thisSubfolderName.size() - 3, 3, 3,
'.');
421 std::cout <<
" -> " << std::setw(30) << std::left << thisSubfolderName;
422 std::cout << std::setw(14) << std::right << it1->totalHistos_;
423 std::cout << std::setw(14) << std::right << it1->totalBins_;
424 std::cout << std::setw(14) << std::right << it1->totalEmptyBins_;
425 std::cout << std::setw(14) << std::right << std::setprecision(3)
426 << (float)it1->totalEmptyBins_ / (
float)it1->totalBins_;
429 if (it1->totalHistos_) {
430 std::cout << std::setw(14) << std::right << std::setprecision(3) << it1->totalBins_ / float(it1->totalHistos_);
432 std::cout << std::setw(14) << std::right <<
"-";
434 std::cout << std::setw(14) << std::right << std::setprecision(3) << it1->totalMemory_ / 1024. / 1024.;
437 if (it1->totalHistos_) {
438 std::cout << std::setw(14) << std::right << std::setprecision(3)
439 << it1->totalMemory_ / 1024. / it1->totalHistos_;
441 std::cout << std::setw(14) << std::right <<
"-";
446 nHistograms += it1->totalHistos_;
447 nBins += it1->totalBins_;
448 nEmptyBins += it1->totalEmptyBins_;
449 nBytes += it1->totalMemory_;
452 overallNHistograms += nHistograms;
453 overallNBins += nBins;
454 overallNEmptyBins += nEmptyBins;
455 overallNBytes += nBytes;
458 std::cout <<
" " << std::setw(30) << std::left <<
"SUBSYSTEM TOTAL";
459 std::cout << std::setw(14) << std::right << nHistograms;
460 std::cout << std::setw(14) << std::right << nBins;
461 std::cout << std::setw(14) << std::right << nEmptyBins;
462 std::cout << std::setw(14) << std::right << (float)nEmptyBins / (
float)nBins;
463 std::cout << std::setw(14) << std::right << std::setprecision(3) << nBins / float(nHistograms);
464 std::cout << std::setw(14) << std::right << std::setprecision(3) << nBytes / 1024. / 1000.;
465 std::cout << std::setw(14) << std::right << std::setprecision(3) << nBytes / 1024. / nHistograms;
468 std::cout <<
".........................................................................................."
474 std::cout <<
"------------------------------------------------------------------------------------------"
480 std::cout <<
"FOR LUMI PRODUCTS ONLY:" << std::endl;
481 std::cout <<
"------------------------------------------------------------------------------------------"
483 std::cout <<
"Number of subsystems: " << dqmStoreStatsTopLevel.size() << std::endl;
484 std::cout <<
"Total number of histograms: " << overallNHistograms <<
" with: " << overallNBins <<
" bins alltogether"
486 std::cout <<
"Total memory occupied by histograms (excl. overhead): " << overallNBytes / 1024. / 1000. <<
" MB"
490 std::cout <<
"==========================================================================================="
492 std::cout <<
"[DQMStoreStats::calcstats] -- End of output ";
496 std::cout <<
"FOR LUMI PRODUCTS ONLY." << std::endl;
497 std::cout <<
"==========================================================================================="
510 std::map<std::string, std::string> jrInfo;
511 unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
513 jrInfo[
"Source"] =
"DQMServices/Components";
514 jrInfo[
"FileClass"] =
"DQMStoreStats";
516 jrInfo[
"DumpType"] =
"EndRun";
518 jrInfo[
"DumpType"] =
"EndLumi";
520 jrInfo[
"DumpType"] =
"EndJob";
522 jrInfo[
"DumpType"] =
"EventLoop";
524 jrInfo[
"Type"] =
"RunProduct";
526 jrInfo[
"Type"] =
"LumiProduct";
530 for (
auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
531 unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
532 for (
auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
534 nHistograms += it1->totalHistos_;
535 nBins += it1->totalBins_;
536 nEmptyBins += it1->totalEmptyBins_;
537 nBytes += it1->totalMemory_;
539 overallNHistograms += nHistograms;
540 overallNBins += nBins;
541 overallNBytes += nBytes;
542 std::stringstream iss(
"");
544 jrInfo[it0->subsystemName_ +
std::string(
"_h")] = iss.str();
547 jrInfo[it0->subsystemName_ +
std::string(
"_b")] = iss.str();
550 jrInfo[it0->subsystemName_ +
std::string(
"_be")] = iss.str();
552 iss << ((float)nEmptyBins / (
float)nBins);
553 jrInfo[it0->subsystemName_ +
std::string(
"_fbe")] = iss.str();
555 iss << ((float)nBins / (
float)nHistograms);
556 jrInfo[it0->subsystemName_ +
std::string(
"_b_h")] = iss.str();
558 iss << nBytes / 1024. / 1024.;
559 jrInfo[it0->subsystemName_ +
std::string(
"_MB")] = iss.str();
561 iss << nBytes / 1024. / nHistograms;
562 jrInfo[it0->subsystemName_ +
std::string(
"_Kb_h")] = iss.str();
575 std::cout <<
"------------------------------------------------------------------------------------------"
577 std::cout <<
"Memory profile:" << std::endl;
578 std::cout <<
"------------------------------------------------------------------------------------------"
582 std::pair<time_t, unsigned int> maxItem(0, 0);
584 if (it->second > maxItem.second) {
589 std::stringstream rootOutputFileName;
590 rootOutputFileName <<
"dqmStoreStats_memProfile_" << getpid() <<
".root";
594 TFile
outputFile(rootOutputFileName.str().c_str(),
"RECREATE");
599 TTree memHistoryTree(
"dqmstorestats_memhistory",
"memory history");
600 memHistoryTree.Branch(
"seconds", &aTime,
"seconds/I");
601 memHistoryTree.Branch(
"megabytes", &aMb,
"megabytes/F");
604 aMb = it->second / 1000.;
605 memHistoryTree.Fill();
612 std::cout <<
"Approx. maximum total virtual memory size of job: ";
615 <<
" sec. after constructor called)," << std::endl;
617 <<
" samples)" << std::endl;
619 std::cout <<
"(could not be determined)" << std::endl;
648 unsigned int memSize = 0;
651 while (!procFile.eof()) {
652 procFile >> readBuffer;
660 return std::pair<time_t, unsigned int>(time(
nullptr), memSize);
663 return std::pair<time_t, unsigned int>(0, 0);
679 if (procFile.good()) {
682 std::cerr <<
" [DQMStoreStats::beginJob] ** WARNING: could not open file: " <<
procFileName_.str() << std::endl;
683 std::cerr <<
" Total memory profile will not be available." << std::endl;
std::string subfolderName_
T getUntrackedParameter(std::string const &, T const &) const
void AddBinsS(unsigned int nBins, unsigned int nEmptyBins)
void update(unsigned int bins, unsigned int empty, unsigned int memory)
void AddBinsD(unsigned int nBins, unsigned int nEmptyBins)
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
void AddBinsI(unsigned int nBins, unsigned int nEmptyBins)
std::string subsystemName_
void mainrows_cumulative(std::string &sql_statement)
VIterator< Folder * > CreateIterator()
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
void summary(std::string &sql_statement)
void endRun(const edm::Run &r, const edm::EventSetup &c) override
void mainrows(std::string &sql_statement)
bool isOpenProcFileSuccessful_
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
Item CurrentItem() const override
std::string pathnamematch_
std::string maxbinsmesubsys_
DQMStoreStats(const edm::ParameterSet &)
void files(std::string &sql_statement)
void analyze(const edm::Event &e, const edm::EventSetup &c) override
void parents(std::string &sql_statement)
bool IsDone() const override
static unsigned int getEmptyMetric(T *array, int lenx, int leny, int lenz)
Folder * cd(const std::string &name)
edm::ParameterSet parameters_
void AddBinsF(unsigned int nBins, unsigned int nEmptyBins)
void children(std::string &sql_statement)
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
void calcIgProfDump(Folder &)
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
std::pair< unsigned int, unsigned int > readMemoryEntry() const
std::stringstream procFileName_
~DQMStoreStats() override
void symbols(std::string &sql_statement)