CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
DQMStoreStats Class Reference
Inheritance diagram for DQMStoreStats:
edm::one::EDAnalyzer< edm::one::WatchRuns, edm::one::WatchLuminosityBlocks > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Types

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

Public Member Functions

 DQMStoreStats (const edm::ParameterSet &)
 
 ~DQMStoreStats () override=default
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::WatchRuns, edm::one::WatchLuminosityBlocks >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () 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
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
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 beginLuminosityBlock (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) 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)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

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::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Detailed Description

DQMStoreStats itself

Definition at line 312 of file DQMStoreStats.cc.

Member Enumeration Documentation

◆ statsMode

Enumerator
considerAllME 
considerOnlyLumiProductME 

Definition at line 317 of file DQMStoreStats.cc.

Constructor & Destructor Documentation

◆ DQMStoreStats()

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

Definition at line 413 of file DQMStoreStats.cc.

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

414  : subsystem_(""),
415  subfolder_(""),
416  nbinsglobal_(0),
417  nbinssubsys_(0),
418  nmeglobal_(0),
419  nmesubsys_(0),
420  maxbinsglobal_(0),
421  maxbinssubsys_(0),
422  maxbinsmeglobal_(""),
423  maxbinsmesubsys_(""),
424  statsdepth_(1),
425  pathnamematch_(""),
426  verbose_(0) {
427  parameters_ = ps;
429  statsdepth_ = ps.getUntrackedParameter<int>("statsDepth", statsdepth_);
430  verbose_ = ps.getUntrackedParameter<int>("verbose", verbose_);
431  dumpMemHistory_ = ps.getUntrackedParameter<bool>("dumpMemoryHistory", false);
432  runonendrun_ = ps.getUntrackedParameter<bool>("runOnEndRun", true);
433  runonendjob_ = ps.getUntrackedParameter<bool>("runOnEndJob", false);
434  runonendlumi_ = ps.getUntrackedParameter<bool>("runOnEndLumi", false);
435  runineventloop_ = ps.getUntrackedParameter<bool>("runInEventLoop", false);
436  dumpToFWJR_ = ps.getUntrackedParameter<bool>("dumpToFWJR", false);
437 
438  startingTime_ = time(nullptr);
439 }
time_t startingTime_
T getUntrackedParameter(std::string const &, T const &) const
std::string subsystem_
std::string maxbinsmeglobal_
std::string pathnamematch_
std::string maxbinsmesubsys_
std::string subfolder_
edm::ParameterSet parameters_

◆ ~DQMStoreStats()

DQMStoreStats::~DQMStoreStats ( )
overridedefault

Member Function Documentation

◆ analyze()

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

Implements edm::one::EDAnalyzerBase.

Definition at line 1062 of file DQMStoreStats.cc.

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

1062  {
1063  //now read virtual memory size from proc folder
1064  memoryHistoryVector_.emplace_back(readMemoryEntry());
1065 
1066  if (runineventloop_) {
1070  }
1071 }
std::pair< unsigned int, unsigned int > readMemoryEntry() const
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
int calcstats(int)
void dumpMemoryProfile()

◆ beginJob()

void DQMStoreStats::beginJob ( void  )
overrideprotectedvirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 1033 of file DQMStoreStats.cc.

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

1033  {
1036 
1037  // access the proc/ folder for memory information
1038  procFileName_ << "/proc/" << getpid() << "/status";
1039 
1040  // open for a test
1041  std::ifstream procFile(procFileName_.str().c_str(), ios::in);
1042 
1043  if (procFile.good()) {
1045  } else {
1046  std::cerr << " [DQMStoreStats::beginJob] ** WARNING: could not open file: " << procFileName_.str() << std::endl;
1047  std::cerr << " Total memory profile will not be available." << std::endl;
1048  isOpenProcFileSuccessful_ = false;
1049  }
1050 
1051  procFile.close();
1052 }
DQMStore * dbe_
bool isOpenProcFileSuccessful_
std::stringstream procFileName_

◆ beginLuminosityBlock()

void DQMStoreStats::beginLuminosityBlock ( const edm::LuminosityBlock lumiSeg,
const edm::EventSetup c 
)
overrideprotected

Definition at line 1087 of file DQMStoreStats.cc.

1087 {}

◆ beginRun()

void DQMStoreStats::beginRun ( const edm::Run r,
const edm::EventSetup c 
)
overrideprotected

Definition at line 1057 of file DQMStoreStats.cc.

1057 {}

◆ calcIgProfDump()

void DQMStoreStats::calcIgProfDump ( Folder root)
private

Definition at line 441 of file DQMStoreStats.cc.

References Folder::children(), VIterator< Item >::CurrentItem(), VIterator< Item >::First(), cuy::ii, VIterator< Item >::IsDone(), Folder::mainrows(), VIterator< Item >::Next(), Folder::parents(), cms::cuda::stream, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by calcstats().

441  {
442  std::ofstream stream("dqm-bin-stats.sql");
443  stream << ""
444  " PRAGMA journal_mode=OFF;"
445  " PRAGMA count_changes=OFF;"
446  " DROP TABLE IF EXISTS files;"
447  " DROP TABLE IF EXISTS symbols;"
448  " DROP TABLE IF EXISTS mainrows;"
449  " DROP TABLE IF EXISTS children;"
450  " DROP TABLE IF EXISTS parents;"
451  " DROP TABLE IF EXISTS summary;"
452  " CREATE TABLE children ("
453  " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id),"
454  " parent_id INTEGER CONSTRAINT parent_exists REFERENCES mainrows(id),"
455  " from_parent_count INTEGER,"
456  " from_parent_calls INTEGER,"
457  " from_parent_paths INTEGER,"
458  " pct REAL"
459  " );"
460  " CREATE TABLE files ("
461  " id,"
462  " name TEXT"
463  " );"
464  " CREATE TABLE mainrows ("
465  " id INTEGER PRIMARY KEY,"
466  " symbol_id INTEGER CONSTRAINT symbol_id_exists REFERENCES symbols(id),"
467  " self_count INTEGER,"
468  " cumulative_count INTEGER,"
469  " kids INTEGER,"
470  " self_calls INTEGER,"
471  " total_calls INTEGER,"
472  " self_paths INTEGER,"
473  " total_paths INTEGER,"
474  " pct REAL"
475  " );"
476  " CREATE TABLE parents ("
477  " self_id INTEGER CONSTRAINT self_exists REFERENCES mainrows(id),"
478  " child_id INTEGER CONSTRAINT child_exists REFERENCES mainrows(id),"
479  " to_child_count INTEGER,"
480  " to_child_calls INTEGER,"
481  " to_child_paths INTEGER,"
482  " pct REAL"
483  " );"
484  " CREATE TABLE summary ("
485  " counter TEXT,"
486  " total_count INTEGER,"
487  " total_freq INTEGER,"
488  " tick_period REAL"
489  " );"
490  " CREATE TABLE symbols ("
491  " id,"
492  " name TEXT,"
493  " filename_id INTEGER CONSTRAINT file_id_exists REFERENCES files(id)"
494  " );"
495  " CREATE UNIQUE INDEX fileIndex ON files (id);"
496  " CREATE INDEX selfCountIndex ON mainrows(self_count);"
497  " CREATE UNIQUE INDEX symbolsIndex ON symbols (id);"
498  " CREATE INDEX totalCountIndex ON mainrows(cumulative_count);"
499  << std::endl;
500 
501  std::string sql_statement("");
502 
503  root.files(sql_statement);
504  root.symbols(sql_statement);
505  root.mainrows_cumulative(sql_statement);
506  root.summary(sql_statement);
507  VIterator<Folder*> subsystems = root.CreateIterator();
508  size_t ii = 0;
509  for (subsystems.First(); !subsystems.IsDone(); subsystems.Next(), ++ii) {
510  subsystems.CurrentItem()->mainrows(sql_statement);
511  subsystems.CurrentItem()->parents(sql_statement);
512  subsystems.CurrentItem()->children(sql_statement);
513  }
514  stream << sql_statement << std::endl;
515 }
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
void mainrows(std::string &sql_statement)
Item CurrentItem() const override
void Next() override
ii
Definition: cuy.py:589
void parents(std::string &sql_statement)
bool IsDone() const override
void First() override
void children(std::string &sql_statement)

◆ calcstats()

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 523 of file DQMStoreStats.cc.

References DQMStoreStatsSubfolder::AddBinsD(), DQMStoreStatsSubfolder::AddBinsF(), DQMStoreStatsSubfolder::AddBinsI(), DQMStoreStatsSubfolder::AddBinsS(), calcIgProfDump(), Folder::cd(), considerAllME, considerOnlyLumiProductME, gather_cfg::cout, dbe_, dumpToFWJR_, dqmMemoryStats::float, dqm::implementation::IGetter::getAllContents(), getEmptyMetric(), createfilelist::int, 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::TH1I, MonitorElementData::TH1S, MonitorElementData::TH2D, MonitorElementData::TH2F, MonitorElementData::TH2I, MonitorElementData::TH2S, MonitorElementData::TH3F, MonitorElementData::TPROFILE, MonitorElementData::TPROFILE2D, and Folder::update().

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

523  {
525  nbinsglobal_ = 0;
526  nbinssubsys_ = 0;
527  maxbinsglobal_ = 0;
528  maxbinssubsys_ = 0;
529  std::string path = "";
530  std::string subsystemname = "";
531  std::string subfoldername = "";
532  size_t subsysStringEnd = 0, subfolderStringBegin = 0, subfolderStringEnd = 0;
533 
534  std::vector<MonitorElement*> melist;
536 
537  Folder dbeFolder("root");
538  DQMStoreStatsTopLevel dqmStoreStatsTopLevel;
539 
540  // loop all ME
541  for (auto& it : melist) {
542  // consider only ME with getLumiFlag() == true ?
543  if (mode == DQMStoreStats::considerOnlyLumiProductME && !(it->getLumiFlag()))
544  continue;
545 
546  // figure out subsystem/subfolder names
547  const std::string& path = it->getPathname();
548 
549  subfolderStringBegin = 0;
550  Folder* curr = &dbeFolder;
551  while (true) {
552  subfolderStringEnd = path.find('/', subfolderStringBegin);
553  if (std::string::npos == subfolderStringEnd) {
554  curr = curr->cd(path.substr(subfolderStringBegin, path.size() - subfolderStringBegin));
555  break;
556  }
557  curr = curr->cd(path.substr(subfolderStringBegin, subfolderStringEnd - subfolderStringBegin));
558  subfolderStringBegin = ++subfolderStringEnd < path.size() ? subfolderStringEnd : path.size();
559  }
560 
561  // protection against ghost ME with empty paths
562  if (path.empty())
563  continue;
564 
565  subsysStringEnd = path.find('/', 0);
566  if (std::string::npos == subsysStringEnd)
567  subsysStringEnd = path.size(); // no subfolder
568 
569  // new subsystem?
570  if (path.substr(0, subsysStringEnd) != subsystemname) {
571  DQMStoreStatsSubsystem aSubsystem;
572  subsystemname = path.substr(0, subsysStringEnd);
573  aSubsystem.subsystemName_ = subsystemname;
574  dqmStoreStatsTopLevel.push_back(aSubsystem);
575  subfoldername = "";
576  }
577 
578  // get subfolder name (if there is one..)
579  if (path.size() == subsysStringEnd) {
580  // no subfolders in subsystem, make dummy
581  DQMStoreStatsSubfolder aSubfolder;
582  aSubfolder.subfolderName_ = subsystemname; // <-- for tagging this case
583  dqmStoreStatsTopLevel.back().push_back(aSubfolder);
584  }
585 
586  else {
587  // there is a subfolder, get its name
588  subfolderStringEnd = path.find('/', subsysStringEnd + 1);
589  if (std::string::npos == subfolderStringEnd)
590  subfolderStringEnd = path.size();
591 
592  // new subfolder?
593  if (path.substr(subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1) != subfoldername) {
594  subfoldername = path.substr(subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1);
595  DQMStoreStatsSubfolder aSubfolder;
596  aSubfolder.subfolderName_ = subfoldername;
597  dqmStoreStatsTopLevel.back().push_back(aSubfolder);
598  }
599  }
600 
601  // shortcut
602  DQMStoreStatsSubfolder& currentSubfolder = dqmStoreStatsTopLevel.back().back();
603 
604  switch (it->kind()) {
605  // one-dim ME
607  currentSubfolder.AddBinsF(it->getNbinsX(), getEmptyMetric(it->getTH1F()->GetArray(), it->getTH1F()->fN, 0, 0));
608  curr->update(it->getNbinsX(),
609  getEmptyMetric(it->getTH1F()->GetArray(), it->getTH1F()->fN, 0, 0),
610  it->getNbinsX() * sizeof(float));
611  break;
613  currentSubfolder.AddBinsS(it->getNbinsX(), getEmptyMetric(it->getTH1S()->GetArray(), it->getTH1S()->fN, 0, 0));
614  curr->update(it->getNbinsX(),
615  getEmptyMetric(it->getTH1S()->GetArray(), it->getTH1S()->fN, 0, 0),
616  it->getNbinsX() * sizeof(short));
617  break;
619  currentSubfolder.AddBinsD(it->getNbinsX(), getEmptyMetric(it->getTH1D()->GetArray(), it->getTH1D()->fN, 0, 0));
620  curr->update(it->getNbinsX(),
621  getEmptyMetric(it->getTH1D()->GetArray(), it->getTH1D()->fN, 0, 0),
622  it->getNbinsX() * sizeof(double));
623  break;
625  currentSubfolder.AddBinsI(it->getNbinsX(), getEmptyMetric(it->getTH1I()->GetArray(), it->getTH1I()->fN, 0, 0));
626  curr->update(it->getNbinsX(),
627  getEmptyMetric(it->getTH1I()->GetArray(), it->getTH1I()->fN, 0, 0),
628  it->getNbinsX() * sizeof(int));
629  break;
631  currentSubfolder.AddBinsD(it->getNbinsX(),
632  getEmptyMetric(it->getTProfile()->GetArray(), it->getTProfile()->fN, 0, 0));
633  curr->update(it->getNbinsX(),
634  getEmptyMetric(it->getTProfile()->GetArray(), it->getTProfile()->fN, 0, 0),
635  it->getNbinsX() * sizeof(double));
636  break;
637 
638  // two-dim ME
640  currentSubfolder.AddBinsF(
641  it->getNbinsX() * it->getNbinsY(),
642  getEmptyMetric(it->getTH2F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
643  curr->update(it->getNbinsX() * it->getNbinsY(),
644  getEmptyMetric(it->getTH2F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
645  it->getNbinsX() * it->getNbinsY() * sizeof(float));
646  break;
648  currentSubfolder.AddBinsS(
649  it->getNbinsX() * it->getNbinsY(),
650  getEmptyMetric(it->getTH2S()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
651  curr->update(it->getNbinsX() * it->getNbinsY(),
652  getEmptyMetric(it->getTH2S()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
653  it->getNbinsX() * it->getNbinsY() * sizeof(short));
654  break;
656  currentSubfolder.AddBinsD(
657  it->getNbinsX() * it->getNbinsY(),
658  getEmptyMetric(it->getTH2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
659  curr->update(it->getNbinsX() * it->getNbinsY(),
660  getEmptyMetric(it->getTH2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
661  it->getNbinsX() * it->getNbinsY() * sizeof(double));
662  break;
664  currentSubfolder.AddBinsI(
665  it->getNbinsX() * it->getNbinsY(),
666  getEmptyMetric(it->getTH2I()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
667  curr->update(it->getNbinsX() * it->getNbinsY(),
668  getEmptyMetric(it->getTH2I()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
669  it->getNbinsX() * it->getNbinsY() * sizeof(int));
670  break;
672  currentSubfolder.AddBinsD(
673  it->getNbinsX() * it->getNbinsY(),
674  getEmptyMetric(it->getTProfile2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
675  curr->update(it->getNbinsX() * it->getNbinsY(),
676  getEmptyMetric(it->getTProfile2D()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
677  it->getNbinsX() * it->getNbinsY() * sizeof(double));
678  break;
679 
680  // three-dim ME
682  currentSubfolder.AddBinsF(
683  it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(),
684  getEmptyMetric(it->getTH3F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, it->getNbinsZ() + 2));
685  curr->update(
686  it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(),
687  getEmptyMetric(it->getTH3F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, it->getNbinsZ() + 2),
688  it->getNbinsX() * it->getNbinsY() * it->getNbinsZ() * sizeof(float));
689  break;
690 
691  default: {
692  }
693  // here we have a DQM_KIND_INVALID, DQM_KIND_INT, DQM_KIND_REAL or DQM_KIND_STRING
694  // which we don't care much about. Alternatively:
695 
696  // std::cerr << "[DQMStoreStats::calcstats] ** WARNING: monitor element of kind: "
697  // << (*it)->kind() << ", name: \"" << (*it)->getName() << "\"\n"
698  // << " in path: \"" << path << "\" not considered." << std::endl;
699  }
700  }
701 
703  calcIgProfDump(dbeFolder);
704 
705  // OUTPUT
706 
707  std::cout << endl;
708  std::cout << "==========================================================================================="
709  << std::endl;
710  std::cout << "[DQMStoreStats::calcstats] -- Dumping stats results ";
712  std::cout << "FOR ALL ME" << std::endl;
714  std::cout << "FOR LUMI PRODUCTS ONLY" << std::endl;
715  std::cout << "==========================================================================================="
716  << std::endl;
717  std::cout << endl;
718 
719  std::cout << "------------------------------------------------------------------------------------------"
720  << std::endl;
721  std::cout << "Configuration:" << std::endl;
722  std::cout << "------------------------------------------------------------------------------------------"
723  << std::endl;
724  std::cout << " > running ";
725  if (runonendrun_)
726  std::cout << "on run end." << std::endl;
727  if (runonendlumi_)
728  std::cout << "on lumi end." << std::endl;
729  if (runonendjob_)
730  std::cout << "on job end." << std::endl;
731  if (runineventloop_)
732  std::cout << "in event loop." << std::endl;
733  std::cout << " > pathNameMatch = \"" << pathnamematch_ << "\"" << std::endl;
734  std::cout << std::endl;
735 
736  // dump folder structure
737  std::cout << "------------------------------------------------------------------------------------------"
738  << std::endl;
739  std::cout << "Top level folder tree:" << std::endl;
740  std::cout << "------------------------------------------------------------------------------------------"
741  << std::endl;
742  for (auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
743  std::cout << it0->subsystemName_ << " (subsystem)" << std::endl;
744 
745  for (auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
746  std::cout << " |--> " << it1->subfolderName_ << " (subfolder)" << std::endl;
747  }
748  }
749 
750  // dump mem/bin table
751 
752  unsigned int overallNHistograms = 0, overallNBins = 0, overallNEmptyBins = 0, overallNBytes = 0;
753 
754  std::cout << std::endl;
755  std::cout << "------------------------------------------------------------------------------------------"
756  << std::endl;
757  std::cout << "Detailed ressource usage information ";
759  std::cout << "FOR ALL ME" << std::endl;
761  std::cout << "FOR LUMI PRODUCTS ONLY" << std::endl;
762  std::cout << "------------------------------------------------------------------------------------------"
763  << std::endl;
764  std::cout << "subsystem/folder histograms bins Empty bins Empty/Total "
765  "bins per MB kB per"
766  << std::endl;
767  std::cout << " (total) (total) (total) "
768  "histogram (total) histogram "
769  << std::endl;
770  std::cout << "------------------------------------------------------------------------------------------"
771  << std::endl;
772  for (auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
773  std::cout << it0->subsystemName_ << std::endl;
774 
775  unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
776 
777  for (auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
778  // fixed-size working copy
779  std::string thisSubfolderName(it1->subfolderName_);
780  if (thisSubfolderName.size() > 30) {
781  thisSubfolderName.resize(30);
782  thisSubfolderName.replace(thisSubfolderName.size() - 3, 3, 3, '.');
783  }
784 
785  std::cout << " -> " << std::setw(30) << std::left << thisSubfolderName;
786  std::cout << std::setw(14) << std::right << it1->totalHistos_;
787  std::cout << std::setw(14) << std::right << it1->totalBins_;
788  std::cout << std::setw(14) << std::right << it1->totalEmptyBins_;
789  std::cout << std::setw(14) << std::right << std::setprecision(3)
790  << (float)it1->totalEmptyBins_ / (float)it1->totalBins_;
791 
792  // bins/histogram, need to catch nan if histos=0
793  if (it1->totalHistos_) {
794  std::cout << std::setw(14) << std::right << std::setprecision(3) << it1->totalBins_ / float(it1->totalHistos_);
795  } else
796  std::cout << std::setw(14) << std::right << "-";
797 
798  std::cout << std::setw(14) << std::right << std::setprecision(3) << it1->totalMemory_ / 1024. / 1024.;
799 
800  // mem/histogram, need to catch nan if histos=0
801  if (it1->totalHistos_) {
802  std::cout << std::setw(14) << std::right << std::setprecision(3)
803  << it1->totalMemory_ / 1024. / it1->totalHistos_;
804  } else
805  std::cout << std::setw(14) << std::right << "-";
806 
807  std::cout << std::endl;
808 
809  // collect totals
810  nHistograms += it1->totalHistos_;
811  nBins += it1->totalBins_;
812  nEmptyBins += it1->totalEmptyBins_;
813  nBytes += it1->totalMemory_;
814  }
815 
816  overallNHistograms += nHistograms;
817  overallNBins += nBins;
818  overallNEmptyBins += nEmptyBins;
819  overallNBytes += nBytes;
820 
821  // display totals
822  std::cout << " " << std::setw(30) << std::left << "SUBSYSTEM TOTAL";
823  std::cout << std::setw(14) << std::right << nHistograms;
824  std::cout << std::setw(14) << std::right << nBins;
825  std::cout << std::setw(14) << std::right << nEmptyBins;
826  std::cout << std::setw(14) << std::right << (float)nEmptyBins / (float)nBins;
827  std::cout << std::setw(14) << std::right << std::setprecision(3) << nBins / float(nHistograms);
828  std::cout << std::setw(14) << std::right << std::setprecision(3) << nBytes / 1024. / 1000.;
829  std::cout << std::setw(14) << std::right << std::setprecision(3) << nBytes / 1024. / nHistograms;
830  std::cout << std::endl;
831 
832  std::cout << ".........................................................................................."
833  << std::endl;
834  }
835 
836  // dump total
837  std::cout << std::endl;
838  std::cout << "------------------------------------------------------------------------------------------"
839  << std::endl;
840  std::cout << "Grand total ";
842  std::cout << "FOR ALL ME:" << std::endl;
844  std::cout << "FOR LUMI PRODUCTS ONLY:" << std::endl;
845  std::cout << "------------------------------------------------------------------------------------------"
846  << std::endl;
847  std::cout << "Number of subsystems: " << dqmStoreStatsTopLevel.size() << std::endl;
848  std::cout << "Total number of histograms: " << overallNHistograms << " with: " << overallNBins << " bins alltogether"
849  << std::endl;
850  std::cout << "Total memory occupied by histograms (excl. overhead): " << overallNBytes / 1024. / 1000. << " MB"
851  << std::endl;
852 
853  std::cout << endl;
854  std::cout << "==========================================================================================="
855  << std::endl;
856  std::cout << "[DQMStoreStats::calcstats] -- End of output ";
858  std::cout << "FOR ALL ME." << std::endl;
860  std::cout << "FOR LUMI PRODUCTS ONLY." << std::endl;
861  std::cout << "==========================================================================================="
862  << std::endl;
863  std::cout << endl;
864 
865  // Put together a simplified version of the complete dump that is
866  // sent to std::cout. Just dump the very basic information,
867  // i.e. summary for each folder, both for run and LS products.
868  if (dumpToFWJR_) {
870  // Do not even try if the FWJR service is not available.
871  if (!jr.isAvailable())
872  return 0;
873  // Prepare appropriate map to store FWJR output.
874  std::map<std::string, std::string> jrInfo;
875  unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
876 
877  jrInfo["Source"] = "DQMServices/Components";
878  jrInfo["FileClass"] = "DQMStoreStats";
879  if (runonendrun_)
880  jrInfo["DumpType"] = "EndRun";
881  if (runonendlumi_)
882  jrInfo["DumpType"] = "EndLumi";
883  if (runonendjob_)
884  jrInfo["DumpType"] = "EndJob";
885  if (runineventloop_)
886  jrInfo["DumpType"] = "EventLoop";
888  jrInfo["Type"] = "RunProduct";
890  jrInfo["Type"] = "LumiProduct";
891 
892  jrInfo["pathNameMatch"] = pathnamematch_;
893 
894  for (auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
895  unsigned int nHistograms = 0, nBins = 0, nEmptyBins = 0, nBytes = 0;
896  for (auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
897  // collect totals
898  nHistograms += it1->totalHistos_;
899  nBins += it1->totalBins_;
900  nEmptyBins += it1->totalEmptyBins_;
901  nBytes += it1->totalMemory_;
902  }
903  overallNHistograms += nHistograms;
904  overallNBins += nBins;
905  overallNBytes += nBytes;
906  std::stringstream iss("");
907  iss << nHistograms;
908  jrInfo[it0->subsystemName_ + std::string("_h")] = iss.str();
909  iss.str("");
910  iss << nBins;
911  jrInfo[it0->subsystemName_ + std::string("_b")] = iss.str();
912  iss.str("");
913  iss << nEmptyBins;
914  jrInfo[it0->subsystemName_ + std::string("_be")] = iss.str();
915  iss.str("");
916  iss << ((float)nEmptyBins / (float)nBins);
917  jrInfo[it0->subsystemName_ + std::string("_fbe")] = iss.str();
918  iss.str("");
919  iss << ((float)nBins / (float)nHistograms);
920  jrInfo[it0->subsystemName_ + std::string("_b_h")] = iss.str();
921  iss.str("");
922  iss << nBytes / 1024. / 1024.;
923  jrInfo[it0->subsystemName_ + std::string("_MB")] = iss.str();
924  iss.str("");
925  iss << nBytes / 1024. / nHistograms;
926  jrInfo[it0->subsystemName_ + std::string("_Kb_h")] = iss.str();
927  }
928  jr->reportAnalysisFile("DQMStatsReport", jrInfo);
929  }
930 
931  return 0;
932 }
std::string subfolderName_
DQMStore * dbe_
void AddBinsS(unsigned int nBins, unsigned int nEmptyBins)
void update(unsigned int bins, unsigned int empty, unsigned int memory)
void AddBinsD(unsigned int nBins, unsigned int nEmptyBins)
void AddBinsI(unsigned int nBins, unsigned int nEmptyBins)
std::string subsystemName_
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
Definition: DQMStore.cc:609
std::string pathnamematch_
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)
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:473
void calcIgProfDump(Folder &)
bool isAvailable() const
Definition: Service.h:40

◆ dumpMemoryProfile()

void DQMStoreStats::dumpMemoryProfile ( )
private

Definition at line 937 of file DQMStoreStats.cc.

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

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

937  {
938  std::cout << std::endl;
939  std::cout << "------------------------------------------------------------------------------------------"
940  << std::endl;
941  std::cout << "Memory profile:" << std::endl;
942  std::cout << "------------------------------------------------------------------------------------------"
943  << std::endl;
944 
945  // determine virtual memory maximum
946  std::pair<time_t, unsigned int> maxItem(0, 0);
947  for (auto it = memoryHistoryVector_.begin(); it < memoryHistoryVector_.end(); ++it) {
948  if (it->second > maxItem.second) {
949  maxItem = *it;
950  }
951  }
952 
953  std::stringstream rootOutputFileName;
954  rootOutputFileName << "dqmStoreStats_memProfile_" << getpid() << ".root";
955 
956  // dump memory history to root file
958  TFile outputFile(rootOutputFileName.str().c_str(), "RECREATE");
959 
960  int aTime;
961  float aMb;
962 
963  TTree memHistoryTree("dqmstorestats_memhistory", "memory history");
964  memHistoryTree.Branch("seconds", &aTime, "seconds/I");
965  memHistoryTree.Branch("megabytes", &aMb, "megabytes/F");
966  for (auto it = memoryHistoryVector_.begin(); it < memoryHistoryVector_.end(); ++it) {
967  aTime = it->first - startingTime_;
968  aMb = it->second / 1000.;
969  memHistoryTree.Fill();
970  }
971 
972  outputFile.Write();
973  outputFile.Close();
974  }
975 
976  std::cout << "Approx. maximum total virtual memory size of job: ";
978  std::cout << maxItem.second / 1000. << " MB (reached " << maxItem.first - startingTime_
979  << " sec. after constructor called)," << std::endl;
980  std::cout << " memory history written to: " << rootOutputFileName.str() << " (" << memoryHistoryVector_.size()
981  << " samples)" << std::endl;
982  } else {
983  std::cout << "(could not be determined)" << std::endl;
984  }
985 
986  std::cout << std::endl << std::endl;
987 }
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
time_t startingTime_
bool isOpenProcFileSuccessful_

◆ endJob()

void DQMStoreStats::endJob ( void  )
overrideprotectedvirtual

◆ endLuminosityBlock()

void DQMStoreStats::endLuminosityBlock ( const edm::LuminosityBlock lumiSeg,
const edm::EventSetup c 
)
overrideprotected

◆ endRun()

void DQMStoreStats::endRun ( const edm::Run r,
const edm::EventSetup c 
)
overrideprotected

◆ print()

void DQMStoreStats::print ( void  )
private

Definition at line 992 of file DQMStoreStats.cc.

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

992  {
993  // subsystem info printout
994  std::cout << " ---------- " << subsystem_ << " ---------- " << std::endl;
995  std::cout << " " << subfolder_ << ": ";
996  std::cout << nmesubsys_ << " histograms with " << nbinssubsys_ << " bins. ";
997  if (nmesubsys_ > 0)
998  std::cout << nbinssubsys_ / nmesubsys_ << " bins/histogram ";
999  std::cout << std::endl;
1000  std::cout << " Largest histogram: " << maxbinsmesubsys_ << " with " << maxbinssubsys_ << " bins." << std::endl;
1001 }
std::string subsystem_
std::string maxbinsmesubsys_
std::string subfolder_

◆ readMemoryEntry()

std::pair< unsigned int, unsigned int > DQMStoreStats::readMemoryEntry ( ) const
private

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

Definition at line 1006 of file DQMStoreStats.cc.

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

Referenced by analyze().

1006  {
1007  // see if initial test reading was successful
1009  std::ifstream procFile(procFileName_.str().c_str(), ios::in);
1010 
1011  std::string readBuffer("");
1012  unsigned int memSize = 0;
1013 
1014  // scan procfile
1015  while (!procFile.eof()) {
1016  procFile >> readBuffer;
1017  if (std::string("VmSize:") == readBuffer) {
1018  procFile >> memSize;
1019  break;
1020  }
1021  }
1022 
1023  procFile.close();
1024  return std::pair<time_t, unsigned int>(time(nullptr), memSize);
1025  }
1026 
1027  return std::pair<time_t, unsigned int>(0, 0);
1028 }
bool isOpenProcFileSuccessful_
std::stringstream procFileName_

Member Data Documentation

◆ dbe_

DQMStore* DQMStoreStats::dbe_
private

Definition at line 346 of file DQMStoreStats.cc.

Referenced by beginJob(), and calcstats().

◆ dumpMemHistory_

bool DQMStoreStats::dumpMemHistory_
private

Definition at line 373 of file DQMStoreStats.cc.

Referenced by DQMStoreStats(), and dumpMemoryProfile().

◆ dumpToFWJR_

bool DQMStoreStats::dumpToFWJR_
private

Definition at line 374 of file DQMStoreStats.cc.

Referenced by calcstats(), and DQMStoreStats().

◆ isOpenProcFileSuccessful_

bool DQMStoreStats::isOpenProcFileSuccessful_
private

Definition at line 366 of file DQMStoreStats.cc.

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

◆ maxbinsglobal_

int DQMStoreStats::maxbinsglobal_
private

Definition at line 355 of file DQMStoreStats.cc.

Referenced by calcstats().

◆ maxbinsmeglobal_

std::string DQMStoreStats::maxbinsmeglobal_
private

Definition at line 357 of file DQMStoreStats.cc.

◆ maxbinsmesubsys_

std::string DQMStoreStats::maxbinsmesubsys_
private

Definition at line 358 of file DQMStoreStats.cc.

Referenced by print().

◆ maxbinssubsys_

int DQMStoreStats::maxbinssubsys_
private

Definition at line 356 of file DQMStoreStats.cc.

Referenced by calcstats(), and print().

◆ memoryHistoryVector_

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

Definition at line 364 of file DQMStoreStats.cc.

Referenced by analyze(), and dumpMemoryProfile().

◆ nbinsglobal_

int DQMStoreStats::nbinsglobal_
private

Definition at line 351 of file DQMStoreStats.cc.

Referenced by calcstats().

◆ nbinssubsys_

int DQMStoreStats::nbinssubsys_
private

Definition at line 352 of file DQMStoreStats.cc.

Referenced by calcstats(), and print().

◆ nmeglobal_

int DQMStoreStats::nmeglobal_
private

Definition at line 353 of file DQMStoreStats.cc.

◆ nmesubsys_

int DQMStoreStats::nmesubsys_
private

Definition at line 354 of file DQMStoreStats.cc.

Referenced by print().

◆ parameters_

edm::ParameterSet DQMStoreStats::parameters_
private

◆ pathnamematch_

std::string DQMStoreStats::pathnamematch_
private

Definition at line 361 of file DQMStoreStats.cc.

Referenced by calcstats(), and DQMStoreStats().

◆ procFileName_

std::stringstream DQMStoreStats::procFileName_
private

Definition at line 367 of file DQMStoreStats.cc.

Referenced by beginJob(), and readMemoryEntry().

◆ runineventloop_

bool DQMStoreStats::runineventloop_
private

Definition at line 372 of file DQMStoreStats.cc.

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

◆ runonendjob_

bool DQMStoreStats::runonendjob_
private

Definition at line 370 of file DQMStoreStats.cc.

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

◆ runonendlumi_

bool DQMStoreStats::runonendlumi_
private

Definition at line 371 of file DQMStoreStats.cc.

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

◆ runonendrun_

bool DQMStoreStats::runonendrun_
private

Definition at line 369 of file DQMStoreStats.cc.

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

◆ startingTime_

time_t DQMStoreStats::startingTime_
private

Definition at line 365 of file DQMStoreStats.cc.

Referenced by DQMStoreStats(), and dumpMemoryProfile().

◆ statsdepth_

int DQMStoreStats::statsdepth_
private

Definition at line 360 of file DQMStoreStats.cc.

Referenced by DQMStoreStats().

◆ subfolder_

std::string DQMStoreStats::subfolder_
private

Definition at line 350 of file DQMStoreStats.cc.

Referenced by print().

◆ subsystem_

std::string DQMStoreStats::subsystem_
private

Definition at line 349 of file DQMStoreStats.cc.

Referenced by print().

◆ verbose_

int DQMStoreStats::verbose_
private

Definition at line 362 of file DQMStoreStats.cc.

Referenced by DQMStoreStats().