CMS 3D CMS Logo

CPUTimer.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_CPUTimer_h
2 #define FWCore_Utilities_CPUTimer_h
3 // -*- C++ -*-
4 //
5 // Package: Utilities
6 // Class : CPUTimer
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Sun Apr 16 20:32:13 EDT 2006
19 //
20 
21 // system include files
22 #ifdef __linux__
23 //clock_gettime is not available on OS X
24 #define USE_CLOCK_GETTIME
25 #endif
26 
27 #ifdef USE_CLOCK_GETTIME
28 #include <ctime>
29 #else
30 #include <sys/time.h>
31 #endif
32 
33 // user include files
34 
35 // forward declarations
36 namespace edm {
37  class CPUTimer {
38  public:
39  CPUTimer();
40  ~CPUTimer();
41  CPUTimer(CPUTimer&&) = default;
42 
43  struct Times {
44  Times() : real_(0), cpu_(0) {}
45  double real_;
46  double cpu_;
47  };
48 
49  // ---------- const member functions ---------------------
50  double realTime() const;
51  double cpuTime() const;
52 
53  // ---------- static member functions --------------------
54 
55  // ---------- member functions ---------------------------
56  void start();
57  Times stop(); //returns delta time
58  void reset();
59 
60  void add(const Times& t);
61 
62  private:
63  CPUTimer(const CPUTimer&) = delete; // stop default
64 
65  const CPUTimer& operator=(const CPUTimer&) = delete; // stop default
66 
67  Times calculateDeltaTime() const;
68 
69  // ---------- member data --------------------------------
71 #ifdef USE_CLOCK_GETTIME
72  struct timespec startRealTime_;
73  struct timespec startCPUTime_;
74 #else
75  struct timeval startRealTime_;
76  struct timeval startCPUTime_;
77 #endif
78 
81  };
82 } // namespace edm
83 
84 #endif
void add(const Times &t)
Definition: CPUTimer.cc:104
void start()
Definition: CPUTimer.cc:68
enum edm::CPUTimer::State state_
void reset()
Definition: CPUTimer.cc:99
double accumulatedCPUTime_
Definition: CPUTimer.h:80
Times stop()
Definition: CPUTimer.cc:87
double cpuTime() const
Definition: CPUTimer.cc:146
double accumulatedRealTime_
Definition: CPUTimer.h:79
Times calculateDeltaTime() const
Definition: CPUTimer.cc:109
HLT enums.
const CPUTimer & operator=(const CPUTimer &)=delete
double realTime() const
Definition: CPUTimer.cc:139