All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <dan@berrange.com>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrange" <dan@berrange.com>
Subject: [Qemu-devel] [PATCH 2/2] Add support for generating a systemtap tapset static probes
Date: Mon,  8 Nov 2010 11:33:04 +0000	[thread overview]
Message-ID: <1289215984-9484-3-git-send-email-dan@berrange.com> (raw)
In-Reply-To: <1289215984-9484-1-git-send-email-dan@berrange.com>

From: Daniel P. Berrange <berrange@redhat.com>

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

Signed-off-by: Daniel P. Berrange <dan@berrange.com>
---
 Makefile.target |   19 +++++++++++-
 configure       |    7 ++++
 tracetool       |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+), 1 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 91e6e74..a5e6410 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -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)
diff --git a/configure b/configure
index f8dad3e..e560f87 100755
--- a/configure
+++ b/configure
@@ -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
diff --git a/tracetool b/tracetool
index 5b6636a..d797ab7 100755
--- a/tracetool
+++ b/tracetool
@@ -26,6 +26,12 @@ Output formats:
   -h    Generate .h file
   -c    Generate .c file
   -d    Generate .d file (DTrace only)
+  -s    Generate .stp file (DTrace with SystemTAP only)
+
+Options:
+  --bindir [bindir]  QEMU binary install location
+  --target [arch]    QEMU target architecture
+
 EOF
     exit 1
 }
@@ -390,6 +396,54 @@ linetod_end_dtrace()
 EOF
 }
 
+linetos_begin_dtrace()
+{
+    return
+}
+
+linetos_dtrace()
+{
+    local 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
+
+    if [ "$target" = "i386" ]
+    then
+      binary="qemu"
+    else
+      binary="qemu-system-$target"
+    fi
+
+    # 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()
 {
@@ -455,6 +509,24 @@ tracetod()
     convert d
 }
 
+tracetos()
+{
+    if [ $backend != "dtrace" ]; then
+       echo "SystemTAP tapset generator not applicable to $backend backend"
+       exit 1
+    fi
+    if [ -z "$target" ]; then
+       echo "--target is required for SystemTAP tapset generator"
+       exit 1
+    fi
+    if [ -z "$bindir" ]; then
+       echo "--bindir is required for SystemTAP tapset generator"
+       exit 1
+    fi
+    echo "/* This file is autogenerated by tracetool, do not edit. */"
+    convert s
+}
+
 # Choose backend
 case "$1" in
 "--nop" | "--simple" | "--ust" | "--dtrace") backend="${1#--}" ;;
@@ -462,10 +534,30 @@ case "$1" in
 esac
 shift
 
+bindir=
+case "$1" in
+  "--bindir")
+    bindir=$2
+    shift
+    shift
+    ;;
+esac
+
+target=
+case "$1" in
+  "--target")
+    target=$2
+    shift
+    shift
+    ;;
+esac
+
+
 case "$1" in
 "-h") tracetoh ;;
 "-c") tracetoc ;;
 "-d") tracetod ;;
+"-s") tracetos ;;
 "--check-backend") exit 0 ;; # used by ./configure to test for backend
 *) usage ;;
 esac
-- 
1.7.2.3

  parent reply	other threads:[~2010-11-08 11:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-08 11:33 [Qemu-devel] [PATCH 0/2] Add support for SystemTAP and DTrace tracing backends Daniel P. Berrange
2010-11-08 11:33 ` [Qemu-devel] [PATCH 1/2] Add a DTrace tracing backend targetted for SystemTAP compatability Daniel P. Berrange
2010-11-08 16:52   ` Stefan Hajnoczi
2010-11-08 16:57     ` Daniel P. Berrange
2010-11-08 19:29       ` Stefan Hajnoczi
2010-11-08 11:33 ` Daniel P. Berrange [this message]
2010-11-08 21:24   ` [Qemu-devel] [PATCH 2/2] Add support for generating a systemtap tapset static probes Stefan Hajnoczi
  -- strict thread matches above, loose matches on Subject: below --
2010-11-08 19:33 [Qemu-devel] [PATCH 0/2] Add support for SystemTAP and DTrace tracing backends (v5) Daniel P. Berrange
2010-11-08 19:33 ` [Qemu-devel] [PATCH 2/2] Add support for generating a systemtap tapset static probes Daniel P. Berrange
2010-11-12 13:20 [Qemu-devel] Add support for SystemTAP and DTrace tracing backends (v6) Daniel P. Berrange
2010-11-12 13:20 ` [Qemu-devel] [PATCH 2/2] Add support for generating a systemtap tapset static probes Daniel P. Berrange
2010-11-12 13:53   ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1289215984-9484-3-git-send-email-dan@berrange.com \
    --to=dan@berrange.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.