From patchwork Thu Nov 4 22:36:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?Q?Llu=C3=ADs?= X-Patchwork-Id: 70181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 32F6BB70D5 for ; Fri, 5 Nov 2010 09:46:40 +1100 (EST) Received: from localhost ([127.0.0.1]:52530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PE8ZS-0001TK-7V for incoming@patchwork.ozlabs.org; Thu, 04 Nov 2010 18:46:14 -0400 Received: from [140.186.70.92] (port=41596 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PE8Ph-0005OJ-Mu for qemu-devel@nongnu.org; Thu, 04 Nov 2010 18:36:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PE8Pd-0002eE-0z for qemu-devel@nongnu.org; Thu, 04 Nov 2010 18:36:06 -0400 Received: from mailout-de.gmx.net ([213.165.64.22]:35260 helo=mail.gmx.net) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PE8Pc-0002e6-Io for qemu-devel@nongnu.org; Thu, 04 Nov 2010 18:36:04 -0400 Received: (qmail invoked by alias); 04 Nov 2010 22:36:02 -0000 Received: from unknown (EHLO localhost) [84.88.53.92] by mail.gmx.net (mp064) with SMTP; 04 Nov 2010 23:36:02 +0100 X-Authenticated: #12333383 X-Provags-ID: V01U2FsdGVkX1+L0Il52RKLHFBsdJJSNBuTafu5AxHSoe9n21IO6f CAsCIPwjsgUg4P To: qemu-devel@nongnu.org From: =?utf-8?b?TGx1w61z?= Date: Thu, 04 Nov 2010 23:36:25 +0100 Message-ID: <20101104223624.16785.9186.stgit@ginnungagap.bsc.es> In-Reply-To: <20101104223552.16785.84410.stgit@ginnungagap.bsc.es> References: <20101104223552.16785.84410.stgit@ginnungagap.bsc.es> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH v2 2/3] trace-instrument: let the user override events generated by 'tracetool' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- Makefile | 4 ++-- simpletrace.py | 2 +- trace-events | 23 +++++++++++++++++------ tracetool | 33 ++++++++++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 12 deletions(-) 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] ( [, ] ...) "" +# [ ...] ( [, ] ...) "" # # 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 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 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 < +usage: $0 [] 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