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/module.hpp"
9#include "counters.hpp"
10#include "../macros.hpp"
11#include <array>
12#include <tuple>
13
14
15
16namespace hi::inline v1 {
17
19public:
20 trace_base(trace_base const &) = delete;
21 trace_base(trace_base &&) = delete;
22 trace_base &operator=(trace_base const &) = delete;
23 trace_base &operator=(trace_base &&) = delete;
24
25 trace_base() noexcept : _time_stamp(time_stamp_count::inplace{}), _next(std::exchange(_top, this)) {}
26
27 virtual ~trace_base()
28 {
29 _top = _next;
30 }
31
32 virtual void log() const noexcept = 0;
33
34protected:
35 inline static thread_local trace_base *_top = nullptr;
36
37 time_stamp_count _time_stamp;
38 trace_base *_next = nullptr;
39};
40
41template<fixed_string Tag>
42class trace : public trace_base {
43public:
44 trace() noexcept : trace_base() {}
45
46 virtual ~trace() noexcept
47 {
48 if (std::uncaught_exceptions()) {
49 log();
50 }
51
52 hilet current_time_stamp = time_stamp_count{time_stamp_count::inplace{}};
53 global_counter<Tag>.add_duration(current_time_stamp.count() - _time_stamp.count());
54 }
55
56 void log() const noexcept override
57 {
58 if (_next) {
59 _next->log();
60 }
61 }
62};
63
64
65} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Definition trace.hpp:18
Definition trace.hpp:42
Since Window's 10 QueryPerformanceCounter() counts at only 10MHz which is too low to measure performa...
Definition time_stamp_count.hpp:31
Definition time_stamp_count.hpp:33