Patchwork [v2,2/3] trace-instrument: let the user override events generated by 'tracetool'

login
register
mail settings
Submitter =?utf-8?Q?Llu=C3=ADs?=
Date Nov. 4, 2010, 10:36 p.m.
Message ID <20101104223624.16785.9186.stgit@ginnungagap.bsc.es>
Download mbox | patch
Permalink /patch/70181/
State New
Headers show

Comments

=?utf-8?Q?Llu=C3=ADs?= - Nov. 4, 2010, 10:36 p.m.
Add a new event keyword ("instrument") that lets the user provide her own
implementation of tracing events.

Still, tracetool's original implementation is accessible through function
'_trace_##name' instead of 'trace_##name' (in case the user only wants to wrap
around the event).

Additionally, a '#define trace_##name##_enabled 1' is provided in "trace.h" in
case the tracing point arguments need some extra computations only when enabled.

Signed-off-by: LluĂ­s Vilanova <vilanova@ac.upc.edu>
---
 Makefile       |    4 ++--
 simpletrace.py |    2 +-
 trace-events   |   23 +++++++++++++++++------
 tracetool      |   33 ++++++++++++++++++++++++++++++---
 4 files changed, 50 insertions(+), 12 deletions(-)

Patch

diff --git a/Makefile b/Makefile
index 2ba52aa..97cb3b4 100644
--- a/Makefile
+++ b/Makefile
@@ -110,12 +110,12 @@  bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS)
 
 trace.h: trace.h-timestamp
 trace.h-timestamp: $(SRC_PATH)/trace-events config-host.mak
-	$(call quiet-command,sh $(SRC_PATH)/tracetool --regular --$(TRACE_BACKEND) -h < $< > $@,"  GEN   trace.h")
+	$(call quiet-command,sh $(SRC_PATH)/tracetool $(TRACETOOL_EXTRA) --regular --$(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 config-host.mak
-	$(call quiet-command,sh $(SRC_PATH)/tracetool --regular --$(TRACE_BACKEND) -c < $< > $@,"  GEN   trace.c")
+	$(call quiet-command,sh $(SRC_PATH)/tracetool $(TRACETOOL_EXTRA) --regular --$(TRACE_BACKEND) -c < $< > $@,"  GEN   trace.c")
 	@cmp -s $@ trace.c || cp $@ trace.c
 
 trace.o: trace.c $(GENERATED_HEADERS)
diff --git a/simpletrace.py b/simpletrace.py
index 553a727..6d8100e 100755
--- a/simpletrace.py
+++ b/simpletrace.py
@@ -19,7 +19,7 @@  header_version  = 0
 
 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 err(msg):
     sys.stderr.write(msg + '\n')
diff --git a/trace-events b/trace-events
index 947f8b0..fefac91 100644
--- a/trace-events
+++ b/trace-events
@@ -12,21 +12,32 @@ 
 #
 # Format of a trace event:
 #
-# [disable] <name>(<type1> <arg1>[, <type2> <arg2>] ...) "<format-string>"
+# [<property> ...] <name>(<type1> <arg1>[, <type2> <arg2>] ...) "<format-string>"
 #
 # Example: qemu_malloc(size_t size) "size %zu"
 #
-# The "disable" keyword will build without the trace event.
-# In case of 'simple' trace backend, it will allow the trace event to be
-# compiled, but this would be turned off by default. It can be toggled on via
-# the monitor.
-#
 # The <name> must be a valid as a C function name.
 #
 # Types should be standard C types.  Use void * for pointers because the trace
 # system may not have the necessary headers included.
 #
 # The <format-string> should be a sprintf()-compatible format string.
+#
+# Properties:
+#
+# - disable
+#   Build QEMU without the trace event.
+#   In case of using the 'simple' trace backend, it will allow the trace event
+#   to be compiled, but this would be turned off by default. It can be toggled
+#   on via the monitor.
+#
+# - instrument
+#   Let the user provide code for the trace event.
+#   The "instrument" keyword will let the user provide her own 'trace_##name'
+#   implementation on "trace-instrument.h" and "libinstrument.a" (their location
+#   is identified by the '--with-instrument' configure option).
+#   The original backend-specific function is still available under the name
+#   'trace_##name##_backend'.
 
 # qemu-malloc.c
 disable qemu_malloc(size_t size, void *ptr) "size %zu ptr %p"
diff --git a/tracetool b/tracetool
index c5ae6a7..f9098da 100755
--- a/tracetool
+++ b/tracetool
@@ -349,15 +349,30 @@  traceto_h_regular()
 #include "qemu-common.h"
 EOF
     convert h $1 $2
+    if [ "$had_instrument" = "1" ]; then
+        echo '#include "trace-instrument.h"'
+    fi
     echo "#endif /* TRACE_H */"
 }
 
 line_h_regular()
 {
-    local api func
+    # XXX: should still provide instrumentation if event is disabled?
+    local api func instrument
     api=$(get_api_name "$1")
     func=$(get_func_name "$1")
-    echo "#define $api $func"
+    instrument=$(get_property "$1" "instrument")
+    if [ "$instrument" = "1" ]; then
+        had_instrument="1"
+    else
+        echo "#define $api $func"
+    fi
+
+    local disable
+    disable=$(get_property "$1" "disable")
+    if [ "$disable" = "0" ]; then
+        echo "#define ${api}_enabled 1"
+    fi
 }
 
 ### Regular -- C
@@ -402,12 +417,18 @@  frontend=nil
 backend=nil
 output=nil
 
+enable_instrument="0"
+had_instrument="0"
+
 usage()
 {
     cat >&2 <<EOF
-usage: $0 <frontend> <backend> <output>
+usage: $0 [<flag>] <frontend> <backend> <output>
 Generate tracing code for a file on stdin.
 
+Flags:
+  --instrument  Enable instrumentation
+
 Frontends:
   --regular     Regular frontend
 
@@ -425,6 +446,7 @@  EOF
 
 while [ $# -gt 0 ]; do
     case $1 in
+        "--instrument") enable_instrument="1" ;;
         "--regular") frontend="${1#--}" ;;
         "--nop"|"--simple"|"--ust") backend="${1#--}" ;;
         "-h"|"-c") output="${1#-}" ;;
@@ -441,4 +463,9 @@  fi
 
 traceto_${output}_$frontend $frontend $backend
 
+if [ "$had_instrument" = "1" -a "$enable_instrument" = "0" ]; then
+    echo "ERROR: You must configure QEMU using '--with-instrument' to use the 'instrument' property in \"trace-events\"" >/dev/stderr
+    exit 1
+fi
+
 exit 0