From: Stefan Hajnoczi <stefanha@gmail.com>
To: Lluís <xscript@gmx.net>
Cc: qemu-devel@nongnu.org, chouteau@adacore.com
Subject: Re: [Qemu-devel] [PATCH v7 05/13] trace: avoid conditional code compilation during option parsing
Date: Wed, 31 Aug 2011 12:43:31 +0100 [thread overview]
Message-ID: <CAJSP0QXWdwsa42TeoKghrvsKrcw-spv7yA9usA8d4=5vARYoLQ@mail.gmail.com> (raw)
In-Reply-To: <20110825191804.1413.26801.stgit@ginnungagap.bsc.es>
On Thu, Aug 25, 2011 at 8:18 PM, Lluís <xscript@gmx.net> wrote:
> diff --git a/vl.c b/vl.c
> index 145d738..ed2db9a 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -156,7 +156,7 @@ int main(int argc, char **argv)
> #include "slirp/libslirp.h"
>
> #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 = 0;
> #endif
> int defconfig = 1;
> - const char *trace_file = NULL;
> const char *log_mask = NULL;
> const char *log_file = NULL;
> GMemVTable mem_trace = {
> @@ -2928,14 +2927,27 @@ int main(int argc, char **argv, char **envp)
> }
> xen_mode = XEN_ATTACH;
> break;
> -#ifdef CONFIG_TRACE_SIMPLE
> case QEMU_OPTION_trace:
> + {
> opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
> - if (opts) {
> - trace_file = qemu_opt_get(opts, "file");
> + if (!opts) {
> + exit(1);
> + }
> + if (!trace_config_init()) {
> + fprintf(stderr, "qemu: error: option \"-%s\" is not "
> + "supported by the selected tracing backend\n",
> + popt->name);
> + exit(1);
> + }
> + const char *trace_file = qemu_opt_get(opts, "file");
> + if (trace_file && !trace_config_init_file(trace_file)) {
> + fprintf(stderr, "error: suboption \"-%s file\" is not "
> + "supported by the selected tracing backend\n",
> + popt->name);
> + exit(1);
> }
> break;
> -#endif
> + }
> case QEMU_OPTION_readconfig:
> {
> int ret = qemu_read_config_file(optarg);
> @@ -2993,10 +3005,6 @@ int main(int argc, char **argv, char **envp)
> set_cpu_log(log_mask);
> }
>
> - if (!st_init(trace_file)) {
> - fprintf(stderr, "warning: unable to initialize simple trace backend\n");
> - }
> -
This changes the semantics of simpletrace. If you start without
-trace ... then simpletrace will not be initialized and will not be
functional (no write-out thread). That means you cannot start without
an events file and interactively enable the events that you want. The
stderr backend handles this case fine because it has no initialization
code which this hunk replaces with trace_config_init() (only called
when -trace ... is given).
I suggest changing the trace backend interface to a single function:
/**
* Set up the trace backend with the -trace events=...,file=... arguments
*
* @events file with events to be enabled on startup, may be NULL
* @file name of trace output file, may be NULL
* @return true on success, false on error
*/
bool trace_backend_init(const char *events, const char *file);
In the vl.c:main() args parsing switch statement, just collect const
char *events and *file. Then after the switch statement
unconditionally call trace_backend_init(events, file) (even if -trace
was not given). Default behavior for backends that do not support
-trace becomes:
bool trace_backend_init(const char *events, const char *file)
{
if (events || file) {
fprintf(stderr, "The -trace option is not supported by this
trace backend\n");
return false;
}
return true;
}
This guarantees that trace backends will receive the
trace_backend_init() call even when -trace is not used. This is where
they can create threads or do any other setup.
Stefan
next prev parent reply other threads:[~2011-08-31 11:43 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-25 19:17 [Qemu-devel] [PATCH v7 00/13] trace-state: make the behaviour of "disable" consistent across all backends Lluís
2011-08-25 19:17 ` [Qemu-devel] [PATCH v7 01/13] [simple] Include qemu-timer-common.o in trace-obj-y Lluís
2011-08-25 19:17 ` [Qemu-devel] [PATCH v7 02/13] trace: [configure] rename CONFIG_*_TRACE into CONFIG_TRACE_* Lluís
2011-08-25 19:17 ` [Qemu-devel] [PATCH v7 03/13] trace: [make] replace 'ifeq' with values in CONFIG_TRACE_* Lluís
2011-08-31 12:15 ` Stefan Hajnoczi
2011-08-25 19:17 ` [Qemu-devel] [PATCH v7 04/13] trace: move backend-specific code into the trace/ directory Lluís
2011-08-25 19:18 ` [Qemu-devel] [PATCH v7 05/13] trace: avoid conditional code compilation during option parsing Lluís
2011-08-31 9:53 ` Stefan Hajnoczi
2011-08-31 11:43 ` Stefan Hajnoczi [this message]
2011-08-25 19:18 ` [Qemu-devel] [PATCH v7 06/13] trace: generalize the "property" concept in the trace-events file Lluís
2011-08-25 19:18 ` [Qemu-devel] [PATCH v7 07/13] trace-state: separate trace event control and query routines from the simple backend Lluís
2011-08-25 19:18 ` [Qemu-devel] [PATCH v7 08/13] trace-state: always compile support for controlling and querying trace event states Lluís
2011-08-31 10:10 ` Stefan Hajnoczi
2011-08-25 19:18 ` [Qemu-devel] [PATCH v7 09/13] trace-state: add "-trace events" argument to control initial state Lluís
2011-08-25 19:18 ` [Qemu-devel] [PATCH v7 10/13] trace-state: always use the "nop" backend on events with the "disable" keyword Lluís
2011-08-25 19:18 ` [Qemu-devel] [PATCH v7 11/13] trace-state: [simple] disable all trace points by default Lluís
2011-08-31 10:21 ` Stefan Hajnoczi
2011-08-25 19:18 ` [Qemu-devel] [PATCH v7 12/13] trace-state: [stderr] add support for dynamically enabling/disabling events Lluís
2011-08-25 19:18 ` [Qemu-devel] [PATCH v7 13/13] trace: enable all events Lluís
2011-08-31 9:54 ` [Qemu-devel] [PATCH v7 00/13] trace-state: make the behaviour of "disable" consistent across all backends Stefan Hajnoczi
2011-08-31 12:17 ` Stefan Hajnoczi
2011-08-31 16:52 ` Lluís
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJSP0QXWdwsa42TeoKghrvsKrcw-spv7yA9usA8d4=5vARYoLQ@mail.gmail.com' \
--to=stefanha@gmail.com \
--cc=chouteau@adacore.com \
--cc=qemu-devel@nongnu.org \
--cc=xscript@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).