Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option in IgProfService to dump profiles at {pre,post}ModuleEvent #36923

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions IgTools/IgProf/plugins/IgProfService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ IgProfService::IgProfService(ParameterSet const &ps, ActivityRegistry &iRegistry
atPreEvent_ = ps.getUntrackedParameter<std::string>("reportToFileAtPreEvent", atPreEvent_);
atPostEvent_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostEvent", atPostEvent_);

modules_ = ps.getUntrackedParameter<std::vector<std::string>>("reportModules", modules_);
moduleTypes_ = ps.getUntrackedParameter<std::vector<std::string>>("reportModuleTypes", moduleTypes_);
std::sort(modules_.begin(), modules_.end());
std::sort(moduleTypes_.begin(), moduleTypes_.end());
atPreModuleEvent_ = ps.getUntrackedParameter<std::string>("reportToFileAtPreModuleEvent", atPreModuleEvent_);
atPostModuleEvent_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostModuleEvent", atPostModuleEvent_);

atPostEndLumi_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostEndLumi", atPostEndLumi_);
atPostEndRun_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostEndRun", atPostEndRun_);
atPostEndJob_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostEndJob", atPostEndJob_);
Expand All @@ -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);
Expand Down Expand Up @@ -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_); }

Expand All @@ -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;

Expand All @@ -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());
}

Expand Down Expand Up @@ -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);
11 changes: 10 additions & 1 deletion IgTools/IgProf/plugins/IgProfService.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 *);

Expand All @@ -56,6 +60,11 @@ namespace edm {
std::string atPreEvent_;
std::string atPostEvent_;

std::vector<std::string> modules_;
std::vector<std::string> moduleTypes_;
std::string atPreModuleEvent_;
std::string atPostModuleEvent_;

std::string atPostEndLumi_;
std::string atPostEndRun_;
std::string atPostEndJob_;
Expand Down