Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
macros.hpp
Go to the documentation of this file.
1#pragma once
2
11
13
14// NOLINTBEGIN(cppcoreguidelines-macro-usage)
15
16#ifdef HELIOS_ENABLE_PROFILE
17
18#include <source_location>
19#include <string_view>
20
21#define HELIOS_PROFILE_DETAIL_SCOPE(...) \
22 const ::helios::profile::ZoneSpec HELIOS_ANONYMOUS_VAR(_helios_spec){ \
23 __VA_ARGS__}; \
24 ::helios::profile::ScopedZone HELIOS_ANONYMOUS_VAR(_helios_zone)( \
25 HELIOS_ANONYMOUS_VAR(_helios_spec))
26
27#define HELIOS_PROFILE_SCOPE() \
28 HELIOS_PROFILE_DETAIL_SCOPE(std::string_view{}, \
29 std::source_location::current(), 0U, true, 0)
30
31#define HELIOS_PROFILE_SCOPE_N(name) \
32 HELIOS_PROFILE_DETAIL_SCOPE((name), std::source_location::current(), 0U, \
33 true, 0)
34
35#define HELIOS_PROFILE_SCOPE_C(color) \
36 HELIOS_PROFILE_DETAIL_SCOPE( \
37 std::string_view{}, std::source_location::current(), (color), true, 0)
38
39#define HELIOS_PROFILE_SCOPE_NC(name, color) \
40 HELIOS_PROFILE_DETAIL_SCOPE((name), std::source_location::current(), \
41 (color), true, 0)
42
43#define HELIOS_PROFILE_SCOPE_IF(name, active_expr) \
44 const ::helios::profile::ZoneSpec HELIOS_ANONYMOUS_VAR(_helios_spec){ \
45 (name), std::source_location::current(), 0U, true, 0}; \
46 const bool HELIOS_ANONYMOUS_VAR(_helios_active) = \
47 static_cast<bool>(active_expr); \
48 ::helios::profile::ScopedZone HELIOS_ANONYMOUS_VAR(_helios_zone)( \
49 HELIOS_ANONYMOUS_VAR(_helios_spec), \
50 HELIOS_ANONYMOUS_VAR(_helios_active))
51
52#define HELIOS_PROFILE_SCOPE_S(depth) \
53 HELIOS_PROFILE_DETAIL_SCOPE( \
54 std::string_view{}, std::source_location::current(), 0U, true, (depth))
55
56#define HELIOS_PROFILE_SCOPE_NS(name, depth) \
57 HELIOS_PROFILE_DETAIL_SCOPE((name), std::source_location::current(), 0U, \
58 true, (depth))
59
60#define HELIOS_PROFILE_ZONE_TEXT(text) \
61 do { \
62 if (const auto _storage = \
63 ::helios::profile::ScopedZone::CurrentZoneStorage(); \
64 !_storage.empty()) { \
65 ::helios::profile::Profiler::Instance().ZoneText(_storage, (text)); \
66 } \
67 } while (false)
68
69#define HELIOS_PROFILE_ZONE_VALUE(value) \
70 do { \
71 if (const auto _storage = \
72 ::helios::profile::ScopedZone::CurrentZoneStorage(); \
73 !_storage.empty()) { \
74 ::helios::profile::Profiler::Instance().ZoneValue(_storage, (value)); \
75 } \
76 } while (false)
77
78#define HELIOS_PROFILE_ZONE_NAME(name) \
79 do { \
80 if (const auto _storage = \
81 ::helios::profile::ScopedZone::CurrentZoneStorage(); \
82 !_storage.empty()) { \
83 ::helios::profile::Profiler::Instance().ZoneName(_storage, (name)); \
84 } \
85 } while (false)
86
87#define HELIOS_PROFILE_FRAME() ::helios::profile::FrameMark()
88
89#define HELIOS_PROFILE_FRAME_N(name) \
90 ::helios::profile::FrameMarkNamed(::helios::CStringView{(name)})
91
92#define HELIOS_PROFILE_FRAME_START(name) \
93 ::helios::profile::FrameMarkStart(::helios::CStringView{(name)})
94
95#define HELIOS_PROFILE_FRAME_END(name) \
96 ::helios::profile::FrameMarkEnd(::helios::CStringView{(name)})
97
98#define HELIOS_PROFILE_MESSAGE(msg) ::helios::profile::Message(msg)
99
100#define HELIOS_PROFILE_SET_THREAD_NAME(name) \
101 ::helios::profile::SetThreadName(::helios::CStringView{(name)})
102
103#define HELIOS_PROFILE_PLOT(name, value) \
104 ::helios::profile::Plot(::helios::CStringView{(name)}, (value))
105
106#define HELIOS_PROFILE_PLOT_CONFIG(name, type, step, fill, color) \
107 ::helios::profile::PlotConfig(::helios::CStringView{(name)}, (type), (step), \
108 (fill), (color))
109
110#define HELIOS_PROFILE_ALLOC(ptr, size) \
111 ::helios::profile::Alloc((ptr), (size), std::nullopt, 0)
112
113#define HELIOS_PROFILE_FREE(ptr) ::helios::profile::Free((ptr), std::nullopt, 0)
114
115#define HELIOS_PROFILE_ALLOC_N(ptr, size, name) \
116 ::helios::profile::Alloc((ptr), (size), ::helios::CStringView{(name)}, 0)
117
118#define HELIOS_PROFILE_FREE_N(ptr, name) \
119 ::helios::profile::Free((ptr), ::helios::CStringView{(name)}, 0)
120
121#define HELIOS_PROFILE_ALLOC_S(ptr, size, depth) \
122 ::helios::profile::Alloc((ptr), (size), std::nullopt, (depth))
123
124#define HELIOS_PROFILE_FREE_S(ptr, depth) \
125 ::helios::profile::Free((ptr), std::nullopt, (depth))
126
127#define HELIOS_PROFILE_ALLOC_NS(ptr, size, depth, name) \
128 ::helios::profile::Alloc((ptr), (size), ::helios::CStringView{(name)}, \
129 (depth))
130
131#define HELIOS_PROFILE_FREE_NS(ptr, depth, name) \
132 ::helios::profile::Free((ptr), ::helios::CStringView{(name)}, (depth))
133
134#define HELIOS_PROFILE_MEMORY_DISCARD(name) \
135 ::helios::profile::MemoryDiscard(::helios::CStringView{(name)})
136
137#define HELIOS_PROFILE_MEMORY_DISCARD_S(name, depth) \
138 ::helios::profile::MemoryDiscardS(::helios::CStringView{(name)}, (depth))
139
140#else // HELIOS_ENABLE_PROFILE
141
142#define HELIOS_PROFILE_SCOPE() \
143 [[maybe_unused]] static constexpr int HELIOS_ANONYMOUS_VAR(_helios_prof) = 0
144#define HELIOS_PROFILE_SCOPE_N(name) HELIOS_PROFILE_SCOPE()
145#define HELIOS_PROFILE_SCOPE_C(color) HELIOS_PROFILE_SCOPE()
146#define HELIOS_PROFILE_SCOPE_NC(name, color) HELIOS_PROFILE_SCOPE()
147#define HELIOS_PROFILE_SCOPE_IF(name, active) HELIOS_PROFILE_SCOPE()
148#define HELIOS_PROFILE_SCOPE_S(depth) HELIOS_PROFILE_SCOPE()
149#define HELIOS_PROFILE_SCOPE_NS(name, depth) HELIOS_PROFILE_SCOPE()
150#define HELIOS_PROFILE_ZONE_TEXT(text) \
151 [[maybe_unused]] static constexpr int HELIOS_ANONYMOUS_VAR(_helios_prof) = 0
152#define HELIOS_PROFILE_ZONE_VALUE(value) HELIOS_PROFILE_ZONE_TEXT(value)
153#define HELIOS_PROFILE_ZONE_NAME(name) HELIOS_PROFILE_ZONE_TEXT(name)
154#define HELIOS_PROFILE_FRAME() HELIOS_PROFILE_SCOPE()
155#define HELIOS_PROFILE_FRAME_N(name) HELIOS_PROFILE_SCOPE()
156#define HELIOS_PROFILE_FRAME_START(name) HELIOS_PROFILE_SCOPE()
157#define HELIOS_PROFILE_FRAME_END(name) HELIOS_PROFILE_SCOPE()
158#define HELIOS_PROFILE_MESSAGE(msg) HELIOS_PROFILE_SCOPE()
159#define HELIOS_PROFILE_SET_THREAD_NAME(name) HELIOS_PROFILE_SCOPE()
160#define HELIOS_PROFILE_PLOT(name, value) HELIOS_PROFILE_SCOPE()
161#define HELIOS_PROFILE_PLOT_CONFIG(name, type, step, fill, color) \
162 HELIOS_PROFILE_SCOPE()
163#define HELIOS_PROFILE_ALLOC(ptr, size) HELIOS_PROFILE_SCOPE()
164#define HELIOS_PROFILE_FREE(ptr) HELIOS_PROFILE_SCOPE()
165#define HELIOS_PROFILE_ALLOC_N(ptr, size, name) HELIOS_PROFILE_SCOPE()
166#define HELIOS_PROFILE_FREE_N(ptr, name) HELIOS_PROFILE_SCOPE()
167#define HELIOS_PROFILE_ALLOC_S(ptr, size, depth) HELIOS_PROFILE_SCOPE()
168#define HELIOS_PROFILE_FREE_S(ptr, depth) HELIOS_PROFILE_SCOPE()
169#define HELIOS_PROFILE_ALLOC_NS(ptr, size, depth, name) HELIOS_PROFILE_SCOPE()
170#define HELIOS_PROFILE_FREE_NS(ptr, depth, name) HELIOS_PROFILE_SCOPE()
171#define HELIOS_PROFILE_MEMORY_DISCARD(name) HELIOS_PROFILE_SCOPE()
172#define HELIOS_PROFILE_MEMORY_DISCARD_S(name, depth) HELIOS_PROFILE_SCOPE()
173
174#endif // HELIOS_ENABLE_PROFILE
175
176// NOLINTEND(cppcoreguidelines-macro-usage)