From patchwork Wed Nov 3 19:58:35 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: 70061 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 8DB26B6EF1 for ; Thu, 4 Nov 2010 07:05:15 +1100 (EST) Received: from localhost ([127.0.0.1]:49186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDjZz-000229-TV for incoming@patchwork.ozlabs.org; Wed, 03 Nov 2010 16:05:08 -0400 Received: from [140.186.70.92] (port=56796 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDjTi-0007Gz-3q for qemu-devel@nongnu.org; Wed, 03 Nov 2010 15:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDjTY-0005V3-J7 for qemu-devel@nongnu.org; Wed, 03 Nov 2010 15:58:35 -0400 Received: from mailout-de.gmx.net ([213.165.64.22]:34016 helo=mail.gmx.net) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PDjTY-0005UT-4b for qemu-devel@nongnu.org; Wed, 03 Nov 2010 15:58:28 -0400 Received: (qmail invoked by alias); 03 Nov 2010 19:58:26 -0000 Received: from unknown (EHLO localhost) [84.88.53.92] by mail.gmx.net (mp068) with SMTP; 03 Nov 2010 20:58:26 +0100 X-Authenticated: #12333383 X-Provags-ID: V01U2FsdGVkX1/Y7zYkqRXYM4zEj1M/BNfM+tuHeGHz/JUg/JemVJ 3i3pDJeyN+kKbp To: qemu-devel@nongnu.org From: =?utf-8?b?TGx1w61z?= Date: Wed, 03 Nov 2010 20:58:35 +0100 Message-ID: <20101103195835.6430.79816.stgit@ginnungagap.bsc.es> In-Reply-To: <20101103195814.6430.3786.stgit@ginnungagap.bsc.es> References: <20101103195814.6430.3786.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 v1 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). Signed-off-by: LluĂ­s Vilanova --- 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] ( [, ] ...) "" +# [ ...] ( [, ] ...) "" # # 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 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 < +usage: $0 [] 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