CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TimeProfilerService.cc
Go to the documentation of this file.
3 namespace evf{
4 
5 
6  static double getTime()
7  {
8  struct timeval t;
9  if(gettimeofday(&t,0)<0)
10  throw cms::Exception("SysCallFailed","Failed call to gettimeofday");
11 
12  return (double)t.tv_sec + (double(t.tv_usec) * 1E-6);
13  }
14 
16  {
19 
22 
25  }
26 
28  {}
29 
31  {}
32 
34  {}
36  const edm::Timestamp& iTime)
37  {}
39  {}
41  {
43  }
44 
46  {
47  double t = getTime() - curr_module_time_;
48  std::map<std::string, times>::iterator it = profiles_.find(desc.moduleLabel());
49  if(it==profiles_.end())
50  {
51  times tt;
52  tt.ncalls_ = 0;
53  tt.total_ = 0.;
54  tt.max_ = 0.;
55  tt.firstEvent_ = t;
56  profiles_.insert(std::pair<std::string, times>(desc.moduleLabel(),tt));
57  }
58  else
59  {
60  (*it).second.ncalls_++;
61  (*it).second.total_ += t;
62  (*it).second.max_ = ((*it).second.max_ > t) ? (*it).second.max_ : t;
63  }
64  }
65  double TimeProfilerService::getFirst(std::string const &name) const
66  {
67  std::map<std::string, times>::const_iterator it = profiles_.find(name);
68 
69  if(it==profiles_.end())
70  return -1.;
71  return (*it).second.firstEvent_;
72  }
73 
74  double TimeProfilerService::getMax(std::string const &name) const
75  {
76  std::map<std::string, times>::const_iterator it = profiles_.find(name);
77 
78  if(it == profiles_.end())
79  return -1.;
80  return (*it).second.max_;
81  }
82 
83  double TimeProfilerService::getAve(std::string const &name) const
84  {
85  std::map<std::string, times>::const_iterator it = profiles_.find(name);
86 
87  if(it == profiles_.end())
88  return -1.;
89  return (*it).second.total_/(*it).second.ncalls_;
90  }
91 }
double getAve(std::string const &name) const
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void watchPostModule(PostModule::slot_type const &iSlot)
void watchPreProcessEvent(PreProcessEvent::slot_type const &iSlot)
TimeProfilerService(const edm::ParameterSet &, edm::ActivityRegistry &)
std::string const & moduleLabel() const
double getFirst(std::string const &name) const
void watchPreModule(PreModule::slot_type const &iSlot)
void postEventProcessing(const edm::Event &, const edm::EventSetup &)
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
double getMax(std::string const &name) const
void preEventProcessing(const edm::EventID &, const edm::Timestamp &)
void postModule(const edm::ModuleDescription &)
static double getTime()
std::map< std::string, times > profiles_
void preModule(const edm::ModuleDescription &)
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal