Re: [PATCH 0/5] trace: inroduce qmp: trace namespace

2021-10-26 Thread Markus Armbruster
Stefan Hajnoczi  writes:

> On Thu, Oct 14, 2021 at 06:22:32PM +0300, Vladimir Sementsov-Ogievskiy wrote:
>> 12.10.2021 14:49, Markus Armbruster wrote:
>> > Vladimir Sementsov-Ogievskiy  writes:

[...]

>> Another possible way is to update QAPI code generator to insert a personal
>> trace point for each qmp command.. That seems more complicated to implement,
>> but I can try.
>
> That's what came to mind when I saw this series too. The QAPI generator
> can create a trace event for each QMP command. That way each command has
> a dedicated trace event that can be enabled/disabled in the usual way
> (e.g. built-in "trace" monitor command, SystemTap scripts, etc) without
> introducing special syntax.

I like how this way stays entirely within the existing interface.  I
couldn't tell you how to implement it, though :)




Re: [PATCH 0/5] trace: inroduce qmp: trace namespace

2021-10-25 Thread Stefan Hajnoczi
On Thu, Oct 14, 2021 at 06:22:32PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> 12.10.2021 14:49, Markus Armbruster wrote:
> > Vladimir Sementsov-Ogievskiy  writes:
> > 
> > > Hi all!
> > > 
> > > We have handle_qmp_command and qmp_command_repond trace points to trace
> > > qmp commands. They are very useful to debug problems involving
> > > management tools like libvirt.
> > > 
> > > But tracing all qmp commands is too much.
> > > 
> > > Here I suggest a kind of tracing namespace. Formally this series adds a
> > > trace points called qmp: for every command, which may be
> > > enabled in separate like
> > > 
> > >--trace qmp:drive-backup
> > > 
> > > or by pattern like
> > > 
> > >--trace qmp:block-job-*
> > > 
> > > or similarly with help of qmp command trace-event-set-state.
> > > 
> > > This also allows to enable tracing of some qmp commands permanently
> > >   (by downstream patch or in libvirt xml). For example, I'm going to
> > > enable tracing of block job comamnds and blockdev-* commands in
> > > Virtuozzo. Qemu logs are often too empty (for example, in comparison
> > > with Libvirt), logging block jobs is not too much but will be very
> > > helpful.
> > 
> > What exactly is traced?  Peeking at PATCH 5... looks like it's input
> > that makes it to qmp_dispatch() and command responses, but not events.
> > 
> > Fine print on "input that makes it to qmp_dispatch()":
> > 
> > * You trace right before we execute the command, not when we receive,
> >parse and enqueue input.
> > 
> > * Corollary: input with certain errors is not traced.
> > 
> > * You don't trace the input text, you trace the unparsed parse tree.
> > 
> > All fine, I presume.
> > 
> > Existing tracepoints in monitor/qmp.c, and what information they send
> > (inessential bits omitted for clarity):
> > 
> > * handle_qmp_command
> > 
> >Handling a QMP command: unparsed parse tree
> > 
> >Fine print, safe to ignore:
> > 
> >- Out-of-band commands will be executed right away, in-band commands
> >  will be queued.  Tracepoints monitor_qmp_in_band_enqueue and
> >  monitor_qmp_in_band_dequeue provide insight into that.
> > 
> >- This also receives and queues parse errors, without tracing them.
> >  Tracepoint monitor_qmp_err_in_band traces them as they are dequeued.
> > 
> > * monitor_qmp_cmd_in_band
> > 
> >About to execute in-band command: command ID, if any
> > 
> > * monitor_qmp_cmd_out_of_band
> > 
> >About to execute out-of-band command: command ID, if any
> > 
> > * monitor_qmp_respond
> > 
> >About to send command response or event: QObject
> > 
> > For input, --trace qmp:* is like --trace handle_qmp_command, except it
> > traces late rather than early.
> > 
> > For output, --trace qmp:* is like --trace monitor_qmp_respond less
> > events.
> > 
> > The main improvement over existing tracepoints seems to be the ability
> > to filter on command names.
> > 
> > To get that, you overload the @name argument of QMP command
> > trace-event-set-state.  In addition to the documented meaning "Event
> > name pattern", it also has an alternate, undocumented meaning "QMP
> > command name pattern".  The "undocumented" part is easy enough to fix.
> > However, QMP heavily frowns on argument values that need to be parsed.
> 
> Still, pattern is parsed anyway, as pattern. But yes, this patch adds
> rather specific and tricky logic, which a lot more than just a pattern
> to search through the list.
> 
> Another possible way is to update QAPI code generator to insert a personal
> trace point for each qmp command.. That seems more complicated to implement,
> but I can try.

That's what came to mind when I saw this series too. The QAPI generator
can create a trace event for each QMP command. That way each command has
a dedicated trace event that can be enabled/disabled in the usual way
(e.g. built-in "trace" monitor command, SystemTap scripts, etc) without
introducing special syntax.

Stefan


signature.asc
Description: PGP signature


Re: [PATCH 0/5] trace: inroduce qmp: trace namespace

2021-10-14 Thread Vladimir Sementsov-Ogievskiy

12.10.2021 14:49, Markus Armbruster wrote:

Vladimir Sementsov-Ogievskiy  writes:


Hi all!

We have handle_qmp_command and qmp_command_repond trace points to trace
qmp commands. They are very useful to debug problems involving
management tools like libvirt.

But tracing all qmp commands is too much.

Here I suggest a kind of tracing namespace. Formally this series adds a
trace points called qmp: for every command, which may be
enabled in separate like

   --trace qmp:drive-backup

or by pattern like

   --trace qmp:block-job-*

or similarly with help of qmp command trace-event-set-state.

This also allows to enable tracing of some qmp commands permanently
  (by downstream patch or in libvirt xml). For example, I'm going to
enable tracing of block job comamnds and blockdev-* commands in
Virtuozzo. Qemu logs are often too empty (for example, in comparison
with Libvirt), logging block jobs is not too much but will be very
helpful.


What exactly is traced?  Peeking at PATCH 5... looks like it's input
that makes it to qmp_dispatch() and command responses, but not events.

Fine print on "input that makes it to qmp_dispatch()":

* You trace right before we execute the command, not when we receive,
   parse and enqueue input.

* Corollary: input with certain errors is not traced.

* You don't trace the input text, you trace the unparsed parse tree.

All fine, I presume.

Existing tracepoints in monitor/qmp.c, and what information they send
(inessential bits omitted for clarity):

* handle_qmp_command

   Handling a QMP command: unparsed parse tree

   Fine print, safe to ignore:

   - Out-of-band commands will be executed right away, in-band commands
 will be queued.  Tracepoints monitor_qmp_in_band_enqueue and
 monitor_qmp_in_band_dequeue provide insight into that.

   - This also receives and queues parse errors, without tracing them.
 Tracepoint monitor_qmp_err_in_band traces them as they are dequeued.

* monitor_qmp_cmd_in_band

   About to execute in-band command: command ID, if any

* monitor_qmp_cmd_out_of_band

   About to execute out-of-band command: command ID, if any

* monitor_qmp_respond

   About to send command response or event: QObject

For input, --trace qmp:* is like --trace handle_qmp_command, except it
traces late rather than early.

For output, --trace qmp:* is like --trace monitor_qmp_respond less
events.

The main improvement over existing tracepoints seems to be the ability
to filter on command names.

To get that, you overload the @name argument of QMP command
trace-event-set-state.  In addition to the documented meaning "Event
name pattern", it also has an alternate, undocumented meaning "QMP
command name pattern".  The "undocumented" part is easy enough to fix.
However, QMP heavily frowns on argument values that need to be parsed.


Still, pattern is parsed anyway, as pattern. But yes, this patch adds
rather specific and tricky logic, which a lot more than just a pattern
to search through the list.

Another possible way is to update QAPI code generator to insert a personal
trace point for each qmp command.. That seems more complicated to implement,
but I can try.


But before we discuss this in depth, we should decide whether we want
the filtering feature.

Management applications can enable and disable tracing as needed, but
doing it all in QEMU might be more convenient or robust.

Libvirt logs all QMP traffic.


I am not sure.. At lest in Vz7 (based on RH7) it doesn't.. Is something changed 
in new versions?

For example, I run a migration by virsh. In libvirtd.log I see migration events, but 
don't see the "migrate" command itself, neither migrate-set-parameters / 
migrate-set-capabilities..

So, I never could rely on libvirt logs in this area, and we usually use Qemu 
tracing to debug QMP traffic.

Also, Libvirt is not the only source of QMP traffic.. In Vz7 backup is done separately. I do 
backup of VM. In vm log I see drive-backup trace point. In Libvirt I see only "new 
connection, client: /usr/libexec/vz_backup_client "..


 I doubt it'll make use of your filtering
feature.  Cc'ing libvir-list just in case.

Another way to log all traffic is to route it through socat -x or
similar.

Opinions?



The benefit of Qemu tracepoints, is that you can enable them independently of 
any environment/management tool.

--
Best regards,
Vladimir



Re: [PATCH 0/5] trace: inroduce qmp: trace namespace

2021-10-12 Thread Markus Armbruster
Vladimir Sementsov-Ogievskiy  writes:

> Hi all!
>
> We have handle_qmp_command and qmp_command_repond trace points to trace
> qmp commands. They are very useful to debug problems involving
> management tools like libvirt.
>
> But tracing all qmp commands is too much.
>
> Here I suggest a kind of tracing namespace. Formally this series adds a
> trace points called qmp: for every command, which may be
> enabled in separate like
>
>   --trace qmp:drive-backup
>
> or by pattern like
>
>   --trace qmp:block-job-*
>
> or similarly with help of qmp command trace-event-set-state.
>
> This also allows to enable tracing of some qmp commands permanently
>  (by downstream patch or in libvirt xml). For example, I'm going to
> enable tracing of block job comamnds and blockdev-* commands in
> Virtuozzo. Qemu logs are often too empty (for example, in comparison
> with Libvirt), logging block jobs is not too much but will be very
> helpful.

What exactly is traced?  Peeking at PATCH 5... looks like it's input
that makes it to qmp_dispatch() and command responses, but not events.

Fine print on "input that makes it to qmp_dispatch()":

* You trace right before we execute the command, not when we receive,
  parse and enqueue input.

* Corollary: input with certain errors is not traced.

* You don't trace the input text, you trace the unparsed parse tree.

All fine, I presume.

Existing tracepoints in monitor/qmp.c, and what information they send
(inessential bits omitted for clarity):

* handle_qmp_command

  Handling a QMP command: unparsed parse tree

  Fine print, safe to ignore:

  - Out-of-band commands will be executed right away, in-band commands
will be queued.  Tracepoints monitor_qmp_in_band_enqueue and
monitor_qmp_in_band_dequeue provide insight into that.

  - This also receives and queues parse errors, without tracing them.
Tracepoint monitor_qmp_err_in_band traces them as they are dequeued.

* monitor_qmp_cmd_in_band

  About to execute in-band command: command ID, if any

* monitor_qmp_cmd_out_of_band

  About to execute out-of-band command: command ID, if any

* monitor_qmp_respond

  About to send command response or event: QObject

For input, --trace qmp:* is like --trace handle_qmp_command, except it
traces late rather than early.

For output, --trace qmp:* is like --trace monitor_qmp_respond less
events.

The main improvement over existing tracepoints seems to be the ability
to filter on command names.

To get that, you overload the @name argument of QMP command
trace-event-set-state.  In addition to the documented meaning "Event
name pattern", it also has an alternate, undocumented meaning "QMP
command name pattern".  The "undocumented" part is easy enough to fix.
However, QMP heavily frowns on argument values that need to be parsed.
But before we discuss this in depth, we should decide whether we want
the filtering feature.

Management applications can enable and disable tracing as needed, but
doing it all in QEMU might be more convenient or robust.

Libvirt logs all QMP traffic.  I doubt it'll make use of your filtering
feature.  Cc'ing libvir-list just in case.

Another way to log all traffic is to route it through socat -x or
similar.

Opinions?




[PATCH 0/5] trace: inroduce qmp: trace namespace

2021-09-23 Thread Vladimir Sementsov-Ogievskiy
Hi all!

We have handle_qmp_command and qmp_command_repond trace points to trace
qmp commands. They are very useful to debug problems involving
management tools like libvirt.

But tracing all qmp commands is too much.

Here I suggest a kind of tracing namespace. Formally this series adds a
trace points called qmp: for every command, which may be
enabled in separate like

  --trace qmp:drive-backup

or by pattern like

  --trace qmp:block-job-*

or similarly with help of qmp command trace-event-set-state.

This also allows to enable tracing of some qmp commands permanently
 (by downstream patch or in libvirt xml). For example, I'm going to
enable tracing of block job comamnds and blockdev-* commands in
Virtuozzo. Qemu logs are often too empty (for example, in comparison
with Libvirt), logging block jobs is not too much but will be very
helpful.

Vladimir Sementsov-Ogievskiy (5):
  trace/control: introduce trace_opt_parse_opts()
  qapi/qmp: QmpCommand: add .tracing field and API
  monitor: add qmp tracing API for qmp_commands
  util/qemu-option: make qemu_opt_del_all() function public
  trace: add qmp trace event namespace

 include/monitor/monitor.h   |  3 +++
 include/qapi/qmp/dispatch.h | 14 ++
 include/qemu/option.h   |  1 +
 trace/control.h |  7 +++
 monitor/qmp.c   | 10 ++
 qapi/qmp-dispatch.c | 20 
 qapi/qmp-registry.c | 27 +++
 softmmu/vl.c| 21 -
 trace/control.c | 18 --
 trace/qmp.c | 20 
 util/qemu-option.c  |  2 +-
 qapi/trace-events   |  2 ++
 12 files changed, 137 insertions(+), 8 deletions(-)

-- 
2.29.2