Received: from eggs.gnu.org ([140.186.70.92]:41740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYOl7-0005DH-FX for qemu-devel@nongnu.org; Wed, 07 Dec 2011 16:10:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYOl5-0003r5-RS for qemu-devel@nongnu.org; Wed, 07 Dec 2011 16:10:33 -0500 Received: from gw.ac.upc.edu ([147.83.30.3]:52806) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYOl5-0003qt-DE for qemu-devel@nongnu.org; Wed, 07 Dec 2011 16:10:31 -0500 Received: from localhost (unknown [84.88.53.92]) by gw.ac.upc.edu (Postfix) with ESMTP id 64BBF6B0247 for ; Wed, 7 Dec 2011 22:10:30 +0100 (CET) From: =?utf-8?b?TGx1w61z?= Vilanova Date: Wed, 07 Dec 2011 22:10:22 +0100 Message-ID: <20111207211022.24875.5345.stgit@ginnungagap.bsc.es> In-Reply-To: <20111207210936.24875.39375.stgit@ginnungagap.bsc.es> References: <20111207210936.24875.39375.stgit@ginnungagap.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH RFC 3/4] trace-instrument: Add support for user-provided code on a per-event basis List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Adds support for the 'instrument' propery into the "trace-events" file. Events with this property will generate tracing routines named '${api_name}_backend' (instead of '${api_name}'), and expect the user to = provide its own implementation for the '${api_name}' routines. Signed-off-by: Llu=C3=ADs Vilanova --- Makefile.objs | 23 +++++++++++++++++++++-- Makefile.target | 2 +- configure | 38 ++++++++++++++++++++++++++++++++++++++ scripts/simpletrace.py | 2 +- scripts/tracetool | 16 ++++++++++++++++ 5 files changed, 77 insertions(+), 4 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index 0012b04..13f9349 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -346,12 +346,12 @@ else trace.h: trace.h-timestamp endif trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak - $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND= ) -h < $< > $@," GEN trace.h") + $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool $(TRACETOOL_EXTRA= ) --$(TRACE_BACKEND) -h < $< > $@," GEN trace.h") @cmp -s $@ trace.h || cp $@ trace.h =20 trace.c: trace.c-timestamp trace.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak - $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND= ) -c < $< > $@," GEN trace.c") + $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool $(TRACETOOL_EXTRA= ) --$(TRACE_BACKEND) -c < $< > $@," GEN trace.c") @cmp -s $@ trace.c || cp $@ trace.c =20 trace.o: trace.c $(GENERATED_HEADERS) @@ -399,6 +399,25 @@ trace-obj-y +=3D $(addprefix trace/, $(trace-nested-= y)) $(trace-obj-y): $(GENERATED_HEADERS) =20 ###################################################################### +# trace instrument + +ifdef CONFIG_TRACE_INSTRUMENT +LIBTRACE_INSTRUMENT =3D libtrace-instrument/libtrace-instrument.a + +.PHONY: force +force: + +$(LIBTRACE_INSTRUMENT): QEMU_CFLAGS +=3D -I$(SRC_PATH)/fpu +$(LIBTRACE_INSTRUMENT): QEMU_CFLAGS +=3D -I$(SRC_PATH)/tcg/$(TARGET_BASE= _ARCH) +$(LIBTRACE_INSTRUMENT): VPATH =3D $(TRACE_INSTRUMENT_PATH) +$(LIBTRACE_INSTRUMENT): $(dir $(LIBTRACE_INSTRUMENT))/Makefile force + $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) \ + QEMU_CFLAGS=3D"$(QEMU_CFLAGS)" \ + TARGET_DIR=3D$(TARGET_DIR)$(dir $@)/ VPATH=3D$(VPATH) \ + SRC_PATH=3D$(SRC_PATH) V=3D"$(V)" $(notdir $@)) +endif + +###################################################################### # backdoor =20 backdoor-nested-$(CONFIG_USER_ONLY) +=3D user.o diff --git a/Makefile.target b/Makefile.target index a400d92..1b1c71b 100644 --- a/Makefile.target +++ b/Makefile.target @@ -415,7 +415,7 @@ endif # CONFIG_LINUX_USER =20 obj-$(CONFIG_GDBSTUB_XML) +=3D gdbstub-xml.o =20 -$(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y) $(LIBBACKDOOR) +$(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y) $(LIBBACKDOOR) $(LIB= TRACE_INSTRUMENT) $(call LINK,$^) =20 =20 diff --git a/configure b/configure index 67d4c9a..ab7ced5 100755 --- a/configure +++ b/configure @@ -176,6 +176,7 @@ pie=3D"" zero_malloc=3D"" trace_backend=3D"nop" trace_file=3D"trace" +trace_instrument=3D"" backdoor=3D"" spice=3D"" rbd=3D"" @@ -550,6 +551,8 @@ for opt do ;; --with-trace-file=3D*) trace_file=3D"$optarg" ;; + --with-trace-instrument=3D*) trace_instrument=3D"$optarg" + ;; --with-backdoor=3D*) backdoor=3D"$optarg" ;; --enable-gprof) gprof=3D"yes" @@ -1065,6 +1068,8 @@ echo " --enable-trace-backend=3DB Set trace backen= d" echo " Available backends:" $("$source_path"/s= cripts/tracetool --list-backends) echo " --with-trace-file=3DNAME Full PATH,NAME of file to store trace= s" echo " Default:trace-" +echo " --with-trace-instrument=3DPATH" +echo " Directory to build user-provided trace = event instrumentation library" echo " --with-backdoor=3DPATH Directory to build user-provided back= door library" echo " --disable-spice disable spice" echo " --enable-spice enable spice" @@ -2699,6 +2704,26 @@ if compile_prog "" "" ; then fi =20 ########################################## +# check for a valid directory for trace instrumentation +if test -n "$trace_instrument"; then + if test ! -f "$trace_instrument/Makefile"; then + echo + echo "Error: cannot make into '$trace_instrument'" + echo "Please choose a directory where I can run 'make'" + echo + exit 1 + fi + if test ! -f "$trace_instrument/trace-instrument.h"; then + echo + echo "Error: directory '$trace_instrument' does not contain a \"= trace-instrument.h\" file" + echo + exit 1 + fi + trace_instrument=3D`readlink -f "$trace_instrument"` +fi + + +########################################## # End of CC checks # After here, no more $cc or $ld runs =20 @@ -2856,6 +2881,9 @@ echo "uuid support $uuid" echo "vhost-net support $vhost_net" echo "Trace backend $trace_backend" echo "Trace output file $trace_file-" +if test -n "$trace_instrument"; then +echo "Trace instrument $trace_instrument" +fi if test -n "$backdoor"; then echo "Backdoor lib dir $backdoor" fi @@ -3251,6 +3279,12 @@ echo "CONFIG_TRACE_FILE=3D$trace_file" >> $config_= host_mak if test "$trace_default" =3D "yes"; then echo "CONFIG_TRACE_DEFAULT=3Dy" >> $config_host_mak fi +if test -n "$trace_instrument"; then + echo "CONFIG_TRACE_INSTRUMENT=3Dy" >> $config_host_mak + echo "TRACE_INSTRUMENT_PATH=3D\"$trace_instrument\"" >> $config_host_m= ak + echo "TRACETOOL_EXTRA=3D--instrument" >> $config_host_mak + QEMU_CFLAGS=3D"-I\"$trace_instrument\" $QEMU_CFLAGS" +fi =20 # backdoor channel if test -n "$backdoor"; then @@ -3370,6 +3404,10 @@ if test "$target" =3D "arm-linux-user" -o "$target= " =3D "armeb-linux-user" -o "$targ mkdir -p $target_dir/nwfpe fi symlink $source_path/Makefile.target $target_dir/Makefile +if test -n "$trace_instrument"; then + mkdir -p $target_dir/libtrace-instrument + symlink $trace_instrument/Makefile $target_dir/libtrace-instrument/M= akefile +fi if test -n "$backdoor"; then mkdir -p $target_dir/libbackdoor symlink $backdoor/Makefile $target_dir/libbackdoor/Makefile diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index f55e5e6..3706938 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -20,7 +20,7 @@ dropped_event_id =3D 0xfffffffffffffffe =20 trace_fmt =3D '=3DQQQQQQQQ' trace_len =3D struct.calcsize(trace_fmt) -event_re =3D re.compile(r'(disable\s+)?([a-zA-Z0-9_]+)\(([^)]*)\).*') +event_re =3D re.compile(r'(disable\s+|instrument\s+)*([a-zA-Z0-9_]+)\((= [^)]*)\).*') =20 def parse_events(fobj): """Parse a trace-events file into {event_num: (name, arg1, ...)}.""" diff --git a/scripts/tracetool b/scripts/tracetool index c699801..6390d21 100755 --- a/scripts/tracetool +++ b/scripts/tracetool @@ -35,6 +35,7 @@ Options: --target-type [type] QEMU emulator target type ('system' or 'user'= ) --probe-prefix [prefix] Prefix for dtrace probe names (default: qemu-\$targettype-\$targetarch) + --instrument Enable static trace point instrumentation =20 EOF exit 1 @@ -553,8 +554,16 @@ convert() "lineto$1_nop" "$str" enabled=3D0 else + if has_property "$str" "instrument"; then + if [ "$instrument" !=3D "1" ]; then + echo "Event '"$(get_name "$str")"' has the 'instrume= nt' property but instrumentation is not enabled" >&2 + exit 1 + fi + get_api_name_fmt=3D"${get_api_name_fmt_default}_backend" + fi "$process_line" "$str" enabled=3D1 + unset get_api_name_fmt fi if [ "$1" =3D "h" ]; then name=3D$(get_name "$str") @@ -578,6 +587,11 @@ tracetoh() #include "qemu-common.h" EOF convert h + + if [ "$instrument" =3D "1" ]; then + echo '#include "trace-instrument.h"' + fi + echo "#endif /* TRACE_H */" } =20 @@ -629,6 +643,7 @@ binary=3D targettype=3D targetarch=3D probeprefix=3D +instrument=3D =20 =20 until [ -z "$1" ] @@ -640,6 +655,7 @@ do "--target-arch") shift ; targetarch=3D"$1" ;; "--target-type") shift ; targettype=3D"$1" ;; "--probe-prefix") shift ; probeprefix=3D"$1" ;; + "--instrument") instrument=3D"1" ;; =20 "-h" | "-c" | "-d") output=3D"${1#-}" ;; "--stap") output=3D"${1#--}" ;;