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 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #ifndef WIN32 00033 #include <sys/time.h> 00034 #else 00035 #include <time.h> 00036 #include <Winsock2.h> 00037 #include "XrdSys/XrdWin32.hh" 00038 #endif 00039 00040 /* This include file describes the oo elapsed time interval interface. It is 00041 used by the oo Real Time Monitor, among others. 00042 */ 00043 00044 class XrdSysTimer { 00045 00046 public: 00047 struct timeval *Delta_Time(struct timeval &tbeg); 00048 00049 static time_t Midnight(time_t tnow=0); 00050 00051 inline int TimeLE(time_t tsec) {return StopWatch.tv_sec <= tsec;} 00052 00053 // The following routines return the current interval added to the 00054 // passed argument as well as returning the current Unix seconds 00055 // 00056 unsigned long Report(double &); 00057 unsigned long Report(unsigned long &); 00058 unsigned long Report(unsigned long long &); 00059 unsigned long Report(struct timeval &); 00060 00061 inline void Reset() {gettimeofday(&StopWatch, 0);} 00062 00063 inline time_t Seconds() {return StopWatch.tv_sec;} 00064 00065 inline void Set(struct timeval &tod) 00066 {StopWatch.tv_sec = tod.tv_sec; 00067 StopWatch.tv_usec = tod.tv_usec; 00068 } 00069 00070 static void Snooze(int seconds); 00071 00072 static char *s2hms(int sec, char *buff, int blen); 00073 00074 static int TimeZone(); 00075 00076 static void Wait(int milliseconds); 00077 00078 static void Wait4Midnight(); 00079 00080 XrdSysTimer() {Reset();} 00081 00082 private: 00083 struct timeval StopWatch; // Current running clock 00084 struct timeval LastReport; // Total time from last report 00085 00086 unsigned long Report(); // Place interval in Last Report 00087 }; 00088 #endif