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). Signed-off-by: Lluís Vilanova <vilan...@ac.upc.edu> --- Makefile | 4 ++-- simpletrace.py | 2 +- trace-events | 23 +++++++++++++++++------ tracetool | 23 ++++++++++++++++++++++- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index fec086b..1886317 100644 --- a/Makefile +++ b/Makefile @@ -108,12 +108,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 c2cf168..0f3fab5 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_]+)\(([^)]*)\)\s+"([^"]*)"') +event_re = re.compile(r'\s*(disable\s+|instrument\s+)*([a-zA-Z0-9_]+)\(([^)]*)\)\s+"([^"]*)"') def err(msg): sys.stderr.write(msg + '\n') diff --git a/trace-events b/trace-events index 4300178..3b91a1c 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 4bd264f..facb385 100755 --- a/tracetool +++ b/tracetool @@ -349,12 +349,21 @@ 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() { + # XXX: should still provide instrumentation if event is disabled? local instrument + instrument=$(get_property "$1" "instrument") + if [ "$instrument" = "1" ]; then + had_instrument="1" + return + fi local api func api=$(get_api_name "$1") @@ -404,12 +413,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 @@ -427,6 +442,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#-}" ;; @@ -443,4 +459,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