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 <gert.wollny@collabora.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
macos/master
Gert Wollny 4 years ago committed by Gert Wollny
parent 19d65e83e3
commit 024a0d969d
  1. 4
      meson.build
  2. 4
      meson_options.txt
  3. 41
      src/virgl_util.c
  4. 2
      src/virgl_util.h

@ -96,6 +96,10 @@ if with_tracing == 'perfetto'
conf_data.set('ENABLE_TRACING', 'TRACE_WITH_PERFETTO') conf_data.set('ENABLE_TRACING', 'TRACE_WITH_PERFETTO')
endif endif
if with_tracing == 'stderr'
conf_data.set('ENABLE_TRACING', 'TRACE_WITH_STDERR')
endif
if cc.has_header('sys/uio.h') if cc.has_header('sys/uio.h')
conf_data.set('HAVE_SYS_UIO_H', 1) conf_data.set('HAVE_SYS_UIO_H', 1)
endif endif

@ -63,6 +63,6 @@ option(
'tracing', 'tracing',
type : 'combo', type : 'combo',
value : 'none', value : 'none',
choices : [ 'perfetto', 'none' ], choices : [ 'perfetto', 'stderr', 'none' ],
description : 'enable emitting traces for Perfetto' description : 'enable emitting traces using the selected backend'
) )

@ -47,6 +47,10 @@
#include <vperfetto-min.h> #include <vperfetto-min.h>
#endif #endif
#if ENABLE_TRACING == TRACE_WITH_STDERR
#include <stdio.h>
#endif
unsigned hash_func_u32(void *key) unsigned hash_func_u32(void *key)
{ {
intptr_t ip = pointer_to_intptr(key); intptr_t ip = pointer_to_intptr(key);
@ -139,3 +143,40 @@ void trace_end(char **dummy)
vperfetto_min_endTrackEvent_VMM(); vperfetto_min_endTrackEvent_VMM();
} }
#endif #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

@ -33,7 +33,7 @@
#endif #endif
#define TRACE_WITH_PERFETTO 1 #define TRACE_WITH_PERFETTO 1
#define TRACE_WITH_STDERR 2
#define BIT(n) (UINT32_C(1) << (n)) #define BIT(n) (UINT32_C(1) << (n))

Loading…
Cancel
Save