FudCon Success – Systemtap meets Python

At FudCon, David Malcolm, Jon VanAlten, Will Cohen and I sat down, had some fun and made tracing python methods through systemtap possible:

0 python(20122): => search_function in Lib/encodings/__init__.py:71
15 python(20122):  => normalize_encoding in Lib/encodings/__init__.py:49
37 python(20122):  <= normalize_encoding
170 python(20122):  => <module> in Lib/encodings/utf_8.py:8
193 python(20122):   => IncrementalEncoder in Lib/encodings/utf_8.py:18
206 python(20122):   <= IncrementalEncoder
251 python(20122):   => IncrementalDecoder in Lib/encodings/utf_8.py:22
264 python(20122):   <= IncrementalDecoder
310 python(20122):   => StreamWriter in Lib/encodings/utf_8.py:25
323 python(20122):   <= StreamWriter
340 python(20122):   => StreamReader in Lib/encodings/utf_8.py:28
353 python(20122):   <= StreamReader
367 python(20122):  <= <module>
391 python(20122):  => getregentry in Lib/encodings/utf_8.py:33
410 python(20122):   => __new__ in Lib/codecs.py:77
429 python(20122):   <= __new__
440 python(20122):  <= getregentry
462 python(20122): <= search_function

The coolest part is that it works through the existing patch to python for adding dtrace support. Some small tweaks to the autoconf detection was needed, but the rest was used as is.

If you want to learn how to add static user space probes to your program/package please see Will’s excellent guide. Adding User Space Probing to an Application: A simple example adding markers to a user-space application with SystemTap.

3 Comments

  1. Nice – is that potential F13 material?

  2. There was one addional tweak to the SystemTap script that produces .h and .o files from the .d file to understand the “-I” option. This SystemTap change has been checked into the SystemTap git tree:

    http://sources.redhat.com/git/gitweb.cgi?p=systemtap.git;a=commit;h=2d971c6b8835c7e38ce78dd554827f5f96bc7c04

    This is needed build python with the tracing support.

    The script to generate the the sample output was something like the following:

    probe process(“/usr/lib64/libpython2.6.so”).mark(“function__entry”) {
    printf(“%s => %s in %s:%dn”, thread_indent(1), user_string($arg2),
    user_string($arg1), $arg3);
    }

    probe process(“/usr/lib64/libpython2.6.so”).mark(“function__return”) {
    printf(“%s %s in %s:%dn”, thread_indent(1), function, file, lineno);
    }

    probe python.function.return {
    printf(“%s <= %sn", thread_indent(-1), function);
    }