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_ (
""),
83 std::ofstream stream(
"dqm-bin-stats.sql");
85 " PRAGMA journal_mode=OFF;"
86 " PRAGMA count_changes=OFF;"
87 " DROP TABLE IF EXISTS files;"
88 " DROP TABLE IF EXISTS symbols;"
89 " DROP TABLE IF EXISTS mainrows;"
90 " DROP TABLE IF EXISTS children;"
91 " DROP TABLE IF EXISTS parents;"
92 " DROP TABLE IF EXISTS summary;"
93 " CREATE TABLE children ("
94 " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id),"
95 " parent_id INTEGER CONSTRAINT parent_exists REFERENCES mainrows(id),"
96 " from_parent_count INTEGER,"
97 " from_parent_calls INTEGER,"
98 " from_parent_paths INTEGER,"
101 " CREATE TABLE files ("
105 " CREATE TABLE mainrows ("
106 " id INTEGER PRIMARY KEY,"
107 " symbol_id INTEGER CONSTRAINT symbol_id_exists REFERENCES symbols(id),"
108 " self_count INTEGER,"
109 " cumulative_count INTEGER,"
111 " self_calls INTEGER,"
112 " total_calls INTEGER,"
113 " self_paths INTEGER,"
114 " total_paths INTEGER,"
117 " CREATE TABLE parents ("
118 " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id),"
119 " child_id INTEGER CONSTRAINT child_exists REFERENCES mainrows(id),"
120 " to_child_count INTEGER,"
121 " to_child_calls INTEGER,"
122 " to_child_paths INTEGER,"
125 " CREATE TABLE summary ("
127 " total_count INTEGER,"
128 " total_freq INTEGER,"
131 " CREATE TABLE symbols ("
134 " filename_id INTEGER CONSTRAINT file_id_exists REFERENCES files(id)"
136 " CREATE UNIQUE INDEX fileIndex ON files (id);"
137 " CREATE INDEX selfCountIndex ON mainrows(self_count);"
138 " CREATE UNIQUE INDEX symbolsIndex ON symbols (id);"
139 " CREATE INDEX totalCountIndex ON mainrows(cumulative_count);" << std::endl;
143 root.
files(sql_statement);
155 stream << sql_statement << std::endl;
174 size_t subsysStringEnd = 0, subfolderStringBegin = 0, subfolderStringEnd = 0;
177 std::vector<MonitorElement*> melist;
184 typedef std::vector <MonitorElement*>::iterator meIt;
185 for(meIt it = melist.begin(); it != melist.end(); ++it) {
189 !( (*it)->getLumiFlag() ) )
continue;
194 subfolderStringBegin = 0;
195 Folder * curr = &dbeFolder;
198 subfolderStringEnd = path.find(
'/', subfolderStringBegin );
199 if( std::string::npos == subfolderStringEnd )
201 curr = curr->
cd(path.substr( subfolderStringBegin, path.size()-subfolderStringBegin ));
204 curr = curr->
cd(path.substr( subfolderStringBegin, subfolderStringEnd-subfolderStringBegin ));
205 subfolderStringBegin = ++subfolderStringEnd < path.size() ? subfolderStringEnd : path.size();
209 if( 0 == path.size() )
continue;
211 subsysStringEnd = path.find(
'/', 0 );
212 if( std::string::npos == subsysStringEnd ) subsysStringEnd = path.size();
215 if( path.substr( 0, subsysStringEnd ) != subsystemname ) {
217 subsystemname = path.substr( 0, subsysStringEnd );
219 dqmStoreStatsTopLevel.push_back( aSubsystem );
224 if( path.size() == subsysStringEnd ) {
228 dqmStoreStatsTopLevel.back().push_back( aSubfolder );
234 subfolderStringEnd = path.find(
'/', subsysStringEnd + 1 );
235 if( std::string::npos == subfolderStringEnd ) subfolderStringEnd = path.size();
238 if( path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 ) != subfoldername ) {
239 subfoldername = path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 );
242 dqmStoreStatsTopLevel.back().push_back( aSubfolder );
250 switch( (*it)->kind() ) {
254 currentSubfolder.
AddBinsF( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1F()->GetArray(), (*it)->getTH1F()->fN, 0, 0) );
255 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1F()->GetArray(), (*it)->getTH1F()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( float ) );
258 currentSubfolder.
AddBinsS( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1S()->GetArray(), (*it)->getTH1S()->fN, 0, 0) );
259 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1S()->GetArray(), (*it)->getTH1S()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( short ) );
262 currentSubfolder.
AddBinsD( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1D()->GetArray(), (*it)->getTH1D()->fN, 0, 0) );
263 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1D()->GetArray(), (*it)->getTH1D()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( double ) );
266 currentSubfolder.
AddBinsD( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTProfile()->GetArray(), (*it)->getTProfile()->fN, 0, 0) );
267 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTProfile()->GetArray(), (*it)->getTProfile()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( double ) );
272 currentSubfolder.
AddBinsF( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
273 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(float) );
276 currentSubfolder.
AddBinsS( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2S()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
277 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2S()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(short) );
280 currentSubfolder.
AddBinsD( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
281 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(double) );
284 currentSubfolder.
AddBinsD( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTProfile2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
285 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTProfile2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(double) );
290 currentSubfolder.
AddBinsF( (*it)->getNbinsX() * (*it)->getNbinsY() * (*it)->getNbinsZ(),
getEmptyMetric( (*it)->getTH3F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, (*it)->getNbinsZ()+2 ) );
291 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY() * (*it)->getNbinsZ(),
292 getEmptyMetric( (*it)->getTH3F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, (*it)->getNbinsZ()+2 ),
293 (*it)->getNbinsX() * (*it)->getNbinsY() * (*it)->getNbinsZ()*
sizeof(float));
312 std::cout <<
"===========================================================================================" << std::endl;
313 std::cout <<
"[DQMStoreStats::calcstats] -- Dumping stats results ";
316 std::cout <<
"===========================================================================================" << std::endl;
319 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
320 std::cout <<
"Configuration:" << std::endl;
321 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
331 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
332 std::cout <<
"Top level folder tree:" << std::endl;
333 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
334 for( DQMStoreStatsTopLevel::const_iterator it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 ) {
335 std::cout << it0->subsystemName_ <<
" (subsystem)" << std::endl;
337 for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
338 std::cout <<
" |--> " << it1->subfolderName_ <<
" (subfolder)" << std::endl;
345 unsigned int overallNHistograms = 0, overallNBins = 0, overallNEmptyBins = 0, overallNBytes = 0;
348 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
349 std::cout <<
"Detailed ressource usage information ";
352 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
353 std::cout <<
"subsystem/folder histograms bins Empty bins Empty/Total bins per MB kB per" << std::endl;
354 std::cout <<
" (total) (total) (total) histogram (total) histogram " << std::endl;
355 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
356 for( DQMStoreStatsTopLevel::const_iterator it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 ) {
357 std::cout << it0->subsystemName_ << std::endl;
359 unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
361 for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
364 std::string thisSubfolderName( it1->subfolderName_ );
365 if( thisSubfolderName.size() > 30 ) {
366 thisSubfolderName.resize( 30 );
367 thisSubfolderName.replace( thisSubfolderName.size() - 3, 3, 3,
'.' );
370 std::cout <<
" -> " << std::setw( 30 ) << std::left << thisSubfolderName;
371 std::cout << std::setw( 14 ) << std::right << it1->totalHistos_;
372 std::cout << std::setw( 14 ) << std::right << it1->totalBins_;
373 std::cout << std::setw( 14 ) << std::right << it1->totalEmptyBins_;
374 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << (float)it1->totalEmptyBins_/(
float)it1->totalBins_;
377 if( it1->totalHistos_ ) {
378 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalBins_ / float( it1->totalHistos_ );
380 else std::cout << std::setw( 14 ) << std::right <<
"-";
382 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / 1024.;
385 if( it1->totalHistos_ ) {
386 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / it1->totalHistos_;
388 else std::cout << std::setw( 14 ) << std::right <<
"-";
393 nHistograms += it1->totalHistos_;
394 nBins += it1->totalBins_;
395 nEmptyBins += it1->totalEmptyBins_;
396 nBytes += it1->totalMemory_;
403 overallNHistograms += nHistograms;
404 overallNBins += nBins;
405 overallNEmptyBins += nEmptyBins;
406 overallNBytes += nBytes;
409 std::cout <<
" " << std::setw( 30 ) << std::left <<
"SUBSYSTEM TOTAL";
410 std::cout << std::setw( 14 ) << std::right << nHistograms;
411 std::cout << std::setw( 14 ) << std::right << nBins;
412 std::cout << std::setw( 14 ) << std::right << nEmptyBins;
413 std::cout << std::setw( 14 ) << std::right << (float)nEmptyBins/(
float)nBins;
414 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBins / float( nHistograms );
415 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBytes / 1024. / 1000.;
416 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBytes / 1024. / nHistograms;
419 std::cout <<
".........................................................................................." << std::endl;
426 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
430 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
431 std::cout <<
"Number of subsystems: " << dqmStoreStatsTopLevel.size() << std::endl;
432 std::cout <<
"Total number of histograms: " << overallNHistograms <<
" with: " << overallNBins <<
" bins alltogether" << std::endl;
433 std::cout <<
"Total memory occupied by histograms (excl. overhead): " << overallNBytes / 1024. / 1000. <<
" MB" << std::endl;
438 std::cout <<
"===========================================================================================" << std::endl;
439 std::cout <<
"[DQMStoreStats::calcstats] -- End of output ";
442 std::cout <<
"===========================================================================================" << std::endl;
455 std::map<std::string, std::string> jrInfo;
456 unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
458 jrInfo[
"Source"] =
"DQMServices/Components";
459 jrInfo[
"FileClass"] =
"DQMStoreStats";
461 jrInfo[
"DumpType"] =
"EndRun";
463 jrInfo[
"DumpType"] =
"EndLumi";
465 jrInfo[
"DumpType"] =
"EndJob";
467 jrInfo[
"DumpType"] =
"EventLoop";
469 jrInfo[
"Type"] =
"RunProduct";
471 jrInfo[
"Type"] =
"LumiProduct";
476 for (DQMStoreStatsTopLevel::const_iterator it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 )
478 unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
479 for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
481 nHistograms += it1->totalHistos_;
482 nBins += it1->totalBins_;
483 nEmptyBins += it1->totalEmptyBins_;
484 nBytes += it1->totalMemory_;
486 overallNHistograms += nHistograms;
487 overallNBins += nBins;
488 overallNBytes += nBytes;
489 std::stringstream iss(
"");
491 jrInfo[it0->subsystemName_ +
std::string(
"_h")] = iss.str();
492 iss.str(
"");iss<<nBins;
493 jrInfo[it0->subsystemName_ +
std::string(
"_b")] = iss.str();
494 iss.str(
"");iss<<nEmptyBins;
495 jrInfo[it0->subsystemName_ +
std::string(
"_be")] = iss.str();
496 iss.str(
"");iss<< ((float)nEmptyBins/(
float)nBins);
497 jrInfo[it0->subsystemName_ +
std::string(
"_fbe")] = iss.str();
498 iss.str(
"");iss<< ((float)nBins/(
float)nHistograms);
499 jrInfo[it0->subsystemName_ +
std::string(
"_b_h")] = iss.str();
500 iss.str(
"");iss<<nBytes / 1024. / 1024.;
501 jrInfo[it0->subsystemName_ +
std::string(
"_MB")] = iss.str();
502 iss.str(
"");iss<<nBytes / 1024. / nHistograms;
503 jrInfo[it0->subsystemName_ +
std::string(
"_Kb_h")] = iss.str();
520 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
521 std::cout <<
"Memory profile:" << std::endl;
522 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
525 std::pair<time_t, unsigned int> maxItem( 0, 0 );
526 for( std::vector<std::pair<time_t, unsigned int> >::const_iterator it =
memoryHistoryVector_.begin();
528 if( it->second > maxItem.second ) {
533 std::stringstream rootOutputFileName;
534 rootOutputFileName <<
"dqmStoreStats_memProfile_" << getpid() <<
".root";
539 TFile
outputFile( rootOutputFileName.str().c_str(),
"RECREATE" );
544 TTree memHistoryTree(
"dqmstorestats_memhistory",
"memory history" );
545 memHistoryTree.Branch(
"seconds", &aTime,
"seconds/I" );
546 memHistoryTree.Branch(
"megabytes", &aMb,
"megabytes/F" );
547 for( std::vector<std::pair<time_t, unsigned int> >::const_iterator it =
memoryHistoryVector_.begin();
550 aMb = it->second / 1000.;
551 memHistoryTree.Fill();
559 std::cout <<
"Approx. maximum total virtual memory size of job: ";
562 <<
" MB (reached " << maxItem.first -
startingTime_ <<
" sec. after constructor called)," << std::endl;
565 std::cout <<
"(could not be determined)" << std::endl;
603 unsigned int memSize = 0;
606 while( !procFile.eof() ) {
607 procFile >> readBuffer;
615 return std::pair<time_t, unsigned int>(
time( 0 ), memSize );
618 return std::pair<time_t, unsigned int>( 0, 0 );
638 if( procFile.good() ) {
642 std::cerr <<
" [DQMStoreStats::beginJob] ** WARNING: could not open file: " <<
procFileName_.str() << std::endl;
643 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_
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)
tuple path
else: Piece not in the list, fine.
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 reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
void calcIgProfDump(Folder &)
std::stringstream procFileName_
volatile std::atomic< bool > shutdown_flag false
void analyze(const edm::Event &e, const edm::EventSetup &c)
void symbols(std::string &sql_statement)
string root
initialization