CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  CPUTimer(const CPUTimer&) = delete;
43  CPUTimer& operator=(const CPUTimer&) = delete;
44 
45  struct Times {
46  Times() : real_(0), cpu_(0) {}
47  double real_;
48  double cpu_;
49  };
50 
51  // ---------- const member functions ---------------------
52  double realTime() const;
53  double cpuTime() const;
54 
55  // ---------- static member functions --------------------
56 
57  // ---------- member functions ---------------------------
58  void start();
59  Times stop(); //returns delta time
60  void reset();
61 
62  void add(const Times& t);
63 
64  private:
65  Times calculateDeltaTime() const;
66 
67  // ---------- member data --------------------------------
69 #ifdef USE_CLOCK_GETTIME
70  struct timespec startRealTime_;
71  struct timespec startCPUTime_;
72 #else
73  struct timeval startRealTime_;
74  struct timeval startCPUTime_;
75 #endif
76 
79  };
80 } // namespace edm
81 
82 #endif
void add(const Times &t)
Definition: CPUTimer.cc:104
void start()
Definition: CPUTimer.cc:68
enum edm::CPUTimer::State state_
struct timeval startCPUTime_
Definition: CPUTimer.h:74
void reset()
Definition: CPUTimer.cc:99
CPUTimer & operator=(const CPUTimer &)=delete
struct timeval startRealTime_
Definition: CPUTimer.h:73
double accumulatedCPUTime_
Definition: CPUTimer.h:78
Times stop()
Definition: CPUTimer.cc:87
double cpuTime() const
Definition: CPUTimer.cc:146
double accumulatedRealTime_
Definition: CPUTimer.h:77
Times calculateDeltaTime() const
Definition: CPUTimer.cc:109
double realTime() const
Definition: CPUTimer.cc:139