perfetto: Add some functions for timestamped events

This can be useful if we know when an event happened, but our code isn't
running at that time (such as reporting when an image was presented in
the wayland wsi).

We can't really mix these with events that we log at the current time,
because there could be overlap, so also add a function for creating
custom tracks.

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:44:24 -05:00 committed by Marge Bot
parent 57c03fe49c
commit e9596149cf
3 changed files with 69 additions and 1 deletions

View File

@ -41,6 +41,18 @@
util_perfetto_counter_set(name, value); \
} while (0)
#define _MESA_TRACE_TIMESTAMP_BEGIN(name, track_id, flow_id, timestamp) \
do { \
if (unlikely(util_perfetto_is_tracing_enabled())) \
util_perfetto_trace_full_begin(name, track_id, flow_id, timestamp); \
} while (0)
#define _MESA_TRACE_TIMESTAMP_END(name, track_id, timestamp) \
do { \
if (unlikely(util_perfetto_is_tracing_enabled())) \
util_perfetto_trace_full_end(name, track_id, timestamp); \
} while (0)
/* NOTE: for now disable atrace for C++ to workaround a ndk bug with ordering
* between stdatomic.h and atomic.h. See:
*
@ -56,13 +68,16 @@
#define _MESA_TRACE_FLOW_BEGIN(name, id) \
atrace_begin(ATRACE_TAG_GRAPHICS, name)
#define _MESA_TRACE_SET_COUNTER(name, value)
#define _MESA_TRACE_TIMESTAMP_BEGIN(name, track_id, flow_id, timestamp)
#define _MESA_TRACE_TIMESTAMP_END(name, track_id, timestamp)
#else
#define _MESA_TRACE_BEGIN(name)
#define _MESA_TRACE_END()
#define _MESA_TRACE_FLOW_BEGIN(name, id)
#define _MESA_TRACE_SET_COUNTER(name, value)
#define _MESA_TRACE_TIMESTAMP_BEGIN(name, track_id, flow_id, timestamp)
#define _MESA_TRACE_TIMESTAMP_END(name, track_id, timestamp)
#endif /* HAVE_PERFETTO */
@ -137,6 +152,10 @@ _mesa_trace_scope_end(UNUSED int *scope)
#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)
#define MESA_TRACE_TIMESTAMP_BEGIN(name, track_id, flow_id, timestamp) \
_MESA_TRACE_TIMESTAMP_BEGIN(name, track_id, flow_id, timestamp)
#define MESA_TRACE_TIMESTAMP_END(name, track_id, timestamp) \
_MESA_TRACE_TIMESTAMP_END(name, track_id, timestamp)
static inline void
util_cpu_trace_init()

View File

@ -72,6 +72,34 @@ util_perfetto_trace_begin_flow(const char *fname, uint64_t id)
[&](perfetto::EventContext ctx) { ctx.event()->set_name(fname); });
}
void
util_perfetto_trace_full_begin(const char *fname, uint64_t track_id, uint64_t id, uint64_t timestamp)
{
TRACE_EVENT_BEGIN(
UTIL_PERFETTO_CATEGORY_DEFAULT_STR, nullptr, perfetto::Track(track_id),
timestamp, perfetto::Flow::ProcessScoped(id),
[&](perfetto::EventContext ctx) { ctx.event()->set_name(fname); });
}
uint64_t
util_perfetto_new_track(const char *name)
{
uint64_t track_id = util_perfetto_next_id();
auto track = perfetto::Track(track_id);
auto desc = track.Serialize();
desc.set_name(name);
perfetto::TrackEvent::SetTrackDescriptor(track, desc);
return track_id;
}
void
util_perfetto_trace_full_end(const char *name, uint64_t track_id, uint64_t timestamp)
{
TRACE_EVENT_END(UTIL_PERFETTO_CATEGORY_DEFAULT_STR, perfetto::Track(track_id), timestamp);
util_perfetto_update_tracing_state();
}
void
util_perfetto_counter_set(const char *name, double value)
{

View File

@ -50,8 +50,14 @@ void util_perfetto_trace_begin_flow(const char *fname, uint64_t id);
void util_perfetto_counter_set(const char *name, double value);
void util_perfetto_trace_full_begin(const char *name, uint64_t track_id, uint64_t id, uint64_t timestamp);
void util_perfetto_trace_full_end(const char *name, uint64_t track_id, uint64_t timestamp);
uint64_t util_perfetto_next_id(void);
uint64_t util_perfetto_new_track(const char *name);
#else /* HAVE_PERFETTO */
static inline void
@ -79,6 +85,16 @@ static inline void util_perfetto_trace_begin_flow(const char *fname, uint64_t id
{
}
static inline void
util_perfetto_trace_full_begin(const char *name, uint64_t track_id, uint64_t id, uint64_t timestamp)
{
}
static inline void
util_perfetto_trace_full_end(const char *name, uint64_t track_id)
{
}
static inline void util_perfetto_counter_set(const char *name, double value)
{
}
@ -88,6 +104,11 @@ static inline uint64_t util_perfetto_next_id(void)
return 0;
}
static inline uint64_t util_perfetto_new_track(const char *name)
{
return 0;
}
#endif /* HAVE_PERFETTO */
#ifdef __cplusplus