diff --git a/meson.build b/meson.build index f4c09e5..333dd74 100644 --- a/meson.build +++ b/meson.build @@ -91,6 +91,14 @@ endif endif +if with_tracing == 'percetto' + # percetto uses C++ internally, so we need to link with C++. + # TODO: remove -lstdc++ when percetto is a shared library. + add_project_link_arguments('-lstdc++', language : 'c') + percetto_dep = dependency('percetto', version : '>=0.0.8') + conf_data.set('ENABLE_TRACING', 'TRACE_WITH_PERCETTO') +endif + if with_tracing == 'perfetto' vperfetto_min_dep = dependency('vperfetto_min') conf_data.set('ENABLE_TRACING', 'TRACE_WITH_PERFETTO') diff --git a/meson_options.txt b/meson_options.txt index ce988a6..0a57b6f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -63,6 +63,6 @@ option( 'tracing', type : 'combo', value : 'none', - choices : [ 'perfetto', 'stderr', 'none' ], + choices : [ 'percetto', 'perfetto', 'stderr', 'none' ], description : 'enable emitting traces using the selected backend' ) diff --git a/src/meson.build b/src/meson.build index d854027..257d7dc 100644 --- a/src/meson.build +++ b/src/meson.build @@ -86,6 +86,10 @@ if with_tracing == 'perfetto' virgl_depends += [vperfetto_min_dep] endif +if with_tracing == 'percetto' + virgl_depends += [percetto_dep] +endif + virgl_sources += vrend_sources if have_egl diff --git a/src/virgl_util.c b/src/virgl_util.c index 5f14058..6dead0a 100644 --- a/src/virgl_util.c +++ b/src/virgl_util.c @@ -114,6 +114,15 @@ void flush_eventfd(int fd) } while ((len == -1 && errno == EINTR) || len == sizeof(value)); } +#if ENABLE_TRACING == TRACE_WITH_PERCETTO +PERCETTO_CATEGORY_DEFINE(VIRGL_PERCETTO_CATEGORIES) + +void trace_init(void) +{ + PERCETTO_INIT(PERCETTO_CLOCK_DONT_CARE); +} +#endif + #if ENABLE_TRACING == TRACE_WITH_PERFETTO void trace_init(void) { diff --git a/src/virgl_util.h b/src/virgl_util.h index f0158fd..951410e 100644 --- a/src/virgl_util.h +++ b/src/virgl_util.h @@ -34,6 +34,7 @@ #define TRACE_WITH_PERFETTO 1 #define TRACE_WITH_STDERR 2 +#define TRACE_WITH_PERCETTO 3 #define BIT(n) (UINT32_C(1) << (n)) @@ -63,20 +64,42 @@ void flush_eventfd(int fd); #ifdef ENABLE_TRACING void trace_init(void); -const char *trace_begin(const char *scope); -void trace_end(const char **dummy); #define TRACE_INIT() trace_init() #define TRACE_FUNC() TRACE_SCOPE(__func__) +#if ENABLE_TRACING == TRACE_WITH_PERCETTO + +#include + +#define VIRGL_PERCETTO_CATEGORIES(C, G) \ + C(virgl, "virglrenderer") \ + C(virgls, "virglrenderer detailed events", "slow") + +PERCETTO_CATEGORY_DECLARE(VIRGL_PERCETTO_CATEGORIES) + +#define TRACE_SCOPE(SCOPE) TRACE_EVENT(virgl, SCOPE) +/* Trace high frequency events (tracing may impact performance). */ +#define TRACE_SCOPE_SLOW(SCOPE) TRACE_EVENT(virgls, SCOPE) + +#else + +const char *trace_begin(const char *scope); +void trace_end(const char **scope); + #define TRACE_SCOPE(SCOPE) \ const char *trace_dummy __attribute__((cleanup (trace_end), unused)) = \ trace_begin(SCOPE) +#define TRACE_SCOPE_SLOW(SCOPE) TRACE_SCOPE(SCOPE) + +#endif /* ENABLE_TRACING == TRACE_WITH_PERCETTO */ + #else #define TRACE_INIT() #define TRACE_FUNC() #define TRACE_SCOPE(SCOPE) -#endif +#define TRACE_SCOPE_SLOW(SCOPE) +#endif /* ENABLE_TRACING */ #endif /* VIRGL_UTIL_H */