CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/FWCore/Utilities/interface/CPUTimer.h

Go to the documentation of this file.
00001 #ifndef FWCore_Utilities_CPUTimer_h
00002 #define FWCore_Utilities_CPUTimer_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Utilities
00006 // Class  :     CPUTimer
00007 // 
00016 //
00017 // Original Author:  Chris Jones
00018 //         Created:  Sun Apr 16 20:32:13 EDT 2006
00019 // $Id: CPUTimer.h,v 1.4 2010/10/30 01:30:57 chrjones Exp $
00020 //
00021 
00022 // system include files
00023 #ifdef __linux__
00024 //NOTE: clock_gettime is not available on OS X and is slower
00025 // than getrusage and gettimeofday on linux but gives greater
00026 // timing accuracy so we may want to revisit this in the future
00027 //#define USE_CLOCK_GETTIME
00028 #endif
00029 
00030 #ifdef USE_CLOCK_GETTIME
00031 #include <time.h>
00032 #else
00033 #include <sys/time.h>
00034 #endif
00035 
00036 // user include files
00037 
00038 // forward declarations
00039 namespace edm {
00040 class CPUTimer
00041 {
00042 
00043    public:
00044       CPUTimer();
00045       virtual ~CPUTimer();
00046 
00047       struct Times {
00048          Times():real_(0),cpu_(0) {}
00049          double real_;
00050          double cpu_;
00051       };
00052    
00053    
00054       // ---------- const member functions ---------------------
00055       double realTime() const ;
00056       double cpuTime() const ;
00057       
00058       // ---------- static member functions --------------------
00059 
00060       // ---------- member functions ---------------------------
00061       void start();
00062       Times stop(); //returns delta time
00063       void reset();
00064       
00065       void add(const Times& t);
00066    private:
00067       CPUTimer(const CPUTimer&); // stop default
00068 
00069       const CPUTimer& operator=(const CPUTimer&); // stop default
00070 
00071       Times calculateDeltaTime() const;
00072       
00073       // ---------- member data --------------------------------
00074       enum State {kRunning, kStopped} state_;
00075 #ifdef USE_CLOCK_GETTIME
00076       struct timespec startRealTime_;
00077       struct timespec startCPUTime_;
00078 #else
00079       struct timeval startRealTime_;
00080       struct timeval startCPUTime_;
00081 #endif
00082    
00083       double accumulatedRealTime_;
00084       double accumulatedCPUTime_;
00085       
00086 };
00087 }
00088 
00089 #endif