From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:34853) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qz2Ii-0003j8-Ac for qemu-devel@nongnu.org; Thu, 01 Sep 2011 04:07:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qz2IS-0007gD-Ug for qemu-devel@nongnu.org; Thu, 01 Sep 2011 04:06:55 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:59692) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qz2IS-0007Yv-HU for qemu-devel@nongnu.org; Thu, 01 Sep 2011 04:06:48 -0400 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p8186WRJ024860 for ; Thu, 1 Sep 2011 08:06:32 GMT Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p8186UsD2224198 for ; Thu, 1 Sep 2011 09:06:31 +0100 Received: from d06av09.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p8186Trg020091 for ; Thu, 1 Sep 2011 02:06:30 -0600 From: Stefan Hajnoczi Date: Thu, 1 Sep 2011 09:06:17 +0100 Message-Id: <1314864386-14202-7-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1314864386-14202-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1314864386-14202-1-git-send-email-stefanha@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 06/15] trace: avoid conditional code compilation during option parsing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , =?UTF-8?q?Llu=C3=ADs?= , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= From: Llu=C3=ADs A default implementation for backend-specific routines is provided in "trace/default.c", which backends can override by setting "trace_default=3D= no" in "configure". Signed-off-by: Llu=C3=ADs Vilanova --- Makefile.objs | 2 ++ configure | 6 ++++++ qemu-config.c | 4 ---- qemu-options.hx | 6 ++++-- trace/control.h | 24 ++++++++++++++++++++++++ trace/default.c | 21 +++++++++++++++++++++ trace/simple.c | 10 ++++++---- trace/simple.h | 8 -------- vl.c | 17 +++++++++-------- 9 files changed, 72 insertions(+), 26 deletions(-) create mode 100644 trace/control.h create mode 100644 trace/default.c diff --git a/Makefile.objs b/Makefile.objs index 4f8b0ed..57a80e6 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -379,6 +379,8 @@ ifneq ($(TRACE_BACKEND),dtrace) trace-obj-y =3D trace.o endif =20 +trace-nested-$(CONFIG_TRACE_DEFAULT) +=3D default.o + trace-nested-$(CONFIG_TRACE_SIMPLE) +=3D simple.o trace-obj-$(CONFIG_TRACE_SIMPLE) +=3D qemu-timer-common.o =20 diff --git a/configure b/configure index ebf14ee..4f9b27c 100755 --- a/configure +++ b/configure @@ -3064,12 +3064,15 @@ bsd) ;; esac =20 +# use default implementation for tracing backend-specific routines +trace_default=3Dyes echo "TRACE_BACKEND=3D$trace_backend" >> $config_host_mak if test "$trace_backend" =3D "nop"; then echo "CONFIG_TRACE_NOP=3Dy" >> $config_host_mak fi if test "$trace_backend" =3D "simple"; then echo "CONFIG_TRACE_SIMPLE=3Dy" >> $config_host_mak + trace_default=3Dno # Set the appropriate trace file. trace_file=3D"\"$trace_file-\" FMT_pid" fi @@ -3086,6 +3089,9 @@ if test "$trace_backend" =3D "dtrace"; then fi fi echo "CONFIG_TRACE_FILE=3D$trace_file" >> $config_host_mak +if test "$trace_default" =3D "yes"; then + echo "CONFIG_TRACE_DEFAULT=3Dy" >> $config_host_mak +fi =20 echo "TOOLS=3D$tools" >> $config_host_mak echo "ROMS=3D$roms" >> $config_host_mak diff --git a/qemu-config.c b/qemu-config.c index b64edc9..4f3465d 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -303,7 +303,6 @@ static QemuOptsList qemu_mon_opts =3D { }, }; =20 -#ifdef CONFIG_TRACE_SIMPLE static QemuOptsList qemu_trace_opts =3D { .name =3D "trace", .implied_opt_name =3D "trace", @@ -316,7 +315,6 @@ static QemuOptsList qemu_trace_opts =3D { { /* end of list */ } }, }; -#endif =20 static QemuOptsList qemu_cpudef_opts =3D { .name =3D "cpudef", @@ -517,9 +515,7 @@ static QemuOptsList *vm_config_groups[32] =3D { &qemu_global_opts, &qemu_mon_opts, &qemu_cpudef_opts, -#ifdef CONFIG_TRACE_SIMPLE &qemu_trace_opts, -#endif &qemu_option_rom_opts, &qemu_machine_opts, &qemu_boot_opts, diff --git a/qemu-options.hx b/qemu-options.hx index dcb00b7..2d29933 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2436,17 +2436,19 @@ Normally QEMU loads a configuration file from @va= r{sysconfdir}/qemu.conf and @var{sysconfdir}/target-@var{ARCH}.conf on startup. The @code{-nodefcon= fig} option will prevent QEMU from loading these configuration files at start= up. ETEXI -#ifdef CONFIG_TRACE_SIMPLE DEF("trace", HAS_ARG, QEMU_OPTION_trace, "-trace\n" " Specify a trace file to log traces to\n", QEMU_ARCH_ALL) STEXI +HXCOMM This line is not accurate, as the option is backend-specific but = HX does +HXCOMM not support conditional compilation of text. @item -trace @findex -trace Specify a trace file to log output traces to. + +This option is available only when using the @var{simple} tracing backen= d. ETEXI -#endif =20 HXCOMM This is the last statement. Insert new options before this line! STEXI diff --git a/trace/control.h b/trace/control.h new file mode 100644 index 0000000..bb54339 --- /dev/null +++ b/trace/control.h @@ -0,0 +1,24 @@ +/* + * Interface for configuring and controlling the state of tracing events. + * + * Copyright (C) 2011 Llu=C3=ADs 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=3D...". + * @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 0000000..42fdb6b --- /dev/null +++ b/trace/default.c @@ -0,0 +1,21 @@ +/* + * Default implementation for backend initialization from commandline. + * + * Copyright (C) 2011 Llu=C3=ADs 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=3D...: " + "option not supported by the selected tracing backend\n"= ); + return false; + } + return true; +} diff --git a/trace/simple.c b/trace/simple.c index de355e9..369e860 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" =20 /** Trace file header event ID */ #define HEADER_EVENT_ID (~(uint64_t)0) /* avoids conflicting with TraceE= ventIDs */ @@ -330,7 +331,7 @@ void st_flush_trace_buffer(void) flush_trace_file(true); } =20 -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); =20 if (ret !=3D 0) { - return false; + fprintf(stderr, "warning: unable to initialize simple trace back= end\n"); + } else { + atexit(st_flush_trace_buffer); + st_set_trace_file(file); } =20 - atexit(st_flush_trace_buffer); - st_set_trace_file(file); return true; } diff --git a/trace/simple.h b/trace/simple.h index 77633ab..08b9a52 100644 --- a/trace/simple.h +++ b/trace/simple.h @@ -15,7 +15,6 @@ #include #include =20 -#ifdef CONFIG_TRACE_SIMPLE typedef uint64_t TraceEventID; =20 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 */ =20 #endif /* TRACE_SIMPLE_H */ diff --git a/vl.c b/vl.c index 145d738..60322b6 100644 --- a/vl.c +++ b/vl.c @@ -156,7 +156,7 @@ int main(int argc, char **argv) #include "slirp/libslirp.h" =20 #include "trace.h" -#include "trace/simple.h" +#include "trace/control.h" #include "qemu-queue.h" #include "cpus.h" #include "arch_init.h" @@ -2130,7 +2130,6 @@ int main(int argc, char **argv, char **envp) int show_vnc_port =3D 0; #endif int defconfig =3D 1; - const char *trace_file =3D NULL; const char *log_mask =3D NULL; const char *log_file =3D NULL; GMemVTable mem_trace =3D { @@ -2138,6 +2137,7 @@ int main(int argc, char **argv, char **envp) .realloc =3D realloc_and_trace, .free =3D free_and_trace, }; + const char *trace_file =3D NULL; =20 atexit(qemu_run_exit_notifiers); error_set_progname(argv[0]); @@ -2928,14 +2928,15 @@ int main(int argc, char **argv, char **envp) } xen_mode =3D XEN_ATTACH; break; -#ifdef CONFIG_TRACE_SIMPLE case QEMU_OPTION_trace: + { opts =3D qemu_opts_parse(qemu_find_opts("trace"), optarg= , 0); - if (opts) { - trace_file =3D qemu_opt_get(opts, "file"); + if (!opts) { + exit(1); } + trace_file =3D qemu_opt_get(opts, "file"); break; -#endif + } case QEMU_OPTION_readconfig: { int ret =3D qemu_read_config_file(optarg); @@ -2993,8 +2994,8 @@ int main(int argc, char **argv, char **envp) set_cpu_log(log_mask); } =20 - if (!st_init(trace_file)) { - fprintf(stderr, "warning: unable to initialize simple trace back= end\n"); + if (!trace_backend_init(trace_file)) { + exit(1); } =20 /* If no data_dir is specified then try to find it relative to the --=20 1.7.5.4