From c276b17da65b7ff01627722a1abf2b7a684c8fd8 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 12 Nov 2010 13:20:25 +0000 Subject: [PATCH] Add support for generating a systemtap tapset static probes This introduces generation of a qemu.stp/qemu-system-XXX.stp files which provides tapsets with friendly names for static probes & their arguments. Instead of probe process("qemu").mark("qemu_malloc") { printf("Malloc %d %p\n", $arg1, $arg2); } It is now possible todo probe qemu.system.i386.qemu_malloc { printf("Malloc %d %p\n", size, ptr); } There is one tapset defined per target arch, for both user and system emulators. * Makefile.target: Generate stp files for each target * tracetool: Support for generating systemtap tapsets * configure: Check for whether systemtap is available with the DTrace backend Reviewed-by: Stefan Hajnoczi Signed-off-by: Daniel P. Berrange Signed-off-by: Anthony Liguori --- Makefile.target | 29 ++++++++++- configure | 7 +++ tracetool | 126 ++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 145 insertions(+), 17 deletions(-) diff --git a/Makefile.target b/Makefile.target index 31c968c029..2800f473b7 100644 --- a/Makefile.target +++ b/Makefile.target @@ -41,7 +41,27 @@ kvm.o kvm-all.o vhost.o vhost_net.o: QEMU_CFLAGS+=$(KVM_CFLAGS) config-target.h: config-target.h-timestamp config-target.h-timestamp: config-target.mak -all: $(PROGS) +ifdef CONFIG_SYSTEMTAP_TRACE +stap: $(QEMU_PROG).stp + +ifdef CONFIG_USER_ONLY +TARGET_TYPE=user +else +TARGET_TYPE=system +endif + +$(QEMU_PROG).stp: + $(call quiet-command,sh $(SRC_PATH)/tracetool \ + --$(TRACE_BACKEND) \ + --binary $(bindir)/$(QEMU_PROG) \ + --target-arch $(TARGET_ARCH) \ + --target-type $(TARGET_TYPE) \ + --stap < $(SRC_PATH)/trace-events > $(QEMU_PROG).stp," GEN $(QEMU_PROG).stp") +else +stap: +endif + +all: $(PROGS) stap # Dummy command so that make thinks it has done something @true @@ -341,6 +361,9 @@ clean: rm -f *.o *.a *~ $(PROGS) nwfpe/*.o fpu/*.o rm -f *.d */*.d tcg/*.o ide/*.o rm -f hmp-commands.h qmp-commands.h gdbstub-xml.c +ifdef CONFIG_SYSTEMTAP_TRACE + rm -f *.stp +endif install: all ifneq ($(PROGS),) @@ -349,6 +372,10 @@ ifneq ($(STRIP),) $(STRIP) $(patsubst %,"$(DESTDIR)$(bindir)/%",$(PROGS)) endif endif +ifdef CONFIG_SYSTEMTAP_TRACE + $(INSTALL_DIR) "$(DESTDIR)$(datadir)/../systemtap/tapset" + $(INSTALL_DATA) $(QEMU_PROG).stp "$(DESTDIR)$(datadir)/../systemtap/tapset" +endif # Include automatically generated dependency files -include $(wildcard *.d */*.d) diff --git a/configure b/configure index f8dad3eb00..2917874f96 100755 --- a/configure +++ b/configure @@ -2203,6 +2203,10 @@ if test "$trace_backend" = "dtrace"; then echo exit 1 fi + trace_backend_stap="no" + if has 'stap' ; then + trace_backend_stap="yes" + fi fi ########################################## @@ -2645,6 +2649,9 @@ fi if test "$trace_backend" = "simple"; then trace_file="\"$trace_file-%u\"" fi +if test "$trace_backend" = "dtrace" -a "$trace_backend_stap" = "yes" ; then + echo "CONFIG_SYSTEMTAP_TRACE=y" >> $config_host_mak +fi echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak echo "TOOLS=$tools" >> $config_host_mak diff --git a/tracetool b/tracetool index 1ade103baf..fce491c505 100755 --- a/tracetool +++ b/tracetool @@ -23,9 +23,16 @@ Backends: --dtrace DTrace/SystemTAP backend Output formats: - -h Generate .h file - -c Generate .c file - -d Generate .d file (DTrace only) + -h Generate .h file + -c Generate .c file + -d Generate .d file (DTrace only) + --stap Generate .stp file (DTrace with SystemTAP only) + +Options: + --binary [path] Full path to QEMU binary + --target-arch [arch] QEMU emulator target arch + --target-type [type] QEMU emulator target type ('system' or 'user') + EOF exit 1 } @@ -396,6 +403,51 @@ linetod_end_dtrace() EOF } +linetostap_begin_dtrace() +{ + return +} + +linetostap_dtrace() +{ + local i arg name args arglist state + name=$(get_name "$1") + args=$(get_args "$1") + arglist=$(get_argnames "$1", "") + state=$(get_state "$1") + if [ "$state" = "0" ] ; then + name=${name##disable } + fi + + # Define prototype for probe arguments + cat <