Lightweight 0.20260303.0
Loading...
Searching...
No Matches
TracyProfiler.hpp
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5// Optional Tracy profiler instrumentation. Part of the Lightweight public API:
6// any consumer (tests, tools, examples, downstream apps) inherits the macros.
7//
8// Configure with `-DLIGHTWEIGHT_ENABLE_TRACY=ON` (and `vcpkg install
9// lightweight[tracy]` if using vcpkg) then connect the Tracy GUI to the
10// running process. When the option is OFF, this header provides no-op stubs
11// that mirror Tracy's macro names so call sites can use `ZoneScoped`,
12// `ZoneScopedN(...)`, `ZoneText(...)`, `FrameMark`, etc. directly without
13// changing the source between builds.
14
15#if defined(LIGHTWEIGHT_TRACY_ENABLED)
16 #include <tracy/Tracy.hpp>
17#else
18 // No-op stubs. Each macro consumes ALL of its arguments via `(void) (...)`
19 // so call sites can pass locals (e.g. a sanitized SQL string, or a
20 // `varname` introduced solely for a `*V` zone-named overload) without
21 // triggering unused-variable / unused-parameter warnings when Tracy is
22 // disabled.
23 #define ZoneScoped
24 #define ZoneScopedN(name) ((void) sizeof(name))
25 #define ZoneScopedC(color) ((void) sizeof(color))
26 #define ZoneScopedNC(name, color) (((void) sizeof(name)), ((void) sizeof(color)))
27 #define ZoneText(text, size) (((void) (text)), ((void) (size)))
28 #define ZoneTextV(varname, text, size) (((void) (varname)), ((void) (text)), ((void) (size)))
29 #define ZoneName(text, size) (((void) (text)), ((void) (size)))
30 #define ZoneNameV(varname, text, size) (((void) (varname)), ((void) (text)), ((void) (size)))
31 #define ZoneValue(value) ((void) (value))
32 #define ZoneValueV(varname, value) (((void) (varname)), ((void) (value)))
33 #define ZoneColor(color) ((void) (color))
34 #define ZoneColorV(varname, color) (((void) (varname)), ((void) (color)))
35 #define FrameMark
36 #define FrameMarkNamed(name) ((void) sizeof(name))
37 #define FrameMarkStart(name) ((void) sizeof(name))
38 #define FrameMarkEnd(name) ((void) sizeof(name))
39 #define TracyPlot(name, value) (((void) sizeof(name)), ((void) (value)))
40 #define TracyPlotConfig(name, type, step, fill, color) \
41 (((void) sizeof(name)), ((void) (type)), ((void) (step)), ((void) (fill)), ((void) (color)))
42 #define TracyMessage(text, size) (((void) (text)), ((void) (size)))
43 #define TracyMessageL(text) ((void) (text))
44 #define TracyMessageC(text, size, color) (((void) (text)), ((void) (size)), ((void) (color)))
45 #define TracyMessageLC(text, color) (((void) (text)), ((void) (color)))
46 #define TracyAppInfo(text, size) (((void) (text)), ((void) (size)))
47#endif
48
49// Convenience wrapper for the very common `ZoneText(s.data(), s.size())`
50// pattern over std::string / std::string_view / SqlText / etc. Works in both
51// enabled and disabled builds because it forwards to `ZoneText` above.
52// NOTE: `obj` is evaluated twice — pass an lvalue, not a function call.
53#define ZoneTextObject(obj) ZoneText((obj).data(), (obj).size())