qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH RFC 3/4] trace-instrument: Add support for user-prov


From: Lluís Vilanova
Subject: [Qemu-devel] [PATCH RFC 3/4] trace-instrument: Add support for user-provided code on a per-event basis
Date: Wed, 07 Dec 2011 22:10:22 +0100
User-agent: StGit/0.15

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ís Vilanova <address@hidden>
---
 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
 
 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
 
 trace.o: trace.c $(GENERATED_HEADERS)
@@ -399,6 +399,25 @@ trace-obj-y += $(addprefix trace/, $(trace-nested-y))
 $(trace-obj-y): $(GENERATED_HEADERS)
 
 ######################################################################
+# trace instrument
+
+ifdef CONFIG_TRACE_INSTRUMENT
+LIBTRACE_INSTRUMENT = libtrace-instrument/libtrace-instrument.a
+
+.PHONY: force
+force:
+
+$(LIBTRACE_INSTRUMENT): QEMU_CFLAGS += -I$(SRC_PATH)/fpu
+$(LIBTRACE_INSTRUMENT): QEMU_CFLAGS += -I$(SRC_PATH)/tcg/$(TARGET_BASE_ARCH)
+$(LIBTRACE_INSTRUMENT): VPATH = $(TRACE_INSTRUMENT_PATH)
+$(LIBTRACE_INSTRUMENT): $(dir $(LIBTRACE_INSTRUMENT))/Makefile force
+       $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@)   \
+               QEMU_CFLAGS="$(QEMU_CFLAGS)"                            \
+               TARGET_DIR=$(TARGET_DIR)$(dir $@)/ VPATH=$(VPATH)       \
+               SRC_PATH=$(SRC_PATH) V="$(V)" $(notdir $@))
+endif
+
+######################################################################
 # backdoor
 
 backdoor-nested-$(CONFIG_USER_ONLY) += 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
 
 obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o
 
-$(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y) $(LIBBACKDOOR)
+$(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y) $(LIBBACKDOOR) 
$(LIBTRACE_INSTRUMENT)
        $(call LINK,$^)
 
 
diff --git a/configure b/configure
index 67d4c9a..ab7ced5 100755
--- a/configure
+++ b/configure
@@ -176,6 +176,7 @@ pie=""
 zero_malloc=""
 trace_backend="nop"
 trace_file="trace"
+trace_instrument=""
 backdoor=""
 spice=""
 rbd=""
@@ -550,6 +551,8 @@ for opt do
   ;;
   --with-trace-file=*) trace_file="$optarg"
   ;;
+  --with-trace-instrument=*) trace_instrument="$optarg"
+  ;;
   --with-backdoor=*) backdoor="$optarg"
   ;;
   --enable-gprof) gprof="yes"
@@ -1065,6 +1068,8 @@ echo "  --enable-trace-backend=B Set trace backend"
 echo "                           Available backends:" 
$("$source_path"/scripts/tracetool --list-backends)
 echo "  --with-trace-file=NAME   Full PATH,NAME of file to store traces"
 echo "                           Default:trace-<pid>"
+echo "  --with-trace-instrument=PATH"
+echo "                           Directory to build user-provided trace event 
instrumentation library"
 echo "  --with-backdoor=PATH     Directory to build user-provided backdoor 
library"
 echo "  --disable-spice          disable spice"
 echo "  --enable-spice           enable spice"
@@ -2699,6 +2704,26 @@ if compile_prog "" "" ; then
 fi
 
 ##########################################
+# 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=`readlink -f "$trace_instrument"`
+fi
+
+
+##########################################
 # End of CC checks
 # After here, no more $cc or $ld runs
 
@@ -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-<pid>"
+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=$trace_file" >> $config_host_mak
 if test "$trace_default" = "yes"; then
   echo "CONFIG_TRACE_DEFAULT=y" >> $config_host_mak
 fi
+if test -n "$trace_instrument"; then
+  echo "CONFIG_TRACE_INSTRUMENT=y" >> $config_host_mak
+  echo "TRACE_INSTRUMENT_PATH=\"$trace_instrument\"" >> $config_host_mak
+  echo "TRACETOOL_EXTRA=--instrument" >> $config_host_mak
+  QEMU_CFLAGS="-I\"$trace_instrument\" $QEMU_CFLAGS"
+fi
 
 # backdoor channel
 if test -n "$backdoor"; then
@@ -3370,6 +3404,10 @@ if test "$target" = "arm-linux-user" -o "$target" = 
"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/Makefile
+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 = 0xfffffffffffffffe
 
 trace_fmt = '=QQQQQQQQ'
 trace_len = struct.calcsize(trace_fmt)
-event_re  = re.compile(r'(disable\s+)?([a-zA-Z0-9_]+)\(([^)]*)\).*')
+event_re  = 
re.compile(r'(disable\s+|instrument\s+)*([a-zA-Z0-9_]+)\(([^)]*)\).*')
 
 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
 
 EOF
     exit 1
@@ -553,8 +554,16 @@ convert()
             "lineto$1_nop" "$str"
             enabled=0
         else
+            if has_property "$str" "instrument"; then
+                if [ "$instrument" != "1" ]; then
+                    echo "Event '"$(get_name "$str")"' has the 'instrument' 
property but instrumentation is not enabled" >&2
+                    exit 1
+                fi
+                get_api_name_fmt="${get_api_name_fmt_default}_backend"
+            fi
             "$process_line" "$str"
             enabled=1
+            unset get_api_name_fmt
         fi
         if [ "$1" = "h" ]; then
             name=$(get_name "$str")
@@ -578,6 +587,11 @@ tracetoh()
 #include "qemu-common.h"
 EOF
     convert h
+
+    if [ "$instrument" = "1" ]; then
+        echo '#include "trace-instrument.h"'
+    fi
+
     echo "#endif /* TRACE_H */"
 }
 
@@ -629,6 +643,7 @@ binary=
 targettype=
 targetarch=
 probeprefix=
+instrument=
 
 
 until [ -z "$1" ]
@@ -640,6 +655,7 @@ do
     "--target-arch") shift ; targetarch="$1" ;;
     "--target-type") shift ; targettype="$1" ;;
     "--probe-prefix") shift ; probeprefix="$1" ;;
+    "--instrument") instrument="1" ;;
 
     "-h" | "-c" | "-d") output="${1#-}" ;;
     "--stap") output="${1#--}" ;;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]