The Gaudi Framework  v32r2 (46d42edc)
Gaudi::Timers::RdtscClock< Precision > Class Template Reference

A std::chrono compatible Clock using rdtsc as its timing source. More...

#include <Gaudi/Timers/RdtscClock.h>

Public Types

typedef Precision::rep rep
 
typedef Precision::period period
 
typedef std::chrono::duration< rep, periodduration
 
typedef std::chrono::time_point< RdtscClocktime_point
 

Static Public Member Functions

static rep calibrate () noexcept
 Calibrate the RDTSC clock against wall time. More...
 
static time_point now () noexcept
 

Static Public Attributes

static constexpr bool is_steady {true}
 

Static Private Member Functions

static rep ticks_per_unit () noexcept
 
static rep do_calibrate () noexcept
 

Detailed Description

template<typename Precision = std::chrono::microseconds>
class Gaudi::Timers::RdtscClock< Precision >

A std::chrono compatible Clock using rdtsc as its timing source.

This clock is not directly related to wall time but meant as a low-overhead time interval measurement. The Precision template parameter determines the internal precision of the clock (e.g. std::milli, std::micro). On first invocation of now() the timer is calibrated against a wall-time clock, which will have an overhead of several milliseconds. This can be avoided by calling calibrate() explicitly before the first measurement.

Definition at line 23 of file RdtscClock.h.

Member Typedef Documentation

◆ duration

template<typename Precision = std::chrono::microseconds>
typedef std::chrono::duration<rep, period> Gaudi::Timers::RdtscClock< Precision >::duration

Definition at line 28 of file RdtscClock.h.

◆ period

template<typename Precision = std::chrono::microseconds>
typedef Precision::period Gaudi::Timers::RdtscClock< Precision >::period

Definition at line 27 of file RdtscClock.h.

◆ rep

template<typename Precision = std::chrono::microseconds>
typedef Precision::rep Gaudi::Timers::RdtscClock< Precision >::rep

Definition at line 26 of file RdtscClock.h.

◆ time_point

template<typename Precision = std::chrono::microseconds>
typedef std::chrono::time_point<RdtscClock> Gaudi::Timers::RdtscClock< Precision >::time_point

Definition at line 29 of file RdtscClock.h.

Member Function Documentation

◆ calibrate()

template<typename Precision = std::chrono::microseconds>
static rep Gaudi::Timers::RdtscClock< Precision >::calibrate ( )
inlinestaticnoexcept

Calibrate the RDTSC clock against wall time.

Definition at line 39 of file RdtscClock.h.

39 { return ticks_per_unit(); }
static rep ticks_per_unit() noexcept
Definition: RdtscClock.h:44

◆ do_calibrate()

template<typename Precision = std::chrono::microseconds>
static rep Gaudi::Timers::RdtscClock< Precision >::do_calibrate ( )
inlinestaticprivatenoexcept

Definition at line 49 of file RdtscClock.h.

49  {
50  // Calibration time and conversion factor to unit of Precision
51  static constexpr auto calibTime = std::chrono::milliseconds( 100 );
52  static constexpr auto toPrec = std::ratio_divide<std::milli, period>::num;
53 
54  // Calibrate against wall clock
56  auto t1 = __rdtsc();
57  std::this_thread::sleep_for( calibTime );
58  auto t2 = __rdtsc();
60 
61  // Calculate ticks per unit of Precision
62  auto dt_ref = std::chrono::duration_cast<std::chrono::milliseconds>( t2_ref - t1_ref ).count();
63  rep ticks_per_unit = ( t2 - t1 ) / ( dt_ref * toPrec );
64 
65  return ticks_per_unit;
66  }
Precision::rep rep
Definition: RdtscClock.h:26
static rep ticks_per_unit() noexcept
Definition: RdtscClock.h:44
T sleep_for(T... args)

◆ now()

template<typename Precision = std::chrono::microseconds>
static time_point Gaudi::Timers::RdtscClock< Precision >::now ( )
inlinestaticnoexcept

Definition at line 41 of file RdtscClock.h.

41 { return time_point{duration( __rdtsc() / ticks_per_unit() )}; }
static rep ticks_per_unit() noexcept
Definition: RdtscClock.h:44
std::chrono::duration< rep, period > duration
Definition: RdtscClock.h:28
std::chrono::time_point< RdtscClock > time_point
Definition: RdtscClock.h:29

◆ ticks_per_unit()

template<typename Precision = std::chrono::microseconds>
static rep Gaudi::Timers::RdtscClock< Precision >::ticks_per_unit ( )
inlinestaticprivatenoexcept

Definition at line 44 of file RdtscClock.h.

44  {
45  static rep ticks_per_unit = do_calibrate(); // local static guarantees thread-safety
46  return ticks_per_unit;
47  }
Precision::rep rep
Definition: RdtscClock.h:26
static rep do_calibrate() noexcept
Definition: RdtscClock.h:49
static rep ticks_per_unit() noexcept
Definition: RdtscClock.h:44

Member Data Documentation

◆ is_steady

template<typename Precision = std::chrono::microseconds>
constexpr bool Gaudi::Timers::RdtscClock< Precision >::is_steady {true}
static

Definition at line 31 of file RdtscClock.h.


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