Blame SOURCES/00055-systemtap.patch

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