23 unsigned int len = lenx+leny+lenz;
28 for (
unsigned int i=1;
i<len; ++
i)
35 if (
i%(lenx+leny-1)==0)
39 if (
i%(lenx+leny+lenz-1)==0)
61 maxbinsmeglobal_ (
""),
62 maxbinsmesubsys_ (
""),
86 std::ofstream stream(
"dqm-bin-stats.sql");
88 " PRAGMA journal_mode=OFF;"
89 " PRAGMA count_changes=OFF;"
90 " DROP TABLE IF EXISTS files;"
91 " DROP TABLE IF EXISTS symbols;"
92 " DROP TABLE IF EXISTS mainrows;"
93 " DROP TABLE IF EXISTS children;"
94 " DROP TABLE IF EXISTS parents;"
95 " DROP TABLE IF EXISTS summary;"
96 " CREATE TABLE children ("
97 " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id),"
98 " parent_id INTEGER CONSTRAINT parent_exists REFERENCES mainrows(id),"
99 " from_parent_count INTEGER,"
100 " from_parent_calls INTEGER,"
101 " from_parent_paths INTEGER,"
104 " CREATE TABLE files ("
108 " CREATE TABLE mainrows ("
109 " id INTEGER PRIMARY KEY,"
110 " symbol_id INTEGER CONSTRAINT symbol_id_exists REFERENCES symbols(id),"
111 " self_count INTEGER,"
112 " cumulative_count INTEGER,"
114 " self_calls INTEGER,"
115 " total_calls INTEGER,"
116 " self_paths INTEGER,"
117 " total_paths INTEGER,"
120 " CREATE TABLE parents ("
121 " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id),"
122 " child_id INTEGER CONSTRAINT child_exists REFERENCES mainrows(id),"
123 " to_child_count INTEGER,"
124 " to_child_calls INTEGER,"
125 " to_child_paths INTEGER,"
128 " CREATE TABLE summary ("
130 " total_count INTEGER,"
131 " total_freq INTEGER,"
134 " CREATE TABLE symbols ("
137 " filename_id INTEGER CONSTRAINT file_id_exists REFERENCES files(id)"
139 " CREATE UNIQUE INDEX fileIndex ON files (id);"
140 " CREATE INDEX selfCountIndex ON mainrows(self_count);"
141 " CREATE UNIQUE INDEX symbolsIndex ON symbols (id);"
142 " CREATE INDEX totalCountIndex ON mainrows(cumulative_count);" << std::endl;
144 std::string sql_statement(
"");
146 root.
files(sql_statement);
152 for(subsystems.
First() ; !subsystems.
IsDone() ; subsystems.
Next(), ++ii)
158 stream << sql_statement << std::endl;
174 std::string
path =
"";
175 std::string subsystemname =
"";
176 std::string subfoldername =
"";
177 size_t subsysStringEnd = 0, subfolderStringBegin = 0, subfolderStringEnd = 0;
180 std::vector<MonitorElement*> melist;
187 typedef std::vector <MonitorElement*>::iterator meIt;
188 for(meIt it = melist.begin(); it != melist.end(); ++it) {
192 !( (*it)->getLumiFlag() ) )
continue;
195 std::string path = (*it)->getPathname();
197 subfolderStringBegin = 0;
198 Folder * curr = &dbeFolder;
201 subfolderStringEnd = path.find(
'/', subfolderStringBegin );
202 if( std::string::npos == subfolderStringEnd )
204 curr = curr->
cd(path.substr( subfolderStringBegin, path.size() ));
207 curr = curr->
cd(path.substr( subfolderStringBegin, subfolderStringEnd-subfolderStringBegin ));
208 subfolderStringBegin = subfolderStringEnd+1;
212 if( 0 == path.size() )
continue;
214 subsysStringEnd = path.find(
'/', 0 );
215 if( std::string::npos == subsysStringEnd ) subsysStringEnd = path.size();
218 if( path.substr( 0, subsysStringEnd ) != subsystemname ) {
220 subsystemname = path.substr( 0, subsysStringEnd );
222 dqmStoreStatsTopLevel.push_back( aSubsystem );
226 if( path.size() == subsysStringEnd ) {
230 dqmStoreStatsTopLevel.back().push_back( aSubfolder );
236 subfolderStringEnd = path.find(
'/', subsysStringEnd + 1 );
237 if( std::string::npos == subfolderStringEnd ) subfolderStringEnd = path.size();
240 if( path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 ) != subfoldername ) {
241 subfoldername = path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 );
244 dqmStoreStatsTopLevel.back().push_back( aSubfolder );
252 switch( (*it)->kind() ) {
256 currentSubfolder.
AddBinsF( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1F()->GetArray(), (*it)->getTH1F()->fN, 0, 0) );
257 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1F()->GetArray(), (*it)->getTH1F()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( float ) );
260 currentSubfolder.
AddBinsS( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1S()->GetArray(), (*it)->getTH1S()->fN, 0, 0) );
261 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1S()->GetArray(), (*it)->getTH1S()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( short ) );
264 currentSubfolder.
AddBinsD( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1D()->GetArray(), (*it)->getTH1D()->fN, 0, 0) );
265 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1D()->GetArray(), (*it)->getTH1D()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( double ) );
268 currentSubfolder.
AddBinsD( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTProfile()->GetArray(), (*it)->getTProfile()->fN, 0, 0) );
269 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTProfile()->GetArray(), (*it)->getTProfile()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( double ) );
274 currentSubfolder.
AddBinsF( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
275 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(float) );
278 currentSubfolder.
AddBinsS( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2S()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
279 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2S()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(short) );
282 currentSubfolder.
AddBinsD( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
283 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(double) );
286 currentSubfolder.
AddBinsD( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTProfile2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
287 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTProfile2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(double) );
292 currentSubfolder.
AddBinsF( (*it)->getNbinsX() * (*it)->getNbinsY() * (*it)->getNbinsZ(),
getEmptyMetric( (*it)->getTH3F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, (*it)->getNbinsZ()+2 ) );
293 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY() * (*it)->getNbinsZ(),
294 getEmptyMetric( (*it)->getTH3F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, (*it)->getNbinsZ()+2 ),
295 (*it)->getNbinsX() * (*it)->getNbinsY() * (*it)->getNbinsZ()*
sizeof(float));
314 std::cout <<
"===========================================================================================" << std::endl;
315 std::cout <<
"[DQMStoreStats::calcstats] -- Dumping stats results ";
318 std::cout <<
"===========================================================================================" << std::endl;
321 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
322 std::cout <<
"Configuration:" << std::endl;
323 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
333 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
334 std::cout <<
"Top level folder tree:" << std::endl;
335 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
336 for( DQMStoreStatsTopLevel::const_iterator it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 ) {
337 std::cout << it0->subsystemName_ <<
" (subsystem)" << std::endl;
339 for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
340 std::cout <<
" |--> " << it1->subfolderName_ <<
" (subfolder)" << std::endl;
347 unsigned int overallNHistograms = 0, overallNBins = 0, overallNEmptyBins = 0, overallNBytes = 0;
350 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
351 std::cout <<
"Detailed ressource usage information ";
354 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
355 std::cout <<
"subsystem/folder histograms bins Empty bins Empty/Total bins per MB kB per" << std::endl;
356 std::cout <<
" (total) (total) (total) histogram (total) histogram " << std::endl;
357 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
358 for( DQMStoreStatsTopLevel::const_iterator it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 ) {
359 std::cout << it0->subsystemName_ << std::endl;
361 unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
363 for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
366 std::string thisSubfolderName( it1->subfolderName_ );
367 if( thisSubfolderName.size() > 30 ) {
368 thisSubfolderName.resize( 30 );
369 thisSubfolderName.replace( thisSubfolderName.size() - 3, 3, 3,
'.' );
372 std::cout <<
" -> " << std::setw( 30 ) << std::left << thisSubfolderName;
373 std::cout << std::setw( 14 ) << std::right << it1->totalHistos_;
374 std::cout << std::setw( 14 ) << std::right << it1->totalBins_;
375 std::cout << std::setw( 14 ) << std::right << it1->totalEmptyBins_;
376 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << (float)it1->totalEmptyBins_/(
float)it1->totalBins_;
379 if( it1->totalHistos_ ) {
380 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalBins_ / float( it1->totalHistos_ );
382 else std::cout << std::setw( 14 ) << std::right <<
"-";
384 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / 1024.;
387 if( it1->totalHistos_ ) {
388 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / it1->totalHistos_;
390 else std::cout << std::setw( 14 ) << std::right <<
"-";
395 nHistograms += it1->totalHistos_;
396 nBins += it1->totalBins_;
397 nEmptyBins += it1->totalEmptyBins_;
398 nBytes += it1->totalMemory_;
405 overallNHistograms += nHistograms;
406 overallNBins += nBins;
407 overallNEmptyBins += nEmptyBins;
408 overallNBytes += nBytes;
411 std::cout <<
" " << std::setw( 30 ) << std::left <<
"SUBSYSTEM TOTAL";
412 std::cout << std::setw( 14 ) << std::right << nHistograms;
413 std::cout << std::setw( 14 ) << std::right << nBins;
414 std::cout << std::setw( 14 ) << std::right << nEmptyBins;
415 std::cout << std::setw( 14 ) << std::right << (float)nEmptyBins/(
float)nBins;
416 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBins / float( nHistograms );
417 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBytes / 1024. / 1000.;
418 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBytes / 1024. / nHistograms;
421 std::cout <<
".........................................................................................." << std::endl;
428 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
432 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
433 std::cout <<
"Number of subsystems: " << dqmStoreStatsTopLevel.size() << std::endl;
434 std::cout <<
"Total number of histograms: " << overallNHistograms <<
" with: " << overallNBins <<
" bins alltogether" << std::endl;
435 std::cout <<
"Total memory occupied by histograms (excl. overhead): " << overallNBytes / 1024. / 1000. <<
" MB" << std::endl;
440 std::cout <<
"===========================================================================================" << std::endl;
441 std::cout <<
"[DQMStoreStats::calcstats] -- End of output ";
444 std::cout <<
"===========================================================================================" << std::endl;
457 std::map<std::string, std::string> jrInfo;
458 unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
460 jrInfo[
"Source"] =
"DQMServices/Components";
461 jrInfo[
"FileClass"] =
"DQMStoreStats";
463 jrInfo[
"DumpType"] =
"EndRun";
465 jrInfo[
"DumpType"] =
"EndLumi";
467 jrInfo[
"DumpType"] =
"EndJob";
469 jrInfo[
"DumpType"] =
"EventLoop";
471 jrInfo[
"Type"] =
"RunProduct";
473 jrInfo[
"Type"] =
"LumiProduct";
478 for (DQMStoreStatsTopLevel::const_iterator it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 )
480 unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
481 for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
483 nHistograms += it1->totalHistos_;
484 nBins += it1->totalBins_;
485 nEmptyBins += it1->totalEmptyBins_;
486 nBytes += it1->totalMemory_;
488 overallNHistograms += nHistograms;
489 overallNBins += nBins;
490 overallNBytes += nBytes;
491 std::stringstream iss(
"");
493 jrInfo[it0->subsystemName_ + std::string(
"_h")] = iss.str();
494 iss.str(
"");iss<<nBins;
495 jrInfo[it0->subsystemName_ + std::string(
"_b")] = iss.str();
496 iss.str(
"");iss<<nEmptyBins;
497 jrInfo[it0->subsystemName_ + std::string(
"_be")] = iss.str();
498 iss.str(
"");iss<< ((float)nEmptyBins/(
float)nBins);
499 jrInfo[it0->subsystemName_ + std::string(
"_fbe")] = iss.str();
500 iss.str(
"");iss<< ((float)nBins/(
float)nHistograms);
501 jrInfo[it0->subsystemName_ + std::string(
"_b_h")] = iss.str();
502 iss.str(
"");iss<<nBytes / 1024. / 1024.;
503 jrInfo[it0->subsystemName_ + std::string(
"_MB")] = iss.str();
504 iss.str(
"");iss<<nBytes / 1024. / nHistograms;
505 jrInfo[it0->subsystemName_ + std::string(
"_Kb_h")] = iss.str();
522 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
523 std::cout <<
"Memory profile:" << std::endl;
524 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
527 std::pair<time_t, unsigned int> maxItem( 0, 0 );
528 for( std::vector<std::pair<time_t, unsigned int> >::const_iterator it =
memoryHistoryVector_.begin();
530 if( it->second > maxItem.second ) {
535 std::stringstream rootOutputFileName;
536 rootOutputFileName <<
"dqmStoreStats_memProfile_" << getpid() <<
".root";
541 TFile
outputFile( rootOutputFileName.str().c_str(),
"RECREATE" );
546 TTree memHistoryTree(
"dqmstorestats_memhistory",
"memory history" );
547 memHistoryTree.Branch(
"seconds", &aTime,
"seconds/I" );
548 memHistoryTree.Branch(
"megabytes", &aMb,
"megabytes/F" );
549 for( std::vector<std::pair<time_t, unsigned int> >::const_iterator it =
memoryHistoryVector_.begin();
552 aMb = it->second / 1000.;
553 memHistoryTree.Fill();
561 std::cout <<
"Approx. maximum total virtual memory size of job: ";
564 <<
" MB (reached " << maxItem.first -
startingTime_ <<
" sec. after constructor called)," << std::endl;
567 std::cout <<
"(could not be determined)" << std::endl;
604 std::string readBuffer(
"" );
605 unsigned int memSize = 0;
608 while( !procFile.eof() ) {
609 procFile >> readBuffer;
610 if( std::string(
"VmSize:" ) == readBuffer ) {
617 return std::pair<time_t, unsigned int>(
time( 0 ), memSize );
620 return std::pair<time_t, unsigned int>( 0, 0 );
640 if( procFile.good() ) {
644 std::cerr <<
" [DQMStoreStats::beginJob] ** WARNING: could not open file: " <<
procFileName_.str() << std::endl;
645 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 beginRun(const edm::Run &r, const edm::EventSetup &c)
void AddBinsD(unsigned int nBins, unsigned int nEmptyBins)
virtual bool IsDone() const
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
std::vector< MonitorElement * > getMatchingContents(const std::string &pattern, lat::Regexp::Syntax syntaxType=lat::Regexp::Wildcard) const
std::string subsystemName_
void mainrows_cumulative(std::string &sql_statement)
VIterator< Folder * > CreateIterator()
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
void endRun(const edm::Run &r, const edm::EventSetup &c)
void summary(std::string &sql_statement)
void mainrows(std::string &sql_statement)
bool isOpenProcFileSuccessful_
std::pair< unsigned int, unsigned int > readMemoryEntry(void) const
std::string pathnamematch_
std::string maxbinsmesubsys_
DQMStoreStats(const edm::ParameterSet &)
void files(std::string &sql_statement)
virtual Item CurrentItem() const
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 dumpMemoryProfile(void)
void AddBinsF(unsigned int nBins, unsigned int nEmptyBins)
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
void children(std::string &sql_statement)
void calcIgProfDump(Folder &)
std::stringstream procFileName_
void analyze(const edm::Event &e, const edm::EventSetup &c)
void symbols(std::string &sql_statement)
string root
initialization