diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index d308f08cdf6..de2c53eafd9 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -356,6 +356,7 @@ eglGetDisplay(EGLNativeDisplayType nativeDisplay) _EGLDisplay *disp; void *native_display_ptr; + util_perfetto_init(); _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL); STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay)); @@ -420,6 +421,7 @@ eglGetPlatformDisplayEXT(EGLenum platform, void *native_display, EGLAttrib *attrib_list; EGLDisplay disp; + util_perfetto_init(); _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL); if (_eglConvertIntsToAttribs(int_attribs, &attrib_list) != EGL_SUCCESS) @@ -434,6 +436,7 @@ EGLDisplay EGLAPIENTRY eglGetPlatformDisplay(EGLenum platform, void *native_display, const EGLAttrib *attrib_list) { + util_perfetto_init(); _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL); return _eglGetPlatformDisplayCommon(platform, native_display, attrib_list); } diff --git a/src/util/perf/cpu_trace.h b/src/util/perf/cpu_trace.h index 75afb8cbd0a..c13a3821158 100644 --- a/src/util/perf/cpu_trace.h +++ b/src/util/perf/cpu_trace.h @@ -6,25 +6,46 @@ #ifndef CPU_TRACE_H #define CPU_TRACE_H +#include "u_perfetto.h" + +#include "util/macros.h" + +#if defined(HAVE_PERFETTO) + +/* note that util_perfetto_is_category_enabled always returns false util + * util_perfetto_init is called + */ +#define _MESA_TRACE_BEGIN(category, name) \ + do { \ + if (unlikely(util_perfetto_is_category_enabled(category))) \ + util_perfetto_trace_begin(category, name); \ + } while (0) + +#define _MESA_TRACE_END(category) \ + do { \ + if (unlikely(util_perfetto_is_category_enabled(category))) \ + util_perfetto_trace_end(category); \ + } while (0) + /* NOTE: for now disable atrace for C++ to workaround a ndk bug with ordering * between stdatomic.h and atomic.h. See: * * https://github.com/android/ndk/issues/1178 */ -#if defined(ANDROID) && !defined(__cplusplus) +#elif defined(ANDROID) && !defined(__cplusplus) #include -#define MESA_TRACE_BEGIN(name) atrace_begin(ATRACE_TAG_GRAPHICS, name) -#define MESA_TRACE_END() atrace_end(ATRACE_TAG_GRAPHICS) +#define _MESA_TRACE_BEGIN(category, name) \ + atrace_begin(ATRACE_TAG_GRAPHICS, name) +#define _MESA_TRACE_END(category) atrace_end(ATRACE_TAG_GRAPHICS) #else -/* XXX we would like to use perfetto, but it lacks a C header */ -#define MESA_TRACE_BEGIN(name) -#define MESA_TRACE_END() +#define _MESA_TRACE_BEGIN(category, name) +#define _MESA_TRACE_END(category) -#endif /* ANDROID */ +#endif /* HAVE_PERFETTO */ #if __has_attribute(cleanup) && __has_attribute(unused) @@ -35,34 +56,54 @@ /* This must expand to a single non-scoped statement for * * if (cond) - * MESA_TRACE_SCOPE(...) + * _MESA_TRACE_SCOPE(...) * * to work. */ -#define MESA_TRACE_SCOPE(name) \ +#define _MESA_TRACE_SCOPE(category, name) \ int _MESA_TRACE_SCOPE_VAR(__LINE__) \ - __attribute__((cleanup(mesa_trace_scope_end), unused)) = \ - mesa_trace_scope_begin(name) + __attribute__((cleanup(_mesa_trace_scope_end), unused)) = \ + _mesa_trace_scope_begin(category, name) static inline int -mesa_trace_scope_begin(const char *name) +_mesa_trace_scope_begin(enum util_perfetto_category category, + const char *name) { - MESA_TRACE_BEGIN(name); - return 0; + _MESA_TRACE_BEGIN(category, name); + return category; } static inline void -mesa_trace_scope_end(int *scope) +_mesa_trace_scope_end(int *scope) { - MESA_TRACE_END(); + /* we save the category in the scope variable */ + _MESA_TRACE_END(*scope); } #else -#define MESA_TRACE_SCOPE(name) +#define _MESA_TRACE_SCOPE(category, name) #endif /* __has_attribute(cleanup) && __has_attribute(unused) */ -#define MESA_TRACE_FUNC() MESA_TRACE_SCOPE(__func__) +/* These use the default category. Drivers or subsystems can use these, or + * define their own categories/macros. + */ +#define MESA_TRACE_BEGIN(name) \ + _MESA_TRACE_BEGIN(UTIL_PERFETTO_CATEGORY_DEFAULT, name) +#define MESA_TRACE_END() _MESA_TRACE_END(UTIL_PERFETTO_CATEGORY_DEFAULT) +#define MESA_TRACE_SCOPE(name) \ + _MESA_TRACE_SCOPE(UTIL_PERFETTO_CATEGORY_DEFAULT, name) +#define MESA_TRACE_FUNC() \ + _MESA_TRACE_SCOPE(UTIL_PERFETTO_CATEGORY_DEFAULT, __func__) + +/* these use the slow category */ +#define MESA_TRACE_BEGIN_SLOW(name) \ + _MESA_TRACE_BEGIN(UTIL_PERFETTO_CATEGORY_SLOW, name) +#define MESA_TRACE_END_SLOW() _MESA_TRACE_END(UTIL_PERFETTO_CATEGORY_SLOW) +#define MESA_TRACE_SCOPE_SLOW(name) \ + _MESA_TRACE_SCOPE(UTIL_PERFETTO_CATEGORY_SLOW, name) +#define MESA_TRACE_FUNC_SLOW() \ + _MESA_TRACE_SCOPE(UTIL_PERFETTO_CATEGORY_SLOW, __func__) #endif /* CPU_TRACE_H */