Skip to contentSkip to conversation

Add support for SystemTAP and DTrace tracing backends

PATCH In review Daniel P. Berrange 3 participants 7 messages Nov 8, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Add support for SystemTAP and DTrace tracing backends

This is an update of the SystemTAP/DTrace patches previously sent

http://lists.gnu.org/archive/html/qemu-devel/2010-10/msg01451.html

The patch is now split into two pieces.

The first patch contains the generic DTrace tracing backend support.

The second patch contains additional pieces for SystemTAP to generate a tapset for each of the qemu-system-XXX binaries, to simplify life for admins wanting to use the tracing backend. This addresses the problem in previous versions of the patch where the tapset only worked for /usr/bin/qemu and no other binaries. Unfortunately SystemTAP does not allow for use of wildcards, so it was neccessary to go for a separate tapset file per emulator binary.

Regards,
Daniel

#1 lore raw

PATCH 1/2 Add a DTrace tracing backend targetted for SystemTAP compatability

From: Daniel P. Berrange <[email protected]>

This introduces a new tracing backend that targets the SystemTAP implementation of DTrace userspace tracing. The core functionality should be applicable and standard across any DTrace implementation on Solaris, OS-X, *BSD, but the Makefile rules will likely need some small additional changes to cope with OS specific build requirements.

This backend builds a little differently from the other tracing backends. Specifically there is no 'trace.c' file, because the 'dtrace' command line tool generates a '.o' file directly from the dtrace probe definition file. The probe definition is usually named with a '.d' extension but QEMU uses '.d' files for its external makefile dependancy tracking, so this uses '.dtrace' as the extension for the probe definition file.

The 'tracetool' program gains the ability to generate a trace.h file for DTrace, and also to generate the trace.d file containing the dtrace probe definition.

Example usage of a dtrace probe in systemtap looks like:

  probe process("qemu").mark("qemu_malloc") {
    printf("Malloc %d %p\n", $arg1, $arg2);
  }

* .gitignore: Ignore trace-dtrace.*
* Makefile: Extra rules for generating DTrace files
* Makefile.obj: Don't build trace.o for DTrace, use trace-dtrace.o generated by 'dtrace' instead
* tracetool: Support for generating DTrace data files

---
 .gitignore    |    2 +
 Makefile      |   24 ++++++++++++
 Makefile.objs |    4 ++
 configure     |   14 ++++++-
 tracetool     |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 5 files changed, 149 insertions(+), 11 deletions(-)
.gitignore +2 -0
index a43e4d1..3efb4ec 100644
@@ -4,6 +4,8 @@ config-host.*
 config-target.*
 trace.h
 trace.c
+trace-dtrace.h
+trace-dtrace.dtrace
 *-timestamp
 *-softmmu
 *-darwin-user
Makefile +24 -0
index 02698e9..384bf72 100644
@@ -1,6 +1,10 @@
 # Makefile for QEMU.
 
 GENERATED_HEADERS = config-host.h trace.h qemu-options.def
+GENERATED_HEADERS = config-host.h trace.h
+ifeq ($(TRACE_BACKEND),dtrace)
+GENERATED_HEADERS += trace-dtrace.h
+endif
 
 ifneq ($(wildcard config-host.mak),)
 # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -108,7 +112,11 @@ ui/vnc.o: QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
 
 bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS)
 
+ifeq ($(TRACE_BACKEND),dtrace)
+trace.h: trace.h-timestamp trace-dtrace.h
+else
 trace.h: trace.h-timestamp
+endif
 trace.h-timestamp: $(SRC_PATH)/trace-events config-host.mak
 	$(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -h < $< > $@,"  GEN   trace.h")
 	@cmp -s $@ trace.h || cp $@ trace.h
@@ -120,6 +128,20 @@ trace.c-timestamp: $(SRC_PATH)/trace-events config-host.mak
 
 trace.o: trace.c $(GENERATED_HEADERS)
 
+trace-dtrace.h: trace-dtrace.dtrace
+	$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   trace-dtrace.h")
+
+# Normal practice is to name DTrace probe file with a '.d' extension
+# but that gets picked up by QEMU's Makefile as an external dependancy
+# rule file. So we use '.dtrace' instead
+trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
+trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events config-host.mak
+	$(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -d < $< > $@,"  GEN   trace-dtrace.dtrace")
+	@cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
+
+trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
+	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN trace-dtrace.o")
+
 simpletrace.o: simpletrace.c $(GENERATED_HEADERS)
 
 version.o: $(SRC_PATH)/version.rc config-host.mak
@@ -157,6 +179,8 @@ clean:
 	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 trace.c-timestamp trace.h-timestamp
+	rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp
+	rm -f trace-dtrace.h trace-dtrace.h-timestamp
 	$(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; \
Makefile.objs +4 -0
index faf485e..84fc80e 100644
@@ -285,11 +285,15 @@ libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o
 ######################################################################
 # trace
 
+ifeq ($(TRACE_BACKEND),dtrace)
+trace-obj-y = trace-dtrace.o
+else
 trace-obj-y = trace.o
 ifeq ($(TRACE_BACKEND),simple)
 trace-obj-y += simpletrace.o
 user-obj-y += qemu-timer-common.o
 endif
+endif
 
 vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
configure +13 -1
index 7025d2b..f8dad3e 100755
@@ -929,7 +929,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 simple ust"
+echo "  --trace-backend=B        Trace backend nop simple ust dtrace"
 echo "  --trace-file=NAME        Full PATH,NAME of file to store traces"
 echo "                           Default:trace-<pid>"
 echo "  --disable-spice          disable spice"
@@ -2193,6 +2193,18 @@ EOF
     exit 1
   fi
 fi
+
+##########################################
+# For 'dtrace' backend, test if 'dtrace' command is present
+if test "$trace_backend" = "dtrace"; then
+  if ! has 'dtrace' ; then
+    echo
+    echo "Error: dtrace command is not found in PATH $PATH"
+    echo
+    exit 1
+  fi
+fi
+
 ##########################################
 # End of CC checks
 # After here, no more $cc or $ld runs
tracetool +106 -10

189 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] Add a DTrace tracing backend targetted for SystemTAP compatability

Makefile line 7

Quoted 12 lines · Daniel P. Berrange
Makefile +0 -0
index 02698e9..384bf72 100644
@@ -1,6 +1,10 @@
  # Makefile for QEMU.
 

 GENERATED_HEADERS = config-host.h trace.h qemu-options.def

Makefile +4 -0
+GENERATED_HEADERS = config-host.h trace.h
+ifeq ($(TRACE_BACKEND),dtrace)
+GENERATED_HEADERS += trace-dtrace.h
+endif

What happened to qemu-options.def? GENERATED_HEADERS is defined twice, the first line should probably be deleted.

Looks good otherwise.

Stefan

#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] Add a DTrace tracing backend targetted for SystemTAP compatability

Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines · Daniel P. Berrange
Makefile +0 -0
index 02698e9..384bf72 100644
@@ -1,6 +1,10 @@
  # Makefile for QEMU.
 
Quoted 8 lines

Makefile line 7

Quoted 5 lines

 GENERATED_HEADERS = config-host.h trace.h qemu-options.def

Makefile +4 -0
+GENERATED_HEADERS = config-host.h trace.h
+ifeq ($(TRACE_BACKEND),dtrace)
+GENERATED_HEADERS += trace-dtrace.h
+endif

What happened to qemu-options.def? GENERATED_HEADERS is defined twice, the first line should probably be deleted.

Oh, the loss of qemu-options.def is a rebase/merge error. GENERATED_HEADERS isn't defined twice, because the second line is using += to append to the first definition.

Regards,
Daniel

Signature · 4 lines
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] Add a DTrace tracing backend targetted for SystemTAP compatability

Quoted 18 lines · Daniel P. Berrange
Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines · Daniel P. Berrange
Makefile +0 -0
index 02698e9..384bf72 100644
@@ -1,6 +1,10 @@
  # Makefile for QEMU.
 
Quoted 8 lines

Makefile line 7

Quoted 5 lines

 GENERATED_HEADERS = config-host.h trace.h qemu-options.def

Makefile +4 -0
+GENERATED_HEADERS = config-host.h trace.h
+ifeq ($(TRACE_BACKEND),dtrace)
+GENERATED_HEADERS += trace-dtrace.h
+endif

What happened to qemu-options.def?  GENERATED_HEADERS is defined twice, the first line should probably be deleted.

Quoted 3 lines

Oh, the loss of qemu-options.def is a rebase/merge error. GENERATED_HEADERS isn't defined twice, because the second line is using += to append to the first definition.

Ah, it's the merge error I was referring to:

@@ -1,6 +1,10 @@
# Makefile for QEMU.

GENERATED_HEADERS = config-host.h trace.h qemu-options.def
+GENERATED_HEADERS = config-host.h trace.h

Stefan

#5 lore raw

PATCH 2/2 Add support for generating a systemtap tapset static probes

In reply to Daniel P. Berrange

From: Daniel P. Berrange <[email protected]>

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.

* Makefile: Generate a qemu.stp file for systemtap
* tracetool: Support for generating systemtap tapsets

---
 Makefile.target |   19 +++++++++++-
 configure       |    7 ++++
 tracetool       |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+), 1 deletions(-)
Makefile.target +18 -1
index 91e6e74..a5e6410 100644
@@ -40,7 +40,20 @@ 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
+trace: $(QEMU_PROG).stp
+
+$(QEMU_PROG).stp:
+	$(call quiet-command,sh $(SRC_PATH)/tracetool \
+		--$(TRACE_BACKEND) \
+		--bindir $(bindir) \
+		--target $(TARGET_ARCH) \
+		-s < $(SRC_PATH)/trace-events > $(QEMU_PROG).stp,"  GEN   $(QEMU_PROG).stp")
+else
+trace:
+endif
+
+all: $(PROGS) trace
 
 # Dummy command so that make thinks it has done something
 	@true
@@ -348,6 +361,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)
configure +7 -0
index f8dad3e..e560f87 100755
@@ -2192,6 +2192,10 @@ EOF
     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
tracetool +92 -0

120 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] Add support for generating a systemtap tapset static probes

tracetool linetod_end_dtrace() · line 406

Quoted 12 lines · Daniel P. Berrange
tracetool +8 -0
@@ -390,6 +396,54 @@ linetod_end_dtrace()
 EOF
 }
 
+linetos_begin_dtrace()
+{
+    return
+}
+
+linetos_dtrace()
+{
+    local name args arglist state

Missing binary, i, and arg.

Quoted 4 lines
tracetool +4 -0
+    name=$(get_name "$1")
+    args=$(get_args "$1")
+    arglist=$(get_argnames "$1", "")
+    state=$(get_state "$1")

tracetool linetod_end_dtrace() · line 420

Quoted 10 lines
tracetool +10 -0
+    if [ "$state" = "0" ] ; then
+        name=${name##disable }
+    fi
+
+    if [ "$target" = "i386" ]
+    then
+      binary="qemu"
+    else
+      binary="qemu-system-$target"
+    fi

Perhaps we should just pass in the binary name to avoid hardcoding "qemu" and "qemu-system-$target" here. If possible, let's make SystemTap also work for userspace targets, not just for full-system softmmu targets.

Quoted 30 lines
tracetool +26 -0
+
+    # Define prototype for probe arguments
+    cat <<EOF
+probe qemu.system.$target.$name = process("$bindir/$binary").mark("$name")
+{
+EOF
+
+    i=1
+    for arg in $arglist
+    do
+        cat <<EOF
+  $arg = \$arg$i;
+EOF
+       i="$((i+1))"
+    done
+
+    cat <<EOF
+}
+EOF
+}
+
+linetos_end_dtrace()
+{
+    return
+}
+
 # Process stdin by calling begin, line, and end functions for the backend
 convert()
 {

tracetool tracetod() · line 512

Quoted 4 lines
tracetool +1 -0
@@ -455,6 +509,24 @@ tracetod()
    convert d
 }
 
+tracetos()

How about using 'stap' instead of 's' so it's clear we're not generating assembly?

Stefan