diff --git a/IgTools/IgProf/plugins/IgProfService.cc b/IgTools/IgProf/plugins/IgProfService.cc index 1fde917a6eac9..ee4a15494f2a1 100644 --- a/IgTools/IgProf/plugins/IgProfService.cc +++ b/IgTools/IgProf/plugins/IgProfService.cc @@ -58,6 +58,13 @@ IgProfService::IgProfService(ParameterSet const &ps, ActivityRegistry &iRegistry atPreEvent_ = ps.getUntrackedParameter("reportToFileAtPreEvent", atPreEvent_); atPostEvent_ = ps.getUntrackedParameter("reportToFileAtPostEvent", atPostEvent_); + modules_ = ps.getUntrackedParameter>("reportModules", modules_); + moduleTypes_ = ps.getUntrackedParameter>("reportModuleTypes", moduleTypes_); + std::sort(modules_.begin(), modules_.end()); + std::sort(moduleTypes_.begin(), moduleTypes_.end()); + atPreModuleEvent_ = ps.getUntrackedParameter("reportToFileAtPreModuleEvent", atPreModuleEvent_); + atPostModuleEvent_ = ps.getUntrackedParameter("reportToFileAtPostModuleEvent", atPostModuleEvent_); + atPostEndLumi_ = ps.getUntrackedParameter("reportToFileAtPostEndLumi", atPostEndLumi_); atPostEndRun_ = ps.getUntrackedParameter("reportToFileAtPostEndRun", atPostEndRun_); atPostEndJob_ = ps.getUntrackedParameter("reportToFileAtPostEndJob", atPostEndJob_); @@ -73,6 +80,11 @@ IgProfService::IgProfService(ParameterSet const &ps, ActivityRegistry &iRegistry iRegistry.watchPreEvent(this, &IgProfService::preEvent); iRegistry.watchPostEvent(this, &IgProfService::postEvent); + if (not modules_.empty() or not moduleTypes_.empty()) { + iRegistry.watchPreModuleEvent(this, &IgProfService::preModuleEvent); + iRegistry.watchPostModuleEvent(this, &IgProfService::postModuleEvent); + } + iRegistry.watchPostGlobalEndLumi(this, &IgProfService::postEndLumi); iRegistry.watchPostGlobalEndRun(this, &IgProfService::postEndRun); iRegistry.watchPostEndJob(this, &IgProfService::postEndJob); @@ -106,9 +118,39 @@ void IgProfService::postEvent(StreamContext const &iStream) { makeDump(atPostEvent_); } -void IgProfService::postEndLumi(GlobalContext const &) { makeDump(atPostEndLumi_); } +void IgProfService::preModuleEvent(StreamContext const &iStream, ModuleCallingContext const &mcc) { + nevent_ = iStream.eventID().event(); + if ((prescale_ > 0) && (nrecord_ >= mineventrecord_) && (((nrecord_ - mineventrecord_) % prescale_) == 0)) { + auto const &moduleLabel = mcc.moduleDescription()->moduleLabel(); + auto const &moduleType = mcc.moduleDescription()->moduleName(); + if (std::binary_search(modules_.begin(), modules_.end(), moduleLabel) or + std::binary_search(moduleTypes_.begin(), moduleTypes_.end(), moduleType)) { + makeDump(atPreModuleEvent_, moduleLabel); + } + } +} + +void IgProfService::postModuleEvent(StreamContext const &iStream, ModuleCallingContext const &mcc) { + nevent_ = iStream.eventID().event(); + if ((prescale_ > 0) && (nrecord_ >= mineventrecord_) && (((nrecord_ - mineventrecord_) % prescale_) == 0)) { + auto const &moduleLabel = mcc.moduleDescription()->moduleLabel(); + auto const &moduleType = mcc.moduleDescription()->moduleName(); + if (std::binary_search(modules_.begin(), modules_.end(), moduleLabel) or + std::binary_search(moduleTypes_.begin(), moduleTypes_.end(), moduleType)) { + makeDump(atPostModuleEvent_, moduleLabel); + } + } +} + +void IgProfService::postEndLumi(GlobalContext const &gc) { + nlumi_ = gc.luminosityBlockID().luminosityBlock(); + makeDump(atPostEndLumi_); +} -void IgProfService::postEndRun(GlobalContext const &) { makeDump(atPostEndRun_); } +void IgProfService::postEndRun(GlobalContext const &gc) { + nrun_ = gc.luminosityBlockID().run(); + makeDump(atPostEndRun_); +} void IgProfService::postEndJob() { makeDump(atPostEndJob_); } @@ -122,7 +164,7 @@ void IgProfService::postCloseFile(std::string const &) { makeDump(atPostCloseFile_); } -void IgProfService::makeDump(const std::string &format) { +void IgProfService::makeDump(const std::string &format, std::string_view moduleLabel) { if (!dump_ || format.empty()) return; @@ -133,6 +175,7 @@ void IgProfService::makeDump(const std::string &format) { final = replaceU64(final, "%L", nlumi_); final = replace(final, "%F", nfileopened_); final = replace(final, "%C", nfileclosed_); + final = replace(final, "%M", moduleLabel); dump_(final.c_str()); } @@ -164,4 +207,16 @@ std::string IgProfService::replaceU64(const std::string &s, const char *pat, uns return result; } +std::string IgProfService::replace(const std::string &s, const char *pat, std::string_view val) { + size_t pos = 0; + size_t patlen = strlen(pat); + std::string result = s; + while ((pos = result.find(pat, pos)) != std::string::npos) { + result.replace(pos, patlen, val.data()); + pos = pos - patlen + val.size(); + } + + return result; +} + DEFINE_FWK_SERVICE(IgProfService); diff --git a/IgTools/IgProf/plugins/IgProfService.h b/IgTools/IgProf/plugins/IgProfService.h index 1f9080d70ba8f..859a7d18d009f 100644 --- a/IgTools/IgProf/plugins/IgProfService.h +++ b/IgTools/IgProf/plugins/IgProfService.h @@ -30,6 +30,9 @@ namespace edm { void preEvent(StreamContext const &sc); void postEvent(StreamContext const &sc); + void preModuleEvent(StreamContext const &sc, ModuleCallingContext const &mcc); + void postModuleEvent(StreamContext const &sc, ModuleCallingContext const &mcc); + void postEndLumi(GlobalContext const &gc); void postEndRun(GlobalContext const &gc); @@ -43,9 +46,10 @@ namespace edm { inline bool isProcessWideService(IgProfService const *) { return true; } private: - void makeDump(const std::string &format); + void makeDump(const std::string &format, std::string_view moduleLabel = ""); static std::string replace(const std::string &s, const char *pat, int val); static std::string replaceU64(const std::string &s, const char *pat, unsigned long long val); + static std::string replace(const std::string &s, const char *pat, std::string_view val); void (*dump_)(const char *); @@ -56,6 +60,11 @@ namespace edm { std::string atPreEvent_; std::string atPostEvent_; + std::vector modules_; + std::vector moduleTypes_; + std::string atPreModuleEvent_; + std::string atPostModuleEvent_; + std::string atPostEndLumi_; std::string atPostEndRun_; std::string atPostEndJob_;