|
8 | 8 | #include <ostream> |
9 | 9 | #include <string_view> |
10 | 10 | #include <tracy/Tracy.hpp> |
| 11 | +#include <unordered_map> |
11 | 12 | #include <vector> |
12 | 13 |
|
13 | 14 | /** |
@@ -65,19 +66,19 @@ struct AggregateEntry { |
65 | 66 | // AggregateData: Result of normalizing benchmark data |
66 | 67 | // entries: Key -> ParentKey -> Entry |
67 | 68 | // Empty string is used as key if the entry has no parent. |
68 | | -using AggregateData = std::map<OperationKey, std::map<OperationKey, AggregateEntry>>; |
| 69 | +using AggregateData = std::unordered_map<OperationKey, std::map<OperationKey, AggregateEntry>>; |
69 | 70 |
|
70 | 71 | // Contains all statically known op counts |
71 | 72 | struct GlobalBenchStatsContainer { |
72 | 73 | public: |
73 | 74 | static inline thread_local TimeStatsEntry* parent = nullptr; |
74 | 75 | ~GlobalBenchStatsContainer(); |
75 | 76 | std::mutex mutex; |
76 | | - std::vector<TimeStatsEntry*> entries; |
| 77 | + std::vector<std::shared_ptr<TimeStatsEntry>> entries; |
77 | 78 | void print() const; |
78 | 79 | // NOTE: Should be called when other threads aren't active |
79 | 80 | void clear(); |
80 | | - void add_entry(const char* key, TimeStatsEntry* entry); |
| 81 | + void add_entry(const char* key, const std::shared_ptr<TimeStatsEntry>& entry); |
81 | 82 | void print_stats_recursive(const OperationKey& key, const TimeStats* stats, const std::string& indent) const; |
82 | 83 | void print_aggregate_counts(std::ostream&, size_t) const; |
83 | 84 | void print_aggregate_counts_hierarchical(std::ostream&) const; |
@@ -151,16 +152,17 @@ struct TimeStatsEntry { |
151 | 152 | template <OperationLabel Op> struct ThreadBenchStats { |
152 | 153 | public: |
153 | 154 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
154 | | - static inline thread_local TimeStatsEntry stats; |
| 155 | + static inline thread_local std::shared_ptr<TimeStatsEntry> stats; |
155 | 156 |
|
156 | 157 | static void init_entry(TimeStatsEntry& entry); |
157 | 158 | // returns null if use_bb_bench not enabled |
158 | | - static TimeStatsEntry* ensure_stats() |
| 159 | + static std::shared_ptr<TimeStatsEntry> ensure_stats() |
159 | 160 | { |
160 | | - if (bb::detail::use_bb_bench && BB_UNLIKELY(stats.key.empty())) { |
161 | | - GLOBAL_BENCH_STATS.add_entry(Op.value, &stats); |
| 161 | + if (bb::detail::use_bb_bench && BB_UNLIKELY(stats == nullptr)) { |
| 162 | + stats = std::make_shared<TimeStatsEntry>(); |
| 163 | + GLOBAL_BENCH_STATS.add_entry(Op.value, stats); |
162 | 164 | } |
163 | | - return bb::detail::use_bb_bench ? &stats : nullptr; |
| 165 | + return stats; |
164 | 166 | } |
165 | 167 | }; |
166 | 168 |
|
@@ -198,7 +200,7 @@ struct BenchReporter { |
198 | 200 | #define BB_BENCH_TRACY() BB_BENCH_ONLY_NAME(__func__) |
199 | 201 | #define BB_BENCH_TRACY_NAME(name) BB_BENCH_ONLY_NAME(name) |
200 | 202 | #define BB_BENCH_ONLY_NAME(name) \ |
201 | | - bb::detail::BenchReporter _bb_bench_reporter((bb::detail::ThreadBenchStats<name>::ensure_stats())) |
| 203 | + bb::detail::BenchReporter _bb_bench_reporter((bb::detail::ThreadBenchStats<name>::ensure_stats().get())) |
202 | 204 | #define BB_BENCH_ENABLE_NESTING() \ |
203 | 205 | if (_bb_bench_reporter.stats) \ |
204 | 206 | bb::detail::GlobalBenchStatsContainer::parent = _bb_bench_reporter.stats |
|
0 commit comments