tess 1.0.0
Performance-first tile and path simulation substrate
Loading...
Searching...
No Matches
export.h
1#pragma once
2
3#include <tess/diagnostics/diagnostics.h>
4#include <tess/diagnostics/trace.h>
5
6#include <array>
7#include <cstddef>
8
9namespace tess::diagnostics {
10
11#if TESS_DIAGNOSTICS_ENABLED
12
14inline constexpr std::size_t diagnostics_snapshot_trace_capacity = 64;
15
23 std::array<TraceCategoryStats, trace_category_count> per_category{};
24
25 // Timing accumulator for a category, guarding the Count sentinel and any
26 // out-of-range value.
27 [[nodiscard]] auto stats(TraceCategory value) const noexcept
28 -> const TraceCategoryStats& {
29 static constexpr TraceCategoryStats kZero{};
30 const auto index = static_cast<std::size_t>(value);
31 if (index >= per_category.size()) {
32 return kZero;
33 }
34 return per_category[index];
35 }
36};
37
50 PathCounters path;
51 AllocationCounters allocation;
53 TimingSnapshot timing;
54 std::array<TraceRecord, diagnostics_snapshot_trace_capacity> trace_records{};
55 std::size_t trace_record_count = 0;
56 std::uint64_t trace_records_dropped = 0;
57};
58
65[[nodiscard]] inline auto capture_timing(const TraceBuffer& buffer) noexcept
67 TimingSnapshot snapshot;
68 snapshot.per_category = buffer.all_stats();
69 return snapshot;
70}
71
78[[nodiscard]] inline auto capture_diagnostics(
79 const PathCounters& path, const AllocationCounters& allocation,
80 const QueuedPhaseCounters& queued, const TraceBuffer& buffer) noexcept
81 -> DiagnosticsSnapshot {
82 DiagnosticsSnapshot snapshot;
83 snapshot.path = path;
84 snapshot.allocation = allocation;
85 snapshot.queued = queued;
86 snapshot.timing = capture_timing(buffer);
87 const auto omitted = buffer.size() > snapshot.trace_records.size()
88 ? buffer.size() - snapshot.trace_records.size()
89 : std::size_t{0};
90 snapshot.trace_record_count = buffer.size() - omitted;
91 snapshot.trace_records_dropped =
92 buffer.dropped() + static_cast<std::uint64_t>(omitted);
93 for (std::size_t index = 0; index < snapshot.trace_record_count; ++index) {
94 snapshot.trace_records[index] = buffer[omitted + index];
95 }
96 return snapshot;
97}
98
99#endif // TESS_DIAGNOSTICS_ENABLED
100
101} // namespace tess::diagnostics
Definition trace.h:101
Definition diagnostics.h:103
Definition diagnostics.h:78
Definition diagnostics.h:118
Definition export.h:22