00001 #ifndef __XrdSysTimer__
00002 #define __XrdSysTimer__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef WIN32
00016 #include <sys/time.h>
00017 #else
00018 #include <time.h>
00019 #include <Winsock2.h>
00020 #include "XrdSys/XrdWin32.hh"
00021 #endif
00022
00023
00024
00025
00026
00027 class XrdSysTimer {
00028
00029 public:
00030 struct timeval *Delta_Time(struct timeval &tbeg);
00031
00032 static time_t Midnight(time_t tnow=0);
00033
00034 inline int TimeLE(time_t tsec) {return StopWatch.tv_sec <= tsec;}
00035
00036
00037
00038
00039 unsigned long Report(double &);
00040 unsigned long Report(unsigned long &);
00041 unsigned long Report(unsigned long long &);
00042 unsigned long Report(struct timeval &);
00043
00044 inline void Reset() {gettimeofday(&StopWatch, 0);}
00045
00046 inline time_t Seconds() {return StopWatch.tv_sec;}
00047
00048 inline void Set(struct timeval &tod)
00049 {StopWatch.tv_sec = tod.tv_sec;
00050 StopWatch.tv_usec = tod.tv_usec;
00051 }
00052
00053 static void Snooze(int seconds);
00054
00055 static char *s2hms(int sec, char *buff, int blen);
00056
00057 static void Wait(int milliseconds);
00058
00059 XrdSysTimer() {Reset();}
00060
00061 private:
00062 struct timeval StopWatch;
00063 struct timeval LastReport;
00064
00065 unsigned long Report();
00066 };
00067 #endif