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: 2012/08/17 15:44:22 $
6  * $Revision: 1.17 $
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;
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()-subfolderStringBegin ));
205  break;
206  }
207  curr = curr->cd(path.substr( subfolderStringBegin, subfolderStringEnd-subfolderStringBegin ));
208  subfolderStringBegin = ++subfolderStringEnd < path.size() ? subfolderStringEnd : path.size();
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  subfoldername = "";
224  }
225 
226  // get subfolder name (if there is one..)
227  if( path.size() == subsysStringEnd ) {
228  // no subfolders in subsystem, make dummy
229  DQMStoreStatsSubfolder aSubfolder;
230  aSubfolder.subfolderName_ = subsystemname; // <-- for tagging this case
231  dqmStoreStatsTopLevel.back().push_back( aSubfolder );
232  }
233 
234  else {
235 
236  // there is a subfolder, get its name
237  subfolderStringEnd = path.find( '/', subsysStringEnd + 1 );
238  if( std::string::npos == subfolderStringEnd ) subfolderStringEnd = path.size();
239 
240  // new subfolder?
241  if( path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 ) != subfoldername ) {
242  subfoldername = path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 );
243  DQMStoreStatsSubfolder aSubfolder;
244  aSubfolder.subfolderName_ = subfoldername;
245  dqmStoreStatsTopLevel.back().push_back( aSubfolder );
246  }
247 
248  }
249 
250  // shortcut
251  DQMStoreStatsSubfolder& currentSubfolder = dqmStoreStatsTopLevel.back().back();
252 
253  switch( (*it)->kind() ) {
254 
255  // one-dim ME
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 ) );
259  break;
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 ) );
263  break;
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 ) );
267  break;
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 ) );
271  break;
272 
273  // two-dim ME
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) );
277  break;
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) );
281  break;
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) );
285  break;
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) );
289  break;
290 
291  // three-dim ME
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));
297  break;
298 
299  default: {}
300  // here we have a DQM_KIND_INVALID, DQM_KIND_INT, DQM_KIND_REAL or DQM_KIND_STRING
301  // which we don't care much about. Alternatively:
302 
303  // std::cerr << "[DQMStoreStats::calcstats] ** WARNING: monitor element of kind: "
304  // << (*it)->kind() << ", name: \"" << (*it)->getName() << "\"\n"
305  // << " in path: \"" << path << "\" not considered." << std::endl;
306  }
307  }
308 
310  calcIgProfDump(dbeFolder);
311 
312  // OUTPUT
313 
314  std::cout << endl;
315  std::cout << "===========================================================================================" << std::endl;
316  std::cout << "[DQMStoreStats::calcstats] -- Dumping stats results ";
317  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME" << std::endl;
318  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY" << std::endl;
319  std::cout << "===========================================================================================" << std::endl;
320  std::cout << endl;
321 
322  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
323  std::cout << "Configuration:" << std::endl;
324  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
325  std::cout << " > running ";
326  if (runonendrun_) std::cout << "on run end." << std::endl;
327  if (runonendlumi_) std::cout << "on lumi end." << std::endl;
328  if (runonendjob_) std::cout << "on job end." << std::endl;
329  if (runineventloop_) std::cout << "in event loop." << std::endl;
330  std::cout << " > pathNameMatch = \"" << pathnamematch_ << "\"" << std::endl;
331  std::cout << std::endl;
332 
333  // dump folder structure
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;
339 
340  for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
341  std::cout << " |--> " << it1->subfolderName_ << " (subfolder)" << std::endl;
342  }
343 
344  }
345 
346  // dump mem/bin table
347 
348  unsigned int overallNHistograms = 0, overallNBins = 0, overallNEmptyBins = 0, overallNBytes = 0;
349 
350  std::cout << std::endl;
351  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
352  std::cout << "Detailed ressource usage information ";
353  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME" << std::endl;
354  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY" << std::endl;
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;
361 
362  unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
363 
364  for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
365 
366  // fixed-size working copy
367  std::string thisSubfolderName( it1->subfolderName_ );
368  if( thisSubfolderName.size() > 30 ) {
369  thisSubfolderName.resize( 30 );
370  thisSubfolderName.replace( thisSubfolderName.size() - 3, 3, 3, '.' );
371  }
372 
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_;
378 
379  // bins/histogram, need to catch nan if histos=0
380  if( it1->totalHistos_ ) {
381  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalBins_ / float( it1->totalHistos_ );
382  }
383  else std::cout << std::setw( 14 ) << std::right << "-";
384 
385  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / 1024.;
386 
387  // mem/histogram, need to catch nan if histos=0
388  if( it1->totalHistos_ ) {
389  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / it1->totalHistos_;
390  }
391  else std::cout << std::setw( 14 ) << std::right << "-";
392 
393  std::cout << std::endl;
394 
395  // collect totals
396  nHistograms += it1->totalHistos_;
397  nBins += it1->totalBins_;
398  nEmptyBins += it1->totalEmptyBins_;
399  nBytes += it1->totalMemory_;
400 
401  }
402 
403 
404 
405 
406  overallNHistograms += nHistograms;
407  overallNBins += nBins;
408  overallNEmptyBins += nEmptyBins;
409  overallNBytes += nBytes;
410 
411  // display totals
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;
420  std::cout << std::endl;
421 
422  std::cout << ".........................................................................................." << std::endl;
423 
424  }
425 
426 
427  // dump total
428  std::cout << std::endl;
429  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
430  std::cout << "Grand total ";
431  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME:" << std::endl;
432  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY:" << 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;
437 
438 
439 
440  std::cout << endl;
441  std::cout << "===========================================================================================" << std::endl;
442  std::cout << "[DQMStoreStats::calcstats] -- End of output ";
443  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME." << std::endl;
444  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY." << std::endl;
445  std::cout << "===========================================================================================" << std::endl;
446  std::cout << endl;
447 
448  // Put together a simplified version of the complete dump that is
449  // sent to std::cout. Just dump the very basic information,
450  // i.e. summary for each folder, both for run and LS products.
451  if (dumpToFWJR_)
452  {
454  // Do not even try if the FWJR service is not available.
455  if (!jr.isAvailable())
456  return 0;
457  // Prepare appropriate map to store FWJR output.
458  std::map<std::string, std::string> jrInfo;
459  unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
460 
461  jrInfo["Source"] = "DQMServices/Components";
462  jrInfo["FileClass"] = "DQMStoreStats";
463  if (runonendrun_)
464  jrInfo["DumpType"] = "EndRun";
465  if (runonendlumi_)
466  jrInfo["DumpType"] = "EndLumi";
467  if (runonendjob_)
468  jrInfo["DumpType"] = "EndJob";
469  if (runineventloop_)
470  jrInfo["DumpType"] = "EventLoop";
472  jrInfo["Type"] = "RunProduct";
474  jrInfo["Type"] = "LumiProduct";
475 
476 
477  jrInfo["pathNameMatch"] = pathnamematch_;
478 
479  for (DQMStoreStatsTopLevel::const_iterator it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 )
480  {
481  unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
482  for( DQMStoreStatsSubsystem::const_iterator it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
483  // collect totals
484  nHistograms += it1->totalHistos_;
485  nBins += it1->totalBins_;
486  nEmptyBins += it1->totalEmptyBins_;
487  nBytes += it1->totalMemory_;
488  }
489  overallNHistograms += nHistograms;
490  overallNBins += nBins;
491  overallNBytes += nBytes;
492  std::stringstream iss("");
493  iss << nHistograms;
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();
507  }
508  jr->reportAnalysisFile("DQMStatsReport", jrInfo);
509  }
510 
511  return 0;
512 
513 }
514 
515 
516 
521 
522  std::cout << std::endl;
523  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
524  std::cout << "Memory profile:" << std::endl;
525  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
526 
527  // determine virtual memory maximum
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();
530  it < memoryHistoryVector_.end(); ++it ) {
531  if( it->second > maxItem.second ) {
532  maxItem = *it;
533  }
534  }
535 
536  std::stringstream rootOutputFileName;
537  rootOutputFileName << "dqmStoreStats_memProfile_" << getpid() << ".root";
538 
539  // dump memory history to root file
541 
542  TFile outputFile( rootOutputFileName.str().c_str(), "RECREATE" );
543 
544  int aTime;
545  float aMb;
546 
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();
551  it < memoryHistoryVector_.end(); ++it ) {
552  aTime = it->first - startingTime_;
553  aMb = it->second / 1000.;
554  memHistoryTree.Fill();
555  }
556 
557  outputFile.Write();
558  outputFile.Close();
559 
560  }
561 
562  std::cout << "Approx. maximum total virtual memory size of job: ";
564  std::cout << maxItem.second / 1000.
565  << " MB (reached " << maxItem.first - startingTime_ << " sec. after constructor called)," << std::endl;
566  std::cout << " memory history written to: " << rootOutputFileName.str() << " (" << memoryHistoryVector_.size() << " samples)" << std::endl;
567  } else {
568  std::cout << "(could not be determined)" << std::endl;
569  }
570 
571  std::cout << std::endl << std::endl;
572 
573 }
574 
575 
576 
581  // subsystem info printout
582  std::cout << " ---------- " << subsystem_ << " ---------- " << std::endl;
583  std::cout << " " << subfolder_ << ": " ;
584  std::cout << nmesubsys_ << " histograms with "
585  << nbinssubsys_ << " bins. " ;
586  if (nmesubsys_ > 0) std::cout << nbinssubsys_/nmesubsys_ << " bins/histogram " ;
587  std::cout << std::endl;
588  std::cout << " Largest histogram: " << maxbinsmesubsys_ << " with " <<
589  maxbinssubsys_ << " bins." << std::endl;
590 }
591 
592 
593 
594 
598 std::pair<unsigned int, unsigned int> DQMStoreStats::readMemoryEntry( void ) const {
599 
600  // see if initial test reading was successful
602 
603  std::ifstream procFile( procFileName_.str().c_str(), ios::in );
604 
605  std::string readBuffer( "" );
606  unsigned int memSize = 0;
607 
608  // scan procfile
609  while( !procFile.eof() ) {
610  procFile >> readBuffer;
611  if( std::string( "VmSize:" ) == readBuffer ) {
612  procFile >> memSize;
613  break;
614  }
615  }
616 
617  procFile.close();
618  return std::pair<time_t, unsigned int>( time( 0 ), memSize );
619  }
620 
621  return std::pair<time_t, unsigned int>( 0, 0 );
622 
623 }
624 
625 
626 
627 //==================================================================//
628 //========================= beginJob ===============================//
629 //==================================================================//
631 
634 
635  // access the proc/ folder for memory information
636  procFileName_ << "/proc/" << getpid() << "/status";
637 
638  // open for a test
639  std::ifstream procFile( procFileName_.str().c_str(), ios::in );
640 
641  if( procFile.good() ) {
643  }
644  else {
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;
648  }
649 
650  procFile.close();
651 
652 }
653 
654 //==================================================================//
655 //========================= beginRun ===============================//
656 //==================================================================//
657 void DQMStoreStats::beginRun(const edm::Run& r, const EventSetup& context) {
658 }
659 
660 
661 //==================================================================//
662 //==================== beginLuminosityBlock ========================//
663 //==================================================================//
665  const EventSetup& context) {
666 }
667 
668 
669 //==================================================================//
670 //==================== analyse (takes each event) ==================//
671 //==================================================================//
672 void DQMStoreStats::analyze(const Event& iEvent, const EventSetup& iSetup) {
673 
674  //now read virtual memory size from proc folder
675  memoryHistoryVector_.push_back( readMemoryEntry() );
676 
677  if (runineventloop_) {
681  }
682 
683 }
684 
685 
686 //==================================================================//
687 //========================= endLuminosityBlock =====================//
688 //==================================================================//
690  const EventSetup& context) {
691  if (runonendlumi_) {
695  }
696 
697 }
698 
699 //==================================================================//
700 //============================= endRun =============================//
701 //==================================================================//
702 void DQMStoreStats::endRun(const Run& r, const EventSetup& context) {
703 
704  if (runonendrun_) {
708  }
709 
710 }
711 
712 //==================================================================//
713 //============================= endJob =============================//
714 //==================================================================//
716 
717  if (runonendjob_) {
721  }
722 
723 }
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:685
std::vector< MonitorElement * > getMatchingContents(const std::string &pattern, lat::Regexp::Syntax syntaxType=lat::Regexp::Wildcard) const
Definition: DQMStore.cc:1696
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)
int ii
Definition: cuy.py:588
time_t startingTime_
void endRun(const edm::Run &r, const edm::EventSetup &c)
void summary(std::string &sql_statement)
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)
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:121
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:36
string root
initialization
Definition: dbtoconf.py:70