The Gaudi Framework  v36r9p1 (5c15b2bb)
Gaudi::Timers::RdtscClock< Precision > Class Template Reference

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

#include </builds/gaudi/Gaudi/GaudiKernel/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 37 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 42 of file RdtscClock.h.

◆ period

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

Definition at line 41 of file RdtscClock.h.

◆ rep

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

Definition at line 40 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 43 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 53 of file RdtscClock.h.

53 { return ticks_per_unit(); }

◆ do_calibrate()

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

Definition at line 63 of file RdtscClock.h.

63  {
64  // Calibration time and conversion factor to unit of Precision
65  static constexpr auto calibTime = std::chrono::milliseconds( 100 );
66  static constexpr auto toPrec = std::ratio_divide<std::milli, period>::num;
67 
68  // Calibrate against wall clock
70  auto t1 = __rdtsc();
71  std::this_thread::sleep_for( calibTime );
72  auto t2 = __rdtsc();
74 
75  // Calculate ticks per unit of Precision
76  auto dt_ref = std::chrono::duration_cast<std::chrono::milliseconds>( t2_ref - t1_ref ).count();
77  rep ticks_per_unit = ( t2 - t1 ) / ( dt_ref * toPrec );
78 
79  return ticks_per_unit;
80  }

◆ now()

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

Definition at line 55 of file RdtscClock.h.

55 { return time_point{ duration( __rdtsc() / ticks_per_unit() ) }; }

◆ ticks_per_unit()

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

Definition at line 58 of file RdtscClock.h.

58  {
59  static rep ticks_per_unit = do_calibrate(); // local static guarantees thread-safety
60  return ticks_per_unit;
61  }

Member Data Documentation

◆ is_steady

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

Definition at line 45 of file RdtscClock.h.


The documentation for this class was generated from the following file:
std::this_thread::sleep_for
T sleep_for(T... args)
Gaudi::Timers::RdtscClock::duration
std::chrono::duration< rep, period > duration
Definition: RdtscClock.h:42
Gaudi::Timers::RdtscClock::time_point
std::chrono::time_point< RdtscClock > time_point
Definition: RdtscClock.h:43
std::chrono::milliseconds
TemplatedAlg
Definition: TemplatedAlg.h:25
std::ratio_divide
Gaudi::Timers::RdtscClock::ticks_per_unit
static rep ticks_per_unit() noexcept
Definition: RdtscClock.h:58
Gaudi::Timers::RdtscClock::do_calibrate
static rep do_calibrate() noexcept
Definition: RdtscClock.h:63
t1
TemplatedAlg< int, std::vector< std::string > > t1
Definition: TemplatedAlg.cpp:21
Gaudi::Timers::RdtscClock::rep
Precision::rep rep
Definition: RdtscClock.h:40
std::chrono::high_resolution_clock::now
T now(T... args)