CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IgProfModule.cc
Go to the documentation of this file.
9 
11 #include <string>
12 #include <dlfcn.h>
13 #include <cstdio>
14 #include <cstring>
15 
17 {
18 public:
20  : dump_(0),
21  prescale_(0),
22  nrecord_(0),
23  nevent_(0),
24  nrun_(0),
25  nlumi_(0),
26  nfile_(0)
27  {
28  // Removing the __extension__ gives a warning which
29  // is acknowledged as a language problem in the C++ Standard Core
30  // Language Defect Report
31  //
32  // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#195
33  //
34  // since the suggested decision seems to be that the syntax should
35  // actually be "Conditionally-Supported Behavior" in some
36  // future C++ standard I simply silence the warning.
37  if (void *sym = dlsym(0, "igprof_dump_now"))
38  dump_ = __extension__ (void(*)(const char *)) sym;
39  else
40  edm::LogWarning("IgProfModule")
41  << "IgProfModule requested but application is not"
42  << " currently being profiled with igprof\n";
43 
44  prescale_ = ps.getUntrackedParameter<int>("reportEventInterval", prescale_);
45  atBeginJob_ = ps.getUntrackedParameter<std::string>("reportToFileAtBeginJob", atBeginJob_);
46  atEndJob_ = ps.getUntrackedParameter<std::string>("reportToFileAtEndJob", atEndJob_);
47  atBeginLumi_ = ps.getUntrackedParameter<std::string>("reportToFileAtBeginLumi", atBeginLumi_);
48  atEndLumi_ = ps.getUntrackedParameter<std::string>("reportToFileAtEndLumi", atEndLumi_);
49  atInputFile_ = ps.getUntrackedParameter<std::string>("reportToFileAtInputFile", atInputFile_);
50  atEvent_ = ps.getUntrackedParameter<std::string>("reportToFileAtEvent", atEvent_);
51  }
52 
53  virtual void beginJob()
54  { makeDump(atBeginJob_); }
55 
56  virtual void endJob(void)
57  { makeDump(atEndJob_); }
58 
59  virtual void analyze(const edm::Event &e, const edm::EventSetup &)
60  {
61  nevent_ = e.id().event();
62  if (prescale_ > 0 && (++nrecord_ % prescale_) == 1)
64  }
65 
66  virtual void beginRun(const edm::Run &r, const edm::EventSetup &)
67  { nrun_ = r.run(); makeDump(atBeginRun_); }
68 
69  virtual void endRun(const edm::Run &, const edm::EventSetup &)
70  { makeDump(atEndRun_); }
71 
74 
76  { makeDump(atEndLumi_); }
77 
78  virtual void respondToOpenInputFile(const edm::FileBlock &)
80 
81 private:
82  void makeDump(const std::string &format)
83  {
84  if (! dump_ || format.empty())
85  return;
86 
87  std::string final(format);
88  final = replace(final, "%I", nrecord_);
89  final = replace(final, "%E", nevent_);
90  final = replace(final, "%R", nrun_);
91  final = replace(final, "%L", nlumi_);
92  final = replace(final, "%F", nfile_);
93  dump_(final.c_str());
94  }
95 
96  static std::string replace(const std::string &s, const char *pat, int val)
97  {
98  size_t pos = 0;
99  size_t patlen = strlen(pat);
100  std::string result = s;
101  while ((pos = result.find(pat, pos)) != std::string::npos)
102  {
103  char buf[64];
104  int n = sprintf(buf, "%d", val);
105  result.replace(pos, patlen, buf);
106  pos = pos - patlen + n;
107  }
108 
109  return result;
110  }
111 
112  void (*dump_)(const char *);
113  std::string atBeginJob_;
114  std::string atEndJob_;
115  std::string atBeginRun_;
116  std::string atEndRun_;
117  std::string atBeginLumi_;
118  std::string atEndLumi_;
119  std::string atInputFile_;
120  std::string atEvent_;
122  int nrecord_;
123  int nevent_;
124  int nrun_;
125  int nlumi_;
126  int nfile_;
127 };
128 
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
virtual void beginRun(const edm::Run &r, const edm::EventSetup &)
Definition: IgProfModule.cc:66
RunNumber_t run() const
Definition: RunBase.h:42
std::string atBeginRun_
std::string atInputFile_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &)
Definition: IgProfModule.cc:75
virtual void respondToOpenInputFile(const edm::FileBlock &)
Definition: IgProfModule.cc:78
string format
Some error handling for the usage.
virtual void endRun(const edm::Run &, const edm::EventSetup &)
Definition: IgProfModule.cc:69
std::string atEndLumi_
void(* dump_)(const char *)
static std::string replace(const std::string &s, const char *pat, int val)
Definition: IgProfModule.cc:96
virtual void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &)
Definition: IgProfModule.cc:72
void makeDump(const std::string &format)
Definition: IgProfModule.cc:82
std::string atEndRun_
LuminosityBlockNumber_t luminosityBlock() const
virtual void analyze(const edm::Event &e, const edm::EventSetup &)
Definition: IgProfModule.cc:59
tuple result
Definition: query.py:137
std::string atEndJob_
virtual void beginJob()
Definition: IgProfModule.cc:53
virtual void endJob(void)
Definition: IgProfModule.cc:56
edm::EventID id() const
Definition: EventBase.h:56
std::string atEvent_
std::string atBeginJob_
std::string atBeginLumi_
IgProfModule(const edm::ParameterSet &ps)
Definition: IgProfModule.cc:19
Definition: Run.h:33