Using LTTng

The Linux Trace Toolkit project was started by Karim Yaghmour as a means of tracing kernel activity and was one of the first trace tools generally available for the Linux kernel. Later, Mathieu Desnoyers took up the idea and re-implemented it as the next generation trace tool, LTTng. It was then expanded to cover user space traces as well as the kernel. The project website is at http://lttng.org/ and contains a comprehensive user manual.

LTTng consists of three components:

In addition to those, you will need a trace viewer such as Babeltrace (http://www.efficios.com/babeltrace) or the Eclipse Trace Compaas plug-in to display and filter the raw trace data on the host or target.

LTTng requires a kernel configured with CONFIG_TRACEPOINTS, which is enabled when you select Kernel hacking | Tracers | Kernel Function Tracer.

The description that follows refers to LTTng version 2.5; other versions may be different.

You need to add these packages to the target dependencies, for example, in conf/local.conf:

If you want to run Babeltrace on the target, also append the package babeltrace.

You need to enable the following:

For user space trace tracing, enable this:

There is a package called lttng-babletrace for the target. Buildroot builds the host babeltrace automatically and places in output/host/usr/bin/babeltrace.

LTTng can use the set of ftrace events described above as potential trace points. Initially, they are disabled.

The control interface for LTTng is the lttng command. You can list the kernel probes using the following:

Traces are captured in the context of a session which, in this example, is called test:

Now enable a few events in the current session. You can enable all kernel tracepoints using the --all option but remember the warning about generating too much trace data. Let's start with a couple of scheduler-related trace events:

Check that everything is set up:

Now start tracing:

Run the test load and then stop tracing:

Traces for the session are written to the session directory, lttng-traces/<session>/kernel.

You can use the Babeltrace viewer to dump the raw trace data in text format, in this case, I ran it on the host computer:

The output is too verbose to fit on this page, so I will leave it as an exercise for you, the reader, to capture and display a trace in this way. The text output from eBabeltrace does have the advantage that it is easy to search for strings using grep and similar commands.

A good choice for a graphical trace viewer is the Trace Compass plug-in for Eclipse, which is now part of the Eclipse IDE for C/C++ Developers bundle. Importing the trace data into Eclipse is characteristically fiddly. Briefly, you need to follow these steps:

In the preceding screenshot, I have zoomed in on the control flow view to show state transitions between dropbear and a shell, and also some activity of the lttng daemon.