churchyard / rpms / python2

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