HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
hikogui
trace.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 "fixed_string.hpp"
8
#include "time_stamp_count.hpp"
9
#include "counters.hpp"
10
#include "datum.hpp"
11
#include <array>
12
#include <tuple>
13
14
namespace
hi::inline v1 {
15
16
class
trace_base
{
17
public
:
18
trace_base
(
trace_base
const
&) =
delete
;
19
trace_base
(
trace_base
&&) =
delete
;
20
trace_base
&operator=(
trace_base
const
&) =
delete
;
21
trace_base
&operator=(
trace_base
&&) =
delete
;
22
23
trace_base
() noexcept : _time_stamp(
time_stamp_count::inplace
{}), _next(std::exchange(_top,
this
)) {}
24
25
virtual
~trace_base
()
26
{
27
_top = _next;
28
}
29
30
virtual
void
log
()
const
noexcept
= 0;
31
32
protected
:
33
inline
static
thread_local
trace_base
*_top =
nullptr
;
34
35
time_stamp_count
_time_stamp;
36
trace_base
*_next =
nullptr
;
37
};
38
39
template
<basic_fixed_
string
Tag,
int
NumItems = 0>
40
class
trace
:
public
trace_base
{
41
public
:
42
trace
() noexcept :
trace_base
(), items(), size(0) {}
43
44
virtual
~trace
()
noexcept
45
{
46
if
(std::uncaught_exceptions()) {
47
log
();
48
}
49
50
hilet
current_time_stamp =
time_stamp_count
{
time_stamp_count::inplace
{}};
51
global_counter<Tag>.add_duration(current_time_stamp.count() - _time_stamp.count());
52
}
53
54
void
log
()
const
noexcept
override
55
{
56
if
(_next) {
57
_next->log();
58
}
59
}
60
61
template
<
typename
T>
62
void
set(
char
const
*key, T &&value)
noexcept
63
{
64
// XXX Use type erase to store the type of the value and a pointer
65
// to the location of the value on the stack.
66
67
hi_axiom(size < NumItems);
68
items[size++] = {key,
datum
{std::forward<T>(value)}};
69
}
70
71
private
:
72
std::array<std::pair<char const *, datum>
, NumItems> items;
73
std::size_t
size = 0;
74
};
75
76
template
<basic_fixed_
string
Tag>
77
class
trace
<Tag, 0> :
public
trace_base
{
78
public
:
79
trace
() noexcept :
trace_base
() {}
80
81
virtual
~trace
()
noexcept
82
{
83
if
(std::uncaught_exceptions()) {
84
log
();
85
}
86
87
hilet
current_time_stamp =
time_stamp_count
{
time_stamp_count::inplace
{}};
88
global_counter<Tag>.add_duration(current_time_stamp.count() - _time_stamp.count());
89
}
90
91
void
log
()
const
noexcept
override
92
{
93
if
(_next) {
94
_next->log();
95
}
96
}
97
};
98
99
}
// namespace hi::inline v1
hilet
#define hilet
Invariant should be the default for variables.
Definition
required.hpp:23
v1::datum
A dynamic data type.
Definition
datum.hpp:209
v1::log
Definition
log.hpp:111
v1::time_stamp_count
Since Window's 10 QueryPerformanceCounter() counts at only 10MHz which is too low to measure performa...
Definition
time_stamp_count.hpp:29
v1::time_stamp_count::inplace
Definition
time_stamp_count.hpp:31
v1::trace_base
Definition
trace.hpp:16
v1::trace
Definition
trace.hpp:40
std::array
std::size_t
Generated on Mon Apr 22 2024 12:53:26 for HikoGUI by
1.10.0