From patchwork Thu Aug 12 10:36:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 61591 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 D050EB70AF for ; Thu, 12 Aug 2010 23:40:55 +1000 (EST) Received: from localhost ([127.0.0.1]:37782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OjY1c-00011W-3a for incoming@patchwork.ozlabs.org; Thu, 12 Aug 2010 09:40:52 -0400 Received: from [140.186.70.92] (port=48958 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OjXzO-0007YS-S0 for qemu-devel@nongnu.org; Thu, 12 Aug 2010 09:38:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OjXxw-0003TP-Io for qemu-devel@nongnu.org; Thu, 12 Aug 2010 09:37:16 -0400 Received: from mtagate2.de.ibm.com ([195.212.17.162]:57576) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OjXxw-0003Mu-2A for qemu-devel@nongnu.org; Thu, 12 Aug 2010 09:37:04 -0400 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate2.de.ibm.com (8.13.1/8.13.1) with ESMTP id o7CAak6o029215 for ; Thu, 12 Aug 2010 10:36:46 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o7CAakWk1827030 for ; Thu, 12 Aug 2010 12:36:46 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o7CAajiH022627 for ; Thu, 12 Aug 2010 12:36:46 +0200 Received: from stefan-thinkpad.ibm.com (dev11556.de.ibm.com [9.145.242.211]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o7CAahLt022591; Thu, 12 Aug 2010 12:36:44 +0200 From: Stefan Hajnoczi To: Date: Thu, 12 Aug 2010 11:36:22 +0100 Message-Id: <1281609395-17621-2-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1281609395-17621-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1281609395-17621-1-git-send-email-stefanha@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Julien Desfossez , Stefan Hajnoczi , Prerna Saxena Subject: [Qemu-devel] [PATCH 01/14] trace: Add trace-events file for declaring trace events 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 This patch introduces the trace-events file where trace events can be declared like so: qemu_malloc(size_t size) "size %zu" qemu_free(void *ptr) "ptr %p" These trace event declarations are processed by a new tool called tracetool to generate code for the trace events. Trace event declarations are independent of the backend tracing system (LTTng User Space Tracing, ftrace markers, DTrace). The default "nop" backend generates empty trace event functions. Therefore trace events are disabled by default. The trace-events file serves two purposes: 1. Adding trace events is easy. It is not necessary to understand the details of a backend tracing system. The trace-events file is a single location where trace events can be declared without code duplication. 2. QEMU is not tightly coupled to one particular backend tracing system. In order to support tracing across QEMU host platforms and to anticipate new backend tracing systems that are currently maturing, it is important to be flexible and not tied to one system. Signed-off-by: Stefan Hajnoczi trace: Rebuild when switching trace backends Fix to ensure rebuild is properly triggered when switching trace backends using ./configure. Signed-off-by: Prerna Saxena Signed-off-by: Stefan Hajnoczi --- .gitignore | 2 + Makefile | 17 ++++- Makefile.objs | 5 ++ Makefile.target | 1 + configure | 18 ++++++ trace-events | 24 ++++++++ tracetool | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 238 insertions(+), 4 deletions(-) create mode 100644 trace-events create mode 100755 tracetool diff --git a/.gitignore b/.gitignore index ec6f89f..f3f2bb7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ config-devices.* config-all-devices.* config-host.* config-target.* +trace.h +trace.c *-softmmu *-darwin-user *-linux-user diff --git a/Makefile b/Makefile index f95cc2f..3c5e6a0 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Makefile for QEMU. -GENERATED_HEADERS = config-host.h +GENERATED_HEADERS = config-host.h trace.h ifneq ($(wildcard config-host.mak),) # Put the all: rule here so that config-host.mak can contain dependencies. @@ -104,16 +104,24 @@ ui/vnc.o: QEMU_CFLAGS += $(VNC_TLS_CFLAGS) bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS) +trace.h: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -h < $< > $@," GEN $@") + +trace.c: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -c < $< > $@," GEN $@") + +trace.o: trace.c $(GENERATED_HEADERS) + ###################################################################### qemu-img.o: qemu-img-cmds.h qemu-img.o qemu-tool.o qemu-nbd.o qemu-io.o: $(GENERATED_HEADERS) -qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(block-obj-y) $(qobject-obj-y) +qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(trace-obj-y) $(block-obj-y) $(qobject-obj-y) -qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(block-obj-y) $(qobject-obj-y) +qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(trace-obj-y) $(block-obj-y) $(qobject-obj-y) -qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(block-obj-y) $(qobject-obj-y) +qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(trace-obj-y) $(block-obj-y) $(qobject-obj-y) qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@," GEN $@") @@ -133,6 +141,7 @@ clean: rm -f *.o *.d *.a $(TOOLS) TAGS cscope.* *.pod *~ */*~ rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d rm -f qemu-img-cmds.h + rm -f trace.c trace.h $(MAKE) -C tests clean for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \ if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \ diff --git a/Makefile.objs b/Makefile.objs index 4a1eaa1..c61332d 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -265,6 +265,11 @@ libdis-$(CONFIG_S390_DIS) += s390-dis.o libdis-$(CONFIG_SH4_DIS) += sh4-dis.o libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o +###################################################################### +# trace + +trace-obj-y = trace.o + vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS) diff --git a/Makefile.target b/Makefile.target index b791492..d3f5878 100644 --- a/Makefile.target +++ b/Makefile.target @@ -310,6 +310,7 @@ obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y)) endif # CONFIG_SOFTMMU +obj-y += $(addprefix ../, $(trace-obj-y)) obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o $(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y) diff --git a/configure b/configure index a20371c..d3648b2 100755 --- a/configure +++ b/configure @@ -315,6 +315,7 @@ pkgversion="" check_utests="no" user_pie="no" zero_malloc="" +trace_backend="nop" # OS specific if check_define __linux__ ; then @@ -517,6 +518,8 @@ for opt do ;; --target-list=*) target_list="$optarg" ;; + --trace-backend=*) trace_backend="$optarg" + ;; --enable-gprof) gprof="yes" ;; --static) @@ -895,6 +898,7 @@ echo " --enable-docs enable documentation build" echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" +echo " --trace-backend=B Trace backend nop" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1 @@ -2057,6 +2061,18 @@ if compile_prog "" "" ; then fdatasync=yes fi +########################################## +# check if trace backend exists + +sh "$source_path/tracetool" "--$trace_backend" --check-backend > /dev/null 2> /dev/null +if test "$?" -ne 0 ; then + echo + echo "Error: invalid trace backend" + echo "Please choose a supported trace backend." + echo + exit 1 +fi + # End of CC checks # After here, no more $cc or $ld runs @@ -2187,6 +2203,7 @@ echo "preadv support $preadv" echo "fdatasync $fdatasync" echo "uuid support $uuid" echo "vhost-net support $vhost_net" +echo "Trace backend $trace_backend" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support" @@ -2448,6 +2465,7 @@ bsd) ;; esac +echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak echo "TOOLS=$tools" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak diff --git a/trace-events b/trace-events new file mode 100644 index 0000000..a37d3cc --- /dev/null +++ b/trace-events @@ -0,0 +1,24 @@ +# Trace events for debugging and performance instrumentation +# +# This file is processed by the tracetool script during the build. +# +# To add a new trace event: +# +# 1. Choose a name for the trace event. Declare its arguments and format +# string. +# +# 2. Call the trace event from code using trace_##name, e.g. multiwrite_cb() -> +# trace_multiwrite_cb(). The source file must #include "trace.h". +# +# Format of a trace event: +# +# ( [, ] ...) "" +# +# Example: qemu_malloc(size_t size) "size %zu" +# +# 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. diff --git a/tracetool b/tracetool new file mode 100755 index 0000000..86b6446 --- /dev/null +++ b/tracetool @@ -0,0 +1,175 @@ +#!/bin/sh +# +# Code generator for trace events +# +# Copyright IBM, Corp. 2010 +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. + +# Disable pathname expansion, makes processing text with '*' characters simpler +set -f + +usage() +{ + cat >&2 <