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 // $Id: PathTimerService.cc,v 1.14 2008/07/30 09:35:08 wittich Exp $
10 //
11 
17 #include <iostream>
18 #include <string>
19 #include <vector>
20 #include <sys/time.h>
21 #include <sstream>
22 #include <math.h>
23 
24 using namespace std ;
25 namespace edm {
26  namespace service {
27 
28  static double getTime() {
29  struct timeval t;
30  if(gettimeofday(&t,0)<0)
31  throw cms::Exception("SysCallFailed","Failed call to gettimeofday");
32 
33  return (double)t.tv_sec + (double(t.tv_usec) * 1E-6);
34  }
35 
36  edm::CPUTimer* PathTimerService::_CPUtimer = 0;
37 
38  PathTimerService::PathTimerService(const ParameterSet& iPS, ActivityRegistry&iRegistry):
39  total_event_count_(0),
40  _perfInfo(new HLTPerformanceInfo)
41  {
44 
47 
50 
52 
53  _myPS=iPS;
54 
55  if (!_CPUtimer) _CPUtimer = new edm::CPUTimer();
56  }
57 
58 
60  if (_CPUtimer) {
61  delete _CPUtimer ;
62  _CPUtimer = 0 ;
63  }
64  }
65 
66 
68 
70  std::vector<std::string> trigPaths= tns->getTrigPaths();
71  for ( unsigned int i=0; i<trigPaths.size(); i++) {
72  _pathMapping[i]=trigPaths[i];
73  HLTPerformanceInfo::Path hltPath(trigPaths[i]);
74  std::vector<unsigned int> loc ;
75  const std::vector<std::string> modules=tns->getTrigPathModules(trigPaths[i]);
76  unsigned int mIdx = 0 ;
77  _perfInfo->addPath(hltPath);
78  for ( unsigned int j=0; j<modules.size(); j++) {
79  _moduleTime[modules[j]]=0. ;
80  _moduleCPUTime[modules[j]]=0. ;
81  HLTPerformanceInfo::Modules::const_iterator iMod =
82  _perfInfo->findModule(modules[j].c_str());
83  if ( iMod == _perfInfo->endModules() ) {
84  HLTPerformanceInfo::Module hltModule(modules[j].c_str(),0.,0.,hlt::Ready);
85  _perfInfo->addModule(hltModule);
86  }
87 
88  //--- Check the module frequency in the path ---//
89  bool duplicateModule = false ;
90  for (unsigned int k=0; k<j; k++) {
91  if (modules[k] == modules[j]) {
92  if (!duplicateModule) loc.push_back(k) ;
93  duplicateModule = true ;
94  }
95  }
96  if (!duplicateModule) {
97  _perfInfo->addModuleToPath(modules[j].c_str(),trigPaths[i].c_str());
98  loc.push_back(mIdx++) ;
99  }
100  }
101  _newPathIndex.push_back(loc) ;
102  }
103  curr_job_ = getTime();
104  }
105 
107 
109  const edm::Timestamp& iTime) {
110  curr_event_ = iID;
112 
113  _perfInfo->clearModules();
114 
115  std::map<std::string, double>::iterator iter=_moduleTime.begin();
116  std::map<std::string, double>::iterator iCPU=_moduleCPUTime.begin();
117 
118  while ( iter != _moduleTime.end()) {
119  (*iter).second=0.;
120  iter++;
121  }
122  while ( iCPU != _moduleCPUTime.end()) {
123  (*iCPU).second=0.;
124  iCPU++;
125  }
126 
127  }
130  }
131 
133  _CPUtimer->reset() ;
134  _CPUtimer->start() ;
135  }
136 
138 
139  _CPUtimer->stop() ;
140  double tWall = _CPUtimer->realTime() ;
141  double tCPU = _CPUtimer->cpuTime() ;
142  _CPUtimer->reset() ;
143 
144  _moduleTime[desc.moduleLabel()] = tWall ;
145  _moduleCPUTime[desc.moduleLabel()] = tCPU ;
146 
147  HLTPerformanceInfo::Modules::iterator iMod =
148  _perfInfo->findModule(desc.moduleLabel().c_str());
149  if ( iMod != _perfInfo->endModules() ) {
150  iMod->setTime(tWall) ;
151  iMod->setCPUTime(tCPU) ;
152  }
153 
154  }
155 
157  const HLTPathStatus &status) {
158  HLTPerformanceInfo::PathList::iterator iPath=_perfInfo->beginPaths();
159  int ctr = 0 ;
160  while ( iPath != _perfInfo->endPaths() ) {
161  if ( iPath->name() == name) {
162  unsigned int pIndex = _newPathIndex.at(ctr).at(status.index()) ;
163  iPath->setStatus(HLTPathStatus(status.state(),pIndex)) ;
164  _perfInfo->setStatusOfModulesFromPath(name.c_str());
165  }
166  iPath++;
167  ctr++;
168 
169  }
170 
171  }
172  }
173 }
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:21
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:54
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()
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
get index of module giving the status of this path
Definition: HLTPathStatus.h:56