perfetto: Add flows

Perfetto can assign flow ids to events, which can be used to connect
related events in tracks when they share the same id.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28634>
This commit is contained in:
Derek Foreman 2024-04-05 07:24:57 -05:00 committed by Marge Bot
parent 8b460cf9b5
commit 16b8dbedfa
3 changed files with 55 additions and 0 deletions

View file

@ -23,6 +23,12 @@
util_perfetto_trace_begin(name); \
} while (0)
#define _MESA_TRACE_FLOW_BEGIN(name, id) \
do { \
if (unlikely(util_perfetto_is_tracing_enabled())) \
util_perfetto_trace_begin_flow(name, id); \
} while (0)
#define _MESA_TRACE_END() \
do { \
if (unlikely(util_perfetto_is_tracing_enabled())) \
@ -41,11 +47,14 @@
#define _MESA_TRACE_BEGIN(name) \
atrace_begin(ATRACE_TAG_GRAPHICS, name)
#define _MESA_TRACE_END() atrace_end(ATRACE_TAG_GRAPHICS)
#define _MESA_TRACE_FLOW_BEGIN(name, id) \
atrace_begin(ATRACE_TAG_GRAPHICS, name)
#else
#define _MESA_TRACE_BEGIN(name)
#define _MESA_TRACE_END()
#define _MESA_TRACE_FLOW_BEGIN(name, id)
#endif /* HAVE_PERFETTO */
@ -79,6 +88,11 @@
__attribute__((cleanup(_mesa_trace_scope_end), unused)) = \
_mesa_trace_scope_begin(name)
#define _MESA_TRACE_SCOPE_FLOW(name, id) \
int _MESA_TRACE_SCOPE_VAR(__LINE__) \
__attribute__((cleanup(_mesa_trace_scope_end), unused)) = \
_mesa_trace_scope_flow_begin(name, id)
static inline int
_mesa_trace_scope_begin(const char *name)
{
@ -87,6 +101,16 @@ _mesa_trace_scope_begin(const char *name)
return 0;
}
static inline int
_mesa_trace_scope_flow_begin(const char *name, uint64_t *id)
{
if (*id == 0)
*id = util_perfetto_next_id();
_MESA_TRACE_FLOW_BEGIN(name, *id);
_MESA_GPUVIS_TRACE_BEGIN(name);
return 0;
}
static inline void
_mesa_trace_scope_end(UNUSED int *scope)
{
@ -101,7 +125,9 @@ _mesa_trace_scope_end(UNUSED int *scope)
#endif /* __has_attribute(cleanup) && __has_attribute(unused) */
#define MESA_TRACE_SCOPE(name) _MESA_TRACE_SCOPE(name)
#define MESA_TRACE_SCOPE_FLOW(name, id) _MESA_TRACE_SCOPE_FLOW(name, id)
#define MESA_TRACE_FUNC() _MESA_TRACE_SCOPE(__func__)
#define MESA_TRACE_FUNC_FLOW(id) _MESA_TRACE_SCOPE_FLOW(__func__, id)
static inline void
util_cpu_trace_init()

View file

@ -39,6 +39,8 @@ PERFETTO_TRACK_EVENT_STATIC_STORAGE();
int util_perfetto_tracing_state;
static uint64_t util_perfetto_unique_id = 1;
static void
util_perfetto_update_tracing_state(void)
{
@ -62,6 +64,20 @@ util_perfetto_trace_end(void)
util_perfetto_update_tracing_state();
}
void
util_perfetto_trace_begin_flow(const char *fname, uint64_t id)
{
TRACE_EVENT_BEGIN(
UTIL_PERFETTO_CATEGORY_DEFAULT_STR, nullptr, perfetto::Flow::ProcessScoped(id),
[&](perfetto::EventContext ctx) { ctx.event()->set_name(fname); });
}
uint64_t
util_perfetto_next_id(void)
{
return p_atomic_inc_return(&util_perfetto_unique_id);
}
class UtilPerfettoObserver : public perfetto::TrackEventSessionObserver {
public:
UtilPerfettoObserver() { perfetto::TrackEvent::AddSessionObserver(this); }

View file

@ -46,6 +46,10 @@ void util_perfetto_trace_begin(const char *name);
void util_perfetto_trace_end(void);
void util_perfetto_trace_begin_flow(const char *fname, uint64_t id);
uint64_t util_perfetto_next_id(void);
#else /* HAVE_PERFETTO */
static inline void
@ -69,6 +73,15 @@ util_perfetto_trace_end(void)
{
}
static inline void util_perfetto_trace_begin_flow(const char *fname, uint64_t id)
{
}
static inline uint64_t util_perfetto_next_id(void)
{
return 0;
}
#endif /* HAVE_PERFETTO */
#ifdef __cplusplus