| The Gaudi Framework v32r1 (f65d50dc)

Public Types | Static Public Member Functions | Static Public Attributes | Static Private Member Functions | List of all members
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, period > | duration
typedef std::chrono::time_point< RdtscClock > | time_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 | ( |  | ) |
| inline static noexcept

Calibrate the RDTSC clock against wall time.

Definition at line 39 of file RdtscClock.h.

39 { return ticks_per_unit(); }
Gaudi::Timers::RdtscClock::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 | ( |  | ) |
| inline static private noexcept

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
55 auto t1_ref = std::chrono::high_resolution_clock::now();
56 auto t1 = __rdtsc();
57 std::this_thread::sleep_for( calibTime );
58 auto t2 = __rdtsc();
59 auto t2_ref = std::chrono::high_resolution_clock::now();
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 }
std::chrono::milliseconds
Gaudi::Timers::RdtscClock::rep
Precision::rep rep
Definition: RdtscClock.h:26
Gaudi::Timers::RdtscClock::ticks_per_unit
static rep ticks_per_unit() noexcept
Definition: RdtscClock.h:44
std::this_thread::sleep_for
T sleep_for(T... args)
std::chrono::high_resolution_clock::now
T now(T... args)
std::ratio_divide

## ◆ now()

template<typename Precision = std::chrono::microseconds>

static time_point Gaudi::Timers::RdtscClock< Precision >::now | ( |  | ) |
| inline static noexcept

Definition at line 41 of file RdtscClock.h.

41 { return time_point{duration( __rdtsc() / ticks_per_unit() )}; }
Gaudi::Timers::RdtscClock::ticks_per_unit
static rep ticks_per_unit() noexcept
Definition: RdtscClock.h:44
Gaudi::Timers::RdtscClock::duration
std::chrono::duration< rep, period > duration
Definition: RdtscClock.h:28
Gaudi::Timers::RdtscClock::time_point
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 | ( |  | ) |
| inline static private noexcept

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 }
Gaudi::Timers::RdtscClock::rep
Precision::rep rep
Definition: RdtscClock.h:26
Gaudi::Timers::RdtscClock::do_calibrate
static rep do_calibrate() noexcept
Definition: RdtscClock.h:49
Gaudi::Timers::RdtscClock::ticks_per_unit
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:

- GaudiKernel/Gaudi/Timers/RdtscClock.h