From c53eeaf75a04782e15a0cc931eda0b9e3143cfd0 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Tue, 28 Mar 2017 14:44:18 +0100 Subject: [PATCH 1/3] configure: eliminate Python dependency for --help The ./configure script should produce --help output even if Python is not installed. Listing trace backends is simple: show the names of all Python modules in scripts/tracetool/backend/ whose source code contains 'PUBLIC = True'. Perform the backend enumeration in shell instead of Python so that we can move the Python check until after ./configure --help. Reported-by: Peter Maydell Signed-off-by: Stefan Hajnoczi Reviewed-by: Peter Maydell Message-id: 20170328134418.3426-1-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- configure | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/configure b/configure index be4d326ae0..6db3044fb0 100755 --- a/configure +++ b/configure @@ -1191,21 +1191,6 @@ for opt do esac done -if ! has $python; then - error_exit "Python not found. Use --python=/path/to/python" -fi - -# Note that if the Python conditional here evaluates True we will exit -# with status 1 which is a shell 'false' value. -if ! $python -c 'import sys; sys.exit(sys.version_info < (2,6) or sys.version_info >= (3,))'; then - error_exit "Cannot use '$python', Python 2.6 or later is required." \ - "Note that Python 3 or later is not yet supported." \ - "Use --python=/path/to/python to specify a supported Python." -fi - -# Suppress writing compiled files -python="$python -B" - case "$cpu" in ppc) CPU_CFLAGS="-m32" @@ -1280,6 +1265,9 @@ for config in $mak_wilds; do default_target_list="${default_target_list} $(basename "$config" .mak)" done +# Enumerate public trace backends for --help output +trace_backend_list=$(echo $(grep -le '^PUBLIC = True$' scripts/tracetool/backend/*.py | sed -e 's/^.*\/\(.*\)\.py$/\1/')) + if test x"$show_help" = x"yes" ; then cat << EOF @@ -1333,7 +1321,7 @@ Advanced options (experts only): set block driver read-only whitelist (affects only QEMU, not qemu-img) --enable-trace-backends=B Set trace backend - Available backends: $($python $source_path/scripts/tracetool.py --list-backends) + Available backends: $trace_backend_list --with-trace-file=NAME Full PATH,NAME of file to store traces Default:trace- --disable-slirp disable SLIRP userspace network connectivity @@ -1433,6 +1421,21 @@ EOF exit 0 fi +if ! has $python; then + error_exit "Python not found. Use --python=/path/to/python" +fi + +# Note that if the Python conditional here evaluates True we will exit +# with status 1 which is a shell 'false' value. +if ! $python -c 'import sys; sys.exit(sys.version_info < (2,6) or sys.version_info >= (3,))'; then + error_exit "Cannot use '$python', Python 2.6 or later is required." \ + "Note that Python 3 or later is not yet supported." \ + "Use --python=/path/to/python to specify a supported Python." +fi + +# Suppress writing compiled files +python="$python -B" + # Now we have handled --enable-tcg-interpreter and know we're not just # printing the help message, bail out if the host CPU isn't supported. if test "$ARCH" = "unknown"; then From 3d1baccb08562e2893085f102c863507917c0453 Mon Sep 17 00:00:00 2001 From: "Xu, Anthony" Date: Tue, 4 Apr 2017 21:39:39 +0000 Subject: [PATCH 2/3] trace: Put all trace.o into libqemuutil.a Currently all trace.o are linked into qemu-system, qemu-img, qemu-nbd, qemu-io etc., even the corresponding components are not included. Put all trace.o into libqemuutil.a that the linker would only pull in .o files containing symbols that are actually referenced by the program. Signed-off -by: Anthony Xu Signed-off-by: Stefan Hajnoczi --- Makefile | 6 +++--- Makefile.target | 5 ++--- tests/Makefile.include | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 6c359b2f86..31d41a7eae 100644 --- a/Makefile +++ b/Makefile @@ -346,7 +346,7 @@ dtc/%: mkdir -p $@ $(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(chardev-obj-y) \ - $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) $(trace-obj-y) + $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) # Only keep -O and -g cflags @@ -366,11 +366,11 @@ Makefile: $(version-obj-y) # Build libraries libqemustub.a: $(stub-obj-y) -libqemuutil.a: $(util-obj-y) +libqemuutil.a: $(util-obj-y) $(trace-obj-y) ###################################################################### -COMMON_LDADDS = $(trace-obj-y) libqemuutil.a libqemustub.a +COMMON_LDADDS = libqemuutil.a libqemustub.a qemu-img.o: qemu-img-cmds.h diff --git a/Makefile.target b/Makefile.target index 7df2b8c149..e62021d5aa 100644 --- a/Makefile.target +++ b/Makefile.target @@ -188,8 +188,7 @@ dummy := $(call unnest-vars,.., \ qom-obj-y \ io-obj-y \ common-obj-y \ - common-obj-m \ - trace-obj-y) + common-obj-m) target-obj-y := $(target-obj-y-save) all-obj-y += $(common-obj-y) all-obj-y += $(target-obj-y) @@ -201,7 +200,7 @@ all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y) $(QEMU_PROG_BUILD): config-devices.mak -COMMON_LDADDS = $(trace-obj-y) ../libqemuutil.a ../libqemustub.a +COMMON_LDADDS = ../libqemuutil.a ../libqemustub.a # build either PROG or PROGW $(QEMU_PROG_BUILD): $(all-obj-y) $(COMMON_LDADDS) diff --git a/tests/Makefile.include b/tests/Makefile.include index f3de81fcfb..579ec07cce 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -519,7 +519,7 @@ QEMU_CFLAGS += -I$(SRC_PATH)/tests # Deps that are common to various different sets of tests below -test-util-obj-y = $(trace-obj-y) libqemuutil.a libqemustub.a +test-util-obj-y = libqemuutil.a libqemustub.a test-qom-obj-y = $(qom-obj-y) $(test-util-obj-y) test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \ tests/test-qapi-event.o tests/test-qmp-introspect.o \ From 659370f71f2c3d4105b04178abd751242e1c1b68 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Tue, 11 Apr 2017 10:56:54 +0100 Subject: [PATCH 3/3] simpletrace: document Analyzer method signatures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Users can inherit from the simpletrace.Analyzer class and receive callbacks when events of interest occur in a trace file. The method signature is a little magic because the timestamp and pid arguments are optional. Document this. Signed-off-by: Stefan Hajnoczi Reviewed-by: Alex Bennée Message-id: 20170411095654.18383-1-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- scripts/simpletrace.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 4c990047b6..d60b3a08f7 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -116,7 +116,28 @@ class Analyzer(object): is invoked. If a method matching a trace event name exists, it is invoked to process - that trace record. Otherwise the catchall() method is invoked.""" + that trace record. Otherwise the catchall() method is invoked. + + Example: + The following method handles the runstate_set(int new_state) trace event:: + + def runstate_set(self, new_state): + ... + + The method can also take a timestamp argument before the trace event + arguments:: + + def runstate_set(self, timestamp, new_state): + ... + + Timestamps have the uint64_t type and are in nanoseconds. + + The pid can be included in addition to the timestamp and is useful when + dealing with traces from multiple processes:: + + def runstate_set(self, timestamp, pid, new_state): + ... + """ def begin(self): """Called at the start of the trace."""