HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
ttauri
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
tt {
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
40
41
template
<basic_fixed_
string
Tag,
int
NumItems = 0>
42
class
trace
:
public
trace_base
{
43
public
:
44
trace
() noexcept :
trace_base
(), items(), size(0) {}
45
46
virtual
~trace
()
noexcept
47
{
48
if
(std::uncaught_exceptions()) {
49
log
();
50
}
51
52
ttlet 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
template
<
typename
T>
64
void
set(
char
const
*key, T &&value)
noexcept
65
{
66
// XXX Use type erase to store the type of the value and a pointer
67
// to the location of the value on the stack.
68
69
tt_axiom(size < NumItems);
70
items[size++] = {key,
datum
{std::forward<T>(value)}};
71
}
72
73
private
:
74
std::array<std::pair<char const *, datum>
, NumItems> items;
75
size_t
size = 0;
76
};
77
78
template
<basic_fixed_
string
Tag>
79
class
trace
<Tag,0> :
public
trace_base
{
80
public
:
81
trace
() noexcept :
trace_base
() {}
82
83
virtual
~trace
()
noexcept
84
{
85
if
(std::uncaught_exceptions()) {
86
log
();
87
}
88
89
ttlet current_time_stamp =
time_stamp_count
{
time_stamp_count::inplace
{}};
90
global_counter<Tag>.add_duration(current_time_stamp.count() - _time_stamp.count());
91
}
92
93
void
log
()
const
noexcept
override
94
{
95
if
(_next) {
96
_next->log();
97
}
98
}
99
};
100
101
}
// namespace tt
tt::datum
A dynamic data type.
Definition
datum.hpp:213
tt::log
Definition
log.hpp:113
tt::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
tt::time_stamp_count::inplace
Definition
time_stamp_count.hpp:31
tt::trace_base
Definition
trace.hpp:16
tt::trace
Definition
trace.hpp:42
std::array
Generated on Mon Apr 22 2024 12:53:32 for HikoGUI by
1.10.0