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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
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)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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

DQMStore * dbe_
 
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 299 of file DQMStoreStats.h.

Member Enumeration Documentation

Enumerator
considerAllME 
considerOnlyLumiProductME 

Definition at line 304 of file DQMStoreStats.h.

Constructor & Destructor Documentation

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

Definition at line 47 of file DQMStoreStats.cc.

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

48  : subsystem_(""),
49  subfolder_(""),
50  nbinsglobal_(0),
51  nbinssubsys_(0),
52  nmeglobal_(0),
53  nmesubsys_(0),
54  maxbinsglobal_(0),
55  maxbinssubsys_(0),
56  maxbinsmeglobal_(""),
57  maxbinsmesubsys_(""),
58  statsdepth_(1),
59  pathnamematch_("*"),
60  verbose_(0) {
61  parameters_ = ps;
63  statsdepth_ = ps.getUntrackedParameter<int>("statsDepth", statsdepth_);
64  verbose_ = ps.getUntrackedParameter<int>("verbose", verbose_);
65  dumpMemHistory_ = ps.getUntrackedParameter<bool>("dumpMemoryHistory", false);
66  runonendrun_ = ps.getUntrackedParameter<bool>("runOnEndRun", true);
67  runonendjob_ = ps.getUntrackedParameter<bool>("runOnEndJob", false);
68  runonendlumi_ = ps.getUntrackedParameter<bool>("runOnEndLumi", false);
69  runineventloop_ = ps.getUntrackedParameter<bool>("runInEventLoop", false);
70  dumpToFWJR_ = ps.getUntrackedParameter<bool>("dumpToFWJR", false);
71 
72  startingTime_ = time(nullptr);
73 }
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 683 of file DQMStoreStats.cc.

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

683  {
684  //now read virtual memory size from proc folder
685  memoryHistoryVector_.emplace_back(readMemoryEntry());
686 
687  if (runineventloop_) {
691  }
692 }
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 654 of file DQMStoreStats.cc.

References beam_dqm_sourceclient-live_cfg::cerr, dbe_, recoMuon::in, isOpenProcFileSuccessful_, Utilities::operator, and procFileName_.

654  {
657 
658  // access the proc/ folder for memory information
659  procFileName_ << "/proc/" << getpid() << "/status";
660 
661  // open for a test
662  std::ifstream procFile(procFileName_.str().c_str(), ios::in);
663 
664  if (procFile.good()) {
666  } else {
667  std::cerr << " [DQMStoreStats::beginJob] ** WARNING: could not open file: " << procFileName_.str() << std::endl;
668  std::cerr << " Total memory profile will not be available." << std::endl;
670  }
671 
672  procFile.close();
673 }
DQMStore * dbe_
bool isOpenProcFileSuccessful_
std::stringstream procFileName_
void DQMStoreStats::beginRun ( const edm::Run r,
const edm::EventSetup c 
)
overrideprotected

Definition at line 678 of file DQMStoreStats.cc.

678 {}
void DQMStoreStats::calcIgProfDump ( Folder root)
private

Definition at line 77 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().

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

References DQMStoreStatsSubfolder::AddBinsD(), DQMStoreStatsSubfolder::AddBinsF(), DQMStoreStatsSubfolder::AddBinsS(), calcIgProfDump(), Folder::cd(), considerAllME, considerOnlyLumiProductME, gather_cfg::cout, dbe_, dumpToFWJR_, dqmMemoryStats::float, getEmptyMetric(), edm::Service< T >::isAvailable(), maxbinsglobal_, maxbinssubsys_, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, seedmultiplicitymonitor_newtracking_cfi::nBins, nbinsglobal_, nbinssubsys_, castor_dqm_sourceclient_file_cfg::path, pathnamematch_, edm::JobReport::reportAnalysisFile(), runineventloop_, runonendjob_, runonendlumi_, runonendrun_, AlCaHLTBitMon_QueryRunRegistry::string, DQMStoreStatsSubfolder::subfolderName_, DQMStoreStatsSubsystem::subsystemName_, MonitorElementData::TH1D, MonitorElementData::TH1F, MonitorElementData::TH1S, MonitorElementData::TH2D, MonitorElementData::TH2F, MonitorElementData::TH2S, MonitorElementData::TH3F, MonitorElementData::TPROFILE, MonitorElementData::TPROFILE2D, and Folder::update().

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

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

Definition at line 558 of file DQMStoreStats.cc.

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

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

558  {
559  std::cout << std::endl;
560  std::cout << "------------------------------------------------------------------------------------------"
561  << std::endl;
562  std::cout << "Memory profile:" << std::endl;
563  std::cout << "------------------------------------------------------------------------------------------"
564  << std::endl;
565 
566  // determine virtual memory maximum
567  std::pair<time_t, unsigned int> maxItem(0, 0);
568  for (auto it = memoryHistoryVector_.begin(); it < memoryHistoryVector_.end(); ++it) {
569  if (it->second > maxItem.second) {
570  maxItem = *it;
571  }
572  }
573 
574  std::stringstream rootOutputFileName;
575  rootOutputFileName << "dqmStoreStats_memProfile_" << getpid() << ".root";
576 
577  // dump memory history to root file
579  TFile outputFile(rootOutputFileName.str().c_str(), "RECREATE");
580 
581  int aTime;
582  float aMb;
583 
584  TTree memHistoryTree("dqmstorestats_memhistory", "memory history");
585  memHistoryTree.Branch("seconds", &aTime, "seconds/I");
586  memHistoryTree.Branch("megabytes", &aMb, "megabytes/F");
587  for (auto it = memoryHistoryVector_.begin(); it < memoryHistoryVector_.end(); ++it) {
588  aTime = it->first - startingTime_;
589  aMb = it->second / 1000.;
590  memHistoryTree.Fill();
591  }
592 
593  outputFile.Write();
594  outputFile.Close();
595  }
596 
597  std::cout << "Approx. maximum total virtual memory size of job: ";
599  std::cout << maxItem.second / 1000. << " MB (reached " << maxItem.first - startingTime_
600  << " sec. after constructor called)," << std::endl;
601  std::cout << " memory history written to: " << rootOutputFileName.str() << " (" << memoryHistoryVector_.size()
602  << " samples)" << std::endl;
603  } else {
604  std::cout << "(could not be determined)" << std::endl;
605  }
606 
607  std::cout << std::endl << std::endl;
608 }
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 613 of file DQMStoreStats.cc.

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

613  {
614  // subsystem info printout
615  std::cout << " ---------- " << subsystem_ << " ---------- " << std::endl;
616  std::cout << " " << subfolder_ << ": ";
617  std::cout << nmesubsys_ << " histograms with " << nbinssubsys_ << " bins. ";
618  if (nmesubsys_ > 0)
619  std::cout << nbinssubsys_ / nmesubsys_ << " bins/histogram ";
620  std::cout << std::endl;
621  std::cout << " Largest histogram: " << maxbinsmesubsys_ << " with " << maxbinssubsys_ << " bins." << std::endl;
622 }
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 627 of file DQMStoreStats.cc.

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

Referenced by analyze().

627  {
628  // see if initial test reading was successful
630  std::ifstream procFile(procFileName_.str().c_str(), ios::in);
631 
632  std::string readBuffer("");
633  unsigned int memSize = 0;
634 
635  // scan procfile
636  while (!procFile.eof()) {
637  procFile >> readBuffer;
638  if (std::string("VmSize:") == readBuffer) {
639  procFile >> memSize;
640  break;
641  }
642  }
643 
644  procFile.close();
645  return std::pair<time_t, unsigned int>(time(nullptr), memSize);
646  }
647 
648  return std::pair<time_t, unsigned int>(0, 0);
649 }
bool isOpenProcFileSuccessful_
std::stringstream procFileName_

Member Data Documentation

DQMStore* DQMStoreStats::dbe_
private

Definition at line 332 of file DQMStoreStats.h.

Referenced by beginJob(), and calcstats().

bool DQMStoreStats::dumpMemHistory_
private

Definition at line 359 of file DQMStoreStats.h.

Referenced by DQMStoreStats(), and dumpMemoryProfile().

bool DQMStoreStats::dumpToFWJR_
private

Definition at line 360 of file DQMStoreStats.h.

Referenced by calcstats(), and DQMStoreStats().

bool DQMStoreStats::isOpenProcFileSuccessful_
private

Definition at line 352 of file DQMStoreStats.h.

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

int DQMStoreStats::maxbinsglobal_
private

Definition at line 341 of file DQMStoreStats.h.

Referenced by calcstats().

std::string DQMStoreStats::maxbinsmeglobal_
private

Definition at line 343 of file DQMStoreStats.h.

std::string DQMStoreStats::maxbinsmesubsys_
private

Definition at line 344 of file DQMStoreStats.h.

Referenced by print().

int DQMStoreStats::maxbinssubsys_
private

Definition at line 342 of file DQMStoreStats.h.

Referenced by calcstats(), and print().

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

Definition at line 350 of file DQMStoreStats.h.

Referenced by analyze(), and dumpMemoryProfile().

int DQMStoreStats::nbinsglobal_
private

Definition at line 337 of file DQMStoreStats.h.

Referenced by calcstats().

int DQMStoreStats::nbinssubsys_
private

Definition at line 338 of file DQMStoreStats.h.

Referenced by calcstats(), and print().

int DQMStoreStats::nmeglobal_
private

Definition at line 339 of file DQMStoreStats.h.

int DQMStoreStats::nmesubsys_
private

Definition at line 340 of file DQMStoreStats.h.

Referenced by print().

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

Definition at line 347 of file DQMStoreStats.h.

Referenced by calcstats(), and DQMStoreStats().

std::stringstream DQMStoreStats::procFileName_
private

Definition at line 353 of file DQMStoreStats.h.

Referenced by beginJob(), and readMemoryEntry().

bool DQMStoreStats::runineventloop_
private

Definition at line 358 of file DQMStoreStats.h.

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

bool DQMStoreStats::runonendjob_
private

Definition at line 356 of file DQMStoreStats.h.

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

bool DQMStoreStats::runonendlumi_
private

Definition at line 357 of file DQMStoreStats.h.

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

bool DQMStoreStats::runonendrun_
private

Definition at line 355 of file DQMStoreStats.h.

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

time_t DQMStoreStats::startingTime_
private

Definition at line 351 of file DQMStoreStats.h.

Referenced by DQMStoreStats(), and dumpMemoryProfile().

int DQMStoreStats::statsdepth_
private

Definition at line 346 of file DQMStoreStats.h.

Referenced by DQMStoreStats().

std::string DQMStoreStats::subfolder_
private

Definition at line 336 of file DQMStoreStats.h.

Referenced by print().

std::string DQMStoreStats::subsystem_
private

Definition at line 335 of file DQMStoreStats.h.

Referenced by print().

int DQMStoreStats::verbose_
private

Definition at line 348 of file DQMStoreStats.h.

Referenced by DQMStoreStats().