Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:20

0001 #ifndef FWCore_Utilities_WallclockTimer_h
0002 #define FWCore_Utilities_WallclockTimer_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Utilities
0006 // Class  :     WallclockTimer
0007 //
0008 /**\class WallclockTimer WallclockTimer.h FWCore/Utilities/interface/WallclockTimer.h
0009 
0010  Description: Timer which measures the CPU and wallclock time
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Sun Apr 16 20:32:13 EDT 2006
0019 //
0020 
0021 // system include files
0022 #ifdef __linux__
0023 //clock_gettime is not available on OS X
0024 #define USE_CLOCK_GETTIME
0025 #endif
0026 
0027 #ifdef USE_CLOCK_GETTIME
0028 #include <ctime>
0029 #else
0030 #include <sys/time.h>
0031 #endif
0032 
0033 // user include files
0034 
0035 // forward declarations
0036 namespace edm {
0037   class WallclockTimer {
0038   public:
0039     WallclockTimer();
0040     ~WallclockTimer();
0041     WallclockTimer(WallclockTimer&&) = default;
0042     WallclockTimer(const WallclockTimer&) = delete;
0043     WallclockTimer& operator=(const WallclockTimer&) = delete;
0044 
0045     // ---------- const member functions ---------------------
0046     double realTime() const;
0047 
0048     // ---------- static member functions --------------------
0049 
0050     // ---------- member functions ---------------------------
0051     void start();
0052     double stop();  //returns delta time
0053     void reset();
0054 
0055     void add(double t);
0056 
0057   private:
0058     double calculateDeltaTime() const;
0059 
0060     // ---------- member data --------------------------------
0061     enum State { kRunning, kStopped } state_;
0062 #ifdef USE_CLOCK_GETTIME
0063     struct timespec startRealTime_;
0064 #else
0065     struct timeval startRealTime_;
0066 #endif
0067 
0068     double accumulatedRealTime_;
0069   };
0070 }  // namespace edm
0071 
0072 #endif