- Install SystemTap
- Install debug file
- Further Reading
About 2 months ago, I happened to read a book about how to learn OS principles by hands-on experience on Solaris with MDB and DTrace. After reading the chapters about memory management, I was totally impressed by MDB and DTrace. They acts like a microscope to help you look into the kernel. For example, you can walk through the data structures used by Solaris kernel to manage the process. You can even observe the memory related data structures and emulate the translation between virtual address and physical address manually. Then I became curious about if Linux has similar tools because I am pretty sure that it will be very helpful to understand the design and implementation of Linux kernel.
Since I have heard about SystemTap before, so after googling “systemtap ubuntu”, I found several articles about how to install SystemTap in Ubuntu. However, those are kind of outdated even the one posted in the SystemTap’s homepage. For example, some complicated steps are not needed anymore while some are not applicable when working with latest kernel. So I decided to write down this experience. The environment is a Ubuntu 14.04(trust) box running in DigitalOcean with 3.13.0-36-generic kernel image.
SystemTap 2.3 is available in the apt source thus it can be installed simply with
apt-get. Gcc is also required since the SystemTap script will be translated into C source code which will be compiled as kernel module finally.
1 2 3
Test the installation with the HelloWorld example:
You should see
Hello, World! is emitted in the console.
Install debug file
SystemTap is a powerful trace tool. Let’s see another example which will print
hello world to the console when the system call
sys_call is called.
It is likely to end with the error information:
1 2 3 4 5 6
The debug symbols are required to solve this problem. You can following the instruction in the Ubuntu Wiki.
You can also install the symbols manually if you failed by following above instructions. Goto ddeb and find a symbol file matched your kernel. If you are not able to find a matched symbol file, I suggest you upgrade your linux kernel or you will have to build it by yourself.
build directory not found
/lib/modules/3.13.0-36-generic/build is actually a soft link to the linux header files directory. This error is not supposed to appear because when you install the headers by
sudo apt-get install linux-headers-$(uname -r), the soft link will be created automatically. But if you are as unlucky as me, please install the linux headers and make sure the
build links to
disktop.stp does not work
SystemTap is also shipped with some examples.
disktop.top is a SystemTap script used to get the status of reading/writing. If you use the SystemTap provided by the apt software repository, the following error is likely to occur.
1 2 3 4 5 6 7 8 9
This is probably a bug. One way to fix it is building SystemTap from source.
1 2 3 4 5 6 7 8 9
pass 4 compile error
This is the most weird issue I have met. Almost all the examples can’t work and SystemTap keeps complaing
pass 4: compilation failed. [man error::pass4]. That means the SystemTap script can be translated into C source code which can also be compile as a kernel module. However, it fails to load the kernel module. After downgrading the kernel from 3.13.0-36 to 3.13.0-32, I found ever thing is ok. After I switched back to 3.13.0-36, however, nothing is wrong. If you meet similar issue, try to clean the symbols file, linux headers and switch to other kernel version with matched debug symbol files and linux headers.
Getting Started with SystemTap: A introduction with simple examples. It is simple and thus good for beginners.
SystemTap Beginners Guid: SystemTap guide from Red Hat planned for beginners
SystemTap on CentOS: Detail how to install SystemTap in CentOS. I followed the step on a CentOS 6.5 box. The whole process was very smooth. Every thing is fine including the disktop example.
SystemTap examples: Examples from SystemTap’s homepage