aboutsummaryrefslogtreecommitdiff
path: root/tracetool
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2010-11-08 19:33:07 +0000
committerAnthony Liguori <aliguori@us.ibm.com>2010-11-16 09:31:18 -0600
commit4addb1127f6327c7ebcbd150a6b589e7677adc92 (patch)
tree543364846e74df2531f4a1f80a456e3291fafeed /tracetool
parent9696846600cac4bd0dfd6835e45e69d25ec2b11e (diff)
downloadqemu-4addb1127f6327c7ebcbd150a6b589e7677adc92.zip
qemu-4addb1127f6327c7ebcbd150a6b589e7677adc92.tar.gz
qemu-4addb1127f6327c7ebcbd150a6b589e7677adc92.tar.bz2
Add a DTrace tracing backend targetted for SystemTAP compatability
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 Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'tracetool')
-rwxr-xr-xtracetool116
1 files changed, 106 insertions, 10 deletions
diff --git a/tracetool b/tracetool
index 7010858..5b6636a 100755
--- a/tracetool
+++ b/tracetool
@@ -20,10 +20,12 @@ Backends:
--nop Tracing disabled
--simple Simple built-in backend
--ust LTTng User Space Tracing backend
+ --dtrace DTrace/SystemTAP backend
Output formats:
-h Generate .h file
-c Generate .c file
+ -d Generate .d file (DTrace only)
EOF
exit 1
}
@@ -46,8 +48,9 @@ get_args()
# Get the argument name list of a trace event
get_argnames()
{
- local nfields field name
+ local nfields field name sep
nfields=0
+ sep="$2"
for field in $(get_args "$1"); do
nfields=$((nfields + 1))
@@ -58,7 +61,7 @@ get_argnames()
name=${field%,}
test "$field" = "$name" && continue
- printf "%s" "$name, "
+ printf "%s%s " $name $sep
done
# Last argument name
@@ -73,7 +76,7 @@ get_argc()
{
local name argc
argc=0
- for name in $(get_argnames "$1"); do
+ for name in $(get_argnames "$1", ","); do
argc=$((argc + 1))
done
echo $argc
@@ -154,7 +157,7 @@ EOF
cast_args_to_uint64_t()
{
local arg
- for arg in $(get_argnames "$1"); do
+ for arg in $(get_argnames "$1", ","); do
printf "%s" "(uint64_t)(uintptr_t)$arg"
done
}
@@ -247,7 +250,7 @@ linetoh_ust()
local name args argnames
name=$(get_name "$1")
args=$(get_args "$1")
- argnames=$(get_argnames "$1")
+ argnames=$(get_argnames "$1", ",")
cat <<EOF
DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames));
@@ -274,7 +277,7 @@ linetoc_ust()
local name args argnames fmt
name=$(get_name "$1")
args=$(get_args "$1")
- argnames=$(get_argnames "$1")
+ argnames=$(get_argnames "$1", ",")
fmt=$(get_fmt "$1")
cat <<EOF
@@ -306,6 +309,87 @@ EOF
echo "}"
}
+linetoh_begin_dtrace()
+{
+ cat <<EOF
+#include "trace-dtrace.h"
+EOF
+}
+
+linetoh_dtrace()
+{
+ local name args argnames state nameupper
+ name=$(get_name "$1")
+ args=$(get_args "$1")
+ argnames=$(get_argnames "$1", ",")
+ state=$(get_state "$1")
+ if [ "$state" = "0" ] ; then
+ name=${name##disable }
+ fi
+
+ nameupper=`echo $name | tr '[:lower:]' '[:upper:]'`
+
+ # Define an empty function for the trace event
+ cat <<EOF
+static inline void trace_$name($args) {
+ if (QEMU_${nameupper}_ENABLED()) {
+ QEMU_${nameupper}($argnames);
+ }
+}
+EOF
+}
+
+linetoh_end_dtrace()
+{
+ return
+}
+
+linetoc_begin_dtrace()
+{
+ return
+}
+
+linetoc_dtrace()
+{
+ # No need for function definitions in dtrace backend
+ return
+}
+
+linetoc_end_dtrace()
+{
+ return
+}
+
+linetod_begin_dtrace()
+{
+ cat <<EOF
+provider qemu {
+EOF
+}
+
+linetod_dtrace()
+{
+ local name args state
+ name=$(get_name "$1")
+ args=$(get_args "$1")
+ state=$(get_state "$1")
+ if [ "$state" = "0" ] ; then
+ name=${name##disable }
+ fi
+
+ # Define prototype for probe arguments
+ cat <<EOF
+ probe $name($args);
+EOF
+}
+
+linetod_end_dtrace()
+{
+ cat <<EOF
+};
+EOF
+}
+
# Process stdin by calling begin, line, and end functions for the backend
convert()
{
@@ -324,9 +408,10 @@ convert()
disable=${str%%disable *}
echo
if test -z "$disable"; then
- # Pass the disabled state as an arg to lineto$1_simple().
- # For all other cases, call lineto$1_nop()
- if [ $backend = "simple" ]; then
+ # Pass the disabled state as an arg for the simple
+ # or DTrace backends which handle it dynamically.
+ # For all other backends, call lineto$1_nop()
+ if [ $backend = "simple" -o "$backend" = "dtrace" ]; then
"$process_line" "$str"
else
"lineto$1_nop" "${str##disable }"
@@ -360,9 +445,19 @@ tracetoc()
convert c
}
+tracetod()
+{
+ if [ $backend != "dtrace" ]; then
+ echo "DTrace probe generator not applicable to $backend backend"
+ exit 1
+ fi
+ echo "/* This file is autogenerated by tracetool, do not edit. */"
+ convert d
+}
+
# Choose backend
case "$1" in
-"--nop" | "--simple" | "--ust") backend="${1#--}" ;;
+"--nop" | "--simple" | "--ust" | "--dtrace") backend="${1#--}" ;;
*) usage ;;
esac
shift
@@ -370,6 +465,7 @@ shift
case "$1" in
"-h") tracetoh ;;
"-c") tracetoc ;;
+"-d") tracetod ;;
"--check-backend") exit 0 ;; # used by ./configure to test for backend
*) usage ;;
esac