XRootD
XrdSysTimer Class Reference

#include <XrdSysTimer.hh>

+ Collaboration diagram for XrdSysTimer:

Public Member Functions

 XrdSysTimer ()
 
struct timeval * Delta_Time (struct timeval &tbeg)
 
unsigned long Report (double &)
 
unsigned long Report (struct timeval &)
 
unsigned long Report (unsigned long &)
 
unsigned long Report (unsigned long long &)
 
void Reset ()
 
time_t Seconds ()
 
void Set (struct timeval &tod)
 
int TimeLE (time_t tsec)
 

Static Public Member Functions

static time_t Midnight (time_t tnow=0)
 
static char * s2hms (int sec, char *buff, int blen)
 
static void Snooze (int seconds)
 
static int TimeZone ()
 
static void Wait (int milliseconds)
 
static void Wait4Midnight ()
 

Detailed Description

Definition at line 44 of file XrdSysTimer.hh.

Constructor & Destructor Documentation

◆ XrdSysTimer()

XrdSysTimer::XrdSysTimer ( )
inline

Definition at line 80 of file XrdSysTimer.hh.

80 {Reset();}
void Reset()
Definition: XrdSysTimer.hh:61

References Reset().

+ Here is the call graph for this function:

Member Function Documentation

◆ Delta_Time()

struct timeval * XrdSysTimer::Delta_Time ( struct timeval &  tbeg)

Definition at line 45 of file XrdSysTimer.cc.

46 {
47  gettimeofday(&LastReport, 0);
48  LastReport.tv_sec = LastReport.tv_sec - tbeg.tv_sec;
49  LastReport.tv_usec = LastReport.tv_usec - tbeg.tv_usec;
50  if (LastReport.tv_usec < 0) {LastReport.tv_sec--; LastReport.tv_usec += 1000000;}
51  return &LastReport;
52 }

◆ Midnight()

time_t XrdSysTimer::Midnight ( time_t  tnow = 0)
static

Definition at line 58 of file XrdSysTimer.cc.

59 {
60  struct tm midtime;
61  time_t add_time;
62 
63 // Compute time at midnight
64 //
65  if (tnow == 0 || tnow == 1) {add_time = tnow; tnow = time(0);}
66  else add_time = 0;
67  localtime_r((const time_t *) &tnow, &midtime);
68  if (add_time) {midtime.tm_hour = 23; midtime.tm_min = midtime.tm_sec = 59;}
69  else midtime.tm_hour = midtime.tm_min = midtime.tm_sec = 0;
70  return mktime(&midtime) + add_time;
71 }

Referenced by getXDate(), and Wait4Midnight().

+ Here is the caller graph for this function:

◆ Report() [1/4]

unsigned long XrdSysTimer::Report ( double &  Total_Time)

Definition at line 100 of file XrdSysTimer.cc.

101 {
102  unsigned long report_time = Report();
103 
104 // Add up the time as a double
105 //
106  Total_Time += static_cast<double>(LastReport.tv_sec) +
107  static_cast<double>(LastReport.tv_usec/1000)/1000.0;
108 
109 // Return time
110 //
111  return report_time;
112 }
unsigned long Report(double &)
Definition: XrdSysTimer.cc:100

References Report().

Referenced by Report().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Report() [2/4]

unsigned long XrdSysTimer::Report ( struct timeval &  Total_Time)

Definition at line 148 of file XrdSysTimer.cc.

149 {
150  unsigned long report_time = Report();
151 
152 // Add the interval to the interval total time so far
153 //
154  Total_Time.tv_sec += LastReport.tv_sec;
155  Total_Time.tv_usec += LastReport.tv_usec;
156  if (Total_Time.tv_usec > 1000000) {Total_Time.tv_sec++;
157  Total_Time.tv_usec -= 1000000;}
158 
159 // Return time
160 //
161  return report_time;
162 }

References Report().

+ Here is the call graph for this function:

◆ Report() [3/4]

unsigned long XrdSysTimer::Report ( unsigned long &  Total_Time)

Definition at line 116 of file XrdSysTimer.cc.

117 {
118  unsigned long report_time = Report();
119 
120 // Add up the time as a 32-bit value to nearest milliseconds (max = 24 days)
121 //
122  Total_Time += (unsigned long)LastReport.tv_sec*1000 +
123  (unsigned long)(LastReport.tv_usec/1000);
124 
125 // Return time
126 //
127  return report_time;
128 }

References Report().

+ Here is the call graph for this function:

◆ Report() [4/4]

unsigned long XrdSysTimer::Report ( unsigned long long &  Total_Time)

Definition at line 132 of file XrdSysTimer.cc.

133 {
134  unsigned long report_time = Report();
135 
136 // Add up the time as a 64-bit value to nearest milliseconds
137 //
138  Total_Time += (unsigned long long)LastReport.tv_sec*1000 +
139  (unsigned long long)(LastReport.tv_usec/1000);
140 
141 // Return time
142 //
143  return report_time;
144 }

References Report().

+ Here is the call graph for this function:

◆ Reset()

void XrdSysTimer::Reset ( )
inline

Definition at line 61 of file XrdSysTimer.hh.

61 {gettimeofday(&StopWatch, 0);}

Referenced by XrdSysTimer().

+ Here is the caller graph for this function:

◆ s2hms()

char * XrdSysTimer::s2hms ( int  sec,
char *  buff,
int  blen 
)
static

Definition at line 192 of file XrdSysTimer.cc.

193 {
194  int hours, minutes;
195 
196  minutes = sec/60;
197  sec = sec%60;
198  hours = minutes/60;
199  minutes = minutes%60;
200 
201  snprintf(buff, blen-1, "%d:%02d:%02d", hours, minutes, sec);
202  buff[blen-1] = '\0';
203  return buff;
204 }

Referenced by XrdXrootdProtocol::Recycle().

+ Here is the caller graph for this function:

◆ Seconds()

time_t XrdSysTimer::Seconds ( )
inline

Definition at line 63 of file XrdSysTimer.hh.

63 {return StopWatch.tv_sec;}

◆ Set()

void XrdSysTimer::Set ( struct timeval &  tod)
inline

Definition at line 65 of file XrdSysTimer.hh.

66  {StopWatch.tv_sec = tod.tv_sec;
67  StopWatch.tv_usec = tod.tv_usec;
68  }

◆ Snooze()

void XrdSysTimer::Snooze ( int  seconds)
static

Definition at line 168 of file XrdSysTimer.cc.

169 {
170 #ifndef WIN32
171  struct timespec naptime, waketime;
172 
173 // Calculate nano sleep time
174 //
175  naptime.tv_sec = sec;
176  naptime.tv_nsec = 0;
177 
178 // Wait for a lsoppy number of seconds
179 //
180  while(nanosleep(&naptime, &waketime) && EINTR == errno)
181  {naptime.tv_sec = waketime.tv_sec;
182  naptime.tv_nsec = waketime.tv_nsec;
183  }
184 #else
185  ::Sleep(sec*1000);
186 #endif
187 }

Referenced by XrdPosixFile::DelayedDestroy(), XrdCmsNode::Delete(), XrdFrmMonitor::Ident(), main(), XrdFrmMigrate::Migrate(), XrdCmsAdmin::MonAds(), XrdCmsCluster::MonPerf(), XrdCmsCluster::MonRefs(), XrdTlsCrl::Refresh(), XrdCmsMeter::Run(), XrdCmsFinderTRG::RunPM(), XrdCmsMeter::RunPM(), XrdOfsTPCAuth::RunTTL(), XrdCmsClientMan::Start(), XrdFrmXfrDaemon::Start(), XrdFrmXfrQueue::StopMon(), and XrdCmsCache::TickTock().

+ Here is the caller graph for this function:

◆ TimeLE()

int XrdSysTimer::TimeLE ( time_t  tsec)
inline

Definition at line 51 of file XrdSysTimer.hh.

51 {return StopWatch.tv_sec <= tsec;}

◆ TimeZone()

int XrdSysTimer::TimeZone ( )
static

Definition at line 210 of file XrdSysTimer.cc.

211 {
212  time_t currTime = time(0);
213  time_t currTimeGMT = 0;
214  tm ptm;
215 
216  gmtime_r( &currTime, &ptm );
217  currTimeGMT = mktime( &ptm );
218  currTime /= 60*60;
219  currTimeGMT /= 60*60;
220  return currTime - currTimeGMT;
221 }

◆ Wait()

void XrdSysTimer::Wait ( int  milliseconds)
static

Definition at line 227 of file XrdSysTimer.cc.

228 {
229 #ifndef WIN32
230  struct timespec naptime, waketime;
231 
232 // Calculate nano sleep time
233 //
234  naptime.tv_sec = mills/1000;
235  naptime.tv_nsec = (mills%1000)*1000000;
236 
237 // Wait for exactly x milliseconds
238 //
239  while(nanosleep(&naptime, &waketime) && EINTR == errno)
240  {naptime.tv_sec = waketime.tv_sec;
241  naptime.tv_nsec = waketime.tv_nsec;
242  }
243 #else
244  ::Sleep(mills);
245 #endif
246 }

Referenced by XrdPosixObject::Dir(), XrdCmsConfig::DoIt(), XrdPosixObject::File(), XrdOfsEvr::flushEvents(), XrdCmsFinderRMT::Forward(), XrdSutPFCache::Get(), XrdCmsBaseFS::Pacer(), XrdPfc::Cache::Prefetch(), XrdCmsFinderRMT::Prepare(), XrdBuffManager::Reshape(), XrdCl::TaskManager::RunTasks(), XrdCmsFinderTRG::Start(), and XrdCmsRRQ::TimeOut().

+ Here is the caller graph for this function:

◆ Wait4Midnight()

void XrdSysTimer::Wait4Midnight ( )
static

Definition at line 252 of file XrdSysTimer.cc.

253 {
254 
255 // Wait until midnight arrives
256 //
257 #ifndef __APPLE__
258  timespec Midnite = {Midnight(1), 0};
259  while(clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&Midnite,0) == EINTR) {}
260 #else
261  timespec tleft, Midnite = {Midnight(1) - time(0), 0};
262  int ntpWait = 60;
263 do{while(nanosleep(&Midnite, &tleft) && EINTR == errno)
264  {Midnite.tv_sec = tleft.tv_sec;
265  Midnite.tv_nsec = tleft.tv_nsec;
266  }
267  if (Midnight(1) - time(0) >= 60) break;
268  Midnite.tv_sec = 1;
269  Midnite.tv_nsec = 0;
270  } while(ntpWait--); // This avoids multiple wakeups when NTP adjusts clock
271 #endif
272 }
static time_t Midnight(time_t tnow=0)
Definition: XrdSysTimer.cc:58

References Midnight().

Referenced by XrdSysLogger::zHandler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: