churchyard / rpms / python38

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