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 //
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::WallclockTimer::kStopped
Definition: WallclockTimer.h:63
edm::WallclockTimer::realTime
double realTime() const
Definition: WallclockTimer.cc:110
edm::WallclockTimer::add
void add(double t)
Definition: WallclockTimer.cc:87
OrderedSet.t
t
Definition: OrderedSet.py:90
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
edm::WallclockTimer::start
void start()
Definition: WallclockTimer.cc:63
edm::WallclockTimer::kRunning
Definition: WallclockTimer.h:63
WallclockTimer.h
edm::WallclockTimer::accumulatedRealTime_
double accumulatedRealTime_
Definition: WallclockTimer.h:70
edm::WallclockTimer::WallclockTimer
WallclockTimer()
Definition: WallclockTimer.cc:33
edm::WallclockTimer::startRealTime_
struct timeval startRealTime_
Definition: WallclockTimer.h:67
Exception.h
edm::WallclockTimer::state_
enum edm::WallclockTimer::State state_
edm::WallclockTimer::reset
void reset()
Definition: WallclockTimer.cc:85
edm::WallclockTimer::stop
double stop()
Definition: WallclockTimer.cc:74
edm::WallclockTimer::~WallclockTimer
~WallclockTimer()
Definition: WallclockTimer.cc:47
edm::WallclockTimer::calculateDeltaTime
double calculateDeltaTime() const
Definition: WallclockTimer.cc:89