Profile/Systemtap

Using Systemtap to profile Sugar
In my system (Fedora 18) I found a bug and needed install systemtap from git. Newer systems can have it solved.

Installing systemtap from git
The installation is very standard, requieres set a destination directory:

$ git clone git://sourceware.org/git/systemtap.git $ cd systemtap/ $ ./configure --prefix=/home/[your-user-name]/systemtap-2.5-27886 $ make $ make install

Installing from repositories
You can try install from repositories too.


 * 1) yum install -y systemtap-devel systemtap-runtime systemtap-client

If you install from git and from the repositories, in the same system, can have conflicts trying to run the probes.

Adding your user to the needed groups
To run stap as a user, you need add it to the following groups


 * 1) usermod -a -G stapusr gonzalo
 * 2) usermod -a -G stapsys gonzalo
 * 3) usermod -a -G stapdev gonzalo

after that, you need restart your session.

You always can run stap as root too.

Using systemtap
Systemtap have "probes" already included in the kernel, and several libraries in user space too. Both GLib and python have probes, making it very useful for us. You can use it to monitor when files are read, or when objects are created or destroyed. To do it, have a language to create scripts. Several scripts are already created, and you can create new or modify them.

Systemtap monitor events in all the process in the system, but you can define a filter to monitor only a specific process.

This example show how to analyze memory use with SystemTap

Using with sugar-buid
In sugar-build, we build glib, then we need move the global glib and gobject probes, to not have conflicts.

I renamed the global probes:


 * 1) cd /usr/share/systemtap/tapset/
 * 2) mv 64-glib.stp 64-glib.stp.old
 * 3) mv 64-gobject.stp 64-gobject.stp.old

Now we can download a sample test, like and run it in our sugar-build session.

To define as target a running process, can use the -x parameter. (Remember stap monitor all the system)

To get the sugar process PID, can do:

$ ps ax | grep jarabe 24673 ?       Sl     0:28 python2 -m jarabe.main

The first number is the PID

Running stap with the PID we found:

$ stap -v -x 24673 glib-memtrace2.stp

This will show every 5 seconds, the memory use and if GObjects were created.

Another probe you can use is

$ stap -v -x 24673 pyfuntime.stp

Will show every time a python method start and finish, and the time spent.

Finally, to have a "top" like of python functions, download

Troubleshoting

 * If your user can't run stap, execute the command "groups" and check if stapusr, stapsys and stapdev groups are present.


 * If you need check what directories is using systemtap to look for the probes, can do:

stap -p1 -vv 'probe begin { }' > /dev/null