CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PathTimerService.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Services
4 // Class : PathTimerService
5 //
6 // Implementation:
7 //
8 // Original Author: Jim Kowalkowski
9 //
10 
16 #include <iostream>
17 #include <string>
18 #include <vector>
19 #include <sys/time.h>
20 #include <sstream>
21 #include <math.h>
22 
23 using namespace std ;
24 namespace edm {
25  namespace service {
26 
27  static double getTime() {
28  struct timeval t;
29  if(gettimeofday(&t,0)<0)
30  throw cms::Exception("SysCallFailed","Failed call to gettimeofday");
31 
32  return (double)t.tv_sec + (double(t.tv_usec) * 1E-6);
33  }
34 
35  edm::CPUTimer* PathTimerService::_CPUtimer = 0;
36 
37  PathTimerService::PathTimerService(const ParameterSet& iPS, ActivityRegistry&iRegistry):
38  total_event_count_(0),
39  _perfInfo(new HLTPerformanceInfo)
40  {
43 
46 
49 
51 
52  _myPS=iPS;
53 
54  if (!_CPUtimer) _CPUtimer = new edm::CPUTimer();
55  }
56 
57 
59  if (_CPUtimer) {
60  delete _CPUtimer ;
61  _CPUtimer = 0 ;
62  }
63  }
64 
65 
67 
69  std::vector<std::string> trigPaths= tns->getTrigPaths();
70  for ( unsigned int i=0; i<trigPaths.size(); i++) {
71  _pathMapping[i]=trigPaths[i];
72  HLTPerformanceInfo::Path hltPath(trigPaths[i]);
73  std::vector<unsigned int> loc ;
74  const std::vector<std::string> modules=tns->getTrigPathModules(trigPaths[i]);
75  unsigned int mIdx = 0 ;
76  _perfInfo->addPath(hltPath);
77  for ( unsigned int j=0; j<modules.size(); j++) {
78  _moduleTime[modules[j]]=0. ;
79  _moduleCPUTime[modules[j]]=0. ;
80  HLTPerformanceInfo::Modules::const_iterator iMod =
81  _perfInfo->findModule(modules[j].c_str());
82  if ( iMod == _perfInfo->endModules() ) {
83  HLTPerformanceInfo::Module hltModule(modules[j].c_str(),0.,0.,hlt::Ready);
84  _perfInfo->addModule(hltModule);
85  }
86 
87  //--- Check the module frequency in the path ---//
88  bool duplicateModule = false ;
89  for (unsigned int k=0; k<j; k++) {
90  if (modules[k] == modules[j]) {
91  if (!duplicateModule) loc.push_back(k) ;
92  duplicateModule = true ;
93  }
94  }
95  if (!duplicateModule) {
96  _perfInfo->addModuleToPath(modules[j].c_str(),trigPaths[i].c_str());
97  loc.push_back(mIdx++) ;
98  }
99  }
100  _newPathIndex.push_back(loc) ;
101  }
102  curr_job_ = getTime();
103  }
104 
106 
108  const edm::Timestamp& iTime) {
109  curr_event_ = iID;
111 
112  _perfInfo->clearModules();
113 
114  std::map<std::string, double>::iterator iter=_moduleTime.begin();
115  std::map<std::string, double>::iterator iCPU=_moduleCPUTime.begin();
116 
117  while ( iter != _moduleTime.end()) {
118  (*iter).second=0.;
119  iter++;
120  }
121  while ( iCPU != _moduleCPUTime.end()) {
122  (*iCPU).second=0.;
123  iCPU++;
124  }
125 
126  }
129  }
130 
132  _CPUtimer->reset() ;
133  _CPUtimer->start() ;
134  }
135 
137 
138  _CPUtimer->stop() ;
139  double tWall = _CPUtimer->realTime() ;
140  double tCPU = _CPUtimer->cpuTime() ;
141  _CPUtimer->reset() ;
142 
143  _moduleTime[desc.moduleLabel()] = tWall ;
144  _moduleCPUTime[desc.moduleLabel()] = tCPU ;
145 
146  HLTPerformanceInfo::Modules::iterator iMod =
147  _perfInfo->findModule(desc.moduleLabel().c_str());
148  if ( iMod != _perfInfo->endModules() ) {
149  iMod->setTime(tWall) ;
150  iMod->setCPUTime(tCPU) ;
151  }
152 
153  }
154 
156  const HLTPathStatus &status) {
157  HLTPerformanceInfo::PathList::iterator iPath=_perfInfo->beginPaths();
158  int ctr = 0 ;
159  while ( iPath != _perfInfo->endPaths() ) {
160  if ( iPath->name() == name) {
161  unsigned int pIndex = _newPathIndex.at(ctr).at(status.index()) ;
162  iPath->setStatus(HLTPathStatus(status.state(),pIndex)) ;
163  _perfInfo->setStatusOfModulesFromPath(name.c_str());
164  }
165  iPath++;
166  ctr++;
167 
168  }
169 
170  }
171  }
172 }
std::map< int, std::string > _pathMapping
int i
Definition: DBlmapReader.cc:9
Strings const & getTrigPathModules(std::string const &name) const
not [yet] run
Definition: HLTenums.h:18
void start()
Definition: CPUTimer.cc:74
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void watchPostModule(PostModule::slot_type const &iSlot)
void watchPreProcessEvent(PreProcessEvent::slot_type const &iSlot)
std::map< std::string, double > _moduleCPUTime
void reset()
Definition: CPUTimer.cc:107
std::vector< std::vector< unsigned int > > _newPathIndex
std::string const & moduleLabel() const
void watchPreModule(PreModule::slot_type const &iSlot)
void preModule(const ModuleDescription &)
static edm::CPUTimer * _CPUtimer
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
void postEventProcessing(const Event &, const EventSetup &)
int j
Definition: DBlmapReader.cc:9
void postPathProcessing(const std::string &, const HLTPathStatus &)
std::map< std::string, double > _moduleTime
Times stop()
Definition: CPUTimer.cc:94
hlt::HLTState state() const
get state of path
Definition: HLTPathStatus.h:51
int k[5][pyjets_maxn]
double cpuTime() const
Definition: CPUTimer.cc:158
void preEventProcessing(const edm::EventID &, const edm::Timestamp &)
void postModule(const ModuleDescription &)
Strings const & getTrigPaths() const
static double getTime()
volatile std::atomic< bool > shutdown_flag false
tuple status
Definition: ntuplemaker.py:245
double realTime() const
Definition: CPUTimer.cc:150
std::auto_ptr< HLTPerformanceInfo > _perfInfo
void watchPostProcessPath(PostProcessPath::slot_type const &iSlot)
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
unsigned int index() const
Definition: HLTPathStatus.h:55