CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 //NOTE: clock_gettime is not available on OS X and is slower
24 // than getrusage and gettimeofday on linux but gives greater
25 // timing accuracy so we may want to revisit this in the future
26 //#define USE_CLOCK_GETTIME
27 #endif
28 
29 #ifdef USE_CLOCK_GETTIME
30 #include <time.h>
31 #else
32 #include <sys/time.h>
33 #endif
34 
35 // user include files
36 
37 // forward declarations
38 namespace edm {
39 class CPUTimer
40 {
41 
42  public:
43  CPUTimer();
44  virtual ~CPUTimer();
45 
46  struct Times {
47  Times():real_(0),cpu_(0) {}
48  double real_;
49  double cpu_;
50  };
51 
52 
53  // ---------- const member functions ---------------------
54  double realTime() const ;
55  double cpuTime() const ;
56 
57  // ---------- static member functions --------------------
58 
59  // ---------- member functions ---------------------------
60  void start();
61  Times stop(); //returns delta time
62  void reset();
63 
64  void add(const Times& t);
65  private:
66  CPUTimer(const CPUTimer&); // stop default
67 
68  const CPUTimer& operator=(const CPUTimer&); // stop default
69 
70  Times calculateDeltaTime() const;
71 
72  // ---------- member data --------------------------------
74 #ifdef USE_CLOCK_GETTIME
75  struct timespec startRealTime_;
76  struct timespec startCPUTime_;
77 #else
78  struct timeval startRealTime_;
79  struct timeval startCPUTime_;
80 #endif
81 
84 
85 };
86 }
87 
88 #endif
void add(const Times &t)
Definition: CPUTimer.cc:113
void start()
Definition: CPUTimer.cc:74
enum edm::CPUTimer::State state_
struct timeval startCPUTime_
Definition: CPUTimer.h:79
void reset()
Definition: CPUTimer.cc:107
struct timeval startRealTime_
Definition: CPUTimer.h:78
double accumulatedCPUTime_
Definition: CPUTimer.h:83
Times stop()
Definition: CPUTimer.cc:94
double cpuTime() const
Definition: CPUTimer.cc:158
double accumulatedRealTime_
Definition: CPUTimer.h:82
Times calculateDeltaTime() const
Definition: CPUTimer.cc:119
virtual ~CPUTimer()
Definition: CPUTimer.cc:56
const CPUTimer & operator=(const CPUTimer &)
double realTime() const
Definition: CPUTimer.cc:150