Enable ftrace on Ubuntu Linux

Introduction

I was interested in using ftrace for a potential project, but didn’t find much documentation on how to get it working. I hope to change that by providing step-by-step instructions to enable ftrace for use in Ubuntu Linux 9.10 (Karmic Koala). Overview from the kernel documentation:

Ftrace is an internal tracer designed to help out developers and designers of systems to find what is going on inside the kernel. It can be used for debugging or analyzing latencies and performance issues that take place outside of user-space.

Given that ftrace is targeted towards developers and designers of systems, I’m assuming you more or less know what you’re doing with these steps. I also recommend virtualizing an instance of linux so that if you do mess up, you aren’t left with an un-bootable machine.

Steps

Download and install Ubuntu 9.10 Alpha-3

Run the following commands to install the necessary dependencies for a custom kernel:

$ sudo apt-get install git-core fakeroot build-essential makedumpfile kernel-wedge
$ sudo apt-get build-dep linux

Get the latest version of the Ubuntu kernel:

$ cd ~/
$ git clone git://kernel.ubuntu.com/ubuntu/ubuntu-karmic.git

edit “debian/config/config.common.ubuntu” and make the following changes:

CONFIG_FTRACE_SYSCALLS=y
CONFIG_FUNCTION_TRACER=y

Next, run the following commands:

$ sudo debian/rules clean
$ CONCURRENCY_LEVEL=2 AUTOBUILD=1 NOEXTRAS=1 fakeroot debian/rules binary-386

If you are prompted about enabling other forms of tracing, see ftrace.txt for more information about each type. You will want to enable DYNAMIC_FTRACE, which allows you to only trace functions you are concerned about.

Once finished, run the following commands from the parent directory :

$ sudo dpkg -i linux-image-2.6.31-5-386_2.6.31-5.24_i386.deb
$ sudo dpkg -i linux-headers-2.6.31-5-386_2.6.31-5.24_i386.deb
$ sudo update-grub

Restart your computer, and you should now see the kernel we compiled as a boot option:

The rest is outlined in LWN’s look at ftrace, but here are a few things I noticed:

  • You don’t have to mount a debugfs. There’s already one at /sys/kernel/debug (where it’s recommended to be).
  • I ran into some permission errors when trying to change what the current tracer was. Changing the owner or permissions of that directory should solve this issue.

To verify that everything is working, when you cat “/sys/kernel/debug/tracing/available_tracers” you should see more options than just “nop”. Enjoy!

Resources

This entry was posted in Operating Systems. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>