LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Typedefs | Functions | Variables
LogCabin::Core::Time Namespace Reference

Classes

struct  CSystemClock
 Wall clock in nanosecond granularity. More...
struct  CSteadyClock
 Monotonic clock in nanosecond granularity. More...
struct  MockableClock
 Reads the current time. More...
class  SteadyTimeConverter
 Used to convert one or more SteadyClock::time_point values into values of the SystemClock. More...

Typedefs

typedef MockableClock
< std::chrono::steady_clock > 
SteadyClock
 The best available clock on this system for uses where a steady, monotonic clock is desired.
typedef MockableClock
< std::chrono::system_clock > 
SystemClock
 A clock that reads wall time and is affected by NTP adjustments.

Functions

int64_t parseSignedDuration (const std::string &description)
 Convert a human-readable description of a time duration into a number of nanoseconds.
uint64_t parseNonNegativeDuration (const std::string &description)
 Convert a human-readable description of a time duration into a number of nanoseconds.
void sleep (SteadyClock::time_point wake)
 Block the calling thread until the given time.
void sleep (std::chrono::nanoseconds duration)
 Block the calling thread for the given duration.
template<typename Clock , typename Duration >
struct timespec makeTimeSpec (const std::chrono::time_point< Clock, Duration > &when)
 Convert a C++11 time point into a POSIX timespec.
static __inline uint64_t rdtsc ()
 Read the CPU's cycle counter.

Variables

const clockid_t STEADY_CLOCK_ID
 The clock used by CSteadyClock.

Typedef Documentation

typedef MockableClock<std::chrono::steady_clock> LogCabin::Core::Time::SteadyClock

The best available clock on this system for uses where a steady, monotonic clock is desired.

Definition at line 166 of file Time.h.

typedef MockableClock<std::chrono::system_clock> LogCabin::Core::Time::SystemClock

A clock that reads wall time and is affected by NTP adjustments.

Definition at line 181 of file Time.h.


Function Documentation

int64_t LogCabin::Core::Time::parseSignedDuration ( const std::string &  description)

Convert a human-readable description of a time duration into a number of nanoseconds.

Parameters:
descriptionSomething like 10, 10s, -200ms, 3us, or -999ns. With no units, defaults to seconds. May be negative. Allowed units: ns, nanosecond(s), ms, millisecond(s), s, second(s), min, minute(s), h, hr, hour(s), d, day(s), w, wk, week(s), mo, month(s), y, yr, year(s).
Returns:
Number of nanoseconds, capped to the range of a signed 64-bit integer.
Exceptions:
std::runtime_errorIf description could not be parsed successfully.

Definition at line 60 of file Time.cc.

uint64_t LogCabin::Core::Time::parseNonNegativeDuration ( const std::string &  description)

Convert a human-readable description of a time duration into a number of nanoseconds.

Parameters:
descriptionSomething like 10, 10s, 200ms, 3us, or 999ns. With no units, defaults to seconds. May not be negative. Allowed units: ns, nanosecond(s), ms, millisecond(s), s, second(s), min, minute(s), h, hr, hour(s), d, day(s), w, wk, week(s), mo, month(s), y, yr, year(s).
Returns:
Number of nanoseconds, capped on the high end to the range of a signed 64-bit integer.
Exceptions:
std::runtime_errorIf description could not be parsed successfully.

Definition at line 178 of file Time.cc.

void LogCabin::Core::Time::sleep ( SteadyClock::time_point  wake)

Block the calling thread until the given time.

Definition at line 190 of file Time.cc.

void LogCabin::Core::Time::sleep ( std::chrono::nanoseconds  duration)

Block the calling thread for the given duration.

Definition at line 208 of file Time.cc.

template<typename Clock , typename Duration >
struct timespec LogCabin::Core::Time::makeTimeSpec ( const std::chrono::time_point< Clock, Duration > &  when) [read]

Convert a C++11 time point into a POSIX timespec.

Parameters:
whenTime point to convert.
Returns:
Time in seconds and nanoseconds relative to the Clock's epoch.

Definition at line 40 of file Time.h.

static __inline uint64_t LogCabin::Core::Time::rdtsc ( ) [static]

Read the CPU's cycle counter.

This is useful for benchmarking.

Definition at line 237 of file Time.h.


Variable Documentation

The clock used by CSteadyClock.

For now (2014), we can't use CLOCK_MONOTONIC_RAW in condition variables since glibc doesn't support that, so stick with CLOCK_MONOTONIC. This rate of this clock may change due to NTP adjustments, but at least it won't jump.

Definition at line 80 of file Time.h.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines