Blame SOURCES/00055-systemtap.patch

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