Blame SOURCES/00055-systemtap.patch

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