20 unsigned int len = lenx+leny+lenz;
25 for (
unsigned int i=1;
i<len; ++
i)
32 if (
i%(lenx+leny-1)==0)
36 if (
i%(lenx+leny+lenz-1)==0)
58 maxbinsmeglobal_ (
""),
59 maxbinsmesubsys_ (
""),
82 std::ofstream stream(
"dqm-bin-stats.sql");
84 " PRAGMA journal_mode=OFF;" 85 " PRAGMA count_changes=OFF;" 86 " DROP TABLE IF EXISTS files;" 87 " DROP TABLE IF EXISTS symbols;" 88 " DROP TABLE IF EXISTS mainrows;" 89 " DROP TABLE IF EXISTS children;" 90 " DROP TABLE IF EXISTS parents;" 91 " DROP TABLE IF EXISTS summary;" 92 " CREATE TABLE children (" 93 " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id)," 94 " parent_id INTEGER CONSTRAINT parent_exists REFERENCES mainrows(id)," 95 " from_parent_count INTEGER," 96 " from_parent_calls INTEGER," 97 " from_parent_paths INTEGER," 100 " CREATE TABLE files (" 104 " CREATE TABLE mainrows (" 105 " id INTEGER PRIMARY KEY," 106 " symbol_id INTEGER CONSTRAINT symbol_id_exists REFERENCES symbols(id)," 107 " self_count INTEGER," 108 " cumulative_count INTEGER," 110 " self_calls INTEGER," 111 " total_calls INTEGER," 112 " self_paths INTEGER," 113 " total_paths INTEGER," 116 " CREATE TABLE parents (" 117 " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id)," 118 " child_id INTEGER CONSTRAINT child_exists REFERENCES mainrows(id)," 119 " to_child_count INTEGER," 120 " to_child_calls INTEGER," 121 " to_child_paths INTEGER," 124 " CREATE TABLE summary (" 126 " total_count INTEGER," 127 " total_freq INTEGER," 130 " CREATE TABLE symbols (" 133 " filename_id INTEGER CONSTRAINT file_id_exists REFERENCES files(id)" 135 " CREATE UNIQUE INDEX fileIndex ON files (id);" 136 " CREATE INDEX selfCountIndex ON mainrows(self_count);" 137 " CREATE UNIQUE INDEX symbolsIndex ON symbols (id);" 138 " CREATE INDEX totalCountIndex ON mainrows(cumulative_count);" << std::endl;
142 root.
files(sql_statement);
154 stream << sql_statement << std::endl;
173 size_t subsysStringEnd = 0, subfolderStringBegin = 0, subfolderStringEnd = 0;
176 std::vector<MonitorElement*> melist;
183 for(
auto & it : melist) {
187 !( it->getLumiFlag() ) )
continue;
192 subfolderStringBegin = 0;
193 Folder * curr = &dbeFolder;
196 subfolderStringEnd = path.find(
'/', subfolderStringBegin );
197 if( std::string::npos == subfolderStringEnd )
199 curr = curr->
cd(path.substr( subfolderStringBegin, path.size()-subfolderStringBegin ));
202 curr = curr->
cd(path.substr( subfolderStringBegin, subfolderStringEnd-subfolderStringBegin ));
203 subfolderStringBegin = ++subfolderStringEnd < path.size() ? subfolderStringEnd : path.size();
207 if( path.empty() )
continue;
209 subsysStringEnd = path.find(
'/', 0 );
210 if( std::string::npos == subsysStringEnd ) subsysStringEnd = path.size();
213 if( path.substr( 0, subsysStringEnd ) != subsystemname ) {
215 subsystemname = path.substr( 0, subsysStringEnd );
217 dqmStoreStatsTopLevel.push_back( aSubsystem );
222 if( path.size() == subsysStringEnd ) {
226 dqmStoreStatsTopLevel.back().push_back( aSubfolder );
232 subfolderStringEnd = path.find(
'/', subsysStringEnd + 1 );
233 if( std::string::npos == subfolderStringEnd ) subfolderStringEnd = path.size();
236 if( path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 ) != subfoldername ) {
237 subfoldername = path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 );
240 dqmStoreStatsTopLevel.back().push_back( aSubfolder );
248 switch( it->kind() ) {
252 currentSubfolder.
AddBinsF( it->getNbinsX(),
getEmptyMetric(it->getTH1F()->GetArray(), it->getTH1F()->fN, 0, 0) );
253 curr->
update( it->getNbinsX(),
getEmptyMetric(it->getTH1F()->GetArray(), it->getTH1F()->fN, 0, 0), it->getNbinsX()*
sizeof(
float ) );
256 currentSubfolder.
AddBinsS( it->getNbinsX(),
getEmptyMetric(it->getTH1S()->GetArray(), it->getTH1S()->fN, 0, 0) );
257 curr->
update( it->getNbinsX(),
getEmptyMetric(it->getTH1S()->GetArray(), it->getTH1S()->fN, 0, 0), it->getNbinsX()*
sizeof( short ) );
260 currentSubfolder.
AddBinsD( it->getNbinsX(),
getEmptyMetric(it->getTH1D()->GetArray(), it->getTH1D()->fN, 0, 0) );
261 curr->
update( it->getNbinsX(),
getEmptyMetric(it->getTH1D()->GetArray(), it->getTH1D()->fN, 0, 0), it->getNbinsX()*
sizeof( double ) );
264 currentSubfolder.
AddBinsD( it->getNbinsX(),
getEmptyMetric(it->getTProfile()->GetArray(), it->getTProfile()->fN, 0, 0) );
265 curr->
update( it->getNbinsX(),
getEmptyMetric(it->getTProfile()->GetArray(), it->getTProfile()->fN, 0, 0), it->getNbinsX()*
sizeof( double ) );
270 currentSubfolder.
AddBinsF( it->getNbinsX() * it->getNbinsY(),
getEmptyMetric(it->getTH2F()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0) );
271 curr->
update( it->getNbinsX() * it->getNbinsY(),
getEmptyMetric(it->getTH2F()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0), it->getNbinsX() * it->getNbinsY()*
sizeof(
float) );
274 currentSubfolder.
AddBinsS( it->getNbinsX() * it->getNbinsY(),
getEmptyMetric(it->getTH2S()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0) );
275 curr->
update( it->getNbinsX() * it->getNbinsY(),
getEmptyMetric(it->getTH2S()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0), it->getNbinsX() * it->getNbinsY()*
sizeof(short) );
278 currentSubfolder.
AddBinsD( it->getNbinsX() * it->getNbinsY(),
getEmptyMetric(it->getTH2D()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0) );
279 curr->
update( it->getNbinsX() * it->getNbinsY(),
getEmptyMetric(it->getTH2D()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0), it->getNbinsX() * it->getNbinsY()*
sizeof(double) );
282 currentSubfolder.
AddBinsD( it->getNbinsX() * it->getNbinsY(),
getEmptyMetric(it->getTProfile2D()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0) );
283 curr->
update( it->getNbinsX() * it->getNbinsY(),
getEmptyMetric(it->getTProfile2D()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0), it->getNbinsX() * it->getNbinsY()*
sizeof(double) );
288 currentSubfolder.
AddBinsF( it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(),
getEmptyMetric( it->getTH3F()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, it->getNbinsZ()+2 ) );
289 curr->
update( it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(),
290 getEmptyMetric( it->getTH3F()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, it->getNbinsZ()+2 ),
291 it->getNbinsX() * it->getNbinsY() * it->getNbinsZ()*
sizeof(
float));
310 std::cout <<
"===========================================================================================" << std::endl;
311 std::cout <<
"[DQMStoreStats::calcstats] -- Dumping stats results ";
314 std::cout <<
"===========================================================================================" << std::endl;
317 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
318 std::cout <<
"Configuration:" << std::endl;
319 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
329 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
330 std::cout <<
"Top level folder tree:" << std::endl;
331 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
332 for(
auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 ) {
333 std::cout << it0->subsystemName_ <<
" (subsystem)" << std::endl;
335 for(
auto it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
336 std::cout <<
" |--> " << it1->subfolderName_ <<
" (subfolder)" << std::endl;
343 unsigned int overallNHistograms = 0, overallNBins = 0, overallNEmptyBins = 0, overallNBytes = 0;
346 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
347 std::cout <<
"Detailed ressource usage information ";
350 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
351 std::cout <<
"subsystem/folder histograms bins Empty bins Empty/Total bins per MB kB per" << std::endl;
352 std::cout <<
" (total) (total) (total) histogram (total) histogram " << std::endl;
353 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
354 for(
auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 ) {
355 std::cout << it0->subsystemName_ << std::endl;
357 unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
359 for(
auto it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
362 std::string thisSubfolderName( it1->subfolderName_ );
363 if( thisSubfolderName.size() > 30 ) {
364 thisSubfolderName.resize( 30 );
365 thisSubfolderName.replace( thisSubfolderName.size() - 3, 3, 3,
'.' );
368 std::cout <<
" -> " << std::setw( 30 ) << std::left << thisSubfolderName;
369 std::cout << std::setw( 14 ) << std::right << it1->totalHistos_;
370 std::cout << std::setw( 14 ) << std::right << it1->totalBins_;
371 std::cout << std::setw( 14 ) << std::right << it1->totalEmptyBins_;
372 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << (
float)it1->totalEmptyBins_/(
float)it1->totalBins_;
375 if( it1->totalHistos_ ) {
376 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalBins_ /
float( it1->totalHistos_ );
378 else std::cout << std::setw( 14 ) << std::right <<
"-";
380 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / 1024.;
383 if( it1->totalHistos_ ) {
384 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / it1->totalHistos_;
386 else std::cout << std::setw( 14 ) << std::right <<
"-";
391 nHistograms += it1->totalHistos_;
392 nBins += it1->totalBins_;
393 nEmptyBins += it1->totalEmptyBins_;
394 nBytes += it1->totalMemory_;
401 overallNHistograms += nHistograms;
402 overallNBins += nBins;
403 overallNEmptyBins += nEmptyBins;
404 overallNBytes += nBytes;
407 std::cout <<
" " << std::setw( 30 ) << std::left <<
"SUBSYSTEM TOTAL";
408 std::cout << std::setw( 14 ) << std::right << nHistograms;
409 std::cout << std::setw( 14 ) << std::right << nBins;
410 std::cout << std::setw( 14 ) << std::right << nEmptyBins;
411 std::cout << std::setw( 14 ) << std::right << (
float)nEmptyBins/(
float)nBins;
412 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBins /
float( nHistograms );
413 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBytes / 1024. / 1000.;
414 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBytes / 1024. / nHistograms;
417 std::cout <<
".........................................................................................." << std::endl;
424 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
428 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
429 std::cout <<
"Number of subsystems: " << dqmStoreStatsTopLevel.size() << std::endl;
430 std::cout <<
"Total number of histograms: " << overallNHistograms <<
" with: " << overallNBins <<
" bins alltogether" << std::endl;
431 std::cout <<
"Total memory occupied by histograms (excl. overhead): " << overallNBytes / 1024. / 1000. <<
" MB" << std::endl;
436 std::cout <<
"===========================================================================================" << std::endl;
437 std::cout <<
"[DQMStoreStats::calcstats] -- End of output ";
440 std::cout <<
"===========================================================================================" << std::endl;
453 std::map<std::string, std::string> jrInfo;
454 unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
456 jrInfo[
"Source"] =
"DQMServices/Components";
457 jrInfo[
"FileClass"] =
"DQMStoreStats";
459 jrInfo[
"DumpType"] =
"EndRun";
461 jrInfo[
"DumpType"] =
"EndLumi";
463 jrInfo[
"DumpType"] =
"EndJob";
465 jrInfo[
"DumpType"] =
"EventLoop";
467 jrInfo[
"Type"] =
"RunProduct";
469 jrInfo[
"Type"] =
"LumiProduct";
474 for (
auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 )
476 unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
477 for(
auto it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
479 nHistograms += it1->totalHistos_;
480 nBins += it1->totalBins_;
481 nEmptyBins += it1->totalEmptyBins_;
482 nBytes += it1->totalMemory_;
484 overallNHistograms += nHistograms;
485 overallNBins += nBins;
486 overallNBytes += nBytes;
487 std::stringstream iss(
"");
489 jrInfo[it0->subsystemName_ +
std::string(
"_h")] = iss.str();
490 iss.str(
"");iss<<nBins;
491 jrInfo[it0->subsystemName_ +
std::string(
"_b")] = iss.str();
492 iss.str(
"");iss<<nEmptyBins;
493 jrInfo[it0->subsystemName_ +
std::string(
"_be")] = iss.str();
494 iss.str(
"");iss<< ((
float)nEmptyBins/(
float)nBins);
495 jrInfo[it0->subsystemName_ +
std::string(
"_fbe")] = iss.str();
496 iss.str(
"");iss<< ((
float)nBins/(
float)nHistograms);
497 jrInfo[it0->subsystemName_ +
std::string(
"_b_h")] = iss.str();
498 iss.str(
"");iss<<nBytes / 1024. / 1024.;
499 jrInfo[it0->subsystemName_ +
std::string(
"_MB")] = iss.str();
500 iss.str(
"");iss<<nBytes / 1024. / nHistograms;
501 jrInfo[it0->subsystemName_ +
std::string(
"_Kb_h")] = iss.str();
518 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
519 std::cout <<
"Memory profile:" << std::endl;
520 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
523 std::pair<time_t, unsigned int> maxItem( 0, 0 );
526 if( it->second > maxItem.second ) {
531 std::stringstream rootOutputFileName;
532 rootOutputFileName <<
"dqmStoreStats_memProfile_" << getpid() <<
".root";
537 TFile
outputFile( rootOutputFileName.str().c_str(),
"RECREATE" );
542 TTree memHistoryTree(
"dqmstorestats_memhistory",
"memory history" );
543 memHistoryTree.Branch(
"seconds", &aTime,
"seconds/I" );
544 memHistoryTree.Branch(
"megabytes", &aMb,
"megabytes/F" );
548 aMb = it->second / 1000.;
549 memHistoryTree.Fill();
557 std::cout <<
"Approx. maximum total virtual memory size of job: ";
560 <<
" MB (reached " << maxItem.first -
startingTime_ <<
" sec. after constructor called)," << std::endl;
563 std::cout <<
"(could not be determined)" << std::endl;
601 unsigned int memSize = 0;
604 while( !procFile.eof() ) {
605 procFile >> readBuffer;
613 return std::pair<time_t, unsigned int>(
time(
nullptr ), memSize );
616 return std::pair<time_t, unsigned int>( 0, 0 );
636 if( procFile.good() ) {
640 std::cerr <<
" [DQMStoreStats::beginJob] ** WARNING: could not open file: " <<
procFileName_.str() << std::endl;
641 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_
std::string subsystemName_
void mainrows_cumulative(std::string &sql_statement)
VIterator< Folder * > CreateIterator()
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
Item CurrentItem() const override
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
std::string pathnamematch_
std::string maxbinsmesubsys_
DQMStoreStats(const edm::ParameterSet &)
void files(std::string &sql_statement)
bool IsDone() const override
void analyze(const edm::Event &e, const edm::EventSetup &c) override
void parents(std::string &sql_statement)
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)