1 The LTTng Documentation
2 =======================
3 Philippe Proulx <pproulx@efficios.com>
7 include::../common/copyright.txt[]
10 include::../common/welcome.txt[]
13 include::../common/audience.txt[]
17 === What's in this documentation?
19 The LTTng Documentation is divided into the following sections:
21 * **<<nuts-and-bolts,Nuts and bolts>>** explains the
22 rudiments of software tracing and the rationale behind the
25 You can skip this section if you’re familiar with software tracing and
26 with the LTTng project.
28 * **<<installing-lttng,Installation>>** describes the steps to
29 install the LTTng packages on common Linux distributions and from
32 You can skip this section if you already properly installed LTTng on
35 * **<<getting-started,Quick start>>** is a concise guide to
36 getting started quickly with LTTng kernel and user space tracing.
38 We recommend this section if you're new to LTTng or to software tracing
41 You can skip this section if you're not new to LTTng.
43 * **<<core-concepts,Core concepts>>** explains the concepts at
46 It's a good idea to become familiar with the core concepts
47 before attempting to use the toolkit.
49 * **<<plumbing,Components of LTTng>>** describes the various components
50 of the LTTng machinery, like the daemons, the libraries, and the
51 command-line interface.
52 * **<<instrumenting,Instrumentation>>** shows different ways to
53 instrument user applications and the Linux kernel.
55 Instrumenting source code is essential to provide a meaningful
58 You can skip this section if you do not have a programming background.
60 * **<<controlling-tracing,Tracing control>>** is divided into topics
61 which demonstrate how to use the vast array of features that
62 LTTng{nbsp}{revision} offers.
63 * **<<reference,Reference>>** contains reference tables.
64 * **<<glossary,Glossary>>** is a specialized dictionary of terms related
65 to LTTng or to the field of software tracing.
68 include::../common/convention.txt[]
71 include::../common/acknowledgements.txt[]
75 == What's new in LTTng {revision}?
77 LTTng{nbsp}{revision} bears the name _Joannès_. A Berliner Weisse style
78 beer from the http://letreflenoir.com/[Trèfle Noir] microbrewery in
79 https://en.wikipedia.org/wiki/Rouyn-Noranda[Rouyn-Noranda], the
80 https://www.beeradvocate.com/beer/profile/20537/238967/[_**Joannès**_]
81 is a tangy beer with a distinct pink dress and intense fruit flavor,
82 thanks to the presence of fresh blackcurrant grown in Témiscamingue.
84 New features and changes in LTTng{nbsp}{revision}:
86 * **Tracing control**:
87 ** You can override the name or the URL of a tracing session
88 configuration when you use man:lttng-load(1) thanks to the new
89 opt:lttng-load(1):--override-name and
90 opt:lttng-load(1):--override-url options.
91 ** The new `lttng regenerate` command replaces the now deprecated
92 `lttng metadata` command of LTTng 2.8. man:lttng-regenerate(1) can
93 also <<regenerate-statedump,generate the state dump event records>>
94 of a given tracing session on demand, a handy feature when
95 <<taking-a-snapshot,taking a snapshot>>.
96 ** You can add PMU counters by raw ID with man:lttng-add-context(1):
101 $ lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted
105 The format of the raw ID is the same as used with man:perf-record(1).
106 See <<adding-context,Add context fields to a channel>> for more
109 ** The LTTng <<lttng-relayd,relay daemon>> is now supported on
110 OS{nbsp}X and macOS for a smoother integration within a trace
111 analysis workflow, regardless of the platform used.
113 * **User space tracing**:
114 ** Improved performance (tested on x86-64 and ARMv7-A
115 (https://en.wikipedia.org/wiki/Cubieboard[Cubieboard])
117 ** New helper library (`liblttng-ust-fd`) to help with
118 <<liblttng-ust-fd,applications which close file descriptors that
119 don't belong to them>>, for example, in a loop which closes file
120 descriptors after man:fork(2), or BSD's `closeall()`.
121 ** More accurate <<liblttng-ust-dl,dynamic linker instrumentation>> and
122 state dump event records, especially when a dynamically loaded
123 library manually loads its own dependencies.
124 ** New `ctf_*()` field definition macros (see man:lttng-ust(3)):
125 *** `ctf_array_hex()`
126 *** `ctf_array_network()`
127 *** `ctf_array_network_hex()`
128 *** `ctf_sequence_hex()`
129 *** `ctf_sequence_network()`
130 *** `ctf_sequence_network_hex()`
131 ** New `lttng_ust_loaded` weak symbol defined by `liblttng-ust` for
132 an application to know if the LTTng-UST shared library is loaded
140 int lttng_ust_loaded __attribute__((weak));
144 if (lttng_ust_loaded) {
145 puts("LTTng-UST is loaded!");
147 puts("LTTng-UST is not loaded!");
155 ** LTTng-UST thread names have the `-ust` suffix.
157 * **Linux kernel tracing**:
158 ** Improved performance (tested on x86-64 and ARMv7-A
159 (https://en.wikipedia.org/wiki/Cubieboard[Cubieboard])
161 ** New enumeration <<lttng-modules-tp-fields,field definition macros>>:
162 `ctf_enum()` and `ctf_user_enum()`.
163 ** IPv4, IPv6, and TCP header data is recorded in the event records
164 produced by tracepoints starting with `net_`.
165 ** Detailed system call event records: `select`, `pselect6`, `poll`,
166 `ppoll`, `epoll_wait`, `epoll_pwait`, and `epoll_ctl` on all
167 architectures supported by LTTng-modules, and `accept4` on x86-64.
168 ** New I²C instrumentation: the `extract_sensitive_payload` parameter
169 of the new `lttng-probe-i2c` LTTng module controls whether or not
170 the payloads of I²C messages are recorded in I²C event records, since
171 they may contain sensitive data (for example, keystrokes).
172 ** When the LTTng kernel modules are built into the Linux kernel image,
173 the `CONFIG_TRACEPOINTS` configuration option is automatically
180 What is LTTng? As its name suggests, the _Linux Trace Toolkit: next
181 generation_ is a modern toolkit for tracing Linux systems and
182 applications. So your first question might be:
189 As the history of software engineering progressed and led to what
190 we now take for granted--complex, numerous and
191 interdependent software applications running in parallel on
192 sophisticated operating systems like Linux--the authors of such
193 components, software developers, began feeling a natural
194 urge to have tools that would ensure the robustness and good performance
195 of their masterpieces.
197 One major achievement in this field is, inarguably, the
198 https://www.gnu.org/software/gdb/[GNU debugger (GDB)],
199 an essential tool for developers to find and fix bugs. But even the best
200 debugger won't help make your software run faster, and nowadays, faster
201 software means either more work done by the same hardware, or cheaper
202 hardware for the same work.
204 A _profiler_ is often the tool of choice to identify performance
205 bottlenecks. Profiling is suitable to identify _where_ performance is
206 lost in a given software. The profiler outputs a profile, a statistical
207 summary of observed events, which you may use to discover which
208 functions took the most time to execute. However, a profiler won't
209 report _why_ some identified functions are the bottleneck. Bottlenecks
210 might only occur when specific conditions are met, conditions that are
211 sometimes impossible to capture by a statistical profiler, or impossible
212 to reproduce with an application altered by the overhead of an
213 event-based profiler. For a thorough investigation of software
214 performance issues, a history of execution is essential, with the
215 recorded values of variables and context fields you choose, and
216 with as little influence as possible on the instrumented software. This
217 is where tracing comes in handy.
219 _Tracing_ is a technique used to understand what goes on in a running
220 software system. The software used for tracing is called a _tracer_,
221 which is conceptually similar to a tape recorder. When recording,
222 specific instrumentation points placed in the software source code
223 generate events that are saved on a giant tape: a _trace_ file. You
224 can trace user applications and the operating system at the same time,
225 opening the possibility of resolving a wide range of problems that would
226 otherwise be extremely challenging.
228 Tracing is often compared to _logging_. However, tracers and loggers are
229 two different tools, serving two different purposes. Tracers are
230 designed to record much lower-level events that occur much more
231 frequently than log messages, often in the range of thousands per
232 second, with very little execution overhead. Logging is more appropriate
233 for a very high-level analysis of less frequent events: user accesses,
234 exceptional conditions (errors and warnings, for example), database
235 transactions, instant messaging communications, and such. Simply put,
236 logging is one of the many use cases that can be satisfied with tracing.
238 The list of recorded events inside a trace file can be read manually
239 like a log file for the maximum level of detail, but it is generally
240 much more interesting to perform application-specific analyses to
241 produce reduced statistics and graphs that are useful to resolve a
242 given problem. Trace viewers and analyzers are specialized tools
245 In the end, this is what LTTng is: a powerful, open source set of
246 tools to trace the Linux kernel and user applications at the same time.
247 LTTng is composed of several components actively maintained and
248 developed by its link:/community/#where[community].
251 [[lttng-alternatives]]
252 === Alternatives to noch:{LTTng}
254 Excluding proprietary solutions, a few competing software tracers
257 * https://github.com/dtrace4linux/linux[dtrace4linux] is a port of
258 Sun Microsystems's DTrace to Linux. The cmd:dtrace tool interprets
259 user scripts and is responsible for loading code into the
260 Linux kernel for further execution and collecting the outputted data.
261 * https://en.wikipedia.org/wiki/Berkeley_Packet_Filter[eBPF] is a
262 subsystem in the Linux kernel in which a virtual machine can execute
263 programs passed from the user space to the kernel. You can attach
264 such programs to tracepoints and KProbes thanks to a system call, and
265 they can output data to the user space when executed thanks to
266 different mechanisms (pipe, VM register values, and eBPF maps, to name
268 * https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace]
269 is the de facto function tracer of the Linux kernel. Its user
270 interface is a set of special files in sysfs.
271 * https://perf.wiki.kernel.org/[perf] is
272 a performance analyzing tool for Linux which supports hardware
273 performance counters, tracepoints, as well as other counters and
274 types of probes. perf's controlling utility is the cmd:perf command
276 * http://linux.die.net/man/1/strace[strace]
277 is a command-line utility which records system calls made by a
278 user process, as well as signal deliveries and changes of process
279 state. strace makes use of https://en.wikipedia.org/wiki/Ptrace[ptrace]
280 to fulfill its function.
281 * http://www.sysdig.org/[sysdig], like SystemTap, uses scripts to
282 analyze Linux kernel events. You write scripts, or _chisels_ in
283 sysdig's jargon, in Lua and sysdig executes them while the system is
284 being traced or afterwards. sysdig's interface is the cmd:sysdig
285 command-line tool as well as the curses-based cmd:csysdig tool.
286 * https://sourceware.org/systemtap/[SystemTap] is a Linux kernel and
287 user space tracer which uses custom user scripts to produce plain text
288 traces. SystemTap converts the scripts to the C language, and then
289 compiles them as Linux kernel modules which are loaded to produce
290 trace data. SystemTap's primary user interface is the cmd:stap
293 The main distinctive features of LTTng is that it produces correlated
294 kernel and user space traces, as well as doing so with the lowest
295 overhead amongst other solutions. It produces trace files in the
296 http://diamon.org/ctf[CTF] format, a file format optimized
297 for the production and analyses of multi-gigabyte data.
299 LTTng is the result of more than 10 years of active open source
300 development by a community of passionate developers.
301 LTTng{nbsp}{revision} is currently available on major desktop and server
304 The main interface for tracing control is a single command-line tool
305 named cmd:lttng. The latter can create several tracing sessions, enable
306 and disable events on the fly, filter events efficiently with custom
307 user expressions, start and stop tracing, and much more. LTTng can
308 record the traces on the file system or send them over the network, and
309 keep them totally or partially. You can view the traces once tracing
310 becomes inactive or in real-time.
312 <<installing-lttng,Install LTTng now>> and
313 <<getting-started,start tracing>>!
319 **LTTng** is a set of software <<plumbing,components>> which interact to
320 <<instrumenting,instrument>> the Linux kernel and user applications, and
321 to <<controlling-tracing,control tracing>> (start and stop
322 tracing, enable and disable event rules, and the rest). Those
323 components are bundled into the following packages:
325 * **LTTng-tools**: Libraries and command-line interface to
327 * **LTTng-modules**: Linux kernel modules to instrument and
329 * **LTTng-UST**: Libraries and Java/Python packages to instrument and
330 trace user applications.
332 Most distributions mark the LTTng-modules and LTTng-UST packages as
333 optional when installing LTTng-tools (which is always required). In the
334 following sections, we always provide the steps to install all three,
337 * You only need to install LTTng-modules if you intend to trace the
339 * You only need to install LTTng-UST if you intend to trace user
343 .Availability of LTTng{nbsp}{revision} for major Linux distributions as of 3 October 2017.
345 |Distribution |Available in releases |Alternatives
347 |https://www.ubuntu.com/[Ubuntu]
348 |<<ubuntu,Ubuntu{nbsp}17.04 _Zesty Zapus_ and Ubuntu{nbsp}17.10 _Artful Aardvark_>>.
350 Ubuntu{nbsp}14.04 _Trusty Tahr_ and Ubuntu{nbsp}16.04 _Xenial Xerus_:
351 <<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>.
352 |<<building-from-source,Build LTTng{nbsp}{revision} from source>> for
353 other Ubuntu releases.
355 |https://getfedora.org/[Fedora]
356 |<<fedora,Fedora{nbsp}26>>.
357 |link:/docs/v2.10#doc-fedora[LTTng{nbsp}2.10 for Fedora 27].
359 <<building-from-source,Build LTTng{nbsp}{revision} from source>> for
360 other Fedora releases.
362 |https://www.debian.org/[Debian]
363 |<<debian,Debian "stretch" (stable)>>.
364 |<<building-from-source,Build LTTng{nbsp}{revision} from source>> for
365 other Debian releases.
367 |https://www.archlinux.org/[Arch Linux]
369 |link:/docs/v2.10#doc-arch-linux[LTTng{nbsp}2.10 for the current Arch Linux build].
371 <<building-from-source,Build LTTng{nbsp}{revision} from source>>.
373 |https://alpinelinux.org/[Alpine Linux]
374 |<<alpine-linux,Alpine Linux "edge">>.
375 |<<building-from-source,Build LTTng{nbsp}{revision} from source>> for
376 other Alpine Linux releases.
378 |https://www.redhat.com/[RHEL] and https://www.suse.com/[SLES]
379 |See http://packages.efficios.com/[EfficiOS Enterprise Packages].
382 |https://buildroot.org/[Buildroot]
383 |<<"buildroot", "Buildroot{nbsp}2017.02, Buildroot{nbsp}2017.05, and Buildroot{nbsp}2017.08">>.
384 |link:/docs/v2.8#doc-buildroot[LTTng{nbsp}2.8 for Buildroot{nbsp}2016.11].
386 <<building-from-source,Build LTTng{nbsp}{revision} from source>> for
387 other Buildroot releases.
389 |http://www.openembedded.org/wiki/Main_Page[OpenEmbedded] and
390 https://www.yoctoproject.org/[Yocto]
391 |<<oe-yocto,Yocto Project{nbsp}2.3 _Pyro_>> (`openembedded-core` layer).
392 |link:/docs/v2.8#doc-oe-yocto[LTTng{nbsp}2.8 for Yocto Project{nbsp}2.2 _Morty_]
393 (`openembedded-core` layer).
395 <<building-from-source,Build LTTng{nbsp}{revision} from source>> for
396 other OpenEmbedded releases.
401 === [[ubuntu-official-repositories]]Ubuntu
403 LTTng{nbsp}{revision} is available on Ubuntu{nbsp}17.04 _Zesty Zapus_
404 and Ubuntu{nbsp}17.10 _Artful Aardvark_. For previous releases of
405 Ubuntu, <<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>.
407 To install LTTng{nbsp}{revision} on Ubuntu{nbsp}17.04 _Zesty Zapus_:
409 . Install the main LTTng{nbsp}{revision} packages:
414 # apt-get install lttng-tools
415 # apt-get install lttng-modules-dkms
416 # apt-get install liblttng-ust-dev
420 . **If you need to instrument and trace
421 <<java-application,Java applications>>**, install the LTTng-UST
427 # apt-get install liblttng-ust-agent-java
431 . **If you need to instrument and trace
432 <<python-application,Python{nbsp}3 applications>>**, install the
433 LTTng-UST Python agent:
438 # apt-get install python3-lttngust
444 ==== noch:{LTTng} Stable {revision} PPA
446 The https://launchpad.net/~lttng/+archive/ubuntu/stable-{revision}[LTTng
447 Stable{nbsp}{revision} PPA] offers the latest stable
448 LTTng{nbsp}{revision} packages for:
450 * Ubuntu{nbsp}14.04 _Trusty Tahr_
451 * Ubuntu{nbsp}16.04 _Xenial Xerus_
453 To install LTTng{nbsp}{revision} from the LTTng Stable{nbsp}{revision} PPA:
455 . Add the LTTng Stable{nbsp}{revision} PPA repository and update the
461 # apt-add-repository ppa:lttng/stable-2.9
466 . Install the main LTTng{nbsp}{revision} packages:
471 # apt-get install lttng-tools
472 # apt-get install lttng-modules-dkms
473 # apt-get install liblttng-ust-dev
477 . **If you need to instrument and trace
478 <<java-application,Java applications>>**, install the LTTng-UST
484 # apt-get install liblttng-ust-agent-java
488 . **If you need to instrument and trace
489 <<python-application,Python{nbsp}3 applications>>**, install the
490 LTTng-UST Python agent:
495 # apt-get install python3-lttngust
503 To install LTTng{nbsp}{revision} on Fedora{nbsp}26:
505 . Install the LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision}
511 # yum install lttng-tools
512 # yum install lttng-ust
516 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
522 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.9.tar.bz2 &&
523 tar -xf lttng-modules-latest-2.9.tar.bz2 &&
524 cd lttng-modules-2.9.* &&
526 sudo make modules_install &&
532 .Java and Python application instrumentation and tracing
534 If you need to instrument and trace <<java-application,Java
535 applications>> on Fedora, you need to build and install
536 LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass
537 the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or
538 `--enable-java-agent-all` options to the `configure` script, depending
539 on which Java logging framework you use.
541 If you need to instrument and trace <<python-application,Python
542 applications>> on Fedora, you need to build and install
543 LTTng-UST{nbsp}{revision} from source and pass the
544 `--enable-python-agent` option to the `configure` script.
551 To install LTTng{nbsp}{revision} on Debian "stretch" (stable):
553 . Install the main LTTng{nbsp}{revision} packages:
558 # apt-get install lttng-modules-dkms
559 # apt-get install liblttng-ust-dev
560 # apt-get install lttng-tools
564 . **If you need to instrument and trace <<java-application,Java
565 applications>>**, install the LTTng-UST Java agent:
570 # apt-get install liblttng-ust-agent-java
574 . **If you need to instrument and trace <<python-application,Python
575 applications>>**, install the LTTng-UST Python agent:
580 # apt-get install python3-lttngust
588 To install LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision} on
591 . Make sure your system is
592 https://wiki.alpinelinux.org/wiki/Edge[configured for "edge"].
593 . Enable the _testing_ repository by uncommenting the corresponding
594 line in path:{/etc/apk/repositories}.
595 . Add the LTTng packages:
600 # apk add lttng-tools
601 # apk add lttng-ust-dev
605 To install LTTng-modules{nbsp}{revision} (Linux kernel tracing support)
606 on Alpine Linux "edge":
608 . Add the vanilla Linux kernel:
613 # apk add linux-vanilla linux-vanilla-dev
617 . Reboot with the vanilla Linux kernel.
618 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
624 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.9.tar.bz2 &&
625 tar -xf lttng-modules-latest-2.9.tar.bz2 &&
626 cd lttng-modules-2.9.* &&
628 sudo make modules_install &&
634 [[enterprise-distributions]]
635 === RHEL, SUSE, and other enterprise distributions
637 To install LTTng on enterprise Linux distributions, such as Red Hat
638 Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SUSE), please
639 see http://packages.efficios.com/[EfficiOS Enterprise Packages].
645 To install LTTng{nbsp}{revision} on Buildroot{nbsp}2017.02,
646 Buildroot{nbsp}2017.05, or Buildroot{nbsp}2017.08:
648 . Launch the Buildroot configuration tool:
657 . In **Kernel**, check **Linux kernel**.
658 . In **Toolchain**, check **Enable WCHAR support**.
659 . In **Target packages**{nbsp}→ **Debugging, profiling and benchmark**,
660 check **lttng-modules** and **lttng-tools**.
661 . In **Target packages**{nbsp}→ **Libraries**{nbsp}→
662 **Other**, check **lttng-libust**.
666 === OpenEmbedded and Yocto
668 LTTng{nbsp}{revision} recipes are available in the
669 http://layers.openembedded.org/layerindex/branch/master/layer/openembedded-core/[`openembedded-core`]
670 layer for Yocto Project{nbsp}2.3 _Pyro_ under the following names:
676 With BitBake, the simplest way to include LTTng recipes in your target
677 image is to add them to `IMAGE_INSTALL_append` in path:{conf/local.conf}:
680 IMAGE_INSTALL_append = " lttng-tools lttng-modules lttng-ust"
685 . Select a machine and an image recipe.
686 . Click **Edit image recipe**.
687 . Under the **All recipes** tab, search for **lttng**.
688 . Check the desired LTTng recipes.
691 .Java and Python application instrumentation and tracing
693 If you need to instrument and trace <<java-application,Java
694 applications>> on Yocto/OpenEmbedded, you need to build and install
695 LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass
696 the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or
697 `--enable-java-agent-all` options to the `configure` script, depending
698 on which Java logging framework you use.
700 If you need to instrument and trace <<python-application,Python
701 applications>> on Yocto/OpenEmbedded, you need to build and install
702 LTTng-UST{nbsp}{revision} from source and pass the
703 `--enable-python-agent` option to the `configure` script.
707 [[building-from-source]]
708 === Build from source
710 To build and install LTTng{nbsp}{revision} from source:
712 . Using your distribution's package manager, or from source, install
713 the following dependencies of LTTng-tools and LTTng-UST:
716 * https://sourceforge.net/projects/libuuid/[libuuid]
717 * http://directory.fsf.org/wiki/Popt[popt]
718 * http://liburcu.org/[Userspace RCU]
719 * http://www.xmlsoft.org/[libxml2]
722 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
728 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.9.tar.bz2 &&
729 tar -xf lttng-modules-latest-2.9.tar.bz2 &&
730 cd lttng-modules-2.9.* &&
732 sudo make modules_install &&
737 . Download, build, and install the latest LTTng-UST{nbsp}{revision}:
743 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.9.tar.bz2 &&
744 tar -xf lttng-ust-latest-2.9.tar.bz2 &&
745 cd lttng-ust-2.9.* &&
755 .Java and Python application tracing
757 If you need to instrument and trace <<java-application,Java
758 applications>>, pass the `--enable-java-agent-jul`,
759 `--enable-java-agent-log4j`, or `--enable-java-agent-all` options to the
760 `configure` script, depending on which Java logging framework you use.
762 If you need to instrument and trace <<python-application,Python
763 applications>>, pass the `--enable-python-agent` option to the
764 `configure` script. You can set the `PYTHON` environment variable to the
765 path to the Python interpreter for which to install the LTTng-UST Python
773 By default, LTTng-UST libraries are installed to
774 dir:{/usr/local/lib}, which is the de facto directory in which to
775 keep self-compiled and third-party libraries.
777 When <<building-tracepoint-providers-and-user-application,linking an
778 instrumented user application with `liblttng-ust`>>:
780 * Append `/usr/local/lib` to the env:LD_LIBRARY_PATH environment
782 * Pass the `-L/usr/local/lib` and `-Wl,-rpath,/usr/local/lib` options to
783 man:gcc(1), man:g++(1), or man:clang(1).
787 . Download, build, and install the latest LTTng-tools{nbsp}{revision}:
793 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.9.tar.bz2 &&
794 tar -xf lttng-tools-latest-2.9.tar.bz2 &&
795 cd lttng-tools-2.9.* &&
803 TIP: The https://github.com/eepp/vlttng[vlttng tool] can do all the
804 previous steps automatically for a given version of LTTng and confine
805 the installed files in a specific directory. This can be useful to test
806 LTTng without installing it on your system.
812 This is a short guide to get started quickly with LTTng kernel and user
815 Before you follow this guide, make sure to <<installing-lttng,install>>
818 This tutorial walks you through the steps to:
820 . <<tracing-the-linux-kernel,Trace the Linux kernel>>.
821 . <<tracing-your-own-user-application,Trace a user application>> written
823 . <<viewing-and-analyzing-your-traces,View and analyze the
827 [[tracing-the-linux-kernel]]
828 === Trace the Linux kernel
830 The following command lines start with the `#` prompt because you need
831 root privileges to trace the Linux kernel. You can also trace the kernel
832 as a regular user if your Unix user is a member of the
833 <<tracing-group,tracing group>>.
835 . Create a <<tracing-session,tracing session>> which writes its traces
836 to dir:{/tmp/my-kernel-trace}:
841 # lttng create my-kernel-session --output=/tmp/my-kernel-trace
845 . List the available kernel tracepoints and system calls:
850 # lttng list --kernel
851 # lttng list --kernel --syscall
855 . Create <<event,event rules>> which match the desired instrumentation
856 point names, for example the `sched_switch` and `sched_process_fork`
857 tracepoints, and the man:open(2) and man:close(2) system calls:
862 # lttng enable-event --kernel sched_switch,sched_process_fork
863 # lttng enable-event --kernel --syscall open,close
867 You can also create an event rule which matches _all_ the Linux kernel
868 tracepoints (this will generate a lot of data when tracing):
873 # lttng enable-event --kernel --all
877 . <<basic-tracing-session-control,Start tracing>>:
886 . Do some operation on your system for a few seconds. For example,
887 load a website, or list the files of a directory.
888 . <<basic-tracing-session-control,Stop tracing>> and destroy the
899 The man:lttng-destroy(1) command does not destroy the trace data; it
900 only destroys the state of the tracing session.
902 . For the sake of this example, make the recorded trace accessible to
908 # chown -R $(whoami) /tmp/my-kernel-trace
912 See <<viewing-and-analyzing-your-traces,View and analyze the
913 recorded events>> to view the recorded events.
916 [[tracing-your-own-user-application]]
917 === Trace a user application
919 This section steps you through a simple example to trace a
920 _Hello world_ program written in C.
922 To create the traceable user application:
924 . Create the tracepoint provider header file, which defines the
925 tracepoints and the events they can generate:
931 #undef TRACEPOINT_PROVIDER
932 #define TRACEPOINT_PROVIDER hello_world
934 #undef TRACEPOINT_INCLUDE
935 #define TRACEPOINT_INCLUDE "./hello-tp.h"
937 #if !defined(_HELLO_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
940 #include <lttng/tracepoint.h>
950 ctf_string(my_string_field, my_string_arg)
951 ctf_integer(int, my_integer_field, my_integer_arg)
955 #endif /* _HELLO_TP_H */
957 #include <lttng/tracepoint-event.h>
961 . Create the tracepoint provider package source file:
967 #define TRACEPOINT_CREATE_PROBES
968 #define TRACEPOINT_DEFINE
970 #include "hello-tp.h"
974 . Build the tracepoint provider package:
979 $ gcc -c -I. hello-tp.c
983 . Create the _Hello World_ application source file:
990 #include "hello-tp.h"
992 int main(int argc, char *argv[])
996 puts("Hello, World!\nPress Enter to continue...");
999 * The following getchar() call is only placed here for the purpose
1000 * of this demonstration, to pause the application in order for
1001 * you to have time to list its tracepoints. It is not
1007 * A tracepoint() call.
1009 * Arguments, as defined in hello-tp.h:
1011 * 1. Tracepoint provider name (required)
1012 * 2. Tracepoint name (required)
1013 * 3. my_integer_arg (first user-defined argument)
1014 * 4. my_string_arg (second user-defined argument)
1016 * Notice the tracepoint provider and tracepoint names are
1017 * NOT strings: they are in fact parts of variables that the
1018 * macros in hello-tp.h create.
1020 tracepoint(hello_world, my_first_tracepoint, 23, "hi there!");
1022 for (x = 0; x < argc; ++x) {
1023 tracepoint(hello_world, my_first_tracepoint, x, argv[x]);
1026 puts("Quitting now!");
1027 tracepoint(hello_world, my_first_tracepoint, x * x, "x^2");
1034 . Build the application:
1043 . Link the application with the tracepoint provider package,
1044 `liblttng-ust`, and `libdl`:
1049 $ gcc -o hello hello.o hello-tp.o -llttng-ust -ldl
1053 Here's the whole build process:
1056 .User space tracing tutorial's build steps.
1057 image::ust-flow.png[]
1059 To trace the user application:
1061 . Run the application with a few arguments:
1066 $ ./hello world and beyond
1075 Press Enter to continue...
1079 . Start an LTTng <<lttng-sessiond,session daemon>>:
1084 $ lttng-sessiond --daemonize
1088 Note that a session daemon might already be running, for example as
1089 a service that the distribution's service manager started.
1091 . List the available user space tracepoints:
1096 $ lttng list --userspace
1100 You see the `hello_world:my_first_tracepoint` tracepoint listed
1101 under the `./hello` process.
1103 . Create a <<tracing-session,tracing session>>:
1108 $ lttng create my-user-space-session
1112 . Create an <<event,event rule>> which matches the
1113 `hello_world:my_first_tracepoint` event name:
1118 $ lttng enable-event --userspace hello_world:my_first_tracepoint
1122 . <<basic-tracing-session-control,Start tracing>>:
1131 . Go back to the running `hello` application and press Enter. The
1132 program executes all `tracepoint()` instrumentation points and exits.
1133 . <<basic-tracing-session-control,Stop tracing>> and destroy the
1144 The man:lttng-destroy(1) command does not destroy the trace data; it
1145 only destroys the state of the tracing session.
1147 By default, LTTng saves the traces in
1148 +$LTTNG_HOME/lttng-traces/__name__-__date__-__time__+,
1149 where +__name__+ is the tracing session name. The
1150 env:LTTNG_HOME environment variable defaults to `$HOME` if not set.
1152 See <<viewing-and-analyzing-your-traces,View and analyze the
1153 recorded events>> to view the recorded events.
1156 [[viewing-and-analyzing-your-traces]]
1157 === View and analyze the recorded events
1159 Once you have completed the <<tracing-the-linux-kernel,Trace the Linux
1160 kernel>> and <<tracing-your-own-user-application,Trace a user
1161 application>> tutorials, you can inspect the recorded events.
1163 Many tools are available to read LTTng traces:
1165 * **cmd:babeltrace** is a command-line utility which converts trace
1166 formats; it supports the format that LTTng produces, CTF, as well as a
1167 basic text output which can be ++grep++ed. The cmd:babeltrace command
1168 is part of the http://diamon.org/babeltrace[Babeltrace] project.
1169 * Babeltrace also includes
1170 **https://www.python.org/[Python] bindings** so
1171 that you can easily open and read an LTTng trace with your own script,
1172 benefiting from the power of Python.
1173 * http://tracecompass.org/[**Trace Compass**]
1174 is a graphical user interface for viewing and analyzing any type of
1175 logs or traces, including LTTng's.
1176 * https://github.com/lttng/lttng-analyses[**LTTng analyses**] is a
1177 project which includes many high-level analyses of LTTng kernel
1178 traces, like scheduling statistics, interrupt frequency distribution,
1179 top CPU usage, and more.
1181 NOTE: This section assumes that the traces recorded during the previous
1182 tutorials were saved to their default location, in the
1183 dir:{$LTTNG_HOME/lttng-traces} directory. The env:LTTNG_HOME
1184 environment variable defaults to `$HOME` if not set.
1187 [[viewing-and-analyzing-your-traces-bt]]
1188 ==== Use the cmd:babeltrace command-line tool
1190 The simplest way to list all the recorded events of a trace is to pass
1191 its path to cmd:babeltrace with no options:
1195 $ babeltrace ~/lttng-traces/my-user-space-session*
1198 cmd:babeltrace finds all traces recursively within the given path and
1199 prints all their events, merging them in chronological order.
1201 You can pipe the output of cmd:babeltrace into a tool like man:grep(1) for
1206 $ babeltrace /tmp/my-kernel-trace | grep _switch
1209 You can pipe the output of cmd:babeltrace into a tool like man:wc(1) to
1210 count the recorded events:
1214 $ babeltrace /tmp/my-kernel-trace | grep _open | wc --lines
1218 [[viewing-and-analyzing-your-traces-bt-python]]
1219 ==== Use the Babeltrace Python bindings
1221 The <<viewing-and-analyzing-your-traces-bt,text output of cmd:babeltrace>>
1222 is useful to isolate events by simple matching using man:grep(1) and
1223 similar utilities. However, more elaborate filters, such as keeping only
1224 event records with a field value falling within a specific range, are
1225 not trivial to write using a shell. Moreover, reductions and even the
1226 most basic computations involving multiple event records are virtually
1227 impossible to implement.
1229 Fortunately, Babeltrace ships with Python 3 bindings which makes it easy
1230 to read the event records of an LTTng trace sequentially and compute the
1231 desired information.
1233 The following script accepts an LTTng Linux kernel trace path as its
1234 first argument and prints the short names of the top 5 running processes
1235 on CPU 0 during the whole trace:
1240 from collections import Counter
1246 if len(sys.argv) != 2:
1247 msg = 'Usage: python3 {} TRACEPATH'.format(sys.argv[0])
1248 print(msg, file=sys.stderr)
1251 # A trace collection contains one or more traces
1252 col = babeltrace.TraceCollection()
1254 # Add the trace provided by the user (LTTng traces always have
1256 if col.add_trace(sys.argv[1], 'ctf') is None:
1257 raise RuntimeError('Cannot add trace')
1259 # This counter dict contains execution times:
1261 # task command name -> total execution time (ns)
1262 exec_times = Counter()
1264 # This contains the last `sched_switch` timestamp
1268 for event in col.events:
1269 # Keep only `sched_switch` events
1270 if event.name != 'sched_switch':
1273 # Keep only events which happened on CPU 0
1274 if event['cpu_id'] != 0:
1278 cur_ts = event.timestamp
1284 # Previous task command (short) name
1285 prev_comm = event['prev_comm']
1287 # Initialize entry in our dict if not yet done
1288 if prev_comm not in exec_times:
1289 exec_times[prev_comm] = 0
1291 # Compute previous command execution time
1292 diff = cur_ts - last_ts
1294 # Update execution time of this command
1295 exec_times[prev_comm] += diff
1297 # Update last timestamp
1301 for name, ns in exec_times.most_common(5):
1303 print('{:20}{} s'.format(name, s))
1308 if __name__ == '__main__':
1309 sys.exit(0 if top5proc() else 1)
1316 $ python3 top5proc.py /tmp/my-kernel-trace/kernel
1322 swapper/0 48.607245889 s
1323 chromium 7.192738188 s
1324 pavucontrol 0.709894415 s
1325 Compositor 0.660867933 s
1326 Xorg.bin 0.616753786 s
1329 Note that `swapper/0` is the "idle" process of CPU 0 on Linux; since we
1330 weren't using the CPU that much when tracing, its first position in the
1335 == [[understanding-lttng]]Core concepts
1337 From a user's perspective, the LTTng system is built on a few concepts,
1338 or objects, on which the <<lttng-cli,cmd:lttng command-line tool>>
1339 operates by sending commands to the <<lttng-sessiond,session daemon>>.
1340 Understanding how those objects relate to eachother is key in mastering
1343 The core concepts are:
1345 * <<tracing-session,Tracing session>>
1346 * <<domain,Tracing domain>>
1347 * <<channel,Channel and ring buffer>>
1348 * <<"event","Instrumentation point, event rule, event, and event record">>
1354 A _tracing session_ is a stateful dialogue between you and
1355 a <<lttng-sessiond,session daemon>>. You can
1356 <<creating-destroying-tracing-sessions,create a new tracing
1357 session>> with the `lttng create` command.
1359 Anything that you do when you control LTTng tracers happens within a
1360 tracing session. In particular, a tracing session:
1363 * Has its own set of trace files.
1364 * Has its own state of activity (started or stopped).
1365 * Has its own <<tracing-session-mode,mode>> (local, network streaming,
1367 * Has its own <<channel,channels>> which have their own
1368 <<event,event rules>>.
1371 .A _tracing session_ contains <<channel,channels>> that are members of <<domain,tracing domains>> and contain <<event,event rules>>.
1372 image::concepts.png[]
1374 Those attributes and objects are completely isolated between different
1377 A tracing session is analogous to a cash machine session:
1378 the operations you do on the banking system through the cash machine do
1379 not alter the data of other users of the same system. In the case of
1380 the cash machine, a session lasts as long as your bank card is inside.
1381 In the case of LTTng, a tracing session lasts from the `lttng create`
1382 command to the `lttng destroy` command.
1385 .Each Unix user has its own set of tracing sessions.
1386 image::many-sessions.png[]
1389 [[tracing-session-mode]]
1390 ==== Tracing session mode
1392 LTTng can send the generated trace data to different locations. The
1393 _tracing session mode_ dictates where to send it. The following modes
1394 are available in LTTng{nbsp}{revision}:
1397 LTTng writes the traces to the file system of the machine being traced
1400 Network streaming mode::
1401 LTTng sends the traces over the network to a
1402 <<lttng-relayd,relay daemon>> running on a remote system.
1405 LTTng does not write the traces by default. Instead, you can request
1406 LTTng to <<taking-a-snapshot,take a snapshot>>, that is, a copy of the
1407 current tracing buffers, and to write it to the target's file system
1408 or to send it over the network to a <<lttng-relayd,relay daemon>>
1409 running on a remote system.
1412 This mode is similar to the network streaming mode, but a live
1413 trace viewer can connect to the distant relay daemon to
1414 <<lttng-live,view event records as LTTng generates them>> by
1421 A _tracing domain_ is a namespace for event sources. A tracing domain
1422 has its own properties and features.
1424 There are currently five available tracing domains:
1428 * `java.util.logging` (JUL)
1432 You must specify a tracing domain when using some commands to avoid
1433 ambiguity. For example, since all the domains support named tracepoints
1434 as event sources (instrumentation points that you manually insert in the
1435 source code), you need to specify a tracing domain when
1436 <<enabling-disabling-events,creating an event rule>> because all the
1437 tracing domains could have tracepoints with the same names.
1439 Some features are reserved to specific tracing domains. Dynamic function
1440 entry and return instrumentation points, for example, are currently only
1441 supported in the Linux kernel tracing domain, but support for other
1442 tracing domains could be added in the future.
1444 You can create <<channel,channels>> in the Linux kernel and user space
1445 tracing domains. The other tracing domains have a single default
1450 === Channel and ring buffer
1452 A _channel_ is an object which is responsible for a set of ring buffers.
1453 Each ring buffer is divided into multiple sub-buffers. When an LTTng
1454 tracer emits an event, it can record it to one or more
1455 sub-buffers. The attributes of a channel determine what to do when
1456 there's no space left for a new event record because all sub-buffers
1457 are full, where to send a full sub-buffer, and other behaviours.
1459 A channel is always associated to a <<domain,tracing domain>>. The
1460 `java.util.logging` (JUL), log4j, and Python tracing domains each have
1461 a default channel which you cannot configure.
1463 A channel also owns <<event,event rules>>. When an LTTng tracer emits
1464 an event, it records it to the sub-buffers of all
1465 the enabled channels with a satisfied event rule, as long as those
1466 channels are part of active <<tracing-session,tracing sessions>>.
1469 [[channel-buffering-schemes]]
1470 ==== Per-user vs. per-process buffering schemes
1472 A channel has at least one ring buffer _per CPU_. LTTng always
1473 records an event to the ring buffer associated to the CPU on which it
1476 Two _buffering schemes_ are available when you
1477 <<enabling-disabling-channels,create a channel>> in the
1478 user space <<domain,tracing domain>>:
1480 Per-user buffering::
1481 Allocate one set of ring buffers--one per CPU--shared by all the
1482 instrumented processes of each Unix user.
1486 .Per-user buffering scheme.
1487 image::per-user-buffering.png[]
1490 Per-process buffering::
1491 Allocate one set of ring buffers--one per CPU--for each
1492 instrumented process.
1496 .Per-process buffering scheme.
1497 image::per-process-buffering.png[]
1500 The per-process buffering scheme tends to consume more memory than the
1501 per-user option because systems generally have more instrumented
1502 processes than Unix users running instrumented processes. However, the
1503 per-process buffering scheme ensures that one process having a high
1504 event throughput won't fill all the shared sub-buffers of the same
1507 The Linux kernel tracing domain has only one available buffering scheme
1508 which is to allocate a single set of ring buffers for the whole system.
1509 This scheme is similar to the per-user option, but with a single, global
1510 user "running" the kernel.
1513 [[channel-overwrite-mode-vs-discard-mode]]
1514 ==== Overwrite vs. discard event loss modes
1516 When an event occurs, LTTng records it to a specific sub-buffer (yellow
1517 arc in the following animation) of a specific channel's ring buffer.
1518 When there's no space left in a sub-buffer, the tracer marks it as
1519 consumable (red) and another, empty sub-buffer starts receiving the
1520 following event records. A <<lttng-consumerd,consumer daemon>>
1521 eventually consumes the marked sub-buffer (returns to white).
1524 [role="docsvg-channel-subbuf-anim"]
1529 In an ideal world, sub-buffers are consumed faster than they are filled,
1530 as is the case in the previous animation. In the real world,
1531 however, all sub-buffers can be full at some point, leaving no space to
1532 record the following events.
1534 By design, LTTng is a _non-blocking_ tracer: when no empty sub-buffer is
1535 available, it is acceptable to lose event records when the alternative
1536 would be to cause substantial delays in the instrumented application's
1537 execution. LTTng privileges performance over integrity; it aims at
1538 perturbing the traced system as little as possible in order to make
1539 tracing of subtle race conditions and rare interrupt cascades possible.
1541 When it comes to losing event records because no empty sub-buffer is
1542 available, the channel's _event loss mode_ determines what to do. The
1543 available event loss modes are:
1546 Drop the newest event records until a the tracer
1547 releases a sub-buffer.
1550 Clear the sub-buffer containing the oldest event records and start
1551 writing the newest event records there.
1553 This mode is sometimes called _flight recorder mode_ because it's
1555 https://en.wikipedia.org/wiki/Flight_recorder[flight recorder]:
1556 always keep a fixed amount of the latest data.
1558 Which mechanism you should choose depends on your context: prioritize
1559 the newest or the oldest event records in the ring buffer?
1561 Beware that, in overwrite mode, the tracer abandons a whole sub-buffer
1562 as soon as a there's no space left for a new event record, whereas in
1563 discard mode, the tracer only discards the event record that doesn't
1566 In discard mode, LTTng increments a count of lost event records when an
1567 event record is lost and saves this count to the trace. In overwrite
1568 mode, since LTTng 2.8, LTTng increments a count of lost sub-buffers when
1569 a sub-buffer is lost and saves this count to the trace. In this mode,
1570 the exact number of lost event records in those lost sub-buffers is not
1571 saved to the trace. Trace analyses can use the trace's saved discarded
1572 event record and sub-buffer counts to decide whether or not to perform
1573 the analyses even if trace data is known to be missing.
1575 There are a few ways to decrease your probability of losing event
1577 <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>> shows
1578 how you can fine-une the sub-buffer count and size of a channel to
1579 virtually stop losing event records, though at the cost of greater
1583 [[channel-subbuf-size-vs-subbuf-count]]
1584 ==== Sub-buffer count and size
1586 When you <<enabling-disabling-channels,create a channel>>, you can
1587 set its number of sub-buffers and their size.
1589 Note that there is noticeable CPU overhead introduced when
1590 switching sub-buffers (marking a full one as consumable and switching
1591 to an empty one for the following events to be recorded). Knowing this,
1592 the following list presents a few practical situations along with how
1593 to configure the sub-buffer count and size for them:
1595 * **High event throughput**: In general, prefer bigger sub-buffers to
1596 lower the risk of losing event records.
1598 Having bigger sub-buffers also ensures a lower
1599 <<channel-switch-timer,sub-buffer switching frequency>>.
1601 The number of sub-buffers is only meaningful if you create the channel
1602 in overwrite mode: in this case, if a sub-buffer overwrite happens, the
1603 other sub-buffers are left unaltered.
1605 * **Low event throughput**: In general, prefer smaller sub-buffers
1606 since the risk of losing event records is low.
1608 Because events occur less frequently, the sub-buffer switching frequency
1609 should remain low and thus the tracer's overhead should not be a
1612 * **Low memory system**: If your target system has a low memory
1613 limit, prefer fewer first, then smaller sub-buffers.
1615 Even if the system is limited in memory, you want to keep the
1616 sub-buffers as big as possible to avoid a high sub-buffer switching
1619 Note that LTTng uses http://diamon.org/ctf/[CTF] as its trace format,
1620 which means event data is very compact. For example, the average
1621 LTTng kernel event record weights about 32{nbsp}bytes. Thus, a
1622 sub-buffer size of 1{nbsp}MiB is considered big.
1624 The previous situations highlight the major trade-off between a few big
1625 sub-buffers and more, smaller sub-buffers: sub-buffer switching
1626 frequency vs. how much data is lost in overwrite mode. Assuming a
1627 constant event throughput and using the overwrite mode, the two
1628 following configurations have the same ring buffer total size:
1631 [role="docsvg-channel-subbuf-size-vs-count-anim"]
1636 * **2 sub-buffers of 4{nbsp}MiB each**: Expect a very low sub-buffer
1637 switching frequency, but if a sub-buffer overwrite happens, half of
1638 the event records so far (4{nbsp}MiB) are definitely lost.
1639 * **8 sub-buffers of 1{nbsp}MiB each**: Expect 4{nbsp}times the tracer's
1640 overhead as the previous configuration, but if a sub-buffer
1641 overwrite happens, only the eighth of event records so far are
1644 In discard mode, the sub-buffers count parameter is pointless: use two
1645 sub-buffers and set their size according to the requirements of your
1649 [[channel-switch-timer]]
1650 ==== Switch timer period
1652 The _switch timer period_ is an important configurable attribute of
1653 a channel to ensure periodic sub-buffer flushing.
1655 When the _switch timer_ expires, a sub-buffer switch happens. You can
1656 set the switch timer period attribute when you
1657 <<enabling-disabling-channels,create a channel>> to ensure that event
1658 data is consumed and committed to trace files or to a distant relay
1659 daemon periodically in case of a low event throughput.
1662 [role="docsvg-channel-switch-timer"]
1667 This attribute is also convenient when you use big sub-buffers to cope
1668 with a sporadic high event throughput, even if the throughput is
1672 [[channel-read-timer]]
1673 ==== Read timer period
1675 By default, the LTTng tracers use a notification mechanism to signal a
1676 full sub-buffer so that a consumer daemon can consume it. When such
1677 notifications must be avoided, for example in real-time applications,
1678 you can use the channel's _read timer_ instead. When the read timer
1679 fires, the <<lttng-consumerd,consumer daemon>> checks for full,
1680 consumable sub-buffers.
1683 [[tracefile-rotation]]
1684 ==== Trace file count and size
1686 By default, trace files can grow as large as needed. You can set the
1687 maximum size of each trace file that a channel writes when you
1688 <<enabling-disabling-channels,create a channel>>. When the size of
1689 a trace file reaches the channel's fixed maximum size, LTTng creates
1690 another file to contain the next event records. LTTng appends a file
1691 count to each trace file name in this case.
1693 If you set the trace file size attribute when you create a channel, the
1694 maximum number of trace files that LTTng creates is _unlimited_ by
1695 default. To limit them, you can also set a maximum number of trace
1696 files. When the number of trace files reaches the channel's fixed
1697 maximum count, the oldest trace file is overwritten. This mechanism is
1698 called _trace file rotation_.
1702 === Instrumentation point, event rule, event, and event record
1704 An _event rule_ is a set of conditions which must be **all** satisfied
1705 for LTTng to record an occuring event.
1707 You set the conditions when you <<enabling-disabling-events,create
1710 You always attach an event rule to <<channel,channel>> when you create
1713 When an event passes the conditions of an event rule, LTTng records it
1714 in one of the attached channel's sub-buffers.
1716 The available conditions, as of LTTng{nbsp}{revision}, are:
1718 * The event rule _is enabled_.
1719 * The instrumentation point's type _is{nbsp}T_.
1720 * The instrumentation point's name (sometimes called _event name_)
1721 _matches{nbsp}N_, but _is not{nbsp}E_.
1722 * The instrumentation point's log level _is as severe as{nbsp}L_, or
1723 _is exactly{nbsp}L_.
1724 * The fields of the event's payload _satisfy_ a filter
1725 expression{nbsp}__F__.
1727 As you can see, all the conditions but the dynamic filter are related to
1728 the event rule's status or to the instrumentation point, not to the
1729 occurring events. This is why, without a filter, checking if an event
1730 passes an event rule is not a dynamic task: when you create or modify an
1731 event rule, all the tracers of its tracing domain enable or disable the
1732 instrumentation points themselves once. This is possible because the
1733 attributes of an instrumentation point (type, name, and log level) are
1734 defined statically. In other words, without a dynamic filter, the tracer
1735 _does not evaluate_ the arguments of an instrumentation point unless it
1736 matches an enabled event rule.
1738 Note that, for LTTng to record an event, the <<channel,channel>> to
1739 which a matching event rule is attached must also be enabled, and the
1740 tracing session owning this channel must be active.
1743 .Logical path from an instrumentation point to an event record.
1744 image::event-rule.png[]
1746 .Event, event record, or event rule?
1748 With so many similar terms, it's easy to get confused.
1750 An **event** is the consequence of the execution of an _instrumentation
1751 point_, like a tracepoint that you manually place in some source code,
1752 or a Linux kernel KProbe. An event is said to _occur_ at a specific
1753 time. Different actions can be taken upon the occurrence of an event,
1754 like record the event's payload to a buffer.
1756 An **event record** is the representation of an event in a sub-buffer. A
1757 tracer is responsible for capturing the payload of an event, current
1758 context variables, the event's ID, and the event's timestamp. LTTng
1759 can append this sub-buffer to a trace file.
1761 An **event rule** is a set of conditions which must all be satisfied for
1762 LTTng to record an occuring event. Events still occur without
1763 satisfying event rules, but LTTng does not record them.
1768 == Components of noch:{LTTng}
1770 The second _T_ in _LTTng_ stands for _toolkit_: it would be wrong
1771 to call LTTng a simple _tool_ since it is composed of multiple
1772 interacting components. This section describes those components,
1773 explains their respective roles, and shows how they connect together to
1774 form the LTTng ecosystem.
1776 The following diagram shows how the most important components of LTTng
1777 interact with user applications, the Linux kernel, and you:
1780 .Control and trace data paths between LTTng components.
1781 image::plumbing.png[]
1783 The LTTng project incorporates:
1785 * **LTTng-tools**: Libraries and command-line interface to
1786 control tracing sessions.
1787 ** <<lttng-sessiond,Session daemon>> (man:lttng-sessiond(8)).
1788 ** <<lttng-consumerd,Consumer daemon>> (man:lttng-consumerd(8)).
1789 ** <<lttng-relayd,Relay daemon>> (man:lttng-relayd(8)).
1790 ** <<liblttng-ctl-lttng,Tracing control library>> (`liblttng-ctl`).
1791 ** <<lttng-cli,Tracing control command-line tool>> (man:lttng(1)).
1792 * **LTTng-UST**: Libraries and Java/Python packages to trace user
1794 ** <<lttng-ust,User space tracing library>> (`liblttng-ust`) and its
1795 headers to instrument and trace any native user application.
1796 ** <<prebuilt-ust-helpers,Preloadable user space tracing helpers>>:
1797 *** `liblttng-ust-libc-wrapper`
1798 *** `liblttng-ust-pthread-wrapper`
1799 *** `liblttng-ust-cyg-profile`
1800 *** `liblttng-ust-cyg-profile-fast`
1801 *** `liblttng-ust-dl`
1802 ** User space tracepoint provider source files generator command-line
1803 tool (man:lttng-gen-tp(1)).
1804 ** <<lttng-ust-agents,LTTng-UST Java agent>> to instrument and trace
1805 Java applications using `java.util.logging` or
1806 Apache log4j 1.2 logging.
1807 ** <<lttng-ust-agents,LTTng-UST Python agent>> to instrument
1808 Python applications using the standard `logging` package.
1809 * **LTTng-modules**: <<lttng-modules,Linux kernel modules>> to trace
1811 ** LTTng kernel tracer module.
1812 ** Tracing ring buffer kernel modules.
1813 ** Probe kernel modules.
1814 ** LTTng logger kernel module.
1818 === Tracing control command-line interface
1821 .The tracing control command-line interface.
1822 image::plumbing-lttng-cli.png[]
1824 The _man:lttng(1) command-line tool_ is the standard user interface to
1825 control LTTng <<tracing-session,tracing sessions>>. The cmd:lttng tool
1826 is part of LTTng-tools.
1828 The cmd:lttng tool is linked with
1829 <<liblttng-ctl-lttng,`liblttng-ctl`>> to communicate with
1830 one or more <<lttng-sessiond,session daemons>> behind the scenes.
1832 The cmd:lttng tool has a Git-like interface:
1836 $ lttng <GENERAL OPTIONS> <COMMAND> <COMMAND OPTIONS>
1839 The <<controlling-tracing,Tracing control>> section explores the
1840 available features of LTTng using the cmd:lttng tool.
1843 [[liblttng-ctl-lttng]]
1844 === Tracing control library
1847 .The tracing control library.
1848 image::plumbing-liblttng-ctl.png[]
1850 The _LTTng control library_, `liblttng-ctl`, is used to communicate
1851 with a <<lttng-sessiond,session daemon>> using a C API that hides the
1852 underlying protocol's details. `liblttng-ctl` is part of LTTng-tools.
1854 The <<lttng-cli,cmd:lttng command-line tool>>
1855 is linked with `liblttng-ctl`.
1857 You can use `liblttng-ctl` in C or $$C++$$ source code by including its
1862 #include <lttng/lttng.h>
1865 Some objects are referenced by name (C string), such as tracing
1866 sessions, but most of them require to create a handle first using
1867 `lttng_create_handle()`.
1869 The best available developer documentation for `liblttng-ctl` is, as of
1870 LTTng{nbsp}{revision}, its installed header files. Every function and
1871 structure is thoroughly documented.
1875 === User space tracing library
1878 .The user space tracing library.
1879 image::plumbing-liblttng-ust.png[]
1881 The _user space tracing library_, `liblttng-ust` (see man:lttng-ust(3)),
1882 is the LTTng user space tracer. It receives commands from a
1883 <<lttng-sessiond,session daemon>>, for example to
1884 enable and disable specific instrumentation points, and writes event
1885 records to ring buffers shared with a
1886 <<lttng-consumerd,consumer daemon>>.
1887 `liblttng-ust` is part of LTTng-UST.
1889 Public C header files are installed beside `liblttng-ust` to
1890 instrument any <<c-application,C or $$C++$$ application>>.
1892 <<lttng-ust-agents,LTTng-UST agents>>, which are regular Java and Python
1893 packages, use their own library providing tracepoints which is
1894 linked with `liblttng-ust`.
1896 An application or library does not have to initialize `liblttng-ust`
1897 manually: its constructor does the necessary tasks to properly register
1898 to a session daemon. The initialization phase also enables the
1899 instrumentation points matching the <<event,event rules>> that you
1903 [[lttng-ust-agents]]
1904 === User space tracing agents
1907 .The user space tracing agents.
1908 image::plumbing-lttng-ust-agents.png[]
1910 The _LTTng-UST Java and Python agents_ are regular Java and Python
1911 packages which add LTTng tracing capabilities to the
1912 native logging frameworks. The LTTng-UST agents are part of LTTng-UST.
1914 In the case of Java, the
1915 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[`java.util.logging`
1916 core logging facilities] and
1917 https://logging.apache.org/log4j/1.2/[Apache log4j 1.2] are supported.
1918 Note that Apache Log4{nbsp}2 is not supported.
1920 In the case of Python, the standard
1921 https://docs.python.org/3/library/logging.html[`logging`] package
1922 is supported. Both Python 2 and Python 3 modules can import the
1923 LTTng-UST Python agent package.
1925 The applications using the LTTng-UST agents are in the
1926 `java.util.logging` (JUL),
1927 log4j, and Python <<domain,tracing domains>>.
1929 Both agents use the same mechanism to trace the log statements. When an
1930 agent is initialized, it creates a log handler that attaches to the root
1931 logger. The agent also registers to a <<lttng-sessiond,session daemon>>.
1932 When the application executes a log statement, it is passed to the
1933 agent's log handler by the root logger. The agent's log handler calls a
1934 native function in a tracepoint provider package shared library linked
1935 with <<lttng-ust,`liblttng-ust`>>, passing the formatted log message and
1936 other fields, like its logger name and its log level. This native
1937 function contains a user space instrumentation point, hence tracing the
1940 The log level condition of an
1941 <<event,event rule>> is considered when tracing
1942 a Java or a Python application, and it's compatible with the standard
1943 JUL, log4j, and Python log levels.
1947 === LTTng kernel modules
1950 .The LTTng kernel modules.
1951 image::plumbing-lttng-modules.png[]
1953 The _LTTng kernel modules_ are a set of Linux kernel modules
1954 which implement the kernel tracer of the LTTng project. The LTTng
1955 kernel modules are part of LTTng-modules.
1957 The LTTng kernel modules include:
1959 * A set of _probe_ modules.
1961 Each module attaches to a specific subsystem
1962 of the Linux kernel using its tracepoint instrument points. There are
1963 also modules to attach to the entry and return points of the Linux
1964 system call functions.
1966 * _Ring buffer_ modules.
1968 A ring buffer implementation is provided as kernel modules. The LTTng
1969 kernel tracer writes to the ring buffer; a
1970 <<lttng-consumerd,consumer daemon>> reads from the ring buffer.
1972 * The _LTTng kernel tracer_ module.
1973 * The _LTTng logger_ module.
1975 The LTTng logger module implements the special path:{/proc/lttng-logger}
1976 file so that any executable can generate LTTng events by opening and
1977 writing to this file.
1979 See <<proc-lttng-logger-abi,LTTng logger>>.
1981 Generally, you do not have to load the LTTng kernel modules manually
1982 (using man:modprobe(8), for example): a root <<lttng-sessiond,session
1983 daemon>> loads the necessary modules when starting. If you have extra
1984 probe modules, you can specify to load them to the session daemon on
1987 The LTTng kernel modules are installed in
1988 +/usr/lib/modules/__release__/extra+ by default, where +__release__+ is
1989 the kernel release (see `uname --kernel-release`).
1996 .The session daemon.
1997 image::plumbing-sessiond.png[]
1999 The _session daemon_, man:lttng-sessiond(8), is a daemon responsible for
2000 managing tracing sessions and for controlling the various components of
2001 LTTng. The session daemon is part of LTTng-tools.
2003 The session daemon sends control requests to and receives control
2006 * The <<lttng-ust,user space tracing library>>.
2008 Any instance of the user space tracing library first registers to
2009 a session daemon. Then, the session daemon can send requests to
2010 this instance, such as:
2013 ** Get the list of tracepoints.
2014 ** Share an <<event,event rule>> so that the user space tracing library
2015 can enable or disable tracepoints. Amongst the possible conditions
2016 of an event rule is a filter expression which `liblttng-ust` evalutes
2017 when an event occurs.
2018 ** Share <<channel,channel>> attributes and ring buffer locations.
2021 The session daemon and the user space tracing library use a Unix
2022 domain socket for their communication.
2024 * The <<lttng-ust-agents,user space tracing agents>>.
2026 Any instance of a user space tracing agent first registers to
2027 a session daemon. Then, the session daemon can send requests to
2028 this instance, such as:
2031 ** Get the list of loggers.
2032 ** Enable or disable a specific logger.
2035 The session daemon and the user space tracing agent use a TCP connection
2036 for their communication.
2038 * The <<lttng-modules,LTTng kernel tracer>>.
2039 * The <<lttng-consumerd,consumer daemon>>.
2041 The session daemon sends requests to the consumer daemon to instruct
2042 it where to send the trace data streams, amongst other information.
2044 * The <<lttng-relayd,relay daemon>>.
2046 The session daemon receives commands from the
2047 <<liblttng-ctl-lttng,tracing control library>>.
2049 The root session daemon loads the appropriate
2050 <<lttng-modules,LTTng kernel modules>> on startup. It also spawns
2051 a <<lttng-consumerd,consumer daemon>> as soon as you create
2052 an <<event,event rule>>.
2054 The session daemon does not send and receive trace data: this is the
2055 role of the <<lttng-consumerd,consumer daemon>> and
2056 <<lttng-relayd,relay daemon>>. It does, however, generate the
2057 http://diamon.org/ctf/[CTF] metadata stream.
2059 Each Unix user can have its own session daemon instance. The
2060 tracing sessions managed by different session daemons are completely
2063 The root user's session daemon is the only one which is
2064 allowed to control the LTTng kernel tracer, and its spawned consumer
2065 daemon is the only one which is allowed to consume trace data from the
2066 LTTng kernel tracer. Note, however, that any Unix user which is a member
2067 of the <<tracing-group,tracing group>> is allowed
2068 to create <<channel,channels>> in the
2069 Linux kernel <<domain,tracing domain>>, and thus to trace the Linux
2072 The <<lttng-cli,cmd:lttng command-line tool>> automatically starts a
2073 session daemon when using its `create` command if none is currently
2074 running. You can also start the session daemon manually.
2081 .The consumer daemon.
2082 image::plumbing-consumerd.png[]
2084 The _consumer daemon_, man:lttng-consumerd(8), is a daemon which shares
2085 ring buffers with user applications or with the LTTng kernel modules to
2086 collect trace data and send it to some location (on disk or to a
2087 <<lttng-relayd,relay daemon>> over the network). The consumer daemon
2088 is part of LTTng-tools.
2090 You do not start a consumer daemon manually: a consumer daemon is always
2091 spawned by a <<lttng-sessiond,session daemon>> as soon as you create an
2092 <<event,event rule>>, that is, before you start tracing. When you kill
2093 its owner session daemon, the consumer daemon also exits because it is
2094 the session daemon's child process. Command-line options of
2095 man:lttng-sessiond(8) target the consumer daemon process.
2097 There are up to two running consumer daemons per Unix user, whereas only
2098 one session daemon can run per user. This is because each process can be
2099 either 32-bit or 64-bit: if the target system runs a mixture of 32-bit
2100 and 64-bit processes, it is more efficient to have separate
2101 corresponding 32-bit and 64-bit consumer daemons. The root user is an
2102 exception: it can have up to _three_ running consumer daemons: 32-bit
2103 and 64-bit instances for its user applications, and one more
2104 reserved for collecting kernel trace data.
2112 image::plumbing-relayd.png[]
2114 The _relay daemon_, man:lttng-relayd(8), is a daemon acting as a bridge
2115 between remote session and consumer daemons, local trace files, and a
2116 remote live trace viewer. The relay daemon is part of LTTng-tools.
2118 The main purpose of the relay daemon is to implement a receiver of
2119 <<sending-trace-data-over-the-network,trace data over the network>>.
2120 This is useful when the target system does not have much file system
2121 space to record trace files locally.
2123 The relay daemon is also a server to which a
2124 <<lttng-live,live trace viewer>> can
2125 connect. The live trace viewer sends requests to the relay daemon to
2126 receive trace data as the target system emits events. The
2127 communication protocol is named _LTTng live_; it is used over TCP
2130 Note that you can start the relay daemon on the target system directly.
2131 This is the setup of choice when the use case is to view events as
2132 the target system emits them without the need of a remote system.
2136 == [[using-lttng]]Instrumentation
2138 There are many examples of tracing and monitoring in our everyday life:
2140 * You have access to real-time and historical weather reports and
2141 forecasts thanks to weather stations installed around the country.
2142 * You know your heart is safe thanks to an electrocardiogram.
2143 * You make sure not to drive your car too fast and to have enough fuel
2144 to reach your destination thanks to gauges visible on your dashboard.
2146 All the previous examples have something in common: they rely on
2147 **instruments**. Without the electrodes attached to the surface of your
2148 body's skin, cardiac monitoring is futile.
2150 LTTng, as a tracer, is no different from those real life examples. If
2151 you're about to trace a software system or, in other words, record its
2152 history of execution, you better have **instrumentation points** in the
2153 subject you're tracing, that is, the actual software.
2155 Various ways were developed to instrument a piece of software for LTTng
2156 tracing. The most straightforward one is to manually place
2157 instrumentation points, called _tracepoints_, in the software's source
2158 code. It is also possible to add instrumentation points dynamically in
2159 the Linux kernel <<domain,tracing domain>>.
2161 If you're only interested in tracing the Linux kernel, your
2162 instrumentation needs are probably already covered by LTTng's built-in
2163 <<lttng-modules,Linux kernel tracepoints>>. You may also wish to trace a
2164 user application which is already instrumented for LTTng tracing.
2165 In such cases, you can skip this whole section and read the topics of
2166 the <<controlling-tracing,Tracing control>> section.
2168 Many methods are available to instrument a piece of software for LTTng
2171 * <<c-application,User space instrumentation for C and $$C++$$
2173 * <<prebuilt-ust-helpers,Prebuilt user space tracing helpers>>.
2174 * <<java-application,User space Java agent>>.
2175 * <<python-application,User space Python agent>>.
2176 * <<proc-lttng-logger-abi,LTTng logger>>.
2177 * <<instrumenting-linux-kernel,LTTng kernel tracepoints>>.
2181 === [[cxx-application]]User space instrumentation for C and $$C++$$ applications
2183 The procedure to instrument a C or $$C++$$ user application with
2184 the <<lttng-ust,LTTng user space tracing library>>, `liblttng-ust`, is:
2186 . <<tracepoint-provider,Create the source files of a tracepoint provider
2188 . <<probing-the-application-source-code,Add tracepoints to
2189 the application's source code>>.
2190 . <<building-tracepoint-providers-and-user-application,Build and link
2191 a tracepoint provider package and the user application>>.
2193 If you need quick, man:printf(3)-like instrumentation, you can skip
2194 those steps and use <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>>
2197 IMPORTANT: You need to <<installing-lttng,install>> LTTng-UST to
2198 instrument a user application with `liblttng-ust`.
2201 [[tracepoint-provider]]
2202 ==== Create the source files of a tracepoint provider package
2204 A _tracepoint provider_ is a set of compiled functions which provide
2205 **tracepoints** to an application, the type of instrumentation point
2206 supported by LTTng-UST. Those functions can emit events with
2207 user-defined fields and serialize those events as event records to one
2208 or more LTTng-UST <<channel,channel>> sub-buffers. The `tracepoint()`
2209 macro, which you <<probing-the-application-source-code,insert in a user
2210 application's source code>>, calls those functions.
2212 A _tracepoint provider package_ is an object file (`.o`) or a shared
2213 library (`.so`) which contains one or more tracepoint providers.
2214 Its source files are:
2216 * One or more <<tpp-header,tracepoint provider header>> (`.h`).
2217 * A <<tpp-source,tracepoint provider package source>> (`.c`).
2219 A tracepoint provider package is dynamically linked with `liblttng-ust`,
2220 the LTTng user space tracer, at run time.
2223 .User application linked with `liblttng-ust` and containing a tracepoint provider.
2224 image::ust-app.png[]
2226 NOTE: If you need quick, man:printf(3)-like instrumentation, you can
2227 skip creating and using a tracepoint provider and use
2228 <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>> instead.
2232 ===== Create a tracepoint provider header file template
2234 A _tracepoint provider header file_ contains the tracepoint
2235 definitions of a tracepoint provider.
2237 To create a tracepoint provider header file:
2239 . Start from this template:
2243 .Tracepoint provider header file template (`.h` file extension).
2245 #undef TRACEPOINT_PROVIDER
2246 #define TRACEPOINT_PROVIDER provider_name
2248 #undef TRACEPOINT_INCLUDE
2249 #define TRACEPOINT_INCLUDE "./tp.h"
2251 #if !defined(_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
2254 #include <lttng/tracepoint.h>
2257 * Use TRACEPOINT_EVENT(), TRACEPOINT_EVENT_CLASS(),
2258 * TRACEPOINT_EVENT_INSTANCE(), and TRACEPOINT_LOGLEVEL() here.
2263 #include <lttng/tracepoint-event.h>
2269 * `provider_name` with the name of your tracepoint provider.
2270 * `"tp.h"` with the name of your tracepoint provider header file.
2272 . Below the `#include <lttng/tracepoint.h>` line, put your
2273 <<defining-tracepoints,tracepoint definitions>>.
2275 Your tracepoint provider name must be unique amongst all the possible
2276 tracepoint provider names used on the same target system. We
2277 suggest to include the name of your project or company in the name,
2278 for example, `org_lttng_my_project_tpp`.
2280 TIP: [[lttng-gen-tp]]You can use the man:lttng-gen-tp(1) tool to create
2281 this boilerplate for you. When using cmd:lttng-gen-tp, all you need to
2282 write are the <<defining-tracepoints,tracepoint definitions>>.
2285 [[defining-tracepoints]]
2286 ===== Create a tracepoint definition
2288 A _tracepoint definition_ defines, for a given tracepoint:
2290 * Its **input arguments**. They are the macro parameters that the
2291 `tracepoint()` macro accepts for this particular tracepoint
2292 in the user application's source code.
2293 * Its **output event fields**. They are the sources of event fields
2294 that form the payload of any event that the execution of the
2295 `tracepoint()` macro emits for this particular tracepoint.
2297 You can create a tracepoint definition by using the
2298 `TRACEPOINT_EVENT()` macro below the `#include <lttng/tracepoint.h>`
2300 <<tpp-header,tracepoint provider header file template>>.
2302 The syntax of the `TRACEPOINT_EVENT()` macro is:
2305 .`TRACEPOINT_EVENT()` macro syntax.
2308 /* Tracepoint provider name */
2311 /* Tracepoint name */
2314 /* Input arguments */
2319 /* Output event fields */
2328 * `provider_name` with your tracepoint provider name.
2329 * `tracepoint_name` with your tracepoint name.
2330 * `arguments` with the <<tpp-def-input-args,input arguments>>.
2331 * `fields` with the <<tpp-def-output-fields,output event field>>
2334 This tracepoint emits events named `provider_name:tracepoint_name`.
2337 .Event name's length limitation
2339 The concatenation of the tracepoint provider name and the
2340 tracepoint name must not exceed **254 characters**. If it does, the
2341 instrumented application compiles and runs, but LTTng throws multiple
2342 warnings and you could experience serious issues.
2345 [[tpp-def-input-args]]The syntax of the `TP_ARGS()` macro is:
2348 .`TP_ARGS()` macro syntax.
2357 * `type` with the C type of the argument.
2358 * `arg_name` with the argument name.
2360 You can repeat `type` and `arg_name` up to 10 times to have
2361 more than one argument.
2363 .`TP_ARGS()` usage with three arguments.
2375 The `TP_ARGS()` and `TP_ARGS(void)` forms are valid to create a
2376 tracepoint definition with no input arguments.
2378 [[tpp-def-output-fields]]The `TP_FIELDS()` macro contains a list of
2379 `ctf_*()` macros. Each `ctf_*()` macro defines one event field. See
2380 man:lttng-ust(3) for a complete description of the available `ctf_*()`
2381 macros. A `ctf_*()` macro specifies the type, size, and byte order of
2384 Each `ctf_*()` macro takes an _argument expression_ parameter. This is a
2385 C expression that the tracer evalutes at the `tracepoint()` macro site
2386 in the application's source code. This expression provides a field's
2387 source of data. The argument expression can include input argument names
2388 listed in the `TP_ARGS()` macro.
2390 Each `ctf_*()` macro also takes a _field name_ parameter. Field names
2391 must be unique within a given tracepoint definition.
2393 Here's a complete tracepoint definition example:
2395 .Tracepoint definition.
2397 The following tracepoint definition defines a tracepoint which takes
2398 three input arguments and has four output event fields.
2402 #include "my-custom-structure.h"
2408 const struct my_custom_structure*, my_custom_structure,
2413 ctf_string(query_field, query)
2414 ctf_float(double, ratio_field, ratio)
2415 ctf_integer(int, recv_size, my_custom_structure->recv_size)
2416 ctf_integer(int, send_size, my_custom_structure->send_size)
2421 You can refer to this tracepoint definition with the `tracepoint()`
2422 macro in your application's source code like this:
2426 tracepoint(my_provider, my_tracepoint,
2427 my_structure, some_ratio, the_query);
2431 NOTE: The LTTng tracer only evaluates tracepoint arguments at run time
2432 if they satisfy an enabled <<event,event rule>>.
2435 [[using-tracepoint-classes]]
2436 ===== Use a tracepoint class
2438 A _tracepoint class_ is a class of tracepoints which share the same
2439 output event field definitions. A _tracepoint instance_ is one
2440 instance of such a defined tracepoint class, with its own tracepoint
2443 The <<defining-tracepoints,`TRACEPOINT_EVENT()` macro>> is actually a
2444 shorthand which defines both a tracepoint class and a tracepoint
2445 instance at the same time.
2447 When you build a tracepoint provider package, the C or $$C++$$ compiler
2448 creates one serialization function for each **tracepoint class**. A
2449 serialization function is responsible for serializing the event fields
2450 of a tracepoint to a sub-buffer when tracing.
2452 For various performance reasons, when your situation requires multiple
2453 tracepoint definitions with different names, but with the same event
2454 fields, we recommend that you manually create a tracepoint class
2455 and instantiate as many tracepoint instances as needed. One positive
2456 effect of such a design, amongst other advantages, is that all
2457 tracepoint instances of the same tracepoint class reuse the same
2458 serialization function, thus reducing
2459 https://en.wikipedia.org/wiki/Cache_pollution[cache pollution].
2461 .Use a tracepoint class and tracepoint instances.
2463 Consider the following three tracepoint definitions:
2475 ctf_integer(int, userid, userid)
2476 ctf_integer(size_t, len, len)
2488 ctf_integer(int, userid, userid)
2489 ctf_integer(size_t, len, len)
2501 ctf_integer(int, userid, userid)
2502 ctf_integer(size_t, len, len)
2507 In this case, we create three tracepoint classes, with one implicit
2508 tracepoint instance for each of them: `get_account`, `get_settings`, and
2509 `get_transaction`. However, they all share the same event field names
2510 and types. Hence three identical, yet independent serialization
2511 functions are created when you build the tracepoint provider package.
2513 A better design choice is to define a single tracepoint class and three
2514 tracepoint instances:
2518 /* The tracepoint class */
2519 TRACEPOINT_EVENT_CLASS(
2520 /* Tracepoint provider name */
2523 /* Tracepoint class name */
2526 /* Input arguments */
2532 /* Output event fields */
2534 ctf_integer(int, userid, userid)
2535 ctf_integer(size_t, len, len)
2539 /* The tracepoint instances */
2540 TRACEPOINT_EVENT_INSTANCE(
2541 /* Tracepoint provider name */
2544 /* Tracepoint class name */
2547 /* Tracepoint name */
2550 /* Input arguments */
2556 TRACEPOINT_EVENT_INSTANCE(
2565 TRACEPOINT_EVENT_INSTANCE(
2578 [[assigning-log-levels]]
2579 ===== Assign a log level to a tracepoint definition
2581 You can assign an optional _log level_ to a
2582 <<defining-tracepoints,tracepoint definition>>.
2584 Assigning different levels of severity to tracepoint definitions can
2585 be useful: when you <<enabling-disabling-events,create an event rule>>,
2586 you can target tracepoints having a log level as severe as a specific
2589 The concept of LTTng-UST log levels is similar to the levels found
2590 in typical logging frameworks:
2592 * In a logging framework, the log level is given by the function
2593 or method name you use at the log statement site: `debug()`,
2594 `info()`, `warn()`, `error()`, and so on.
2595 * In LTTng-UST, you statically assign the log level to a tracepoint
2596 definition; any `tracepoint()` macro invocation which refers to
2597 this definition has this log level.
2599 You can assign a log level to a tracepoint definition with the
2600 `TRACEPOINT_LOGLEVEL()` macro. You must use this macro _after_ the
2601 <<defining-tracepoints,`TRACEPOINT_EVENT()`>> or
2602 <<using-tracepoint-classes,`TRACEPOINT_INSTANCE()`>> macro for a given
2605 The syntax of the `TRACEPOINT_LOGLEVEL()` macro is:
2608 .`TRACEPOINT_LOGLEVEL()` macro syntax.
2610 TRACEPOINT_LOGLEVEL(provider_name, tracepoint_name, log_level)
2615 * `provider_name` with the tracepoint provider name.
2616 * `tracepoint_name` with the tracepoint name.
2617 * `log_level` with the log level to assign to the tracepoint
2618 definition named `tracepoint_name` in the `provider_name`
2619 tracepoint provider.
2621 See man:lttng-ust(3) for a list of available log level names.
2623 .Assign the `TRACE_DEBUG_UNIT` log level to a tracepoint definition.
2627 /* Tracepoint definition */
2636 ctf_integer(int, userid, userid)
2637 ctf_integer(size_t, len, len)
2641 /* Log level assignment */
2642 TRACEPOINT_LOGLEVEL(my_app, get_transaction, TRACE_DEBUG_UNIT)
2648 ===== Create a tracepoint provider package source file
2650 A _tracepoint provider package source file_ is a C source file which
2651 includes a <<tpp-header,tracepoint provider header file>> to expand its
2652 macros into event serialization and other functions.
2654 You can always use the following tracepoint provider package source
2658 .Tracepoint provider package source file template.
2660 #define TRACEPOINT_CREATE_PROBES
2665 Replace `tp.h` with the name of your <<tpp-header,tracepoint provider
2666 header file>> name. You may also include more than one tracepoint
2667 provider header file here to create a tracepoint provider package
2668 holding more than one tracepoint providers.
2671 [[probing-the-application-source-code]]
2672 ==== Add tracepoints to an application's source code
2674 Once you <<tpp-header,create a tracepoint provider header file>>, you
2675 can use the `tracepoint()` macro in your application's
2676 source code to insert the tracepoints that this header
2677 <<defining-tracepoints,defines>>.
2679 The `tracepoint()` macro takes at least two parameters: the tracepoint
2680 provider name and the tracepoint name. The corresponding tracepoint
2681 definition defines the other parameters.
2683 .`tracepoint()` usage.
2685 The following <<defining-tracepoints,tracepoint definition>> defines a
2686 tracepoint which takes two input arguments and has two output event
2690 .Tracepoint provider header file.
2692 #include "my-custom-structure.h"
2699 const char*, cmd_name
2702 ctf_string(cmd_name, cmd_name)
2703 ctf_integer(int, number_of_args, argc)
2708 You can refer to this tracepoint definition with the `tracepoint()`
2709 macro in your application's source code like this:
2712 .Application's source file.
2716 int main(int argc, char* argv[])
2718 tracepoint(my_provider, my_tracepoint, argc, argv[0]);
2724 Note how the application's source code includes
2725 the tracepoint provider header file containing the tracepoint
2726 definitions to use, path:{tp.h}.
2729 .`tracepoint()` usage with a complex tracepoint definition.
2731 Consider this complex tracepoint definition, where multiple event
2732 fields refer to the same input arguments in their argument expression
2736 .Tracepoint provider header file.
2738 /* For `struct stat` */
2739 #include <sys/types.h>
2740 #include <sys/stat.h>
2752 ctf_integer(int, my_constant_field, 23 + 17)
2753 ctf_integer(int, my_int_arg_field, my_int_arg)
2754 ctf_integer(int, my_int_arg_field2, my_int_arg * my_int_arg)
2755 ctf_integer(int, sum4_field, my_str_arg[0] + my_str_arg[1] +
2756 my_str_arg[2] + my_str_arg[3])
2757 ctf_string(my_str_arg_field, my_str_arg)
2758 ctf_integer_hex(off_t, size_field, st->st_size)
2759 ctf_float(double, size_dbl_field, (double) st->st_size)
2760 ctf_sequence_text(char, half_my_str_arg_field, my_str_arg,
2761 size_t, strlen(my_str_arg) / 2)
2766 You can refer to this tracepoint definition with the `tracepoint()`
2767 macro in your application's source code like this:
2770 .Application's source file.
2772 #define TRACEPOINT_DEFINE
2779 stat("/etc/fstab", &s);
2780 tracepoint(my_provider, my_tracepoint, 23, "Hello, World!", &s);
2786 If you look at the event record that LTTng writes when tracing this
2787 program, assuming the file size of path:{/etc/fstab} is 301{nbsp}bytes,
2788 it should look like this:
2790 .Event record fields
2792 |Field's name |Field's value
2793 |`my_constant_field` |40
2794 |`my_int_arg_field` |23
2795 |`my_int_arg_field2` |529
2797 |`my_str_arg_field` |`Hello, World!`
2798 |`size_field` |0x12d
2799 |`size_dbl_field` |301.0
2800 |`half_my_str_arg_field` |`Hello,`
2804 Sometimes, the arguments you pass to `tracepoint()` are expensive to
2805 compute--they use the call stack, for example. To avoid this
2806 computation when the tracepoint is disabled, you can use the
2807 `tracepoint_enabled()` and `do_tracepoint()` macros.
2809 The syntax of the `tracepoint_enabled()` and `do_tracepoint()` macros
2813 .`tracepoint_enabled()` and `do_tracepoint()` macros syntax.
2815 tracepoint_enabled(provider_name, tracepoint_name)
2816 do_tracepoint(provider_name, tracepoint_name, ...)
2821 * `provider_name` with the tracepoint provider name.
2822 * `tracepoint_name` with the tracepoint name.
2824 `tracepoint_enabled()` returns a non-zero value if the tracepoint named
2825 `tracepoint_name` from the provider named `provider_name` is enabled
2828 `do_tracepoint()` is like `tracepoint()`, except that it doesn't check
2829 if the tracepoint is enabled. Using `tracepoint()` with
2830 `tracepoint_enabled()` is dangerous since `tracepoint()` also contains
2831 the `tracepoint_enabled()` check, thus a race condition is
2832 possible in this situation:
2835 .Possible race condition when using `tracepoint_enabled()` with `tracepoint()`.
2837 if (tracepoint_enabled(my_provider, my_tracepoint)) {
2838 stuff = prepare_stuff();
2841 tracepoint(my_provider, my_tracepoint, stuff);
2844 If the tracepoint is enabled after the condition, then `stuff` is not
2845 prepared: the emitted event will either contain wrong data, or the whole
2846 application could crash (segmentation fault, for example).
2848 NOTE: Neither `tracepoint_enabled()` nor `do_tracepoint()` have an
2849 `STAP_PROBEV()` call. If you need it, you must emit
2853 [[building-tracepoint-providers-and-user-application]]
2854 ==== Build and link a tracepoint provider package and an application
2856 Once you have one or more <<tpp-header,tracepoint provider header
2857 files>> and a <<tpp-source,tracepoint provider package source file>>,
2858 you can create the tracepoint provider package by compiling its source
2859 file. From here, multiple build and run scenarios are possible. The
2860 following table shows common application and library configurations
2861 along with the required command lines to achieve them.
2863 In the following diagrams, we use the following file names:
2866 Executable application.
2869 Application's object file.
2872 Tracepoint provider package object file.
2875 Tracepoint provider package archive file.
2878 Tracepoint provider package shared object file.
2881 User library object file.
2884 User library shared object file.
2886 We use the following symbols in the diagrams of table below:
2889 .Symbols used in the build scenario diagrams.
2890 image::ust-sit-symbols.png[]
2892 We assume that path:{.} is part of the env:LD_LIBRARY_PATH environment
2893 variable in the following instructions.
2895 [role="growable ust-scenarios",cols="asciidoc,asciidoc"]
2896 .Common tracepoint provider package scenarios.
2898 |Scenario |Instructions
2901 The instrumented application is statically linked with
2902 the tracepoint provider package object.
2904 image::ust-sit+app-linked-with-tp-o+app-instrumented.png[]
2907 include::../common/ust-sit-step-tp-o.txt[]
2909 To build the instrumented application:
2911 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2916 #define TRACEPOINT_DEFINE
2920 . Compile the application source file:
2929 . Build the application:
2934 $ gcc -o app app.o tpp.o -llttng-ust -ldl
2938 To run the instrumented application:
2940 * Start the application:
2950 The instrumented application is statically linked with the
2951 tracepoint provider package archive file.
2953 image::ust-sit+app-linked-with-tp-a+app-instrumented.png[]
2956 To create the tracepoint provider package archive file:
2958 . Compile the <<tpp-source,tracepoint provider package source file>>:
2967 . Create the tracepoint provider package archive file:
2972 $ ar rcs tpp.a tpp.o
2976 To build the instrumented application:
2978 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2983 #define TRACEPOINT_DEFINE
2987 . Compile the application source file:
2996 . Build the application:
3001 $ gcc -o app app.o tpp.a -llttng-ust -ldl
3005 To run the instrumented application:
3007 * Start the application:
3017 The instrumented application is linked with the tracepoint provider
3018 package shared object.
3020 image::ust-sit+app-linked-with-tp-so+app-instrumented.png[]
3023 include::../common/ust-sit-step-tp-so.txt[]
3025 To build the instrumented application:
3027 . In path:{app.c}, before including path:{tpp.h}, add the following line:
3032 #define TRACEPOINT_DEFINE
3036 . Compile the application source file:
3045 . Build the application:
3050 $ gcc -o app app.o -ldl -L. -ltpp
3054 To run the instrumented application:
3056 * Start the application:
3066 The tracepoint provider package shared object is preloaded before the
3067 instrumented application starts.
3069 image::ust-sit+tp-so-preloaded+app-instrumented.png[]
3072 include::../common/ust-sit-step-tp-so.txt[]
3074 To build the instrumented application:
3076 . In path:{app.c}, before including path:{tpp.h}, add the
3082 #define TRACEPOINT_DEFINE
3083 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3087 . Compile the application source file:
3096 . Build the application:
3101 $ gcc -o app app.o -ldl
3105 To run the instrumented application with tracing support:
3107 * Preload the tracepoint provider package shared object and
3108 start the application:
3113 $ LD_PRELOAD=./libtpp.so ./app
3117 To run the instrumented application without tracing support:
3119 * Start the application:
3129 The instrumented application dynamically loads the tracepoint provider
3130 package shared object.
3132 See the <<dlclose-warning,warning about `dlclose()`>>.
3134 image::ust-sit+app-dlopens-tp-so+app-instrumented.png[]
3137 include::../common/ust-sit-step-tp-so.txt[]
3139 To build the instrumented application:
3141 . In path:{app.c}, before including path:{tpp.h}, add the
3147 #define TRACEPOINT_DEFINE
3148 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3152 . Compile the application source file:
3161 . Build the application:
3166 $ gcc -o app app.o -ldl
3170 To run the instrumented application:
3172 * Start the application:
3182 The application is linked with the instrumented user library.
3184 The instrumented user library is statically linked with the tracepoint
3185 provider package object file.
3187 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-o+lib-instrumented.png[]
3190 include::../common/ust-sit-step-tp-o-fpic.txt[]
3192 To build the instrumented user library:
3194 . In path:{emon.c}, before including path:{tpp.h}, add the
3200 #define TRACEPOINT_DEFINE
3204 . Compile the user library source file:
3209 $ gcc -I. -fpic -c emon.c
3213 . Build the user library shared object:
3218 $ gcc -shared -o libemon.so emon.o tpp.o -llttng-ust -ldl
3222 To build the application:
3224 . Compile the application source file:
3233 . Build the application:
3238 $ gcc -o app app.o -L. -lemon
3242 To run the application:
3244 * Start the application:
3254 The application is linked with the instrumented user library.
3256 The instrumented user library is linked with the tracepoint provider
3257 package shared object.
3259 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3262 include::../common/ust-sit-step-tp-so.txt[]
3264 To build the instrumented user library:
3266 . In path:{emon.c}, before including path:{tpp.h}, add the
3272 #define TRACEPOINT_DEFINE
3276 . Compile the user library source file:
3281 $ gcc -I. -fpic -c emon.c
3285 . Build the user library shared object:
3290 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3294 To build the application:
3296 . Compile the application source file:
3305 . Build the application:
3310 $ gcc -o app app.o -L. -lemon
3314 To run the application:
3316 * Start the application:
3326 The tracepoint provider package shared object is preloaded before the
3329 The application is linked with the instrumented user library.
3331 image::ust-sit+tp-so-preloaded+app-linked-with-lib+lib-instrumented.png[]
3334 include::../common/ust-sit-step-tp-so.txt[]
3336 To build the instrumented user library:
3338 . In path:{emon.c}, before including path:{tpp.h}, add the
3344 #define TRACEPOINT_DEFINE
3345 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3349 . Compile the user library source file:
3354 $ gcc -I. -fpic -c emon.c
3358 . Build the user library shared object:
3363 $ gcc -shared -o libemon.so emon.o -ldl
3367 To build the application:
3369 . Compile the application source file:
3378 . Build the application:
3383 $ gcc -o app app.o -L. -lemon
3387 To run the application with tracing support:
3389 * Preload the tracepoint provider package shared object and
3390 start the application:
3395 $ LD_PRELOAD=./libtpp.so ./app
3399 To run the application without tracing support:
3401 * Start the application:
3411 The application is linked with the instrumented user library.
3413 The instrumented user library dynamically loads the tracepoint provider
3414 package shared object.
3416 See the <<dlclose-warning,warning about `dlclose()`>>.
3418 image::ust-sit+app-linked-with-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3421 include::../common/ust-sit-step-tp-so.txt[]
3423 To build the instrumented user library:
3425 . In path:{emon.c}, before including path:{tpp.h}, add the
3431 #define TRACEPOINT_DEFINE
3432 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3436 . Compile the user library source file:
3441 $ gcc -I. -fpic -c emon.c
3445 . Build the user library shared object:
3450 $ gcc -shared -o libemon.so emon.o -ldl
3454 To build the application:
3456 . Compile the application source file:
3465 . Build the application:
3470 $ gcc -o app app.o -L. -lemon
3474 To run the application:
3476 * Start the application:
3486 The application dynamically loads the instrumented user library.
3488 The instrumented user library is linked with the tracepoint provider
3489 package shared object.
3491 See the <<dlclose-warning,warning about `dlclose()`>>.
3493 image::ust-sit+app-dlopens-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3496 include::../common/ust-sit-step-tp-so.txt[]
3498 To build the instrumented user library:
3500 . In path:{emon.c}, before including path:{tpp.h}, add the
3506 #define TRACEPOINT_DEFINE
3510 . Compile the user library source file:
3515 $ gcc -I. -fpic -c emon.c
3519 . Build the user library shared object:
3524 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3528 To build the application:
3530 . Compile the application source file:
3539 . Build the application:
3544 $ gcc -o app app.o -ldl -L. -lemon
3548 To run the application:
3550 * Start the application:
3560 The application dynamically loads the instrumented user library.
3562 The instrumented user library dynamically loads the tracepoint provider
3563 package shared object.
3565 See the <<dlclose-warning,warning about `dlclose()`>>.
3567 image::ust-sit+app-dlopens-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3570 include::../common/ust-sit-step-tp-so.txt[]
3572 To build the instrumented user library:
3574 . In path:{emon.c}, before including path:{tpp.h}, add the
3580 #define TRACEPOINT_DEFINE
3581 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3585 . Compile the user library source file:
3590 $ gcc -I. -fpic -c emon.c
3594 . Build the user library shared object:
3599 $ gcc -shared -o libemon.so emon.o -ldl
3603 To build the application:
3605 . Compile the application source file:
3614 . Build the application:
3619 $ gcc -o app app.o -ldl -L. -lemon
3623 To run the application:
3625 * Start the application:
3635 The tracepoint provider package shared object is preloaded before the
3638 The application dynamically loads the instrumented user library.
3640 image::ust-sit+tp-so-preloaded+app-dlopens-lib+lib-instrumented.png[]
3643 include::../common/ust-sit-step-tp-so.txt[]
3645 To build the instrumented user library:
3647 . In path:{emon.c}, before including path:{tpp.h}, add the
3653 #define TRACEPOINT_DEFINE
3654 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3658 . Compile the user library source file:
3663 $ gcc -I. -fpic -c emon.c
3667 . Build the user library shared object:
3672 $ gcc -shared -o libemon.so emon.o -ldl
3676 To build the application:
3678 . Compile the application source file:
3687 . Build the application:
3692 $ gcc -o app app.o -L. -lemon
3696 To run the application with tracing support:
3698 * Preload the tracepoint provider package shared object and
3699 start the application:
3704 $ LD_PRELOAD=./libtpp.so ./app
3708 To run the application without tracing support:
3710 * Start the application:
3720 The application is statically linked with the tracepoint provider
3721 package object file.
3723 The application is linked with the instrumented user library.
3725 image::ust-sit+app-linked-with-tp-o+app-linked-with-lib+lib-instrumented.png[]
3728 include::../common/ust-sit-step-tp-o.txt[]
3730 To build the instrumented user library:
3732 . In path:{emon.c}, before including path:{tpp.h}, add the
3738 #define TRACEPOINT_DEFINE
3742 . Compile the user library source file:
3747 $ gcc -I. -fpic -c emon.c
3751 . Build the user library shared object:
3756 $ gcc -shared -o libemon.so emon.o
3760 To build the application:
3762 . Compile the application source file:
3771 . Build the application:
3776 $ gcc -o app app.o tpp.o -llttng-ust -ldl -L. -lemon
3780 To run the instrumented application:
3782 * Start the application:
3792 The application is statically linked with the tracepoint provider
3793 package object file.
3795 The application dynamically loads the instrumented user library.
3797 image::ust-sit+app-linked-with-tp-o+app-dlopens-lib+lib-instrumented.png[]
3800 include::../common/ust-sit-step-tp-o.txt[]
3802 To build the application:
3804 . In path:{app.c}, before including path:{tpp.h}, add the following line:
3809 #define TRACEPOINT_DEFINE
3813 . Compile the application source file:
3822 . Build the application:
3827 $ gcc -Wl,--export-dynamic -o app app.o tpp.o \
3832 The `--export-dynamic` option passed to the linker is necessary for the
3833 dynamically loaded library to ``see'' the tracepoint symbols defined in
3836 To build the instrumented user library:
3838 . Compile the user library source file:
3843 $ gcc -I. -fpic -c emon.c
3847 . Build the user library shared object:
3852 $ gcc -shared -o libemon.so emon.o
3856 To run the application:
3858 * Start the application:
3870 .Do not use man:dlclose(3) on a tracepoint provider package
3872 Never use man:dlclose(3) on any shared object which:
3874 * Is linked with, statically or dynamically, a tracepoint provider
3876 * Calls man:dlopen(3) itself to dynamically open a tracepoint provider
3877 package shared object.
3879 This is currently considered **unsafe** due to a lack of reference
3880 counting from LTTng-UST to the shared object.
3882 A known workaround (available since glibc 2.2) is to use the
3883 `RTLD_NODELETE` flag when calling man:dlopen(3) initially. This has the
3884 effect of not unloading the loaded shared object, even if man:dlclose(3)
3887 You can also preload the tracepoint provider package shared object with
3888 the env:LD_PRELOAD environment variable to overcome this limitation.
3892 [[using-lttng-ust-with-daemons]]
3893 ===== Use noch:{LTTng-UST} with daemons
3895 If your instrumented application calls man:fork(2), man:clone(2),
3896 or BSD's man:rfork(2), without a following man:exec(3)-family
3897 system call, you must preload the path:{liblttng-ust-fork.so} shared
3898 object when you start the application.
3902 $ LD_PRELOAD=liblttng-ust-fork.so ./my-app
3905 If your tracepoint provider package is
3906 a shared library which you also preload, you must put both
3907 shared objects in env:LD_PRELOAD:
3911 $ LD_PRELOAD=liblttng-ust-fork.so:/path/to/tp.so ./my-app
3917 ===== Use noch:{LTTng-UST} with applications which close file descriptors that don't belong to them
3919 If your instrumented application closes one or more file descriptors
3920 which it did not open itself, you must preload the
3921 path:{liblttng-ust-fd.so} shared object when you start the application:
3925 $ LD_PRELOAD=liblttng-ust-fd.so ./my-app
3928 Typical use cases include closing all the file descriptors after
3929 man:fork(2) or man:rfork(2) and buggy applications doing
3933 [[lttng-ust-pkg-config]]
3934 ===== Use noch:{pkg-config}
3936 On some distributions, LTTng-UST ships with a
3937 https://www.freedesktop.org/wiki/Software/pkg-config/[pkg-config]
3938 metadata file. If this is your case, then you can use cmd:pkg-config to
3939 build an application on the command line:
3943 $ gcc -o my-app my-app.o tp.o $(pkg-config --cflags --libs lttng-ust)
3947 [[instrumenting-32-bit-app-on-64-bit-system]]
3948 ===== [[advanced-instrumenting-techniques]]Build a 32-bit instrumented application for a 64-bit target system
3950 In order to trace a 32-bit application running on a 64-bit system,
3951 LTTng must use a dedicated 32-bit
3952 <<lttng-consumerd,consumer daemon>>.
3954 The following steps show how to build and install a 32-bit consumer
3955 daemon, which is _not_ part of the default 64-bit LTTng build, how to
3956 build and install the 32-bit LTTng-UST libraries, and how to build and
3957 link an instrumented 32-bit application in that context.
3959 To build a 32-bit instrumented application for a 64-bit target system,
3960 assuming you have a fresh target system with no installed Userspace RCU
3963 . Download, build, and install a 32-bit version of Userspace RCU:
3968 $ cd $(mktemp -d) &&
3969 wget http://lttng.org/files/urcu/userspace-rcu-latest-0.9.tar.bz2 &&
3970 tar -xf userspace-rcu-latest-0.9.tar.bz2 &&
3971 cd userspace-rcu-0.9.* &&
3972 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 &&
3974 sudo make install &&
3979 . Using your distribution's package manager, or from source, install
3980 the following 32-bit versions of the following dependencies of
3981 LTTng-tools and LTTng-UST:
3984 * https://sourceforge.net/projects/libuuid/[libuuid]
3985 * http://directory.fsf.org/wiki/Popt[popt]
3986 * http://www.xmlsoft.org/[libxml2]
3989 . Download, build, and install a 32-bit version of the latest
3990 LTTng-UST{nbsp}{revision}:
3995 $ cd $(mktemp -d) &&
3996 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.9.tar.bz2 &&
3997 tar -xf lttng-ust-latest-2.9.tar.bz2 &&
3998 cd lttng-ust-2.9.* &&
3999 ./configure --libdir=/usr/local/lib32 \
4000 CFLAGS=-m32 CXXFLAGS=-m32 \
4001 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' &&
4003 sudo make install &&
4010 Depending on your distribution,
4011 32-bit libraries could be installed at a different location than
4012 `/usr/lib32`. For example, Debian is known to install
4013 some 32-bit libraries in `/usr/lib/i386-linux-gnu`.
4015 In this case, make sure to set `LDFLAGS` to all the
4016 relevant 32-bit library paths, for example:
4020 $ LDFLAGS='-L/usr/lib/i386-linux-gnu -L/usr/lib32'
4024 . Download the latest LTTng-tools{nbsp}{revision}, build, and install
4025 the 32-bit consumer daemon:
4030 $ cd $(mktemp -d) &&
4031 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.9.tar.bz2 &&
4032 tar -xf lttng-tools-latest-2.9.tar.bz2 &&
4033 cd lttng-tools-2.9.* &&
4034 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 CXXFLAGS=-m32 \
4035 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' \
4036 --disable-bin-lttng --disable-bin-lttng-crash \
4037 --disable-bin-lttng-relayd --disable-bin-lttng-sessiond &&
4039 cd src/bin/lttng-consumerd &&
4040 sudo make install &&
4045 . From your distribution or from source,
4046 <<installing-lttng,install>> the 64-bit versions of
4047 LTTng-UST and Userspace RCU.
4048 . Download, build, and install the 64-bit version of the
4049 latest LTTng-tools{nbsp}{revision}:
4054 $ cd $(mktemp -d) &&
4055 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.9.tar.bz2 &&
4056 tar -xf lttng-tools-latest-2.9.tar.bz2 &&
4057 cd lttng-tools-2.9.* &&
4058 ./configure --with-consumerd32-libdir=/usr/local/lib32 \
4059 --with-consumerd32-bin=/usr/local/lib32/lttng/libexec/lttng-consumerd &&
4061 sudo make install &&
4066 . Pass the following options to man:gcc(1), man:g++(1), or man:clang(1)
4067 when linking your 32-bit application:
4070 -m32 -L/usr/lib32 -L/usr/local/lib32 \
4071 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32
4074 For example, let's rebuild the quick start example in
4075 <<tracing-your-own-user-application,Trace a user application>> as an
4076 instrumented 32-bit application:
4081 $ gcc -m32 -c -I. hello-tp.c
4082 $ gcc -m32 -c hello.c
4083 $ gcc -m32 -o hello hello.o hello-tp.o \
4084 -L/usr/lib32 -L/usr/local/lib32 \
4085 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32 \
4090 No special action is required to execute the 32-bit application and
4091 to trace it: use the command-line man:lttng(1) tool as usual.
4098 man:tracef(3) is a small LTTng-UST API designed for quick,
4099 man:printf(3)-like instrumentation without the burden of
4100 <<tracepoint-provider,creating>> and
4101 <<building-tracepoint-providers-and-user-application,building>>
4102 a tracepoint provider package.
4104 To use `tracef()` in your application:
4106 . In the C or C++ source files where you need to use `tracef()`,
4107 include `<lttng/tracef.h>`:
4112 #include <lttng/tracef.h>
4116 . In the application's source code, use `tracef()` like you would use
4124 tracef("my message: %d (%s)", my_integer, my_string);
4130 . Link your application with `liblttng-ust`:
4135 $ gcc -o app app.c -llttng-ust
4139 To trace the events that `tracef()` calls emit:
4141 * <<enabling-disabling-events,Create an event rule>> which matches the
4142 `lttng_ust_tracef:*` event name:
4147 $ lttng enable-event --userspace 'lttng_ust_tracef:*'
4152 .Limitations of `tracef()`
4154 The `tracef()` utility function was developed to make user space tracing
4155 super simple, albeit with notable disadvantages compared to
4156 <<defining-tracepoints,user-defined tracepoints>>:
4158 * All the emitted events have the same tracepoint provider and
4159 tracepoint names, respectively `lttng_ust_tracef` and `event`.
4160 * There is no static type checking.
4161 * The only event record field you actually get, named `msg`, is a string
4162 potentially containing the values you passed to `tracef()`
4163 using your own format string. This also means that you cannot filter
4164 events with a custom expression at run time because there are no
4166 * Since `tracef()` uses the C standard library's man:vasprintf(3)
4167 function behind the scenes to format the strings at run time, its
4168 expected performance is lower than with user-defined tracepoints,
4169 which do not require a conversion to a string.
4171 Taking this into consideration, `tracef()` is useful for some quick
4172 prototyping and debugging, but you should not consider it for any
4173 permanent and serious applicative instrumentation.
4179 ==== Use `tracelog()`
4181 The man:tracelog(3) API is very similar to <<tracef,`tracef()`>>, with
4182 the difference that it accepts an additional log level parameter.
4184 The goal of `tracelog()` is to ease the migration from logging to
4187 To use `tracelog()` in your application:
4189 . In the C or C++ source files where you need to use `tracelog()`,
4190 include `<lttng/tracelog.h>`:
4195 #include <lttng/tracelog.h>
4199 . In the application's source code, use `tracelog()` like you would use
4200 man:printf(3), except for the first parameter which is the log
4208 tracelog(TRACE_WARNING, "my message: %d (%s)",
4209 my_integer, my_string);
4215 See man:lttng-ust(3) for a list of available log level names.
4217 . Link your application with `liblttng-ust`:
4222 $ gcc -o app app.c -llttng-ust
4226 To trace the events that `tracelog()` calls emit with a log level
4227 _as severe as_ a specific log level:
4229 * <<enabling-disabling-events,Create an event rule>> which matches the
4230 `lttng_ust_tracelog:*` event name and a minimum level
4236 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
4237 --loglevel=TRACE_WARNING
4241 To trace the events that `tracelog()` calls emit with a
4242 _specific log level_:
4244 * Create an event rule which matches the `lttng_ust_tracelog:*`
4245 event name and a specific log level:
4250 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
4251 --loglevel-only=TRACE_INFO
4256 [[prebuilt-ust-helpers]]
4257 === Prebuilt user space tracing helpers
4259 The LTTng-UST package provides a few helpers in the form or preloadable
4260 shared objects which automatically instrument system functions and
4263 The helper shared objects are normally found in dir:{/usr/lib}. If you
4264 built LTTng-UST <<building-from-source,from source>>, they are probably
4265 located in dir:{/usr/local/lib}.
4267 The installed user space tracing helpers in LTTng-UST{nbsp}{revision}
4270 path:{liblttng-ust-libc-wrapper.so}::
4271 path:{liblttng-ust-pthread-wrapper.so}::
4272 <<liblttng-ust-libc-pthread-wrapper,C{nbsp}standard library
4273 memory and POSIX threads function tracing>>.
4275 path:{liblttng-ust-cyg-profile.so}::
4276 path:{liblttng-ust-cyg-profile-fast.so}::
4277 <<liblttng-ust-cyg-profile,Function entry and exit tracing>>.
4279 path:{liblttng-ust-dl.so}::
4280 <<liblttng-ust-dl,Dynamic linker tracing>>.
4282 To use a user space tracing helper with any user application:
4284 * Preload the helper shared object when you start the application:
4289 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so my-app
4293 You can preload more than one helper:
4298 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so:liblttng-ust-dl.so my-app
4304 [[liblttng-ust-libc-pthread-wrapper]]
4305 ==== Instrument C standard library memory and POSIX threads functions
4307 The path:{liblttng-ust-libc-wrapper.so} and
4308 path:{liblttng-ust-pthread-wrapper.so} helpers
4309 add instrumentation to some C standard library and POSIX
4313 .Functions instrumented by preloading path:{liblttng-ust-libc-wrapper.so}.
4315 |TP provider name |TP name |Instrumented function
4317 .6+|`lttng_ust_libc` |`malloc` |man:malloc(3)
4318 |`calloc` |man:calloc(3)
4319 |`realloc` |man:realloc(3)
4320 |`free` |man:free(3)
4321 |`memalign` |man:memalign(3)
4322 |`posix_memalign` |man:posix_memalign(3)
4326 .Functions instrumented by preloading path:{liblttng-ust-pthread-wrapper.so}.
4328 |TP provider name |TP name |Instrumented function
4330 .4+|`lttng_ust_pthread` |`pthread_mutex_lock_req` |man:pthread_mutex_lock(3p) (request time)
4331 |`pthread_mutex_lock_acq` |man:pthread_mutex_lock(3p) (acquire time)
4332 |`pthread_mutex_trylock` |man:pthread_mutex_trylock(3p)
4333 |`pthread_mutex_unlock` |man:pthread_mutex_unlock(3p)
4336 When you preload the shared object, it replaces the functions listed
4337 in the previous tables by wrappers which contain tracepoints and call
4338 the replaced functions.
4341 [[liblttng-ust-cyg-profile]]
4342 ==== Instrument function entry and exit
4344 The path:{liblttng-ust-cyg-profile*.so} helpers can add instrumentation
4345 to the entry and exit points of functions.
4347 man:gcc(1) and man:clang(1) have an option named
4348 https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html[`-finstrument-functions`]
4349 which generates instrumentation calls for entry and exit to functions.
4350 The LTTng-UST function tracing helpers,
4351 path:{liblttng-ust-cyg-profile.so} and
4352 path:{liblttng-ust-cyg-profile-fast.so}, take advantage of this feature
4353 to add tracepoints to the two generated functions (which contain
4354 `cyg_profile` in their names, hence the helper's name).
4356 To use the LTTng-UST function tracing helper, the source files to
4357 instrument must be built using the `-finstrument-functions` compiler
4360 There are two versions of the LTTng-UST function tracing helper:
4362 * **path:{liblttng-ust-cyg-profile-fast.so}** is a lightweight variant
4363 that you should only use when it can be _guaranteed_ that the
4364 complete event stream is recorded without any lost event record.
4365 Any kind of duplicate information is left out.
4367 Assuming no event record is lost, having only the function addresses on
4368 entry is enough to create a call graph, since an event record always
4369 contains the ID of the CPU that generated it.
4371 You can use a tool like man:addr2line(1) to convert function addresses
4372 back to source file names and line numbers.
4374 * **path:{liblttng-ust-cyg-profile.so}** is a more robust variant
4375 which also works in use cases where event records might get discarded or
4376 not recorded from application startup.
4377 In these cases, the trace analyzer needs more information to be
4378 able to reconstruct the program flow.
4380 See man:lttng-ust-cyg-profile(3) to learn more about the instrumentation
4381 points of this helper.
4383 All the tracepoints that this helper provides have the
4384 log level `TRACE_DEBUG_FUNCTION` (see man:lttng-ust(3)).
4386 TIP: It's sometimes a good idea to limit the number of source files that
4387 you compile with the `-finstrument-functions` option to prevent LTTng
4388 from writing an excessive amount of trace data at run time. When using
4389 man:gcc(1), you can use the
4390 `-finstrument-functions-exclude-function-list` option to avoid
4391 instrument entries and exits of specific function names.
4396 ==== Instrument the dynamic linker
4398 The path:{liblttng-ust-dl.so} helper adds instrumentation to the
4399 man:dlopen(3) and man:dlclose(3) function calls.
4401 See man:lttng-ust-dl(3) to learn more about the instrumentation points
4406 [[java-application]]
4407 === User space Java agent
4409 You can instrument any Java application which uses one of the following
4412 * The https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[**`java.util.logging`**]
4413 (JUL) core logging facilities.
4414 * http://logging.apache.org/log4j/1.2/[**Apache log4j 1.2**], since
4415 LTTng 2.6. Note that Apache Log4j{nbsp}2 is not supported.
4418 .LTTng-UST Java agent imported by a Java application.
4419 image::java-app.png[]
4421 Note that the methods described below are new in LTTng{nbsp}{revision}.
4422 Previous LTTng versions use another technique.
4424 NOTE: We use http://openjdk.java.net/[OpenJDK]{nbsp}8 for development
4425 and https://ci.lttng.org/[continuous integration], thus this version is
4426 directly supported. However, the LTTng-UST Java agent is also tested
4427 with OpenJDK{nbsp}7.
4432 ==== Use the LTTng-UST Java agent for `java.util.logging`
4434 To use the LTTng-UST Java agent in a Java application which uses
4435 `java.util.logging` (JUL):
4437 . In the Java application's source code, import the LTTng-UST
4438 log handler package for `java.util.logging`:
4443 import org.lttng.ust.agent.jul.LttngLogHandler;
4447 . Create an LTTng-UST JUL log handler:
4452 Handler lttngUstLogHandler = new LttngLogHandler();
4456 . Add this handler to the JUL loggers which should emit LTTng events:
4461 Logger myLogger = Logger.getLogger("some-logger");
4463 myLogger.addHandler(lttngUstLogHandler);
4467 . Use `java.util.logging` log statements and configuration as usual.
4468 The loggers with an attached LTTng-UST log handler can emit
4471 . Before exiting the application, remove the LTTng-UST log handler from
4472 the loggers attached to it and call its `close()` method:
4477 myLogger.removeHandler(lttngUstLogHandler);
4478 lttngUstLogHandler.close();
4482 This is not strictly necessary, but it is recommended for a clean
4483 disposal of the handler's resources.
4485 . Include the LTTng-UST Java agent's common and JUL-specific JAR files,
4486 path:{lttng-ust-agent-common.jar} and path:{lttng-ust-agent-jul.jar},
4488 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4489 path] when you build the Java application.
4491 The JAR files are typically located in dir:{/usr/share/java}.
4493 IMPORTANT: The LTTng-UST Java agent must be
4494 <<installing-lttng,installed>> for the logging framework your
4497 .Use the LTTng-UST Java agent for `java.util.logging`.
4502 import java.io.IOException;
4503 import java.util.logging.Handler;
4504 import java.util.logging.Logger;
4505 import org.lttng.ust.agent.jul.LttngLogHandler;
4509 private static final int answer = 42;
4511 public static void main(String[] argv) throws Exception
4514 Logger logger = Logger.getLogger("jello");
4516 // Create an LTTng-UST log handler
4517 Handler lttngUstLogHandler = new LttngLogHandler();
4519 // Add the LTTng-UST log handler to our logger
4520 logger.addHandler(lttngUstLogHandler);
4523 logger.info("some info");
4524 logger.warning("some warning");
4526 logger.finer("finer information; the answer is " + answer);
4528 logger.severe("error!");
4530 // Not mandatory, but cleaner
4531 logger.removeHandler(lttngUstLogHandler);
4532 lttngUstLogHandler.close();
4541 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4544 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4545 <<enabling-disabling-events,create an event rule>> matching the
4546 `jello` JUL logger, and <<basic-tracing-session-control,start tracing>>:
4551 $ lttng enable-event --jul jello
4555 Run the compiled class:
4559 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4562 <<basic-tracing-session-control,Stop tracing>> and inspect the
4572 In the resulting trace, an <<event,event record>> generated by a Java
4573 application using `java.util.logging` is named `lttng_jul:event` and
4574 has the following fields:
4577 Log record's message.
4583 Name of the class in which the log statement was executed.
4586 Name of the method in which the log statement was executed.
4589 Logging time (timestamp in milliseconds).
4592 Log level integer value.
4595 ID of the thread in which the log statement was executed.
4597 You can use the opt:lttng-enable-event(1):--loglevel or
4598 opt:lttng-enable-event(1):--loglevel-only option of the
4599 man:lttng-enable-event(1) command to target a range of JUL log levels
4600 or a specific JUL log level.
4605 ==== Use the LTTng-UST Java agent for Apache log4j
4607 To use the LTTng-UST Java agent in a Java application which uses
4610 . In the Java application's source code, import the LTTng-UST
4611 log appender package for Apache log4j:
4616 import org.lttng.ust.agent.log4j.LttngLogAppender;
4620 . Create an LTTng-UST log4j log appender:
4625 Appender lttngUstLogAppender = new LttngLogAppender();
4629 . Add this appender to the log4j loggers which should emit LTTng events:
4634 Logger myLogger = Logger.getLogger("some-logger");
4636 myLogger.addAppender(lttngUstLogAppender);
4640 . Use Apache log4j log statements and configuration as usual. The
4641 loggers with an attached LTTng-UST log appender can emit LTTng events.
4643 . Before exiting the application, remove the LTTng-UST log appender from
4644 the loggers attached to it and call its `close()` method:
4649 myLogger.removeAppender(lttngUstLogAppender);
4650 lttngUstLogAppender.close();
4654 This is not strictly necessary, but it is recommended for a clean
4655 disposal of the appender's resources.
4657 . Include the LTTng-UST Java agent's common and log4j-specific JAR
4658 files, path:{lttng-ust-agent-common.jar} and
4659 path:{lttng-ust-agent-log4j.jar}, in the
4660 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4661 path] when you build the Java application.
4663 The JAR files are typically located in dir:{/usr/share/java}.
4665 IMPORTANT: The LTTng-UST Java agent must be
4666 <<installing-lttng,installed>> for the logging framework your
4669 .Use the LTTng-UST Java agent for Apache log4j.
4674 import org.apache.log4j.Appender;
4675 import org.apache.log4j.Logger;
4676 import org.lttng.ust.agent.log4j.LttngLogAppender;
4680 private static final int answer = 42;
4682 public static void main(String[] argv) throws Exception
4685 Logger logger = Logger.getLogger("jello");
4687 // Create an LTTng-UST log appender
4688 Appender lttngUstLogAppender = new LttngLogAppender();
4690 // Add the LTTng-UST log appender to our logger
4691 logger.addAppender(lttngUstLogAppender);
4694 logger.info("some info");
4695 logger.warn("some warning");
4697 logger.debug("debug information; the answer is " + answer);
4699 logger.fatal("error!");
4701 // Not mandatory, but cleaner
4702 logger.removeAppender(lttngUstLogAppender);
4703 lttngUstLogAppender.close();
4709 Build this example (`$LOG4JPATH` is the path to the Apache log4j JAR
4714 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH Test.java
4717 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4718 <<enabling-disabling-events,create an event rule>> matching the
4719 `jello` log4j logger, and <<basic-tracing-session-control,start tracing>>:
4724 $ lttng enable-event --log4j jello
4728 Run the compiled class:
4732 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH:. Test
4735 <<basic-tracing-session-control,Stop tracing>> and inspect the
4745 In the resulting trace, an <<event,event record>> generated by a Java
4746 application using log4j is named `lttng_log4j:event` and
4747 has the following fields:
4750 Log record's message.
4756 Name of the class in which the log statement was executed.
4759 Name of the method in which the log statement was executed.
4762 Name of the file in which the executed log statement is located.
4765 Line number at which the log statement was executed.
4771 Log level integer value.
4774 Name of the Java thread in which the log statement was executed.
4776 You can use the opt:lttng-enable-event(1):--loglevel or
4777 opt:lttng-enable-event(1):--loglevel-only option of the
4778 man:lttng-enable-event(1) command to target a range of Apache log4j log levels
4779 or a specific log4j log level.
4783 [[java-application-context]]
4784 ==== Provide application-specific context fields in a Java application
4786 A Java application-specific context field is a piece of state provided
4787 by the application which <<adding-context,you can add>>, using the
4788 man:lttng-add-context(1) command, to each <<event,event record>>
4789 produced by the log statements of this application.
4791 For example, a given object might have a current request ID variable.
4792 You can create a context information retriever for this object and
4793 assign a name to this current request ID. You can then, using the
4794 man:lttng-add-context(1) command, add this context field by name to
4795 the JUL or log4j <<channel,channel>>.
4797 To provide application-specific context fields in a Java application:
4799 . In the Java application's source code, import the LTTng-UST
4800 Java agent context classes and interfaces:
4805 import org.lttng.ust.agent.context.ContextInfoManager;
4806 import org.lttng.ust.agent.context.IContextInfoRetriever;
4810 . Create a context information retriever class, that is, a class which
4811 implements the `IContextInfoRetriever` interface:
4816 class MyContextInfoRetriever implements IContextInfoRetriever
4819 public Object retrieveContextInfo(String key)
4821 if (key.equals("intCtx")) {
4823 } else if (key.equals("strContext")) {
4824 return "context value!";
4833 This `retrieveContextInfo()` method is the only member of the
4834 `IContextInfoRetriever` interface. Its role is to return the current
4835 value of a state by name to create a context field. The names of the
4836 context fields and which state variables they return depends on your
4839 All primitive types and objects are supported as context fields.
4840 When `retrieveContextInfo()` returns an object, the context field
4841 serializer calls its `toString()` method to add a string field to
4842 event records. The method can also return `null`, which means that
4843 no context field is available for the required name.
4845 . Register an instance of your context information retriever class to
4846 the context information manager singleton:
4851 IContextInfoRetriever cir = new MyContextInfoRetriever();
4852 ContextInfoManager cim = ContextInfoManager.getInstance();
4853 cim.registerContextInfoRetriever("retrieverName", cir);
4857 . Before exiting the application, remove your context information
4858 retriever from the context information manager singleton:
4863 ContextInfoManager cim = ContextInfoManager.getInstance();
4864 cim.unregisterContextInfoRetriever("retrieverName");
4868 This is not strictly necessary, but it is recommended for a clean
4869 disposal of some manager's resources.
4871 . Build your Java application with LTTng-UST Java agent support as
4872 usual, following the procedure for either the <<jul,JUL>> or
4873 <<log4j,Apache log4j>> framework.
4876 .Provide application-specific context fields in a Java application.
4881 import java.util.logging.Handler;
4882 import java.util.logging.Logger;
4883 import org.lttng.ust.agent.jul.LttngLogHandler;
4884 import org.lttng.ust.agent.context.ContextInfoManager;
4885 import org.lttng.ust.agent.context.IContextInfoRetriever;
4889 // Our context information retriever class
4890 private static class MyContextInfoRetriever
4891 implements IContextInfoRetriever
4894 public Object retrieveContextInfo(String key) {
4895 if (key.equals("intCtx")) {
4897 } else if (key.equals("strContext")) {
4898 return "context value!";
4905 private static final int answer = 42;
4907 public static void main(String args[]) throws Exception
4909 // Get the context information manager instance
4910 ContextInfoManager cim = ContextInfoManager.getInstance();
4912 // Create and register our context information retriever
4913 IContextInfoRetriever cir = new MyContextInfoRetriever();
4914 cim.registerContextInfoRetriever("myRetriever", cir);
4917 Logger logger = Logger.getLogger("jello");
4919 // Create an LTTng-UST log handler
4920 Handler lttngUstLogHandler = new LttngLogHandler();
4922 // Add the LTTng-UST log handler to our logger
4923 logger.addHandler(lttngUstLogHandler);
4926 logger.info("some info");
4927 logger.warning("some warning");
4929 logger.finer("finer information; the answer is " + answer);
4931 logger.severe("error!");
4933 // Not mandatory, but cleaner
4934 logger.removeHandler(lttngUstLogHandler);
4935 lttngUstLogHandler.close();
4936 cim.unregisterContextInfoRetriever("myRetriever");
4945 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4948 <<creating-destroying-tracing-sessions,Create a tracing session>>
4949 and <<enabling-disabling-events,create an event rule>> matching the
4955 $ lttng enable-event --jul jello
4958 <<adding-context,Add the application-specific context fields>> to the
4963 $ lttng add-context --jul --type='$app.myRetriever:intCtx'
4964 $ lttng add-context --jul --type='$app.myRetriever:strContext'
4967 <<basic-tracing-session-control,Start tracing>>:
4974 Run the compiled class:
4978 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4981 <<basic-tracing-session-control,Stop tracing>> and inspect the
4993 [[python-application]]
4994 === User space Python agent
4996 You can instrument a Python 2 or Python 3 application which uses the
4997 standard https://docs.python.org/3/library/logging.html[`logging`]
5000 Each log statement emits an LTTng event once the
5001 application module imports the
5002 <<lttng-ust-agents,LTTng-UST Python agent>> package.
5005 .A Python application importing the LTTng-UST Python agent.
5006 image::python-app.png[]
5008 To use the LTTng-UST Python agent:
5010 . In the Python application's source code, import the LTTng-UST Python
5020 The LTTng-UST Python agent automatically adds its logging handler to the
5021 root logger at import time.
5023 Any log statement that the application executes before this import does
5024 not emit an LTTng event.
5026 IMPORTANT: The LTTng-UST Python agent must be
5027 <<installing-lttng,installed>>.
5029 . Use log statements and logging configuration as usual.
5030 Since the LTTng-UST Python agent adds a handler to the _root_
5031 logger, you can trace any log statement from any logger.
5033 .Use the LTTng-UST Python agent.
5044 logging.basicConfig()
5045 logger = logging.getLogger('my-logger')
5048 logger.debug('debug message')
5049 logger.info('info message')
5050 logger.warn('warn message')
5051 logger.error('error message')
5052 logger.critical('critical message')
5056 if __name__ == '__main__':
5060 NOTE: `logging.basicConfig()`, which adds to the root logger a basic
5061 logging handler which prints to the standard error stream, is not
5062 strictly required for LTTng-UST tracing to work, but in versions of
5063 Python preceding 3.2, you could see a warning message which indicates
5064 that no handler exists for the logger `my-logger`.
5066 <<creating-destroying-tracing-sessions,Create a tracing session>>,
5067 <<enabling-disabling-events,create an event rule>> matching the
5068 `my-logger` Python logger, and <<basic-tracing-session-control,start
5074 $ lttng enable-event --python my-logger
5078 Run the Python script:
5085 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
5095 In the resulting trace, an <<event,event record>> generated by a Python
5096 application is named `lttng_python:event` and has the following fields:
5099 Logging time (string).
5102 Log record's message.
5108 Name of the function in which the log statement was executed.
5111 Line number at which the log statement was executed.
5114 Log level integer value.
5117 ID of the Python thread in which the log statement was executed.
5120 Name of the Python thread in which the log statement was executed.
5122 You can use the opt:lttng-enable-event(1):--loglevel or
5123 opt:lttng-enable-event(1):--loglevel-only option of the
5124 man:lttng-enable-event(1) command to target a range of Python log levels
5125 or a specific Python log level.
5127 When an application imports the LTTng-UST Python agent, the agent tries
5128 to register to a <<lttng-sessiond,session daemon>>. Note that you must
5129 <<start-sessiond,start the session daemon>> _before_ you run the Python
5130 application. If a session daemon is found, the agent tries to register
5131 to it during 5{nbsp}seconds, after which the application continues
5132 without LTTng tracing support. You can override this timeout value with
5133 the env:LTTNG_UST_PYTHON_REGISTER_TIMEOUT environment variable
5136 If the session daemon stops while a Python application with an imported
5137 LTTng-UST Python agent runs, the agent retries to connect and to
5138 register to a session daemon every 3{nbsp}seconds. You can override this
5139 delay with the env:LTTNG_UST_PYTHON_REGISTER_RETRY_DELAY environment
5144 [[proc-lttng-logger-abi]]
5147 The `lttng-tracer` Linux kernel module, part of
5148 <<lttng-modules,LTTng-modules>>, creates the special LTTng logger file
5149 path:{/proc/lttng-logger} when it's loaded. Any application can write
5150 text data to this file to emit an LTTng event.
5153 .An application writes to the LTTng logger file to emit an LTTng event.
5154 image::lttng-logger.png[]
5156 The LTTng logger is the quickest method--not the most efficient,
5157 however--to add instrumentation to an application. It is designed
5158 mostly to instrument shell scripts:
5162 $ echo "Some message, some $variable" > /proc/lttng-logger
5165 Any event that the LTTng logger emits is named `lttng_logger` and
5166 belongs to the Linux kernel <<domain,tracing domain>>. However, unlike
5167 other instrumentation points in the kernel tracing domain, **any Unix
5168 user** can <<enabling-disabling-events,create an event rule>> which
5169 matches its event name, not only the root user or users in the
5170 <<tracing-group,tracing group>>.
5172 To use the LTTng logger:
5174 * From any application, write text data to the path:{/proc/lttng-logger}
5177 The `msg` field of `lttng_logger` event records contains the
5180 NOTE: The maximum message length of an LTTng logger event is
5181 1024{nbsp}bytes. Writing more than this makes the LTTng logger emit more
5182 than one event to contain the remaining data.
5184 You should not use the LTTng logger to trace a user application which
5185 can be instrumented in a more efficient way, namely:
5187 * <<c-application,C and $$C++$$ applications>>.
5188 * <<java-application,Java applications>>.
5189 * <<python-application,Python applications>>.
5191 .Use the LTTng logger.
5196 echo 'Hello, World!' > /proc/lttng-logger
5198 df --human-readable --print-type / > /proc/lttng-logger
5201 <<creating-destroying-tracing-sessions,Create a tracing session>>,
5202 <<enabling-disabling-events,create an event rule>> matching the
5203 `lttng_logger` Linux kernel tracepoint, and
5204 <<basic-tracing-session-control,start tracing>>:
5209 $ lttng enable-event --kernel lttng_logger
5213 Run the Bash script:
5220 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
5231 [[instrumenting-linux-kernel]]
5232 === LTTng kernel tracepoints
5234 NOTE: This section shows how to _add_ instrumentation points to the
5235 Linux kernel. The kernel's subsystems are already thoroughly
5236 instrumented at strategic places for LTTng when you
5237 <<installing-lttng,install>> the <<lttng-modules,LTTng-modules>>
5241 There are two methods to instrument the Linux kernel:
5243 . <<linux-add-lttng-layer,Add an LTTng layer>> over an existing ftrace
5244 tracepoint which uses the `TRACE_EVENT()` API.
5246 Choose this if you want to instrumentation a Linux kernel tree with an
5247 instrumentation point compatible with ftrace, perf, and SystemTap.
5249 . Use an <<linux-lttng-tracepoint-event,LTTng-only approach>> to
5250 instrument an out-of-tree kernel module.
5252 Choose this if you don't need ftrace, perf, or SystemTap support.
5256 [[linux-add-lttng-layer]]
5257 ==== [[instrumenting-linux-kernel-itself]][[mainline-trace-event]][[lttng-adaptation-layer]]Add an LTTng layer to an existing ftrace tracepoint
5259 This section shows how to add an LTTng layer to existing ftrace
5260 instrumentation using the `TRACE_EVENT()` API.
5262 This section does not document the `TRACE_EVENT()` macro. You can
5263 read the following articles to learn more about this API:
5265 * http://lwn.net/Articles/379903/[Using the TRACE_EVENT() macro (Part 1)]
5266 * http://lwn.net/Articles/381064/[Using the TRACE_EVENT() macro (Part 2)]
5267 * http://lwn.net/Articles/383362/[Using the TRACE_EVENT() macro (Part 3)]
5269 The following procedure assumes that your ftrace tracepoints are
5270 correctly defined in their own header and that they are created in
5271 one source file using the `CREATE_TRACE_POINTS` definition.
5273 To add an LTTng layer over an existing ftrace tracepoint:
5275 . Make sure the following kernel configuration options are
5281 * `CONFIG_HIGH_RES_TIMERS`
5282 * `CONFIG_TRACEPOINTS`
5285 . Build the Linux source tree with your custom ftrace tracepoints.
5286 . Boot the resulting Linux image on your target system.
5288 Confirm that the tracepoints exist by looking for their names in the
5289 dir:{/sys/kernel/debug/tracing/events/subsys} directory, where `subsys`
5290 is your subsystem's name.
5292 . Get a copy of the latest LTTng-modules{nbsp}{revision}:
5297 $ cd $(mktemp -d) &&
5298 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.9.tar.bz2 &&
5299 tar -xf lttng-modules-latest-2.9.tar.bz2 &&
5300 cd lttng-modules-2.9.*
5304 . In dir:{instrumentation/events/lttng-module}, relative to the root
5305 of the LTTng-modules source tree, create a header file named
5306 +__subsys__.h+ for your custom subsystem +__subsys__+ and write your
5307 LTTng-modules tracepoint definitions using the LTTng-modules
5310 Start with this template:
5314 .path:{instrumentation/events/lttng-module/my_subsys.h}
5317 #define TRACE_SYSTEM my_subsys
5319 #if !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ)
5320 #define _LTTNG_MY_SUBSYS_H
5322 #include "../../../probes/lttng-tracepoint-event.h"
5323 #include <linux/tracepoint.h>
5325 LTTNG_TRACEPOINT_EVENT(
5327 * Format is identical to TRACE_EVENT()'s version for the three
5328 * following macro parameters:
5331 TP_PROTO(int my_int, const char *my_string),
5332 TP_ARGS(my_int, my_string),
5334 /* LTTng-modules specific macros */
5336 ctf_integer(int, my_int_field, my_int)
5337 ctf_string(my_bar_field, my_bar)
5341 #endif /* !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ) */
5343 #include "../../../probes/define_trace.h"
5347 The entries in the `TP_FIELDS()` section are the list of fields for the
5348 LTTng tracepoint. This is similar to the `TP_STRUCT__entry()` part of
5349 ftrace's `TRACE_EVENT()` macro.
5351 See <<lttng-modules-tp-fields,Tracepoint fields macros>> for a
5352 complete description of the available `ctf_*()` macros.
5354 . Create the LTTng-modules probe's kernel module C source file,
5355 +probes/lttng-probe-__subsys__.c+, where +__subsys__+ is your
5360 .path:{probes/lttng-probe-my-subsys.c}
5362 #include <linux/module.h>
5363 #include "../lttng-tracer.h"
5366 * Build-time verification of mismatch between mainline
5367 * TRACE_EVENT() arguments and the LTTng-modules adaptation
5368 * layer LTTNG_TRACEPOINT_EVENT() arguments.
5370 #include <trace/events/my_subsys.h>
5372 /* Create LTTng tracepoint probes */
5373 #define LTTNG_PACKAGE_BUILD
5374 #define CREATE_TRACE_POINTS
5375 #define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
5377 #include "../instrumentation/events/lttng-module/my_subsys.h"
5379 MODULE_LICENSE("GPL and additional rights");
5380 MODULE_AUTHOR("Your name <your-email>");
5381 MODULE_DESCRIPTION("LTTng my_subsys probes");
5382 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
5383 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
5384 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
5385 LTTNG_MODULES_EXTRAVERSION);
5389 . Edit path:{probes/KBuild} and add your new kernel module object
5390 next to the existing ones:
5394 .path:{probes/KBuild}
5398 obj-m += lttng-probe-module.o
5399 obj-m += lttng-probe-power.o
5401 obj-m += lttng-probe-my-subsys.o
5407 . Build and install the LTTng kernel modules:
5412 $ make KERNELDIR=/path/to/linux
5413 # make modules_install && depmod -a
5417 Replace `/path/to/linux` with the path to the Linux source tree where
5418 you defined and used tracepoints with ftrace's `TRACE_EVENT()` macro.
5420 Note that you can also use the
5421 <<lttng-tracepoint-event-code,`LTTNG_TRACEPOINT_EVENT_CODE()` macro>>
5422 instead of `LTTNG_TRACEPOINT_EVENT()` to use custom local variables and
5423 C code that need to be executed before the event fields are recorded.
5425 The best way to learn how to use the previous LTTng-modules macros is to
5426 inspect the existing LTTng-modules tracepoint definitions in the
5427 dir:{instrumentation/events/lttng-module} header files. Compare them
5428 with the Linux kernel mainline versions in the
5429 dir:{include/trace/events} directory of the Linux source tree.
5433 [[lttng-tracepoint-event-code]]
5434 ===== Use custom C code to access the data for tracepoint fields
5436 Although we recommended to always use the
5437 <<lttng-adaptation-layer,`LTTNG_TRACEPOINT_EVENT()`>> macro to describe
5438 the arguments and fields of an LTTng-modules tracepoint when possible,
5439 sometimes you need a more complex process to access the data that the
5440 tracer records as event record fields. In other words, you need local
5441 variables and multiple C{nbsp}statements instead of simple
5442 argument-based expressions that you pass to the
5443 <<lttng-modules-tp-fields,`ctf_*()` macros of `TP_FIELDS()`>>.
5445 You can use the `LTTNG_TRACEPOINT_EVENT_CODE()` macro instead of
5446 `LTTNG_TRACEPOINT_EVENT()` to declare custom local variables and define
5447 a block of C{nbsp}code to be executed before LTTng records the fields.
5448 The structure of this macro is:
5451 .`LTTNG_TRACEPOINT_EVENT_CODE()` macro syntax.
5453 LTTNG_TRACEPOINT_EVENT_CODE(
5455 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5456 * version for the following three macro parameters:
5459 TP_PROTO(int my_int, const char *my_string),
5460 TP_ARGS(my_int, my_string),
5462 /* Declarations of custom local variables */
5465 unsigned long b = 0;
5466 const char *name = "(undefined)";
5467 struct my_struct *my_struct;
5471 * Custom code which uses both tracepoint arguments
5472 * (in TP_ARGS()) and local variables (in TP_locvar()).
5474 * Local variables are actually members of a structure pointed
5475 * to by the special variable tp_locvar.
5479 tp_locvar->a = my_int + 17;
5480 tp_locvar->my_struct = get_my_struct_at(tp_locvar->a);
5481 tp_locvar->b = my_struct_compute_b(tp_locvar->my_struct);
5482 tp_locvar->name = my_struct_get_name(tp_locvar->my_struct);
5483 put_my_struct(tp_locvar->my_struct);
5492 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5493 * version for this, except that tp_locvar members can be
5494 * used in the argument expression parameters of
5495 * the ctf_*() macros.
5498 ctf_integer(unsigned long, my_struct_b, tp_locvar->b)
5499 ctf_integer(int, my_struct_a, tp_locvar->a)
5500 ctf_string(my_string_field, my_string)
5501 ctf_string(my_struct_name, tp_locvar->name)
5506 IMPORTANT: The C code defined in `TP_code()` must not have any side
5507 effects when executed. In particular, the code must not allocate
5508 memory or get resources without deallocating this memory or putting
5509 those resources afterwards.
5512 [[instrumenting-linux-kernel-tracing]]
5513 ==== Load and unload a custom probe kernel module
5515 You must load a <<lttng-adaptation-layer,created LTTng-modules probe
5516 kernel module>> in the kernel before it can emit LTTng events.
5518 To load the default probe kernel modules and a custom probe kernel
5521 * Use the opt:lttng-sessiond(8):--extra-kmod-probes option to give extra
5522 probe modules to load when starting a root <<lttng-sessiond,session
5526 .Load the `my_subsys`, `usb`, and the default probe modules.
5530 # lttng-sessiond --extra-kmod-probes=my_subsys,usb
5535 You only need to pass the subsystem name, not the whole kernel module
5538 To load _only_ a given custom probe kernel module:
5540 * Use the opt:lttng-sessiond(8):--kmod-probes option to give the probe
5541 modules to load when starting a root session daemon:
5544 .Load only the `my_subsys` and `usb` probe modules.
5548 # lttng-sessiond --kmod-probes=my_subsys,usb
5553 To confirm that a probe module is loaded:
5560 $ lsmod | grep lttng_probe_usb
5564 To unload the loaded probe modules:
5566 * Kill the session daemon with `SIGTERM`:
5571 # pkill lttng-sessiond
5575 You can also use man:modprobe(8)'s `--remove` option if the session
5576 daemon terminates abnormally.
5579 [[controlling-tracing]]
5582 Once an application or a Linux kernel is
5583 <<instrumenting,instrumented>> for LTTng tracing,
5586 This section is divided in topics on how to use the various
5587 <<plumbing,components of LTTng>>, in particular the <<lttng-cli,cmd:lttng
5588 command-line tool>>, to _control_ the LTTng daemons and tracers.
5590 NOTE: In the following subsections, we refer to an man:lttng(1) command
5591 using its man page name. For example, instead of _Run the `create`
5592 command to..._, we use _Run the man:lttng-create(1) command to..._.
5596 === Start a session daemon
5598 In some situations, you need to run a <<lttng-sessiond,session daemon>>
5599 (man:lttng-sessiond(8)) _before_ you can use the man:lttng(1)
5602 You will see the following error when you run a command while no session
5606 Error: No session daemon is available
5609 The only command that automatically runs a session daemon is
5610 man:lttng-create(1), which you use to
5611 <<creating-destroying-tracing-sessions,create a tracing session>>. While
5612 this is most of the time the first operation that you do, sometimes it's
5613 not. Some examples are:
5615 * <<list-instrumentation-points,List the available instrumentation points>>.
5616 * <<saving-loading-tracing-session,Load a tracing session configuration>>.
5618 [[tracing-group]] Each Unix user must have its own running session
5619 daemon to trace user applications. The session daemon that the root user
5620 starts is the only one allowed to control the LTTng kernel tracer. Users
5621 that are part of the _tracing group_ can control the root session
5622 daemon. The default tracing group name is `tracing`; you can set it to
5623 something else with the opt:lttng-sessiond(8):--group option when you
5624 start the root session daemon.
5626 To start a user session daemon:
5628 * Run man:lttng-sessiond(8):
5633 $ lttng-sessiond --daemonize
5637 To start the root session daemon:
5639 * Run man:lttng-sessiond(8) as the root user:
5644 # lttng-sessiond --daemonize
5648 In both cases, remove the opt:lttng-sessiond(8):--daemonize option to
5649 start the session daemon in foreground.
5651 To stop a session daemon, use man:kill(1) on its process ID (standard
5654 Note that some Linux distributions could manage the LTTng session daemon
5655 as a service. In this case, you should use the service manager to
5656 start, restart, and stop session daemons.
5659 [[creating-destroying-tracing-sessions]]
5660 === Create and destroy a tracing session
5662 Almost all the LTTng control operations happen in the scope of
5663 a <<tracing-session,tracing session>>, which is the dialogue between the
5664 <<lttng-sessiond,session daemon>> and you.
5666 To create a tracing session with a generated name:
5668 * Use the man:lttng-create(1) command:
5677 The created tracing session's name is `auto` followed by the
5680 To create a tracing session with a specific name:
5682 * Use the optional argument of the man:lttng-create(1) command:
5687 $ lttng create my-session
5691 Replace `my-session` with the specific tracing session name.
5693 LTTng appends the creation date to the created tracing session's name.
5695 LTTng writes the traces of a tracing session in
5696 +$LTTNG_HOME/lttng-trace/__name__+ by default, where +__name__+ is the
5697 name of the tracing session. Note that the env:LTTNG_HOME environment
5698 variable defaults to `$HOME` if not set.
5700 To output LTTng traces to a non-default location:
5702 * Use the opt:lttng-create(1):--output option of the man:lttng-create(1) command:
5707 $ lttng create my-session --output=/tmp/some-directory
5711 You may create as many tracing sessions as you wish.
5713 To list all the existing tracing sessions for your Unix user:
5715 * Use the man:lttng-list(1) command:
5724 When you create a tracing session, it is set as the _current tracing
5725 session_. The following man:lttng(1) commands operate on the current
5726 tracing session when you don't specify one:
5728 [role="list-3-cols"]
5745 To change the current tracing session:
5747 * Use the man:lttng-set-session(1) command:
5752 $ lttng set-session new-session
5756 Replace `new-session` by the name of the new current tracing session.
5758 When you are done tracing in a given tracing session, you can destroy
5759 it. This operation frees the resources taken by the tracing session
5760 to destroy; it does not destroy the trace data that LTTng wrote for
5761 this tracing session.
5763 To destroy the current tracing session:
5765 * Use the man:lttng-destroy(1) command:
5775 [[list-instrumentation-points]]
5776 === List the available instrumentation points
5778 The <<lttng-sessiond,session daemon>> can query the running instrumented
5779 user applications and the Linux kernel to get a list of available
5780 instrumentation points. For the Linux kernel <<domain,tracing domain>>,
5781 they are tracepoints and system calls. For the user space tracing
5782 domain, they are tracepoints. For the other tracing domains, they are
5785 To list the available instrumentation points:
5787 * Use the man:lttng-list(1) command with the requested tracing domain's
5791 * opt:lttng-list(1):--kernel: Linux kernel tracepoints (your Unix user
5792 must be a root user, or it must be a member of the
5793 <<tracing-group,tracing group>>).
5794 * opt:lttng-list(1):--kernel with opt:lttng-list(1):--syscall: Linux
5795 kernel system calls (your Unix user must be a root user, or it must be
5796 a member of the tracing group).
5797 * opt:lttng-list(1):--userspace: user space tracepoints.
5798 * opt:lttng-list(1):--jul: `java.util.logging` loggers.
5799 * opt:lttng-list(1):--log4j: Apache log4j loggers.
5800 * opt:lttng-list(1):--python: Python loggers.
5803 .List the available user space tracepoints.
5807 $ lttng list --userspace
5811 .List the available Linux kernel system call tracepoints.
5815 $ lttng list --kernel --syscall
5820 [[enabling-disabling-events]]
5821 === Create and enable an event rule
5823 Once you <<creating-destroying-tracing-sessions,create a tracing
5824 session>>, you can create <<event,event rules>> with the
5825 man:lttng-enable-event(1) command.
5827 You specify each condition with a command-line option. The available
5828 condition options are shown in the following table.
5830 [role="growable",cols="asciidoc,asciidoc,default"]
5831 .Condition command-line options for the man:lttng-enable-event(1) command.
5833 |Option |Description |Applicable tracing domains
5839 . +--probe=__ADDR__+
5840 . +--function=__ADDR__+
5843 Instead of using the default _tracepoint_ instrumentation type, use:
5845 . A Linux system call.
5846 . A Linux https://lwn.net/Articles/132196/[KProbe] (symbol or address).
5847 . The entry and return points of a Linux function (symbol or address).
5851 |First positional argument.
5854 Tracepoint or system call name. In the case of a Linux KProbe or
5855 function, this is a custom name given to the event rule. With the
5856 JUL, log4j, and Python domains, this is a logger name.
5858 With a tracepoint, logger, or system call name, the last character
5859 can be `*` to match anything that remains.
5866 . +--loglevel=__LEVEL__+
5867 . +--loglevel-only=__LEVEL__+
5870 . Match only tracepoints or log statements with a logging level at
5871 least as severe as +__LEVEL__+.
5872 . Match only tracepoints or log statements with a logging level
5873 equal to +__LEVEL__+.
5875 See man:lttng-enable-event(1) for the list of available logging level
5878 |User space, JUL, log4j, and Python.
5880 |+--exclude=__EXCLUSIONS__+
5883 When you use a `*` character at the end of the tracepoint or logger
5884 name (first positional argument), exclude the specific names in the
5885 comma-delimited list +__EXCLUSIONS__+.
5888 User space, JUL, log4j, and Python.
5890 |+--filter=__EXPR__+
5893 Match only events which satisfy the expression +__EXPR__+.
5895 See man:lttng-enable-event(1) to learn more about the syntax of a
5902 You attach an event rule to a <<channel,channel>> on creation. If you do
5903 not specify the channel with the opt:lttng-enable-event(1):--channel
5904 option, and if the event rule to create is the first in its
5905 <<domain,tracing domain>> for a given tracing session, then LTTng
5906 creates a _default channel_ for you. This default channel is reused in
5907 subsequent invocations of the man:lttng-enable-event(1) command for the
5908 same tracing domain.
5910 An event rule is always enabled at creation time.
5912 The following examples show how you can combine the previous
5913 command-line options to create simple to more complex event rules.
5915 .Create an event rule targetting a Linux kernel tracepoint (default channel).
5919 $ lttng enable-event --kernel sched_switch
5923 .Create an event rule matching four Linux kernel system calls (default channel).
5927 $ lttng enable-event --kernel --syscall open,write,read,close
5931 .Create event rules matching tracepoints with filter expressions (default channel).
5935 $ lttng enable-event --kernel sched_switch --filter='prev_comm == "bash"'
5940 $ lttng enable-event --kernel --all \
5941 --filter='$ctx.tid == 1988 || $ctx.tid == 1534'
5946 $ lttng enable-event --jul my_logger \
5947 --filter='$app.retriever:cur_msg_id > 3'
5950 IMPORTANT: Make sure to always quote the filter string when you
5951 use man:lttng(1) from a shell.
5954 .Create an event rule matching any user space tracepoint of a given tracepoint provider with a log level range (default channel).
5958 $ lttng enable-event --userspace my_app:'*' --loglevel=TRACE_INFO
5961 IMPORTANT: Make sure to always quote the wildcard character when you
5962 use man:lttng(1) from a shell.
5965 .Create an event rule matching multiple Python loggers with a wildcard and with exclusions (default channel).
5969 $ lttng enable-event --python my-app.'*' \
5970 --exclude='my-app.module,my-app.hello'
5974 .Create an event rule matching any Apache log4j logger with a specific log level (default channel).
5978 $ lttng enable-event --log4j --all --loglevel-only=LOG4J_WARN
5982 .Create an event rule attached to a specific channel matching a specific user space tracepoint provider and tracepoint.
5986 $ lttng enable-event --userspace my_app:my_tracepoint --channel=my-channel
5990 The event rules of a given channel form a whitelist: as soon as an
5991 emitted event passes one of them, LTTng can record the event. For
5992 example, an event named `my_app:my_tracepoint` emitted from a user space
5993 tracepoint with a `TRACE_ERROR` log level passes both of the following
5998 $ lttng enable-event --userspace my_app:my_tracepoint
5999 $ lttng enable-event --userspace my_app:my_tracepoint \
6000 --loglevel=TRACE_INFO
6003 The second event rule is redundant: the first one includes
6007 [[disable-event-rule]]
6008 === Disable an event rule
6010 To disable an event rule that you <<enabling-disabling-events,created>>
6011 previously, use the man:lttng-disable-event(1) command. This command
6012 disables _all_ the event rules (of a given tracing domain and channel)
6013 which match an instrumentation point. The other conditions are not
6014 supported as of LTTng{nbsp}{revision}.
6016 The LTTng tracer does not record an emitted event which passes
6017 a _disabled_ event rule.
6019 .Disable an event rule matching a Python logger (default channel).
6023 $ lttng disable-event --python my-logger
6027 .Disable an event rule matching all `java.util.logging` loggers (default channel).
6031 $ lttng disable-event --jul '*'
6035 .Disable _all_ the event rules of the default channel.
6037 The opt:lttng-disable-event(1):--all-events option is not, like the
6038 opt:lttng-enable-event(1):--all option of man:lttng-enable-event(1), the
6039 equivalent of the event name `*` (wildcard): it disables _all_ the event
6040 rules of a given channel.
6044 $ lttng disable-event --jul --all-events
6048 NOTE: You cannot delete an event rule once you create it.
6052 === Get the status of a tracing session
6054 To get the status of the current tracing session, that is, its
6055 parameters, its channels, event rules, and their attributes:
6057 * Use the man:lttng-status(1) command:
6067 To get the status of any tracing session:
6069 * Use the man:lttng-list(1) command with the tracing session's name:
6074 $ lttng list my-session
6078 Replace `my-session` with the desired tracing session's name.
6081 [[basic-tracing-session-control]]
6082 === Start and stop a tracing session
6084 Once you <<creating-destroying-tracing-sessions,create a tracing
6086 <<enabling-disabling-events,create one or more event rules>>,
6087 you can start and stop the tracers for this tracing session.
6089 To start tracing in the current tracing session:
6091 * Use the man:lttng-start(1) command:
6100 LTTng is very flexible: you can launch user applications before
6101 or after the you start the tracers. The tracers only record the events
6102 if they pass enabled event rules and if they occur while the tracers are
6105 To stop tracing in the current tracing session:
6107 * Use the man:lttng-stop(1) command:
6116 If there were <<channel-overwrite-mode-vs-discard-mode,lost event
6117 records>> or lost sub-buffers since the last time you ran
6118 man:lttng-start(1), warnings are printed when you run the
6119 man:lttng-stop(1) command.
6122 [[enabling-disabling-channels]]
6123 === Create a channel
6125 Once you create a tracing session, you can create a <<channel,channel>>
6126 with the man:lttng-enable-channel(1) command.
6128 Note that LTTng automatically creates a default channel when, for a
6129 given <<domain,tracing domain>>, no channels exist and you
6130 <<enabling-disabling-events,create>> the first event rule. This default
6131 channel is named `channel0` and its attributes are set to reasonable
6132 values. Therefore, you only need to create a channel when you need
6133 non-default attributes.
6135 You specify each non-default channel attribute with a command-line
6136 option when you use the man:lttng-enable-channel(1) command. The
6137 available command-line options are:
6139 [role="growable",cols="asciidoc,asciidoc"]
6140 .Command-line options for the man:lttng-enable-channel(1) command.
6142 |Option |Description
6148 <<channel-overwrite-mode-vs-discard-mode,event loss mode>> instead of
6149 the default _discard_ mode.
6151 |`--buffers-pid` (user space tracing domain only)
6154 Use the per-process <<channel-buffering-schemes,buffering scheme>>
6155 instead of the default per-user buffering scheme.
6157 |+--subbuf-size=__SIZE__+
6160 Allocate sub-buffers of +__SIZE__+ bytes (power of two), for each CPU,
6161 either for each Unix user (default), or for each instrumented process.
6163 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
6165 |+--num-subbuf=__COUNT__+
6168 Allocate +__COUNT__+ sub-buffers (power of two), for each CPU, either
6169 for each Unix user (default), or for each instrumented process.
6171 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
6173 |+--tracefile-size=__SIZE__+
6176 Set the maximum size of each trace file that this channel writes within
6177 a stream to +__SIZE__+ bytes instead of no maximum.
6179 See <<tracefile-rotation,Trace file count and size>>.
6181 |+--tracefile-count=__COUNT__+
6184 Limit the number of trace files that this channel creates to
6185 +__COUNT__+ channels instead of no limit.
6187 See <<tracefile-rotation,Trace file count and size>>.
6189 |+--switch-timer=__PERIODUS__+
6192 Set the <<channel-switch-timer,switch timer period>>
6193 to +__PERIODUS__+{nbsp}µs.
6195 |+--read-timer=__PERIODUS__+
6198 Set the <<channel-read-timer,read timer period>>
6199 to +__PERIODUS__+{nbsp}µs.
6201 |+--output=__TYPE__+ (Linux kernel tracing domain only)
6204 Set the channel's output type to +__TYPE__+, either `mmap` or `splice`.
6208 You can only create a channel in the Linux kernel and user space
6209 <<domain,tracing domains>>: other tracing domains have their own channel
6210 created on the fly when <<enabling-disabling-events,creating event
6215 Because of a current LTTng limitation, you must create all channels
6216 _before_ you <<basic-tracing-session-control,start tracing>> in a given
6217 tracing session, that is, before the first time you run
6220 Since LTTng automatically creates a default channel when you use the
6221 man:lttng-enable-event(1) command with a specific tracing domain, you
6222 cannot, for example, create a Linux kernel event rule, start tracing,
6223 and then create a user space event rule, because no user space channel
6224 exists yet and it's too late to create one.
6226 For this reason, make sure to configure your channels properly
6227 before starting the tracers for the first time!
6230 The following examples show how you can combine the previous
6231 command-line options to create simple to more complex channels.
6233 .Create a Linux kernel channel with default attributes.
6237 $ lttng enable-channel --kernel my-channel
6241 .Create a user space channel with 4 sub-buffers or 1{nbsp}MiB each, per CPU, per instrumented process.
6245 $ lttng enable-channel --userspace --num-subbuf=4 --subbuf-size=1M \
6246 --buffers-pid my-channel
6250 .Create a Linux kernel channel which rotates 8 trace files of 4{nbsp}MiB each for each stream
6254 $ lttng enable-channel --kernel --tracefile-count=8 \
6255 --tracefile-size=4194304 my-channel
6259 .Create a user space channel in overwrite (or _flight recorder_) mode.
6263 $ lttng enable-channel --userspace --overwrite my-channel
6267 You can <<enabling-disabling-events,create>> the same event rule in
6268 two different channels:
6272 $ lttng enable-event --userspace --channel=my-channel app:tp
6273 $ lttng enable-event --userspace --channel=other-channel app:tp
6276 If both channels are enabled, when a tracepoint named `app:tp` is
6277 reached, LTTng records two events, one for each channel.
6281 === Disable a channel
6283 To disable a specific channel that you <<enabling-disabling-channels,created>>
6284 previously, use the man:lttng-disable-channel(1) command.
6286 .Disable a specific Linux kernel channel.
6290 $ lttng disable-channel --kernel my-channel
6294 The state of a channel precedes the individual states of event rules
6295 attached to it: event rules which belong to a disabled channel, even if
6296 they are enabled, are also considered disabled.
6300 === Add context fields to a channel
6302 Event record fields in trace files provide important information about
6303 events that occured previously, but sometimes some external context may
6304 help you solve a problem faster. Examples of context fields are:
6306 * The **process ID**, **thread ID**, **process name**, and
6307 **process priority** of the thread in which the event occurs.
6308 * The **hostname** of the system on which the event occurs.
6309 * The current values of many possible **performance counters** using
6311 ** CPU cycles, stalled cycles, idle cycles, and the other cycle types.
6313 ** Branch instructions, misses, and loads.
6315 * Any context defined at the application level (supported for the
6316 JUL and log4j <<domain,tracing domains>>).
6318 To get the full list of available context fields, see
6319 `lttng add-context --list`. Some context fields are reserved for a
6320 specific <<domain,tracing domain>> (Linux kernel or user space).
6322 You add context fields to <<channel,channels>>. All the events
6323 that a channel with added context fields records contain those fields.
6325 To add context fields to one or all the channels of a given tracing
6328 * Use the man:lttng-add-context(1) command.
6330 .Add context fields to all the channels of the current tracing session.
6332 The following command line adds the virtual process identifier and
6333 the per-thread CPU cycles count fields to all the user space channels
6334 of the current tracing session.
6338 $ lttng add-context --userspace --type=vpid --type=perf:thread:cpu-cycles
6342 .Add performance counter context fields by raw ID
6344 See man:lttng-add-context(1) for the exact format of the context field
6345 type, which is partly compatible with the format used in
6350 $ lttng add-context --userspace --type=perf:thread:raw:r0110:test
6351 $ lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted
6355 .Add a context field to a specific channel.
6357 The following command line adds the thread identifier context field
6358 to the Linux kernel channel named `my-channel` in the current
6363 $ lttng add-context --kernel --channel=my-channel --type=tid
6367 .Add an application-specific context field to a specific channel.
6369 The following command line adds the `cur_msg_id` context field of the
6370 `retriever` context retriever for all the instrumented
6371 <<java-application,Java applications>> recording <<event,event records>>
6372 in the channel named `my-channel`:
6376 $ lttng add-context --kernel --channel=my-channel \
6377 --type='$app:retriever:cur_msg_id'
6380 IMPORTANT: Make sure to always quote the `$` character when you
6381 use man:lttng-add-context(1) from a shell.
6384 NOTE: You cannot remove context fields from a channel once you add it.
6389 === Track process IDs
6391 It's often useful to allow only specific process IDs (PIDs) to emit
6392 events. For example, you may wish to record all the system calls made by
6393 a given process (à la http://linux.die.net/man/1/strace[strace]).
6395 The man:lttng-track(1) and man:lttng-untrack(1) commands serve this
6396 purpose. Both commands operate on a whitelist of process IDs. You _add_
6397 entries to this whitelist with the man:lttng-track(1) command and remove
6398 entries with the man:lttng-untrack(1) command. Any process which has one
6399 of the PIDs in the whitelist is allowed to emit LTTng events which pass
6400 an enabled <<event,event rule>>.
6402 NOTE: The PID tracker tracks the _numeric process IDs_. Should a
6403 process with a given tracked ID exit and another process be given this
6404 ID, then the latter would also be allowed to emit events.
6406 .Track and untrack process IDs.
6408 For the sake of the following example, assume the target system has 16
6412 <<creating-destroying-tracing-sessions,create a tracing session>>,
6413 the whitelist contains all the possible PIDs:
6416 .All PIDs are tracked.
6417 image::track-all.png[]
6419 When the whitelist is full and you use the man:lttng-track(1) command to
6420 specify some PIDs to track, LTTng first clears the whitelist, then it
6421 tracks the specific PIDs. After:
6425 $ lttng track --pid=3,4,7,10,13
6431 .PIDs 3, 4, 7, 10, and 13 are tracked.
6432 image::track-3-4-7-10-13.png[]
6434 You can add more PIDs to the whitelist afterwards:
6438 $ lttng track --pid=1,15,16
6444 .PIDs 1, 15, and 16 are added to the whitelist.
6445 image::track-1-3-4-7-10-13-15-16.png[]
6447 The man:lttng-untrack(1) command removes entries from the PID tracker's
6448 whitelist. Given the previous example, the following command:
6452 $ lttng untrack --pid=3,7,10,13
6455 leads to this whitelist:
6458 .PIDs 3, 7, 10, and 13 are removed from the whitelist.
6459 image::track-1-4-15-16.png[]
6461 LTTng can track all possible PIDs again using the opt:track(1):--all
6466 $ lttng track --pid --all
6469 The result is, again:
6472 .All PIDs are tracked.
6473 image::track-all.png[]
6476 .Track only specific PIDs
6478 A very typical use case with PID tracking is to start with an empty
6479 whitelist, then <<basic-tracing-session-control,start the tracers>>, and
6480 then add PIDs manually while tracers are active. You can accomplish this
6481 by using the opt:lttng-untrack(1):--all option of the
6482 man:lttng-untrack(1) command to clear the whitelist after you
6483 <<creating-destroying-tracing-sessions,create a tracing session>>:
6487 $ lttng untrack --pid --all
6493 .No PIDs are tracked.
6494 image::untrack-all.png[]
6496 If you trace with this whitelist configuration, the tracer records no
6497 events for this <<domain,tracing domain>> because no processes are
6498 tracked. You can use the man:lttng-track(1) command as usual to track
6499 specific PIDs, for example:
6503 $ lttng track --pid=6,11
6509 .PIDs 6 and 11 are tracked.
6510 image::track-6-11.png[]
6515 [[saving-loading-tracing-session]]
6516 === Save and load tracing session configurations
6518 Configuring a <<tracing-session,tracing session>> can be long. Some of
6519 the tasks involved are:
6521 * <<enabling-disabling-channels,Create channels>> with
6522 specific attributes.
6523 * <<adding-context,Add context fields>> to specific channels.
6524 * <<enabling-disabling-events,Create event rules>> with specific log
6525 level and filter conditions.
6527 If you use LTTng to solve real world problems, chances are you have to
6528 record events using the same tracing session setup over and over,
6529 modifying a few variables each time in your instrumented program
6530 or environment. To avoid constant tracing session reconfiguration,
6531 the man:lttng(1) command-line tool can save and load tracing session
6532 configurations to/from XML files.
6534 To save a given tracing session configuration:
6536 * Use the man:lttng-save(1) command:
6541 $ lttng save my-session
6545 Replace `my-session` with the name of the tracing session to save.
6547 LTTng saves tracing session configurations to
6548 dir:{$LTTNG_HOME/.lttng/sessions} by default. Note that the
6549 env:LTTNG_HOME environment variable defaults to `$HOME` if not set. Use
6550 the opt:lttng-save(1):--output-path option to change this destination
6553 LTTng saves all configuration parameters, for example:
6555 * The tracing session name.
6556 * The trace data output path.
6557 * The channels with their state and all their attributes.
6558 * The context fields you added to channels.
6559 * The event rules with their state, log level and filter conditions.
6561 To load a tracing session:
6563 * Use the man:lttng-load(1) command:
6568 $ lttng load my-session
6572 Replace `my-session` with the name of the tracing session to load.
6574 When LTTng loads a configuration, it restores your saved tracing session
6575 as if you just configured it manually.
6577 See man:lttng(1) for the complete list of command-line options. You
6578 can also save and load all many sessions at a time, and decide in which
6579 directory to output the XML files.
6582 [[sending-trace-data-over-the-network]]
6583 === Send trace data over the network
6585 LTTng can send the recorded trace data to a remote system over the
6586 network instead of writing it to the local file system.
6588 To send the trace data over the network:
6590 . On the _remote_ system (which can also be the target system),
6591 start an LTTng <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)):
6600 . On the _target_ system, create a tracing session configured to
6601 send trace data over the network:
6606 $ lttng create my-session --set-url=net://remote-system
6610 Replace `remote-system` by the host name or IP address of the
6611 remote system. See man:lttng-create(1) for the exact URL format.
6613 . On the target system, use the man:lttng(1) command-line tool as usual.
6614 When tracing is active, the target's consumer daemon sends sub-buffers
6615 to the relay daemon running on the remote system instead of flushing
6616 them to the local file system. The relay daemon writes the received
6617 packets to the local file system.
6619 The relay daemon writes trace files to
6620 +$LTTNG_HOME/lttng-traces/__hostname__/__session__+ by default, where
6621 +__hostname__+ is the host name of the target system and +__session__+
6622 is the tracing session name. Note that the env:LTTNG_HOME environment
6623 variable defaults to `$HOME` if not set. Use the
6624 opt:lttng-relayd(8):--output option of man:lttng-relayd(8) to write
6625 trace files to another base directory.
6630 === View events as LTTng emits them (noch:{LTTng} live)
6632 LTTng live is a network protocol implemented by the <<lttng-relayd,relay
6633 daemon>> (man:lttng-relayd(8)) to allow compatible trace viewers to
6634 display events as LTTng emits them on the target system while tracing is
6637 The relay daemon creates a _tee_: it forwards the trace data to both
6638 the local file system and to connected live viewers:
6641 .The relay daemon creates a _tee_, forwarding the trace data to both trace files and a connected live viewer.
6646 . On the _target system_, create a <<tracing-session,tracing session>>
6652 $ lttng create my-session --live
6656 This spawns a local relay daemon.
6658 . Start the live viewer and configure it to connect to the relay
6659 daemon. For example, with http://diamon.org/babeltrace[Babeltrace]:
6664 $ babeltrace --input-format=lttng-live \
6665 net://localhost/host/hostname/my-session
6672 * `hostname` with the host name of the target system.
6673 * `my-session` with the name of the tracing session to view.
6676 . Configure the tracing session as usual with the man:lttng(1)
6677 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6679 You can list the available live tracing sessions with Babeltrace:
6683 $ babeltrace --input-format=lttng-live net://localhost
6686 You can start the relay daemon on another system. In this case, you need
6687 to specify the relay daemon's URL when you create the tracing session
6688 with the opt:lttng-create(1):--set-url option. You also need to replace
6689 `localhost` in the procedure above with the host name of the system on
6690 which the relay daemon is running.
6692 See man:lttng-create(1) and man:lttng-relayd(8) for the complete list of
6693 command-line options.
6697 [[taking-a-snapshot]]
6698 === Take a snapshot of the current sub-buffers of a tracing session
6700 The normal behavior of LTTng is to append full sub-buffers to growing
6701 trace data files. This is ideal to keep a full history of the events
6702 that occurred on the target system, but it can
6703 represent too much data in some situations. For example, you may wish
6704 to trace your application continuously until some critical situation
6705 happens, in which case you only need the latest few recorded
6706 events to perform the desired analysis, not multi-gigabyte trace files.
6708 With the man:lttng-snapshot(1) command, you can take a snapshot of the
6709 current sub-buffers of a given <<tracing-session,tracing session>>.
6710 LTTng can write the snapshot to the local file system or send it over
6715 . Create a tracing session in _snapshot mode_:
6720 $ lttng create my-session --snapshot
6724 The <<channel-overwrite-mode-vs-discard-mode,event loss mode>> of
6725 <<channel,channels>> created in this mode is automatically set to
6726 _overwrite_ (flight recorder mode).
6728 . Configure the tracing session as usual with the man:lttng(1)
6729 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6731 . **Optional**: When you need to take a snapshot,
6732 <<basic-tracing-session-control,stop tracing>>.
6734 You can take a snapshot when the tracers are active, but if you stop
6735 them first, you are sure that the data in the sub-buffers does not
6736 change before you actually take the snapshot.
6743 $ lttng snapshot record --name=my-first-snapshot
6747 LTTng writes the current sub-buffers of all the current tracing
6748 session's channels to trace files on the local file system. Those trace
6749 files have `my-first-snapshot` in their name.
6751 There is no difference between the format of a normal trace file and the
6752 format of a snapshot: viewers of LTTng traces also support LTTng
6755 By default, LTTng writes snapshot files to the path shown by
6756 `lttng snapshot list-output`. You can change this path or decide to send
6757 snapshots over the network using either:
6759 . An output path or URL that you specify when you create the
6761 . An snapshot output path or URL that you add using
6762 `lttng snapshot add-output`
6763 . An output path or URL that you provide directly to the
6764 `lttng snapshot record` command.
6766 Method 3 overrides method 2, which overrides method 1. When you
6767 specify a URL, a relay daemon must listen on a remote system (see
6768 <<sending-trace-data-over-the-network,Send trace data over the network>>).
6773 === Use the machine interface
6775 With any command of the man:lttng(1) command-line tool, you can set the
6776 opt:lttng(1):--mi option to `xml` (before the command name) to get an
6777 XML machine interface output, for example:
6781 $ lttng --mi=xml enable-event --kernel --syscall open
6784 A schema definition (XSD) is
6785 https://github.com/lttng/lttng-tools/blob/stable-2.9/src/common/mi-lttng-3.0.xsd[available]
6786 to ease the integration with external tools as much as possible.
6790 [[metadata-regenerate]]
6791 === Regenerate the metadata of an LTTng trace
6793 An LTTng trace, which is a http://diamon.org/ctf[CTF] trace, has both
6794 data stream files and a metadata file. This metadata file contains,
6795 amongst other things, information about the offset of the clock sources
6796 used to timestamp <<event,event records>> when tracing.
6798 If, once a <<tracing-session,tracing session>> is
6799 <<basic-tracing-session-control,started>>, a major
6800 https://en.wikipedia.org/wiki/Network_Time_Protocol[NTP] correction
6801 happens, the trace's clock offset also needs to be updated. You
6802 can use the `metadata` item of the man:lttng-regenerate(1) command
6805 The main use case of this command is to allow a system to boot with
6806 an incorrect wall time and trace it with LTTng before its wall time
6807 is corrected. Once the system is known to be in a state where its
6808 wall time is correct, it can run `lttng regenerate metadata`.
6810 To regenerate the metadata of an LTTng trace:
6812 * Use the `metadata` item of the man:lttng-regenerate(1) command:
6817 $ lttng regenerate metadata
6823 `lttng regenerate metadata` has the following limitations:
6825 * Tracing session <<creating-destroying-tracing-sessions,created>>
6827 * User space <<channel,channels>>, if any, are using
6828 <<channel-buffering-schemes,per-user buffering>>.
6833 [[regenerate-statedump]]
6834 === Regenerate the state dump of a tracing session
6836 The LTTng kernel and user space tracers generate state dump
6837 <<event,event records>> when the application starts or when you
6838 <<basic-tracing-session-control,start a tracing session>>. An analysis
6839 can use the state dump event records to set an initial state before it
6840 builds the rest of the state from the following event records.
6841 http://tracecompass.org/[Trace Compass] is a notable example of an
6842 application which uses the state dump of an LTTng trace.
6844 When you <<taking-a-snapshot,take a snapshot>>, it's possible that the
6845 state dump event records are not included in the snapshot because they
6846 were recorded to a sub-buffer that has been consumed or overwritten
6849 You can use the `lttng regenerate statedump` command to emit the state
6850 dump event records again.
6852 To regenerate the state dump of the current tracing session, provided
6853 create it in snapshot mode, before you take a snapshot:
6855 . Use the `statedump` item of the man:lttng-regenerate(1) command:
6860 $ lttng regenerate statedump
6864 . <<basic-tracing-session-control,Stop the tracing session>>:
6873 . <<taking-a-snapshot,Take a snapshot>>:
6878 $ lttng snapshot record --name=my-snapshot
6882 Depending on the event throughput, you should run steps 1 and 2
6883 as closely as possible.
6885 NOTE: To record the state dump events, you need to
6886 <<enabling-disabling-events,create event rules>> which enable them.
6887 LTTng-UST state dump tracepoints start with `lttng_ust_statedump:`.
6888 LTTng-modules state dump tracepoints start with `lttng_statedump_`.
6892 [[persistent-memory-file-systems]]
6893 === Record trace data on persistent memory file systems
6895 https://en.wikipedia.org/wiki/Non-volatile_random-access_memory[Non-volatile random-access memory]
6896 (NVRAM) is random-access memory that retains its information when power
6897 is turned off (non-volatile). Systems with such memory can store data
6898 structures in RAM and retrieve them after a reboot, without flushing
6899 to typical _storage_.
6901 Linux supports NVRAM file systems thanks to either
6902 http://pramfs.sourceforge.net/[PRAMFS] or
6903 https://www.kernel.org/doc/Documentation/filesystems/dax.txt[DAX]{nbsp}+{nbsp}http://lkml.iu.edu/hypermail/linux/kernel/1504.1/03463.html[pmem]
6904 (requires Linux 4.1+).
6906 This section does not describe how to operate such file systems;
6907 we assume that you have a working persistent memory file system.
6909 When you create a <<tracing-session,tracing session>>, you can specify
6910 the path of the shared memory holding the sub-buffers. If you specify a
6911 location on an NVRAM file system, then you can retrieve the latest
6912 recorded trace data when the system reboots after a crash.
6914 To record trace data on a persistent memory file system and retrieve the
6915 trace data after a system crash:
6917 . Create a tracing session with a sub-buffer shared memory path located
6918 on an NVRAM file system:
6923 $ lttng create my-session --shm-path=/path/to/shm
6927 . Configure the tracing session as usual with the man:lttng(1)
6928 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6930 . After a system crash, use the man:lttng-crash(1) command-line tool to
6931 view the trace data recorded on the NVRAM file system:
6936 $ lttng-crash /path/to/shm
6940 The binary layout of the ring buffer files is not exactly the same as
6941 the trace files layout. This is why you need to use man:lttng-crash(1)
6942 instead of your preferred trace viewer directly.
6944 To convert the ring buffer files to LTTng trace files:
6946 * Use the opt:lttng-crash(1):--extract option of man:lttng-crash(1):
6951 $ lttng-crash --extract=/path/to/trace /path/to/shm
6959 [[lttng-modules-ref]]
6960 === noch:{LTTng-modules}
6964 [[lttng-tracepoint-enum]]
6965 ==== `LTTNG_TRACEPOINT_ENUM()` usage
6967 Use the `LTTNG_TRACEPOINT_ENUM()` macro to define an enumeration:
6971 LTTNG_TRACEPOINT_ENUM(name, TP_ENUM_VALUES(entries))
6976 * `name` with the name of the enumeration (C identifier, unique
6977 amongst all the defined enumerations).
6978 * `entries` with a list of enumeration entries.
6980 The available enumeration entry macros are:
6982 +ctf_enum_value(__name__, __value__)+::
6983 Entry named +__name__+ mapped to the integral value +__value__+.
6985 +ctf_enum_range(__name__, __begin__, __end__)+::
6986 Entry named +__name__+ mapped to the range of integral values between
6987 +__begin__+ (included) and +__end__+ (included).
6989 +ctf_enum_auto(__name__)+::
6990 Entry named +__name__+ mapped to the integral value following the
6991 last mapping's value.
6993 The last value of a `ctf_enum_value()` entry is its +__value__+
6996 The last value of a `ctf_enum_range()` entry is its +__end__+ parameter.
6998 If `ctf_enum_auto()` is the first entry in the list, its integral
7001 Use the `ctf_enum()` <<lttng-modules-tp-fields,field definition macro>>
7002 to use a defined enumeration as a tracepoint field.
7004 .Define an enumeration with `LTTNG_TRACEPOINT_ENUM()`.
7008 LTTNG_TRACEPOINT_ENUM(
7011 ctf_enum_auto("AUTO: EXPECT 0")
7012 ctf_enum_value("VALUE: 23", 23)
7013 ctf_enum_value("VALUE: 27", 27)
7014 ctf_enum_auto("AUTO: EXPECT 28")
7015 ctf_enum_range("RANGE: 101 TO 303", 101, 303)
7016 ctf_enum_auto("AUTO: EXPECT 304")
7024 [[lttng-modules-tp-fields]]
7025 ==== Tracepoint fields macros (for `TP_FIELDS()`)
7027 [[tp-fast-assign]][[tp-struct-entry]]The available macros to define
7028 tracepoint fields, which must be listed within `TP_FIELDS()` in
7029 `LTTNG_TRACEPOINT_EVENT()`, are:
7031 [role="func-desc growable",cols="asciidoc,asciidoc"]
7032 .Available macros to define LTTng-modules tracepoint fields
7034 |Macro |Description and parameters
7037 +ctf_integer(__t__, __n__, __e__)+
7039 +ctf_integer_nowrite(__t__, __n__, __e__)+
7041 +ctf_user_integer(__t__, __n__, __e__)+
7043 +ctf_user_integer_nowrite(__t__, __n__, __e__)+
7045 Standard integer, displayed in base 10.
7048 Integer C type (`int`, `long`, `size_t`, ...).
7054 Argument expression.
7057 +ctf_integer_hex(__t__, __n__, __e__)+
7059 +ctf_user_integer_hex(__t__, __n__, __e__)+
7061 Standard integer, displayed in base 16.
7070 Argument expression.
7072 |+ctf_integer_oct(__t__, __n__, __e__)+
7074 Standard integer, displayed in base 8.
7083 Argument expression.
7086 +ctf_integer_network(__t__, __n__, __e__)+
7088 +ctf_user_integer_network(__t__, __n__, __e__)+
7090 Integer in network byte order (big-endian), displayed in base 10.
7099 Argument expression.
7102 +ctf_integer_network_hex(__t__, __n__, __e__)+
7104 +ctf_user_integer_network_hex(__t__, __n__, __e__)+
7106 Integer in network byte order, displayed in base 16.
7115 Argument expression.
7118 +ctf_enum(__N__, __t__, __n__, __e__)+
7120 +ctf_enum_nowrite(__N__, __t__, __n__, __e__)+
7122 +ctf_user_enum(__N__, __t__, __n__, __e__)+
7124 +ctf_user_enum_nowrite(__N__, __t__, __n__, __e__)+
7129 Name of a <<lttng-tracepoint-enum,previously defined enumeration>>.
7132 Integer C type (`int`, `long`, `size_t`, ...).
7138 Argument expression.
7141 +ctf_string(__n__, __e__)+
7143 +ctf_string_nowrite(__n__, __e__)+
7145 +ctf_user_string(__n__, __e__)+
7147 +ctf_user_string_nowrite(__n__, __e__)+
7149 Null-terminated string; undefined behavior if +__e__+ is `NULL`.
7155 Argument expression.
7158 +ctf_array(__t__, __n__, __e__, __s__)+
7160 +ctf_array_nowrite(__t__, __n__, __e__, __s__)+
7162 +ctf_user_array(__t__, __n__, __e__, __s__)+
7164 +ctf_user_array_nowrite(__t__, __n__, __e__, __s__)+
7166 Statically-sized array of integers.
7169 Array element C type.
7175 Argument expression.
7181 +ctf_array_bitfield(__t__, __n__, __e__, __s__)+
7183 +ctf_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7185 +ctf_user_array_bitfield(__t__, __n__, __e__, __s__)+
7187 +ctf_user_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7189 Statically-sized array of bits.
7191 The type of +__e__+ must be an integer type. +__s__+ is the number
7192 of elements of such type in +__e__+, not the number of bits.
7195 Array element C type.
7201 Argument expression.
7207 +ctf_array_text(__t__, __n__, __e__, __s__)+
7209 +ctf_array_text_nowrite(__t__, __n__, __e__, __s__)+
7211 +ctf_user_array_text(__t__, __n__, __e__, __s__)+
7213 +ctf_user_array_text_nowrite(__t__, __n__, __e__, __s__)+
7215 Statically-sized array, printed as text.
7217 The string does not need to be null-terminated.
7220 Array element C type (always `char`).
7226 Argument expression.
7232 +ctf_sequence(__t__, __n__, __e__, __T__, __E__)+
7234 +ctf_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7236 +ctf_user_sequence(__t__, __n__, __e__, __T__, __E__)+
7238 +ctf_user_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7240 Dynamically-sized array of integers.
7242 The type of +__E__+ must be unsigned.
7245 Array element C type.
7251 Argument expression.
7254 Length expression C type.
7260 +ctf_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7262 +ctf_user_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7264 Dynamically-sized array of integers, displayed in base 16.
7266 The type of +__E__+ must be unsigned.
7269 Array element C type.
7275 Argument expression.
7278 Length expression C type.
7283 |+ctf_sequence_network(__t__, __n__, __e__, __T__, __E__)+
7285 Dynamically-sized array of integers in network byte order (big-endian),
7286 displayed in base 10.
7288 The type of +__E__+ must be unsigned.
7291 Array element C type.
7297 Argument expression.
7300 Length expression C type.
7306 +ctf_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7308 +ctf_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7310 +ctf_user_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7312 +ctf_user_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7314 Dynamically-sized array of bits.
7316 The type of +__e__+ must be an integer type. +__s__+ is the number
7317 of elements of such type in +__e__+, not the number of bits.
7319 The type of +__E__+ must be unsigned.
7322 Array element C type.
7328 Argument expression.
7331 Length expression C type.
7337 +ctf_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7339 +ctf_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7341 +ctf_user_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7343 +ctf_user_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7345 Dynamically-sized array, displayed as text.
7347 The string does not need to be null-terminated.
7349 The type of +__E__+ must be unsigned.
7351 The behaviour is undefined if +__e__+ is `NULL`.
7354 Sequence element C type (always `char`).
7360 Argument expression.
7363 Length expression C type.
7369 Use the `_user` versions when the argument expression, `e`, is
7370 a user space address. In the cases of `ctf_user_integer*()` and
7371 `ctf_user_float*()`, `&e` must be a user space address, thus `e` must
7374 The `_nowrite` versions omit themselves from the session trace, but are
7375 otherwise identical. This means the `_nowrite` fields won't be written
7376 in the recorded trace. Their primary purpose is to make some
7377 of the event context available to the
7378 <<enabling-disabling-events,event filters>> without having to
7379 commit the data to sub-buffers.
7385 Terms related to LTTng and to tracing in general:
7388 The http://diamon.org/babeltrace[Babeltrace] project, which includes
7389 the cmd:babeltrace command, some libraries, and Python bindings.
7391 <<channel-buffering-schemes,buffering scheme>>::
7392 A layout of sub-buffers applied to a given channel.
7394 <<channel,channel>>::
7395 An entity which is responsible for a set of ring buffers.
7397 <<event,Event rules>> are always attached to a specific channel.
7400 A reference of time for a tracer.
7402 <<lttng-consumerd,consumer daemon>>::
7403 A process which is responsible for consuming the full sub-buffers
7404 and write them to a file system or send them over the network.
7406 <<channel-overwrite-mode-vs-discard-mode,discard mode>>:: The event loss
7407 mode in which the tracer _discards_ new event records when there's no
7408 sub-buffer space left to store them.
7411 The consequence of the execution of an instrumentation
7412 point, like a tracepoint that you manually place in some source code,
7413 or a Linux kernel KProbe.
7415 An event is said to _occur_ at a specific time. Different actions can
7416 be taken upon the occurrence of an event, like record the event's payload
7419 <<channel-overwrite-mode-vs-discard-mode,event loss mode>>::
7420 The mechanism by which event records of a given channel are lost
7421 (not recorded) when there is no sub-buffer space left to store them.
7423 [[def-event-name]]event name::
7424 The name of an event, which is also the name of the event record.
7425 This is also called the _instrumentation point name_.
7428 A record, in a trace, of the payload of an event which occured.
7430 <<event,event rule>>::
7431 Set of conditions which must be satisfied for one or more occuring
7432 events to be recorded.
7434 `java.util.logging`::
7436 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[core logging facilities].
7438 <<instrumenting,instrumentation>>::
7439 The use of LTTng probes to make a piece of software traceable.
7441 instrumentation point::
7442 A point in the execution path of a piece of software that, when
7443 reached by this execution, can emit an event.
7445 instrumentation point name::
7446 See _<<def-event-name,event name>>_.
7449 A http://logging.apache.org/log4j/1.2/[logging library] for Java
7450 developed by the Apache Software Foundation.
7453 Level of severity of a log statement or user space
7454 instrumentation point.
7457 The _Linux Trace Toolkit: next generation_ project.
7459 <<lttng-cli,cmd:lttng>>::
7460 A command-line tool provided by the LTTng-tools project which you
7461 can use to send and receive control messages to and from a
7465 The https://github.com/lttng/lttng-analyses[LTTng analyses] project,
7466 which is a set of analyzing programs that are used to obtain a
7467 higher level view of an LTTng trace.
7469 cmd:lttng-consumerd::
7470 The name of the consumer daemon program.
7473 A utility provided by the LTTng-tools project which can convert
7474 ring buffer files (usually
7475 <<persistent-memory-file-systems,saved on a persistent memory file system>>)
7478 LTTng Documentation::
7481 <<lttng-live,LTTng live>>::
7482 A communication protocol between the relay daemon and live viewers
7483 which makes it possible to see events "live", as they are received by
7486 <<lttng-modules,LTTng-modules>>::
7487 The https://github.com/lttng/lttng-modules[LTTng-modules] project,
7488 which contains the Linux kernel modules to make the Linux kernel
7489 instrumentation points available for LTTng tracing.
7492 The name of the relay daemon program.
7494 cmd:lttng-sessiond::
7495 The name of the session daemon program.
7498 The https://github.com/lttng/lttng-tools[LTTng-tools] project, which
7499 contains the various programs and libraries used to
7500 <<controlling-tracing,control tracing>>.
7502 <<lttng-ust,LTTng-UST>>::
7503 The https://github.com/lttng/lttng-ust[LTTng-UST] project, which
7504 contains libraries to instrument user applications.
7506 <<lttng-ust-agents,LTTng-UST Java agent>>::
7507 A Java package provided by the LTTng-UST project to allow the
7508 LTTng instrumentation of `java.util.logging` and Apache log4j 1.2
7511 <<lttng-ust-agents,LTTng-UST Python agent>>::
7512 A Python package provided by the LTTng-UST project to allow the
7513 LTTng instrumentation of Python logging statements.
7515 <<channel-overwrite-mode-vs-discard-mode,overwrite mode>>::
7516 The event loss mode in which new event records overwrite older
7517 event records when there's no sub-buffer space left to store them.
7519 <<channel-buffering-schemes,per-process buffering>>::
7520 A buffering scheme in which each instrumented process has its own
7521 sub-buffers for a given user space channel.
7523 <<channel-buffering-schemes,per-user buffering>>::
7524 A buffering scheme in which all the processes of a Unix user share the
7525 same sub-buffer for a given user space channel.
7527 <<lttng-relayd,relay daemon>>::
7528 A process which is responsible for receiving the trace data sent by
7529 a distant consumer daemon.
7532 A set of sub-buffers.
7534 <<lttng-sessiond,session daemon>>::
7535 A process which receives control commands from you and orchestrates
7536 the tracers and various LTTng daemons.
7538 <<taking-a-snapshot,snapshot>>::
7539 A copy of the current data of all the sub-buffers of a given tracing
7540 session, saved as trace files.
7543 One part of an LTTng ring buffer which contains event records.
7546 The time information attached to an event when it is emitted.
7549 A set of files which are the concatenations of one or more
7550 flushed sub-buffers.
7553 The action of recording the events emitted by an application
7554 or by a system, or to initiate such recording by controlling
7558 The http://tracecompass.org[Trace Compass] project and application.
7561 An instrumentation point using the tracepoint mechanism of the Linux
7562 kernel or of LTTng-UST.
7564 tracepoint definition::
7565 The definition of a single tracepoint.
7568 The name of a tracepoint.
7570 tracepoint provider::
7571 A set of functions providing tracepoints to an instrumented user
7574 Not to be confused with a _tracepoint provider package_: many tracepoint
7575 providers can exist within a tracepoint provider package.
7577 tracepoint provider package::
7578 One or more tracepoint providers compiled as an object file or as
7582 A software which records emitted events.
7584 <<domain,tracing domain>>::
7585 A namespace for event sources.
7587 <<tracing-group,tracing group>>::
7588 The Unix group in which a Unix user can be to be allowed to trace the
7591 <<tracing-session,tracing session>>::
7592 A stateful dialogue between you and a <<lttng-sessiond,session
7596 An application running in user space, as opposed to a Linux kernel
7597 module, for example.