Chapter 2. Using SystemTap

Chapter 2. Using SystemTap

2.1. Installation and Setup
2.1.1. Installing SystemTap
2.1.2. Installing Required Kernel Information RPMs
2.1.3. Initial Testing
2.2. Generating Instrumentation for Other Computers
2.3. Running SystemTap Scripts

This chapter instructs users how to install SystemTap, and provides an introduction on how to run SystemTap scripts.

2.1. Installation and Setup

To deploy SystemTap, you need to install the SystemTap packages along with the corresponding set of -devel, -debuginfo and -debuginfo-common packages for your kernel. If your system has multiple kernels installed, and you wish to use SystemTap on more than one kernel kernel, you will need to install the -devel and -debuginfo packages for each of those kernel versions.

These procedures will be discussed in detail in the following sections.

Important

Many users confuse -debuginfo with -debug. Remember that the deployment of SystemTap requires the installation of the -debuginfo package of the kernel, not the -debug version of the kernel.

SystemTap needs information about the kernel in order to place instrumentation in it (i.e. probe it). This information also allows SystemTap to generate the code for the instrumentation. This information is contained in the matching -devel and -debuginfo packages for your kernel. The necessary -devel and -debuginfo packages for the ordinary "vanilla" kernel are as follows:

  • kernel-debuginfo

  • kernel-debuginfo-common

  • kernel-devel

Likewise, the necessary packages for the PAE kernel would be kernel-PAE-debuginfo, kernel-PAE-debuginfo-common, and kernel-PAE-devel.

To determine what kernel your system is currently using, use:

uname -r

For example, if you wish to use SystemTap on kernel version 2.6.18-53.el5 on an i686 machine, then you would need to download and install the following RPMs:

  • kernel-debuginfo-2.6.18-53.1.13.el5.i686.rpm

  • kernel-debuginfo-common-2.6.18-53.1.13.el5.i686.rpm

  • kernel-devel-2.6.18-53.1.13.el5.i686.rpm

Important

The version, variant, and architecture of the -devel, -debuginfo and -debuginfo-common packages must match the kernel you wish to probe with SystemTap exactly.

To help ease your deployment of SystemTap, you can use stapprep.sh. stapprep.sh determines the kernel information packages you need to install in order to run SystemTap. If you run stapprep.sh (as an ordinary, non-root user) without any arguments, it will display the kernel information packages required for the loaded kernel. You can also pass a specific kernel version to stapprep.sh (e.g. 2.6.18-92.el5) if you wish to probe a kernel that is not currently loaded.

Note

Running stapprep.sh as root will display the required kernel packages and install them as well, provided that yum and yum-utils are configured properly.

stapprep.sh
#! /bin/bash
check_error() { if test $1 != 0; then echo $2; exit $1; fi }

if [ "$#" -lt 1 ]; then
    UNAME=`uname -r` # determine the kernel running on the machine
else
    UNAME=$1 #user passed in uname value
fi
UNAME=`echo $UNAME | sed "s/ //"` #strip out any whitespace
KERNEL="kernel"
for VARIANT in debug kdump PAE xen; do
  TMP=`echo $UNAME | sed s/$VARIANT//`
  if [ "$TMP" != "$UNAME" ]; then
      UNAME=$TMP; KERNEL="kernel-$VARIANT"
  fi
done
KERN_ARCH=`uname -m`
KERN_REV=`echo $UNAME | sed s/.$KERN_ARCH//` # strip arch from uname
CANDIDATES="$KERNEL-$KERN_REV.$KERN_ARCH \
  $KERNEL-devel-$KERN_REV.$KERN_ARCH \
  $KERNEL-debuginfo-$KERN_REV.$KERN_ARCH \
  kernel-debuginfo-common-$KERN_REV.$KERN_ARCH"
NEEDED=`rpm --qf "%{name}-%{version}-%{release}.%{arch}\n" \
    -q $CANDIDATES | grep "is not installed" | awk '{print $2}'`
if [ "$NEEDED" != "" ]; then
    echo -e "Need to install the following packages:\n$NEEDED"
    if [ `id -u` = "0" ]; then #attempt download and install
        DIR=`mktemp -d` || exit 1
        yumdownloader --enablerepo="*debuginfo*" $NEEDED --destdir=$DIR
        check_error $? "problem downloading rpm(s) $NEEDED"
        rpm --force -ivh $DIR/*.rpm
        check_error $? "problem installing rpm(s) $NEEDED"
        rm -r $DIR #cleanup
    fi
fi

If you do not have yum and yum-utils installed (and you are unable to install them), you will have to manually download and install the required kernel information packages. To generate the URL from which to download the required packages, use the following script:

rheldebugurl.sh
#! /bin/bash
pkg="redhat-release"
releasever=`rpm -q --qf "%{version}" $pkg`
base=`uname -m`
echo "ftp://ftp.redhat.com/pub/redhat/linux/\
enterprise/$releasever/en/os/$base/Debuginfo"

Once you have manually downloaded the required packages to the machine, install the RPMs by running rpm --force -ivh package_names.