CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 m_streamEventTimer(iNumStreams),
45 m_streamPathTiming(iNumStreams),
46 m_modules(iModules),
47 m_minModuleID(0),
48 m_numberOfEvents(0)
49 {
50  std::sort(m_modules.begin(),m_modules.end(),
51  [] (const ModuleDescription* iLHS,
52  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 
65  std::vector<unsigned int> numModulesInPath;
66  std::vector<unsigned int> numModulesInEndPath;
67 
68  const unsigned int numPaths = iNamesService.getTrigPaths().size();
69  const unsigned int numEndPaths = iNamesService.getEndPaths().size();
70  m_pathNames.reserve(numPaths+numEndPaths);
71  std::copy(iNamesService.getTrigPaths().begin(),
72  iNamesService.getTrigPaths().end(),
73  std::back_inserter(m_pathNames));
74  std::copy(iNamesService.getEndPaths().begin(),
75  iNamesService.getEndPaths().end(),
76  std::back_inserter(m_pathNames));
77 
78  numModulesInPath.reserve(numPaths);
79  numModulesInEndPath.reserve(numEndPaths);
80 
81  m_modulesOnPaths.reserve(numPaths+numEndPaths);
82 
83  for(unsigned int i =0; i<numPaths;++i) {
84  numModulesInPath.push_back(iNamesService.getTrigPathModules(i).size());
85  m_modulesOnPaths.push_back(iNamesService.getTrigPathModules(i));
86  }
87  for(unsigned int i =0; i<numEndPaths;++i) {
88  numModulesInEndPath.push_back(iNamesService.getEndPathModules(i).size());
89  m_modulesOnPaths.push_back(iNamesService.getEndPathModules(i));
90  }
91 
92  m_endPathOffset =numModulesInPath.size();
93 
94  for( auto& stream: m_streamPathTiming) {
95  unsigned int index = 0;
96  stream.resize(numModulesInPath.size()+numModulesInEndPath.size());
97  for(unsigned int numMods : numModulesInPath) {
98  stream[index].m_moduleTiming.resize(numMods);
99  ++index;
100  }
101  for(unsigned int numMods : numModulesInEndPath) {
102  stream[index].m_moduleTiming.resize(numMods);
103  ++index;
104  }
105 
106  }
107 }
108 
109 //
110 // member functions
111 //
114  PathContext const& iPath) {
115  unsigned int offset = 0;
116  if(iPath.isEndPath()) {
117  offset = m_endPathOffset;
118  }
119  assert(iPath.pathID()+offset < m_streamPathTiming[iStream.streamID().value()].size());
120  return m_streamPathTiming[iStream.streamID().value()][iPath.pathID()+offset];
121 }
122 
123 
124 
125 void
128  m_streamEventTimer[iID.value()].start();
129 }
130 
131 void
133  m_streamEventTimer[iContext.streamID().value()].stop();
134 }
135 
136 void
138  PathContext const& iPath) {
139  auto& timing = pathTiming(iStream,iPath);
140  timing.m_timer.start();
141 }
142 
143 void
145  PathContext const& iPath,
146  HLTPathStatus const& iStatus) {
147  auto& timing = pathTiming(iStream,iPath);
148  timing.m_timer.stop();
149 
150  //mark all modules up to and including the decision module as being visited
151  auto& modsOnPath = timing.m_moduleTiming;
152  for(unsigned int i = 0; i< iStatus.index()+1;++i) {
153  ++modsOnPath[i].m_timesVisited;
154  }
155 }
156 
157 
158 void
160  auto& mod =
162  mod.m_timer.start();
163  ++(mod.m_timesRun);
164 
165 }
167  ModuleCallingContext const& iModule) {
168  auto& mod =
170  auto times = mod.m_timer.stop();
171 
172  if(iModule.type() == ParentContext::Type::kPlaceInPath ) {
173  auto place = iModule.placeInPathContext();
174 
175  auto& modTiming = pathTiming(iStream,*(place->pathContext())).m_moduleTiming[place->placeInPath()];
176  modTiming.m_realTime += times;
177  }
178 
179 }
181  ModuleCallingContext const& iModule) {
182  auto& mod =
184  auto times = mod.m_timer.stop();
185 
186  if(iModule.type() == ParentContext::Type::kPlaceInPath ) {
187  auto place = iModule.placeInPathContext();
188 
189  auto& modTiming = pathTiming(iStream,*(place->pathContext())).m_moduleTiming[place->placeInPath()];
190  modTiming.m_realTime += times;
191  }
192 
193 }
194 void
196  ModuleCallingContext const& iModule) {
197  auto& mod =
199  mod.m_timer.start();
200 }
201 
202 void
205 }
206 
207 void
210 }
211 
212 
213 static void
214 fillPathSummary(unsigned int iStartIndex,
215  unsigned int iEndIndex,
216  std::vector<std::string> const& iPathNames,
217  std::vector<std::vector<std::string>> const& iModulesOnPaths,
218  std::vector<std::vector<SystemTimeKeeper::PathTiming>> const& iPathTimings,
219  std::vector<PathTimingSummary>& iSummary) {
220  iSummary.resize(iEndIndex-iStartIndex);
221 
222  for(auto const& stream: iPathTimings) {
223  auto it = iSummary.begin();
224  for(unsigned int index = iStartIndex; index < iEndIndex; ++index, ++it) {
225  auto const& pathTiming = stream[index];
226  it->name = iPathNames[index];
227  it->bitPosition = index-iStartIndex;
228  if(not pathTiming.m_moduleTiming.empty()) {
229  it->timesRun += pathTiming.m_moduleTiming[0].m_timesVisited;
230  }
231  it->realTime += pathTiming.m_timer.realTime();
232  if(it->moduleInPathSummaries.empty()) {
233  it->moduleInPathSummaries.resize(pathTiming.m_moduleTiming.size());
234  }
235  for(unsigned int modIndex=0; modIndex < pathTiming.m_moduleTiming.size(); ++modIndex) {
236  auto const& modTiming =pathTiming.m_moduleTiming[modIndex];
237  auto& modSummary =it->moduleInPathSummaries[modIndex];
238  if(modSummary.moduleLabel.empty()) {
239  modSummary.moduleLabel = iModulesOnPaths[index][modIndex];
240  }
241  modSummary.timesVisited += modTiming.m_timesVisited;
242  modSummary.realTime += modTiming.m_realTime;
243  }
244  }
245  }
246 }
247 
248 void
250  {
252  double sumEventTime = 0.;
253  for(auto const& stream: m_streamEventTimer) {
254  sumEventTime += stream.realTime();
255  }
258  rep.eventSummary.sumStreamRealTime = sumEventTime;
259  }
260 
261  //Per module summary
262  {
263  auto& summary = rep.workerSummaries;
264  summary.resize(m_modules.size());
265  //Figure out how often a module was visited
266  std::map<std::string,unsigned int> visited;
267  for(auto const& stream: m_streamPathTiming) {
268  unsigned int pathIndex = 0;
269  for(auto const& path: stream) {
270  unsigned int modIndex = 0;
271  for(auto const& mod: path.m_moduleTiming) {
272  visited[m_modulesOnPaths[pathIndex][modIndex]] += mod.m_timesVisited;
273  ++modIndex;
274  }
275  ++pathIndex;
276  }
277  }
278 
279  unsigned int modIndex=0;
280  for(auto const& mod: m_modules) {
281  auto& outMod = summary[modIndex];
282  outMod.moduleLabel = mod->moduleLabel();
283  outMod.realTime = 0.;
284 
285  auto moduleId =mod->id()-m_minModuleID;
286  for(auto const& stream: m_streamModuleTiming) {
287  auto const& timing = stream[moduleId];
288  outMod.realTime += timing.m_timer.realTime();
289  outMod.timesRun += timing.m_timesRun;
290  }
291  outMod.timesVisited = visited[mod->moduleLabel()];
292  if(0 == outMod.timesVisited) {
293  outMod.timesVisited = outMod.timesRun;
294  }
295  ++modIndex;
296  }
297  }
299 
300  //Per path summary
301  {
304  }
305 }
306 
307 
308 //
309 // const member functions
310 //
311 
312 //
313 // static member functions
314 //
std::vector< std::vector< std::string > > m_modulesOnPaths
void fillTriggerTimingReport(TriggerTimingReport &rep) const
std::vector< PathTimingSummary > endPathSummaries
int i
Definition: DBlmapReader.cc:9
Strings const & getTrigPathModules(std::string const &name) const
string rep
Definition: cuy.py:1188
void stopEvent(StreamContext const &)
std::atomic< unsigned int > m_numberOfEvents
void start()
Definition: CPUTimer.cc:74
void restartModuleEvent(StreamContext const &, ModuleCallingContext const &)
Strings const & getEndPaths() const
void startModuleEvent(StreamContext const &, ModuleCallingContext const &)
assert(m_qm.get())
std::vector< ModuleInPathTiming > m_moduleTiming
std::vector< std::vector< ModuleTiming > > m_streamModuleTiming
std::vector< std::string > m_pathNames
bool isEndPath() const
Definition: PathContext.h:42
Strings const & getEndPathModules(std::string const &name) const
std::vector< const ModuleDescription * > m_modules
EventTimingSummary eventSummary
ModuleDescription const * moduleDescription() const
static void fillPathSummary(Path const &path, PathSummary &sum)
std::vector< PathTimingSummary > trigPathSummaries
unsigned int pathID() const
Definition: PathContext.h:39
Times stop()
Definition: CPUTimer.cc:94
void stopPath(StreamContext const &, PathContext const &, HLTPathStatus const &)
void stopModuleEvent(StreamContext const &, ModuleCallingContext const &)
StreamID const & streamID() const
Definition: StreamContext.h:57
double cpuTime() const
Definition: CPUTimer.cc:158
unsigned int value() const
Definition: StreamID.h:46
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:120
void startPath(StreamContext const &, PathContext const &)
SystemTimeKeeper(unsigned int iNumStreams, std::vector< const ModuleDescription * > const &iModules, service::TriggerNamesService const &iNameService)
void pauseModuleEvent(StreamContext const &, ModuleCallingContext const &)
Strings const & getTrigPaths() const
std::vector< WallclockTimer > m_streamEventTimer
PathTiming & pathTiming(StreamContext const &, PathContext const &)
unsigned int m_endPathOffset
std::vector< WorkerTimingSummary > workerSummaries
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
PlaceInPathContext const * placeInPathContext() const
std::vector< std::vector< PathTiming > > m_streamPathTiming
double realTime() const
Definition: CPUTimer.cc:150
tuple size
Write out results.
unsigned int id() const
unsigned int index() const
Definition: HLTPathStatus.h:55