CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/Utilities/Timing/interface/LinuxCPUTime.h

Go to the documentation of this file.
00001 #ifndef UTILITIES_TIMING_LINUXCPUTIME_H
00002 #define UTILITIES_TIMING_LINUXCPUTIME_H
00003 //
00004 //   V 0.0 
00005 //
00006 
00007 
00008 #include <iosfwd>
00009 #include <string>
00010 #include <fstream>
00011 #include "ctime"
00012 #include "Utilities/Timing/interface/GenTimer.h"
00013 
00016 class LinuxCPUTime {
00017 public:
00018 
00019    typedef double TimeType;
00020 
00021 
00023   explicit LinuxCPUTime(int pid=0): 
00024     utime_(std::clock()/CLOCKS_PER_SEC), stime_(0) {
00025   }
00026 
00028   ~LinuxCPUTime(){}
00029 
00031   inline TimeType utime() const { return utime_;}
00032   inline TimeType stime() const { return stime_;}
00033   inline TimeType cputime() const { return utime_+stime_;}
00034   inline TimeType operator()() const { return cputime();}
00035 
00036 private:
00037   TimeType utime_;
00038   TimeType stime_;
00039 };
00040 
00041 class LinuxElapsedTime {
00042 public:
00043   static std::ostream * dout;
00044   LinuxElapsedTime(const std::string & iname="Total",
00045                    std::ostream & iout=*dout) : out(iout), name(iname){}
00046   ~LinuxElapsedTime();
00047 
00048 private:
00049   std::ostream & out;
00050   std::string name;
00051   LinuxCPUTime begin;
00052 };
00053 
00054 
00055 struct LCPUTime {
00056 
00057   struct OneTick {
00058     OneTick() : one(0.01) {}
00059     
00060     double one;
00061   };
00062   
00063   static double oneTick() {
00064     static OneTick local;
00065     return local.one;
00066   };
00067 
00068 
00069   typedef GenTimeInterval<LCPUTime> TimeInterval;
00070   typedef LinuxCPUTime::TimeType IntervalType;
00071   typedef LinuxCPUTime::TimeType TimeType;
00072 
00073   inline static TimeType time() { LinuxCPUTime a; return a();}
00074   inline static TimeType time(int pid) { LinuxCPUTime a(pid); return a();}
00075 
00076 };
00077 
00078 typedef GenTimer<LCPUTime> LinuxCPUTimer; 
00079 
00080 
00081 #endif // UTILITIES_TIMING_LINUXCPUTIME_H