HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
trace.hpp
1// Copyright Take Vos 2019, 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 "../utility/utility.hpp"
8#include "../time/time.hpp"
9#include "counters.hpp"
10#include "../macros.hpp"
11#include <array>
12#include <tuple>
13#include <exception>
14
15hi_export_module(hikogui.telemetry : trace);
16
17hi_export namespace hi::inline v1 {
18
20public:
21 trace_base(trace_base const &) = delete;
22 trace_base(trace_base &&) = delete;
23 trace_base &operator=(trace_base const &) = delete;
24 trace_base &operator=(trace_base &&) = delete;
25
26 trace_base() noexcept : _time_stamp(time_stamp_count::inplace{}), _next(std::exchange(_top, this)) {}
27
28 virtual ~trace_base()
29 {
30 _top = _next;
31 }
32
33 virtual void log() const noexcept = 0;
34
35protected:
36 inline static thread_local trace_base *_top = nullptr;
37
38 time_stamp_count _time_stamp;
39 trace_base *_next = nullptr;
40};
41
42template<fixed_string Tag>
43class trace : public trace_base {
44public:
45 trace() noexcept : trace_base() {}
46
47 virtual ~trace() noexcept
48 {
49 if (std::uncaught_exceptions()) {
50 log();
51 }
52
53 auto const current_time_stamp = time_stamp_count{time_stamp_count::inplace{}};
54 global_counter<Tag>.add_duration(current_time_stamp.count() - _time_stamp.count());
55 }
56
57 void log() const noexcept override
58 {
59 if (_next) {
60 _next->log();
61 }
62 }
63};
64
65
66} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition trace.hpp:19
Definition trace.hpp:43
Since Window's 10 QueryPerformanceCounter() counts at only 10MHz which is too low to measure performa...
Definition time_stamp_count.hpp:36
Definition time_stamp_count.hpp:38