From 3dde1c96508ada7b00fde40ce915757f72d359d2 Mon Sep 17 00:00:00 2001 From: dmalcolm Date: Tue, 9 Feb 2010 22:46:34 +0000 Subject: [PATCH] - add a systemtap tapset defining "python.function.entry" and "python.function.return" to make it easy to use the static probepoint within Python; add an example of using the tapset to the docs --- libpython.stp | 17 ++++++++++++++++ python.spec | 45 ++++++++++++++++++++++++++++++++++++++++++- systemtap-example.stp | 19 ++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 libpython.stp create mode 100644 systemtap-example.stp diff --git a/libpython.stp b/libpython.stp new file mode 100644 index 0000000..56cf2fb --- /dev/null +++ b/libpython.stp @@ -0,0 +1,17 @@ +/* Systemtap tapset to make it easier to trace Python */ + +/* + Define python.function.entry/return: +*/ +probe python.function.entry = process("python").library("LIBRARY_PATH").mark("function__entry") +{ + filename = user_string($arg1); + funcname = user_string($arg2); + lineno = $arg3; +} +probe python.function.return = process("python").library("LIBRARY_PATH").mark("function__return") +{ + filename = user_string($arg1); + funcname = user_string($arg2); + lineno = $arg3; +} diff --git a/python.spec b/python.spec index 425b6cf..e2e345a 100644 --- a/python.spec +++ b/python.spec @@ -52,7 +52,7 @@ Summary: An interpreted, interactive, object-oriented programming language Name: %{python} Version: 2.6.4 -Release: 17%{?dist} +Release: 18%{?dist} License: Python Group: Development/Languages Provides: python-abi = %{pybasever} @@ -82,6 +82,16 @@ Source1: libpython-36a517ef7848cbd0b3dcc7371f32e47ac4c87eba.tar.gz Source2: pythondeps.sh %global __python_requires %{SOURCE2} +# Systemtap tapset to make it easier to use the systemtap static probes +# (actually a template; LIBRARY_PATH will get fixed up during install) +# Written by dmalcolm; not yet sent upstream +Source3: libpython.stp + + +# Example systemtap script using the tapset +# Written by wcohen, mjw, dmalcolm; not yet sent upstream +Source4: systemtap-example.stp + # Modules/Setup.dist is ultimately used by the "makesetup" script to construct # the Makefile and config.c @@ -416,6 +426,11 @@ code that uses more than just unittest and/or test_support.py. %setup -q -n Python-%{version} -T -D -a 1 %endif # with_gdb_hooks +%if 0%{?with_systemtap} +# Provide an example of usage of the tapset: +cp -a %{SOURCE4} . +%endif # with_systemtap + # Ensure that we're using the system copy of various libraries, rather than # copies shipped by upstream in the tarball: # Remove embedded copy of expat: @@ -696,6 +711,25 @@ LD_LIBRARY_PATH=. ./python -c "import compileall; import sys; compileall.compile LD_LIBRARY_PATH=. ./python -O -c "import compileall; import sys; compileall.compile_dir('%{buildroot}%{dir_holding_gdb_py}', ddir='%{dir_holding_gdb_py}')" %endif # with_gdb_hooks +# +# Systemtap hooks: +# +%if 0%{?with_systemtap} +# Install a tapset for this libpython into tapsetdir, fixing up the path to the +# library: +mkdir -p %{buildroot}%{tapsetdir} +%ifarch ppc64 s390x x86_64 ia64 alpha sparc64 +%global libpython_stp libpython%{pybasever}-64.stp +%else +%global libpython_stp libpython%{pybasever}-32.stp +%endif + +sed \ + -e "s|LIBRARY_PATH|%{_libdir}/%{py_INSTSONAME}|" \ + %{SOURCE3} \ + > %{buildroot}%{tapsetdir}/%{libpython_stp} +%endif # with_systemtap + %clean rm -fr %{buildroot} @@ -842,6 +876,10 @@ rm -fr %{buildroot} %defattr(-,root,root,-) %doc LICENSE README %{_libdir}/%{py_INSTSONAME} +%if 0%{?with_systemtap} +%{tapsetdir}/%{libpython_stp} +%doc systemtap-example.stp +%endif %files devel %defattr(-,root,root,-) @@ -903,6 +941,11 @@ rm -fr %{buildroot} # payload file would be unpackaged) %changelog +* Tue Feb 9 2010 David Malcolm - 2.6.4-18 +- add a systemtap tapset defining "python.function.entry" and +"python.function.return" to make it easy to use the static probepoint within +Python; add an example of using the tapset to the docs + * Tue Feb 9 2010 David Malcolm - 2.6.4-17 - add systemtap static probes (wcohen; patch 55; rh bug #545179) - update some comments in specfile relating to gdb work diff --git a/systemtap-example.stp b/systemtap-example.stp new file mode 100644 index 0000000..164333a --- /dev/null +++ b/systemtap-example.stp @@ -0,0 +1,19 @@ +/* + Example usage of the Python systemtap tapset to show a nested view of all + Python function calls (and returns) across the whole system. + + Run this using + stap systemtap-example.stp + to instrument all Python processes on the system, or (for example) using + stap systemtap-example.stp -c COMMAND + to instrument a specific program (implemented in Python) +*/ +probe python.function.entry +{ + printf("%s => %s in %s:%d\n", thread_indent(1), funcname, filename, lineno); +} + +probe python.function.return +{ + printf("%s <= %s in %s:%d\n", thread_indent(-1), funcname, filename, lineno); +}