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 // constants, enums and typedefs
32 //
33 
34 //
35 // static data member definitions
36 //
37 
38 //
39 // constructors and destructor
40 //
41 SystemTimeKeeper::SystemTimeKeeper(unsigned int iNumStreams,
42  std::vector<const ModuleDescription*> const& iModules,
43  service::TriggerNamesService const& iNamesService,
44  ProcessContext const* iProcessContext)
45  : m_streamEventTimer(iNumStreams),
46  m_streamPathTiming(iNumStreams),
47  m_modules(iModules),
48  m_processContext(iProcessContext),
49  m_minModuleID(0),
50  m_numberOfEvents(0) {
51  std::sort(
52  m_modules.begin(), m_modules.end(), [](const ModuleDescription* iLHS, const ModuleDescription* iRHS) -> bool {
53  return iLHS->id() < iRHS->id();
54  });
55  if (not m_modules.empty()) {
56  m_minModuleID = m_modules.front()->id();
57  unsigned int numModuleSlots = m_modules.back()->id() - m_minModuleID + 1;
58  m_streamModuleTiming.resize(iNumStreams);
59  for (auto& stream : m_streamModuleTiming) {
60  stream.resize(numModuleSlots);
61  }
62  }
63 
64  std::vector<unsigned int> numModulesInPath;
65  std::vector<unsigned int> numModulesInEndPath;
66 
67  const unsigned int numPaths = iNamesService.getTrigPaths().size();
68  const unsigned int numEndPaths = iNamesService.getEndPaths().size();
69  m_pathNames.reserve(numPaths + numEndPaths);
70  std::copy(iNamesService.getTrigPaths().begin(), iNamesService.getTrigPaths().end(), std::back_inserter(m_pathNames));
71  std::copy(iNamesService.getEndPaths().begin(), iNamesService.getEndPaths().end(), std::back_inserter(m_pathNames));
72 
73  numModulesInPath.reserve(numPaths);
74  numModulesInEndPath.reserve(numEndPaths);
75 
76  m_modulesOnPaths.reserve(numPaths + numEndPaths);
77 
78  for (unsigned int i = 0; i < numPaths; ++i) {
79  numModulesInPath.push_back(iNamesService.getTrigPathModules(i).size());
80  m_modulesOnPaths.push_back(iNamesService.getTrigPathModules(i));
81  }
82  for (unsigned int i = 0; i < numEndPaths; ++i) {
83  numModulesInEndPath.push_back(iNamesService.getEndPathModules(i).size());
84  m_modulesOnPaths.push_back(iNamesService.getEndPathModules(i));
85  }
86 
87  m_endPathOffset = numModulesInPath.size();
88 
89  for (auto& stream : m_streamPathTiming) {
90  unsigned int index = 0;
91  stream.resize(numModulesInPath.size() + numModulesInEndPath.size());
92  for (unsigned int numMods : numModulesInPath) {
93  stream[index].m_moduleTiming.resize(numMods);
94  ++index;
95  }
96  for (unsigned int numMods : numModulesInEndPath) {
97  stream[index].m_moduleTiming.resize(numMods);
98  ++index;
99  }
100  }
101 }
102 
103 //
104 // member functions
105 //
107  unsigned int offset = 0;
108  if (iPath.isEndPath()) {
110  }
111  assert(iPath.pathID() + offset < m_streamPathTiming[iStream.streamID().value()].size());
112  return m_streamPathTiming[iStream.streamID().value()][iPath.pathID() + offset];
113 }
114 
115 //NOTE: Have to check bounds rather than ProcessContext on the
116 // module callbacks because the ProcessContext could be for a
117 // SubProcess which requested an usncheduled execution of a
118 // module in a parent process. In that case the ProcessContext
119 // is for the SubProcess but the module is is for the parent process.
120 inline bool SystemTimeKeeper::checkBounds(unsigned int id) const {
121  return id >= m_minModuleID and id < m_streamModuleTiming.front().size() + m_minModuleID;
122 }
123 
126  m_streamEventTimer[iID.value()].start();
127 }
128 
130  m_streamEventTimer[iContext.streamID().value()].stop();
131 }
132 
133 void SystemTimeKeeper::startPath(StreamContext const& iStream, PathContext const& iPath) {
134  if (m_processContext == iStream.processContext()) {
135  auto& timing = pathTiming(iStream, iPath);
136  timing.m_timer.start();
137  }
138 }
139 
140 void SystemTimeKeeper::stopPath(StreamContext const& iStream, PathContext const& iPath, HLTPathStatus const& iStatus) {
141  if (m_processContext == iStream.processContext()) {
142  auto& timing = pathTiming(iStream, iPath);
143  timing.m_timer.stop();
144 
145  //mark all modules up to and including the decision module as being visited
146  auto& modsOnPath = timing.m_moduleTiming;
147  for (unsigned int i = 0; i < iStatus.index() + 1; ++i) {
148  ++modsOnPath[i].m_timesVisited;
149  }
150  }
151 }
152 
154  if (checkBounds(iModule.moduleDescription()->id())) {
155  auto& mod = m_streamModuleTiming[iStream.streamID().value()][iModule.moduleDescription()->id() - m_minModuleID];
156  mod.m_timer.start();
157  ++(mod.m_timesRun);
158  }
159 }
161  if (checkBounds(iModule.moduleDescription()->id())) {
162  auto& mod = m_streamModuleTiming[iStream.streamID().value()][iModule.moduleDescription()->id() - m_minModuleID];
163  auto times = mod.m_timer.stop();
164 
165  if (iModule.type() == ParentContext::Type::kPlaceInPath) {
166  auto place = iModule.placeInPathContext();
167 
168  auto& modTiming = pathTiming(iStream, *(place->pathContext())).m_moduleTiming[place->placeInPath()];
169  modTiming.m_realTime += times;
170  }
171  }
172 }
174  if (checkBounds(iModule.moduleDescription()->id())) {
175  auto& mod = m_streamModuleTiming[iStream.streamID().value()][iModule.moduleDescription()->id() - m_minModuleID];
176  auto times = mod.m_timer.stop();
177 
178  if (iModule.type() == ParentContext::Type::kPlaceInPath) {
179  auto place = iModule.placeInPathContext();
180 
181  auto& modTiming = pathTiming(iStream, *(place->pathContext())).m_moduleTiming[place->placeInPath()];
182  modTiming.m_realTime += times;
183  }
184  }
185 }
187  if (checkBounds(iModule.moduleDescription()->id())) {
188  auto& mod = m_streamModuleTiming[iStream.streamID().value()][iModule.moduleDescription()->id() - m_minModuleID];
189  mod.m_timer.start();
190  }
191 }
192 
194 
196 
197 static void fillPathSummary(unsigned int iStartIndex,
198  unsigned int iEndIndex,
199  std::vector<std::string> const& iPathNames,
200  std::vector<std::vector<std::string>> const& iModulesOnPaths,
201  std::vector<std::vector<SystemTimeKeeper::PathTiming>> const& iPathTimings,
202  std::vector<PathTimingSummary>& iSummary) {
203  iSummary.resize(iEndIndex - iStartIndex);
204 
205  for (auto const& stream : iPathTimings) {
206  auto it = iSummary.begin();
207  for (unsigned int index = iStartIndex; index < iEndIndex; ++index, ++it) {
208  auto const& pathTiming = stream[index];
209  it->name = iPathNames[index];
210  it->bitPosition = index - iStartIndex;
211  if (not pathTiming.m_moduleTiming.empty()) {
212  it->timesRun += pathTiming.m_moduleTiming[0].m_timesVisited;
213  }
214  it->realTime += pathTiming.m_timer.realTime();
215  if (it->moduleInPathSummaries.empty()) {
216  it->moduleInPathSummaries.resize(pathTiming.m_moduleTiming.size());
217  }
218  for (unsigned int modIndex = 0; modIndex < pathTiming.m_moduleTiming.size(); ++modIndex) {
219  auto const& modTiming = pathTiming.m_moduleTiming[modIndex];
220  auto& modSummary = it->moduleInPathSummaries[modIndex];
221  if (modSummary.moduleLabel.empty()) {
222  modSummary.moduleLabel = iModulesOnPaths[index][modIndex];
223  }
224  modSummary.timesVisited += modTiming.m_timesVisited;
225  modSummary.realTime += modTiming.m_realTime;
226  }
227  }
228  }
229 }
230 
232  {
233  rep.eventSummary.totalEvents = m_numberOfEvents;
234  double sumEventTime = 0.;
235  for (auto const& stream : m_streamEventTimer) {
236  sumEventTime += stream.realTime();
237  }
238  rep.eventSummary.realTime = m_processingLoopTimer.realTime();
239  rep.eventSummary.cpuTime = m_processingLoopTimer.cpuTime();
240  rep.eventSummary.sumStreamRealTime = sumEventTime;
241  }
242 
243  //Per module summary
244  {
245  auto& summary = rep.workerSummaries;
246  summary.resize(m_modules.size());
247  //Figure out how often a module was visited
248  std::map<std::string, unsigned int> visited;
249  for (auto const& stream : m_streamPathTiming) {
250  unsigned int pathIndex = 0;
251  for (auto const& path : stream) {
252  unsigned int modIndex = 0;
253  for (auto const& mod : path.m_moduleTiming) {
254  visited[m_modulesOnPaths[pathIndex][modIndex]] += mod.m_timesVisited;
255  ++modIndex;
256  }
257  ++pathIndex;
258  }
259  }
260 
261  unsigned int modIndex = 0;
262  for (auto const& mod : m_modules) {
263  auto& outMod = summary[modIndex];
264  outMod.moduleLabel = mod->moduleLabel();
265  outMod.realTime = 0.;
266 
267  auto moduleId = mod->id() - m_minModuleID;
268  for (auto const& stream : m_streamModuleTiming) {
269  auto const& timing = stream[moduleId];
270  outMod.realTime += timing.m_timer.realTime();
271  outMod.timesRun += timing.m_timesRun;
272  }
273  outMod.timesVisited = visited[mod->moduleLabel()];
274  if (0 == outMod.timesVisited) {
275  outMod.timesVisited = outMod.timesRun;
276  }
277  ++modIndex;
278  }
279  }
280  sort_all(rep.workerSummaries);
281 
282  //Per path summary
283  {
287  m_pathNames,
290  rep.endPathSummaries);
291  }
292 }
293 
294 //
295 // const member functions
296 //
297 
298 //
299 // static member functions
300 //
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:79
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
edm::sort_all
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:92
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:111
edm::ProcessContext
Definition: ProcessContext.h:27
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
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:103
TriggerTimingReport.h
edm::SystemTimeKeeper::PathTiming::m_moduleTiming
std::vector< ModuleInPathTiming > m_moduleTiming
Definition: SystemTimeKeeper.h:81
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:193
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:195
edm::SystemTimeKeeper::startModuleEvent
void startModuleEvent(StreamContext const &, ModuleCallingContext const &)
Definition: SystemTimeKeeper.cc:153
HLTPathStatus.h
edm::ModuleDescription
Definition: ModuleDescription.h:21
edm::SystemTimeKeeper::m_streamModuleTiming
std::vector< std::vector< ModuleTiming > > m_streamModuleTiming
Definition: SystemTimeKeeper.h:100
ModuleDescription.h
edm::PathContext::pathID
unsigned int pathID() const
Definition: PathContext.h:32
edm::SystemTimeKeeper::startEvent
void startEvent(StreamID)
Definition: SystemTimeKeeper.cc:124
edm::StreamContext
Definition: StreamContext.h:31
edm::TriggerTimingReport
Definition: TriggerTimingReport.h:52
edm::SystemTimeKeeper::m_processContext
ProcessContext const * m_processContext
Definition: SystemTimeKeeper.h:107
edm::CPUTimer::start
void start()
Definition: CPUTimer.cc:68
class-composition.visited
visited
Definition: class-composition.py:74
edm::PathContext::isEndPath
bool isEndPath() const
Definition: PathContext.h:35
edm::StreamContext::streamID
StreamID const & streamID() const
Definition: StreamContext.h:54
edm::PathContext
Definition: PathContext.h:24
edm::SystemTimeKeeper::fillTriggerTimingReport
void fillTriggerTimingReport(TriggerTimingReport &rep) const
Definition: SystemTimeKeeper.cc:231
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:102
edm::SystemTimeKeeper::m_processingLoopTimer
CPUTimer m_processingLoopTimer
Definition: SystemTimeKeeper.h:106
edm::SystemTimeKeeper::SystemTimeKeeper
SystemTimeKeeper(unsigned int iNumStreams, std::vector< const ModuleDescription * > const &iModules, service::TriggerNamesService const &iNameService, ProcessContext const *iProcessContext)
Definition: SystemTimeKeeper.cc:41
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
cuy.rep
rep
Definition: cuy.py:1190
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::SystemTimeKeeper::stopPath
void stopPath(StreamContext const &, PathContext const &, HLTPathStatus const &)
Definition: SystemTimeKeeper.cc:140
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:160
edm::fillPathSummary
static void fillPathSummary(Path const &path, PathSummary &sum)
Definition: StreamSchedule.cc:842
PathContext.h
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:133
edm::SystemTimeKeeper::m_streamEventTimer
std::vector< WallclockTimer > m_streamEventTimer
Definition: SystemTimeKeeper.h:96
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:106
edm::CPUTimer::cpuTime
double cpuTime() const
Definition: CPUTimer.cc:146
edm::SystemTimeKeeper::pauseModuleEvent
void pauseModuleEvent(StreamContext const &, ModuleCallingContext const &)
Definition: SystemTimeKeeper.cc:173
SystemTimeKeeper.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
edm::SystemTimeKeeper::checkBounds
bool checkBounds(unsigned int id) const
Definition: SystemTimeKeeper.cc:120
edm::SystemTimeKeeper::m_modulesOnPaths
std::vector< std::vector< std::string > > m_modulesOnPaths
Definition: SystemTimeKeeper.h:104
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:98
edm::CPUTimer::realTime
double realTime() const
Definition: CPUTimer.cc:139
StreamContext.h
edm::SystemTimeKeeper::m_endPathOffset
unsigned int m_endPathOffset
Definition: SystemTimeKeeper.h:110
edm::SystemTimeKeeper::stopEvent
void stopEvent(StreamContext const &)
Definition: SystemTimeKeeper.cc:129
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:186
edm::SystemTimeKeeper::m_minModuleID
unsigned int m_minModuleID
Definition: SystemTimeKeeper.h:109
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