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
26 #include "SystemTimeKeeper.h"
27 
28 using namespace edm;
29 //
30 // constants, enums and typedefs
31 //
32 
33 //
34 // static data member definitions
35 //
36 
37 //
38 // constructors and destructor
39 //
40 SystemTimeKeeper::SystemTimeKeeper(unsigned int iNumStreams,
41  std::vector<const ModuleDescription*> const& iModules,
42  service::TriggerNamesService const& iNamesService):
43 m_streamEventTimer(iNumStreams),
44 m_streamPathTiming(iNumStreams),
45 m_modules(iModules),
46 m_minModuleID(0),
47 m_numberOfEvents(0)
48 {
49  std::sort(m_modules.begin(),m_modules.end(),
50  [] (const ModuleDescription* iLHS,
51  const ModuleDescription* iRHS) -> bool {
52  return iLHS->id() < iRHS->id();
53  });
54  if(not m_modules.empty()) {
55  m_minModuleID = m_modules.front()->id();
56  unsigned int numModuleSlots = m_modules.back()->id() - m_minModuleID + 1;
57  m_streamModuleTiming.resize(iNumStreams);
58  for(auto& stream: m_streamModuleTiming) {
59  stream.resize(numModuleSlots);
60  }
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(),
71  iNamesService.getTrigPaths().end(),
72  std::back_inserter(m_pathNames));
73  std::copy(iNamesService.getEndPaths().begin(),
74  iNamesService.getEndPaths().end(),
75  std::back_inserter(m_pathNames));
76 
77  numModulesInPath.reserve(numPaths);
78  numModulesInEndPath.reserve(numEndPaths);
79 
80  m_modulesOnPaths.reserve(numPaths+numEndPaths);
81 
82  for(unsigned int i =0; i<numPaths;++i) {
83  numModulesInPath.push_back(iNamesService.getTrigPathModules(i).size());
84  m_modulesOnPaths.push_back(iNamesService.getTrigPathModules(i));
85  }
86  for(unsigned int i =0; i<numEndPaths;++i) {
87  numModulesInEndPath.push_back(iNamesService.getEndPathModules(i).size());
88  m_modulesOnPaths.push_back(iNamesService.getEndPathModules(i));
89  }
90 
91  m_endPathOffset =numModulesInPath.size();
92 
93  for( auto& stream: m_streamPathTiming) {
94  unsigned int index = 0;
95  stream.resize(numModulesInPath.size()+numModulesInEndPath.size());
96  for(unsigned int numMods : numModulesInPath) {
97  stream[index].m_moduleTiming.resize(numMods);
98  ++index;
99  }
100  for(unsigned int numMods : numModulesInEndPath) {
101  stream[index].m_moduleTiming.resize(numMods);
102  ++index;
103  }
104 
105  }
106 }
107 
108 //
109 // member functions
110 //
113  PathContext const& iPath) {
114  unsigned int offset = 0;
115  if(iPath.isEndPath()) {
116  offset = m_endPathOffset;
117  }
118  assert(iPath.pathID()+offset < m_streamPathTiming[iStream.streamID().value()].size());
119  return m_streamPathTiming[iStream.streamID().value()][iPath.pathID()+offset];
120 }
121 
122 
123 
124 void
127  m_streamEventTimer[iID.value()].start();
128 }
129 
130 void
132  m_streamEventTimer[iContext.streamID().value()].stop();
133 }
134 
135 void
137  PathContext const& iPath) {
138  auto& timing = pathTiming(iStream,iPath);
139  timing.m_timer.start();
140 }
141 
142 void
144  PathContext const& iPath,
145  HLTPathStatus const& iStatus) {
146  auto& timing = pathTiming(iStream,iPath);
147  timing.m_timer.stop();
148 
149  //mark all modules up to and including the decision module as being visited
150  auto& modsOnPath = timing.m_moduleTiming;
151  for(unsigned int i = 0; i< iStatus.index()+1;++i) {
152  ++modsOnPath[i].m_timesVisited;
153  }
154 }
155 
156 
157 void
159  auto& mod =
161  mod.m_timer.start();
162  ++(mod.m_timesRun);
163 
164 }
166  ModuleCallingContext const& iModule) {
167  auto& mod =
169  auto times = mod.m_timer.stop();
170 
171  if(iModule.type() == ParentContext::Type::kPlaceInPath ) {
172  auto place = iModule.placeInPathContext();
173 
174  auto& modTiming = pathTiming(iStream,*(place->pathContext())).m_moduleTiming[place->placeInPath()];
175  modTiming.m_realTime += times;
176  }
177 
178 }
180  ModuleCallingContext const& iModule) {
181  auto& mod =
183  auto times = mod.m_timer.stop();
184 
185  if(iModule.type() == ParentContext::Type::kPlaceInPath ) {
186  auto place = iModule.placeInPathContext();
187 
188  auto& modTiming = pathTiming(iStream,*(place->pathContext())).m_moduleTiming[place->placeInPath()];
189  modTiming.m_realTime += times;
190  }
191 
192 }
193 void
195  ModuleCallingContext const& iModule) {
196  auto& mod =
198  mod.m_timer.start();
199 }
200 
201 void
204 }
205 
206 void
209 }
210 
211 
212 static void
213 fillPathSummary(unsigned int iStartIndex,
214  unsigned int iEndIndex,
215  std::vector<std::string> const& iPathNames,
216  std::vector<std::vector<std::string>> const& iModulesOnPaths,
217  std::vector<std::vector<SystemTimeKeeper::PathTiming>> const& iPathTimings,
218  std::vector<PathTimingSummary>& iSummary) {
219  iSummary.resize(iEndIndex-iStartIndex);
220 
221  for(auto const& stream: iPathTimings) {
222  auto it = iSummary.begin();
223  for(unsigned int index = iStartIndex; index < iEndIndex; ++index, ++it) {
224  auto const& pathTiming = stream[index];
225  it->name = iPathNames[index];
226  it->bitPosition = index-iStartIndex;
227  if(not pathTiming.m_moduleTiming.empty()) {
228  it->timesRun += pathTiming.m_moduleTiming[0].m_timesVisited;
229  }
230  it->realTime += pathTiming.m_timer.realTime();
231  if(it->moduleInPathSummaries.empty()) {
232  it->moduleInPathSummaries.resize(pathTiming.m_moduleTiming.size());
233  }
234  for(unsigned int modIndex=0; modIndex < pathTiming.m_moduleTiming.size(); ++modIndex) {
235  auto const& modTiming =pathTiming.m_moduleTiming[modIndex];
236  auto& modSummary =it->moduleInPathSummaries[modIndex];
237  if(modSummary.moduleLabel.empty()) {
238  modSummary.moduleLabel = iModulesOnPaths[index][modIndex];
239  }
240  modSummary.timesVisited += modTiming.m_timesVisited;
241  modSummary.realTime += modTiming.m_realTime;
242  }
243  }
244  }
245 }
246 
247 void
249  {
251  double sumEventTime = 0.;
252  for(auto const& stream: m_streamEventTimer) {
253  sumEventTime += stream.realTime();
254  }
257  rep.eventSummary.sumStreamRealTime = sumEventTime;
258  }
259 
260  //Per module summary
261  {
262  auto& summary = rep.workerSummaries;
263  summary.resize(m_modules.size());
264  //Figure out how often a module was visited
265  std::map<std::string,unsigned int> visited;
266  for(auto const& stream: m_streamPathTiming) {
267  unsigned int pathIndex = 0;
268  for(auto const& path: stream) {
269  unsigned int modIndex = 0;
270  for(auto const& mod: path.m_moduleTiming) {
271  visited[m_modulesOnPaths[pathIndex][modIndex]] += mod.m_timesVisited;
272  ++modIndex;
273  }
274  ++pathIndex;
275  }
276  }
277 
278  unsigned int modIndex=0;
279  for(auto const& mod: m_modules) {
280  auto& outMod = summary[modIndex];
281  outMod.moduleLabel = mod->moduleLabel();
282  outMod.realTime = 0.;
283 
284  auto moduleId =mod->id()-m_minModuleID;
285  for(auto const& stream: m_streamModuleTiming) {
286  auto const& timing = stream[moduleId];
287  outMod.realTime += timing.m_timer.realTime();
288  outMod.timesRun += timing.m_timesRun;
289  }
290  outMod.timesVisited = visited[mod->moduleLabel()];
291  if(0 == outMod.timesVisited) {
292  outMod.timesVisited = outMod.timesRun;
293  }
294  ++modIndex;
295  }
296  }
297 
298  //Per path summary
299  {
302  }
303 }
304 
305 
306 //
307 // const member functions
308 //
309 
310 //
311 // static member functions
312 //
std::vector< std::vector< std::string > > m_modulesOnPaths
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
void fillTriggerTimingReport(TriggerTimingReport &rep)
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 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