Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
tracy_wrapper.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2024 DS
4
5/*
6 * Wrapper for <tracy/Tracy.hpp>, so that we can use Tracy's macros without
7 * having it as mandatory dependency.
8 *
9 * For annotations that you don't intend to upstream, you can also include
10 * <tracy/Tracy.hpp> directly (which also works in irr/).
11 */
12
13#pragma once
14
15#include "config.h"
16#include "util/basic_macros.h"
17
18#if BUILD_WITH_TRACY
19
20#include <tracy/Tracy.hpp> // IWYU pragma: export
21
22#else
23
24// Copied from Tracy.hpp
25
26#define TracyNoop
27
28#define ZoneNamed(x,y)
29#define ZoneNamedN(x,y,z)
30#define ZoneNamedC(x,y,z)
31#define ZoneNamedNC(x,y,z,w)
32
33#define ZoneTransient(x,y)
34#define ZoneTransientN(x,y,z)
35
36#define ZoneScoped
37#define ZoneScopedN(x)
38#define ZoneScopedC(x)
39#define ZoneScopedNC(x,y)
40
41#define ZoneText(x,y)
42#define ZoneTextV(x,y,z)
43#define ZoneTextF(x,...)
44#define ZoneTextVF(x,y,...)
45#define ZoneName(x,y)
46#define ZoneNameV(x,y,z)
47#define ZoneNameF(x,...)
48#define ZoneNameVF(x,y,...)
49#define ZoneColor(x)
50#define ZoneColorV(x,y)
51#define ZoneValue(x)
52#define ZoneValueV(x,y)
53#define ZoneIsActive false
54#define ZoneIsActiveV(x) false
55
56#define FrameMark
57#define FrameMarkNamed(x)
58#define FrameMarkStart(x)
59#define FrameMarkEnd(x)
60
61#define FrameImage(x,y,z,w,a)
62
63#define TracyLockable( type, varname ) type varname
64#define TracyLockableN( type, varname, desc ) type varname
65#define TracySharedLockable( type, varname ) type varname
66#define TracySharedLockableN( type, varname, desc ) type varname
67#define LockableBase( type ) type
68#define SharedLockableBase( type ) type
69#define LockMark(x) (void)x
70#define LockableName(x,y,z)
71
72#define TracyPlot(x,y)
73#define TracyPlotConfig(x,y,z,w,a)
74
75#define TracyMessage(x,y)
76#define TracyMessageL(x)
77#define TracyMessageC(x,y,z)
78#define TracyMessageLC(x,y)
79#define TracyAppInfo(x,y)
80
81#define TracyAlloc(x,y)
82#define TracyFree(x)
83#define TracySecureAlloc(x,y)
84#define TracySecureFree(x)
85
86#define TracyAllocN(x,y,z)
87#define TracyFreeN(x,y)
88#define TracySecureAllocN(x,y,z)
89#define TracySecureFreeN(x,y)
90
91#define ZoneNamedS(x,y,z)
92#define ZoneNamedNS(x,y,z,w)
93#define ZoneNamedCS(x,y,z,w)
94#define ZoneNamedNCS(x,y,z,w,a)
95
96#define ZoneTransientS(x,y,z)
97#define ZoneTransientNS(x,y,z,w)
98
99#define ZoneScopedS(x)
100#define ZoneScopedNS(x,y)
101#define ZoneScopedCS(x,y)
102#define ZoneScopedNCS(x,y,z)
103
104#define TracyAllocS(x,y,z)
105#define TracyFreeS(x,y)
106#define TracySecureAllocS(x,y,z)
107#define TracySecureFreeS(x,y)
108
109#define TracyAllocNS(x,y,z,w)
110#define TracyFreeNS(x,y,z)
111#define TracySecureAllocNS(x,y,z,w)
112#define TracySecureFreeNS(x,y,z)
113
114#define TracyMessageS(x,y,z)
115#define TracyMessageLS(x,y)
116#define TracyMessageCS(x,y,z,w)
117#define TracyMessageLCS(x,y,z)
118
119#define TracySourceCallbackRegister(x,y)
120#define TracyParameterRegister(x,y)
121#define TracyParameterSetup(x,y,z,w)
122#define TracyIsConnected false
123#define TracyIsStarted false
124#define TracySetProgramName(x)
125
126#define TracyFiberEnter(x)
127#define TracyFiberEnterHint(x,y)
128#define TracyFiberLeave
129
130#endif
131
132
133// Helper for making sure frames end in all possible control flow path
135{
136 const char *m_name;
137 bool m_started = false;
138
139public:
140 FrameMarker(const char *name) : m_name(name) {}
141
143
145
146 FrameMarker(FrameMarker &&other) noexcept :
147 m_name(other.m_name), m_started(other.m_started)
148 {
149 other.m_started = false;
150 }
151
153 {
154 if (&other != this) {
155 end();
156 m_name = other.m_name;
157 m_started = other.m_started;
158 other.m_started = false;
159 }
160 return *this;
161 }
162
164 {
165 if (!m_started) {
167 m_started = true;
168 }
169 return std::move(*this);
170 }
171
172 void start()
173 {
174 // no move happens, because we drop the reference
175 (void)std::move(*this).started();
176 }
177
178 void end()
179 {
180 if (m_started) {
181 m_started = false;
183 }
184 }
185};
#define DISABLE_CLASS_COPY(C)
Definition basic_macros.h:26
Definition tracy_wrapper.h:135
FrameMarker(const char *name)
Definition tracy_wrapper.h:140
~FrameMarker()
Definition tracy_wrapper.h:142
const char * m_name
Definition tracy_wrapper.h:136
void start()
Definition tracy_wrapper.h:172
void end()
Definition tracy_wrapper.h:178
FrameMarker && started() &&
Definition tracy_wrapper.h:163
FrameMarker & operator=(FrameMarker &&other) noexcept
Definition tracy_wrapper.h:152
bool m_started
Definition tracy_wrapper.h:137
#define FrameMarkEnd(x)
Definition tracy_wrapper.h:59
#define FrameMarkStart(x)
Definition tracy_wrapper.h:58