Technical Blog Post
Abstract
Howto tracing with LTTng
Body
Version 2.x offers several improvements in relation to previous 1.x series, including:
- Introduction of a new trace file format called CTF(Common Trace Format)
- Beyond default kernel events, it allows trace of user-space applications
- New implementation of ring buffer algorithm
- Able to attach context information to events
Building & installing
Note: In this section I will show how to build LTTng from source although it is already delivered in some Linux distributions, for instance, in RPM packages for pcc64 in OpenSuse Linux and Fedora 17. So you might want to use a stable version from your chosen distro or just build latest yourself.
Its source code is version'ed in different git trees, one for each component (see table 1).
Table 1. LTTng source components
|
Component |
Description |
GIT URL |
|---|---|---|
|
liburcu |
Library that implement RCU (Read-Copy-Update)mechanism in user-space |
git://git.lttng.org/userspace-rcu.git |
|
LTTng-Tools |
Provides main client that control execution of LTTng |
git://git.lttng.org/lttng-tools.git |
|
LTTng-modules |
Kernel modules for tracing kernel events. |
git://git.lttng.org/lttng-modules.git |
|
LTTng-UST |
Enable tracing in user-space |
git://git.lttng.org/lttng-ust.git |
# Cloning LTTng source code
#
$ git clone git://git.lttng.org/lttng-tools.git
$ git clone git://git.lttng.org/lttng-modules.git
$ git clone git://git.lttng.org/lttng-ust.git
$ git clone git://git.lttng.org/userspace-rcu.git
- Common to all are GNU Autotools and Libtool
- At the time this post is written, requires kernel >= 2.6.38 to build lttng-modules
- Some components rely on third-party libraries so take a look at README file in each component
# Buiding and installing liburcu library
#
$ cd userspace-rcu
$ ./bootstrap
$ ./configure
$ make
$ make install
$ sudo ldconfig
# Bulding and installing lttng-ust
#
$ cd lttng-ust
$ ./bootstrap
$ ./configure
$ make
$ make install
$ ldconfig
# Building and installing lttng-tools
#
$ cd lttng-tools
$ ./bootstrap
$ ./configure
$ make
$ make install
$ ldconfig
# Building and installing lttng-modules
#
$ cd lttng-modules
$ make
$ sudo make modules_install
$ sudo depmod -a
# Create group if it doesn't exist
$ sudo groupadd -r tracing
# Add <username> to the group
$ sudo usermod -aG tracing <username>
LTTng tracing relies on concept of session. The table 2 shows commands to manage a session lifecycle.
|
Command |
Description |
|---|---|
|
create NAME |
Create a session with NAME. By default, tracing files are held in ~/lttng-traces but it may be redefined with option -o |
|
set-session NAME |
Used to switch between sessions, setting current to NAME. |
|
start |
Start tracing |
|
stop |
Stop tracing |
|
destroy NAME |
Destroy the session with NAME. The option -a or –all may be used to destroy all the sessions. |
|
list NAME |
Show information regarding session with NAME or list all sessions if NAME is omitted. |
$ sudo lttng-sessiond &
$ lttng create demo_session
Session demo_session created.
Traces will be written in /home/wainersm/lttng-traces/demo_session-20121030-233238
$ lttng start
Tracing started for session demo_session
$ firefox &
$ lttng stop
Waiting for data availability
Tracing stopped for session demo_session
$ lttng destroy demo_session
Session demo_session destroyed
|
Comand |
Description |
|---|---|
|
list [-k] [-u] |
List available events of kernel (-k) and user-space (-u) |
|
enable-event [options] |
Add events to the session. The [options] filter which events should be traced. For example, “-a -k --syscall” is used to add syscall events. |
|
disable-event [opções] |
Remove events to the session. The [options]
filter which events should be removed. |
|
add-context -t [type] |
Add information context to an event. As of this post is written, [type] may be pid, procname, prio, nice, vpid, tid, pthread_id, vtid, ppid, vppid as well as available PMU events. |
$ lttng list -k
Kernel events:
-------------
timer_init (loglevel: TRACE_EMERG (0)) (type: tracepoint)
timer_start (loglevel: TRACE_EMERG (0)) (type: tracepoint)
timer_expire_entry (loglevel: TRACE_EMERG (0)) (type: tracepoint)
timer_expire_exit (loglevel: TRACE_EMERG (0)) (type: tracepoint)
timer_cancel (loglevel: TRACE_EMERG (0)) (type: tracepoint)
hrtimer_init (loglevel: TRACE_EMERG (0)) (type: tracepoint)
hrtimer_start (loglevel: TRACE_EMERG (0)) (type: tracepoint)
hrtimer_expire_entry (loglevel: TRACE_EMERG (0)) (type: tracepoint)
hrtimer_expire_exit (loglevel: TRACE_EMERG (0)) (type: tracepoint)
hrtimer_cancel (loglevel: TRACE_EMERG (0)) (type: tracepoint)
itimer_state (loglevel: TRACE_EMERG (0)) (type: tracepoint)
itimer_expire (loglevel: TRACE_EMERG (0)) (type: tracepoint)
lttng_statedump_start (loglevel: TRACE_EMERG (0)) (type: tracepoint)
lttng_statedump_end (loglevel: TRACE_EMERG (0)) (type: tracepoint)
lttng_statedump_process_state (loglevel: TRACE_EMERG (0)) (type: tracepoint)
lttng_statedump_file_descriptor (loglevel: TRACE_EMERG (0)) (type: tracepoint)
lttng_statedump_vm_map (loglevel: TRACE_EMERG (0)) (type: tracepoint)
lttng_statedump_network_interface (loglevel: TRACE_EMERG (0)) (type: tracepoint)
lttng_statedump_interrupt (loglevel: TRACE_EMERG (0)) (type: tracepoint)
signal_generate (loglevel: TRACE_EMERG (0)) (type: tracepoint)
signal_deliver (loglevel: TRACE_EMERG (0)) (type: tracepoint)
signal_overflow_fail (loglevel: TRACE_EMERG (0)) (type: tracepoint)
signal_lose_info (loglevel: TRACE_EMERG (0)) (type: tracepoint)
sched_kthread_stop (loglevel: TRACE_EMERG (0)) (type: tracepoint)
sched_kthread_stop_ret (loglevel: TRACE_EMERG (0)) (type: tracepoint)
sched_wakeup (loglevel: TRACE_EMERG (0)) (type: tracepoint)
sched_wakeup_new (loglevel: TRACE_EMERG (0)) (type: tracepoint)
(…)
The example below shows how to add all kernel events for tracing in a session:
$ lttng enable-event -a -k
All kernel events are enabled in channel channel0
- Babeltrace
- It is a library and command-line tool able to read and convert trace data stored in different formats (including CTF).
- LTTV Viewer
- It is a graphical visualizer (GTK+) able to make analysis of trace data produced by LTT, but it currently doesn't support CTF.
- Eclipse LTTng
- The Eclipse LTTng is a set of plug-ins able to visualize LTTng gathered data. Currently it is maintained by a pretty active community.
- LTTng project - https://lttng.org
- Eclipse LTTng plug-in - http://wiki.eclipse.org/Linux_Tools_Project/LTTng2/User_Guide
UID
ibm16171537
