Blame SOURCES/00055-systemtap.patch

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