CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMStoreStats.cc
Go to the documentation of this file.
1 /*
2  * \file DQMStoreStats.cc
3  * \author Andreas Meyer
4  * Last Update:
5  * $Date: 2011/06/07 23:29:24 $
6  * $Revision: 1.15 $
7  * $Author: rovere $
8  *
9  * Description: Print out statistics of histograms in DQMStore
10 */
11 
15 
16 using namespace std;
17 using namespace edm;
18 
19 template <class T>
20 static unsigned int getEmptyMetric(T * array, int lenx, int leny, int lenz)
21 {
22  // len{x,y,z} MUST include under/overflow bins.
23  unsigned int len = lenx+leny+lenz;
24  unsigned int result=0;
25  // start from 1 to exclude underflow bin. The comparison is accurate
26  // since it takes properly into account under/overflow bins, for all
27  // kind of histograms.
28  for (unsigned int i=1; i<len; ++i)
29  {
30  // get rid of under/overflow bins for x,y,z axis, to have a correct statistics.
31  if (i%(lenx-1)==0)
32  continue;
33  if (i%lenx==0)
34  continue;
35  if (i%(lenx+leny-1)==0)
36  continue;
37  if (i%(lenx+leny)==0)
38  continue;
39  if (i%(lenx+leny+lenz-1)==0)
40  continue;
41 
42  if (array[i] == 0)
43  result += 1;
44  }
45 
46  return result;
47 }
48 
49 //==================================================================//
50 //================= Constructor and Destructor =====================//
51 //==================================================================//
53  : subsystem_ (""),
54  subfolder_ (""),
55  nbinsglobal_ (0),
56  nbinssubsys_ (0),
57  nmeglobal_ (0),
58  nmesubsys_ (0),
59  maxbinsglobal_ (0),
60  maxbinssubsys_ (0),
61  maxbinsmeglobal_ (""),
62  maxbinsmesubsys_ (""),
63  statsdepth_ (1),
64  pathnamematch_ ("*"),
65  verbose_ (0)
66 {
67  parameters_ = ps;
68  pathnamematch_ = ps.getUntrackedParameter<std::string>( "pathNameMatch", pathnamematch_ );
69  statsdepth_ = ps.getUntrackedParameter<int>( "statsDepth", statsdepth_ );
70  verbose_ = ps.getUntrackedParameter<int>( "verbose", verbose_ );
71  dumpMemHistory_ = ps.getUntrackedParameter<bool>( "dumpMemoryHistory", false );
72  runonendrun_ = ps.getUntrackedParameter<bool>( "runOnEndRun", true );
73  runonendjob_ = ps.getUntrackedParameter<bool>( "runOnEndJob", false );
74  runonendlumi_ = ps.getUntrackedParameter<bool>( "runOnEndLumi", false );
75  runineventloop_ = ps.getUntrackedParameter<bool>( "runInEventLoop", false );
76  dumpToFWJR_ = ps.getUntrackedParameter<bool>( "dumpToFWJR", false );
77 
78  startingTime_ = time( 0 );
79 }
80 
82 }
83 
85 {
86  std::ofstream stream("dqm-bin-stats.sql");
87  stream << ""
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,"
102 " pct REAL"
103 " );"
104 " CREATE TABLE files ("
105 " id,"
106 " name TEXT"
107 " );"
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,"
113 " kids INTEGER,"
114 " self_calls INTEGER,"
115 " total_calls INTEGER,"
116 " self_paths INTEGER,"
117 " total_paths INTEGER,"
118 " pct REAL"
119 " );"
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,"
126 " pct REAL"
127 " );"
128 " CREATE TABLE summary ("
129 " counter TEXT,"
130 " total_count INTEGER,"
131 " total_freq INTEGER,"
132 " tick_period REAL"
133 " );"
134 " CREATE TABLE symbols ("
135 " id,"
136 " name TEXT,"
137 " filename_id INTEGER CONSTRAINT file_id_exists REFERENCES files(id)"
138 " );"
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;
143 
144  std::string sql_statement("");
145 
146  root.files(sql_statement);
147  root.symbols(sql_statement);
148  root.mainrows_cumulative(sql_statement);
149  root.summary(sql_statement);
150  VIterator<Folder *> subsystems = root.CreateIterator() ;
151  size_t ii=0;
152  for(subsystems.First() ; !subsystems.IsDone() ; subsystems.Next(), ++ii)
153  {
154  subsystems.CurrentItem()->mainrows(sql_statement);
155  subsystems.CurrentItem()->parents(sql_statement);
156  subsystems.CurrentItem()->children(sql_statement);
157  }
158  stream << sql_statement << std::endl;
159 }
160 
168 
170  nbinsglobal_ = 0;
171  nbinssubsys_ = 0;
172  maxbinsglobal_ = 0;
173  maxbinssubsys_ = 0;
174  std::string path = "";
175  std::string subsystemname = "";
176  std::string subfoldername = "";
177  size_t subsysStringEnd = 0, subfolderStringBegin = 0, subfolderStringEnd = 0;
178 
179 
180  std::vector<MonitorElement*> melist;
182 
183  Folder dbeFolder("root");
184  DQMStoreStatsTopLevel dqmStoreStatsTopLevel;
185 
186  // loop all ME
187  typedef std::vector <MonitorElement*>::iterator meIt;
188  for(meIt it = melist.begin(); it != melist.end(); ++it) {
189 
190  // consider only ME with getLumiFlag() == true ?
192  !( (*it)->getLumiFlag() ) ) continue;
193 
194  // figure out subsystem/subfolder names
195  std::string path = (*it)->getPathname();
196 
197  subfolderStringBegin = 0;
198  Folder * curr = &dbeFolder;
199  while(1)
200  {
201  subfolderStringEnd = path.find( '/', subfolderStringBegin );
202  if( std::string::npos == subfolderStringEnd )
203  {
204  curr = curr->cd(path.substr( subfolderStringBegin, path.size() ));
205  break;
206  }
207  curr = curr->cd(path.substr( subfolderStringBegin, subfolderStringEnd-subfolderStringBegin ));
208  subfolderStringBegin = subfolderStringEnd+1;
209  }
210 
211  // protection against ghost ME with empty paths
212  if( 0 == path.size() ) continue;
213 
214  subsysStringEnd = path.find( '/', 0 );
215  if( std::string::npos == subsysStringEnd ) subsysStringEnd = path.size(); // no subfolder
216 
217  // new subsystem?
218  if( path.substr( 0, subsysStringEnd ) != subsystemname ) {
219  DQMStoreStatsSubsystem aSubsystem;
220  subsystemname = path.substr( 0, subsysStringEnd );
221  aSubsystem.subsystemName_ = subsystemname;
222  dqmStoreStatsTopLevel.push_back( aSubsystem );
223  }
224 
225  // get subfolder name (if there is one..)
226  if( path.size() == subsysStringEnd ) {
227  // no subfolders in subsystem, make dummy
228  DQMStoreStatsSubfolder aSubfolder;
229  aSubfolder.subfolderName_ = subsystemname; // <-- for tagging this case
230  dqmStoreStatsTopLevel.back().push_back( aSubfolder );
231  }
232 
233  else {
234 
235  // there is a subfolder, get its name
236  subfolderStringEnd = path.find( '/', subsysStringEnd + 1 );
237  if( std::string::npos == subfolderStringEnd ) subfolderStringEnd = path.size();
238 
239  // new subfolder?
240  if( path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 ) != subfoldername ) {
241  subfoldername = path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 );
242  DQMStoreStatsSubfolder aSubfolder;
243  aSubfolder.subfolderName_ = subfoldername;
244  dqmStoreStatsTopLevel.back().push_back( aSubfolder );
245  }
246 
247  }
248 
249  // shortcut
250  DQMStoreStatsSubfolder& currentSubfolder = dqmStoreStatsTopLevel.back().back();
251 
252  switch( (*it)->kind() ) {
253 
254  // one-dim ME
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 ) );
258  break;
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 ) );
262  break;
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 ) );
266  break;
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 ) );
270  break;
271 
272  // two-dim ME
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) );
276  break;
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) );
280  break;
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) );
284  break;
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) );
288  break;
289 
290  // three-dim ME
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));
296  break;
297 
298  default: {}
299  // here we have a DQM_KIND_INVALID, DQM_KIND_INT, DQM_KIND_REAL or DQM_KIND_STRING
300  // which we don't care much about. Alternatively:
301 
302  // std::cerr << "[DQMStoreStats::calcstats] ** WARNING: monitor element of kind: "
303  // << (*it)->kind() << ", name: \"" << (*it)->getName() << "\"\n"
304  // << " in path: \"" << path << "\" not considered." << std::endl;
305  }
306  }
307 
309  calcIgProfDump(dbeFolder);
310 
311  // OUTPUT
312 
313  std::cout << endl;
314  std::cout << "===========================================================================================" << std::endl;
315  std::cout << "[DQMStoreStats::calcstats] -- Dumping stats results ";
316  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME" << std::endl;
317  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY" << std::endl;
318  std::cout << "===========================================================================================" << std::endl;
319  std::cout << endl;
320 
321  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
322  std::cout << "Configuration:" << std::endl;
323  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
324  std::cout << " > running ";
325  if (runonendrun_) std::cout << "on run end." << std::endl;
326  if (runonendlumi_) std::cout << "on lumi end." << std::endl;
327  if (runonendjob_) std::cout << "on job end." << std::endl;
328  if (runineventloop_) std::cout << "in event loop." << std::endl;
329  std::cout << " > pathNameMatch = \"" << pathnamematch_ << "\"" << std::endl;
330  std::cout << std::endl;
331 
332  // dump folder structure
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;
338 
339  for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
340  std::cout << " |--> " << it1->subfolderName_ << " (subfolder)" << std::endl;
341  }
342 
343  }
344 
345  // dump mem/bin table
346 
347  unsigned int overallNHistograms = 0, overallNBins = 0, overallNEmptyBins = 0, overallNBytes = 0;
348 
349  std::cout << std::endl;
350  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
351  std::cout << "Detailed ressource usage information ";
352  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME" << std::endl;
353  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY" << std::endl;
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;
360 
361  unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
362 
363  for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
364 
365  // fixed-size working copy
366  std::string thisSubfolderName( it1->subfolderName_ );
367  if( thisSubfolderName.size() > 30 ) {
368  thisSubfolderName.resize( 30 );
369  thisSubfolderName.replace( thisSubfolderName.size() - 3, 3, 3, '.' );
370  }
371 
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_;
377 
378  // bins/histogram, need to catch nan if histos=0
379  if( it1->totalHistos_ ) {
380  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalBins_ / float( it1->totalHistos_ );
381  }
382  else std::cout << std::setw( 14 ) << std::right << "-";
383 
384  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / 1024.;
385 
386  // mem/histogram, need to catch nan if histos=0
387  if( it1->totalHistos_ ) {
388  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / it1->totalHistos_;
389  }
390  else std::cout << std::setw( 14 ) << std::right << "-";
391 
392  std::cout << std::endl;
393 
394  // collect totals
395  nHistograms += it1->totalHistos_;
396  nBins += it1->totalBins_;
397  nEmptyBins += it1->totalEmptyBins_;
398  nBytes += it1->totalMemory_;
399 
400  }
401 
402 
403 
404 
405  overallNHistograms += nHistograms;
406  overallNBins += nBins;
407  overallNEmptyBins += nEmptyBins;
408  overallNBytes += nBytes;
409 
410  // display totals
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;
419  std::cout << std::endl;
420 
421  std::cout << ".........................................................................................." << std::endl;
422 
423  }
424 
425 
426  // dump total
427  std::cout << std::endl;
428  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
429  std::cout << "Grand total ";
430  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME:" << std::endl;
431  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY:" << 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;
436 
437 
438 
439  std::cout << endl;
440  std::cout << "===========================================================================================" << std::endl;
441  std::cout << "[DQMStoreStats::calcstats] -- End of output ";
442  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME." << std::endl;
443  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY." << std::endl;
444  std::cout << "===========================================================================================" << std::endl;
445  std::cout << endl;
446 
447  // Put together a simplified version of the complete dump that is
448  // sent to std::cout. Just dump the very basic information,
449  // i.e. summary for each folder, both for run and LS products.
450  if (dumpToFWJR_)
451  {
453  // Do not even try if the FWJR service is not available.
454  if (!jr.isAvailable())
455  return 0;
456  // Prepare appropriate map to store FWJR output.
457  std::map<std::string, std::string> jrInfo;
458  unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
459 
460  jrInfo["Source"] = "DQMServices/Components";
461  jrInfo["FileClass"] = "DQMStoreStats";
462  if (runonendrun_)
463  jrInfo["DumpType"] = "EndRun";
464  if (runonendlumi_)
465  jrInfo["DumpType"] = "EndLumi";
466  if (runonendjob_)
467  jrInfo["DumpType"] = "EndJob";
468  if (runineventloop_)
469  jrInfo["DumpType"] = "EventLoop";
471  jrInfo["Type"] = "RunProduct";
473  jrInfo["Type"] = "LumiProduct";
474 
475 
476  jrInfo["pathNameMatch"] = pathnamematch_;
477 
478  for (DQMStoreStatsTopLevel::const_iterator it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 )
479  {
480  unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
481  for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
482  // collect totals
483  nHistograms += it1->totalHistos_;
484  nBins += it1->totalBins_;
485  nEmptyBins += it1->totalEmptyBins_;
486  nBytes += it1->totalMemory_;
487  }
488  overallNHistograms += nHistograms;
489  overallNBins += nBins;
490  overallNBytes += nBytes;
491  std::stringstream iss("");
492  iss << nHistograms;
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();
506  }
507  jr->reportAnalysisFile("DQMStatsReport", jrInfo);
508  }
509 
510  return 0;
511 
512 }
513 
514 
515 
520 
521  std::cout << std::endl;
522  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
523  std::cout << "Memory profile:" << std::endl;
524  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
525 
526  // determine virtual memory maximum
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();
529  it < memoryHistoryVector_.end(); ++it ) {
530  if( it->second > maxItem.second ) {
531  maxItem = *it;
532  }
533  }
534 
535  std::stringstream rootOutputFileName;
536  rootOutputFileName << "dqmStoreStats_memProfile_" << getpid() << ".root";
537 
538  // dump memory history to root file
540 
541  TFile outputFile( rootOutputFileName.str().c_str(), "RECREATE" );
542 
543  int aTime;
544  float aMb;
545 
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();
550  it < memoryHistoryVector_.end(); ++it ) {
551  aTime = it->first - startingTime_;
552  aMb = it->second / 1000.;
553  memHistoryTree.Fill();
554  }
555 
556  outputFile.Write();
557  outputFile.Close();
558 
559  }
560 
561  std::cout << "Approx. maximum total virtual memory size of job: ";
563  std::cout << maxItem.second / 1000.
564  << " MB (reached " << maxItem.first - startingTime_ << " sec. after constructor called)," << std::endl;
565  std::cout << " memory history written to: " << rootOutputFileName.str() << " (" << memoryHistoryVector_.size() << " samples)" << std::endl;
566  } else {
567  std::cout << "(could not be determined)" << std::endl;
568  }
569 
570  std::cout << std::endl << std::endl;
571 
572 }
573 
574 
575 
580  // subsystem info printout
581  std::cout << " ---------- " << subsystem_ << " ---------- " << std::endl;
582  std::cout << " " << subfolder_ << ": " ;
583  std::cout << nmesubsys_ << " histograms with "
584  << nbinssubsys_ << " bins. " ;
585  if (nmesubsys_ > 0) std::cout << nbinssubsys_/nmesubsys_ << " bins/histogram " ;
586  std::cout << std::endl;
587  std::cout << " Largest histogram: " << maxbinsmesubsys_ << " with " <<
588  maxbinssubsys_ << " bins." << std::endl;
589 }
590 
591 
592 
593 
597 std::pair<unsigned int, unsigned int> DQMStoreStats::readMemoryEntry( void ) const {
598 
599  // see if initial test reading was successful
601 
602  std::ifstream procFile( procFileName_.str().c_str(), ios::in );
603 
604  std::string readBuffer( "" );
605  unsigned int memSize = 0;
606 
607  // scan procfile
608  while( !procFile.eof() ) {
609  procFile >> readBuffer;
610  if( std::string( "VmSize:" ) == readBuffer ) {
611  procFile >> memSize;
612  break;
613  }
614  }
615 
616  procFile.close();
617  return std::pair<time_t, unsigned int>( time( 0 ), memSize );
618  }
619 
620  return std::pair<time_t, unsigned int>( 0, 0 );
621 
622 }
623 
624 
625 
626 //==================================================================//
627 //========================= beginJob ===============================//
628 //==================================================================//
630 
633 
634  // access the proc/ folder for memory information
635  procFileName_ << "/proc/" << getpid() << "/status";
636 
637  // open for a test
638  std::ifstream procFile( procFileName_.str().c_str(), ios::in );
639 
640  if( procFile.good() ) {
642  }
643  else {
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;
647  }
648 
649  procFile.close();
650 
651 }
652 
653 //==================================================================//
654 //========================= beginRun ===============================//
655 //==================================================================//
656 void DQMStoreStats::beginRun(const edm::Run& r, const EventSetup& context) {
657 }
658 
659 
660 //==================================================================//
661 //==================== beginLuminosityBlock ========================//
662 //==================================================================//
664  const EventSetup& context) {
665 }
666 
667 
668 //==================================================================//
669 //==================== analyse (takes each event) ==================//
670 //==================================================================//
671 void DQMStoreStats::analyze(const Event& iEvent, const EventSetup& iSetup) {
672 
673  //now read virtual memory size from proc folder
674  memoryHistoryVector_.push_back( readMemoryEntry() );
675 
676  if (runineventloop_) {
680  }
681 
682 }
683 
684 
685 //==================================================================//
686 //========================= endLuminosityBlock =====================//
687 //==================================================================//
689  const EventSetup& context) {
690  if (runonendlumi_) {
694  }
695 
696 }
697 
698 //==================================================================//
699 //============================= endRun =============================//
700 //==================================================================//
701 void DQMStoreStats::endRun(const Run& r, const EventSetup& context) {
702 
703  if (runonendrun_) {
707  }
708 
709 }
710 
711 //==================================================================//
712 //============================= endJob =============================//
713 //==================================================================//
715 
716  if (runonendjob_) {
720  }
721 
722 }
std::string subfolderName_
Definition: DQMStoreStats.h:44
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
DQMStore * dbe_
void AddBinsS(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:50
virtual void First()
Definition: DQMStoreStats.h:91
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)
Definition: DQMStoreStats.h:51
virtual bool IsDone() const
Definition: DQMStoreStats.h:96
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:652
std::vector< MonitorElement * > getMatchingContents(const std::string &pattern, lat::Regexp::Syntax syntaxType=lat::Regexp::Wildcard) const
Definition: DQMStore.cc:1488
std::string subsystemName_
Definition: DQMStoreStats.h:61
void mainrows_cumulative(std::string &sql_statement)
VIterator< Folder * > CreateIterator()
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
time_t startingTime_
void endRun(const edm::Run &r, const edm::EventSetup &c)
void summary(std::string &sql_statement)
int path() const
Definition: HLTadd.h:3
std::string subsystem_
void mainrows(std::string &sql_statement)
int calcstats(int)
int iEvent
Definition: GenABIO.cc:243
bool isOpenProcFileSuccessful_
std::pair< unsigned int, unsigned int > readMemoryEntry(void) const
tuple result
Definition: query.py:137
std::string pathnamematch_
bool isAvailable() const
Definition: Service.h:47
std::string maxbinsmesubsys_
DQMStoreStats(const edm::ParameterSet &)
void files(std::string &sql_statement)
virtual void Next()
Definition: DQMStoreStats.h:92
virtual Item CurrentItem() const
void parents(std::string &sql_statement)
std::string subfolder_
static unsigned int getEmptyMetric(T *array, int lenx, int leny, int lenz)
int mode
Definition: AMPTWrapper.h:139
Folder * cd(const std::string &name)
edm::ParameterSet parameters_
void dumpMemoryProfile(void)
void AddBinsF(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:49
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
void children(std::string &sql_statement)
void calcIgProfDump(Folder &)
tuple cout
Definition: gather_cfg.py:41
std::stringstream procFileName_
void analyze(const edm::Event &e, const edm::EventSetup &c)
long double T
void symbols(std::string &sql_statement)
Definition: Run.h:32
string root
initialization
Definition: dbtoconf.py:70