File indexing completed on 2024-04-06 12:13:11
0001 #ifndef FWCore_Utilities_CPUTimer_h
0002 #define FWCore_Utilities_CPUTimer_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #ifdef __linux__
0023
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
0034
0035
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
0052 double realTime() const;
0053 double cpuTime() const;
0054
0055
0056
0057
0058 void start();
0059 Times stop();
0060 void reset();
0061
0062 void add(const Times& t);
0063
0064 private:
0065 Times calculateDeltaTime() const;
0066
0067
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 }
0081
0082 #endif