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 <time.h>
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 {
39 
40  public:
41  CPUTimer();
42  ~CPUTimer();
43  CPUTimer(CPUTimer&&) = default;
44 
45  struct Times {
46  Times():real_(0),cpu_(0) {}
47  double real_;
48  double cpu_;
49  };
50 
51 
52  // ---------- const member functions ---------------------
53  double realTime() const ;
54  double cpuTime() const ;
55 
56  // ---------- static member functions --------------------
57 
58  // ---------- member functions ---------------------------
59  void start();
60  Times stop(); //returns delta time
61  void reset();
62 
63  void add(const Times& t);
64  private:
65  CPUTimer(const CPUTimer&) = delete; // stop default
66 
67  const CPUTimer& operator=(const CPUTimer&) = delete; // stop default
68 
69  Times calculateDeltaTime() const;
70 
71  // ---------- member data --------------------------------
73 #ifdef USE_CLOCK_GETTIME
74  struct timespec startRealTime_;
75  struct timespec startCPUTime_;
76 #else
77  struct timeval startRealTime_;
78  struct timeval startCPUTime_;
79 #endif
80 
83 
84 };
85 }
86 
87 #endif
void add(const Times &t)
Definition: CPUTimer.cc:113
void start()
Definition: CPUTimer.cc:74
enum edm::CPUTimer::State state_
void reset()
Definition: CPUTimer.cc:107
double accumulatedCPUTime_
Definition: CPUTimer.h:82
Times stop()
Definition: CPUTimer.cc:94
double cpuTime() const
Definition: CPUTimer.cc:158
double accumulatedRealTime_
Definition: CPUTimer.h:81
Times calculateDeltaTime() const
Definition: CPUTimer.cc:119
HLT enums.
const CPUTimer & operator=(const CPUTimer &)=delete
double realTime() const
Definition: CPUTimer.cc:150