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 77 of file XrdSysTimer.cc.

78 {
79  time_t add_time;
80 
81 // Compute time at midnight, today (tnow 0) or at the end of today (tnow 1)
82 //
83  if (tnow == 0 || tnow == 1) {add_time = tnow; tnow = time(0);}
84  else add_time = 0;
85 
86  time_t midnight = tnow - SecondsOfDay(tnow);
87  if (add_time) midnight += 86400;
88 
89 // On the day of a daylight saving change, a day is not 86400 seconds long, and
90 // the result can be an hour off. Correct it to the nearest local midnight. In
91 // a zone where the clock jumps from 00:00 to 01:00, the day has no midnight
92 // and starts at the change; a step back from it would give 23:00 of the day
93 // before, thus keep the result when the step back does not end at midnight.
94 //
95  long secs = SecondsOfDay(midnight);
96  if (secs >= 43200) midnight += 86400 - secs;
97  else if (secs && !SecondsOfDay(midnight - secs)) midnight -= secs;
98  return midnight;
99 }

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 128 of file XrdSysTimer.cc.

129 {
130  unsigned long report_time = Report();
131 
132 // Add up the time as a double
133 //
134  Total_Time += static_cast<double>(LastReport.tv_sec) +
135  static_cast<double>(LastReport.tv_usec/1000)/1000.0;
136 
137 // Return time
138 //
139  return report_time;
140 }
unsigned long Report(double &)
Definition: XrdSysTimer.cc:128

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 176 of file XrdSysTimer.cc.

177 {
178  unsigned long report_time = Report();
179 
180 // Add the interval to the interval total time so far
181 //
182  Total_Time.tv_sec += LastReport.tv_sec;
183  Total_Time.tv_usec += LastReport.tv_usec;
184  if (Total_Time.tv_usec > 1000000) {Total_Time.tv_sec++;
185  Total_Time.tv_usec -= 1000000;}
186 
187 // Return time
188 //
189  return report_time;
190 }

References Report().

+ Here is the call graph for this function:

◆ Report() [3/4]

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

Definition at line 144 of file XrdSysTimer.cc.

145 {
146  unsigned long report_time = Report();
147 
148 // Add up the time as a 32-bit value to nearest milliseconds (max = 24 days)
149 //
150  Total_Time += (unsigned long)LastReport.tv_sec*1000 +
151  (unsigned long)(LastReport.tv_usec/1000);
152 
153 // Return time
154 //
155  return report_time;
156 }

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 160 of file XrdSysTimer.cc.

161 {
162  unsigned long report_time = Report();
163 
164 // Add up the time as a 64-bit value to nearest milliseconds
165 //
166  Total_Time += (unsigned long long)LastReport.tv_sec*1000 +
167  (unsigned long long)(LastReport.tv_usec/1000);
168 
169 // Return time
170 //
171  return report_time;
172 }

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 220 of file XrdSysTimer.cc.

221 {
222  int hours, minutes;
223 
224  minutes = sec/60;
225  sec = sec%60;
226  hours = minutes/60;
227  minutes = minutes%60;
228 
229  snprintf(buff, blen-1, "%d:%02d:%02d", hours, minutes, sec);
230  buff[blen-1] = '\0';
231  return buff;
232 }

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 196 of file XrdSysTimer.cc.

197 {
198 #ifndef WIN32
199  struct timespec naptime, waketime;
200 
201 // Calculate nano sleep time
202 //
203  naptime.tv_sec = sec;
204  naptime.tv_nsec = 0;
205 
206 // Wait for a lsoppy number of seconds
207 //
208  while(nanosleep(&naptime, &waketime) && EINTR == errno)
209  {naptime.tv_sec = waketime.tv_sec;
210  naptime.tv_nsec = waketime.tv_nsec;
211  }
212 #else
213  ::Sleep(sec*1000);
214 #endif
215 }

Referenced by XrdPosixFile::DelayedDestroy(), XrdCmsNode::Delete(), XrdOssArcStopMon::DoIt(), 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 238 of file XrdSysTimer.cc.

239 {
240  time_t currTime = time(0);
241  time_t currTimeGMT = 0;
242  tm ptm;
243 
244  gmtime_r( &currTime, &ptm );
245  currTimeGMT = mktime( &ptm );
246  currTime /= 60*60;
247  currTimeGMT /= 60*60;
248  return currTime - currTimeGMT;
249 }

◆ Wait()

void XrdSysTimer::Wait ( int  milliseconds)
static

Definition at line 255 of file XrdSysTimer.cc.

256 {
257 #ifndef WIN32
258  struct timespec naptime, waketime;
259 
260 // Calculate nano sleep time
261 //
262  naptime.tv_sec = mills/1000;
263  naptime.tv_nsec = (mills%1000)*1000000;
264 
265 // Wait for exactly x milliseconds
266 //
267  while(nanosleep(&naptime, &waketime) && EINTR == errno)
268  {naptime.tv_sec = waketime.tv_sec;
269  naptime.tv_nsec = waketime.tv_nsec;
270  }
271 #else
272  ::Sleep(mills);
273 #endif
274 }

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 280 of file XrdSysTimer.cc.

281 {
282 
283 // Wait until midnight arrives
284 //
285 #ifndef __APPLE__
286  timespec Midnite = {Midnight(1), 0};
287  while(clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&Midnite,0) == EINTR) {}
288 #else
289  timespec tleft, Midnite = {Midnight(1) - time(0), 0};
290  int ntpWait = 60;
291 do{while(nanosleep(&Midnite, &tleft) && EINTR == errno)
292  {Midnite.tv_sec = tleft.tv_sec;
293  Midnite.tv_nsec = tleft.tv_nsec;
294  }
295  if (Midnight(1) - time(0) >= 60) break;
296  Midnite.tv_sec = 1;
297  Midnite.tv_nsec = 0;
298  } while(ntpWait--); // This avoids multiple wakeups when NTP adjusts clock
299 #endif
300 }
static time_t Midnight(time_t tnow=0)
Definition: XrdSysTimer.cc:77

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: