HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hires_utc_clock.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "required.hpp"
8#include "unfair_mutex.hpp"
9#include <array>
10#include <atomic>
11#include <chrono>
12#include <thread>
13
14namespace tt {
15class time_stamp_count;
16
20 using rep = int64_t;
21 using period = std::nano;
24 static const bool is_steady = false;
25
28 [[nodiscard]] static time_point now() noexcept;
29
33 [[nodiscard]] static time_point now(time_stamp_count &tsc) noexcept;
34
43 [[nodiscard]] static time_point make(time_stamp_count const &tsc) noexcept;
44
47 static bool start_subsystem() noexcept;
48
51 static void stop_subsystem() noexcept;
52
59 static void adjust_for_drift() noexcept;
60
61private:
62 static inline std::atomic<bool> subsystem_is_running = false;
63 static inline std::jthread subsystem_thread;
64 static inline unfair_mutex mutex;
65 static inline std::array<std::atomic<hires_utc_clock::time_point>, maximum_num_cpus> tsc_epochs = {};
66
67 static void subsystem_proc_frequency_calibration(std::stop_token stop_token) noexcept;
68 static void subsystem_proc(std::stop_token stop_token) noexcept;
69
72 static bool init_subsystem() noexcept;
73
76 static void deinit_subsystem() noexcept;
77
78 [[nodiscard]] static size_t find_cpu_id(uint32_t cpu_id) noexcept;
79};
80
81std::string format_engineering(hires_utc_clock::duration duration);
82
86std::string format_iso8601_utc(hires_utc_clock::time_point utc_timestamp) noexcept;
87
92std::string format_iso8601(hires_utc_clock::time_point utc_timestamp, std::chrono::time_zone const *time_zone = nullptr) noexcept;
93
94} // namespace tt
STL namespace.
Timestamp.
Definition hires_utc_clock.hpp:19
static bool start_subsystem() noexcept
This will start the calibration subsystem.
static time_point make(time_stamp_count const &tsc) noexcept
Make a time point from a time stamp count.
static time_point now() noexcept
Get the current time.
static void stop_subsystem() noexcept
This will stop the calibration subsystem.
static void adjust_for_drift() noexcept
A calibration step which will drift the per-cpu tsc-offset.
Since Window's 10 QueryPerformanceCounter() counts at only 10MHz which is too low to measure performa...
Definition time_stamp_count.hpp:29