diff --git a/Makefile.pre.in b/Makefile.pre.in
index 8451445..ac55105 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -544,6 +544,11 @@ Python/importdl.o: $(srcdir)/Python/importdl.c
Objects/unicodectype.o: $(srcdir)/Objects/unicodectype.c \
$(srcdir)/Objects/unicodetype_db.h
+Python/pydtrace.h: $(srcdir)/Python/pydtrace.d
+ dtrace -o $@ $(DFLAGS) -C -h -s $(srcdir)/Python/pydtrace.d
+
+Python/ceval.o: Python/pydtrace.h
+
STRINGLIB_HEADERS= \
$(srcdir)/Include/bytes_methods.h \
$(srcdir)/Objects/stringlib/count.h \
diff --git a/Python/ceval.c b/Python/ceval.c
index 6eef7ef..43284b9 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -19,6 +19,38 @@
#include
+#ifdef ENABLE_DTRACE
+
+#include "pydtrace.h"
+
+#define PYTHON_DTRACE_ENTRY(py_frame) \
+ if (PYTHON_FUNCTION_ENTRY_ENABLED()) { \
+ char *fl_name = ((PyStringObject *)py_frame->f_code-> \
+ co_filename)->ob_sval; \
+ char *fn_name = ((PyStringObject *)py_frame->f_code-> \
+ co_name)->ob_sval; \
+ \
+ PYTHON_FUNCTION_ENTRY(fl_name, fn_name, py_frame->f_lineno, \
+ py_frame->f_code->co_argcount); \
+ }
+
+#define PYTHON_DTRACE_RETURN(py_frame, object) \
+ if (PYTHON_FUNCTION_RETURN_ENABLED()) { \
+ char *fl_name = ((PyStringObject *)py_frame->f_code-> \
+ co_filename)->ob_sval; \
+ char *fn_name = ((PyStringObject *)py_frame->f_code-> \
+ co_name)->ob_sval; \
+ \
+ PYTHON_FUNCTION_RETURN(fl_name, fn_name, object); \
+ }
+
+#else
+
+#define PYTHON_DTRACE_ENTRY(py_frame) /* nothing */
+#define PYTHON_DTRACE_RETURN(py_frame, object) /* nothing */
+
+#endif /* ENABLE_DTRACE */
+
#ifndef WITH_TSC
#define READ_TIMESTAMP(var)
@@ -2364,6 +2396,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
PyObject **sp;
PCALL(PCALL_ALL);
sp = stack_pointer;
+
+ PYTHON_DTRACE_ENTRY(f);
+
#ifdef WITH_TSC
x = call_function(&sp, oparg, &intr0, &intr1);
#else
@@ -2371,8 +2406,13 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
#endif
stack_pointer = sp;
PUSH(x);
- if (x != NULL)
+ if (x != NULL) {
+ PYTHON_DTRACE_RETURN(f, (char *)x->ob_type->tp_name);
continue;
+ }
+
+ PYTHON_DTRACE_RETURN(f, "error");
+
break;
}
diff --git a/Python/pydtrace.d b/Python/pydtrace.d
new file mode 100644
index 0000000..5768692
--- /dev/null
+++ b/Python/pydtrace.d
@@ -0,0 +1,37 @@
+
+/* Python dtrace provider */
+
+provider python {
+ probe function__entry(char *, char *, int, int);
+ probe function__return(char *, char *, char *);
+};
+
+/*
+
+ f ==> PyFrameObject from compile.h
+ f_code ==> PyCodeObject from frameobject.h
+
+Entry
+ 1. char * (file name, f->f_code->co_filename->ob_sval)
+ 2. char * (function name, f->f_code->co_name->ob_sval)
+ 3. int (line number, f->f_lineno)
+ 4. int (argument count, f->f_code->co_argcount)
+
+Return
+ 1. char * (file name, f->f_code->co_filename->ob_sval)
+ 2. char * (function name, f->f_code->co_name->ob_sval)
+ 3. char * (object type char * , object->ob_type->tp_name)
+
+*/
+
+
+
+/*
+ The definitions for these below are here:
+ http://docs.sun.com/app/docs/doc/817-6223/6mlkidlnp?a=view
+*/
+#pragma D attributes unstable/unstable/Common provider python provider
+#pragma D attributes unstable/unstable/Common provider python module
+#pragma D attributes unstable/unstable/Common provider python function
+#pragma D attributes unstable/unstable/Common provider python name
+#pragma D attributes unstable/unstable/Common provider python args
diff --git a/configure.in b/configure.in
index e450b06..8c52f29 100644
--- a/configure.in
+++ b/configure.in
@@ -3281,6 +3281,28 @@ else
AC_MSG_RESULT($PY_UNICODE_TYPE)
fi
+# Check if dtrace should be enabled
+
+AC_MSG_CHECKING([if dtrace should be enabled])
+
+AC_CHECK_HEADER([sys/sdt.h], [HAVE_SDT_H="yes"])
+
+AC_ARG_ENABLE(dtrace,
+ [ --enable-dtrace enable DTrace support.],
+ [enable_dtrace=$enableval])
+ if test "$enable_dtrace" == "yes" -a "$HAVE_SDT_H" == "yes"; then
+ EXTRA_CFLAGS="$EXTRA_CFLAGS -DENABLE_DTRACE"
+ if test -x "/usr/bin/isainfo"; then
+ arch=`/usr/bin/isainfo -n | cut -b1-5`
+ if test "$arch" == "sparc"; then
+ EXTRA_CFLAGS="-DENABLE_DTRACE -xarch=v7"
+ fi
+ fi
+ else
+ AC_MSG_ERROR([sys/sdt.h was not found])
+ fi
+AC_SUBST(EXTRA_CFLAGS)
+
# check for endianness
AC_C_BIGENDIAN