xrootd
|
00001 #ifndef __XrdSysTimer__ 00002 #define __XrdSysTimer__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S y s T i m e r . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id$ 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 /* This include file describes the oo elapsed time interval interface. It is 00024 used by the oo Real Time Monitor, among others. 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 // The following routines return the current interval added to the 00037 // passed argument as well as returning the current Unix seconds 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; // Current running clock 00063 struct timeval LastReport; // Total time from last report 00064 00065 unsigned long Report(); // Place interval in Last Report 00066 }; 00067 #endif