torsava / rpms / python3

Forked from rpms/python3 6 years ago
Clone
c969609
diff -up Python-3.1.1/configure.in.systemtap Python-3.1.1/configure.in
c969609
--- Python-3.1.1/configure.in.systemtap	2010-02-12 15:24:34.959845279 -0500
c969609
+++ Python-3.1.1/configure.in	2010-02-12 15:24:34.965845345 -0500
c969609
@@ -2359,6 +2359,38 @@ then
c969609
 fi
c969609
 AC_MSG_RESULT($with_pymalloc)
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, 
c969609
diff -up Python-3.1.1/Include/pydtrace.d.systemtap Python-3.1.1/Include/pydtrace.d
c969609
--- Python-3.1.1/Include/pydtrace.d.systemtap	2010-02-12 15:24:34.966844913 -0500
c969609
+++ Python-3.1.1/Include/pydtrace.d	2010-02-12 15:24:34.966844913 -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
c969609
diff -up Python-3.1.1/Makefile.pre.in.systemtap Python-3.1.1/Makefile.pre.in
c969609
--- Python-3.1.1/Makefile.pre.in.systemtap	2010-02-12 15:24:34.953845073 -0500
c969609
+++ Python-3.1.1/Makefile.pre.in	2010-02-12 15:24:34.990844336 -0500
c969609
@@ -312,6 +312,7 @@ PYTHON_OBJS=	\
c969609
 		Python/dtoa.o \
c969609
 		Python/formatter_unicode.o \
c969609
 		Python/$(DYNLOADFILE) \
c969609
+		@DTRACEOBJS@ \
c969609
 		$(LIBOBJS) \
c969609
 		$(MACHDEP_OBJS) \
c969609
 		$(THREADOBJ)
c969609
@@ -592,6 +593,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
 
c969609
@@ -1224,6 +1237,6 @@ 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
c969609
 
c969609
 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
c969609
diff -up Python-3.1.1/pyconfig.h.in.systemtap Python-3.1.1/pyconfig.h.in
c969609
--- Python-3.1.1/pyconfig.h.in.systemtap	2009-05-29 13:25:39.000000000 -0400
c969609
+++ Python-3.1.1/pyconfig.h.in	2010-02-12 15:24:34.991845511 -0500
c969609
@@ -5,6 +5,9 @@
c969609
 #define Py_PYCONFIG_H
c969609
 
c969609
 
c969609
+/* Define if building universal (internal helper macro) */
c969609
+#undef AC_APPLE_UNIVERSAL_BUILD
c969609
+
c969609
 /* Define for AIX if your compiler is a genuine IBM xlC/xlC_r and you want
c969609
    support for AIX C++ shared extension modules. */
c969609
 #undef AIX_GENUINE_CPLUSPLUS
c969609
@@ -995,6 +998,28 @@
c969609
 /* Define if you want to use computed gotos in ceval.c. */
c969609
 #undef USE_COMPUTED_GOTOS
c969609
 
c969609
+/* Enable extensions on AIX 3, Interix.  */
c969609
+#ifndef _ALL_SOURCE
c969609
+# undef _ALL_SOURCE
c969609
+#endif
c969609
+/* Enable GNU extensions on systems that have them.  */
c969609
+#ifndef _GNU_SOURCE
c969609
+# undef _GNU_SOURCE
c969609
+#endif
c969609
+/* Enable threading extensions on Solaris.  */
c969609
+#ifndef _POSIX_PTHREAD_SEMANTICS
c969609
+# undef _POSIX_PTHREAD_SEMANTICS
c969609
+#endif
c969609
+/* Enable extensions on HP NonStop.  */
c969609
+#ifndef _TANDEM_SOURCE
c969609
+# undef _TANDEM_SOURCE
c969609
+#endif
c969609
+/* Enable general extensions on Solaris.  */
c969609
+#ifndef __EXTENSIONS__
c969609
+# undef __EXTENSIONS__
c969609
+#endif
c969609
+
c969609
+
c969609
 /* Define if a va_list is an array of some kind */
c969609
 #undef VA_LIST_IS_ARRAY
c969609
 
c969609
@@ -1011,6 +1036,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. */
c969609
@@ -1032,20 +1060,21 @@
c969609
 /* Define to profile with the Pentium timestamp counter */
c969609
 #undef WITH_TSC
c969609
 
c969609
-/* Define to 1 if your processor stores words with the most significant byte
c969609
-   first (like Motorola and SPARC, unlike Intel and VAX). */
c969609
-#undef WORDS_BIGENDIAN
c969609
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
c969609
+   significant byte first (like Motorola and SPARC, unlike Intel). */
c969609
+#if defined AC_APPLE_UNIVERSAL_BUILD
c969609
+# if defined __BIG_ENDIAN__
c969609
+#  define WORDS_BIGENDIAN 1
c969609
+# endif
c969609
+#else
c969609
+# ifndef WORDS_BIGENDIAN
c969609
+#  undef WORDS_BIGENDIAN
c969609
+# endif
c969609
+#endif
c969609
 
c969609
 /* Define if arithmetic is subject to x87-style double rounding issue */
c969609
 #undef X87_DOUBLE_ROUNDING
c969609
 
c969609
-/* Define to 1 if on AIX 3.
c969609
-   System headers sometimes define this.
c969609
-   We just want to avoid a redefinition error message.  */
c969609
-#ifndef _ALL_SOURCE
c969609
-# undef _ALL_SOURCE
c969609
-#endif
c969609
-
c969609
 /* Define on OpenBSD to activate all library features */
c969609
 #undef _BSD_SOURCE
c969609
 
c969609
@@ -1064,15 +1093,25 @@
c969609
 /* This must be defined on some systems to enable large file support. */
c969609
 #undef _LARGEFILE_SOURCE
c969609
 
c969609
+/* Define to 1 if on MINIX. */
c969609
+#undef _MINIX
c969609
+
c969609
 /* Define on NetBSD to activate all library features */
c969609
 #undef _NETBSD_SOURCE
c969609
 
c969609
 /* Define _OSF_SOURCE to get the makedev macro. */
c969609
 #undef _OSF_SOURCE
c969609
 
c969609
+/* Define to 2 if the system does not provide POSIX.1 features except with
c969609
+   this defined. */
c969609
+#undef _POSIX_1_SOURCE
c969609
+
c969609
 /* Define to activate features from IEEE Stds 1003.1-2001 */
c969609
 #undef _POSIX_C_SOURCE
c969609
 
c969609
+/* Define to 1 if you need to in order for `stat' and other things to work. */
c969609
+#undef _POSIX_SOURCE
c969609
+
c969609
 /* Define if you have POSIX threads, and your system does not define that. */
c969609
 #undef _POSIX_THREADS
c969609
 
c969609
@@ -1080,12 +1119,12 @@
c969609
 #undef _REENTRANT
c969609
 
c969609
 /* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
c969609
-   <pthread.h>, or <semaphore.h> is not used. If the typedef was allowed, the
c969609
+   <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
c969609
    #define below would cause a syntax error. */
c969609
 #undef _UINT32_T
c969609
 
c969609
 /* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>,
c969609
-   <pthread.h>, or <semaphore.h> is not used. If the typedef was allowed, the
c969609
+   <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
c969609
    #define below would cause a syntax error. */
c969609
 #undef _UINT64_T
c969609
 
c969609
diff -up Python-3.1.1/Python/ceval.c.systemtap Python-3.1.1/Python/ceval.c
c969609
--- Python-3.1.1/Python/ceval.c.systemtap	2009-05-30 17:41:10.000000000 -0400
c969609
+++ Python-3.1.1/Python/ceval.c	2010-02-12 15:24:54.075844169 -0500
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)
c969609
@@ -655,6 +659,69 @@ PyEval_EvalCode(PyCodeObject *co, PyObje
c969609
 			  NULL, NULL);
c969609
 }
c969609
 
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
c969609
 
c969609
 /* Interpreter main loop */
c969609
 
c969609
@@ -1061,6 +1128,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int
c969609
 		}
c969609
 	}
c969609
 
c969609
+        if (PYTHON_FUNCTION_ENTRY_ENABLED())
c969609
+                dtrace_entry(f);
c969609
+
c969609
 	co = f->f_code;
c969609
 	names = co->co_names;
c969609
 	consts = co->co_consts;
c969609
@@ -2907,6 +2977,8 @@ fast_yield:
c969609
 
c969609
 	/* pop frame */
c969609
 exit_eval_frame:
c969609
+	if (PYTHON_FUNCTION_RETURN_ENABLED())
c969609
+		dtrace_return(f);
c969609
 	Py_LeaveRecursiveCall();
c969609
 	tstate->frame = f->f_back;
c969609