CMS 3D CMS Logo

SystemTimeKeeper.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCore/Framework
4 // Class : SystemTimeKeeper
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Chris Jones
10 // Created: Mon, 07 Jul 2014 14:37:32 GMT
11 //
12 
13 // system include files
14 #include <algorithm>
15 
16 // user include files
27 #include "SystemTimeKeeper.h"
28 
29 using namespace edm;
30 
31 namespace {
32  bool lessModuleDescription(const ModuleDescription* iLHS, const ModuleDescription* iRHS) {
33  return iLHS->id() < iRHS->id();
34  }
35 } // namespace
36 //
37 // constants, enums and typedefs
38 //
39 
40 //
41 // static data member definitions
42 //
43 
44 //
45 // constructors and destructor
46 //
47 SystemTimeKeeper::SystemTimeKeeper(unsigned int iNumStreams,
48  std::vector<const ModuleDescription*> const& iModules,
49  service::TriggerNamesService const& iNamesService,
50  ProcessContext const* iProcessContext)
51  : m_streamEventTimer(iNumStreams),
52  m_streamPathTiming(iNumStreams),
53  m_modules(iModules),
54  m_processContext(iProcessContext),
55  m_minModuleID(0),
56  m_numberOfEvents(0) {
57  std::sort(m_modules.begin(), m_modules.end(), lessModuleDescription);
58  if (not m_modules.empty()) {
59  m_minModuleID = m_modules.front()->id();
60  unsigned int numModuleSlots = m_modules.back()->id() - m_minModuleID + 1;
61  m_streamModuleTiming.resize(iNumStreams);
62  for (auto& stream : m_streamModuleTiming) {
63  stream.resize(numModuleSlots);
64  }
65  }
66 
67  std::vector<unsigned int> numModulesInPath;
68  std::vector<unsigned int> numModulesInEndPath;
69 
70  const unsigned int numPaths = iNamesService.getTrigPaths().size();
71  const unsigned int numEndPaths = iNamesService.getEndPaths().size();
72  m_pathNames.reserve(numPaths + numEndPaths);
73  std::copy(iNamesService.getTrigPaths().begin(), iNamesService.getTrigPaths().end(), std::back_inserter(m_pathNames));
74  std::copy(iNamesService.getEndPaths().begin(), iNamesService.getEndPaths().end(), std::back_inserter(m_pathNames));
75 
76  numModulesInPath.reserve(numPaths);
77  numModulesInEndPath.reserve(numEndPaths);
78 
79  m_modulesOnPaths.reserve(numPaths + numEndPaths);
80 
81  for (unsigned int i = 0; i < numPaths; ++i) {
82  numModulesInPath.push_back(iNamesService.getTrigPathModules(i).size());
83  m_modulesOnPaths.push_back(iNamesService.getTrigPathModules(i));
84  }
85  for (unsigned int i = 0; i < numEndPaths; ++i) {
86  numModulesInEndPath.push_back(iNamesService.getEndPathModules(i).size());
87  m_modulesOnPaths.push_back(iNamesService.getEndPathModules(i));
88  }
89 
90  m_endPathOffset = numModulesInPath.size();
91 
92  for (auto& stream : m_streamPathTiming) {
93  unsigned int index = 0;
94  stream.resize(numModulesInPath.size() + numModulesInEndPath.size());
95  for (unsigned int numMods : numModulesInPath) {
96  stream[index].m_moduleTiming.resize(numMods);
97  ++index;
98  }
99  for (unsigned int numMods : numModulesInEndPath) {
100  stream[index].m_moduleTiming.resize(numMods);
101  ++index;
102  }
103  }
104 }
105 
106 //
107 // member functions
108 //
110  // The deletion of a module is signaled to all (Sub)Processes, even
111  // though the module exists in only one of them.
112  auto found = std::lower_bound(m_modules.begin(), m_modules.end(), &module, lessModuleDescription);
113  if (*found == &module) {
114  m_modules.erase(found);
115  }
116 }
117 
119  unsigned int offset = 0;
120  if (iPath.isEndPath()) {
122  }
123  assert(iPath.pathID() + offset < m_streamPathTiming[iStream.streamID().value()].size());
124  return m_streamPathTiming[iStream.streamID().value()][iPath.pathID() + offset];
125 }
126 
127 //NOTE: Have to check bounds rather than ProcessContext on the
128 // module callbacks because the ProcessContext could be for a
129 // SubProcess which requested an usncheduled execution of a
130 // module in a parent process. In that case the ProcessContext
131 // is for the SubProcess but the module is is for the parent process.
132 inline bool SystemTimeKeeper::checkBounds(unsigned int id) const {
133  return id >= m_minModuleID and id < m_streamModuleTiming.front().size() + m_minModuleID;
134 }
135 
138  m_streamEventTimer[iID.value()].start();
139 }
140 
142  m_streamEventTimer[iContext.streamID().value()].stop();
143 }
144 
145 void SystemTimeKeeper::startPath(StreamContext const& iStream, PathContext const& iPath) {
146  if (m_processContext == iStream.processContext()) {
147  auto& timing = pathTiming(iStream, iPath);
148  timing.m_timer.start();
149  }
150 }
151 
152 void SystemTimeKeeper::stopPath(StreamContext const& iStream, PathContext const& iPath, HLTPathStatus const& iStatus) {
153  if (m_processContext == iStream.processContext()) {
154  auto& timing = pathTiming(iStream, iPath);
155  timing.m_timer.stop();
156 
157  //mark all modules up to and including the decision module as being visited
158  auto& modsOnPath = timing.m_moduleTiming;
159  for (unsigned int i = 0; i < iStatus.index() + 1; ++i) {
160  ++modsOnPath[i].m_timesVisited;
161  }
162  }
163 }
164 
166  if (checkBounds(iModule.moduleDescription()->id())) {
167  auto& mod = m_streamModuleTiming[iStream.streamID().value()][iModule.moduleDescription()->id() - m_minModuleID];
168  mod.m_timer.start();
169  ++(mod.m_timesRun);
170  }
171 }
173  if (checkBounds(iModule.moduleDescription()->id())) {
174  auto& mod = m_streamModuleTiming[iStream.streamID().value()][iModule.moduleDescription()->id() - m_minModuleID];
175  auto times = mod.m_timer.stop();
176 
177  if (iModule.type() == ParentContext::Type::kPlaceInPath) {
178  auto place = iModule.placeInPathContext();
179 
180  auto& modTiming = pathTiming(iStream, *(place->pathContext())).m_moduleTiming[place->placeInPath()];
181  modTiming.m_realTime += times;
182  }
183  }
184 }
186  if (checkBounds(iModule.moduleDescription()->id())) {
187  auto& mod = m_streamModuleTiming[iStream.streamID().value()][iModule.moduleDescription()->id() - m_minModuleID];
188  auto times = mod.m_timer.stop();
189 
190  if (iModule.type() == ParentContext::Type::kPlaceInPath) {
191  auto place = iModule.placeInPathContext();
192 
193  auto& modTiming = pathTiming(iStream, *(place->pathContext())).m_moduleTiming[place->placeInPath()];
194  modTiming.m_realTime += times;
195  }
196  }
197 }
199  if (checkBounds(iModule.moduleDescription()->id())) {
200  auto& mod = m_streamModuleTiming[iStream.streamID().value()][iModule.moduleDescription()->id() - m_minModuleID];
201  mod.m_timer.start();
202  }
203 }
204 
206 
208 
209 static void fillPathSummary(unsigned int iStartIndex,
210  unsigned int iEndIndex,
211  std::vector<std::string> const& iPathNames,
212  std::vector<std::vector<std::string>> const& iModulesOnPaths,
213  std::vector<std::vector<SystemTimeKeeper::PathTiming>> const& iPathTimings,
214  std::vector<PathTimingSummary>& iSummary) {
215  iSummary.resize(iEndIndex - iStartIndex);
216 
217  for (auto const& stream : iPathTimings) {
218  auto it = iSummary.begin();
219  for (unsigned int index = iStartIndex; index < iEndIndex; ++index, ++it) {
220  auto const& pathTiming = stream[index];
221  it->name = iPathNames[index];
222  it->bitPosition = index - iStartIndex;
223  if (not pathTiming.m_moduleTiming.empty()) {
224  it->timesRun += pathTiming.m_moduleTiming[0].m_timesVisited;
225  }
226  it->realTime += pathTiming.m_timer.realTime();
227  if (it->moduleInPathSummaries.empty()) {
228  it->moduleInPathSummaries.resize(pathTiming.m_moduleTiming.size());
229  }
230  for (unsigned int modIndex = 0; modIndex < pathTiming.m_moduleTiming.size(); ++modIndex) {
231  auto const& modTiming = pathTiming.m_moduleTiming[modIndex];
232  auto& modSummary = it->moduleInPathSummaries[modIndex];
233  if (modSummary.moduleLabel.empty()) {
234  modSummary.moduleLabel = iModulesOnPaths[index][modIndex];
235  }
236  modSummary.timesVisited += modTiming.m_timesVisited;
237  modSummary.realTime += modTiming.m_realTime;
238  }
239  }
240  }
241 }
242 
244  {
245  rep.eventSummary.totalEvents = m_numberOfEvents;
246  double sumEventTime = 0.;
247  for (auto const& stream : m_streamEventTimer) {
248  sumEventTime += stream.realTime();
249  }
250  rep.eventSummary.realTime = m_processingLoopTimer.realTime();
251  rep.eventSummary.cpuTime = m_processingLoopTimer.cpuTime();
252  rep.eventSummary.sumStreamRealTime = sumEventTime;
253  }
254 
255  //Per module summary
256  {
257  auto& summary = rep.workerSummaries;
258  summary.resize(m_modules.size());
259  //Figure out how often a module was visited
260  std::map<std::string, unsigned int> visited;
261  for (auto const& stream : m_streamPathTiming) {
262  unsigned int pathIndex = 0;
263  for (auto const& path : stream) {
264  unsigned int modIndex = 0;
265  for (auto const& mod : path.m_moduleTiming) {
266  visited[m_modulesOnPaths[pathIndex][modIndex]] += mod.m_timesVisited;
267  ++modIndex;
268  }
269  ++pathIndex;
270  }
271  }
272 
273  unsigned int modIndex = 0;
274  for (auto const& mod : m_modules) {
275  auto& outMod = summary[modIndex];
276  outMod.moduleLabel = mod->moduleLabel();
277  outMod.realTime = 0.;
278 
279  auto moduleId = mod->id() - m_minModuleID;
280  for (auto const& stream : m_streamModuleTiming) {
281  auto const& timing = stream[moduleId];
282  outMod.realTime += timing.m_timer.realTime();
283  outMod.timesRun += timing.m_timesRun;
284  }
285  outMod.timesVisited = visited[mod->moduleLabel()];
286  if (0 == outMod.timesVisited) {
287  outMod.timesVisited = outMod.timesRun;
288  }
289  ++modIndex;
290  }
291  }
292  sort_all(rep.workerSummaries);
293 
294  //Per path summary
295  {
299  m_pathNames,
302  rep.endPathSummaries);
303  }
304 }
305 
306 //
307 // const member functions
308 //
309 
310 //
311 // static member functions
312 //
edm::StreamID
Definition: StreamID.h:30
edm::service::TriggerNamesService::getEndPathModules
Strings const & getEndPathModules(std::string const &name) const
Definition: TriggerNamesService.h:87
ModuleCallingContext.h
mps_fire.i
i
Definition: mps_fire.py:428
edm::SystemTimeKeeper::PathTiming
Definition: SystemTimeKeeper.h:81
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
edm::sort_all
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:92
edm::SystemTimeKeeper::removeModuleIfExists
void removeModuleIfExists(ModuleDescription const &module)
Definition: SystemTimeKeeper.cc:109
TriggerNamesService.h
PlaceInPathContext.h
edm::ModuleCallingContext::placeInPathContext
PlaceInPathContext const * placeInPathContext() const
Definition: ModuleCallingContext.h:55
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::SystemTimeKeeper::m_numberOfEvents
std::atomic< unsigned int > m_numberOfEvents
Definition: SystemTimeKeeper.h:113
edm::ProcessContext
Definition: ProcessContext.h:27
mod
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
edm::SystemTimeKeeper::m_pathNames
std::vector< std::string > m_pathNames
Definition: SystemTimeKeeper.h:105
TriggerTimingReport.h
edm::SystemTimeKeeper::PathTiming::m_moduleTiming
std::vector< ModuleInPathTiming > m_moduleTiming
Definition: SystemTimeKeeper.h:83
cms::cuda::stream
uint32_t const T *__restrict__ const uint32_t *__restrict__ int32_t int Histo::index_type cudaStream_t stream
Definition: HistoContainer.h:51
Algorithms.h
edm::ModuleCallingContext::type
Type type() const
Definition: ModuleCallingContext.h:52
cms::cuda::assert
assert(be >=bs)
edm::service::TriggerNamesService::getTrigPathModules
Strings const & getTrigPathModules(std::string const &name) const
Definition: TriggerNamesService.h:78
edm::SystemTimeKeeper::startProcessingLoop
void startProcessingLoop()
Definition: SystemTimeKeeper.cc:205
gpuClustering::moduleId
uint16_t *__restrict__ uint16_t const *__restrict__ uint32_t const *__restrict__ uint32_t *__restrict__ uint32_t const *__restrict__ moduleId
Definition: gpuClusterChargeCut.h:20
edm::StreamID::value
unsigned int value() const
Definition: StreamID.h:43
edm::ParentContext::Type::kPlaceInPath
edm::ModuleCallingContext::moduleDescription
ModuleDescription const * moduleDescription() const
Definition: ModuleCallingContext.h:50
edm::SystemTimeKeeper::stopProcessingLoop
void stopProcessingLoop()
Definition: SystemTimeKeeper.cc:207
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::SystemTimeKeeper::startModuleEvent
void startModuleEvent(StreamContext const &, ModuleCallingContext const &)
Definition: SystemTimeKeeper.cc:165
HLTPathStatus.h
edm::ModuleDescription
Definition: ModuleDescription.h:21
edm::SystemTimeKeeper::m_streamModuleTiming
std::vector< std::vector< ModuleTiming > > m_streamModuleTiming
Definition: SystemTimeKeeper.h:102
ModuleDescription.h
edm::PathContext::pathID
unsigned int pathID() const
Definition: PathContext.h:32
edm::SystemTimeKeeper::startEvent
void startEvent(StreamID)
Definition: SystemTimeKeeper.cc:136
edm::StreamContext
Definition: StreamContext.h:31
edm::TriggerTimingReport
Definition: TriggerTimingReport.h:52
edm::SystemTimeKeeper::m_processContext
ProcessContext const * m_processContext
Definition: SystemTimeKeeper.h:109
edm::CPUTimer::start
void start()
Definition: CPUTimer.cc:68
class-composition.visited
visited
Definition: class-composition.py:83
edm::PathContext::isEndPath
bool isEndPath() const
Definition: PathContext.h:35
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
edm::StreamContext::streamID
StreamID const & streamID() const
Definition: StreamContext.h:54
edm::PathContext
Definition: PathContext.h:24
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
edm::SystemTimeKeeper::fillTriggerTimingReport
void fillTriggerTimingReport(TriggerTimingReport &rep) const
Definition: SystemTimeKeeper.cc:243
edm::StreamContext::processContext
ProcessContext const * processContext() const
Definition: StreamContext.h:63
edm::HLTPathStatus
Definition: HLTPathStatus.h:33
edm::SystemTimeKeeper::m_modules
std::vector< const ModuleDescription * > m_modules
Definition: SystemTimeKeeper.h:104
edm::SystemTimeKeeper::m_processingLoopTimer
CPUTimer m_processingLoopTimer
Definition: SystemTimeKeeper.h:108
edm::SystemTimeKeeper::SystemTimeKeeper
SystemTimeKeeper(unsigned int iNumStreams, std::vector< const ModuleDescription * > const &iModules, service::TriggerNamesService const &iNameService, ProcessContext const *iProcessContext)
Definition: SystemTimeKeeper.cc:47
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
cuy.rep
rep
Definition: cuy.py:1189
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::SystemTimeKeeper::stopPath
void stopPath(StreamContext const &, PathContext const &, HLTPathStatus const &)
Definition: SystemTimeKeeper.cc:152
edm::HLTPathStatus::index
unsigned int index() const
Definition: HLTPathStatus.h:52
edm::CPUTimer::stop
Times stop()
Definition: CPUTimer.cc:87
edm::SystemTimeKeeper::stopModuleEvent
void stopModuleEvent(StreamContext const &, ModuleCallingContext const &)
Definition: SystemTimeKeeper.cc:172
edm::fillPathSummary
static void fillPathSummary(Path const &path, PathSummary &sum)
Definition: StreamSchedule.cc:847
PathContext.h
callgraph.module
module
Definition: callgraph.py:61
edm::service::TriggerNamesService
Definition: TriggerNamesService.h:42
ecalMatacq_cfi.timing
timing
Definition: ecalMatacq_cfi.py:26
edm::SystemTimeKeeper::startPath
void startPath(StreamContext const &, PathContext const &)
Definition: SystemTimeKeeper.cc:145
edm::SystemTimeKeeper::m_streamEventTimer
std::vector< WallclockTimer > m_streamEventTimer
Definition: SystemTimeKeeper.h:98
edm::service::TriggerNamesService::getTrigPaths
Strings const & getTrigPaths() const
Definition: TriggerNamesService.h:55
edm::service::TriggerNamesService::getEndPaths
Strings const & getEndPaths() const
Definition: TriggerNamesService.h:74
edm::SystemTimeKeeper::pathTiming
PathTiming & pathTiming(StreamContext const &, PathContext const &)
Definition: SystemTimeKeeper.cc:118
edm::CPUTimer::cpuTime
double cpuTime() const
Definition: CPUTimer.cc:146
edm::SystemTimeKeeper::pauseModuleEvent
void pauseModuleEvent(StreamContext const &, ModuleCallingContext const &)
Definition: SystemTimeKeeper.cc:185
SystemTimeKeeper.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
edm::SystemTimeKeeper::checkBounds
bool checkBounds(unsigned int id) const
Definition: SystemTimeKeeper.cc:132
edm::SystemTimeKeeper::m_modulesOnPaths
std::vector< std::vector< std::string > > m_modulesOnPaths
Definition: SystemTimeKeeper.h:106
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
edm::SystemTimeKeeper::m_streamPathTiming
std::vector< std::vector< PathTiming > > m_streamPathTiming
Definition: SystemTimeKeeper.h:100
edm::CPUTimer::realTime
double realTime() const
Definition: CPUTimer.cc:139
StreamContext.h
edm::SystemTimeKeeper::m_endPathOffset
unsigned int m_endPathOffset
Definition: SystemTimeKeeper.h:112
edm::SystemTimeKeeper::stopEvent
void stopEvent(StreamContext const &)
Definition: SystemTimeKeeper.cc:141
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
StreamID.h
edm::SystemTimeKeeper::restartModuleEvent
void restartModuleEvent(StreamContext const &, ModuleCallingContext const &)
Definition: SystemTimeKeeper.cc:198
edm::SystemTimeKeeper::m_minModuleID
unsigned int m_minModuleID
Definition: SystemTimeKeeper.h:111
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
edm::ModuleDescription::id
unsigned int id() const
Definition: ModuleDescription.h:46
edm::ModuleCallingContext
Definition: ModuleCallingContext.h:29