All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: BALATON Zoltan <balaton@eik.bme.hu>
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Cleber Rosa" <crosa@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: Re: [PULL 10/11] trace: document how to specify multiple --trace patterns
Date: Tue, 02 Feb 2021 13:41:28 +0100	[thread overview]
Message-ID: <87v9babq13.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <81fbad73-b911-cfb6-dc9f-142ccaee678f@eik.bme.hu> (BALATON Zoltan's message of "Mon, 1 Feb 2021 18:39:49 +0100 (CET)")

BALATON Zoltan <balaton@eik.bme.hu> writes:

> On Mon, 1 Feb 2021, Paolo Bonzini wrote:
>> On 01/02/21 17:54, Kevin Wolf wrote:
>>>> How does this option parsing work? Would then multiple patterns
>>>> separated by
>>>> comma as in -trace pattern1,pattern2 also work?
>>> This would be interpreted as an implied "enable" option with a value of
>>> "pattern1,pattern2". I don't think anything splits that string at the
>>> comma, so it would look for a trace event matching that string.
>>
>> Even worse, it would be interpreted as "-trace
>> enable=pattern1,pattern2=on" (and raise a warning since recently).
>
> Not very intuitive... What would -trace
> enable=pattern1,enable=pattern2 do then?

Welcome to the QemuOpts swamp.  Bring your own mosquito net.

The argument of -trace is parsed with QemuOpts.

The option argument is specified in trace/control.c:

    QemuOptsList qemu_trace_opts = {
        .name = "trace",
        .implied_opt_name = "enable",
        .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
        .desc = {
            {
                .name = "enable",
                .type = QEMU_OPT_STRING,
            },
            {
                .name = "events",
                .type = QEMU_OPT_STRING,
            },{
                .name = "file",
                .type = QEMU_OPT_STRING,
            },
            { /* end of list */ }
        },
    };

We generally refer to QemuOptsList by name.  This one's name is "trace".

The non-empty .desc[] enumerates the recognized parameters.
Additionally, special parameter "id" is recognized.

.implied_opt_name enables "omitted first key defaults to implied key"
sugar.  This is what makes "-trace PATTERN" shorthand for -trace
enable=PATTERN", where PATTERN contains neither '=' nor unescaped ','.

The QemuOpts parser parses an option argument string into a QemuOpts,
stores it for later use, and also returns it for immediate use.

Code can do whatever it wants with the stored parameters.  This is a
wellspring of inconsistency and confusion.

Let's look at the code for -trace.  In qemu_init(), we have:

                case QEMU_OPTION_trace:
                    trace_opt_parse(optarg);
                    break;

This calls trace_opt_parse() for every -trace, in order.  @optarg is the
argument string.

    void trace_opt_parse(const char *optarg)
    {
        QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("trace"),
                                                 optarg, true);

qemu_opts_parse_noisily() parses @optarg into a QemuOpts, stores it for
later use, and also returns it for immediate use.

        if (!opts) {
            exit(1);
        }

        if (qemu_opt_get(opts, "enable")) {
            trace_enable_events(qemu_opt_get(opts, "enable"));
        }

Pass the last enable=PATTERN in @optarg to trace_enable_events().

        trace_init_events(qemu_opt_get(opts, "events"));

Pass the the last events=FILENAME to trace_init_events(), which parses
patterns from file FILENAME and passes them to trace_enable_events().

Non-last enable=... ane events=... are silently ignored.

        init_trace_on_startup = true;

Set a flag for trace_init_file().

        qemu_opts_del(opts);

Delete the stored QemuOpts.  We'll get back to this in jiffie.

    }

Later in qemu_init(), we call trace_init_file().  Here it is:

    void trace_init_file(void)
    {
        QemuOpts *opts = qemu_find_opts_singleton("trace");

This gets the first QemuOpts stored in the QemuOptsList named "trace"
without "id".  If there is none, it creates an empty one for us.

Since trace_opt_parse() deletes, this always creates an empty one.

        const char *file = qemu_opt_get(opts, "file");

This is always null.

    #ifdef CONFIG_TRACE_SIMPLE
        st_set_trace_file(file);
        if (init_trace_on_startup) {
            st_set_trace_file_enabled(true);
        }
    #elif defined CONFIG_TRACE_LOG
        /*
         * If both the simple and the log backends are enabled, "--trace file"
         * only applies to the simple backend; use "-D" for the log
         * backend. However we should only override -D if we actually have
         * something to override it with.
         */
        if (file) {
            qemu_set_log_filename(file, &error_fatal);
        }
    #else
        if (file) {
            fprintf(stderr, "error: --trace file=...: "
                    "option not supported by the selected tracing backends\n");
            exit(1);
        }
    #endif
    }

Bug: option parameter "file" has no effect.  I suspect this was broken
in commit 92eecfff32 "trace: remove argument from trace_init_file",
2020-11-11.

And now I'm ready to answer your question:

    -trace enable=pattern1,enable=pattern2

is a confusing way to say

    -trace enable=pattern2

To specify both patterns, use

    -trace enable=pattern1 -trace enable=pattern2

Lovely, isn't it?



  reply	other threads:[~2021-02-02 12:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-01 15:46 [PULL 00/11] Tracing patches Stefan Hajnoczi
2021-02-01 15:46 ` [PULL 01/11] trace: fix simpletrace doc mismerge Stefan Hajnoczi
2021-02-01 15:46 ` [PULL 02/11] tracing: convert documentation to rST Stefan Hajnoczi
2021-02-01 15:46 ` [PULL 03/11] trace: recommend "log" backend for getting started with tracing Stefan Hajnoczi
2021-02-01 15:46 ` [PULL 04/11] tracetool: fix "PRI" macro decoding Stefan Hajnoczi
2021-02-01 15:46 ` [PULL 05/11] tracetool: also strip %l and %ll from systemtap format strings Stefan Hajnoczi
2021-02-01 15:46 ` [PULL 06/11] trace: add meson custom_target() depend_files for tracetool Stefan Hajnoczi
2021-02-01 15:46 ` [PULL 07/11] error: rename error_with_timestamp to message_with_timestamp Stefan Hajnoczi
2021-02-01 15:47 ` [PULL 08/11] trace: make the 'log' backend timestamp configurable Stefan Hajnoczi
2021-02-01 15:47 ` [PULL 09/11] simpletrace: build() missing 2 required positional arguments Stefan Hajnoczi
2021-02-01 15:47 ` [PULL 10/11] trace: document how to specify multiple --trace patterns Stefan Hajnoczi
2021-02-01 16:05   ` BALATON Zoltan
2021-02-01 16:13     ` Kevin Wolf
2021-02-01 16:27       ` Philippe Mathieu-Daudé
2021-02-01 16:29       ` BALATON Zoltan
2021-02-01 16:54         ` Kevin Wolf
2021-02-01 17:25           ` Paolo Bonzini
2021-02-01 17:39             ` BALATON Zoltan
2021-02-02 12:41               ` Markus Armbruster [this message]
2021-02-02 13:03                 ` BALATON Zoltan
2021-02-02 13:12                 ` Paolo Bonzini
2021-02-01 17:46             ` Daniel P. Berrangé
2021-02-01 18:13               ` BALATON Zoltan
2021-02-02 16:47                 ` Stefan Hajnoczi
2021-02-01 15:47 ` [PULL 11/11] trace: update docs with meson build information Stefan Hajnoczi
2021-02-02 11:24 ` [PULL 00/11] Tracing patches Peter Maydell

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=87v9babq13.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=balaton@eik.bme.hu \
    --cc=crosa@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.