14#include "xrt/xrt_config_have.h"
15#include "xrt/xrt_config_build.h"
19#if defined(XRT_FEATURE_TRACING) && defined(XRT_HAVE_PERCETTO)
20#define U_TRACE_PERCETTO
24#if !defined(XRT_FEATURE_TRACING) || !defined(XRT_HAVE_TRACY)
25#define U_TRACE_FUNC_COLOR(CATEGORY, COLOR) \
27 U_TRACE_FUNC(CATEGORY)
29#define U_TRACE_IDENT_COLOR(CATEGORY, IDENT, COLOR) \
31 U_TRACE_IDENT(CATEGORY, IDENT)
33#define U_TRACE_BEGIN_COLOR(CATEGORY, IDENT, COLOR) \
35 U_TRACE_BEGIN(CATEGORY, IDENT)
38#if defined(XRT_FEATURE_TRACING) && defined(XRT_HAVE_TRACY)
43#include "tracy/TracyC.h"
45#include "tracy/Tracy.hpp"
61 U_TRACE_WHICH_SERVICE,
81#define COLOR_TRACE_MARKER(COLOR) U_TRACE_FUNC_COLOR(color, COLOR)
82#define COLOR_TRACE_IDENT(IDENT, COLOR) U_TRACE_IDENT_COLOR(color, IDENT, COLOR)
83#define COLOR_TRACE_BEGIN(IDENT, COLOR) U_TRACE_BEGIN_COLOR(color, IDENT, COLOR)
84#define COLOR_TRACE_END(IDENT) U_TRACE_END(color, IDENT)
86#define VK_TRACE_MARKER() U_TRACE_FUNC_COLOR(vk, 0xffffff)
87#define VK_TRACE_IDENT(IDENT) U_TRACE_IDENT_COLOR(vk, IDENT, 0xffffff)
88#define VK_TRACE_BEGIN(IDENT) U_TRACE_BEGIN_COLOR(vk, IDENT, 0xffffff)
89#define VK_TRACE_END(IDENT) U_TRACE_END(vk, IDENT)
91#define XRT_TRACE_MARKER() U_TRACE_FUNC_COLOR(xrt, 0x708090)
92#define XRT_TRACE_IDENT(IDENT) U_TRACE_IDENT_COLOR(xrt, IDENT, 0x708090)
93#define XRT_TRACE_BEGIN(IDENT) U_TRACE_BEGIN_COLOR(xrt, IDENT, 0x708090)
94#define XRT_TRACE_END(IDENT) U_TRACE_END(xrt, IDENT)
96#define DRV_TRACE_MARKER() U_TRACE_FUNC_COLOR(drv, 0x000080)
97#define DRV_TRACE_IDENT(IDENT) U_TRACE_IDENT_COLOR(drv, IDENT, 0x000080)
98#define DRV_TRACE_BEGIN(IDENT) U_TRACE_BEGIN_COLOR(drv, IDENT, 0x000080)
99#define DRV_TRACE_END(IDENT) U_TRACE_END(drv, IDENT)
101#define IPC_TRACE_MARKER() U_TRACE_FUNC_COLOR(ipc, 0x87cefa)
102#define IPC_TRACE_IDENT(IDENT) U_TRACE_IDENT_COLOR(ipc, IDENT, 0x87cefa)
103#define IPC_TRACE_BEGIN(IDENT) U_TRACE_BEGIN_COLOR(ipc, IDENT, 0x87cefa)
104#define IPC_TRACE_END(IDENT) U_TRACE_END(ipc, IDENT)
106#define OXR_TRACE_MARKER() U_TRACE_FUNC_COLOR(oxr, 0x7fffd4)
107#define OXR_TRACE_IDENT(IDENT) U_TRACE_IDENT_COLOR(oxr, IDENT, 0x7fffd4)
108#define OXR_TRACE_BEGIN(IDENT) U_TRACE_BEGIN_COLOR(oxr, IDENT, 0x7fffd4)
109#define OXR_TRACE_END(IDENT) U_TRACE_END(oxr, IDENT, 0x7fffd4)
111#define COMP_TRACE_MARKER() U_TRACE_FUNC_COLOR(comp, 0x00ff00)
112#define COMP_TRACE_IDENT(IDENT) U_TRACE_IDENT_COLOR(comp, IDENT, 0x00ff00)
113#define COMP_TRACE_BEGIN(IDENT) U_TRACE_BEGIN_COLOR(comp, IDENT, 0x00ff00)
114#define COMP_TRACE_END(IDENT) U_TRACE_END(comp, IDENT)
116#define SINK_TRACE_MARKER() U_TRACE_FUNC_COLOR(sink, 0xffa500)
117#define SINK_TRACE_IDENT(IDENT) U_TRACE_IDENT_COLOR(sink, IDENT, 0xffa500)
118#define SINK_TRACE_BEGIN(IDENT) U_TRACE_BEGIN_COLOR(sink, IDENT, 0xffa500)
119#define SINK_TRACE_END(IDENT) U_TRACE_END(sink, IDENT)
121#define SWAPCHAIN_TRACE_MARKER() U_TRACE_FUNC_COLOR(sc, 0x007700)
122#define SWAPCHAIN_TRACE_IDENT(IDENT) U_TRACE_IDENT_COLOR(sc, IDENT, 0x007700)
123#define SWAPCHAIN_TRACE_BEGIN(IDENT) U_TRACE_BEGIN_COLOR(sc, IDENT, 0x007700)
124#define SWAPCHAIN_TRACE_END(IDENT) U_TRACE_END(sc, IDENT)
126#define TRACK_TRACE_MARKER() U_TRACE_FUNC_COLOR(track, 0xff0000)
127#define TRACK_TRACE_IDENT(IDENT) U_TRACE_IDENT_COLOR(track, IDENT, 0xff0000)
128#define TRACK_TRACE_BEGIN(IDENT) U_TRACE_BEGIN_COLOR(track, IDENT, 0xff0000)
129#define TRACK_TRACE_END(IDENT) U_TRACE_END(track, IDENT, 0xff0000)
138#ifndef XRT_FEATURE_TRACING
141#define U_TRACE_FUNC(CATEGORY) \
145#define U_TRACE_IDENT(CATEGORY, IDENT) \
149#define U_TRACE_BEGIN(CATEGORY, IDENT) \
150 int __trace_##IDENT = 0; \
154#define U_TRACE_END(CATEGORY, IDENT) \
156 (void)__trace_##IDENT; \
159#define U_TRACE_EVENT_BEGIN_ON_TRACK(CATEGORY, TRACK, TIME, NAME) \
163#define U_TRACE_EVENT_BEGIN_ON_TRACK_DATA(CATEGORY, TRACK, TIME, NAME, ...) \
167#define U_TRACE_EVENT_END_ON_TRACK(CATEGORY, TRACK, TIME) \
171#define U_TRACE_INSTANT_ON_TRACK(CATEGORY, TRACK, TIME, NAME) \
175#define U_TRACE_CATEGORY_IS_ENABLED(_) (false)
177#define U_TRACE_SET_THREAD_NAME(STRING) \
187#define U_TRACE_TARGET_SETUP(WHICH)
196#elif defined(XRT_HAVE_TRACY)
201#define U_TRACE_FUNC_COLOR(CATEGORY, COLOR) ZoneScopedC(COLOR)
203#define U_TRACE_FUNC(CATEGORY) ZoneScoped
205#define U_TRACE_IDENT_COLOR(CATEGORY, IDENT, COLOR) ZoneScopedNC(#IDENT, COLOR)
207#define U_TRACE_IDENT(CATEGORY, IDENT) ZoneScopedN(#IDENT)
209#elif !defined(XRT_OS_WINDOWS)
212u_trace_scope_cleanup(TracyCZoneCtx *ctx_ptr)
214 TracyCZoneEnd(*ctx_ptr);
217#define U_TRACE_FUNC_COLOR(CATEGORY, COLOR) \
218 static const struct ___tracy_source_location_data __func_loc = { \
219 NULL, __func__, __FILE__, (uint32_t)__LINE__, COLOR, \
221 TracyCZoneCtx __attribute__((cleanup(u_trace_scope_cleanup))) ctx = \
222 ___tracy_emit_zone_begin(&__func_loc, true); \
226#define U_TRACE_FUNC(CATEGORY) \
227 static const struct ___tracy_source_location_data __func_loc = { \
228 NULL, __func__, __FILE__, (uint32_t)__LINE__, 0, \
230 TracyCZoneCtx __attribute__((cleanup(u_trace_scope_cleanup))) ctx = \
231 ___tracy_emit_zone_begin(&__func_loc, true); \
234#define U_TRACE_IDENT_COLOR(CATEGORY, IDENT, COLOR) \
235 static const struct ___tracy_source_location_data __##IDENT##_loc = { \
236 #IDENT, __func__, __FILE__, (uint32_t)__LINE__, COLOR, \
238 TracyCZoneCtx __attribute__((cleanup(u_trace_scope_cleanup))) ctx##IDENT = \
239 ___tracy_emit_zone_begin(&__##IDENT##_loc, true); \
242#define U_TRACE_IDENT(CATEGORY, IDENT) \
243 static const struct ___tracy_source_location_data __##IDENT##_loc = { \
244 #IDENT, __func__, __FILE__, (uint32_t)__LINE__, 0, \
246 TracyCZoneCtx __attribute__((cleanup(u_trace_scope_cleanup))) ctx##IDENT = \
247 ___tracy_emit_zone_begin(&__##IDENT##_loc, true); \
251#define U_TRACE_FUNC_COLOR(CATEGORY, COLOR) \
255#define U_TRACE_FUNC(CATEGORY) \
259#define U_TRACE_IDENT_COLOR(CATEGORY, IDENT, COLOR) \
263#define U_TRACE_IDENT(CATEGORY, IDENT) \
269#define U_TRACE_BEGIN(CATEGORY, IDENT) TracyCZoneN(__trace_##IDENT, #IDENT, true)
270#define U_TRACE_BEGIN_COLOR(CATEGORY, IDENT, COLOR) TracyCZoneNC(__trace_##IDENT, #IDENT, COLOR, true)
271#define U_TRACE_END(CATEGORY, IDENT) TracyCZoneEnd(__trace_##IDENT)
273#define U_TRACE_EVENT_BEGIN_ON_TRACK(CATEGORY, TRACK, TIME, NAME) \
277#define U_TRACE_EVENT_BEGIN_ON_TRACK_DATA(CATEGORY, TRACK, TIME, NAME, ...) \
281#define U_TRACE_EVENT_END_ON_TRACK(CATEGORY, TRACK, TIME) \
285#define U_TRACE_INSTANT_ON_TRACK(CATEGORY, TRACK, TIME, NAME) \
289#define U_TRACE_CATEGORY_IS_ENABLED(_) (true)
291#define U_TRACE_SET_THREAD_NAME(STRING) \
294 TracyCZoneN(created, "created", true); \
295 TracyCSetThreadName(STRING); \
296 TracyCZoneEnd(created); \
299#define U_TRACE_TARGET_SETUP(WHICH)
308#elif defined(XRT_HAVE_PERCETTO)
311#error "Tracing only supported on Linux"
315#define U_TRACE_CATEGORIES(C, G) \
327PERCETTO_CATEGORY_DECLARE(U_TRACE_CATEGORIES)
329PERCETTO_TRACK_DECLARE(pc_cpu);
330PERCETTO_TRACK_DECLARE(pc_allotted);
331PERCETTO_TRACK_DECLARE(pc_gpu);
332PERCETTO_TRACK_DECLARE(pc_margin);
333PERCETTO_TRACK_DECLARE(pc_error);
334PERCETTO_TRACK_DECLARE(pc_info);
335PERCETTO_TRACK_DECLARE(pc_present);
336PERCETTO_TRACK_DECLARE(pa_cpu);
337PERCETTO_TRACK_DECLARE(pa_draw);
338PERCETTO_TRACK_DECLARE(pa_wait);
340#define U_TRACE_FUNC(CATEGORY) TRACE_EVENT(CATEGORY, __func__)
341#define U_TRACE_IDENT(CATEGORY, IDENT) TRACE_EVENT(CATEGORY, #IDENT)
342#define U_TRACE_BEGIN(CATEGORY, IDENT) TRACE_EVENT_BEGIN(CATEGORY, #IDENT)
343#define U_TRACE_END(CATEGORY, IDENT) TRACE_EVENT_END(CATEGORY)
344#define U_TRACE_EVENT_BEGIN_ON_TRACK(CATEGORY, TRACK, TIME, NAME) \
345 TRACE_EVENT_BEGIN_ON_TRACK(CATEGORY, TRACK, TIME, NAME)
346#define U_TRACE_EVENT_BEGIN_ON_TRACK_DATA(CATEGORY, TRACK, TIME, NAME, ...) \
347 TRACE_EVENT_BEGIN_ON_TRACK_DATA(CATEGORY, TRACK, TIME, NAME, __VA_ARGS__)
348#define U_TRACE_EVENT_END_ON_TRACK(CATEGORY, TRACK, TIME) TRACE_EVENT_END_ON_TRACK(CATEGORY, TRACK, TIME)
349#define U_TRACE_CATEGORY_IS_ENABLED(CATEGORY) PERCETTO_CATEGORY_IS_ENABLED(CATEGORY)
350#define U_TRACE_INSTANT_ON_TRACK(CATEGORY, TRACK, TIME, NAME) \
351 TRACE_ANY_WITH_ARGS(PERCETTO_EVENT_INSTANT, CATEGORY, &g_percetto_track_##TRACK, TIME, NAME, 0)
352#define U_TRACE_DATA(fd, type, data) u_trace_data(fd, type, (void *)&(data), sizeof(data))
354#define U_TRACE_SET_THREAD_NAME(STRING) \
359#define U_TRACE_TARGET_SETUP(WHICH) \
360 void __attribute__((constructor(101))) u_trace_marker_constructor(void); \
362 void u_trace_marker_constructor(void) \
364 u_trace_marker_setup(WHICH); \
369#error "Need to have Percetto/Perfetto"
u_trace_which
Should the extra tracks be enabled, see Tracing support.
Definition: u_trace_marker.h:60
void u_trace_marker_setup(enum u_trace_which which)
Internal setup function, use U_TRACE_TARGET_SETUP, see Tracing support.
Definition: u_trace_marker.c:95
void u_trace_marker_init(void)
Must be called from a non-static/global constructor context.
Definition: u_trace_marker.c:103
Header holding common defines.
Auto detect OS and certain features.