Blame SOURCES/00055-systemtap.patch

ae2451
diff -up Python-2.7rc1/configure.ac.systemtap Python-2.7rc1/configure.ac
ae2451
--- Python-2.7rc1/configure.ac.systemtap	2010-06-06 10:53:15.514975012 -0400
ae2451
+++ Python-2.7rc1/configure.ac	2010-06-06 10:53:15.520974361 -0400
ae2451
@@ -2616,6 +2616,38 @@ if test "$with_valgrind" != no; then
ae2451
     )
ae2451
 fi
ae2451
 
ae2451
+# Check for dtrace support
ae2451
+AC_MSG_CHECKING(for --with-dtrace)
ae2451
+AC_ARG_WITH(dtrace,
ae2451
+            AC_HELP_STRING(--with(out)-dtrace, disable/enable dtrace support))
ae2451
+
ae2451
+if test ! -z "$with_dtrace"
ae2451
+then
ae2451
+    if dtrace -G -o /dev/null -s $srcdir/Include/pydtrace.d 2>/dev/null
ae2451
+    then
ae2451
+	AC_DEFINE(WITH_DTRACE, 1, 
ae2451
+	 [Define if you want to compile in Dtrace support])
ae2451
+	with_dtrace="Sun"
ae2451
+	DTRACEOBJS="Python/dtrace.o"
ae2451
+	DTRADEHDRS=""
ae2451
+    elif dtrace -h -o /dev/null -s $srcdir/Include/pydtrace.d
ae2451
+    then
ae2451
+	AC_DEFINE(WITH_DTRACE, 1, 
ae2451
+	 [Define if you want to compile in Dtrace support])
ae2451
+	with_dtrace="Apple"
ae2451
+	DTRACEOBJS=""
ae2451
+	DTRADEHDRS="pydtrace.h"
ae2451
+    else
ae2451
+	with_dtrace="no"
ae2451
+    fi
ae2451
+else
ae2451
+    with_dtrace="no"
ae2451
+fi
ae2451
+
ae2451
+AC_MSG_RESULT($with_dtrace)
ae2451
+AC_SUBST(DTRACEOBJS)
ae2451
+AC_SUBST(DTRACEHDRS)
ae2451
+
ae2451
 # Check for --with-wctype-functions
ae2451
 AC_MSG_CHECKING(for --with-wctype-functions)
ae2451
 AC_ARG_WITH(wctype-functions, 
ae2451
diff -up Python-2.7rc1/Include/pydtrace.d.systemtap Python-2.7rc1/Include/pydtrace.d
ae2451
--- Python-2.7rc1/Include/pydtrace.d.systemtap	2010-06-06 10:53:15.520974361 -0400
ae2451
+++ Python-2.7rc1/Include/pydtrace.d	2010-06-06 10:53:15.520974361 -0400
ae2451
@@ -0,0 +1,10 @@
ae2451
+provider python {
ae2451
+	probe function__entry(const char *, const char *, int);
ae2451
+	probe function__return(const char *, const char *, int);
ae2451
+};
ae2451
+
ae2451
+#pragma D attributes Evolving/Evolving/Common provider python provider
ae2451
+#pragma D attributes Private/Private/Common provider python module
ae2451
+#pragma D attributes Private/Private/Common provider python function
ae2451
+#pragma D attributes Evolving/Evolving/Common provider python name
ae2451
+#pragma D attributes Evolving/Evolving/Common provider python args
ae2451
diff -up Python-2.7rc1/Makefile.pre.in.systemtap Python-2.7rc1/Makefile.pre.in
ae2451
--- Python-2.7rc1/Makefile.pre.in.systemtap	2010-06-06 10:53:15.488978775 -0400
ae2451
+++ Python-2.7rc1/Makefile.pre.in	2010-06-06 11:05:30.411100568 -0400
ae2451
@@ -298,6 +298,7 @@ PYTHON_OBJS=	\
ae2451
 		Python/formatter_unicode.o \
ae2451
 		Python/formatter_string.o \
ae2451
 		Python/$(DYNLOADFILE) \
ae2451
+		@DTRACEOBJS@ \
ae2451
 		$(LIBOBJS) \
ae2451
 		$(MACHDEP_OBJS) \
ae2451
 		$(THREADOBJ)
ae2451
@@ -599,6 +600,18 @@ Python/formatter_unicode.o: $(srcdir)/Py
ae2451
 Python/formatter_string.o: $(srcdir)/Python/formatter_string.c \
ae2451
 				$(STRINGLIB_HEADERS)
ae2451
 
ae2451
+# Only needed with --with-dtrace
ae2451
+buildinclude:
ae2451
+	mkdir -p Include
ae2451
+
ae2451
+Include/pydtrace.h: buildinclude $(srcdir)/Include/pydtrace.d
ae2451
+	dtrace -o $@ $(DFLAGS) -C -h -s $(srcdir)/Include/pydtrace.d
ae2451
+
ae2451
+Python/ceval.o: Include/pydtrace.h
ae2451
+
ae2451
+Python/dtrace.o: buildinclude $(srcdir)/Include/pydtrace.d Python/ceval.o
ae2451
+	dtrace -o $@ $(DFLAGS) -C -G -s $(srcdir)/Include/pydtrace.d Python/ceval.o
ae2451
+
ae2451
 ############################################################################
ae2451
 # Header files
ae2451
 
ae2451
@@ -1251,7 +1264,7 @@ Python/thread.o: @THREADHEADERS@
ae2451
 .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
ae2451
 .PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
ae2451
 .PHONY: frameworkaltinstallunixtools recheck autoconf clean clobber distclean
ae2451
-.PHONY: smelly funny patchcheck touch altmaninstall
ae2451
+.PHONY: smelly funny patchcheck touch altmaninstall buildinclude
ae2451
 .PHONY: gdbhooks
ae2451
 
ae2451
 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
ae2451
diff -up Python-2.7rc1/pyconfig.h.in.systemtap Python-2.7rc1/pyconfig.h.in
ae2451
--- Python-2.7rc1/pyconfig.h.in.systemtap	2010-05-08 07:04:18.000000000 -0400
ae2451
+++ Python-2.7rc1/pyconfig.h.in	2010-06-06 10:53:15.521974070 -0400
ae2451
@@ -1074,6 +1074,9 @@
ae2451
 /* Define if you want documentation strings in extension modules */
ae2451
 #undef WITH_DOC_STRINGS
ae2451
 
ae2451
+/* Define if you want to compile in Dtrace support */
ae2451
+#undef WITH_DTRACE
ae2451
+
ae2451
 /* Define if you want to use the new-style (Openstep, Rhapsody, MacOS) dynamic
ae2451
    linker (dyld) instead of the old-style (NextStep) dynamic linker (rld).
ae2451
    Dyld is necessary to support frameworks. */
ae2451
diff -up Python-2.7rc1/Python/ceval.c.systemtap Python-2.7rc1/Python/ceval.c
ae2451
--- Python-2.7rc1/Python/ceval.c.systemtap	2010-05-09 10:46:46.000000000 -0400
ae2451
+++ Python-2.7rc1/Python/ceval.c	2010-06-06 11:08:40.683100500 -0400
ae2451
@@ -19,6 +19,10 @@
ae2451
 
ae2451
 #include <ctype.h>
ae2451
 
ae2451
+#ifdef WITH_DTRACE
ae2451
+#include "pydtrace.h"
ae2451
+#endif
ae2451
+
ae2451
 #ifndef WITH_TSC
ae2451
 
ae2451
 #define READ_TIMESTAMP(var)
ae2451
@@ -671,6 +675,55 @@ PyEval_EvalCode(PyCodeObject *co, PyObje
ae2451
                       NULL);
ae2451
 }
ae2451
 
ae2451
+#ifdef WITH_DTRACE
ae2451
+static void
ae2451
+dtrace_entry(PyFrameObject *f)
ae2451
+{
ae2451
+    const char *filename;
ae2451
+    const char *fname;
ae2451
+    int lineno;
ae2451
+
ae2451
+    filename = PyString_AsString(f->f_code->co_filename);
ae2451
+    fname = PyString_AsString(f->f_code->co_name);
ae2451
+    lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);
ae2451
+
ae2451
+    PYTHON_FUNCTION_ENTRY((char *)filename, (char *)fname, lineno);
ae2451
+
ae2451
+    /*
ae2451
+     * Currently a USDT tail-call will not receive the correct arguments.
ae2451
+     * Disable the tail call here.
ae2451
+     */
ae2451
+#if defined(__sparc)
ae2451
+    asm("nop");
ae2451
+#endif
ae2451
+}
ae2451
+
ae2451
+static void
ae2451
+dtrace_return(PyFrameObject *f)
ae2451
+{
ae2451
+    const char *filename;
ae2451
+    const char *fname;
ae2451
+    int lineno;
ae2451
+
ae2451
+    filename = PyString_AsString(f->f_code->co_filename);
ae2451
+    fname = PyString_AsString(f->f_code->co_name);
ae2451
+    lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);
ae2451
+    PYTHON_FUNCTION_RETURN((char *)filename, (char *)fname, lineno);
ae2451
+
ae2451
+    /*
ae2451
+     * Currently a USDT tail-call will not receive the correct arguments.
ae2451
+     * Disable the tail call here.
ae2451
+     */
ae2451
+#if defined(__sparc)
ae2451
+    asm("nop");
ae2451
+#endif
ae2451
+}
ae2451
+#else
ae2451
+#define	PYTHON_FUNCTION_ENTRY_ENABLED() 0
ae2451
+#define	PYTHON_FUNCTION_RETURN_ENABLED() 0
ae2451
+#define	dtrace_entry(f)
ae2451
+#define	dtrace_return(f)
ae2451
+#endif
ae2451
 
ae2451
 /* Interpreter main loop */
ae2451
 
ae2451
@@ -909,6 +962,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int
ae2451
         }
ae2451
     }
ae2451
 
ae2451
+    if (PYTHON_FUNCTION_ENTRY_ENABLED())
ae2451
+        dtrace_entry(f);
ae2451
+
ae2451
     co = f->f_code;
ae2451
     names = co->co_names;
ae2451
     consts = co->co_consts;
ae2451
@@ -3000,6 +3056,9 @@ fast_yield:
ae2451
 
ae2451
     /* pop frame */
ae2451
 exit_eval_frame:
ae2451
+    if (PYTHON_FUNCTION_RETURN_ENABLED())
ae2451
+        dtrace_return(f);
ae2451
+
ae2451
     Py_LeaveRecursiveCall();
ae2451
     tstate->frame = f->f_back;
ae2451