test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IgProfService.cc
Go to the documentation of this file.
1 
2 //
3 // Description: FWK service to implement hook for igprof memory profile
4 // dump functionality
5 //
6 // Peter Elmer, Princeton University 18 Nov, 2008
7 //
8 
18 #include <string>
19 #include <dlfcn.h>
20 #include <cstdio>
21 #include <cstring>
22 
23 using namespace edm::service;
24 
26  ActivityRegistry&iRegistry)
27  : dump_(0),
28  mineventrecord_(1),
29  prescale_(1),
30  nrecord_(0),
31  nevent_(0),
32  nrun_(0),
33  nlumi_(0),
34  nfileopened_(0),
35  nfileclosed_(0) {
36 
37 
38  // Removing the __extension__ gives a warning which
39  // is acknowledged as a language problem in the C++ Standard Core
40  // Language Defect Report
41  //
42  // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#195
43  //
44  // since the suggested decision seems to be that the syntax should
45  // actually be "Conditionally-Supported Behavior" in some
46  // future C++ standard I simply silence the warning.
47  if (void *sym = dlsym(0, "igprof_dump_now")) {
48  dump_ = __extension__ (void(*)(const char *)) sym;
49  } else
50  edm::LogWarning("IgProfModule")
51  << "IgProfModule requested but application is not"
52  << " currently being profiled with igprof\n";
53 
54  // Get the configuration
55  prescale_
56  = ps.getUntrackedParameter<int>("reportEventInterval", prescale_);
58  = ps.getUntrackedParameter<int>("reportFirstEvent", mineventrecord_);
59 
61  = ps.getUntrackedParameter<std::string>("reportToFileAtPostBeginJob", atPostBeginJob_);
63  = ps.getUntrackedParameter<std::string>("reportToFileAtPostBeginRun", atPostBeginRun_);
65  = ps.getUntrackedParameter<std::string>("reportToFileAtPostBeginLumi", atPostBeginLumi_);
66 
68  = ps.getUntrackedParameter<std::string>("reportToFileAtPreEvent", atPreEvent_);
70  = ps.getUntrackedParameter<std::string>("reportToFileAtPostEvent", atPostEvent_);
71 
73  = ps.getUntrackedParameter<std::string>("reportToFileAtPostEndLumi", atPostEndLumi_);
75  = ps.getUntrackedParameter<std::string>("reportToFileAtPostEndRun", atPostEndRun_);
77  = ps.getUntrackedParameter<std::string>("reportToFileAtPostEndJob", atPostEndJob_);
78 
80  = ps.getUntrackedParameter<std::string>("reportToFileAtPostOpenFile", atPostOpenFile_);
82  = ps.getUntrackedParameter<std::string>("reportToFileAtPostCloseFile", atPostCloseFile_);
83 
84 
85  // Register for the framework signals
89 
92 
96 
99 
100 }
101 
104 }
105 
108 }
109 
111  const edm::EventSetup &) {
113 }
114 
116  const edm::Timestamp & iTime) {
117  ++nrecord_; // count before events
118  nevent_ = id.event();
119  if ((prescale_ > 0) &&
120  (nrecord_ >= mineventrecord_) &&
122 }
123 
125  nevent_ = e.id().event();
126  if ((prescale_ > 0) &&
127  (nrecord_ >= mineventrecord_) &&
129 }
130 
132  const edm::EventSetup &) {
134 }
135 
138 }
139 
142 }
143 
145  ++nfileopened_;
147 }
148 
150  ++nfileclosed_;
152 }
153 
155  if (! dump_ || format.empty())
156  return;
157 
158  std::string final(format);
159  final = replace(final, "%I", nrecord_);
160  final = replace(final, "%E", nevent_);
161  final = replace(final, "%R", nrun_);
162  final = replace(final, "%L", nlumi_);
163  final = replace(final, "%F", nfileopened_);
164  final = replace(final, "%C", nfileclosed_);
165  dump_(final.c_str());
166 }
167 
169 IgProfService::replace(const std::string &s, const char *pat, int val) {
170  size_t pos = 0;
171  size_t patlen = strlen(pat);
172  std::string result = s;
173  while ((pos = result.find(pat, pos)) != std::string::npos)
174  {
175  char buf[64];
176  int n = sprintf(buf, "%d", val);
177  result.replace(pos, patlen, buf);
178  pos = pos - patlen + n;
179  }
180 
181  return result;
182 }
183 
185 
void watchPostBeginRun(PostBeginRun::slot_type const &iSlot)
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
RunNumber_t run() const
Definition: RunBase.h:42
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void postEvent(Event const &ev, EventSetup const &es)
void postCloseFile(std::string const &, bool)
void watchPreProcessEvent(PreProcessEvent::slot_type const &iSlot)
void preEvent(EventID const &id, Timestamp const &ts)
void watchPostEndLumi(PostEndLumi::slot_type const &iSlot)
IgProfService(const ParameterSet &, ActivityRegistry &)
string format
Some error handling for the usage.
void postBeginRun(Run const &run, EventSetup const &es)
void postBeginLumi(LuminosityBlock const &run, EventSetup const &es)
LuminosityBlockNumber_t luminosityBlock() const
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
void watchPostCloseFile(PostCloseFile::slot_type const &iSlot)
void postOpenFile(std::string const &, bool)
tuple result
Definition: query.py:137
void postEndRun(Run const &run, EventSetup const &es)
void watchPostBeginLumi(PostBeginLumi::slot_type const &iSlot)
void(* dump_)(const char *)
Definition: IgProfService.h:52
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:113
void watchPostOpenFile(PostOpenFile::slot_type const &iSlot)
edm::EventID id() const
Definition: EventBase.h:56
void postEndLumi(LuminosityBlock const &run, EventSetup const &es)
void watchPostEndRun(PostEndRun::slot_type const &iSlot)
void makeDump(const std::string &format)
static std::string replace(const std::string &s, const char *pat, int val)
Definition: Run.h:41
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal