churchyard / rpms / python3

Forked from rpms/python3 3 years ago
Clone

Blame python-3.2a1-systemtap.patch

7eb10c
diff -up Python-3.2a1/configure.in.systemtap Python-3.2a1/configure.in
7eb10c
--- Python-3.2a1/configure.in.systemtap	2010-07-19 03:31:40.000000000 -0400
7eb10c
+++ Python-3.2a1/configure.in	2010-08-02 16:19:43.809000621 -0400
7eb10c
@@ -1987,6 +1987,7 @@ AC_ARG_WITH(system_expat,
7eb10c
 AC_MSG_RESULT($with_system_expat)
7eb10c
 
7eb10c
 # Check for use of the system libffi library
7eb10c
+
7eb10c
 AC_MSG_CHECKING(for --with-system-ffi)
7eb10c
 AC_ARG_WITH(system_ffi,
7eb10c
             AS_HELP_STRING([--with-system-ffi], [build _ctypes module using an installed ffi library]))
7eb10c
@@ -2500,6 +2501,38 @@ if test "$with_valgrind" != no; then
7eb10c
     OPT="-DDYNAMIC_ANNOTATIONS_ENABLED=1 $OPT"
c96960
 fi
c96960
 
c96960
+# Check for dtrace support
c96960
+AC_MSG_CHECKING(for --with-dtrace)
c96960
+AC_ARG_WITH(dtrace,
c96960
+            AC_HELP_STRING(--with(out)-dtrace, disable/enable dtrace support))
c96960
+
c96960
+if test ! -z "$with_dtrace"
c96960
+then
c96960
+    if dtrace -G -o /dev/null -s $srcdir/Include/pydtrace.d 2>/dev/null
c96960
+    then
c96960
+	AC_DEFINE(WITH_DTRACE, 1, 
c96960
+	 [Define if you want to compile in Dtrace support])
c96960
+	with_dtrace="Sun"
c96960
+	DTRACEOBJS="Python/dtrace.o"
c96960
+	DTRADEHDRS=""
c96960
+    elif dtrace -h -o /dev/null -s $srcdir/Include/pydtrace.d
c96960
+   then
c96960
+	AC_DEFINE(WITH_DTRACE, 1, 
c96960
+	 [Define if you want to compile in Dtrace support])
c96960
+	with_dtrace="Apple"
c96960
+	DTRACEOBJS=""
c96960
+	DTRADEHDRS="pydtrace.h"
c96960
+    else
c96960
+	with_dtrace="no"
c96960
+    fi
c96960
+else
c96960
+    with_dtrace="no"
c96960
+fi
c96960
+
c96960
+AC_MSG_RESULT($with_dtrace)
c96960
+AC_SUBST(DTRACEOBJS)
c96960
+AC_SUBST(DTRACEHDRS)
c96960
+
c96960
 # Check for --with-wctype-functions
c96960
 AC_MSG_CHECKING(for --with-wctype-functions)
c96960
 AC_ARG_WITH(wctype-functions, 
7eb10c
diff -up Python-3.2a1/Include/pydtrace.d.systemtap Python-3.2a1/Include/pydtrace.d
7eb10c
--- Python-3.2a1/Include/pydtrace.d.systemtap	2010-08-02 16:17:04.249000540 -0400
7eb10c
+++ Python-3.2a1/Include/pydtrace.d	2010-08-02 16:17:04.249000540 -0400
c96960
@@ -0,0 +1,10 @@
c96960
+provider python {
c96960
+	probe function__entry(const char *, const char *, int);
c96960
+	probe function__return(const char *, const char *, int);
c96960
+};
c96960
+
c96960
+#pragma D attributes Evolving/Evolving/Common provider python provider
c96960
+#pragma D attributes Private/Private/Common provider python module
c96960
+#pragma D attributes Private/Private/Common provider python function
c96960
+#pragma D attributes Evolving/Evolving/Common provider python name
c96960
+#pragma D attributes Evolving/Evolving/Common provider python args
7eb10c
diff -up Python-3.2a1/Makefile.pre.in.systemtap Python-3.2a1/Makefile.pre.in
7eb10c
--- Python-3.2a1/Makefile.pre.in.systemtap	2010-08-02 16:17:04.243000614 -0400
7eb10c
+++ Python-3.2a1/Makefile.pre.in	2010-08-02 16:20:41.617000527 -0400
7eb10c
@@ -324,6 +324,7 @@ PYTHON_OBJS=	\
c96960
 		Python/dtoa.o \
c96960
 		Python/formatter_unicode.o \
c96960
 		Python/$(DYNLOADFILE) \
c96960
+		@DTRACEOBJS@ \
c96960
 		$(LIBOBJS) \
c96960
 		$(MACHDEP_OBJS) \
c96960
 		$(THREADOBJ)
7eb10c
@@ -615,6 +616,18 @@ Python/formatter_unicode.o: $(srcdir)/Py
c96960
 				$(srcdir)/Objects/stringlib/formatter.h
c96960
 
c96960
 
c96960
+# Only needed with --with-dtrace
c96960
+buildinclude:
c96960
+	mkdir -p Include
c96960
+
c96960
+Include/pydtrace.h: buildinclude $(srcdir)/Include/pydtrace.d
c96960
+	dtrace -o $@ $(DFLAGS) -C -h -s $(srcdir)/Include/pydtrace.d
c96960
+
c96960
+Python/ceval.o: Include/pydtrace.h
c96960
+
c96960
+Python/dtrace.o: buildinclude $(srcdir)/Include/pydtrace.d Python/ceval.o
c96960
+	dtrace -o $@ $(DFLAGS) -C -G -s $(srcdir)/Include/pydtrace.d Python/ceval.o
c96960
+
c96960
 ############################################################################
c96960
 # Header files
c96960
 
7eb10c
@@ -1248,7 +1261,7 @@ Python/thread.o: @THREADHEADERS@
c96960
 .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
c96960
 .PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
c96960
 .PHONY: frameworkaltinstallunixtools recheck autoconf clean clobber distclean 
c96960
-.PHONY: smelly funny patchcheck
c96960
+.PHONY: smelly funny patchcheck buildinclude
7eb10c
 .PHONY: gdbhooks
c96960
 
c96960
 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
7eb10c
diff -up Python-3.2a1/pyconfig.h.in.systemtap Python-3.2a1/pyconfig.h.in
7eb10c
--- Python-3.2a1/pyconfig.h.in.systemtap	2010-08-02 16:18:33.696001964 -0400
7eb10c
+++ Python-3.2a1/pyconfig.h.in	2010-08-02 16:21:48.566001832 -0400
7eb10c
@@ -1078,6 +1078,9 @@
c96960
 /* Define if you want documentation strings in extension modules */
c96960
 #undef WITH_DOC_STRINGS
c96960
 
c96960
+/* Define if you want to compile in Dtrace support */
c96960
+#undef WITH_DTRACE
c96960
+
c96960
 /* Define if you want to use the new-style (Openstep, Rhapsody, MacOS) dynamic
c96960
    linker (dyld) instead of the old-style (NextStep) dynamic linker (rld).
c96960
    Dyld is necessary to support frameworks. */
7eb10c
diff -up Python-3.2a1/Python/ceval.c.systemtap Python-3.2a1/Python/ceval.c
7eb10c
--- Python-3.2a1/Python/ceval.c.systemtap	2010-07-20 18:39:34.000000000 -0400
7eb10c
+++ Python-3.2a1/Python/ceval.c	2010-08-02 16:23:58.703001000 -0400
c96960
@@ -19,6 +19,10 @@
c96960
 
c96960
 #include <ctype.h>
c96960
 
c96960
+#ifdef WITH_DTRACE
c96960
+#include "pydtrace.h"
c96960
+#endif
c96960
+
c96960
 #ifndef WITH_TSC
c96960
 
c96960
 #define READ_TIMESTAMP(var)
7eb10c
@@ -752,6 +756,70 @@ PyEval_EvalCode(PyCodeObject *co, PyObje
c96960
 }
c96960
 
7eb10c
 
c96960
+#ifdef WITH_DTRACE
c96960
+struct frame_marker_info
c96960
+{
c96960
+	char *filename;
c96960
+	char *name;
c96960
+	int lineno;
c96960
+
c96960
+	PyObject *utf8_filename;
c96960
+	PyObject *utf8_name;
c96960
+};
c96960
+
c96960
+static void
c96960
+get_frame_marker_info(PyFrameObject *f, struct frame_marker_info *fmi)
c96960
+{
c96960
+	fmi->utf8_filename = PyUnicode_AsUTF8String(f->f_code->co_filename);
c96960
+	if (fmi->utf8_filename) {
c96960
+		fmi->filename = PyBytes_AsString(fmi->utf8_filename);
c96960
+	} else {
c96960
+		fmi->filename = NULL;
c96960
+		/* FIXME: clear the exception? */
c96960
+	}
c96960
+
c96960
+	fmi->utf8_name = PyUnicode_AsUTF8String(f->f_code->co_name);
c96960
+	if (fmi->utf8_name) {
c96960
+		fmi->name = PyBytes_AsString(fmi->utf8_name);
c96960
+	} else {
c96960
+		fmi->name = NULL;
c96960
+		/* FIXME: clear the exception? */
c96960
+	}
c96960
+
c96960
+	fmi->lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);
c96960
+}
c96960
+
c96960
+static void
c96960
+release_frame_marker_info(struct frame_marker_info *fmi)
c96960
+{
c96960
+	Py_XDECREF(fmi->utf8_filename);
c96960
+	Py_XDECREF(fmi->utf8_name);
c96960
+}
c96960
+
c96960
+static void
c96960
+dtrace_entry(PyFrameObject *f)
c96960
+{
c96960
+	struct frame_marker_info fmi;
c96960
+	get_frame_marker_info(f, &fmi);
c96960
+	PYTHON_FUNCTION_ENTRY(fmi.filename, fmi.name, fmi.lineno);
c96960
+	release_frame_marker_info(&fmi);
c96960
+}
c96960
+
c96960
+static void
c96960
+dtrace_return(PyFrameObject *f)
c96960
+{
c96960
+	struct frame_marker_info fmi;
c96960
+	get_frame_marker_info(f, &fmi);
c96960
+	PYTHON_FUNCTION_RETURN(fmi.filename, fmi.name, fmi.lineno);
c96960
+	release_frame_marker_info(&fmi);
c96960
+}
c96960
+#else
c96960
+#define	PYTHON_FUNCTION_ENTRY_ENABLED() 0
c96960
+#define	PYTHON_FUNCTION_RETURN_ENABLED() 0
c96960
+#define	dtrace_entry(f)
c96960
+#define	dtrace_return(f)
c96960
+#endif
7eb10c
+ 
c96960
 /* Interpreter main loop */
c96960
 
7eb10c
 PyObject *
7eb10c
@@ -1156,6 +1224,10 @@ PyEval_EvalFrameEx(PyFrameObject *f, int
7eb10c
         }
7eb10c
     }
c96960
 
7eb10c
+    if (PYTHON_FUNCTION_ENTRY_ENABLED()) {
7eb10c
+        dtrace_entry(f);
7eb10c
+    }
c96960
+
7eb10c
     co = f->f_code;
7eb10c
     names = co->co_names;
7eb10c
     consts = co->co_consts;
7eb10c
@@ -3046,6 +3118,9 @@ fast_yield:
c96960
 
7eb10c
     /* pop frame */
c96960
 exit_eval_frame:
7eb10c
+    if (PYTHON_FUNCTION_RETURN_ENABLED()) {
7eb10c
+        dtrace_return(f);
7eb10c
+    }
7eb10c
     Py_LeaveRecursiveCall();
7eb10c
     tstate->frame = f->f_back;
c96960