Search code examples
systemtap

How to do user-space probing using debug info in systemtap


I am new to systemtap and would like to understand how to attach instrumentation dynamically to a production application using debug information in the application.

For a target application (example apache webserver). I would like to find the amount of time spent in the execution of a given function. i.e. i'd like to find time spent from beginning to end of a function, using the function's symbolic information. How can I do this using systemtap- Can you please give the instructions on:

  1. A tapset script for user-space probing using debug information
  2. How to execute this tapset script with a target application.

In particular I would like to find out how I can use the - Debuginfo-based instrumentation for user space tracing.

Here is the reference for "Debuginfo-based information" - https://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps


Solution

  • List the functions:

    stap -L 'process("/usr/sbin/httpd").function("*").call'
    

    Basic count of function call rates:

    stap /usr/share/doc/systemtap*/examples/*/eventcount.stp \
        'process("/usr/sbin/httpd").function("*").call'
    

    Time a function:

    stap -e 'probe process("/usr/sbin/httpd").function("ap_getword_conf").return {
        printf("%s %d\n", ppfunc(), gettimeofday_us()-@entry(gettimeofday_us()))
    }'