diff -r b898402e75ef Doc/howto/index.rst --- a/Doc/howto/index.rst Mon May 19 07:34:08 2014 +0100 +++ b/Doc/howto/index.rst Mon May 19 13:06:24 2014 +0200 @@ -29,4 +29,5 @@ argparse.rst ipaddress.rst clinic.rst + instrumentation.rst diff -r b898402e75ef Makefile.pre.in --- a/Makefile.pre.in Mon May 19 07:34:08 2014 +0100 +++ b/Makefile.pre.in Mon May 19 13:06:24 2014 +0200 @@ -399,6 +399,7 @@ Python/formatter_unicode.o \ Python/fileutils.o \ Python/$(DYNLOADFILE) \ + @SYSTEMTAPOBJS@ \ $(LIBOBJS) \ $(MACHDEP_OBJS) \ $(THREADOBJ) @@ -822,7 +823,8 @@ $(OPCODETARGETS_H): $(OPCODETARGETGEN_FILES) $(OPCODETARGETGEN) $(OPCODETARGETS_H) -Python/ceval.o: $(OPCODETARGETS_H) $(srcdir)/Python/ceval_gil.h +Python/ceval.o: $(OPCODETARGETS_H) $(srcdir)/Python/ceval_gil.h \ + $(srcdir)/Python/ceval_systemtap.h @SYSTEMTAPDEPS@ Python/frozen.o: Python/importlib.h @@ -830,6 +832,13 @@ Objects/typeslots.inc: $(srcdir)/Include/typeslots.h $(srcdir)/Objects/typeslots.py $(PYTHON) $(srcdir)/Objects/typeslots.py < $(srcdir)/Include/typeslots.h > Objects/typeslots.inc +# Only needed with --with-systemtap; not a public header: +$(srcdir)/Python/pysystemtap.h: $(srcdir)/Python/pysystemtap.d + dtrace -o $@ $(DFLAGS) -C -h -s $(srcdir)/Python/pysystemtap.d + +Python/pysystemtap.o: $(srcdir)/Python/pysystemtap.d Python/ceval.o + dtrace -o $@ $(DFLAGS) -C -G -s $(srcdir)/Python/pysystemtap.d Python/ceval.o + ############################################################################ # Header files @@ -1527,6 +1536,7 @@ -rm -f pybuilddir.txt -rm -f Lib/lib2to3/*Grammar*.pickle -rm -f Modules/_testembed Modules/_freeze_importlib + -rm -f $(srcdir)/Python/pysystemtap.h profile-removal: find . -name '*.gc??' -exec rm -f {} ';' diff -r b898402e75ef Misc/NEWS --- a/Misc/NEWS Mon May 19 07:34:08 2014 +0100 +++ b/Misc/NEWS Mon May 19 13:06:24 2014 +0200 @@ -602,6 +602,11 @@ don't clear anymore the state of Python threads early during the Python shutdown. +- Issue #14776: Added a new --with-systemtap configure-time option, which adds + static markers for SystemTap so that SystemTap scripts can observe bytecode + frames being entered and exited and so generate reports on what Python code + is being exectuted. + Library ------- diff -r b898402e75ef Python/ceval.c --- a/Python/ceval.c Mon May 19 07:34:08 2014 +0100 +++ b/Python/ceval.c Mon May 19 13:06:24 2014 +0200 @@ -18,6 +18,8 @@ #include +#include "ceval_systemtap.h" + #ifndef WITH_TSC #define READ_TIMESTAMP(var) @@ -1156,6 +1158,10 @@ } } + if (PYTHON_FUNCTION_ENTRY_ENABLED()) { + systemtap_function_entry(f); + } + co = f->f_code; names = co->co_names; consts = co->co_consts; @@ -3240,6 +3246,11 @@ /* pop frame */ exit_eval_frame: + + if (PYTHON_FUNCTION_RETURN_ENABLED()) { + systemtap_function_return(f); + } + Py_LeaveRecursiveCall(); f->f_executing = 0; tstate->frame = f->f_back; diff -r b898402e75ef configure --- a/configure Mon May 19 07:34:08 2014 +0100 +++ b/configure Mon May 19 13:06:24 2014 +0200 @@ -642,6 +642,8 @@ MACHDEP_OBJS DYNLOADFILE DLINCLDIR +SYSTEMTAPDEPS +SYSTEMTAPOBJS THREADOBJ LDLAST USE_THREAD_MODULE @@ -813,6 +815,7 @@ with_tsc with_pymalloc with_valgrind +with_systemtap with_fpectl with_libm with_libc @@ -1498,6 +1501,7 @@ --with(out)-tsc enable/disable timestamp counter profile --with(out)-pymalloc disable/enable specialized mallocs --with-valgrind Enable Valgrind support + --with(out)-systemtap disable/enable SystemTap support --with-fpectl enable SIGFPE catching --with-libm=STRING math library --with-libc=STRING C library @@ -10440,6 +10444,31 @@ OPT="-DDYNAMIC_ANNOTATIONS_ENABLED=1 $OPT" fi +# Check for systemtap support +# On Linux, /usr/bin/dtrace is in fact a shim to SystemTap +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-systemtap" >&5 +$as_echo_n "checking for --with-systemtap... " >&6; } + +# Check whether --with-systemtap was given. +if test "${with_systemtap+set}" = set; then : + withval=$with_systemtap; +else + with_systemtap=no +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_systemtap" >&5 +$as_echo "$with_systemtap" >&6; } +if test "$with_systemtap" != no; then + +$as_echo "#define WITH_SYSTEMTAP 1" >>confdefs.h + + SYSTEMTAPOBJS="Python/pysystemtap.o" + SYSTEMTAPDEPS="\$(srcdir)/Python/pysystemtap.h" +fi + + + + # -I${DLINCLDIR} is added to the compile rule for importdl.o DLINCLDIR=. diff -r b898402e75ef configure.ac --- a/configure.ac Mon May 19 07:34:08 2014 +0100 +++ b/configure.ac Mon May 19 13:06:24 2014 +0200 @@ -2877,6 +2877,23 @@ OPT="-DDYNAMIC_ANNOTATIONS_ENABLED=1 $OPT" fi +# Check for systemtap support +# On Linux, /usr/bin/dtrace is in fact a shim to SystemTap +AC_MSG_CHECKING([for --with-systemtap]) +AC_ARG_WITH([systemtap], + AC_HELP_STRING([--with(out)-systemtap], [disable/enable SystemTap support]),, + with_systemtap=no) +AC_MSG_RESULT([$with_systemtap]) +if test "$with_systemtap" != no; then + AC_DEFINE(WITH_SYSTEMTAP, 1, + [Define if you want to compile in SystemTap support]) + SYSTEMTAPOBJS="Python/pysystemtap.o" + SYSTEMTAPDEPS="\$(srcdir)/Python/pysystemtap.h" +fi + +AC_SUBST(SYSTEMTAPOBJS) +AC_SUBST(SYSTEMTAPDEPS) + # -I${DLINCLDIR} is added to the compile rule for importdl.o AC_SUBST(DLINCLDIR) DLINCLDIR=. diff -r b898402e75ef pyconfig.h.in --- a/pyconfig.h.in Mon May 19 07:34:08 2014 +0100 +++ b/pyconfig.h.in Mon May 19 13:06:24 2014 +0200 @@ -1346,6 +1346,9 @@ /* Define if you want to compile in Python-specific mallocs */ #undef WITH_PYMALLOC +/* Define if you want to compile in SystemTap support */ +#undef WITH_SYSTEMTAP + /* Define if you want to compile in rudimentary thread support */ #undef WITH_THREAD