BALL
1.4.1
|
00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 // $Id: timer.h,v 1.17 2005/07/29 12:38:15 amoll Exp $ 00005 // 00006 00007 #ifndef BALL_SYSTEM_TIMER_H 00008 #define BALL_SYSTEM_TIMER_H 00009 00010 #ifndef BALL_COMMON_H 00011 # include <BALL/common.h> 00012 #endif 00013 00014 #ifdef BALL_HAS_SYS_TIME_H 00015 # include <sys/time.h> 00016 #endif 00017 #ifdef BALL_HAS_TIME_H 00018 # include <time.h> 00019 #endif 00020 00021 00022 00023 #include <iostream> 00024 00025 namespace BALL 00026 { 00030 class BALL_EXPORT Timer 00031 { 00032 public: 00033 00037 00041 Timer(); 00042 00046 Timer(Timer& timer); 00047 00051 virtual ~Timer(); 00052 00054 00057 00062 void clear(); 00063 00069 bool start(); 00070 00076 bool stop(); 00077 00082 void reset(); 00083 00085 00089 00093 double getClockTime() const; 00094 00098 double getUserTime() const; 00099 00103 double getSystemTime() const; 00104 00109 double getCPUTime() const; 00110 00112 00116 00122 Timer& operator = (const Timer& timer); 00123 00125 00129 00133 bool isRunning() const; 00134 00142 bool operator == (const Timer& timer) const; 00143 00151 bool operator != (const Timer& timer) const; 00152 00159 bool operator < (const Timer& timer) const; 00160 00167 bool operator <= (const Timer& timer) const; 00168 00175 bool operator >= (const Timer& timer) const; 00176 00183 bool operator > (const Timer& timer) const; 00184 00186 00189 00193 bool isValid() const; 00194 00197 void dump(::std::ostream& s = ::std::cout, Size depth = 0L) const; 00198 00200 00201 protected: 00202 00203 private: 00204 00205 static LongSize cpu_speed_; 00206 00207 #ifdef BALL_HAS_WINDOWS_PERFORMANCE_COUNTER 00208 static PointerSizeUInt clock_speed_; 00209 #endif 00210 00211 // state of timer, either true(on) or false(off) 00212 bool is_running_; 00213 00214 // clock seconds value when the timer was last started 00215 LongSize last_secs_; 00216 00217 // clock useconds value when the timer was last started 00218 LongSize last_usecs_; 00219 00220 // user time when the timer was last started 00221 clock_t last_user_time_; 00222 00223 // system time when the timer was last started 00224 clock_t last_system_time_; 00225 00226 // current accumulated clock seconds 00227 LongSize current_secs_; 00228 00229 // current accumulated clock useconds 00230 LongSize current_usecs_; 00231 00232 // current accumulated user time 00233 clock_t current_user_time_; 00234 00235 // current accumulated user time 00236 clock_t current_system_time_; 00237 }; 00238 00239 # ifndef BALL_NO_INLINE_FUNCTIONS 00240 # include "timer.iC" 00241 # endif 00242 00243 } 00244 00245 #endif // BALL_SYSTEM_TIMER_H