perfetto: Add simple support for counters

Perfetto can report time varying numberic values (counters) in tracks.

Add some simple functions to use this.

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 10:22:45 -05:00
committed by Marge Bot
parent 34273bc4ed
commit 60eb27591f
3 changed files with 21 additions and 0 deletions
+9
View File
@@ -35,6 +35,12 @@
util_perfetto_trace_end(); \
} while (0)
#define _MESA_TRACE_SET_COUNTER(name, value) \
do { \
if (unlikely(util_perfetto_is_tracing_enabled())) \
util_perfetto_counter_set(name, value); \
} while (0)
/* NOTE: for now disable atrace for C++ to workaround a ndk bug with ordering
* between stdatomic.h and atomic.h. See:
*
@@ -49,12 +55,14 @@
#define _MESA_TRACE_END() atrace_end(ATRACE_TAG_GRAPHICS)
#define _MESA_TRACE_FLOW_BEGIN(name, id) \
atrace_begin(ATRACE_TAG_GRAPHICS, name)
#define _MESA_TRACE_SET_COUNTER(name, value)
#else
#define _MESA_TRACE_BEGIN(name)
#define _MESA_TRACE_END()
#define _MESA_TRACE_FLOW_BEGIN(name, id)
#define _MESA_TRACE_SET_COUNTER(name, value)
#endif /* HAVE_PERFETTO */
@@ -128,6 +136,7 @@ _mesa_trace_scope_end(UNUSED int *scope)
#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)
#define MESA_TRACE_SET_COUNTER(name, value) _MESA_TRACE_SET_COUNTER(name, value)
static inline void
util_cpu_trace_init()
+6
View File
@@ -72,6 +72,12 @@ util_perfetto_trace_begin_flow(const char *fname, uint64_t id)
[&](perfetto::EventContext ctx) { ctx.event()->set_name(fname); });
}
void
util_perfetto_counter_set(const char *name, double value)
{
TRACE_COUNTER(UTIL_PERFETTO_CATEGORY_DEFAULT_STR, name, value);
}
uint64_t
util_perfetto_next_id(void)
{
+6
View File
@@ -48,6 +48,8 @@ void util_perfetto_trace_end(void);
void util_perfetto_trace_begin_flow(const char *fname, uint64_t id);
void util_perfetto_counter_set(const char *name, double value);
uint64_t util_perfetto_next_id(void);
#else /* HAVE_PERFETTO */
@@ -77,6 +79,10 @@ static inline void util_perfetto_trace_begin_flow(const char *fname, uint64_t id
{
}
static inline void util_perfetto_counter_set(const char *name, double value)
{
}
static inline uint64_t util_perfetto_next_id(void)
{
return 0;