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