CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TimerService.h
Go to the documentation of this file.
1 #ifndef Timer_Service_
2 #define Timer_Service_
3 
13 #include "sigc++/signal.h"
14 
16 
21 
22 #include <string>
23 
24 #ifdef __linux
25 #include <time.h>
26 #else
27 typedef int clockid_t;
28 #define CLOCK_REALTIME 0
29 #define CLOCK_MONOTONIC 1
30 #define CLOCK_PROCESS_CPUTIME_ID 2
31 #define CLOCK_THREAD_CPUTIME_ID 3
32 #endif
33 
34 namespace hlt {
35 
36  class CPUTimer {
37  public:
38  explicit CPUTimer(bool cpu = true) :
40  {
41  reset();
42  }
43 
44  void reset() {
45  start_.tv_sec = 0;
46  start_.tv_nsec = 0;
47  stop_.tv_sec = 0;
48  stop_.tv_nsec = 0;
49  }
50 
51  void start() {
52 #ifdef __linux
53  clock_gettime(timer_, & start_);
54 #endif
55  }
56 
57  void stop() {
58 #ifdef __linux
59  clock_gettime(timer_, & stop_);
60 #endif
61  }
62 
63  // return the delta between start and stop in seconds
64  double delta() const {
65  if (stop_.tv_nsec > start_.tv_nsec)
66  return (double) (stop_.tv_sec - start_.tv_sec) + (double) (stop_.tv_nsec - start_.tv_nsec) / (double) 1e9;
67  else
68  return (double) (stop_.tv_sec - start_.tv_sec) - (double) (start_.tv_nsec - stop_.tv_nsec) / (double) 1e9;
69  }
70 
71  private:
73  timespec start_;
74  timespec stop_;
75  };
76 
77 } // namespace hlt
78 
79 
80 class TimerService {
81  public:
83  ~TimerService();
84 
85  // signal with module-description and processing time (in secs)
86  sigc::signal<void, const edm::ModuleDescription&, double> newMeasurementSignal;
87 
88  // fwk calls this method before a module is processed
89  void preModule(const edm::ModuleDescription& iMod);
90  // fwk calls this method after a module has been processed
91  void postModule(const edm::ModuleDescription& iMod);
92 
93  private:
94  // whether to use CPU-time (default) or wall-clock time
95  bool useCPUtime;
96 
97  // cpu-timer
99 
100  // true is the process is bound to a single CPU
101  bool is_bound_;
102 };
103 
104 #endif // #define Timer_Service_
void postModule(const edm::ModuleDescription &iMod)
Definition: TimerService.cc:47
void preModule(const edm::ModuleDescription &iMod)
Definition: TimerService.cc:40
CPUTimer(bool cpu=true)
Definition: TimerService.h:38
timespec start_
Definition: TimerService.h:73
int clockid_t
TimerService(const edm::ParameterSet &, edm::ActivityRegistry &iAR)
Definition: TimerService.cc:8
timespec stop_
Definition: TimerService.h:74
hlt::CPUTimer cpu_timer
Definition: TimerService.h:98
sigc::signal< void, const edm::ModuleDescription &, double > newMeasurementSignal
Definition: TimerService.h:86
double delta() const
Definition: TimerService.h:64
#define CLOCK_THREAD_CPUTIME_ID
Definition: TimerService.h:31
const clockid_t timer_
Definition: TimerService.h:72
#define CLOCK_REALTIME
Definition: TimerService.h:28