Module: Mesa Branch: main Commit: 3163e637f4999292088983f62f2cec328f6bbb12 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=3163e637f4999292088983f62f2cec328f6bbb12
Author: Chia-I Wu <[email protected]> Date: Thu Aug 25 14:22:19 2022 -0700 util/perf: fix multiple tracepoints in a scope Fixes "../src/util/perf/cpu_trace.h:32:8: error: redefinition of ‘_mesa_trace_scope___LINE__’" This should work until someone wants multiple MESA_TRACE_SCOPE on the same line :) Acked-by: Rob Clark <[email protected]> Reviewed-by: Antonio Caggiano <[email protected]> Reviewed-by: Yiwei Zhang <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18260> --- src/util/perf/cpu_trace.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/util/perf/cpu_trace.h b/src/util/perf/cpu_trace.h index 2cd510aa6e2..75afb8cbd0a 100644 --- a/src/util/perf/cpu_trace.h +++ b/src/util/perf/cpu_trace.h @@ -28,9 +28,20 @@ #if __has_attribute(cleanup) && __has_attribute(unused) -#define MESA_TRACE_SCOPE(name) \ - int _mesa_trace_scope_##__LINE__ \ - __attribute__((cleanup(mesa_trace_scope_end), unused)) = \ +#define _MESA_TRACE_SCOPE_VAR_CONCAT(name, suffix) name##suffix +#define _MESA_TRACE_SCOPE_VAR(suffix) \ + _MESA_TRACE_SCOPE_VAR_CONCAT(_mesa_trace_scope_, suffix) + +/* This must expand to a single non-scoped statement for + * + * if (cond) + * MESA_TRACE_SCOPE(...) + * + * to work. + */ +#define MESA_TRACE_SCOPE(name) \ + int _MESA_TRACE_SCOPE_VAR(__LINE__) \ + __attribute__((cleanup(mesa_trace_scope_end), unused)) = \ mesa_trace_scope_begin(name) static inline int
