CMS 3D CMS Logo

IgProfModule.cc
Go to the documentation of this file.
10 
12 #include <string>
13 #include <dlfcn.h>
14 #include <cstdio>
15 #include <cstring>
16 
17 class IgProfModule : public edm::EDAnalyzer {
18 public:
20  : dump_(nullptr), prescale_(0), nrecord_(0), nevent_(0), nrun_(0), nlumi_(0), nfile_(0) {
21  // Removing the __extension__ gives a warning which
22  // is acknowledged as a language problem in the C++ Standard Core
23  // Language Defect Report
24  //
25  // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#195
26  //
27  // since the suggested decision seems to be that the syntax should
28  // actually be "Conditionally-Supported Behavior" in some
29  // future C++ standard I simply silence the warning.
30  if (void *sym = dlsym(nullptr, "igprof_dump_now"))
31  dump_ = __extension__(void (*)(const char *)) sym;
32  else
33  edm::LogWarning("IgProfModule") << "IgProfModule requested but application is not"
34  << " currently being profiled with igprof\n";
35 
36  prescale_ = ps.getUntrackedParameter<int>("reportEventInterval", prescale_);
37  atBeginJob_ = ps.getUntrackedParameter<std::string>("reportToFileAtBeginJob", atBeginJob_);
38  atEndJob_ = ps.getUntrackedParameter<std::string>("reportToFileAtEndJob", atEndJob_);
39  atBeginLumi_ = ps.getUntrackedParameter<std::string>("reportToFileAtBeginLumi", atBeginLumi_);
40  atEndLumi_ = ps.getUntrackedParameter<std::string>("reportToFileAtEndLumi", atEndLumi_);
41  atInputFile_ = ps.getUntrackedParameter<std::string>("reportToFileAtInputFile", atInputFile_);
42  atEvent_ = ps.getUntrackedParameter<std::string>("reportToFileAtEvent", atEvent_);
43  }
44 
45  void beginJob() override { makeDump(atBeginJob_); }
46 
47  void endJob(void) override { makeDump(atEndJob_); }
48 
49  void analyze(const edm::Event &e, const edm::EventSetup &) override {
50  nevent_ = e.id().event();
51  if (prescale_ > 0 && (++nrecord_ % prescale_) == 1)
53  }
54 
55  void beginRun(const edm::Run &r, const edm::EventSetup &) override {
56  nrun_ = r.run();
58  }
59 
60  void endRun(const edm::Run &, const edm::EventSetup &) override { makeDump(atEndRun_); }
61 
63  nlumi_ = l.luminosityBlock();
65  }
66 
68 
69  void respondToOpenInputFile(const edm::FileBlock &) override {
70  ++nfile_;
72  }
73 
74 private:
75  void makeDump(const std::string &format) {
76  if (!dump_ || format.empty())
77  return;
78 
79  std::string final(format);
80  final = replace(final, "%I", nrecord_);
81  final = replaceU64(final, "%E", nevent_);
82  final = replaceU64(final, "%R", nrun_);
83  final = replaceU64(final, "%L", nlumi_);
84  final = replace(final, "%F", nfile_);
85  dump_(final.c_str());
86  }
87 
88  static std::string replace(const std::string &s, const char *pat, int val) {
89  size_t pos = 0;
90  size_t patlen = strlen(pat);
92  while ((pos = result.find(pat, pos)) != std::string::npos) {
93  char buf[64];
94  int n = sprintf(buf, "%d", val);
95  result.replace(pos, patlen, buf);
96  pos = pos - patlen + n;
97  }
98 
99  return result;
100  }
101 
102  static std::string replaceU64(const std::string &s, const char *pat, unsigned long long val) {
103  size_t pos = 0;
104  size_t patlen = strlen(pat);
105  std::string result = s;
106  while ((pos = result.find(pat, pos)) != std::string::npos) {
107  char buf[64];
108  int n = sprintf(buf, "%llu", val);
109  result.replace(pos, patlen, buf);
110  pos = pos - patlen + n;
111  }
112 
113  return result;
114  }
115 
116  void (*dump_)(const char *);
126  int nrecord_;
130  int nfile_;
131 };
132 
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
IgProfModule::atEndRun_
std::string atEndRun_
Definition: IgProfModule.cc:120
IgProfModule::IgProfModule
IgProfModule(const edm::ParameterSet &ps)
Definition: IgProfModule.cc:19
IgProfModule::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &) override
Definition: IgProfModule.cc:62
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
IgProfModule::nlumi_
edm::LuminosityBlockNumber_t nlumi_
Definition: IgProfModule.cc:129
IgProfModule::makeDump
void makeDump(const std::string &format)
Definition: IgProfModule.cc:75
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
LuminosityBlock.h
pos
Definition: PixelAliasList.h:18
RunLumiEventNumber.h
IgProfModule::atEvent_
std::string atEvent_
Definition: IgProfModule.cc:124
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
EDAnalyzer.h
IgProfModule::atInputFile_
std::string atInputFile_
Definition: IgProfModule.cc:123
edm::LuminosityBlockNumber_t
unsigned int LuminosityBlockNumber_t
Definition: RunLumiEventNumber.h:13
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
edm::FileBlock
Definition: FileBlock.h:20
IgProfModule::endRun
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: IgProfModule.cc:60
IgProfModule::nrecord_
int nrecord_
Definition: IgProfModule.cc:126
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
IgProfModule::dump_
void(* dump_)(const char *)
Definition: IgProfModule.cc:116
Service.h
dqm-mbProfile.format
format
Definition: dqm-mbProfile.py:16
Run.h
IgProfModule::atBeginRun_
std::string atBeginRun_
Definition: IgProfModule.cc:119
IgProfModule::nfile_
int nfile_
Definition: IgProfModule.cc:130
IgProfModule::atEndJob_
std::string atEndJob_
Definition: IgProfModule.cc:118
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
IgProfModule::beginJob
void beginJob() override
Definition: IgProfModule.cc:45
IgProfModule::nrun_
edm::RunNumber_t nrun_
Definition: IgProfModule.cc:128
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
IgProfModule::replace
static std::string replace(const std::string &s, const char *pat, int val)
Definition: IgProfModule.cc:88
IgProfModule::nevent_
edm::EventNumber_t nevent_
Definition: IgProfModule.cc:127
IgProfModule::atEndLumi_
std::string atEndLumi_
Definition: IgProfModule.cc:122
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
IgProfModule::atBeginLumi_
std::string atBeginLumi_
Definition: IgProfModule.cc:121
IgProfModule
Definition: IgProfModule.cc:17
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
IgProfModule::endJob
void endJob(void) override
Definition: IgProfModule.cc:47
IgProfModule::replaceU64
static std::string replaceU64(const std::string &s, const char *pat, unsigned long long val)
Definition: IgProfModule.cc:102
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
IgProfModule::analyze
void analyze(const edm::Event &e, const edm::EventSetup &) override
Definition: IgProfModule.cc:49
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
FileBlock.h
alignCSCRings.r
r
Definition: alignCSCRings.py:93
heppy_batch.val
val
Definition: heppy_batch.py:351
IgProfModule::beginRun
void beginRun(const edm::Run &r, const edm::EventSetup &) override
Definition: IgProfModule.cc:55
IgProfModule::prescale_
int prescale_
Definition: IgProfModule.cc:125
format
IgProfModule::atBeginJob_
std::string atBeginJob_
Definition: IgProfModule.cc:117
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
IgProfModule::respondToOpenInputFile
void respondToOpenInputFile(const edm::FileBlock &) override
Definition: IgProfModule.cc:69
edm::Event
Definition: Event.h:73
IgProfModule::endLuminosityBlock
void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &) override
Definition: IgProfModule.cc:67
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37