CMS 3D CMS Logo

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 namespace edm {
24 }
25 
26 #include <string>
27 
28 #ifdef __linux
29 #include <ctime>
30 #else
31 typedef int clockid_t;
32 #define CLOCK_REALTIME 0
33 #define CLOCK_MONOTONIC 1
34 #define CLOCK_PROCESS_CPUTIME_ID 2
35 #define CLOCK_THREAD_CPUTIME_ID 3
36 #endif
37 
38 namespace hlt {
39 
40  class CPUTimer {
41  public:
42  explicit CPUTimer(bool cpu = true) :
43  timer_( cpu ? CLOCK_THREAD_CPUTIME_ID : CLOCK_REALTIME )
44  {
45  reset();
46  }
47 
48  void reset() {
49  start_.tv_sec = 0;
50  start_.tv_nsec = 0;
51  stop_.tv_sec = 0;
52  stop_.tv_nsec = 0;
53  }
54 
55  void start() {
56 #ifdef __linux
57  clock_gettime(timer_, & start_);
58 #endif
59  }
60 
61  void stop() {
62 #ifdef __linux
63  clock_gettime(timer_, & stop_);
64 #endif
65  }
66 
67  // return the delta between start and stop in seconds
68  double delta() const {
69  if (stop_.tv_nsec > start_.tv_nsec)
70  return (double) (stop_.tv_sec - start_.tv_sec) + (double) (stop_.tv_nsec - start_.tv_nsec) / (double) 1e9;
71  else
72  return (double) (stop_.tv_sec - start_.tv_sec) - (double) (start_.tv_nsec - stop_.tv_nsec) / (double) 1e9;
73  }
74 
75  private:
77  timespec start_;
78  timespec stop_;
79  };
80 
81 } // namespace hlt
82 
83 
84 class TimerService {
85  public:
87  ~TimerService();
88  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
89 
90  // signal with module-description and processing time (in secs)
91  sigc::signal<void, const edm::ModuleDescription&, double> newMeasurementSignal;
92 
93  // fwk calls this method before a module is processed
94  void preModule(const edm::ModuleDescription& iMod);
95  // fwk calls this method after a module has been processed
96  void postModule(const edm::ModuleDescription& iMod);
97 
98  private:
99  // whether to use CPU-time (default) or wall-clock time
101 
102  // cpu-timer
104 
105  // true is the process is bound to a single CPU
106  bool is_bound_;
107 };
108 
109 #endif // #define Timer_Service_
CPUTimer(bool cpu=true)
Definition: TimerService.h:42
std::vector< l1t::Jet >::iterator start_
timespec start_
Definition: TimerService.h:77
timespec stop_
Definition: TimerService.h:78
int clockid_t
Definition: TimerService.h:31
hlt::CPUTimer cpu_timer
Definition: TimerService.h:103
sigc::signal< void, const edm::ModuleDescription &, double > newMeasurementSignal
Definition: TimerService.h:91
HLT enums.
double delta() const
Definition: TimerService.h:68
#define CLOCK_THREAD_CPUTIME_ID
Definition: TimerService.h:35
void reset(double vett[256])
Definition: TPedValues.cc:11
const clockid_t timer_
Definition: TimerService.h:76
#define CLOCK_REALTIME
Definition: TimerService.h:32