CMS 3D CMS Logo

WallclockTimer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Utilities
4 // Class : WallclockTimer
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Sun Apr 16 20:32:20 EDT 2006
11 //
12 
13 // system include files
14 #include <sys/resource.h>
15 #include <errno.h>
16 
17 // user include files
20 
21 //
22 // constants, enums and typedefs
23 //
24 using namespace edm;
25 
26 //
27 // static data member definitions
28 //
29 
30 //
31 // constructors and destructor
32 //
34 state_(kStopped),
35 startRealTime_(),
36 accumulatedRealTime_(0)
37 {
38 #ifdef USE_CLOCK_GETTIME
39  startRealTime_.tv_sec=0;
40  startRealTime_.tv_nsec=0;
41 #else
42  startRealTime_.tv_sec=0;
43  startRealTime_.tv_usec=0;
44 #endif
45 }
46 
47 // WallclockTimer::WallclockTimer(WallclockTimer const& rhs) {
48 // // do actual copying here;
49 // }
50 
52 }
53 
54 //
55 // assignment operators
56 //
57 // WallclockTimer const& WallclockTimer::operator=(WallclockTimer const& rhs) {
58 // //An exception safe implementation is
59 // WallclockTimer temp(rhs);
60 // swap(rhs);
61 //
62 // return *this;
63 // }
64 
65 //
66 // member functions
67 //
68 void
70  if(kStopped == state_) {
71 #ifdef USE_CLOCK_GETTIME
72  clock_gettime(CLOCK_MONOTONIC, &startRealTime_);
73 #else
74  gettimeofday(&startRealTime_, 0);
75 #endif
76  state_ = kRunning;
77  }
78 }
79 
80 double
82  if(kRunning == state_) {
83  auto t = calculateDeltaTime();
85 
87  return t;
88  }
89  return 0.;
90 }
91 
92 void
95 }
96 
97 void
100 }
101 
102 double
104  double returnValue;
105 #ifdef USE_CLOCK_GETTIME
106  double const nanosecToSec = 1E-9;
107  struct timespec tp;
108 
109  clock_gettime(CLOCK_MONOTONIC, &tp);
110  returnValue = tp.tv_sec - startRealTime_.tv_sec + nanosecToSec * (tp.tv_nsec - startRealTime_.tv_nsec);
111 #else
112  double const microsecToSec = 1E-6;
113 
114  struct timeval tp;
115  gettimeofday(&tp, 0);
116 
117  returnValue = tp.tv_sec - startRealTime_.tv_sec + microsecToSec * (tp.tv_usec - startRealTime_.tv_usec);
118 #endif
119  return returnValue;
120 }
121 //
122 // const member functions
123 //
124 double
126  if(kStopped == state_) {
127  return accumulatedRealTime_;
128  }
130 }
131 
132 //
133 // static member functions
134 //
double calculateDeltaTime() const
#define CLOCK_MONOTONIC
Definition: TimerService.h:33
double realTime() const
void add(double t)
enum edm::WallclockTimer::State state_
struct timeval startRealTime_
HLT enums.