CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
DQMStoreStats Class Reference

#include <DQMStoreStats.h>

Inheritance diagram for DQMStoreStats:
edm::EDAnalyzer edm::EDConsumerBase

Public Types

enum  statsMode { considerAllME = 0, considerOnlyLumiProductME = 1 }
 
- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 

Public Member Functions

 DQMStoreStats (const edm::ParameterSet &)
 
 ~DQMStoreStats () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Protected Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c) override
 
void beginJob () override
 
void beginRun (const edm::Run &r, const edm::EventSetup &c) override
 
void endJob () override
 
void endLuminosityBlock (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
 
void endRun (const edm::Run &r, const edm::EventSetup &c) override
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Private Member Functions

void calcIgProfDump (Folder &)
 
int calcstats (int)
 
void dumpMemoryProfile ()
 
void print ()
 
std::pair< unsigned int, unsigned int > readMemoryEntry () const
 

Private Attributes

DQMStoredbe_
 
bool dumpMemHistory_
 
bool dumpToFWJR_
 
bool isOpenProcFileSuccessful_
 
int maxbinsglobal_
 
std::string maxbinsmeglobal_
 
std::string maxbinsmesubsys_
 
int maxbinssubsys_
 
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
 
int nbinsglobal_
 
int nbinssubsys_
 
int nmeglobal_
 
int nmesubsys_
 
edm::ParameterSet parameters_
 
std::string pathnamematch_
 
std::stringstream procFileName_
 
bool runineventloop_
 
bool runonendjob_
 
bool runonendlumi_
 
bool runonendrun_
 
time_t startingTime_
 
int statsdepth_
 
std::string subfolder_
 
std::string subsystem_
 
int verbose_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 

Detailed Description

DQMStoreStats itself

Definition at line 294 of file DQMStoreStats.h.

Member Enumeration Documentation

Enumerator
considerAllME 
considerOnlyLumiProductME 

Definition at line 299 of file DQMStoreStats.h.

Constructor & Destructor Documentation

DQMStoreStats::DQMStoreStats ( const edm::ParameterSet ps)

Definition at line 49 of file DQMStoreStats.cc.

References dumpMemHistory_, dumpToFWJR_, funct::false, edm::ParameterSet::getUntrackedParameter(), parameters_, pathnamematch_, runineventloop_, runonendjob_, runonendlumi_, runonendrun_, startingTime_, statsdepth_, AlCaHLTBitMon_QueryRunRegistry::string, ntuplemaker::time, funct::true, verbose_, and ~DQMStoreStats().

50  : subsystem_ (""),
51  subfolder_ (""),
52  nbinsglobal_ (0),
53  nbinssubsys_ (0),
54  nmeglobal_ (0),
55  nmesubsys_ (0),
56  maxbinsglobal_ (0),
57  maxbinssubsys_ (0),
58  maxbinsmeglobal_ (""),
59  maxbinsmesubsys_ (""),
60  statsdepth_ (1),
61  pathnamematch_ ("*"),
62  verbose_ (0)
63 {
64  parameters_ = ps;
66  statsdepth_ = ps.getUntrackedParameter<int>( "statsDepth", statsdepth_ );
67  verbose_ = ps.getUntrackedParameter<int>( "verbose", verbose_ );
68  dumpMemHistory_ = ps.getUntrackedParameter<bool>( "dumpMemoryHistory", false );
69  runonendrun_ = ps.getUntrackedParameter<bool>( "runOnEndRun", true );
70  runonendjob_ = ps.getUntrackedParameter<bool>( "runOnEndJob", false );
71  runonendlumi_ = ps.getUntrackedParameter<bool>( "runOnEndLumi", false );
72  runineventloop_ = ps.getUntrackedParameter<bool>( "runInEventLoop", false );
73  dumpToFWJR_ = ps.getUntrackedParameter<bool>( "dumpToFWJR", false );
74 
75  startingTime_ = time( nullptr );
76 }
T getUntrackedParameter(std::string const &, T const &) const
time_t startingTime_
std::string subsystem_
std::string maxbinsmeglobal_
std::string pathnamematch_
std::string maxbinsmesubsys_
std::string subfolder_
edm::ParameterSet parameters_
DQMStoreStats::~DQMStoreStats ( )
overridedefault

Referenced by DQMStoreStats().

Member Function Documentation

void DQMStoreStats::analyze ( const edm::Event e,
const edm::EventSetup c 
)
overrideprotected

Definition at line 658 of file DQMStoreStats.cc.

References calcstats(), considerAllME, considerOnlyLumiProductME, dumpMemoryProfile(), memoryHistoryVector_, readMemoryEntry(), and runineventloop_.

658  {
659 
660  //now read virtual memory size from proc folder
661  memoryHistoryVector_.emplace_back(readMemoryEntry() );
662 
663  if (runineventloop_) {
667  }
668 
669 }
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
int calcstats(int)
std::pair< unsigned int, unsigned int > readMemoryEntry() const
void dumpMemoryProfile()
void DQMStoreStats::beginJob ( void  )
overrideprotectedvirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 625 of file DQMStoreStats.cc.

References MessageLogger_cfi::cerr, dbe_, recoMuon::in, isOpenProcFileSuccessful_, Utilities::operator, and procFileName_.

625  {
626 
629 
630  // access the proc/ folder for memory information
631  procFileName_ << "/proc/" << getpid() << "/status";
632 
633  // open for a test
634  std::ifstream procFile( procFileName_.str().c_str(), ios::in );
635 
636  if( procFile.good() ) {
638  }
639  else {
640  std::cerr << " [DQMStoreStats::beginJob] ** WARNING: could not open file: " << procFileName_.str() << std::endl;
641  std::cerr << " Total memory profile will not be available." << std::endl;
643  }
644 
645  procFile.close();
646 
647 }
DQMStore * dbe_
bool isOpenProcFileSuccessful_
std::stringstream procFileName_
void DQMStoreStats::beginRun ( const edm::Run r,
const edm::EventSetup c 
)
overrideprotected

Definition at line 652 of file DQMStoreStats.cc.

652  {
653 }
void DQMStoreStats::calcIgProfDump ( Folder root)
private

Definition at line 80 of file DQMStoreStats.cc.

References Folder::children(), Folder::CreateIterator(), VIterator< Item >::CurrentItem(), Folder::files(), VIterator< Item >::First(), cuy::ii, VIterator< Item >::IsDone(), Folder::mainrows(), Folder::mainrows_cumulative(), VIterator< Item >::Next(), Folder::parents(), AlCaHLTBitMon_QueryRunRegistry::string, Folder::summary(), and Folder::symbols().

Referenced by calcstats().

81 {
82  std::ofstream stream("dqm-bin-stats.sql");
83  stream << ""
84 " PRAGMA journal_mode=OFF;"
85 " PRAGMA count_changes=OFF;"
86 " DROP TABLE IF EXISTS files;"
87 " DROP TABLE IF EXISTS symbols;"
88 " DROP TABLE IF EXISTS mainrows;"
89 " DROP TABLE IF EXISTS children;"
90 " DROP TABLE IF EXISTS parents;"
91 " DROP TABLE IF EXISTS summary;"
92 " CREATE TABLE children ("
93 " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id),"
94 " parent_id INTEGER CONSTRAINT parent_exists REFERENCES mainrows(id),"
95 " from_parent_count INTEGER,"
96 " from_parent_calls INTEGER,"
97 " from_parent_paths INTEGER,"
98 " pct REAL"
99 " );"
100 " CREATE TABLE files ("
101 " id,"
102 " name TEXT"
103 " );"
104 " CREATE TABLE mainrows ("
105 " id INTEGER PRIMARY KEY,"
106 " symbol_id INTEGER CONSTRAINT symbol_id_exists REFERENCES symbols(id),"
107 " self_count INTEGER,"
108 " cumulative_count INTEGER,"
109 " kids INTEGER,"
110 " self_calls INTEGER,"
111 " total_calls INTEGER,"
112 " self_paths INTEGER,"
113 " total_paths INTEGER,"
114 " pct REAL"
115 " );"
116 " CREATE TABLE parents ("
117 " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id),"
118 " child_id INTEGER CONSTRAINT child_exists REFERENCES mainrows(id),"
119 " to_child_count INTEGER,"
120 " to_child_calls INTEGER,"
121 " to_child_paths INTEGER,"
122 " pct REAL"
123 " );"
124 " CREATE TABLE summary ("
125 " counter TEXT,"
126 " total_count INTEGER,"
127 " total_freq INTEGER,"
128 " tick_period REAL"
129 " );"
130 " CREATE TABLE symbols ("
131 " id,"
132 " name TEXT,"
133 " filename_id INTEGER CONSTRAINT file_id_exists REFERENCES files(id)"
134 " );"
135 " CREATE UNIQUE INDEX fileIndex ON files (id);"
136 " CREATE INDEX selfCountIndex ON mainrows(self_count);"
137 " CREATE UNIQUE INDEX symbolsIndex ON symbols (id);"
138 " CREATE INDEX totalCountIndex ON mainrows(cumulative_count);" << std::endl;
139 
140  std::string sql_statement("");
141 
142  root.files(sql_statement);
143  root.symbols(sql_statement);
144  root.mainrows_cumulative(sql_statement);
145  root.summary(sql_statement);
146  VIterator<Folder *> subsystems = root.CreateIterator() ;
147  size_t ii=0;
148  for(subsystems.First() ; !subsystems.IsDone() ; subsystems.Next(), ++ii)
149  {
150  subsystems.CurrentItem()->mainrows(sql_statement);
151  subsystems.CurrentItem()->parents(sql_statement);
152  subsystems.CurrentItem()->children(sql_statement);
153  }
154  stream << sql_statement << std::endl;
155 }
void mainrows_cumulative(std::string &sql_statement)
VIterator< Folder * > CreateIterator()
Item CurrentItem() const override
void summary(std::string &sql_statement)
void mainrows(std::string &sql_statement)
void files(std::string &sql_statement)
void Next() override
Definition: DQMStoreStats.h:92
bool IsDone() const override
Definition: DQMStoreStats.h:96
ii
Definition: cuy.py:590
void parents(std::string &sql_statement)
void First() override
Definition: DQMStoreStats.h:91
void children(std::string &sql_statement)
void symbols(std::string &sql_statement)
int DQMStoreStats::calcstats ( int  mode = DQMStoreStats::considerAllME)
private

do the stats here and produce output;

mode is coded in DQMStoreStats::statMode enum (select subsets of ME, e.g. those with getLumiFlag() == true)

Definition at line 163 of file DQMStoreStats.cc.

References DQMStoreStatsSubfolder::AddBinsD(), DQMStoreStatsSubfolder::AddBinsF(), DQMStoreStatsSubfolder::AddBinsS(), calcIgProfDump(), Folder::cd(), considerAllME, considerOnlyLumiProductME, gather_cfg::cout, dbe_, MonitorElement::DQM_KIND_TH1D, MonitorElement::DQM_KIND_TH1F, MonitorElement::DQM_KIND_TH1S, MonitorElement::DQM_KIND_TH2D, MonitorElement::DQM_KIND_TH2F, MonitorElement::DQM_KIND_TH2S, MonitorElement::DQM_KIND_TH3F, MonitorElement::DQM_KIND_TPROFILE, MonitorElement::DQM_KIND_TPROFILE2D, dumpToFWJR_, objects.autophobj::float, getEmptyMetric(), edm::Service< T >::isAvailable(), maxbinsglobal_, maxbinssubsys_, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, nbinsglobal_, nbinssubsys_, callgraph::path, pathnamematch_, edm::JobReport::reportAnalysisFile(), runineventloop_, runonendjob_, runonendlumi_, runonendrun_, AlCaHLTBitMon_QueryRunRegistry::string, DQMStoreStatsSubfolder::subfolderName_, DQMStoreStatsSubsystem::subsystemName_, and Folder::update().

Referenced by analyze(), endJob(), endLuminosityBlock(), and endRun().

163  {
164 
166  nbinsglobal_ = 0;
167  nbinssubsys_ = 0;
168  maxbinsglobal_ = 0;
169  maxbinssubsys_ = 0;
170  std::string path = "";
171  std::string subsystemname = "";
172  std::string subfoldername = "";
173  size_t subsysStringEnd = 0, subfolderStringBegin = 0, subfolderStringEnd = 0;
174 
175 
176  std::vector<MonitorElement*> melist;
177  melist = dbe_->getMatchingContents( pathnamematch_ );
178 
179  Folder dbeFolder("root");
180  DQMStoreStatsTopLevel dqmStoreStatsTopLevel;
181 
182  // loop all ME
183  for(auto & it : melist) {
184 
185  // consider only ME with getLumiFlag() == true ?
187  !( it->getLumiFlag() ) ) continue;
188 
189  // figure out subsystem/subfolder names
190  const std::string& path = it->getPathname();
191 
192  subfolderStringBegin = 0;
193  Folder * curr = &dbeFolder;
194  while(true)
195  {
196  subfolderStringEnd = path.find( '/', subfolderStringBegin );
197  if( std::string::npos == subfolderStringEnd )
198  {
199  curr = curr->cd(path.substr( subfolderStringBegin, path.size()-subfolderStringBegin ));
200  break;
201  }
202  curr = curr->cd(path.substr( subfolderStringBegin, subfolderStringEnd-subfolderStringBegin ));
203  subfolderStringBegin = ++subfolderStringEnd < path.size() ? subfolderStringEnd : path.size();
204  }
205 
206  // protection against ghost ME with empty paths
207  if( path.empty() ) continue;
208 
209  subsysStringEnd = path.find( '/', 0 );
210  if( std::string::npos == subsysStringEnd ) subsysStringEnd = path.size(); // no subfolder
211 
212  // new subsystem?
213  if( path.substr( 0, subsysStringEnd ) != subsystemname ) {
214  DQMStoreStatsSubsystem aSubsystem;
215  subsystemname = path.substr( 0, subsysStringEnd );
216  aSubsystem.subsystemName_ = subsystemname;
217  dqmStoreStatsTopLevel.push_back( aSubsystem );
218  subfoldername = "";
219  }
220 
221  // get subfolder name (if there is one..)
222  if( path.size() == subsysStringEnd ) {
223  // no subfolders in subsystem, make dummy
224  DQMStoreStatsSubfolder aSubfolder;
225  aSubfolder.subfolderName_ = subsystemname; // <-- for tagging this case
226  dqmStoreStatsTopLevel.back().push_back( aSubfolder );
227  }
228 
229  else {
230 
231  // there is a subfolder, get its name
232  subfolderStringEnd = path.find( '/', subsysStringEnd + 1 );
233  if( std::string::npos == subfolderStringEnd ) subfolderStringEnd = path.size();
234 
235  // new subfolder?
236  if( path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 ) != subfoldername ) {
237  subfoldername = path.substr( subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1 );
238  DQMStoreStatsSubfolder aSubfolder;
239  aSubfolder.subfolderName_ = subfoldername;
240  dqmStoreStatsTopLevel.back().push_back( aSubfolder );
241  }
242 
243  }
244 
245  // shortcut
246  DQMStoreStatsSubfolder& currentSubfolder = dqmStoreStatsTopLevel.back().back();
247 
248  switch( it->kind() ) {
249 
250  // one-dim ME
252  currentSubfolder.AddBinsF( it->getNbinsX(), getEmptyMetric(it->getTH1F()->GetArray(), it->getTH1F()->fN, 0, 0) );
253  curr->update( it->getNbinsX(), getEmptyMetric(it->getTH1F()->GetArray(), it->getTH1F()->fN, 0, 0), it->getNbinsX()*sizeof( float ) );
254  break;
256  currentSubfolder.AddBinsS( it->getNbinsX(), getEmptyMetric(it->getTH1S()->GetArray(), it->getTH1S()->fN, 0, 0) );
257  curr->update( it->getNbinsX(), getEmptyMetric(it->getTH1S()->GetArray(), it->getTH1S()->fN, 0, 0), it->getNbinsX()*sizeof( short ) );
258  break;
260  currentSubfolder.AddBinsD( it->getNbinsX(), getEmptyMetric(it->getTH1D()->GetArray(), it->getTH1D()->fN, 0, 0) );
261  curr->update( it->getNbinsX(), getEmptyMetric(it->getTH1D()->GetArray(), it->getTH1D()->fN, 0, 0), it->getNbinsX()*sizeof( double ) );
262  break;
264  currentSubfolder.AddBinsD( it->getNbinsX(), getEmptyMetric(it->getTProfile()->GetArray(), it->getTProfile()->fN, 0, 0) );
265  curr->update( it->getNbinsX(), getEmptyMetric(it->getTProfile()->GetArray(), it->getTProfile()->fN, 0, 0), it->getNbinsX()*sizeof( double ) );
266  break;
267 
268  // two-dim ME
270  currentSubfolder.AddBinsF( it->getNbinsX() * it->getNbinsY(), getEmptyMetric(it->getTH2F()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0) );
271  curr->update( it->getNbinsX() * it->getNbinsY(), getEmptyMetric(it->getTH2F()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0), it->getNbinsX() * it->getNbinsY()*sizeof(float) );
272  break;
274  currentSubfolder.AddBinsS( it->getNbinsX() * it->getNbinsY(), getEmptyMetric(it->getTH2S()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0) );
275  curr->update( it->getNbinsX() * it->getNbinsY(), getEmptyMetric(it->getTH2S()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0), it->getNbinsX() * it->getNbinsY()*sizeof(short) );
276  break;
278  currentSubfolder.AddBinsD( it->getNbinsX() * it->getNbinsY(), getEmptyMetric(it->getTH2D()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0) );
279  curr->update( it->getNbinsX() * it->getNbinsY(), getEmptyMetric(it->getTH2D()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0), it->getNbinsX() * it->getNbinsY()*sizeof(double) );
280  break;
282  currentSubfolder.AddBinsD( it->getNbinsX() * it->getNbinsY(), getEmptyMetric(it->getTProfile2D()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0) );
283  curr->update( it->getNbinsX() * it->getNbinsY(), getEmptyMetric(it->getTProfile2D()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, 0), it->getNbinsX() * it->getNbinsY()*sizeof(double) );
284  break;
285 
286  // three-dim ME
288  currentSubfolder.AddBinsF( it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(), getEmptyMetric( it->getTH3F()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, it->getNbinsZ()+2 ) );
289  curr->update( it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(),
290  getEmptyMetric( it->getTH3F()->GetArray(), it->getNbinsX()+2, it->getNbinsY()+2, it->getNbinsZ()+2 ),
291  it->getNbinsX() * it->getNbinsY() * it->getNbinsZ()*sizeof(float));
292  break;
293 
294  default: {}
295  // here we have a DQM_KIND_INVALID, DQM_KIND_INT, DQM_KIND_REAL or DQM_KIND_STRING
296  // which we don't care much about. Alternatively:
297 
298  // std::cerr << "[DQMStoreStats::calcstats] ** WARNING: monitor element of kind: "
299  // << (*it)->kind() << ", name: \"" << (*it)->getName() << "\"\n"
300  // << " in path: \"" << path << "\" not considered." << std::endl;
301  }
302  }
303 
305  calcIgProfDump(dbeFolder);
306 
307  // OUTPUT
308 
309  std::cout << endl;
310  std::cout << "===========================================================================================" << std::endl;
311  std::cout << "[DQMStoreStats::calcstats] -- Dumping stats results ";
312  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME" << std::endl;
313  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY" << std::endl;
314  std::cout << "===========================================================================================" << std::endl;
315  std::cout << endl;
316 
317  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
318  std::cout << "Configuration:" << std::endl;
319  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
320  std::cout << " > running ";
321  if (runonendrun_) std::cout << "on run end." << std::endl;
322  if (runonendlumi_) std::cout << "on lumi end." << std::endl;
323  if (runonendjob_) std::cout << "on job end." << std::endl;
324  if (runineventloop_) std::cout << "in event loop." << std::endl;
325  std::cout << " > pathNameMatch = \"" << pathnamematch_ << "\"" << std::endl;
326  std::cout << std::endl;
327 
328  // dump folder structure
329  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
330  std::cout << "Top level folder tree:" << std::endl;
331  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
332  for( auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 ) {
333  std::cout << it0->subsystemName_ << " (subsystem)" << std::endl;
334 
335  for( auto it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
336  std::cout << " |--> " << it1->subfolderName_ << " (subfolder)" << std::endl;
337  }
338 
339  }
340 
341  // dump mem/bin table
342 
343  unsigned int overallNHistograms = 0, overallNBins = 0, overallNEmptyBins = 0, overallNBytes = 0;
344 
345  std::cout << std::endl;
346  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
347  std::cout << "Detailed ressource usage information ";
348  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME" << std::endl;
349  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY" << std::endl;
350  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
351  std::cout << "subsystem/folder histograms bins Empty bins Empty/Total bins per MB kB per" << std::endl;
352  std::cout << " (total) (total) (total) histogram (total) histogram " << std::endl;
353  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
354  for( auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 ) {
355  std::cout << it0->subsystemName_ << std::endl;
356 
357  unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
358 
359  for( auto it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
360 
361  // fixed-size working copy
362  std::string thisSubfolderName( it1->subfolderName_ );
363  if( thisSubfolderName.size() > 30 ) {
364  thisSubfolderName.resize( 30 );
365  thisSubfolderName.replace( thisSubfolderName.size() - 3, 3, 3, '.' );
366  }
367 
368  std::cout << " -> " << std::setw( 30 ) << std::left << thisSubfolderName;
369  std::cout << std::setw( 14 ) << std::right << it1->totalHistos_;
370  std::cout << std::setw( 14 ) << std::right << it1->totalBins_;
371  std::cout << std::setw( 14 ) << std::right << it1->totalEmptyBins_;
372  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << (float)it1->totalEmptyBins_/(float)it1->totalBins_;
373 
374  // bins/histogram, need to catch nan if histos=0
375  if( it1->totalHistos_ ) {
376  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalBins_ / float( it1->totalHistos_ );
377  }
378  else std::cout << std::setw( 14 ) << std::right << "-";
379 
380  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / 1024.;
381 
382  // mem/histogram, need to catch nan if histos=0
383  if( it1->totalHistos_ ) {
384  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << it1->totalMemory_ / 1024. / it1->totalHistos_;
385  }
386  else std::cout << std::setw( 14 ) << std::right << "-";
387 
388  std::cout << std::endl;
389 
390  // collect totals
391  nHistograms += it1->totalHistos_;
392  nBins += it1->totalBins_;
393  nEmptyBins += it1->totalEmptyBins_;
394  nBytes += it1->totalMemory_;
395 
396  }
397 
398 
399 
400 
401  overallNHistograms += nHistograms;
402  overallNBins += nBins;
403  overallNEmptyBins += nEmptyBins;
404  overallNBytes += nBytes;
405 
406  // display totals
407  std::cout << " " << std::setw( 30 ) << std::left << "SUBSYSTEM TOTAL";
408  std::cout << std::setw( 14 ) << std::right << nHistograms;
409  std::cout << std::setw( 14 ) << std::right << nBins;
410  std::cout << std::setw( 14 ) << std::right << nEmptyBins;
411  std::cout << std::setw( 14 ) << std::right << (float)nEmptyBins/(float)nBins;
412  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBins / float( nHistograms );
413  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBytes / 1024. / 1000.;
414  std::cout << std::setw( 14 ) << std::right << std::setprecision( 3 ) << nBytes / 1024. / nHistograms;
415  std::cout << std::endl;
416 
417  std::cout << ".........................................................................................." << std::endl;
418 
419  }
420 
421 
422  // dump total
423  std::cout << std::endl;
424  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
425  std::cout << "Grand total ";
426  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME:" << std::endl;
427  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY:" << std::endl;
428  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
429  std::cout << "Number of subsystems: " << dqmStoreStatsTopLevel.size() << std::endl;
430  std::cout << "Total number of histograms: " << overallNHistograms << " with: " << overallNBins << " bins alltogether" << std::endl;
431  std::cout << "Total memory occupied by histograms (excl. overhead): " << overallNBytes / 1024. / 1000. << " MB" << std::endl;
432 
433 
434 
435  std::cout << endl;
436  std::cout << "===========================================================================================" << std::endl;
437  std::cout << "[DQMStoreStats::calcstats] -- End of output ";
438  if( mode == DQMStoreStats::considerAllME ) std::cout << "FOR ALL ME." << std::endl;
439  else if( mode == DQMStoreStats::considerOnlyLumiProductME ) std::cout << "FOR LUMI PRODUCTS ONLY." << std::endl;
440  std::cout << "===========================================================================================" << std::endl;
441  std::cout << endl;
442 
443  // Put together a simplified version of the complete dump that is
444  // sent to std::cout. Just dump the very basic information,
445  // i.e. summary for each folder, both for run and LS products.
446  if (dumpToFWJR_)
447  {
449  // Do not even try if the FWJR service is not available.
450  if (!jr.isAvailable())
451  return 0;
452  // Prepare appropriate map to store FWJR output.
453  std::map<std::string, std::string> jrInfo;
454  unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
455 
456  jrInfo["Source"] = "DQMServices/Components";
457  jrInfo["FileClass"] = "DQMStoreStats";
458  if (runonendrun_)
459  jrInfo["DumpType"] = "EndRun";
460  if (runonendlumi_)
461  jrInfo["DumpType"] = "EndLumi";
462  if (runonendjob_)
463  jrInfo["DumpType"] = "EndJob";
464  if (runineventloop_)
465  jrInfo["DumpType"] = "EventLoop";
467  jrInfo["Type"] = "RunProduct";
469  jrInfo["Type"] = "LumiProduct";
470 
471 
472  jrInfo["pathNameMatch"] = pathnamematch_;
473 
474  for (auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0 )
475  {
476  unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
477  for( auto it1 = it0->begin(); it1 < it0->end(); ++it1 ) {
478  // collect totals
479  nHistograms += it1->totalHistos_;
480  nBins += it1->totalBins_;
481  nEmptyBins += it1->totalEmptyBins_;
482  nBytes += it1->totalMemory_;
483  }
484  overallNHistograms += nHistograms;
485  overallNBins += nBins;
486  overallNBytes += nBytes;
487  std::stringstream iss("");
488  iss << nHistograms;
489  jrInfo[it0->subsystemName_ + std::string("_h")] = iss.str();
490  iss.str("");iss<<nBins;
491  jrInfo[it0->subsystemName_ + std::string("_b")] = iss.str();
492  iss.str("");iss<<nEmptyBins;
493  jrInfo[it0->subsystemName_ + std::string("_be")] = iss.str();
494  iss.str("");iss<< ((float)nEmptyBins/(float)nBins);
495  jrInfo[it0->subsystemName_ + std::string("_fbe")] = iss.str();
496  iss.str("");iss<< ((float)nBins/(float)nHistograms);
497  jrInfo[it0->subsystemName_ + std::string("_b_h")] = iss.str();
498  iss.str("");iss<<nBytes / 1024. / 1024.;
499  jrInfo[it0->subsystemName_ + std::string("_MB")] = iss.str();
500  iss.str("");iss<<nBytes / 1024. / nHistograms;
501  jrInfo[it0->subsystemName_ + std::string("_Kb_h")] = iss.str();
502  }
503  jr->reportAnalysisFile("DQMStatsReport", jrInfo);
504  }
505 
506  return 0;
507 
508 }
std::string subfolderName_
Definition: DQMStoreStats.h:43
size
Write out results.
DQMStore * dbe_
void AddBinsS(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:49
void update(unsigned int bins, unsigned int empty, unsigned int memory)
Definition: vlib.h:186
void AddBinsD(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:50
std::string subsystemName_
Definition: DQMStoreStats.h:60
def ALL(dt, wheel, station, sector)
Definition: diffTwoXMLs.py:28
return((rh^lh)&mask)
Definition: ME.h:11
int calcstats(int)
std::string pathnamematch_
bool isAvailable() const
Definition: Service.h:46
static unsigned int getEmptyMetric(T *array, int lenx, int leny, int lenz)
Folder * cd(const std::string &name)
void AddBinsF(unsigned int nBins, unsigned int nEmptyBins)
Definition: DQMStoreStats.h:48
void calcIgProfDump(Folder &)
#define str(s)
void DQMStoreStats::dumpMemoryProfile ( )
private

Definition at line 515 of file DQMStoreStats.cc.

References gather_cfg::cout, dumpMemHistory_, isOpenProcFileSuccessful_, memoryHistoryVector_, download_sqlite_cfg::outputFile, and startingTime_.

Referenced by analyze(), endJob(), endLuminosityBlock(), and endRun().

515  {
516 
517  std::cout << std::endl;
518  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
519  std::cout << "Memory profile:" << std::endl;
520  std::cout << "------------------------------------------------------------------------------------------" << std::endl;
521 
522  // determine virtual memory maximum
523  std::pair<time_t, unsigned int> maxItem( 0, 0 );
524  for( auto it = memoryHistoryVector_.begin();
525  it < memoryHistoryVector_.end(); ++it ) {
526  if( it->second > maxItem.second ) {
527  maxItem = *it;
528  }
529  }
530 
531  std::stringstream rootOutputFileName;
532  rootOutputFileName << "dqmStoreStats_memProfile_" << getpid() << ".root";
533 
534  // dump memory history to root file
536 
537  TFile outputFile( rootOutputFileName.str().c_str(), "RECREATE" );
538 
539  int aTime;
540  float aMb;
541 
542  TTree memHistoryTree( "dqmstorestats_memhistory", "memory history" );
543  memHistoryTree.Branch( "seconds", &aTime, "seconds/I" );
544  memHistoryTree.Branch( "megabytes", &aMb, "megabytes/F" );
545  for( auto it = memoryHistoryVector_.begin();
546  it < memoryHistoryVector_.end(); ++it ) {
547  aTime = it->first - startingTime_;
548  aMb = it->second / 1000.;
549  memHistoryTree.Fill();
550  }
551 
552  outputFile.Write();
553  outputFile.Close();
554 
555  }
556 
557  std::cout << "Approx. maximum total virtual memory size of job: ";
559  std::cout << maxItem.second / 1000.
560  << " MB (reached " << maxItem.first - startingTime_ << " sec. after constructor called)," << std::endl;
561  std::cout << " memory history written to: " << rootOutputFileName.str() << " (" << memoryHistoryVector_.size() << " samples)" << std::endl;
562  } else {
563  std::cout << "(could not be determined)" << std::endl;
564  }
565 
566  std::cout << std::endl << std::endl;
567 
568 }
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
time_t startingTime_
bool isOpenProcFileSuccessful_
void DQMStoreStats::endJob ( void  )
overrideprotectedvirtual
void DQMStoreStats::endLuminosityBlock ( const edm::LuminosityBlock lumiSeg,
const edm::EventSetup c 
)
overrideprotected
void DQMStoreStats::endRun ( const edm::Run r,
const edm::EventSetup c 
)
overrideprotected
void DQMStoreStats::print ( void  )
private

Definition at line 575 of file DQMStoreStats.cc.

References gather_cfg::cout, maxbinsmesubsys_, maxbinssubsys_, nbinssubsys_, nmesubsys_, subfolder_, and subsystem_.

575  {
576  // subsystem info printout
577  std::cout << " ---------- " << subsystem_ << " ---------- " << std::endl;
578  std::cout << " " << subfolder_ << ": " ;
579  std::cout << nmesubsys_ << " histograms with "
580  << nbinssubsys_ << " bins. " ;
581  if (nmesubsys_ > 0) std::cout << nbinssubsys_/nmesubsys_ << " bins/histogram " ;
582  std::cout << std::endl;
583  std::cout << " Largest histogram: " << maxbinsmesubsys_ << " with " <<
584  maxbinssubsys_ << " bins." << std::endl;
585 }
std::string subsystem_
std::string maxbinsmesubsys_
std::string subfolder_
std::pair< unsigned int, unsigned int > DQMStoreStats::readMemoryEntry ( ) const
private

read virtual memory size from /proc/<pid>/status file

Definition at line 593 of file DQMStoreStats.cc.

References recoMuon::in, isOpenProcFileSuccessful_, procFileName_, AlCaHLTBitMon_QueryRunRegistry::string, and ntuplemaker::time.

Referenced by analyze().

593  {
594 
595  // see if initial test reading was successful
597 
598  std::ifstream procFile( procFileName_.str().c_str(), ios::in );
599 
600  std::string readBuffer( "" );
601  unsigned int memSize = 0;
602 
603  // scan procfile
604  while( !procFile.eof() ) {
605  procFile >> readBuffer;
606  if( std::string( "VmSize:" ) == readBuffer ) {
607  procFile >> memSize;
608  break;
609  }
610  }
611 
612  procFile.close();
613  return std::pair<time_t, unsigned int>( time( nullptr ), memSize );
614  }
615 
616  return std::pair<time_t, unsigned int>( 0, 0 );
617 
618 }
bool isOpenProcFileSuccessful_
std::stringstream procFileName_

Member Data Documentation

DQMStore* DQMStoreStats::dbe_
private

Definition at line 331 of file DQMStoreStats.h.

Referenced by beginJob(), and calcstats().

bool DQMStoreStats::dumpMemHistory_
private

Definition at line 358 of file DQMStoreStats.h.

Referenced by DQMStoreStats(), and dumpMemoryProfile().

bool DQMStoreStats::dumpToFWJR_
private

Definition at line 359 of file DQMStoreStats.h.

Referenced by calcstats(), and DQMStoreStats().

bool DQMStoreStats::isOpenProcFileSuccessful_
private

Definition at line 351 of file DQMStoreStats.h.

Referenced by beginJob(), dumpMemoryProfile(), and readMemoryEntry().

int DQMStoreStats::maxbinsglobal_
private

Definition at line 340 of file DQMStoreStats.h.

Referenced by calcstats().

std::string DQMStoreStats::maxbinsmeglobal_
private

Definition at line 342 of file DQMStoreStats.h.

std::string DQMStoreStats::maxbinsmesubsys_
private

Definition at line 343 of file DQMStoreStats.h.

Referenced by print().

int DQMStoreStats::maxbinssubsys_
private

Definition at line 341 of file DQMStoreStats.h.

Referenced by calcstats(), and print().

std::vector<std::pair<time_t, unsigned int> > DQMStoreStats::memoryHistoryVector_
private

Definition at line 349 of file DQMStoreStats.h.

Referenced by analyze(), and dumpMemoryProfile().

int DQMStoreStats::nbinsglobal_
private

Definition at line 336 of file DQMStoreStats.h.

Referenced by calcstats().

int DQMStoreStats::nbinssubsys_
private

Definition at line 337 of file DQMStoreStats.h.

Referenced by calcstats(), and print().

int DQMStoreStats::nmeglobal_
private

Definition at line 338 of file DQMStoreStats.h.

int DQMStoreStats::nmesubsys_
private

Definition at line 339 of file DQMStoreStats.h.

Referenced by print().

edm::ParameterSet DQMStoreStats::parameters_
private
std::string DQMStoreStats::pathnamematch_
private

Definition at line 346 of file DQMStoreStats.h.

Referenced by calcstats(), and DQMStoreStats().

std::stringstream DQMStoreStats::procFileName_
private

Definition at line 352 of file DQMStoreStats.h.

Referenced by beginJob(), and readMemoryEntry().

bool DQMStoreStats::runineventloop_
private

Definition at line 357 of file DQMStoreStats.h.

Referenced by analyze(), calcstats(), and DQMStoreStats().

bool DQMStoreStats::runonendjob_
private

Definition at line 355 of file DQMStoreStats.h.

Referenced by calcstats(), DQMStoreStats(), and endJob().

bool DQMStoreStats::runonendlumi_
private

Definition at line 356 of file DQMStoreStats.h.

Referenced by calcstats(), DQMStoreStats(), and endLuminosityBlock().

bool DQMStoreStats::runonendrun_
private

Definition at line 354 of file DQMStoreStats.h.

Referenced by calcstats(), DQMStoreStats(), and endRun().

time_t DQMStoreStats::startingTime_
private

Definition at line 350 of file DQMStoreStats.h.

Referenced by DQMStoreStats(), and dumpMemoryProfile().

int DQMStoreStats::statsdepth_
private

Definition at line 345 of file DQMStoreStats.h.

Referenced by DQMStoreStats().

std::string DQMStoreStats::subfolder_
private

Definition at line 335 of file DQMStoreStats.h.

Referenced by print().

std::string DQMStoreStats::subsystem_
private

Definition at line 334 of file DQMStoreStats.h.

Referenced by print().

int DQMStoreStats::verbose_
private

Definition at line 347 of file DQMStoreStats.h.

Referenced by DQMStoreStats().