churchyard / rpms / python3

Forked from rpms/python3 6 years ago
Clone

Blame 00055-systemtap.patch

5080ffc
diff -up Python-3.2b2/configure.in.systemtap Python-3.2b2/configure.in
5080ffc
--- Python-3.2b2/configure.in.systemtap	2010-12-13 02:59:39.000000000 -0500
5080ffc
+++ Python-3.2b2/configure.in	2010-12-28 17:01:58.044059433 -0500
5080ffc
@@ -2470,6 +2470,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
+
5080ffc
 # -I${DLINCLDIR} is added to the compile rule for importdl.o
5080ffc
 AC_SUBST(DLINCLDIR)
5080ffc
 DLINCLDIR=.
5080ffc
diff -up Python-3.2b2/Include/pydtrace.d.systemtap Python-3.2b2/Include/pydtrace.d
5080ffc
--- Python-3.2b2/Include/pydtrace.d.systemtap	2010-12-28 16:58:41.762936379 -0500
5080ffc
+++ Python-3.2b2/Include/pydtrace.d	2010-12-28 16:58:41.762936379 -0500
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
5080ffc
diff -up Python-3.2b2/Makefile.pre.in.systemtap Python-3.2b2/Makefile.pre.in
5080ffc
--- Python-3.2b2/Makefile.pre.in.systemtap	2010-12-28 16:58:41.000000000 -0500
5080ffc
+++ Python-3.2b2/Makefile.pre.in	2010-12-28 17:00:58.607310089 -0500
5080ffc
@@ -328,6 +328,7 @@ PYTHON_OBJS=	\
c969609
 		Python/formatter_unicode.o \
5080ffc
 		Python/fileutils.o \
c969609
 		Python/$(DYNLOADFILE) \
c969609
+		@DTRACEOBJS@ \
c969609
 		$(LIBOBJS) \
c969609
 		$(MACHDEP_OBJS) \
c969609
 		$(THREADOBJ)
5080ffc
@@ -632,6 +633,18 @@ Objects/typeobject.o: $(srcdir)/Objects/
5080ffc
 $(srcdir)/Objects/typeslots.inc: $(srcdir)/Include/typeslots.h $(srcdir)/Objects/typeslots.py
5080ffc
 	$(PYTHON) $(srcdir)/Objects/typeslots.py < $(srcdir)/Include/typeslots.h > $(srcdir)/Objects/typeslots.inc
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
 
5080ffc
@@ -1282,7 +1295,7 @@ Python/thread.o: @THREADHEADERS@
c969609
 .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
c969609
 .PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
5080ffc
 .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
5080ffc
diff -up Python-3.2b2/pyconfig.h.in.systemtap Python-3.2b2/pyconfig.h.in
5080ffc
--- Python-3.2b2/pyconfig.h.in.systemtap	2010-11-20 05:29:12.000000000 -0500
5080ffc
+++ Python-3.2b2/pyconfig.h.in	2010-12-28 16:58:41.765937360 -0500
5080ffc
@@ -1092,6 +1092,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. */
5080ffc
diff -up Python-3.2b2/Python/ceval.c.systemtap Python-3.2b2/Python/ceval.c
5080ffc
--- Python-3.2b2/Python/ceval.c.systemtap	2010-12-03 15:14:31.000000000 -0500
5080ffc
+++ Python-3.2b2/Python/ceval.c	2010-12-28 16:58:41.768935588 -0500
5080ffc
@@ -18,6 +18,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)
5080ffc
@@ -766,6 +770,70 @@ PyEval_EvalCode(PyObject *co, PyObject *
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 *
5080ffc
@@ -1183,6 +1251,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;
5080ffc
@@ -3048,6 +3120,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