Index: Python/ceval.c =================================================================== --- Python/ceval.c (revision 78334) +++ Python/ceval.c (working copy) @@ -19,6 +19,10 @@ #include +#ifdef WITH_DTRACE +#include "pydtrace.h" +#endif + #ifndef WITH_TSC #define READ_TIMESTAMP(var) @@ -671,7 +675,56 @@ NULL); } +#ifdef WITH_DTRACE +static void +dtrace_entry(PyFrameObject *f) +{ + const char *filename; + const char *fname; + int lineno; + + filename = PyString_AsString(f->f_code->co_filename); + fname = PyString_AsString(f->f_code->co_name); + lineno = PyCode_Addr2Line(f->f_code, f->f_lasti); + PYTHON_FUNCTION_ENTRY((char *)filename, (char *)fname, lineno); + + /* + * Currently a USDT tail-call will not receive the correct arguments. + * Disable the tail call here. + */ +#if defined(__sparc) + asm("nop"); +#endif +} + +static void +dtrace_return(PyFrameObject *f) +{ + const char *filename; + const char *fname; + int lineno; + + filename = PyString_AsString(f->f_code->co_filename); + fname = PyString_AsString(f->f_code->co_name); + lineno = PyCode_Addr2Line(f->f_code, f->f_lasti); + PYTHON_FUNCTION_RETURN((char *)filename, (char *)fname, lineno); + + /* + * Currently a USDT tail-call will not receive the correct arguments. + * Disable the tail call here. + */ +#if defined(__sparc) + asm("nop"); +#endif +} +#else +#define PYTHON_FUNCTION_ENTRY_ENABLED() 0 +#define PYTHON_FUNCTION_RETURN_ENABLED() 0 +#define dtrace_entry(f) +#define dtrace_return(f) +#endif + /* Interpreter main loop */ PyObject * @@ -909,6 +962,9 @@ } } + if (PYTHON_FUNCTION_ENTRY_ENABLED()) + dtrace_entry(f); + co = f->f_code; names = co->co_names; consts = co->co_consts; @@ -3001,6 +3057,8 @@ /* pop frame */ exit_eval_frame: + if (PYTHON_FUNCTION_RETURN_ENABLED()) + dtrace_return(f); Py_LeaveRecursiveCall(); tstate->frame = f->f_back; Index: configure =================================================================== --- configure (revision 78334) +++ configure (working copy) @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 78194 . +# From configure.in Revision: 78202 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for python 2.7. # @@ -724,6 +724,8 @@ USE_THREAD_MODULE LDLAST THREADOBJ +DTRACEOBJS +DTRACEHDRS DLINCLDIR DYNLOADFILE MACHDEP_OBJS @@ -1368,6 +1370,7 @@ --with(out)-tsc enable/disable timestamp counter profile --with(out)-pymalloc disable/enable specialized mallocs --with-valgrind Enable Valgrind support + --with(out)-dtrace disable/enable dtrace support --with-wctype-functions use wctype.h functions --with-fpectl enable SIGFPE catching --with-libm=STRING math library @@ -17992,6 +17995,50 @@ fi +# Check for dtrace support +{ echo "$as_me:$LINENO: checking for --with-dtrace" >&5 +echo $ECHO_N "checking for --with-dtrace... $ECHO_C" >&6; } + +# Check whether --with-dtrace was given. +if test "${with_dtrace+set}" = set; then + withval=$with_dtrace; +fi + + +if test ! -z "$with_dtrace" +then + if dtrace -G -o /dev/null -s $srcdir/Include/pydtrace.d 2>/dev/null + then + +cat >>confdefs.h <<\_ACEOF +#define WITH_DTRACE 1 +_ACEOF + + with_dtrace="Sun" + DTRACEOBJS="Python/dtrace.o" + DTRADEHDRS="" + elif dtrace -h -o /dev/null -s $srcdir/Include/pydtrace.d + then + +cat >>confdefs.h <<\_ACEOF +#define WITH_DTRACE 1 +_ACEOF + + with_dtrace="Apple" + DTRACEOBJS="" + DTRADEHDRS="pydtrace.h" + else + with_dtrace="no" + fi +else + with_dtrace="no" +fi + +{ echo "$as_me:$LINENO: result: $with_dtrace" >&5 +echo "${ECHO_T}$with_dtrace" >&6; } + + + # Check for --with-wctype-functions { echo "$as_me:$LINENO: checking for --with-wctype-functions" >&5 echo $ECHO_N "checking for --with-wctype-functions... $ECHO_C" >&6; } @@ -28557,6 +28604,8 @@ USE_THREAD_MODULE!$USE_THREAD_MODULE$ac_delim LDLAST!$LDLAST$ac_delim THREADOBJ!$THREADOBJ$ac_delim +DTRACEOBJS!$DTRACEOBJS$ac_delim +DTRACEHDRS!$DTRACEHDRS$ac_delim DLINCLDIR!$DLINCLDIR$ac_delim DYNLOADFILE!$DYNLOADFILE$ac_delim MACHDEP_OBJS!$MACHDEP_OBJS$ac_delim @@ -28575,7 +28624,7 @@ LTLIBOBJS!$LTLIBOBJS$ac_delim _ACEOF - if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 27; then + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 29; then break elif $ac_last_try; then { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 Index: configure.in =================================================================== --- configure.in (revision 78334) +++ configure.in (working copy) @@ -2570,6 +2570,38 @@ ) fi +# Check for dtrace support +AC_MSG_CHECKING(for --with-dtrace) +AC_ARG_WITH(dtrace, + AC_HELP_STRING(--with(out)-dtrace, disable/enable dtrace support)) + +if test ! -z "$with_dtrace" +then + if dtrace -G -o /dev/null -s $srcdir/Include/pydtrace.d 2>/dev/null + then + AC_DEFINE(WITH_DTRACE, 1, + [Define if you want to compile in Dtrace support]) + with_dtrace="Sun" + DTRACEOBJS="Python/dtrace.o" + DTRADEHDRS="" + elif dtrace -h -o /dev/null -s $srcdir/Include/pydtrace.d + then + AC_DEFINE(WITH_DTRACE, 1, + [Define if you want to compile in Dtrace support]) + with_dtrace="Apple" + DTRACEOBJS="" + DTRADEHDRS="pydtrace.h" + else + with_dtrace="no" + fi +else + with_dtrace="no" +fi + +AC_MSG_RESULT($with_dtrace) +AC_SUBST(DTRACEOBJS) +AC_SUBST(DTRACEHDRS) + # Check for --with-wctype-functions AC_MSG_CHECKING(for --with-wctype-functions) AC_ARG_WITH(wctype-functions, Index: Makefile.pre.in =================================================================== --- Makefile.pre.in (revision 78334) +++ Makefile.pre.in (working copy) @@ -296,6 +296,7 @@ Python/formatter_unicode.o \ Python/formatter_string.o \ Python/$(DYNLOADFILE) \ + @DTRACEOBJS@ \ $(LIBOBJS) \ $(MACHDEP_OBJS) \ $(THREADOBJ) @@ -585,6 +586,18 @@ Python/formatter_string.o: $(srcdir)/Python/formatter_string.c \ $(STRINGLIB_HEADERS) +# Only needed with --with-dtrace +buildinclude: + mkdir -p Include + +Include/pydtrace.h: buildinclude $(srcdir)/Include/pydtrace.d + dtrace -o $@ $(DFLAGS) -C -h -s $(srcdir)/Include/pydtrace.d + +Python/ceval.o: Include/pydtrace.h + +Python/dtrace.o: buildinclude $(srcdir)/Include/pydtrace.d Python/ceval.o + dtrace -o $@ $(DFLAGS) -C -G -s $(srcdir)/Include/pydtrace.d Python/ceval.o + ############################################################################ # Header files @@ -1232,6 +1245,6 @@ .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure .PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools .PHONY: frameworkaltinstallunixtools recheck autoconf clean clobber distclean -.PHONY: smelly funny patchcheck +.PHONY: smelly funny patchcheck buildinclude # IF YOU PUT ANYTHING HERE IT WILL GO AWAY Index: pyconfig.h.in =================================================================== --- pyconfig.h.in (revision 78334) +++ pyconfig.h.in (working copy) @@ -1046,6 +1046,9 @@ /* Define if you want documentation strings in extension modules */ #undef WITH_DOC_STRINGS +/* Define if you want to compile in Dtrace support */ +#undef WITH_DTRACE + /* Define if you want to use the new-style (Openstep, Rhapsody, MacOS) dynamic linker (dyld) instead of the old-style (NextStep) dynamic linker (rld). Dyld is necessary to support frameworks. */