Using systemtap to trace into libraries

Systemtap is able to trace into userspace libraries. It’s actually very simple:


global last;

function display_time () {
      now = gettimeofday_us ();
      delta = 0;
      if (last > 0)
            delta = now - last;
      last = now;

      printf ("%d (+%d):", now, delta);

probe begin {
      last = 0;
      printf ("ready\n");

probe process("/usr/lib*/")
            .function("guestfs_[a-z]*") ? {
      printf ("\t%s %s\n", probefunc(), $$parms);

Run this script (as root) and in another terminal run any program that uses libguestfs, and you’ll see this output:

$ sudo /tmp/test.stap
1318252148697989 (+0):	guestfs_create 
1318252148698028 (+39):	guestfs_is_config g=0x123ab50
1318252149060531 (+362503):	guestfs_set_pgroup g=0x123ab50 pgroup=0x1
1318252149060588 (+57):	guestfs_add_drive g=0x123ab50 filename=0x123ad50
1318252149060648 (+60):	guestfs_safe_malloc g=0x123ab50 nbytes=0x8
1318252149060668 (+20):	guestfs_safe_realloc g=0x123ab50 ptr=0x123add0 nbytes=0x10
1318252149060689 (+21):	guestfs_safe_strdup g=0x123ab50 str=0x368567df1b
1318252149060705 (+16):	guestfs_safe_realloc g=0x123ab50 ptr=0x123add0 nbytes=0x18
1318252149060719 (+14):	guestfs_safe_strdup g=0x123ab50 str=0x7fffea8473f0
1318252149060736 (+17):	guestfs_is_config g=0x123ab50
1318252149060749 (+13):	guestfs_launch g=0x123ab50


Filed under Uncategorized

3 responses to “Using systemtap to trace into libraries

  1. Frank Ch. Eigler

    Rich, for extra eye candy, consider printing $$parms$ instead of $$parms.

  2. Hi,
    i am new to systemtap
    what does probefunc() do ? can ypu please explain the script in details

    Thanx in advance

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.