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