Lightweight 0.20260617.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
18 #define TracySetThreadName(name) ::tracy::SetThreadName(name)
19#else
20 // No-op stubs. Each macro consumes ALL of its arguments via `(void) (...)`
21 // so call sites can pass locals (e.g. a sanitized SQL string, or a
22 // `varname` introduced solely for a `*V` zone-named overload) without
23 // triggering unused-variable / unused-parameter warnings when Tracy is
24 // disabled.
25 #define ZoneScoped
26 #define ZoneScopedN(name) ((void) sizeof(name))
27 #define ZoneScopedC(color) ((void) sizeof(color))
28 #define ZoneScopedNC(name, color) (((void) sizeof(name)), ((void) sizeof(color)))
29 #define ZoneText(text, size) (((void) (text)), ((void) (size)))
30 #define ZoneTextV(varname, text, size) (((void) (varname)), ((void) (text)), ((void) (size)))
31 #define ZoneName(text, size) (((void) (text)), ((void) (size)))
32 #define ZoneNameV(varname, text, size) (((void) (varname)), ((void) (text)), ((void) (size)))
33 #define ZoneValue(value) ((void) (value))
34 #define ZoneValueV(varname, value) (((void) (varname)), ((void) (value)))
35 #define ZoneColor(color) ((void) (color))
36 #define ZoneColorV(varname, color) (((void) (varname)), ((void) (color)))
37 #define FrameMark
38 #define FrameMarkNamed(name) ((void) sizeof(name))
39 #define FrameMarkStart(name) ((void) sizeof(name))
40 #define FrameMarkEnd(name) ((void) sizeof(name))
41 #define TracyPlot(name, value) (((void) sizeof(name)), ((void) (value)))
42 #define TracyPlotConfig(name, type, step, fill, color) \
43 (((void) sizeof(name)), ((void) (type)), ((void) (step)), ((void) (fill)), ((void) (color)))
44 #define TracyMessage(text, size) (((void) (text)), ((void) (size)))
45 #define TracyMessageL(text) ((void) (text))
46 #define TracyMessageC(text, size, color) (((void) (text)), ((void) (size)), ((void) (color)))
47 #define TracyMessageLC(text, color) (((void) (text)), ((void) (color)))
48 #define TracyAppInfo(text, size) (((void) (text)), ((void) (size)))
49 #define TracySetThreadName(name) ((void) sizeof(name))
50#endif
51
52// Convenience wrapper for the very common `ZoneText(s.data(), s.size())`
53// pattern over std::string / std::string_view / SqlText / etc. Works in both
54// enabled and disabled builds because it forwards to `ZoneText` above.
55// NOTE: `obj` is evaluated twice — pass an lvalue, not a function call.
56#define ZoneTextObject(obj) ZoneText((obj).data(), (obj).size())