CMS 3D CMS Logo

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  : dump_(nullptr),
27  mineventrecord_(1),
28  prescale_(1),
29  nrecord_(0),
30  nevent_(0),
31  nrun_(0),
32  nlumi_(0),
33  nfileopened_(0),
34  nfileclosed_(0) {
35  // Removing the __extension__ gives a warning which
36  // is acknowledged as a language problem in the C++ Standard Core
37  // Language Defect Report
38  //
39  // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#195
40  //
41  // since the suggested decision seems to be that the syntax should
42  // actually be "Conditionally-Supported Behavior" in some
43  // future C++ standard I simply silence the warning.
44  if (void *sym = dlsym(nullptr, "igprof_dump_now")) {
45  dump_ = __extension__(void (*)(const char *)) sym;
46  } else
47  edm::LogWarning("IgProfModule") << "IgProfModule requested but application is not"
48  << " currently being profiled with igprof\n";
49 
50  // Get the configuration
51  prescale_ = ps.getUntrackedParameter<int>("reportEventInterval", prescale_);
52  mineventrecord_ = ps.getUntrackedParameter<int>("reportFirstEvent", mineventrecord_);
53 
54  atPostBeginJob_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostBeginJob", atPostBeginJob_);
55  atPostBeginRun_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostBeginRun", atPostBeginRun_);
56  atPostBeginLumi_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostBeginLumi", atPostBeginLumi_);
57 
58  atPreEvent_ = ps.getUntrackedParameter<std::string>("reportToFileAtPreEvent", atPreEvent_);
59  atPostEvent_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostEvent", atPostEvent_);
60 
61  atPostEndLumi_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostEndLumi", atPostEndLumi_);
62  atPostEndRun_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostEndRun", atPostEndRun_);
63  atPostEndJob_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostEndJob", atPostEndJob_);
64 
65  atPostOpenFile_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostOpenFile", atPostOpenFile_);
66  atPostCloseFile_ = ps.getUntrackedParameter<std::string>("reportToFileAtPostCloseFile", atPostCloseFile_);
67 
68  // Register for the framework signals
72 
73  iRegistry.watchPreEvent(this, &IgProfService::preEvent);
74  iRegistry.watchPostEvent(this, &IgProfService::postEvent);
75 
79 
82 }
83 
85 
87  nrun_ = gc.luminosityBlockID().run();
89 }
90 
94 }
95 
96 void IgProfService::preEvent(StreamContext const &iStream) {
97  ++nrecord_; // count before events
98  nevent_ = iStream.eventID().event();
99  if ((prescale_ > 0) && (nrecord_ >= mineventrecord_) && (((nrecord_ - mineventrecord_) % prescale_) == 0))
101 }
102 
104  nevent_ = iStream.eventID().event();
105  if ((prescale_ > 0) && (nrecord_ >= mineventrecord_) && (((nrecord_ - mineventrecord_) % prescale_) == 0))
107 }
108 
110 
112 
114 
116  ++nfileopened_;
118 }
119 
121  ++nfileclosed_;
123 }
124 
126  if (!dump_ || format.empty())
127  return;
128 
129  std::string final(format);
130  final = replace(final, "%I", nrecord_);
131  final = replaceU64(final, "%E", nevent_);
132  final = replaceU64(final, "%R", nrun_);
133  final = replaceU64(final, "%L", nlumi_);
134  final = replace(final, "%F", nfileopened_);
135  final = replace(final, "%C", nfileclosed_);
136  dump_(final.c_str());
137 }
138 
140  size_t pos = 0;
141  size_t patlen = strlen(pat);
142  std::string result = s;
143  while ((pos = result.find(pat, pos)) != std::string::npos) {
144  char buf[64];
145  int n = sprintf(buf, "%d", val);
146  result.replace(pos, patlen, buf);
147  pos = pos - patlen + n;
148  }
149 
150  return result;
151 }
152 
153 std::string IgProfService::replaceU64(const std::string &s, const char *pat, unsigned long long val) {
154  size_t pos = 0;
155  size_t patlen = strlen(pat);
156  std::string result = s;
157  while ((pos = result.find(pat, pos)) != std::string::npos) {
158  char buf[64];
159  int n = sprintf(buf, "%llu", val);
160  result.replace(pos, patlen, buf);
161  pos = pos - patlen + n;
162  }
163 
164  return result;
165 }
166 
edm::GlobalContext::luminosityBlockID
LuminosityBlockID const & luminosityBlockID() const
Definition: GlobalContext.h:60
edm::service::IgProfService::mineventrecord_
int mineventrecord_
Definition: IgProfService.h:66
edm::service::IgProfService::atPostBeginRun_
std::string atPostBeginRun_
Definition: IgProfService.h:53
edm::service::IgProfService::atPostCloseFile_
std::string atPostCloseFile_
Definition: IgProfService.h:64
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::ActivityRegistry::watchPostGlobalEndRun
void watchPostGlobalEndRun(PostGlobalEndRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:334
edm::service::IgProfService::postBeginRun
void postBeginRun(GlobalContext const &gc)
Definition: IgProfService.cc:86
LuminosityBlock.h
pos
Definition: PixelAliasList.h:18
edm::ActivityRegistry::watchPostGlobalEndLumi
void watchPostGlobalEndLumi(PostGlobalEndLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:410
edm::service::IgProfService::preEvent
void preEvent(StreamContext const &sc)
Definition: IgProfService.cc:96
DEFINE_FWK_SERVICE
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:96
edm::service::IgProfService::nevent_
edm::EventNumber_t nevent_
Definition: IgProfService.h:69
edm::ActivityRegistry::watchPostOpenFile
void watchPostOpenFile(PostOpenFile::slot_type const &iSlot)
Definition: ActivityRegistry.h:227
edm::service::IgProfService::replace
static std::string replace(const std::string &s, const char *pat, int val)
Definition: IgProfService.cc:139
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::service::IgProfService::replaceU64
static std::string replaceU64(const std::string &s, const char *pat, unsigned long long val)
Definition: IgProfService.cc:153
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::service::IgProfService::atPostEndJob_
std::string atPostEndJob_
Definition: IgProfService.h:61
edm::service::IgProfService::atPostOpenFile_
std::string atPostOpenFile_
Definition: IgProfService.h:63
edm::service::IgProfService::prescale_
int prescale_
Definition: IgProfService.h:67
edm::ActivityRegistry::watchPostCloseFile
void watchPostCloseFile(PostCloseFile::slot_type const &iSlot)
Definition: ActivityRegistry.h:241
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::ActivityRegistry::watchPostEndJob
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
Definition: ActivityRegistry.h:170
edm::StreamContext
Definition: StreamContext.h:31
edm::service::IgProfService::postEndLumi
void postEndLumi(GlobalContext const &gc)
Definition: IgProfService.cc:109
dqm-mbProfile.format
format
Definition: dqm-mbProfile.py:16
edm::service::IgProfService::nrun_
edm::RunNumber_t nrun_
Definition: IgProfService.h:70
edm::service::IgProfService::atPostBeginJob_
std::string atPostBeginJob_
Definition: IgProfService.h:52
edm::ActivityRegistry::watchPreEvent
void watchPreEvent(PreEvent::slot_type const &iSlot)
Definition: ActivityRegistry.h:458
edm::ActivityRegistry
Definition: ActivityRegistry.h:134
Run.h
edm::ActivityRegistry::watchPostBeginJob
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
Definition: ActivityRegistry.h:158
IgProfService.h
ServiceMaker.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::GlobalContext
Definition: GlobalContext.h:29
edm::service::IgProfService::atPostEndLumi_
std::string atPostEndLumi_
Definition: IgProfService.h:59
edm::ActivityRegistry::watchPostEvent
void watchPostEvent(PostEvent::slot_type const &iSlot)
Definition: ActivityRegistry.h:464
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
edm::service::IgProfService::atPostEvent_
std::string atPostEvent_
Definition: IgProfService.h:57
edm::service::IgProfService::atPostEndRun_
std::string atPostEndRun_
Definition: IgProfService.h:60
edm::service::IgProfService::makeDump
void makeDump(const std::string &format)
Definition: IgProfService.cc:125
edm::service::IgProfService::nlumi_
edm::LuminosityBlockNumber_t nlumi_
Definition: IgProfService.h:71
edm::service::IgProfService::postEndJob
void postEndJob()
Definition: IgProfService.cc:113
edm::service::IgProfService::nfileopened_
int nfileopened_
Definition: IgProfService.h:72
edm::service::IgProfService
Definition: IgProfService.h:20
edm::EventID::event
EventNumber_t event() const
Definition: EventID.h:40
edm::service::IgProfService::postOpenFile
void postOpenFile(std::string const &, bool)
Definition: IgProfService.cc:115
edm::ActivityRegistry::watchPostGlobalBeginLumi
void watchPostGlobalBeginLumi(PostGlobalBeginLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:398
edm::LuminosityBlockID::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: LuminosityBlockID.h:42
pat
Definition: HeavyIon.h:7
edm::service
Definition: TFileService.h:95
edm::service::IgProfService::postCloseFile
void postCloseFile(std::string const &, bool)
Definition: IgProfService.cc:120
edm::service::IgProfService::postEvent
void postEvent(StreamContext const &sc)
Definition: IgProfService.cc:103
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
FileBlock.h
edm::service::IgProfService::atPostBeginLumi_
std::string atPostBeginLumi_
Definition: IgProfService.h:54
edm::service::IgProfService::postBeginJob
void postBeginJob()
Definition: IgProfService.cc:84
heppy_batch.val
val
Definition: heppy_batch.py:351
edm::service::IgProfService::IgProfService
IgProfService(const ParameterSet &, ActivityRegistry &)
Definition: IgProfService.cc:25
edm::service::IgProfService::dump_
void(* dump_)(const char *)
Definition: IgProfService.h:50
edm::ActivityRegistry::watchPostGlobalBeginRun
void watchPostGlobalBeginRun(PostGlobalBeginRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:322
edm::service::IgProfService::atPreEvent_
std::string atPreEvent_
Definition: IgProfService.h:56
edm::service::IgProfService::postEndRun
void postEndRun(GlobalContext const &gc)
Definition: IgProfService.cc:111
format
edm::LuminosityBlockID::run
RunNumber_t run() const
Definition: LuminosityBlockID.h:41
edm::service::IgProfService::nrecord_
int nrecord_
Definition: IgProfService.h:68
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
edm::service::IgProfService::postBeginLumi
void postBeginLumi(GlobalContext const &gc)
Definition: IgProfService.cc:91
edm::StreamContext::eventID
EventID const & eventID() const
Definition: StreamContext.h:59
edm::service::IgProfService::nfileclosed_
int nfileclosed_
Definition: IgProfService.h:73