trace: make systemtap easier to use for simple logging
v3 cover trace: make systemtap easier to use for simple logging
This is a followup to
v1: https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg04173.html
v2: https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg04759.html
Changed in v3:
- g_strndup the QXL log_buf before printing to avoid a race with guest removing the nul terminator (Stefan)
- Add filtering of PIDs with "-p PID" arg to qemu-trace-stap
- Add a man page for qemu-trace-stap (Eric)
- Remove examples in docs/devel/tracing.txt and just refer people to the above man page.
- Use strerror(errno) instead of raw errno in vfio traces (Eric/Alex)
- Quote probe wildcards to be shell glob safe (Eric)
- Mention explicitly that it is launched separately from QEMU (Eric)
Changed in v2:
- Fix safety of QXL logging
- Handle format specifier macros is a more reliable manner
- Fix trace-events files missing newline
- Remove use of %m formats
Daniel P. Berrangé (4):
display: ensure qxl log_buf is a nul terminated string
trace: enforce that every trace-events file has a final newline
trace: forbid use of %m in trace event format strings
trace: add ability to do simple printf logging via systemtap
MAINTAINERS | 1 + Makefile | 10 ++ Makefile.target | 11 +- docs/devel/tracing.txt | 4 + hw/display/qxl.c | 14 ++- hw/display/trace-events | 2 +- hw/gpio/trace-events | 2 +- hw/vfio/pci.c | 2 +- hw/vfio/trace-events | 2 +- scripts/qemu-trace-stap | 174 +++++++++++++++++++++++++++ scripts/qemu-trace-stap.texi | 139 +++++++++++++++++++++ scripts/tracetool/__init__.py | 6 + scripts/tracetool/format/log_stap.py | 127 +++++++++++++++++++ 13 files changed, 485 insertions(+), 9 deletions(-) create mode 100755 scripts/qemu-trace-stap create mode 100644 scripts/qemu-trace-stap.texi create mode 100644 scripts/tracetool/format/log_stap.py
Signature · 1 line
2.20.1
PATCH v3 1/4 display: ensure qxl log_buf is a nul terminated string
The QXL_IO_LOG command allows the guest to send log messages to the host via a buffer in the QXLRam struct. QEMU prints these to the console if the qxl 'guestdebug' option is set to non-zero. It will also feed them to the trace subsystem if any backends are built-in.
In both cases the log_buf data will get treated as being as a nul terminated string, by the printf '%s' format specifier and / or other code reading the buffer.
QEMU does nothing to guarantee that the log_buf really is nul terminated, so there is potential for out of bounds array access.
This would affect any QEMU which has the log, syslog or ftrace trace backends built into QEMU. It can only be triggered if the 'qxl_io_log' trace event is enabled, however, so they are not vulnerable without specific administrative action to enable this.
It would also affect QEMU if the 'guestdebug' parameter is set to a non-zero value, which again is not the default and requires explicit admin opt-in.
--- hw/display/qxl.c | 14 ++++++++++---- hw/display/trace-events | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-)
hw/display/qxl.c +10 -4
@@ -1763,10 +1763,16 @@ async_common:qxl_set_mode (d, val,0 );break ;case QXL_IO_LOG : -trace_qxl_io_log (d->id, d->ram->log_buf); -if (d->guestdebug) { -fprintf (stderr,"qxl/guest-%d: %" PRId64": %s" , d->id, -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), d->ram->log_buf); +if (TRACE_QXL_IO_LOG_ENABLED || d->guestdebug) { +/* We cannot trust the guest to NUL terminate d->ram->log_buf */ +char *log_buf =g_strndup ((const char *)d->ram->log_buf, +sizeof (d->ram->log_buf)); +trace_qxl_io_log (d->id, log_buf); +if (d->guestdebug) { +fprintf (stderr,"qxl/guest-%d: %" PRId64": %s" , d->id, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), log_buf); + } +g_free (log_buf); }break ;case QXL_IO_RESET :
hw/display/trace-events +1 -1
@@ -72,7 +72,7 @@ qxl_interface_update_area_complete_rest(int qid, uint32_t num_updated_rects) "%d qxl_interface_update_area_complete_overflow(int qid, int max) "%d max=%d" qxl_interface_update_area_complete_schedule_bh(int qid, uint32_t num_dirty) "%d #dirty=%d" qxl_io_destroy_primary_ignored(int qid, const char *mode) "%d %s" -qxl_io_log(int qid, const uint8_t *log_buf) "%d %s" +qxl_io_log(int qid, const char *log_buf) "%d %s" qxl_io_read_unexpected(int qid) "%d" qxl_io_unexpected_vga_mode(int qid, uint64_t addr, uint64_t val, const char *desc) "%d 0x%"PRIx64"=%"PRIu64" (%s)" qxl_io_write(int qid, const char *mode, uint64_t addr, const char *aname, uint64_t val, unsigned size, int async) "%d %s addr=%"PRIu64 " (%s) val=%"PRIu64" size=%u async=%d"
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v3 1/4] display: ensure qxl log_buf is a nul terminated string
Quoted 21 lines · Daniel P. Berrangé
The
QXL_IO_LOGcommand allows the guest to send log messages to the host via a buffer in the QXLRam struct. QEMU prints these to the console if the qxl 'guestdebug' option is set to non-zero. It will also feed them to the trace subsystem if any backends are built-in.In both cases the
log_bufdata will get treated as being as a nul terminated string, by the printf '%s' format specifier and / or other code reading the buffer.QEMU does nothing to guarantee that the
log_bufreally is nul terminated, so there is potential for out of bounds array access.This would affect any QEMU which has the log, syslog or ftrace trace backends built into QEMU. It can only be triggered if the '
qxl_io_log' trace event is enabled, however, so they are not vulnerable without specific administrative action to enable this.It would also affect QEMU if the 'guestdebug' parameter is set to a non-zero value, which again is not the default and requires explicit admin opt-in.
Quoted 5 lines
Signed-off-by Daniel P. Berrangé <[email protected]>--- hw/display/qxl.c | 14 ++++++++++---- hw/display/trace-events | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v3 2/4 trace: enforce that every trace-events file has a final newline
In reply to Daniel P. BerrangéWhen generating the trace-events-all file, the build system simply concatenates all the individual trace-events files. If any one of those files does not have a final newline, the printf format string will have the contents of the first line of the next file appended to it, which is usually a '#' comment.
--- hw/gpio/trace-events | 2 +- scripts/tracetool/__init__.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
hw/gpio/trace-events +1 -1
@@ -4,4 +4,4 @@ nrf51_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" PRIx64 nrf51_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64 nrf51_gpio_set(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 -nrf51_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 +nrf51_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64
scripts/tracetool/__init__.py +2 -0
@@ -350,6 +350,8 @@ def read_events(fobj, fname): events = [] for lineno, line in enumerate(fobj, 1): + if line[-1] != '\n': + raise ValueError("%s does not end with a new line" % fname) if not line.strip(): continue if line.lstrip().startswith('#'):
Signature · 1 line
2.20.1
PATCH v3 3/4 trace: forbid use of %m in trace event format strings
In reply to Daniel P. BerrangéThe '%m' format specifier instructs glibc's printf() implementation to insert the contents of strerror(errno). Since this is a glibc extension it should generally be avoided in QEMU due to need for portability to a variety of platforms.
Even though vfio is Linux-only code that could otherwise use "%m", it must still be avoided in trace-events files because several of the backends do not use the format string and so this error information is invisible to them.
The errno string value should be given as an explicit trace argument instead, making it accessible to all backends. This also allows it to work correctly with future patches that use the format string with systemtap's simple printf code.
--- hw/vfio/pci.c | 2 +- hw/vfio/trace-events | 2 +- scripts/tracetool/__init__.py | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-)
hw/vfio/pci.c +1 -1
@@ -2581,7 +2581,7 @@ static void vfio_populate_device(VFIOPCIDevice *vdev, Error **errp) ret =ioctl (vdev->vbasedev.fd,VFIO_DEVICE_GET_IRQ_INFO , &irq_info);if (ret) {/* This can fail for an old kernel or legacy PCI dev */ -trace_vfio_populate_device_get_irq_info_failure (); +trace_vfio_populate_device_get_irq_info_failure (strerror (errno)); }else if (irq_info.count ==1 ) { vdev->pci_aer = true; }else {
hw/vfio/trace-events +1 -1
@@ -37,7 +37,7 @@ vfio_pci_hot_reset_has_dep_devices(const char *name) "%s: hot reset dependent de vfio_pci_hot_reset_dep_devices(int domain, int bus, int slot, int function, int group_id) "\t%04x:%02x:%02x.%x group %d" vfio_pci_hot_reset_result(const char *name, const char *result) "%s hot reset: %s" vfio_populate_device_config(const char *name, unsigned long size, unsigned long offset, unsigned long flags) "Device %s config:\n size: 0x%lx, offset: 0x%lx, flags: 0x%lx" -vfio_populate_device_get_irq_info_failure(void) "VFIO_DEVICE_GET_IRQ_INFO failure: %m" +vfio_populate_device_get_irq_info_failure(const char *errstr) "VFIO_DEVICE_GET_IRQ_INFO failure: %s" vfio_realize(const char *name, int group_id) " (%s) group %d" vfio_mdev(const char *name, bool is_mdev) " (%s) is_mdev %d" vfio_add_ext_cap_dropped(const char *name, uint16_t cap, uint16_t offset) "%s 0x%x@0x%x"
scripts/tracetool/__init__.py +4 -0
@@ -274,6 +274,10 @@ class Event(object): props = groups["props"].split() fmt = groups["fmt"] fmt_trans = groups["fmt_trans"] + if fmt.find("%m") != -1 or fmt_trans.find("%m") != -1: + raise ValueError("Event format '%m' is forbidden, pass the error " + "as an explicit trace argument") + if len(fmt_trans) > 0: fmt = [fmt_trans, fmt] args = Arguments.build(groups["args"])
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v3 3/4] trace: forbid use of %m in trace event format strings
Quoted 4 lines · Daniel P. Berrangé
The '%m' format specifier instructs glibc's
printf()implementation to insert the contents of strerror(errno). Since this is a glibc extension it should generally be avoided in QEMU due to need for portability to a variety of platforms.
Up to you if you want to mention that syslog() portably supports %m, but not all trace backends use syslog().
Quoted 11 lines
Even though vfio is Linux-only code that could otherwise use "%m", it must still be avoided in trace-events files because several of the backends do not use the format string and so this error information is invisible to them.
The errno string value should be given as an explicit trace argument instead, making it accessible to all backends. This also allows it to work correctly with future patches that use the format string with systemtap's simple printf code.
Quoted 7 lines
Signed-off-by Daniel P. Berrangé <[email protected]>--- hw/vfio/pci.c | 2 +- hw/vfio/trace-events | 2 +- scripts/tracetool/__init__.py | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v3 4/4 trace: add ability to do simple printf logging via systemtap
In reply to Daniel P. BerrangéThe dtrace systemtap trace backend for QEMU is very powerful but it is also somewhat unfriendly to users who aren't familiar with systemtap, or who don't need its power right now.
stap -e "....some strange script...."
The 'log' backend for QEMU by comparison is very crude but incredibly easy to use:
$ qemu -d trace:qio* ...some args... [email protected]:qio_channel_socket_new Socket new ioc=0x563a8a39d400 [email protected]:qio_task_new Task new task=0x563a891d0570 source=0x563a8a39d400 func=0x563a86f1e6c0 opaque=0x563a89078000 [email protected]:qio_task_thread_start Task thread start task=0x563a891d0570 worker=0x563a86f1ce50 opaque=0x563a891d9d90 [email protected]:qio_task_thread_run Task thread run task=0x563a891d0570 [email protected]:qio_channel_socket_connect_sync Socket connect sync ioc=0x563a8a39d400 addr=0x563a891d9d90 [email protected]:qio_channel_socket_connect_fail Socket connect fail ioc=0x563a8a39d400
This commit introduces a way to do simple printf style logging of probe points using systemtap. In particular it creates another set of tapsets, one per emulator:
/usr/share/systemtap/tapset/qemu-*-log.stp
These pre-define probe functions which simply call printf() on their arguments. The printf() format string is taken from the normal trace-events files, with a little munging to the format specifiers to cope with systemtap's more restrictive syntax.
With this you can now do
$ stap -e 'probe qemu.system.x86_64.log.qio*{}'
22806@1547735341399856820 qio_channel_socket_new Socket new ioc=0x56135d1d7c00
22806@1547735341399862570 qio_task_new Task new task=0x56135cd66eb0 source=0x56135d1d7c00 func=0x56135af746c0 opaque=0x56135bf06400
22806@1547735341399865943 qio_task_thread_start Task thread start task=0x56135cd66eb0 worker=0x56135af72e50 opaque=0x56135c071d70
22806@1547735341399976816 qio_task_thread_run Task thread run task=0x56135cd66eb0We go one step further though and introduce a 'qemu-trace-stap' tool to make this even easier
$ qemu-trace-stap run qemu-system-x86_64 'qio*' 22806@1547735341399856820 qio_channel_socket_new Socket new ioc=0x56135d1d7c00 22806@1547735341399862570 qio_task_new Task new task=0x56135cd66eb0 source=0x56135d1d7c00 func=0x56135af746c0 opaque=0x56135bf06400 22806@1547735341399865943 qio_task_thread_start Task thread start task=0x56135cd66eb0 worker=0x56135af72e50 opaque=0x56135c071d70 22806@1547735341399976816 qio_task_thread_run Task thread run task=0x56135cd66eb0
This tool is clever in that it will automatically change the SYSTEMTAP_TAPSET env variable to point to the directory containing the right set of probes for the QEMU binary path you give it. This is useful if you have QEMU installed in /usr but are trying to test and trace a binary in /home/berrange/usr/qemu-git. In that case you'd do
$ qemu-trace-stap run /home/berrange/usr/qemu-git/bin/qemu-system-x86_64 'qio*'
And it'll make sure /home/berrange/usr/qemu-git/share/systemtap/tapset is used for the trace session
The 'qemu-trace-stap' script takes a verbose arg so you can understand what it is running
$ qemu-trace-stap run /home/berrange/usr/qemu-git/bin/qemu-system-x86_64 'qio*'
Using tapset dir '/home/berrange/usr/qemu-git/share/systemtap/tapset' for binary '/home/berrange/usr/qemu-git/bin/qemu-system-x86_64'
Compiling script 'probe qemu.system.x86_64.log.qio* {}'
Running script, <Ctrl>-c to quit
...trace output...It can enable multiple probes at once
$ qemu-trace-stap run qemu-system-x86_64 'qio*' 'qcrypto*' 'buffer*'
By default it monitors all existing running processes and all future launched proceses. This can be restricted to a specific PID using the --pid arg
$ qemu-trace-stap run --pid 2532 qemu-system-x86_64 'qio*'
Finally if you can't remember what probes are valid it can tell you
$ qemu-trace-stap list qemu-system-x86_64 ahci_check_irq ahci_cmd_done ahci_dma_prepare_buf ahci_dma_prepare_buf_fail ahci_dma_rw_buf ahci_irq_lower ...snip...
Or list just those matching a prefix pattern
$ qemu-trace-stap list -v qemu-system-x86_64 'qio*' Using tapset dir '/home/berrange/usr/qemu-git/share/systemtap/tapset' for binary '/home/berrange/usr/qemu-git/bin/qemu-system-x86_64' Listing probes with name 'qemu.system.x86_64.log.qio*' qio_channel_command_abort qio_channel_command_new_pid qio_channel_command_new_spawn qio_channel_command_wait qio_channel_file_new_fd ...snip...
--- MAINTAINERS | 1 + Makefile | 10 ++ Makefile.target | 11 +- docs/devel/tracing.txt | 4 + scripts/qemu-trace-stap | 174 +++++++++++++++++++++++++++ scripts/qemu-trace-stap.texi | 139 +++++++++++++++++++++ scripts/tracetool/format/log_stap.py | 127 +++++++++++++++++++ 7 files changed, 465 insertions(+), 1 deletion(-) create mode 100755 scripts/qemu-trace-stap create mode 100644 scripts/qemu-trace-stap.texi create mode 100644 scripts/tracetool/format/log_stap.py
MAINTAINERS +1 -0
@@ -2017,6 +2017,7 @@ F: trace-events F: qemu-option-trace.texi F: scripts/tracetool.py F: scripts/tracetool/ +F: scripts/qemu-trace-stap* F: docs/devel/tracing.txt T: git https://github.com/stefanha/qemu.git tracing
Makefile +10 -0
@@ -305,6 +305,9 @@ DOCS+=docs/qemu-cpu-models.7 ifdef CONFIG_VIRTFS DOCS+=fsdev/virtfs-proxy-helper.1 endif +ifdef CONFIG_TRACE_SYSTEMTAP +DOCS+=scripts/qemu-trace-stap.1 +endif else DOCS= endif
@@ -700,6 +703,9 @@ ifneq ($(TOOLS),) $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8" $(INSTALL_DATA) qemu-nbd.8 "$(DESTDIR)$(mandir)/man8" endif +ifdef CONFIG_TRACE_SYSTEMTAP + $(INSTALL_DATA) scripts/qemu-trace-stap.1 "$(DESTDIR)$(mandir)/man1" +endif ifneq (,$(findstring qemu-ga,$(TOOLS))) $(INSTALL_DATA) qemu-ga.8 "$(DESTDIR)$(mandir)/man8" $(INSTALL_DATA) docs/interop/qemu-ga-ref.html "$(DESTDIR)$(qemu_docdir)"
@@ -738,6 +744,9 @@ endif ifneq ($(HELPERS-y),) $(call install-prog,$(HELPERS-y),$(DESTDIR)$(libexecdir)) endif +ifdef CONFIG_TRACE_SYSTEMTAP + $(INSTALL_PROG) "scripts/qemu-trace-stap" $(DESTDIR)$(bindir) +endif ifneq ($(BLOBS),) set -e; for x in $(BLOBS); do \ $(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(qemu_datadir)"; \
@@ -838,6 +847,7 @@ qemu-nbd.8: qemu-nbd.texi qemu-option-trace.texi qemu-ga.8: qemu-ga.texi docs/qemu-block-drivers.7: docs/qemu-block-drivers.texi docs/qemu-cpu-models.7: docs/qemu-cpu-models.texi +scripts/qemu-trace-stap.1: scripts/qemu-trace-stap.texi html: qemu-doc.html docs/interop/qemu-qmp-ref.html docs/interop/qemu-ga-ref.html info: qemu-doc.info docs/interop/qemu-qmp-ref.info docs/interop/qemu-ga-ref.info
Makefile.target +10 -1
@@ -45,7 +45,7 @@ config-target.h: config-target.h-timestamp config-target.h-timestamp: config-target.mak ifdef CONFIG_TRACE_SYSTEMTAP -stap: $(QEMU_PROG).stp-installed $(QEMU_PROG).stp $(QEMU_PROG)-simpletrace.stp +stap: $(QEMU_PROG).stp-installed $(QEMU_PROG).stp $(QEMU_PROG)-simpletrace.stp $(QEMU_PROG)-log.stp ifdef CONFIG_USER_ONLY TARGET_TYPE=user
@@ -84,6 +84,14 @@ $(QEMU_PROG)-simpletrace.stp: $(BUILD_DIR)/trace-events-all $(tracetool-y) --probe-prefix=qemu.$(TARGET_TYPE).$(TARGET_NAME) \ $< > $@,"GEN","$(TARGET_DIR)$(QEMU_PROG)-simpletrace.stp") +$(QEMU_PROG)-log.stp: $(BUILD_DIR)/trace-events-all $(tracetool-y) + $(call quiet-command,$(TRACETOOL) \ + --group=all \ + --format=log-stap \ + --backends=$(TRACE_BACKENDS) \ + --probe-prefix=qemu.$(TARGET_TYPE).$(TARGET_NAME) \ + $< > $@,"GEN","$(TARGET_DIR)$(QEMU_PROG)-log.stp") + else stap: endif
@@ -227,6 +235,7 @@ ifdef CONFIG_TRACE_SYSTEMTAP $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset" $(INSTALL_DATA) $(QEMU_PROG).stp-installed "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG).stp" $(INSTALL_DATA) $(QEMU_PROG)-simpletrace.stp "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG)-simpletrace.stp" + $(INSTALL_DATA) $(QEMU_PROG)-log.stp "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG)-log.stp" endif GENERATED_FILES += config-target.h
docs/devel/tracing.txt +4 -0
@@ -317,6 +317,10 @@ probes: --target-name x86_64 \ <trace-events-all >qemu.stp +To facilitate simple usage of systemtap where there merely needs to be printf +logging of certain probes, a helper script "qemu-trace-stap" is provided. +Consult its manual page for guidance on its usage. + == Trace event properties == Each event in the "trace-events-all" file can be prefixed with a space-separated
scripts/qemu-trace-stap new file +174 -0
174 lines not on this page · raw message
scripts/qemu-trace-stap.texi new file +139 -0
139 lines not on this page · raw message
scripts/tracetool/format/log_stap.py new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v3 4/4] trace: add ability to do simple printf logging via systemtap
Quoted 4 lines · Daniel P. Berrangé
The dtrace systemtap trace backend for QEMU is very powerful but it is also somewhat unfriendly to users who aren't familiar with systemtap, or who don't need its power right now.
Quoted 9 lines
stap -e "....some strange script...."
By default it monitors all existing running processes and all future launched proceses. This can be restricted to a specific PID using the --pid arg
$ qemu-trace-stap run --pid 2532 qemu-system-x86_64 'qio*'
Can --pid mode be smart enough to check /proc/NNN/exe without the user having to specify the explicit qemu-system-x86_64 argument? (Could be followup patch)
scripts/qemu-trace-stap line 11
Quoted 9 lines
+++ b/scripts/qemu-trace-stap
scripts/qemu-trace-stap new file +6
-0@@ -0,0 +1,174 @@ +# QEMU SystemTap Trace Tool +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; under version 2 of the License. +#
Why GPLv2-only?
Quoted 25 lines
scripts/qemu-trace-stap new file +25
-0+def main(): + parser = argparse.ArgumentParser(description="QEMU SystemTap trace tool") + parser.add_argument("-v", "--verbose", help="Print verbose progress info", + action='store_true') + + subparser = parser.add_subparsers(help="commands") + subparser.required = True + subparser.dest = "command" + + runparser = subparser.add_parser("run", help="Run a trace session", + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=""" + +To watch all trace points on the qemu-system-x86_64 binary: + + %(argv0)s run qemu-system-x86_64 + +To only watch the trace points matching the qio* and qcrypto* patterns + + %(argv0)s run qemu-system-x86_64 'qio*' 'qcrypto*' +""" % {"argv0": sys.argv[0]}) + runparser.set_defaults(func=cmd_run) + runparser.add_argument("--pid", "-p", dest="pid", + help="Restrict tracing to a specific process ID") + runparser.add_argument("binary", help="QEMU system or user emulator binary")
scripts/qemu-trace-stap line 157
Quoted 10 lines
scripts/qemu-trace-stap new file +10
-0+ runparser.add_argument("probes", help="Probe names or wildcards", + nargs=argparse.REMAINDER) + + listparser = subparser.add_parser("list", help="List probe points", + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=""" + +To list all trace points on the qemu-system-x86_64 binary: + + %(argv0)s list qemu-system-x86_64
No mention of --pid mode in the --help output?
Quoted 14 lines
+++ b/scripts/qemu-trace-stap.texi
scripts/qemu-trace-stap.texi new file +12
-0@@ -0,0 +1,139 @@ +@example +@c man begin SYNOPSIS +@command{qemu-trace-stap} @var{GLOBAL-OPTIONS} @var{COMMAND} @var{COMMAND-OPTIONS} @var{ARGS...} +@c man end +@end example + +@c man begin DESCRIPTION + +The @command{qemu-trace-stap} program facilitates tracing of the execution +of QEMU emulators using SystemTap. + +It is required to have the SystemTap runtime environment installed to use
scripts/qemu-trace-stap.texi line 22
Quoted 10 lines
scripts/qemu-trace-stap.texi new file +10
-0+this program, since it is a wrapper around execution of the @command{stap} +program. + +@c man end + +@c man begin OPTIONS + +The following global options may be used regardless of which command +is executed +
Could use trailing ':'
scripts/qemu-trace-stap.texi line 26
Quoted 4 lines
scripts/qemu-trace-stap.texi new file +4
-0+@table @option +@item @var{--verbose}, @var{-v} + +Display verbose information about command execution
Trailing '.'
Quoted 7 lines
scripts/qemu-trace-stap.texi new file +7
-0+@item @var{run} @var{OPTIONS} @var{BINARY} @var{PATTERN...} + +Run a trace session, printing formatted output any time a process that is +executing @var{BINARY} triggers a probe matching @var{PATTERN}. + +If @var{BINARY} is not an absolute path, it will be located by searching +the directories listed in the @code{$PATH} environment variable.
scripts/qemu-trace-stap.texi line 80
Quoted 10 lines
scripts/qemu-trace-stap.texi new file +10
-0+ +@var{PATTERN} is a plain string that matches a probe name shown by the +@var{list} command. It may optionally contain a @code{*} wildcard to +facilitate matching multiple probes without listing each one explicitly. +Multiple @var{PATTERN} arguments may be given, causing all matching probes +to be monitored. At least one @var{PATTERN} is required, since stap is not +capable of tracing all known QEMU probes concurrently without overflowing +its trace buffer. + +Invokation of this command does not need to be synchronized with
s/Invokation/Invocation/
scripts/qemu-trace-stap.texi line 81
Quoted 1 line
scripts/qemu-trace-stap.texi new file +1
-0+invokation of the QEMU process(es). It will match probes on all
and again
scripts/qemu-trace-stap.texi line 83
Quoted 2 lines
scripts/qemu-trace-stap.texi new file +2
-0+existing running processes and all future launched processes, +unless told to only monitor a specific procss.
s/procss/process/
scripts/qemu-trace-stap.texi line 95
Quoted 12 lines
scripts/qemu-trace-stap.texi new file +12
-0+ +Valid command specific options are: + +@table @option +@item @var{--pid=PID}, @var{-p PID} + +Restrict the tracing session so that it only triggers for the process +identified by @code{PID}. + +@end table + +For example, to monitor all processes executing @command{qemu-system-x86_64},
Maybe "executing @command{qemu-system-x86_64} as found on $PATH,"
scripts/qemu-trace-stap.texi line 127
Quoted 6 lines
scripts/qemu-trace-stap.texi new file +6
-0+@setfilename qemu-trace-stap +@settitle QEMU SystemTap trace tool + +@c man begin LICENSE + +Copyright (C) 2018 Red Hat, Inc.
Welcome to 2019
scripts/qemu-trace-stap.texi line 131
Quoted 4 lines
scripts/qemu-trace-stap.texi new file +4
-0+ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; under version 2 of the License.
Why GPLv2-only?
Quoted 14 lines
scripts/qemu-trace-stap.texi new file +8
-0+ +@c man end + +@c man begin SEEALSO +qemu(1), stap(1) +@c man end + +@end ignorescripts/tracetool/format/log_stap.py new file +0
-0
scripts/tracetool/format/log_stap.py line 10
Quoted 10 lines
scripts/tracetool/format/log_stap.py new file +10
-0@@ -0,0 +1,127 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generate .stp file that printfs log messages (DTrace with SystemTAP only). +""" + +__author__ = "Daniel P. Berrange <[email protected]>" +__copyright__ = "Copyright (C) 2014-2019, Red Hat, Inc." +__license__ = "GPL version 2 or (at your option) any later version"
At least this file is GPLv2+.
Typos are trivial, licensing less so, but I trust you can fix licensing without me having to see a respin (as it won't change code). So:
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v3 4/4] trace: add ability to do simple printf logging via systemtap
Quoted 12 lines · Eric Blake
Quoted 11 lines · Daniel P. Berrangé
The dtrace systemtap trace backend for QEMU is very powerful but it is also somewhat unfriendly to users who aren't familiar with systemtap, or who don't need its power right now.
stap -e "....some strange script...."
By default it monitors all existing running processes and all future launched proceses. This can be restricted to a specific PID using the --pid arg
Quoted 6 lines
Quoted 2 lines
$ qemu-trace-stap run --pid 2532 qemu-system-x86_64 'qio*'Can --pid mode be smart enough to check
/proc/NNN/exewithout the user having to specify the explicit qemu-system-x86_64 argument? (Could be followup patch)
It could do that, but this complicates the parsing of command line arguments, as the binary is a positional arg.
Quoted 11 lines
scripts/qemu-trace-stap line 11
Quoted 9 lines
+++ b/scripts/qemu-trace-stap
scripts/qemu-trace-stap new file +6
-0@@ -0,0 +1,174 @@ +# QEMU SystemTap Trace Tool +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; under version 2 of the License. +#Why GPLv2-only?
A mistake, it should be v2-or-later
Quoted 30 lines
Quoted 30 lines
scripts/qemu-trace-stap new file +29
-0+def main(): + parser = argparse.ArgumentParser(description="QEMU SystemTap trace tool") + parser.add_argument("-v", "--verbose", help="Print verbose progress info", + action='store_true') + + subparser = parser.add_subparsers(help="commands") + subparser.required = True + subparser.dest = "command" + + runparser = subparser.add_parser("run", help="Run a trace session", + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=""" + +To watch all trace points on the qemu-system-x86_64 binary: + + %(argv0)s run qemu-system-x86_64 + +To only watch the trace points matching the qio* and qcrypto* patterns + + %(argv0)s run qemu-system-x86_64 'qio*' 'qcrypto*' +""" % {"argv0": sys.argv[0]}) + runparser.set_defaults(func=cmd_run) + runparser.add_argument("--pid", "-p", dest="pid", + help="Restrict tracing to a specific process ID") + runparser.add_argument("binary", help="QEMU system or user emulator binary") + runparser.add_argument("probes", help="Probe names or wildcards", + nargs=argparse.REMAINDER) + + listparser = subparser.add_parser("list", help="List probe points",
Quoted 8 lines
scripts/qemu-trace-stap line 157
Quoted 6 lines
scripts/qemu-trace-stap new file +6
-0+ formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=""" + +To list all trace points on the qemu-system-x86_64 binary: + + %(argv0)s list qemu-system-x86_64No mention of --pid mode in the --help output?
getopt generates --help output listing all arguments. The epilog is just a bit of text to augment what it already prints
Quoted 3 lines
Typos are trivial, licensing less so, but I trust you can fix licensing without me having to see a respin (as it won't change code). So:
Reviewed-by Eric Blake <[email protected]>
Will incorporate these changes
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|