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 <cerrno>
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 //
33 WallclockTimer::WallclockTimer() : state_(kStopped), startRealTime_(), accumulatedRealTime_(0) {
34 #ifdef USE_CLOCK_GETTIME
35  startRealTime_.tv_sec = 0;
36  startRealTime_.tv_nsec = 0;
37 #else
38  startRealTime_.tv_sec = 0;
39  startRealTime_.tv_usec = 0;
40 #endif
41 }
42 
43 // WallclockTimer::WallclockTimer(WallclockTimer const& rhs) {
44 // // do actual copying here;
45 // }
46 
48 
49 //
50 // assignment operators
51 //
52 // WallclockTimer const& WallclockTimer::operator=(WallclockTimer const& rhs) {
53 // //An exception safe implementation is
54 // WallclockTimer temp(rhs);
55 // swap(rhs);
56 //
57 // return *this;
58 // }
59 
60 //
61 // member functions
62 //
64  if (kStopped == state_) {
65 #ifdef USE_CLOCK_GETTIME
66  clock_gettime(CLOCK_MONOTONIC, &startRealTime_);
67 #else
68  gettimeofday(&startRealTime_, 0);
69 #endif
70  state_ = kRunning;
71  }
72 }
73 
75  if (kRunning == state_) {
76  auto t = calculateDeltaTime();
78 
79  state_ = kStopped;
80  return t;
81  }
82  return 0.;
83 }
84 
86 
88 
90  double returnValue;
91 #ifdef USE_CLOCK_GETTIME
92  double const nanosecToSec = 1E-9;
93  struct timespec tp;
94 
95  clock_gettime(CLOCK_MONOTONIC, &tp);
96  returnValue = tp.tv_sec - startRealTime_.tv_sec + nanosecToSec * (tp.tv_nsec - startRealTime_.tv_nsec);
97 #else
98  double const microsecToSec = 1E-6;
99 
100  struct timeval tp;
101  gettimeofday(&tp, 0);
102 
103  returnValue = tp.tv_sec - startRealTime_.tv_sec + microsecToSec * (tp.tv_usec - startRealTime_.tv_usec);
104 #endif
105  return returnValue;
106 }
107 //
108 // const member functions
109 //
110 double WallclockTimer::realTime() const {
111  if (kStopped == state_) {
112  return accumulatedRealTime_;
113  }
115 }
116 
117 //
118 // static member functions
119 //
void add(double t)
enum edm::WallclockTimer::State state_
double calculateDeltaTime() const
struct timeval startRealTime_
double realTime() const
HLT enums.