HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
v1::time_stamp_count Class Reference

#include <hikogui/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_count & operator+= (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 uint64_t measure_frequency (std::chrono::milliseconds duration) noexcept
 Measure the frequency of the time_stamp_count.
static void set_frequency (uint64_t frequency) noexcept
static void start_subsystem () noexcept
 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()

uint64_t v1::time_stamp_count::count ( ) const
inlinenodiscardconstexprnoexcept

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
inlinenodiscardnoexcept

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()

std::chrono::nanoseconds v1::time_stamp_count::duration_from_count ( uint64_t count)
inlinestaticnodiscardnoexcept

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()

uint64_t v1::time_stamp_count::measure_frequency ( std::chrono::milliseconds duration)
staticnodiscardnoexcept

Measure the frequency of the time_stamp_count.

Frequency drift from TSC is 1ppm

◆ now()

time_stamp_count v1::time_stamp_count::now ( )
inlinestaticnodiscardnoexcept

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

Returns
The current clock count and CPU-id.

◆ start_subsystem()

void v1::time_stamp_count::start_subsystem ( )
staticnoexcept

Start the time_stamp_count subsystem.

◆ thread_id()

uint32_t v1::time_stamp_count::thread_id ( ) const
inlinenodiscardconstexprnoexcept

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
inlinenodiscardnoexcept

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.


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