From e4858974ec36afd8a6b3a9e2b0ad8f357f28efc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:31:03 +0200 Subject: trace: avoid conditional code compilation during option parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A default implementation for backend-specific routines is provided in "trace/default.c", which backends can override by setting "trace_default=no" in "configure". Signed-off-by: Lluís Vilanova --- trace/control.h | 24 ++++++++++++++++++++++++ trace/default.c | 21 +++++++++++++++++++++ trace/simple.c | 10 ++++++---- trace/simple.h | 8 -------- 4 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 trace/control.h create mode 100644 trace/default.c (limited to 'trace') diff --git a/trace/control.h b/trace/control.h new file mode 100644 index 0000000000..bb54339258 --- /dev/null +++ b/trace/control.h @@ -0,0 +1,24 @@ +/* + * Interface for configuring and controlling the state of tracing events. + * + * Copyright (C) 2011 Lluís Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#ifndef TRACE_CONTROL_H +#define TRACE_CONTROL_H + +#include + + +/** Initialize the tracing backend. + * + * @file Name of trace output file; may be NULL. + * Corresponds to commandline option "-trace file=...". + * @return Whether the backend could be successfully initialized. + */ +bool trace_backend_init(const char *file); + +#endif /* TRACE_CONTROL_H */ diff --git a/trace/default.c b/trace/default.c new file mode 100644 index 0000000000..42fdb6b6a4 --- /dev/null +++ b/trace/default.c @@ -0,0 +1,21 @@ +/* + * Default implementation for backend initialization from commandline. + * + * Copyright (C) 2011 Lluís Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include "trace/control.h" + + +bool trace_backend_init(const char *file) +{ + if (file) { + fprintf(stderr, "error: -trace file=...: " + "option not supported by the selected tracing backend\n"); + return false; + } + return true; +} diff --git a/trace/simple.c b/trace/simple.c index de355e9675..369e860305 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -16,6 +16,7 @@ #include #include "qemu-timer.h" #include "trace.h" +#include "trace/control.h" /** Trace file header event ID */ #define HEADER_EVENT_ID (~(uint64_t)0) /* avoids conflicting with TraceEventIDs */ @@ -330,7 +331,7 @@ void st_flush_trace_buffer(void) flush_trace_file(true); } -bool st_init(const char *file) +bool trace_backend_init(const char *file) { pthread_t thread; pthread_attr_t attr; @@ -346,10 +347,11 @@ bool st_init(const char *file) pthread_sigmask(SIG_SETMASK, &oldset, NULL); if (ret != 0) { - return false; + fprintf(stderr, "warning: unable to initialize simple trace backend\n"); + } else { + atexit(st_flush_trace_buffer); + st_set_trace_file(file); } - atexit(st_flush_trace_buffer); - st_set_trace_file(file); return true; } diff --git a/trace/simple.h b/trace/simple.h index 77633ab68a..08b9a52146 100644 --- a/trace/simple.h +++ b/trace/simple.h @@ -15,7 +15,6 @@ #include #include -#ifdef CONFIG_TRACE_SIMPLE typedef uint64_t TraceEventID; typedef struct { @@ -37,12 +36,5 @@ void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf); void st_set_trace_file_enabled(bool enable); bool st_set_trace_file(const char *file); void st_flush_trace_buffer(void); -bool st_init(const char *file); -#else -static inline bool st_init(const char *file) -{ - return true; -} -#endif /* !CONFIG_TRACE_SIMPLE */ #endif /* TRACE_SIMPLE_H */ -- cgit v1.2.1