HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Data Structures | Public Member Functions | Static Public Member Functions
v1::time_stamp_count Class Reference

#include <hikogui/time/time_stamp_count.hpp>

Data Structures

struct  inplace
 
struct  inplace_with_cpu_id
 
struct  inplace_with_thread_id
 

Public Member Functions

constexpr time_stamp_count (uint64_t count, uint32_t aux) noexcept
 
 time_stamp_count (time_stamp_count::inplace) noexcept
 Use a constructor to in-place create the timestamp.
 
 time_stamp_count (time_stamp_count::inplace_with_cpu_id) noexcept
 Use a constructor to in-place create the timestamp.
 
 time_stamp_count (time_stamp_count::inplace_with_thread_id) noexcept
 Use a constructor to in-place create the timestamp.
 
ssize_t cpu_id () const noexcept
 Get the logical CPU index.
 
constexpr uint32_t thread_id () const noexcept
 Get the thread id.
 
constexpr uint64_t count () const noexcept
 Get the count since epoch.
 
std::chrono::nanoseconds time_since_epoch () const noexcept
 Convert to nanoseconds since epoch.
 
constexpr time_stamp_countoperator+= (uint64_t rhs) noexcept
 
constexpr time_stamp_count operator+ (uint64_t rhs) const noexcept
 

Static Public Member Functions

static time_stamp_count now () noexcept
 Get the current count from the CPU's time stamp count.
 
static std::chrono::nanoseconds duration_from_count (uint64_t count) noexcept
 Convert a time-stamp count to a duration.
 
static std::pair< utc_nanoseconds, time_stamp_counttime_stamp_utc_sample ()
 Get a good quality time sample.
 
static uint64_t measure_frequency (std::chrono::milliseconds sample_duration)
 Measure the frequency of the time_stamp_count.
 
static void set_frequency (uint64_t frequency) noexcept
 
static std::pair< uint64_t, bool > start_subsystem ()
 Start the time_stamp_count subsystem.
 

Detailed Description

Since Window's 10 QueryPerformanceCounter() counts at only 10MHz which is too low to measure performance in many cases.

Instead we will use the TSC.

Constructor & Destructor Documentation

◆ time_stamp_count() [1/3]

v1::time_stamp_count::time_stamp_count ( time_stamp_count::inplace )
inlineexplicitnoexcept

Use a constructor to in-place create the timestamp.

◆ time_stamp_count() [2/3]

v1::time_stamp_count::time_stamp_count ( time_stamp_count::inplace_with_cpu_id )
inlineexplicitnoexcept

Use a constructor to in-place create the timestamp.

◆ time_stamp_count() [3/3]

v1::time_stamp_count::time_stamp_count ( time_stamp_count::inplace_with_thread_id )
inlineexplicitnoexcept

Use a constructor to in-place create the timestamp.

Member Function Documentation

◆ count()

constexpr uint64_t v1::time_stamp_count::count ( ) const
inlineconstexprnoexcept

Get the count since epoch.

The epoch is the same as the TSC count's epoch. In most cases the epoch is at system startup time.

◆ cpu_id()

ssize_t v1::time_stamp_count::cpu_id ( ) const
inlinenoexcept

Get the logical CPU index.

This is logical CPU id that the operating system uses for things like thread affinity.

Returns
the processor index, or -1 if the processor index is unknown.

◆ duration_from_count()

static std::chrono::nanoseconds v1::time_stamp_count::duration_from_count ( uint64_t count)
inlinestaticnoexcept

Convert a time-stamp count to a duration.

Parameters
countThe number clock ticks.
Returns
A period of nanoseconds representing the count of clock ticks.

◆ measure_frequency()

static uint64_t v1::time_stamp_count::measure_frequency ( std::chrono::milliseconds sample_duration)
inlinestatic

Measure the frequency of the time_stamp_count.

Frequency drift from TSC is 1ppm

Parameters
sample_durationThe time between samples to determine the frequency longer duration gives a better quality but may increase application start-up time.
Returns
The clock frequency of the TSC in Hz.

◆ now()

static time_stamp_count v1::time_stamp_count::now ( )
inlinestaticnoexcept

Get the current count from the CPU's time stamp count.

Returns
The current clock count and CPU-id.

◆ start_subsystem()

static std::pair< uint64_t, bool > v1::time_stamp_count::start_subsystem ( )
inlinestatic

Start the time_stamp_count subsystem.

Returns
The time-stamp-counter frequency
Exceptions
os_errorWhen the time-stamp-counter does not work. AUX is the same as the cpu-id.

◆ thread_id()

constexpr uint32_t v1::time_stamp_count::thread_id ( ) const
inlineconstexprnoexcept

Get the thread id.

Precondition
Must call time_stamp_count(time_stamp_count::inplace_with_thread_id) first.

◆ time_since_epoch()

std::chrono::nanoseconds v1::time_stamp_count::time_since_epoch ( ) const
inlinenoexcept

Convert to nanoseconds since epoch.

The epoch is the same as the TSC count's epoch. In most cases the epoch is at system startup time.

◆ time_stamp_utc_sample()

static std::pair< utc_nanoseconds, time_stamp_count > v1::time_stamp_count::time_stamp_utc_sample ( )
inlinestatic

Get a good quality time sample.

Precondition
The CPU affinity must be set to a single CPU.
Returns
The current UTC time in nanoseconds, the current time-stamp count.
Exceptions
os_errorWhen there is a problem getting a time-sample.

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