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))