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_cpuTime += times.cpu_;
176  modTiming.m_realTime += times.real_;
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_cpuTime += times.cpu_;
191  modTiming.m_realTime += times.real_;
192  }
193 
194 }
195 void
197  ModuleCallingContext const& iModule) {
198  auto& mod =
200  mod.m_timer.start();
201 }
202 
203 static void
204 fillPathSummary(unsigned int iStartIndex,
205  unsigned int iEndIndex,
206  std::vector<std::string> const& iPathNames,
207  std::vector<std::vector<std::string>> const& iModulesOnPaths,
208  std::vector<std::vector<SystemTimeKeeper::PathTiming>> const& iPathTimings,
209  std::vector<PathTimingSummary>& iSummary) {
210  iSummary.resize(iEndIndex-iStartIndex);
211 
212  for(auto const& stream: iPathTimings) {
213  auto it = iSummary.begin();
214  for(unsigned int index = iStartIndex; index < iEndIndex; ++index, ++it) {
215  auto const& pathTiming = stream[index];
216  it->name = iPathNames[index];
217  it->bitPosition = index-iStartIndex;
218  if(not pathTiming.m_moduleTiming.empty()) {
219  it->timesRun += pathTiming.m_moduleTiming[0].m_timesVisited;
220  }
221  it->realTime += pathTiming.m_timer.realTime();
222  it->cpuTime += pathTiming.m_timer.cpuTime();
223  if(it->moduleInPathSummaries.empty()) {
224  it->moduleInPathSummaries.resize(pathTiming.m_moduleTiming.size());
225  }
226  for(unsigned int modIndex=0; modIndex < pathTiming.m_moduleTiming.size(); ++modIndex) {
227  auto const& modTiming =pathTiming.m_moduleTiming[modIndex];
228  auto& modSummary =it->moduleInPathSummaries[modIndex];
229  if(modSummary.moduleLabel.empty()) {
230  modSummary.moduleLabel = iModulesOnPaths[index][modIndex];
231  }
232  modSummary.timesVisited += modTiming.m_timesVisited;
233  modSummary.realTime += modTiming.m_realTime;
234  modSummary.cpuTime += modTiming.m_cpuTime;
235  }
236  }
237  }
238 }
239 
240 void
242  {
244  double cpuTime = 0.;
245  double realTime = 0.;
246  for(auto const& stream: m_streamEventTimer) {
247  realTime += stream.realTime();
248  cpuTime += stream.cpuTime();
249  }
250  rep.eventSummary.realTime = realTime;
251  rep.eventSummary.cpuTime = cpuTime;
252  }
253 
254  //Per module summary
255  {
256  auto& summary = rep.workerSummaries;
257  summary.resize(m_modules.size());
258  //Figure out how often a module was visited
259  std::map<std::string,unsigned int> visited;
260  for(auto const& stream: m_streamPathTiming) {
261  unsigned int pathIndex = 0;
262  for(auto const& path: stream) {
263  unsigned int modIndex = 0;
264  for(auto const& mod: path.m_moduleTiming) {
265  visited[m_modulesOnPaths[pathIndex][modIndex]] += mod.m_timesVisited;
266  ++modIndex;
267  }
268  ++pathIndex;
269  }
270  }
271 
272  unsigned int modIndex=0;
273  for(auto const& mod: m_modules) {
274  auto& outMod = summary[modIndex];
275  outMod.moduleLabel = mod->moduleLabel();
276  outMod.realTime = 0.;
277  outMod.cpuTime = 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.cpuTime += timing.m_timer.cpuTime();
284  outMod.timesRun += timing.m_timesRun;
285  }
286  outMod.timesVisited = visited[mod->moduleLabel()];
287  if(0 == outMod.timesVisited) {
288  outMod.timesVisited = outMod.timesRun;
289  }
290  ++modIndex;
291  }
292  }
293 
294  //Per path summary
295  {
298  }
299 }
300 
301 
302 //
303 // const member functions
304 //
305 
306 //
307 // static member functions
308 //
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 restartModuleEvent(StreamContext const &, ModuleCallingContext const &)
Strings const & getEndPaths() const
void startModuleEvent(StreamContext const &, ModuleCallingContext const &)
std::vector< ModuleInPathTiming > m_moduleTiming
std::vector< std::vector< ModuleTiming > > m_streamModuleTiming
std::vector< CPUTimer > m_streamEventTimer
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)
tuple path
else: Piece not in the list, fine.
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
unsigned int offset(bool)
void stopPath(StreamContext const &, PathContext const &, HLTPathStatus const &)
void stopModuleEvent(StreamContext const &, ModuleCallingContext const &)
StreamID const & streamID() const
Definition: StreamContext.h:57
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
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
tuple size
Write out results.
unsigned int id() const
unsigned int index() const
Definition: HLTPathStatus.h:55