From 024a0d969dbbb8cfb3a4864b621b7be62e727455 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Wed, 11 Nov 2020 10:58:01 +0100 Subject: [PATCH] virgl: Add tracing to stderr as alternative tracing method This simply logs all tagged calls and scopes to stderr. v2: - Fix option comparsion - add trace_init stub - update the combo option description Signed-off-by: Gert Wollny Reviewed-by: Chia-I Wu --- meson.build | 4 ++++ meson_options.txt | 4 ++-- src/virgl_util.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/virgl_util.h | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index f4d1c04..fc9dea7 100644 --- a/meson.build +++ b/meson.build @@ -96,6 +96,10 @@ if with_tracing == 'perfetto' conf_data.set('ENABLE_TRACING', 'TRACE_WITH_PERFETTO') endif +if with_tracing == 'stderr' + conf_data.set('ENABLE_TRACING', 'TRACE_WITH_STDERR') +endif + if cc.has_header('sys/uio.h') conf_data.set('HAVE_SYS_UIO_H', 1) endif diff --git a/meson_options.txt b/meson_options.txt index e7f3e12..ce988a6 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -63,6 +63,6 @@ option( 'tracing', type : 'combo', value : 'none', - choices : [ 'perfetto', 'none' ], - description : 'enable emitting traces for Perfetto' + choices : [ 'perfetto', 'stderr', 'none' ], + description : 'enable emitting traces using the selected backend' ) diff --git a/src/virgl_util.c b/src/virgl_util.c index 0267acc..2f673dd 100644 --- a/src/virgl_util.c +++ b/src/virgl_util.c @@ -47,6 +47,10 @@ #include #endif +#if ENABLE_TRACING == TRACE_WITH_STDERR +#include +#endif + unsigned hash_func_u32(void *key) { intptr_t ip = pointer_to_intptr(key); @@ -139,3 +143,40 @@ void trace_end(char **dummy) vperfetto_min_endTrackEvent_VMM(); } #endif + +#if ENABLE_TRACING == TRACE_WITH_STDERR +static int nesting_depth = 0; +void trace_init(void) +{ +} + +char *trace_begin(const char* format, ...) +{ + for (int i = 0; i < nesting_depth; ++i) + fprintf(stderr, " "); + + fprintf(stderr, "ENTER:"); + char *buffer; + va_list args; + va_start (args, format); + int size = vasprintf(&buffer, format, args); + + if (size < 0) + buffer=strdup("error"); + + va_end (args); + fprintf(stderr, "%s\n", buffer); + nesting_depth++; + + return buffer; +} + +void trace_end(char **func_name) +{ + --nesting_depth; + for (int i = 0; i < nesting_depth; ++i) + fprintf(stderr, " "); + fprintf(stderr, "LEAVE %s\n", *func_name); + free(*func_name); +} +#endif diff --git a/src/virgl_util.h b/src/virgl_util.h index 29d6fed..861ecd7 100644 --- a/src/virgl_util.h +++ b/src/virgl_util.h @@ -33,7 +33,7 @@ #endif #define TRACE_WITH_PERFETTO 1 - +#define TRACE_WITH_STDERR 2 #define BIT(n) (UINT32_C(1) << (n))