Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:11

0001 #ifndef FWCore_Utilities_CPUTimer_h
0002 #define FWCore_Utilities_CPUTimer_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Utilities
0006 // Class  :     CPUTimer
0007 //
0008 /**\class CPUTimer CPUTimer.h FWCore/Utilities/interface/CPUTimer.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 CPUTimer {
0038   public:
0039     CPUTimer();
0040     ~CPUTimer();
0041     CPUTimer(CPUTimer&&) = default;
0042     CPUTimer(const CPUTimer&) = delete;
0043     CPUTimer& operator=(const CPUTimer&) = delete;
0044 
0045     struct Times {
0046       Times() : real_(0), cpu_(0) {}
0047       double real_;
0048       double cpu_;
0049     };
0050 
0051     // ---------- const member functions ---------------------
0052     double realTime() const;
0053     double cpuTime() const;
0054 
0055     // ---------- static member functions --------------------
0056 
0057     // ---------- member functions ---------------------------
0058     void start();
0059     Times stop();  //returns delta time
0060     void reset();
0061 
0062     void add(const Times& t);
0063 
0064   private:
0065     Times calculateDeltaTime() const;
0066 
0067     // ---------- member data --------------------------------
0068     enum State { kRunning, kStopped } state_;
0069 #ifdef USE_CLOCK_GETTIME
0070     struct timespec startRealTime_;
0071     struct timespec startCPUTime_;
0072 #else
0073     struct timeval startRealTime_;
0074     struct timeval startCPUTime_;
0075 #endif
0076 
0077     double accumulatedRealTime_;
0078     double accumulatedCPUTime_;
0079   };
0080 }  // namespace edm
0081 
0082 #endif