proxygen
folly::TimePoint Class Reference

#include <TimeUtil.h>

Public Member Functions

 TimePoint (bool set=true)
 
void reset ()
 
bool isUnset () const
 
std::chrono::steady_clock::time_point getTime () const
 
std::chrono::steady_clock::time_point getTimeStart () const
 
std::chrono::steady_clock::time_point getTimeEnd () const
 
std::chrono::nanoseconds getTimeWaiting () const
 
pid_t getTid () const
 

Private Attributes

std::chrono::steady_clock::time_point timeStart_
 
std::chrono::steady_clock::time_point timeEnd_
 
std::chrono::nanoseconds timeWaiting_ {0}
 
pid_t tid_
 

Detailed Description

A class for tracking time durations in test code.

This is primarily useful for testing timeout functionality. When comparing the differences between two TimePoints, it can exclude time spent waiting on the OS scheduler. This helps avoid spurious test failures when timeouts are exceeded by longer than expected simply because the underlying system was busy and could not schedule this thread in time.

Definition at line 34 of file TimeUtil.h.

Constructor & Destructor Documentation

folly::TimePoint::TimePoint ( bool  set = true)
inlineexplicit

Definition at line 36 of file TimeUtil.h.

References reset().

36  : tid_(0) {
37  if (set) {
38  reset();
39  }
40  }

Member Function Documentation

pid_t folly::TimePoint::getTid ( ) const
inline

Definition at line 66 of file TimeUtil.h.

References tid_.

Referenced by folly::checkTimeout(), and std::chrono::PrintTo().

66  {
67  return tid_;
68  }
std::chrono::steady_clock::time_point folly::TimePoint::getTime ( ) const
inline

Definition at line 50 of file TimeUtil.h.

References timeStart_.

Referenced by TEST(), and TEST_F().

50  {
51  return timeStart_;
52  }
std::chrono::steady_clock::time_point timeStart_
Definition: TimeUtil.h:71
std::chrono::steady_clock::time_point folly::TimePoint::getTimeEnd ( ) const
inline

Definition at line 58 of file TimeUtil.h.

References timeStart_.

Referenced by folly::checkTimeout(), folly::operator<<(), and TEST_F().

58  {
59  return timeStart_;
60  }
std::chrono::steady_clock::time_point timeStart_
Definition: TimeUtil.h:71
std::chrono::steady_clock::time_point folly::TimePoint::getTimeStart ( ) const
inline

Definition at line 54 of file TimeUtil.h.

References timeStart_.

Referenced by folly::checkTimeout(), folly::operator<<(), std::chrono::PrintTo(), and TEST_F().

54  {
55  return timeStart_;
56  }
std::chrono::steady_clock::time_point timeStart_
Definition: TimeUtil.h:71
std::chrono::nanoseconds folly::TimePoint::getTimeWaiting ( ) const
inline

Definition at line 62 of file TimeUtil.h.

References timeWaiting_.

Referenced by folly::checkTimeout(), folly::operator<<(), std::chrono::PrintTo(), and TEST_F().

62  {
63  return timeWaiting_;
64  }
std::chrono::nanoseconds timeWaiting_
Definition: TimeUtil.h:73
bool folly::TimePoint::isUnset ( ) const
inline

Definition at line 44 of file TimeUtil.h.

References timeEnd_, timeStart_, and timeWaiting_.

Referenced by TEST().

44  {
45  return (
46  timeStart_.time_since_epoch().count() == 0 &&
47  timeEnd_.time_since_epoch().count() == 0 && timeWaiting_.count() == 0);
48  }
std::chrono::steady_clock::time_point timeEnd_
Definition: TimeUtil.h:72
std::chrono::nanoseconds timeWaiting_
Definition: TimeUtil.h:73
std::chrono::steady_clock::time_point timeStart_
Definition: TimeUtil.h:71
void folly::TimePoint::reset ( )

Definition at line 221 of file TimeUtil.cpp.

References folly::getOSThreadID(), folly::getSchedTimeWaiting(), now(), and tid_.

Referenced by TEST(), TEST_F(), and TimePoint().

221  {
222  // Remember the current time
224 
225  // Remember how long this process has spent waiting to be scheduled
226  tid_ = getOSThreadID();
228 
229  // In case it took a while to read the schedstat info,
230  // also record the time after the schedstat check
232 }
std::chrono::steady_clock::time_point timeEnd_
Definition: TimeUtil.h:72
static nanoseconds getSchedTimeWaiting(pid_t tid)
Definition: TimeUtil.cpp:160
std::chrono::steady_clock::time_point now()
uint64_t getOSThreadID()
Definition: ThreadId.h:80
std::chrono::nanoseconds timeWaiting_
Definition: TimeUtil.h:73
std::chrono::steady_clock::time_point timeStart_
Definition: TimeUtil.h:71

Member Data Documentation

pid_t folly::TimePoint::tid_
private

Definition at line 74 of file TimeUtil.h.

Referenced by getTid().

std::chrono::steady_clock::time_point folly::TimePoint::timeEnd_
private

Definition at line 72 of file TimeUtil.h.

Referenced by isUnset().

std::chrono::steady_clock::time_point folly::TimePoint::timeStart_
private

Definition at line 71 of file TimeUtil.h.

Referenced by getTime(), getTimeEnd(), getTimeStart(), and isUnset().

std::chrono::nanoseconds folly::TimePoint::timeWaiting_ {0}
private

Definition at line 73 of file TimeUtil.h.

Referenced by getTimeWaiting(), and isUnset().


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