00001 #ifndef _UT_StopWatch_h_
00002 #define _UT_StopWatch_h_
00003
00004 #include "UT_API.h"
00005 #include <time.h>
00006 #include <stdlib.h>
00007 #include <SYS/SYS_Time.h>
00008 #include <SYS/SYS_Types.h>
00009
00010 typedef SYS_TimeVal UT_TIMERVAL;
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 class UT_API UT_StopWatch
00024 {
00025 public:
00026 UT_StopWatch();
00027
00028 void clear();
00029 void start();
00030 fpreal64 lap() const;
00031 fpreal64 stop();
00032 void resume();
00033
00034 fpreal64 getTime() const;
00035 bool isRunning() const;
00036
00037 fpreal64 operator-( const UT_StopWatch & );
00038
00039
00040 static fpreal64 _timeDiff(const UT_TIMERVAL &later, const UT_TIMERVAL &sooner);
00041
00042 protected:
00043 bool _running;
00044 fpreal64 _elapsedTime;
00045
00046 UT_TIMERVAL _startTime;
00047 };
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 class UT_API UT_Timer
00068 {
00069 public:
00070 UT_Timer();
00071 explicit UT_Timer(const char *block_name);
00072
00073 ~UT_Timer();
00074
00075 static void indent();
00076
00077 static void timeStamp(const char *msg1, const char *msg2=0);
00078
00079 void clear();
00080
00081 void begin( const char *block_name = NULL );
00082
00083 void end();
00084
00085 fpreal64 getBlockDuration();
00086 fpreal64 getTotalDuration();
00087 fpreal64 getAverageDuration();
00088
00089 void setDisplay( bool d ) { myDisplay = d; }
00090
00091 void displayBlockDuration( const char *block_name = NULL );
00092 void displayTotalDuration( const char *block_name = NULL );
00093 void displayAverageDuration( const char *block_name = NULL );
00094
00095 static UT_Timer *getTimer(int id);
00096
00097 private:
00098 bool myBegun;
00099 bool myDisplay;
00100 UT_StopWatch myBlockTimer;
00101 UT_StopWatch mySavedBlockTimer;
00102 fpreal64 myTotal;
00103 int myCount;
00104
00105 static int theIndentation;
00106 static UT_StopWatch theLastBlockTimer;
00107 };
00108
00109 class UT_API UT_TimerAuto
00110 {
00111 public:
00112 UT_TimerAuto(UT_Timer &ts, const char *name): myTimeStamp( ts )
00113 {
00114 myTimeStamp.begin( name );
00115 }
00116
00117 UT_TimerAuto(UT_Timer &ts): myTimeStamp( ts )
00118 {
00119 myTimeStamp.begin();
00120 }
00121
00122 ~UT_TimerAuto()
00123 {
00124 myTimeStamp.end();
00125 }
00126
00127 UT_Timer &myTimeStamp;
00128 };
00129
00130 #endif // _UT_StopWatch_h_