xrootd
XrdSysTimer.hh
Go to the documentation of this file.
1 #ifndef __XrdSysTimer__
2 #define __XrdSysTimer__
3 /******************************************************************************/
4 /* */
5 /* X r d S y s T i m e r . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #ifndef WIN32
14 #include <sys/time.h>
15 #else
16 #include <time.h>
17 #include <Winsock2.h>
18 #include "XrdSys/XrdWin32.hh"
19 #endif
20 
21 /* This include file describes the oo elapsed time interval interface. It is
22  used by the oo Real Time Monitor, among others.
23 */
24 
25 class XrdSysTimer {
26 
27 public:
28  struct timeval *Delta_Time(struct timeval &tbeg);
29 
30 static time_t Midnight(time_t tnow=0);
31 
32 inline int TimeLE(time_t tsec) {return StopWatch.tv_sec <= tsec;}
33 
34  // The following routines return the current interval added to the
35  // passed argument as well as returning the current Unix seconds
36  //
37  unsigned long Report(double &);
38  unsigned long Report(unsigned long &);
39  unsigned long Report(unsigned long long &);
40  unsigned long Report(struct timeval &);
41 
42 inline void Reset() {gettimeofday(&StopWatch, 0);}
43 
44 inline time_t Seconds() {return StopWatch.tv_sec;}
45 
46 inline void Set(struct timeval &tod)
47  {StopWatch.tv_sec = tod.tv_sec;
48  StopWatch.tv_usec = tod.tv_usec;
49  }
50 
51 static void Snooze(int seconds);
52 
53 static char *s2hms(int sec, char *buff, int blen);
54 
55 static void Wait(int milliseconds);
56 
57 static void Wait4Midnight();
58 
60 
61 private:
62  struct timeval StopWatch; // Current running clock
63  struct timeval LastReport; // Total time from last report
64 
65  unsigned long Report(); // Place interval in Last Report
66 };
67 #endif