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;
146 root.
files(sql_statement);
158 stream << sql_statement << std::endl;
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;
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()-subfolderStringBegin ));
207 curr = curr->
cd(path.substr( subfolderStringBegin, subfolderStringEnd-subfolderStringBegin ));
208 subfolderStringBegin = ++subfolderStringEnd < path.size() ? subfolderStringEnd : path.size();
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 );
227 if( path.size() == subsysStringEnd ) {
231 dqmStoreStatsTopLevel.back().push_back( aSubfolder );
237 subfolderStringEnd = path.find(
'/', subsysStringEnd + 1 );
238 if( std::string::npos == subfolderStringEnd ) subfolderStringEnd = path.size();
241 if( path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 ) != subfoldername ) {
242 subfoldername = path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 );
245 dqmStoreStatsTopLevel.back().push_back( aSubfolder );
253 switch( (*it)->kind() ) {
257 currentSubfolder.
AddBinsF( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1F()->GetArray(), (*it)->getTH1F()->fN, 0, 0) );
258 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1F()->GetArray(), (*it)->getTH1F()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( float ) );
261 currentSubfolder.
AddBinsS( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1S()->GetArray(), (*it)->getTH1S()->fN, 0, 0) );
262 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1S()->GetArray(), (*it)->getTH1S()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( short ) );
265 currentSubfolder.
AddBinsD( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1D()->GetArray(), (*it)->getTH1D()->fN, 0, 0) );
266 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTH1D()->GetArray(), (*it)->getTH1D()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( double ) );
269 currentSubfolder.
AddBinsD( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTProfile()->GetArray(), (*it)->getTProfile()->fN, 0, 0) );
270 curr->
update( (*it)->getNbinsX(),
getEmptyMetric((*it)->getTProfile()->GetArray(), (*it)->getTProfile()->fN, 0, 0), (*it)->getNbinsX()*
sizeof( double ) );
275 currentSubfolder.
AddBinsF( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
276 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(float) );
279 currentSubfolder.
AddBinsS( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2S()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
280 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2S()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(short) );
283 currentSubfolder.
AddBinsD( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
284 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTH2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(double) );
287 currentSubfolder.
AddBinsD( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTProfile2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0) );
288 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY(),
getEmptyMetric((*it)->getTProfile2D()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, 0), (*it)->getNbinsX() * (*it)->getNbinsY()*
sizeof(double) );
293 currentSubfolder.
AddBinsF( (*it)->getNbinsX() * (*it)->getNbinsY() * (*it)->getNbinsZ(),
getEmptyMetric( (*it)->getTH3F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, (*it)->getNbinsZ()+2 ) );
294 curr->
update( (*it)->getNbinsX() * (*it)->getNbinsY() * (*it)->getNbinsZ(),
295 getEmptyMetric( (*it)->getTH3F()->GetArray(), (*it)->getNbinsX()+2, (*it)->getNbinsY()+2, (*it)->getNbinsZ()+2 ),
296 (*it)->getNbinsX() * (*it)->getNbinsY() * (*it)->getNbinsZ()*
sizeof(float));
315 std::cout <<
"===========================================================================================" << std::endl;
316 std::cout <<
"[DQMStoreStats::calcstats] -- Dumping stats results ";
319 std::cout <<
"===========================================================================================" << std::endl;
322 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
323 std::cout <<
"Configuration:" << std::endl;
324 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
334 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
335 std::cout <<
"Top level folder tree:" << std::endl;
336 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
337 for( DQMStoreStatsTopLevel::const_iterator it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 ) {
338 std::cout << it0->subsystemName_ <<
" (subsystem)" << std::endl;
340 for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
341 std::cout <<
" |--> " << it1->subfolderName_ <<
" (subfolder)" << std::endl;
348 unsigned int overallNHistograms = 0, overallNBins = 0, overallNEmptyBins = 0, overallNBytes = 0;
351 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
352 std::cout <<
"Detailed ressource usage information ";
355 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
356 std::cout <<
"subsystem/folder histograms bins Empty bins Empty/Total bins per MB kB per" << std::endl;
357 std::cout <<
" (total) (total) (total) histogram (total) histogram " << std::endl;
358 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
359 for( DQMStoreStatsTopLevel::const_iterator it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 ) {
360 std::cout << it0->subsystemName_ << std::endl;
362 unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
364 for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
367 std::string thisSubfolderName( it1->subfolderName_ );
368 if( thisSubfolderName.size() > 30 ) {
369 thisSubfolderName.resize( 30 );
370 thisSubfolderName.replace( thisSubfolderName.size() - 3, 3, 3,
'.' );
373 std::cout <<
" -> " << std::setw( 30 ) << std::left << thisSubfolderName;
374 std::cout << std::setw( 14 ) << std::right << it1->totalHistos_;
375 std::cout << std::setw( 14 ) << std::right << it1->totalBins_;
376 std::cout << std::setw( 14 ) << std::right << it1->totalEmptyBins_;
377 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << (float)it1->totalEmptyBins_/(
float)it1->totalBins_;
380 if( it1->totalHistos_ ) {
381 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalBins_ / float( it1->totalHistos_ );
383 else std::cout << std::setw( 14 ) << std::right <<
"-";
385 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / 1024.;
388 if( it1->totalHistos_ ) {
389 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / it1->totalHistos_;
391 else std::cout << std::setw( 14 ) << std::right <<
"-";
396 nHistograms += it1->totalHistos_;
397 nBins += it1->totalBins_;
398 nEmptyBins += it1->totalEmptyBins_;
399 nBytes += it1->totalMemory_;
406 overallNHistograms += nHistograms;
407 overallNBins += nBins;
408 overallNEmptyBins += nEmptyBins;
409 overallNBytes += nBytes;
412 std::cout <<
" " << std::setw( 30 ) << std::left <<
"SUBSYSTEM TOTAL";
413 std::cout << std::setw( 14 ) << std::right << nHistograms;
414 std::cout << std::setw( 14 ) << std::right << nBins;
415 std::cout << std::setw( 14 ) << std::right << nEmptyBins;
416 std::cout << std::setw( 14 ) << std::right << (float)nEmptyBins/(
float)nBins;
417 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBins / float( nHistograms );
418 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBytes / 1024. / 1000.;
419 std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBytes / 1024. / nHistograms;
422 std::cout <<
".........................................................................................." << std::endl;
429 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
433 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
434 std::cout <<
"Number of subsystems: " << dqmStoreStatsTopLevel.size() << std::endl;
435 std::cout <<
"Total number of histograms: " << overallNHistograms <<
" with: " << overallNBins <<
" bins alltogether" << std::endl;
436 std::cout <<
"Total memory occupied by histograms (excl. overhead): " << overallNBytes / 1024. / 1000. <<
" MB" << std::endl;
441 std::cout <<
"===========================================================================================" << std::endl;
442 std::cout <<
"[DQMStoreStats::calcstats] -- End of output ";
445 std::cout <<
"===========================================================================================" << std::endl;
458 std::map<std::string, std::string> jrInfo;
459 unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
461 jrInfo[
"Source"] =
"DQMServices/Components";
462 jrInfo[
"FileClass"] =
"DQMStoreStats";
464 jrInfo[
"DumpType"] =
"EndRun";
466 jrInfo[
"DumpType"] =
"EndLumi";
468 jrInfo[
"DumpType"] =
"EndJob";
470 jrInfo[
"DumpType"] =
"EventLoop";
472 jrInfo[
"Type"] =
"RunProduct";
474 jrInfo[
"Type"] =
"LumiProduct";
479 for (DQMStoreStatsTopLevel::const_iterator it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 )
481 unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
482 for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
484 nHistograms += it1->totalHistos_;
485 nBins += it1->totalBins_;
486 nEmptyBins += it1->totalEmptyBins_;
487 nBytes += it1->totalMemory_;
489 overallNHistograms += nHistograms;
490 overallNBins += nBins;
491 overallNBytes += nBytes;
492 std::stringstream iss(
"");
494 jrInfo[it0->subsystemName_ +
std::string(
"_h")] = iss.str();
495 iss.str(
"");iss<<nBins;
496 jrInfo[it0->subsystemName_ +
std::string(
"_b")] = iss.str();
497 iss.str(
"");iss<<nEmptyBins;
498 jrInfo[it0->subsystemName_ +
std::string(
"_be")] = iss.str();
499 iss.str(
"");iss<< ((float)nEmptyBins/(
float)nBins);
500 jrInfo[it0->subsystemName_ +
std::string(
"_fbe")] = iss.str();
501 iss.str(
"");iss<< ((float)nBins/(
float)nHistograms);
502 jrInfo[it0->subsystemName_ +
std::string(
"_b_h")] = iss.str();
503 iss.str(
"");iss<<nBytes / 1024. / 1024.;
504 jrInfo[it0->subsystemName_ +
std::string(
"_MB")] = iss.str();
505 iss.str(
"");iss<<nBytes / 1024. / nHistograms;
506 jrInfo[it0->subsystemName_ +
std::string(
"_Kb_h")] = iss.str();
523 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
524 std::cout <<
"Memory profile:" << std::endl;
525 std::cout <<
"------------------------------------------------------------------------------------------" << std::endl;
528 std::pair<time_t, unsigned int> maxItem( 0, 0 );
529 for( std::vector<std::pair<time_t, unsigned int> >::const_iterator it =
memoryHistoryVector_.begin();
531 if( it->second > maxItem.second ) {
536 std::stringstream rootOutputFileName;
537 rootOutputFileName <<
"dqmStoreStats_memProfile_" << getpid() <<
".root";
542 TFile
outputFile( rootOutputFileName.str().c_str(),
"RECREATE" );
547 TTree memHistoryTree(
"dqmstorestats_memhistory",
"memory history" );
548 memHistoryTree.Branch(
"seconds", &aTime,
"seconds/I" );
549 memHistoryTree.Branch(
"megabytes", &aMb,
"megabytes/F" );
550 for( std::vector<std::pair<time_t, unsigned int> >::const_iterator it =
memoryHistoryVector_.begin();
553 aMb = it->second / 1000.;
554 memHistoryTree.Fill();
562 std::cout <<
"Approx. maximum total virtual memory size of job: ";
565 <<
" MB (reached " << maxItem.first -
startingTime_ <<
" sec. after constructor called)," << std::endl;
568 std::cout <<
"(could not be determined)" << std::endl;
606 unsigned int memSize = 0;
609 while( !procFile.eof() ) {
610 procFile >> readBuffer;
618 return std::pair<time_t, unsigned int>(
time( 0 ), memSize );
621 return std::pair<time_t, unsigned int>( 0, 0 );
641 if( procFile.good() ) {
645 std::cerr <<
" [DQMStoreStats::beginJob] ** WARNING: could not open file: " <<
procFileName_.str() << std::endl;
646 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