util/perf: support and prefer perfetto for cpu trace

To keep tracing working, this also adds util_perfetto_init to
eglGet*Display.

Acked-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Antonio Caggiano <antonio.caggiano@collabora.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18260>
This commit is contained in:
Chia-I Wu 2022-08-25 14:55:44 -07:00 committed by Marge Bot
parent 54b105f75d
commit 9518af12aa
2 changed files with 62 additions and 18 deletions

View File

@ -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);
}

View File

@ -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 <cutils/trace.h>
#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 */