106 template <
class Item>
110 virtual void First() = 0;
111 virtual void Next() = 0;
112 virtual bool IsDone()
const = 0;
119 template <
class Item>
143 static unsigned int id = 10;
170 if (subfolder->name() ==
name)
192 result += subfolder->getHistos();
198 result += subfolder->getBins();
204 result += subfolder->getEmptyBins();
210 result += subfolder->getMemory();
223 <<
" Memory: " <<
getMemory() <<
" and my children are: " << std::endl;
230 std::stringstream
s(
"");
231 s <<
"INSERT INTO mainrows(id, symbol_id, self_count, cumulative_count, kids, self_calls, total_calls, self_paths, " 236 sql_statement.append(
s.str());
238 subfolder->mainrows(sql_statement);
243 std::stringstream
s(
"");
244 s <<
"INSERT INTO symbols(id, name, filename_id) VALUES (" <<
id_ <<
",\"" <<
folderName_ <<
"\", " << parentid
246 sql_statement.append(
s.str());
248 subfolder->symbols(sql_statement);
253 std::stringstream
s(
"");
254 s <<
"INSERT INTO parents(self_id, child_id, to_child_count, to_child_calls, to_child_paths, pct) VALUES(" 257 sql_statement.append(
s.str());
259 subfolder->parents(sql_statement);
264 std::stringstream
s(
"");
265 s <<
"INSERT INTO children(self_id, parent_id, from_parent_count, from_parent_calls, from_parent_paths, pct) " 270 sql_statement.append(
s.str());
272 subfolder->children(sql_statement);
276 std::stringstream
s(
"");
277 s <<
"INSERT INTO mainrows(id, symbol_id, self_count, cumulative_count, kids, self_calls, total_calls, self_paths, " 281 sql_statement.append(
s.str());
285 std::stringstream
s(
"");
286 s <<
"INSERT INTO summary(counter, total_count, total_freq, tick_period) VALUES (\"BINS_LIVE\"," <<
getMemory()
287 <<
"," <<
getBins() <<
", 1);\n";
288 sql_statement.append(
s.str());
292 std::stringstream
s(
"");
293 s <<
"INSERT INTO files(id, name) VALUES(" <<
id_ <<
",\"" <<
folderName_ <<
"\");\n";
294 sql_statement.append(
s.str());
385 unsigned int len = lenx + leny + lenz;
390 for (
unsigned int i = 1;
i < len; ++
i) {
392 if (
i % (lenx - 1) == 0)
396 if (
i % (lenx + leny - 1) == 0)
398 if (
i % (lenx + leny) == 0)
400 if (
i % (lenx + leny + lenz - 1) == 0)
422 maxbinsmeglobal_(
""),
423 maxbinsmesubsys_(
""),
442 std::ofstream
stream(
"dqm-bin-stats.sql");
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," 460 " CREATE TABLE files (" 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," 470 " self_calls INTEGER," 471 " total_calls INTEGER," 472 " self_paths INTEGER," 473 " total_paths INTEGER," 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," 484 " CREATE TABLE summary (" 486 " total_count INTEGER," 487 " total_freq INTEGER," 490 " CREATE TABLE symbols (" 493 " filename_id INTEGER CONSTRAINT file_id_exists REFERENCES files(id)" 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);" 503 root.files(sql_statement);
504 root.symbols(sql_statement);
505 root.mainrows_cumulative(sql_statement);
506 root.summary(sql_statement);
514 stream << sql_statement << std::endl;
532 size_t subsysStringEnd = 0, subfolderStringBegin = 0, subfolderStringEnd = 0;
534 std::vector<MonitorElement*> melist;
541 for (
auto& it : melist) {
549 subfolderStringBegin = 0;
550 Folder* curr = &dbeFolder;
552 subfolderStringEnd =
path.find(
'/', subfolderStringBegin);
553 if (std::string::npos == subfolderStringEnd) {
554 curr = curr->
cd(
path.substr(subfolderStringBegin,
path.size() - subfolderStringBegin));
557 curr = curr->
cd(
path.substr(subfolderStringBegin, subfolderStringEnd - subfolderStringBegin));
558 subfolderStringBegin = ++subfolderStringEnd <
path.size() ? subfolderStringEnd :
path.size();
565 subsysStringEnd =
path.find(
'/', 0);
566 if (std::string::npos == subsysStringEnd)
567 subsysStringEnd =
path.size();
570 if (
path.substr(0, subsysStringEnd) != subsystemname) {
572 subsystemname =
path.substr(0, subsysStringEnd);
574 dqmStoreStatsTopLevel.push_back(aSubsystem);
579 if (
path.size() == subsysStringEnd) {
583 dqmStoreStatsTopLevel.back().push_back(aSubfolder);
588 subfolderStringEnd =
path.find(
'/', subsysStringEnd + 1);
589 if (std::string::npos == subfolderStringEnd)
590 subfolderStringEnd =
path.size();
593 if (
path.substr(subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1) != subfoldername) {
594 subfoldername =
path.substr(subsysStringEnd + 1, subfolderStringEnd - subsysStringEnd - 1);
597 dqmStoreStatsTopLevel.back().push_back(aSubfolder);
604 switch (it->kind()) {
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));
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));
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));
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));
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));
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));
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));
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));
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));
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));
683 it->getNbinsX() * it->getNbinsY() * it->getNbinsZ(),
684 getEmptyMetric(it->getTH3F()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, it->getNbinsZ() + 2));
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));
708 std::cout <<
"===========================================================================================" 710 std::cout <<
"[DQMStoreStats::calcstats] -- Dumping stats results ";
714 std::cout <<
"FOR LUMI PRODUCTS ONLY" << std::endl;
715 std::cout <<
"===========================================================================================" 719 std::cout <<
"------------------------------------------------------------------------------------------" 721 std::cout <<
"Configuration:" << std::endl;
722 std::cout <<
"------------------------------------------------------------------------------------------" 728 std::cout <<
"on lumi end." << std::endl;
732 std::cout <<
"in event loop." << std::endl;
737 std::cout <<
"------------------------------------------------------------------------------------------" 739 std::cout <<
"Top level folder tree:" << std::endl;
740 std::cout <<
"------------------------------------------------------------------------------------------" 742 for (
auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
743 std::cout << it0->subsystemName_ <<
" (subsystem)" << std::endl;
745 for (
auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
746 std::cout <<
" |--> " << it1->subfolderName_ <<
" (subfolder)" << std::endl;
752 unsigned int overallNHistograms = 0, overallNBins = 0, overallNBytes = 0;
755 std::cout <<
"------------------------------------------------------------------------------------------" 757 std::cout <<
"Detailed ressource usage information ";
761 std::cout <<
"FOR LUMI PRODUCTS ONLY" << std::endl;
762 std::cout <<
"------------------------------------------------------------------------------------------" 764 std::cout <<
"subsystem/folder histograms bins Empty bins Empty/Total " 768 "histogram (total) histogram " 770 std::cout <<
"------------------------------------------------------------------------------------------" 772 for (
auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
773 std::cout << it0->subsystemName_ << std::endl;
775 unsigned int nHistograms = 0,
nBins = 0, nEmptyBins = 0, nBytes = 0;
777 for (
auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
779 std::string thisSubfolderName(it1->subfolderName_);
780 if (thisSubfolderName.size() > 30) {
781 thisSubfolderName.resize(30);
782 thisSubfolderName.replace(thisSubfolderName.size() - 3, 3, 3,
'.');
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_;
793 if (it1->totalHistos_) {
794 std::cout << std::setw(14) << std::right << std::setprecision(3) << it1->totalBins_ /
float(it1->totalHistos_);
796 std::cout << std::setw(14) << std::right <<
"-";
798 std::cout << std::setw(14) << std::right << std::setprecision(3) << it1->totalMemory_ / 1024. / 1024.;
801 if (it1->totalHistos_) {
802 std::cout << std::setw(14) << std::right << std::setprecision(3)
803 << it1->totalMemory_ / 1024. / it1->totalHistos_;
805 std::cout << std::setw(14) << std::right <<
"-";
810 nHistograms += it1->totalHistos_;
811 nBins += it1->totalBins_;
812 nEmptyBins += it1->totalEmptyBins_;
813 nBytes += it1->totalMemory_;
816 overallNHistograms += nHistograms;
817 overallNBins +=
nBins;
818 overallNBytes += nBytes;
821 std::cout <<
" " << std::setw(30) << std::left <<
"SUBSYSTEM TOTAL";
822 std::cout << std::setw(14) << std::right << nHistograms;
824 std::cout << std::setw(14) << std::right << nEmptyBins;
826 std::cout << std::setw(14) << std::right << std::setprecision(3) <<
nBins /
float(nHistograms);
827 std::cout << std::setw(14) << std::right << std::setprecision(3) << nBytes / 1024. / 1000.;
828 std::cout << std::setw(14) << std::right << std::setprecision(3) << nBytes / 1024. / nHistograms;
831 std::cout <<
".........................................................................................." 837 std::cout <<
"------------------------------------------------------------------------------------------" 843 std::cout <<
"FOR LUMI PRODUCTS ONLY:" << std::endl;
844 std::cout <<
"------------------------------------------------------------------------------------------" 846 std::cout <<
"Number of subsystems: " << dqmStoreStatsTopLevel.size() << std::endl;
847 std::cout <<
"Total number of histograms: " << overallNHistograms <<
" with: " << overallNBins <<
" bins alltogether" 849 std::cout <<
"Total memory occupied by histograms (excl. overhead): " << overallNBytes / 1024. / 1000. <<
" MB" 853 std::cout <<
"===========================================================================================" 855 std::cout <<
"[DQMStoreStats::calcstats] -- End of output ";
859 std::cout <<
"FOR LUMI PRODUCTS ONLY." << std::endl;
860 std::cout <<
"===========================================================================================" 873 std::map<std::string, std::string> jrInfo;
875 jrInfo[
"Source"] =
"DQMServices/Components";
876 jrInfo[
"FileClass"] =
"DQMStoreStats";
878 jrInfo[
"DumpType"] =
"EndRun";
880 jrInfo[
"DumpType"] =
"EndLumi";
882 jrInfo[
"DumpType"] =
"EndJob";
884 jrInfo[
"DumpType"] =
"EventLoop";
886 jrInfo[
"Type"] =
"RunProduct";
888 jrInfo[
"Type"] =
"LumiProduct";
892 for (
auto it0 = dqmStoreStatsTopLevel.begin(); it0 < dqmStoreStatsTopLevel.end(); ++it0) {
893 unsigned int nHistograms = 0,
nBins = 0, nEmptyBins = 0, nBytes = 0;
894 for (
auto it1 = it0->begin(); it1 < it0->end(); ++it1) {
896 nHistograms += it1->totalHistos_;
897 nBins += it1->totalBins_;
898 nEmptyBins += it1->totalEmptyBins_;
899 nBytes += it1->totalMemory_;
901 std::stringstream iss(
"");
903 jrInfo[it0->subsystemName_ +
std::string(
"_h")] = iss.str();
906 jrInfo[it0->subsystemName_ +
std::string(
"_b")] = iss.str();
909 jrInfo[it0->subsystemName_ +
std::string(
"_be")] = iss.str();
912 jrInfo[it0->subsystemName_ +
std::string(
"_fbe")] = iss.str();
915 jrInfo[it0->subsystemName_ +
std::string(
"_b_h")] = iss.str();
917 iss << nBytes / 1024. / 1024.;
918 jrInfo[it0->subsystemName_ +
std::string(
"_MB")] = iss.str();
920 iss << nBytes / 1024. / nHistograms;
921 jrInfo[it0->subsystemName_ +
std::string(
"_Kb_h")] = iss.str();
934 std::cout <<
"------------------------------------------------------------------------------------------" 936 std::cout <<
"Memory profile:" << std::endl;
937 std::cout <<
"------------------------------------------------------------------------------------------" 941 std::pair<time_t, unsigned int> maxItem(0, 0);
943 if (it->second > maxItem.second) {
948 std::stringstream rootOutputFileName;
949 rootOutputFileName <<
"dqmStoreStats_memProfile_" << getpid() <<
".root";
953 TFile
outputFile(rootOutputFileName.str().c_str(),
"RECREATE");
958 TTree memHistoryTree(
"dqmstorestats_memhistory",
"memory history");
959 memHistoryTree.Branch(
"seconds", &aTime,
"seconds/I");
960 memHistoryTree.Branch(
"megabytes", &aMb,
"megabytes/F");
963 aMb = it->second / 1000.;
964 memHistoryTree.Fill();
971 std::cout <<
"Approx. maximum total virtual memory size of job: ";
974 <<
" sec. after constructor called)," << std::endl;
976 <<
" samples)" << std::endl;
978 std::cout <<
"(could not be determined)" << std::endl;
1007 unsigned int memSize = 0;
1010 while (!procFile.eof()) {
1011 procFile >> readBuffer;
1013 procFile >> memSize;
1019 return std::pair<time_t, unsigned int>(
time(
nullptr), memSize);
1022 return std::pair<time_t, unsigned int>(0, 0);
1038 if (procFile.good()) {
1041 std::cerr <<
" [DQMStoreStats::beginJob] ** WARNING: could not open file: " <<
procFileName_.str() << std::endl;
1042 std::cerr <<
" Total memory profile will not be available." << std::endl;
std::string subfolderName_
std::pair< unsigned int, unsigned int > readMemoryEntry() const
virtual bool IsDone() const =0
void AddBinsS(unsigned int nBins, unsigned int nEmptyBins)
~VIterator() override=default
DQMStoreStatsSubsystem()=default
void update(unsigned int bins, unsigned int empty, unsigned int memory)
virtual Item CurrentItem() const =0
virtual ~Iterator()=default
void AddBinsD(unsigned int nBins, unsigned int nEmptyBins)
VIterator(const std::vector< Item > *aVector)
std::vector< std::pair< time_t, unsigned int > > memoryHistoryVector_
void AddBinsI(unsigned int nBins, unsigned int nEmptyBins)
std::string subsystemName_
void mainrows_cumulative(std::string &sql_statement)
unsigned int getEmptyBins()
VIterator< Folder * > CreateIterator()
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
~DQMStoreStats() override=default
unsigned int totalMemory_
void summary(std::string &sql_statement)
T getUntrackedParameter(std::string const &, T const &) const
dqm::reco::DQMStore DQMStore
std::string maxbinsmeglobal_
void endRun(const edm::Run &r, const edm::EventSetup &c) override
void mainrows(std::string &sql_statement)
DQMStoreStatsTopLevel()=default
std::vector< Folder * > subfolders_
const std::string & name()
bool isOpenProcFileSuccessful_
unsigned int totalEmptyBins_
void setLevel(unsigned int value)
unsigned int totalEmptyBins_
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
Item CurrentItem() const override
std::string pathnamematch_
std::string maxbinsmesubsys_
DQMStoreStats(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
void files(std::string &sql_statement)
void setFather(Folder *e)
void dump(std::string indent)
unsigned int totalHistos_
void analyze(const edm::Event &e, const edm::EventSetup &c) override
void parents(std::string &sql_statement)
bool IsDone() const override
dqm::legacy::MonitorElement MonitorElement
static unsigned int getId()
static unsigned int getEmptyMetric(T *array, int lenx, int leny, int lenz)
Folder * cd(const std::string &name)
edm::ParameterSet parameters_
unsigned int totalMemory_
void AddBinsF(unsigned int nBins, unsigned int nEmptyBins)
void children(std::string &sql_statement)
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
void calcIgProfDump(Folder &)
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
unsigned int totalHistos_
const std::vector< Item > * vector_
std::stringstream procFileName_
void symbols(std::string &sql_statement)
void setId(unsigned int id)