8#include "time_stamp_count.hpp"
9#include "hires_utc_clock.hpp"
10#include "required.hpp"
11#include "tagged_map.hpp"
12#include "fixed_string.hpp"
13#include "statistics.hpp"
26constexpr int MAX_NR_TRACES = 1024;
48 inline int64_t
push() noexcept
71 return {id, is_recording};
75inline thread_local trace_stack_type trace_stack;
79void trace_record() noexcept;
81template<basic_fixed_string Tag, basic_fixed_string... InfoTags>
105 template<basic_fixed_
string InfoTag>
108 return info.template get<InfoTag>();
111 template<basic_fixed_
string InfoTag>
112 sdatum
const &get() const noexcept
114 return info.template get<InfoTag>();
122 for (
size_t i = 0; i < rhs.info.size(); i++) {
126 info_string += rhs.info.get_tag(i);
128 info_string +=
static_cast<std::string>(rhs.info[i]);
132 "parent={} tag={} start={} {}",
158 long long prev_count = 0;
169 ttlet current_count = count.fetch_add(1, std::memory_order::acquire);
173 auto prev_peak = peak_duration.
load(std::memory_order::relaxed);
174 decltype(prev_peak) new_peak;
176 new_peak = d.
count() > prev_peak ? d.
count() : prev_peak;
179 version.
store(current_count + 1, std::memory_order::release);
181 return current_count == 0;
186 long long last_count;
197 r.peak_duration = {};
199 r.count = count.load(std::memory_order::acquire);
203 auto tmp = peak_duration.
exchange(0, std::memory_order::relaxed);
204 if (tmp > r.peak_duration.
count()) {
209 }
while (r.count != version.
load(std::memory_order::relaxed));
211 r.last_count = r.count - prev_count;
212 r.last_duration = r.duration - prev_duration;
214 prev_count = r.count;
215 prev_duration = r.duration;
220template<basic_fixed_
string Tag>
221inline trace_statistics_type trace_statistics;
223inline wfree_unordered_map<std::string, trace_statistics_type *, MAX_NR_TRACES> trace_statistics_map;
225template<basic_fixed_string Tag, basic_fixed_string... InfoTags>
234 tt_no_inline
static void add_to_map()
236 trace_statistics_map.insert(Tag, &trace_statistics<Tag>);
258 [[unlikely]] add_to_map();
261 ttlet[id, is_recording] = stack->pop(data.
parent_id);
265 [[unlikely]] tt_log_trace(
"id={} {}",
id, to_string(data));
274 template<basic_fixed_
string InfoTag,
typename T>
275 trace &set(T &&value)
277 data.template get<InfoTag>() = std::forward<T>(value);
A fixed size (64 bits) class for a generic value type.
Definition datum.hpp:124
example: ``` template<tt::basic_fixed_string Foo> class A { auto bar() { return std::string{Foo}; } }...
Definition fixed_string.hpp:30
static time_point make(time_stamp_count const &tsc) noexcept
Make a time point from a time stamp count.
A static sized stack.
Definition stack.hpp:23
Definition tagged_map.hpp:16
Since Window's 10 QueryPerformanceCounter() counts at only 10MHz which is too low to measure performa...
Definition time_stamp_count.hpp:29
std::chrono::nanoseconds time_since_epoch() const noexcept
Convert to nanoseconds since epoch.
Definition time_stamp_count.hpp:108
static time_stamp_count now() noexcept
Get the current count from the CPU's time stamp count.
Definition time_stamp_count.hpp:66
int64_t top_trace_id
Definition trace.hpp:33
std::pair< int64_t, bool > pop(int64_t parent_id) noexcept
Definition trace.hpp:62
int8_t depth
Definition trace.hpp:37
int64_t push() noexcept
Definition trace.hpp:48
int8_t record_depth
Definition trace.hpp:41
int64_t parent_id
Definition trace.hpp:88
time_stamp_count time_stamp
Definition trace.hpp:92
bool write(std::chrono::nanoseconds const &d)
Definition trace.hpp:165
trace()
Definition trace.hpp:246
T atomic_thread_fence(T... args)
T compare_exchange_weak(T... args)