1 The LTTng Documentation
2 =======================
3 Philippe Proulx <pproulx@efficios.com>
4 v2.10, 19 November 2018
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 _KeKriek_. From
78 http://brasseriedunham.com/[Brasserie Dunham], the _**KeKriek**_ is a
79 sour mashed golden wheat ale fermented with local sour cherries from
80 Tougas orchards. Fresh sweet cherry notes with some tartness, lively
81 carbonation with a dry finish.
83 New features and changes in LTTng{nbsp}{revision}:
85 * **Tracing control**:
86 ** You can put more than one wildcard special character (`*`), and not
87 only at the end, when you <<enabling-disabling-events,create an event
88 rule>>, in both the instrumentation point name and the literal
90 link:/man/1/lttng-enable-event/v{revision}/#doc-filter-syntax[filter expressions]:
95 # lttng enable-event --kernel 'x86_*_local_timer_*' \
96 --filter='name == "*a*b*c*d*e" && count >= 23'
103 $ lttng enable-event --userspace '*_my_org:*msg*'
107 ** New trigger and notification API for
108 <<liblttng-ctl-lttng,`liblttng-ctl`>>. This new subsystem allows you
109 to register triggers which emit a notification when a given
110 condition is satisfied. As of LTTng{nbsp}{revision}, only
111 <<channel,channel>> buffer usage conditions are available.
112 Documentation is available in the
113 https://github.com/lttng/lttng-tools/tree/stable-{revision}/include/lttng[`liblttng-ctl`
115 <<notif-trigger-api,Get notified when a channel's buffer usage is too
118 ** You can now embed the whole textual LTTng-tools man pages into the
119 executables at build time with the `--enable-embedded-help`
120 configuration option. Thanks to this option, you don't need the
121 http://www.methods.co.nz/asciidoc/[AsciiDoc] and
122 https://directory.fsf.org/wiki/Xmlto[xmlto] tools at build time, and
123 a manual pager at run time, to get access to this documentation.
125 * **User space tracing**:
126 ** New blocking mode: an LTTng-UST tracepoint can now block until
127 <<channel,sub-buffer>> space is available instead of discarding event
128 records in <<channel-overwrite-mode-vs-discard-mode,discard mode>>.
129 With this feature, you can be sure that no event records are
130 discarded during your application's execution at the expense of
133 For example, the following command lines create a user space tracing
134 channel with an infinite blocking timeout and run an application
135 instrumented with LTTng-UST which is explicitly allowed to block:
141 $ lttng enable-channel --userspace --blocking-timeout=inf blocking-channel
142 $ lttng enable-event --userspace --channel=blocking-channel --all
144 $ LTTNG_UST_ALLOW_BLOCKING=1 my-app
148 See the complete <<blocking-timeout-example,blocking timeout example>>.
150 * **Linux kernel tracing**:
151 ** Linux 4.10, 4.11, and 4.12 support.
152 ** The thread state dump events recorded by LTTng-modules now contain
153 the task's CPU identifier. This improves the precision of the
154 scheduler model for analyses.
155 ** Extended man:socketpair(2) system call tracing data.
161 What is LTTng? As its name suggests, the _Linux Trace Toolkit: next
162 generation_ is a modern toolkit for tracing Linux systems and
163 applications. So your first question might be:
170 As the history of software engineering progressed and led to what
171 we now take for granted--complex, numerous and
172 interdependent software applications running in parallel on
173 sophisticated operating systems like Linux--the authors of such
174 components, software developers, began feeling a natural
175 urge to have tools that would ensure the robustness and good performance
176 of their masterpieces.
178 One major achievement in this field is, inarguably, the
179 https://www.gnu.org/software/gdb/[GNU debugger (GDB)],
180 an essential tool for developers to find and fix bugs. But even the best
181 debugger won't help make your software run faster, and nowadays, faster
182 software means either more work done by the same hardware, or cheaper
183 hardware for the same work.
185 A _profiler_ is often the tool of choice to identify performance
186 bottlenecks. Profiling is suitable to identify _where_ performance is
187 lost in a given software. The profiler outputs a profile, a statistical
188 summary of observed events, which you may use to discover which
189 functions took the most time to execute. However, a profiler won't
190 report _why_ some identified functions are the bottleneck. Bottlenecks
191 might only occur when specific conditions are met, conditions that are
192 sometimes impossible to capture by a statistical profiler, or impossible
193 to reproduce with an application altered by the overhead of an
194 event-based profiler. For a thorough investigation of software
195 performance issues, a history of execution is essential, with the
196 recorded values of variables and context fields you choose, and
197 with as little influence as possible on the instrumented software. This
198 is where tracing comes in handy.
200 _Tracing_ is a technique used to understand what goes on in a running
201 software system. The software used for tracing is called a _tracer_,
202 which is conceptually similar to a tape recorder. When recording,
203 specific instrumentation points placed in the software source code
204 generate events that are saved on a giant tape: a _trace_ file. You
205 can trace user applications and the operating system at the same time,
206 opening the possibility of resolving a wide range of problems that would
207 otherwise be extremely challenging.
209 Tracing is often compared to _logging_. However, tracers and loggers are
210 two different tools, serving two different purposes. Tracers are
211 designed to record much lower-level events that occur much more
212 frequently than log messages, often in the range of thousands per
213 second, with very little execution overhead. Logging is more appropriate
214 for a very high-level analysis of less frequent events: user accesses,
215 exceptional conditions (errors and warnings, for example), database
216 transactions, instant messaging communications, and such. Simply put,
217 logging is one of the many use cases that can be satisfied with tracing.
219 The list of recorded events inside a trace file can be read manually
220 like a log file for the maximum level of detail, but it is generally
221 much more interesting to perform application-specific analyses to
222 produce reduced statistics and graphs that are useful to resolve a
223 given problem. Trace viewers and analyzers are specialized tools
226 In the end, this is what LTTng is: a powerful, open source set of
227 tools to trace the Linux kernel and user applications at the same time.
228 LTTng is composed of several components actively maintained and
229 developed by its link:/community/#where[community].
232 [[lttng-alternatives]]
233 === Alternatives to noch:{LTTng}
235 Excluding proprietary solutions, a few competing software tracers
238 * https://github.com/dtrace4linux/linux[dtrace4linux] is a port of
239 Sun Microsystems's DTrace to Linux. The cmd:dtrace tool interprets
240 user scripts and is responsible for loading code into the
241 Linux kernel for further execution and collecting the outputted data.
242 * https://en.wikipedia.org/wiki/Berkeley_Packet_Filter[eBPF] is a
243 subsystem in the Linux kernel in which a virtual machine can execute
244 programs passed from the user space to the kernel. You can attach
245 such programs to tracepoints and KProbes thanks to a system call, and
246 they can output data to the user space when executed thanks to
247 different mechanisms (pipe, VM register values, and eBPF maps, to name
249 * https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace]
250 is the de facto function tracer of the Linux kernel. Its user
251 interface is a set of special files in sysfs.
252 * https://perf.wiki.kernel.org/[perf] is
253 a performance analyzing tool for Linux which supports hardware
254 performance counters, tracepoints, as well as other counters and
255 types of probes. perf's controlling utility is the cmd:perf command
257 * http://linux.die.net/man/1/strace[strace]
258 is a command-line utility which records system calls made by a
259 user process, as well as signal deliveries and changes of process
260 state. strace makes use of https://en.wikipedia.org/wiki/Ptrace[ptrace]
261 to fulfill its function.
262 * http://www.sysdig.org/[sysdig], like SystemTap, uses scripts to
263 analyze Linux kernel events. You write scripts, or _chisels_ in
264 sysdig's jargon, in Lua and sysdig executes them while the system is
265 being traced or afterwards. sysdig's interface is the cmd:sysdig
266 command-line tool as well as the curses-based cmd:csysdig tool.
267 * https://sourceware.org/systemtap/[SystemTap] is a Linux kernel and
268 user space tracer which uses custom user scripts to produce plain text
269 traces. SystemTap converts the scripts to the C language, and then
270 compiles them as Linux kernel modules which are loaded to produce
271 trace data. SystemTap's primary user interface is the cmd:stap
274 The main distinctive features of LTTng is that it produces correlated
275 kernel and user space traces, as well as doing so with the lowest
276 overhead amongst other solutions. It produces trace files in the
277 http://diamon.org/ctf[CTF] format, a file format optimized
278 for the production and analyses of multi-gigabyte data.
280 LTTng is the result of more than 10 years of active open source
281 development by a community of passionate developers.
282 LTTng{nbsp}{revision} is currently available on major desktop and server
285 The main interface for tracing control is a single command-line tool
286 named cmd:lttng. The latter can create several tracing sessions, enable
287 and disable events on the fly, filter events efficiently with custom
288 user expressions, start and stop tracing, and much more. LTTng can
289 record the traces on the file system or send them over the network, and
290 keep them totally or partially. You can view the traces once tracing
291 becomes inactive or in real-time.
293 <<installing-lttng,Install LTTng now>> and
294 <<getting-started,start tracing>>!
300 **LTTng** is a set of software <<plumbing,components>> which interact to
301 <<instrumenting,instrument>> the Linux kernel and user applications, and
302 to <<controlling-tracing,control tracing>> (start and stop
303 tracing, enable and disable event rules, and the rest). Those
304 components are bundled into the following packages:
306 * **LTTng-tools**: Libraries and command-line interface to
308 * **LTTng-modules**: Linux kernel modules to instrument and
310 * **LTTng-UST**: Libraries and Java/Python packages to instrument and
311 trace user applications.
313 Most distributions mark the LTTng-modules and LTTng-UST packages as
314 optional when installing LTTng-tools (which is always required). In the
315 following sections, we always provide the steps to install all three,
318 * You only need to install LTTng-modules if you intend to trace the
320 * You only need to install LTTng-UST if you intend to trace user
324 .Availability of LTTng{nbsp}{revision} for major Linux distributions as of 12 November 2018.
326 |Distribution |Available in releases |Alternatives
328 |https://www.ubuntu.com/[Ubuntu]
329 |<<ubuntu,Ubuntu{nbsp}18.04 _Bionic Beaver_>>.
331 Ubuntu{nbsp}14.04 _Trusty Tahr_, Ubuntu{nbsp}16.04 _Xenial Xerus_,
332 and Ubuntu{nbsp}18.04 _Bionic Beaver_:
333 <<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>.
334 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
336 |https://getfedora.org/[Fedora]
337 |xref:fedora[Fedora{nbsp}27, Fedora{nbsp}28, and Fedora{nbsp}29].
338 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
340 |https://www.debian.org/[Debian]
341 |<<debian,Debian "buster" (testing)>>.
342 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
344 |https://www.archlinux.org/[Arch Linux]
345 |<<arch-linux,Current Arch Linux build>>.
346 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
348 |https://alpinelinux.org/[Alpine Linux]
349 |<<alpine-linux,Alpine Linux{nbsp}3.7 and Alpine Linux{nbsp}3.8>>.
350 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
352 |https://www.opensuse.org/[openSUSE]
353 |<<opensuse,openSUSE Leap{nbsp}15.0>>.
354 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
356 |https://www.redhat.com/[RHEL] and https://www.suse.com/[SLES]
357 |See http://packages.efficios.com/[EfficiOS Enterprise Packages].
360 |https://buildroot.org/[Buildroot]
361 |xref:buildroot[Buildroot{nbsp}2018.02, Buildroot{nbsp}2018.05,
362 Buildroot{nbsp}2018.08, and Buildroot{nbsp}2018.11].
363 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
365 |http://www.openembedded.org/wiki/Main_Page[OpenEmbedded] and
366 https://www.yoctoproject.org/[Yocto]
368 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
373 === [[ubuntu-official-repositories]]Ubuntu
375 LTTng{nbsp}{revision} is available on Ubuntu{nbsp}18.04 _Bionic Beaver_.
376 For previous supported releases of Ubuntu,
377 <<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>.
379 To install LTTng{nbsp}{revision} on Ubuntu{nbsp}18.04 _Bionic Beaver_:
381 . Install the main LTTng{nbsp}{revision} packages:
386 # apt-get install lttng-tools
387 # apt-get install lttng-modules-dkms
388 # apt-get install liblttng-ust-dev
392 . **If you need to instrument and trace
393 <<java-application,Java applications>>**, install the LTTng-UST
399 # apt-get install liblttng-ust-agent-java
403 . **If you need to instrument and trace
404 <<python-application,Python{nbsp}3 applications>>**, install the
405 LTTng-UST Python agent:
410 # apt-get install python3-lttngust
416 ==== noch:{LTTng} Stable {revision} PPA
418 The https://launchpad.net/~lttng/+archive/ubuntu/stable-{revision}[LTTng
419 Stable{nbsp}{revision} PPA] offers the latest stable
420 LTTng{nbsp}{revision} packages for:
422 * Ubuntu{nbsp}14.04 _Trusty Tahr_
423 * Ubuntu{nbsp}16.04 _Xenial Xerus_
424 * Ubuntu{nbsp}18.04 _Bionic Beaver_
426 To install LTTng{nbsp}{revision} from the LTTng Stable{nbsp}{revision} PPA:
428 . Add the LTTng Stable{nbsp}{revision} PPA repository and update the
434 # apt-add-repository ppa:lttng/stable-2.10
439 . Install the main LTTng{nbsp}{revision} packages:
444 # apt-get install lttng-tools
445 # apt-get install lttng-modules-dkms
446 # apt-get install liblttng-ust-dev
450 . **If you need to instrument and trace
451 <<java-application,Java applications>>**, install the LTTng-UST
457 # apt-get install liblttng-ust-agent-java
461 . **If you need to instrument and trace
462 <<python-application,Python{nbsp}3 applications>>**, install the
463 LTTng-UST Python agent:
468 # apt-get install python3-lttngust
476 To install LTTng{nbsp}{revision} on Fedora{nbsp}27, Fedora{nbsp}28,
479 . Install the LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision}
485 # yum install lttng-tools
486 # yum install lttng-ust
490 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
496 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
497 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
498 cd lttng-modules-2.10.* &&
500 sudo make modules_install &&
506 .Java and Python application instrumentation and tracing
508 If you need to instrument and trace <<java-application,Java
509 applications>> on Fedora, you need to build and install
510 LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass
511 the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or
512 `--enable-java-agent-all` options to the `configure` script, depending
513 on which Java logging framework you use.
515 If you need to instrument and trace <<python-application,Python
516 applications>> on Fedora, you need to build and install
517 LTTng-UST{nbsp}{revision} from source and pass the
518 `--enable-python-agent` option to the `configure` script.
525 To install LTTng{nbsp}{revision} on Debian "buster" (testing):
527 . Install the main LTTng{nbsp}{revision} packages:
532 # apt-get install lttng-modules-dkms
533 # apt-get install liblttng-ust-dev
534 # apt-get install lttng-tools
538 . **If you need to instrument and trace <<java-application,Java
539 applications>>**, install the LTTng-UST Java agent:
544 # apt-get install liblttng-ust-agent-java
548 . **If you need to instrument and trace <<python-application,Python
549 applications>>**, install the LTTng-UST Python agent:
554 # apt-get install python3-lttngust
562 LTTng-UST{nbsp}{revision} is available in Arch Linux's _Community_
563 repository, while LTTng-tools{nbsp}{revision} and
564 LTTng-modules{nbsp}{revision} are available in the
565 https://aur.archlinux.org/[AUR].
567 To install LTTng{nbsp}{revision} on Arch Linux, using
568 https://github.com/rmarquis/pacaur[pacaur] for the AUR packages:
570 . Install the main LTTng{nbsp}{revision} packages:
575 # pacman -Sy lttng-ust
576 $ pikaur -Sy lttng-tools
577 $ pikaur -Sy lttng-modules
581 . **If you need to instrument and trace <<python-application,Python
582 applications>>**, install the LTTng-UST Python agent:
587 # pacman -Sy python-lttngust
588 # pacman -Sy python2-lttngust
596 To install LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision} on
597 Alpine Linux{nbsp}3.7 or Alpine Linux{nbsp}3.8:
599 . Add the LTTng packages:
604 # apk add lttng-tools
605 # apk add lttng-ust-dev
609 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
615 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
616 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
617 cd lttng-modules-2.10.* &&
619 sudo make modules_install &&
628 To install LTTng{nbsp}{revision} on openSUSE Leap{nbsp}15.0:
630 * Install the main LTTng{nbsp}{revision} packages:
635 sudo zypper install lttng-tools
636 sudo zypper install lttng-modules
637 sudo zypper install lttng-ust-devel
642 .Java and Python application instrumentation and tracing
644 If you need to instrument and trace <<java-application,Java
645 applications>> on openSUSE, you need to build and install
646 LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass
647 the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or
648 `--enable-java-agent-all` options to the `configure` script, depending
649 on which Java logging framework you use.
651 If you need to instrument and trace <<python-application,Python
652 applications>> on openSUSE, you need to build and install
653 LTTng-UST{nbsp}{revision} from source and pass the
654 `--enable-python-agent` option to the `configure` script.
658 [[enterprise-distributions]]
659 === RHEL, SUSE, and other enterprise distributions
661 To install LTTng on enterprise Linux distributions, such as Red Hat
662 Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SUSE), please
663 see http://packages.efficios.com/[EfficiOS Enterprise Packages].
669 To install LTTng{nbsp}{revision} on Buildroot{nbsp}2018.02,
670 Buildroot{nbsp}2018.05, Buildroot{nbsp}2018.08, or
671 Buildroot{nbsp}2018.11:
673 . Launch the Buildroot configuration tool:
682 . In **Kernel**, check **Linux kernel**.
683 . In **Toolchain**, check **Enable WCHAR support**.
684 . In **Target packages**{nbsp}→ **Debugging, profiling and benchmark**,
685 check **lttng-modules** and **lttng-tools**.
686 . In **Target packages**{nbsp}→ **Libraries**{nbsp}→
687 **Other**, check **lttng-libust**.
690 [[building-from-source]]
691 === Build from source
693 To build and install LTTng{nbsp}{revision} from source:
695 . Using your distribution's package manager, or from source, install
696 the following dependencies of LTTng-tools and LTTng-UST:
699 * https://sourceforge.net/projects/libuuid/[libuuid]
700 * http://directory.fsf.org/wiki/Popt[popt]
701 * http://liburcu.org/[Userspace RCU]
702 * http://www.xmlsoft.org/[libxml2]
705 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
711 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
712 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
713 cd lttng-modules-2.10.* &&
715 sudo make modules_install &&
720 . Download, build, and install the latest LTTng-UST{nbsp}{revision}:
726 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.10.tar.bz2 &&
727 tar -xf lttng-ust-latest-2.10.tar.bz2 &&
728 cd lttng-ust-2.10.* &&
738 .Java and Python application tracing
740 If you need to instrument and trace <<java-application,Java
741 applications>>, pass the `--enable-java-agent-jul`,
742 `--enable-java-agent-log4j`, or `--enable-java-agent-all` options to the
743 `configure` script, depending on which Java logging framework you use.
745 If you need to instrument and trace <<python-application,Python
746 applications>>, pass the `--enable-python-agent` option to the
747 `configure` script. You can set the `PYTHON` environment variable to the
748 path to the Python interpreter for which to install the LTTng-UST Python
756 By default, LTTng-UST libraries are installed to
757 dir:{/usr/local/lib}, which is the de facto directory in which to
758 keep self-compiled and third-party libraries.
760 When <<building-tracepoint-providers-and-user-application,linking an
761 instrumented user application with `liblttng-ust`>>:
763 * Append `/usr/local/lib` to the env:LD_LIBRARY_PATH environment
765 * Pass the `-L/usr/local/lib` and `-Wl,-rpath,/usr/local/lib` options to
766 man:gcc(1), man:g++(1), or man:clang(1).
770 . Download, build, and install the latest LTTng-tools{nbsp}{revision}:
776 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.10.tar.bz2 &&
777 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
778 cd lttng-tools-2.10.* &&
786 TIP: The https://github.com/eepp/vlttng[vlttng tool] can do all the
787 previous steps automatically for a given version of LTTng and confine
788 the installed files in a specific directory. This can be useful to test
789 LTTng without installing it on your system.
795 This is a short guide to get started quickly with LTTng kernel and user
798 Before you follow this guide, make sure to <<installing-lttng,install>>
801 This tutorial walks you through the steps to:
803 . <<tracing-the-linux-kernel,Trace the Linux kernel>>.
804 . <<tracing-your-own-user-application,Trace a user application>> written
806 . <<viewing-and-analyzing-your-traces,View and analyze the
810 [[tracing-the-linux-kernel]]
811 === Trace the Linux kernel
813 The following command lines start with the `#` prompt because you need
814 root privileges to trace the Linux kernel. You can also trace the kernel
815 as a regular user if your Unix user is a member of the
816 <<tracing-group,tracing group>>.
818 . Create a <<tracing-session,tracing session>> which writes its traces
819 to dir:{/tmp/my-kernel-trace}:
824 # lttng create my-kernel-session --output=/tmp/my-kernel-trace
828 . List the available kernel tracepoints and system calls:
833 # lttng list --kernel
834 # lttng list --kernel --syscall
838 . Create <<event,event rules>> which match the desired instrumentation
839 point names, for example the `sched_switch` and `sched_process_fork`
840 tracepoints, and the man:open(2) and man:close(2) system calls:
845 # lttng enable-event --kernel sched_switch,sched_process_fork
846 # lttng enable-event --kernel --syscall open,close
850 You can also create an event rule which matches _all_ the Linux kernel
851 tracepoints (this will generate a lot of data when tracing):
856 # lttng enable-event --kernel --all
860 . <<basic-tracing-session-control,Start tracing>>:
869 . Do some operation on your system for a few seconds. For example,
870 load a website, or list the files of a directory.
871 . <<creating-destroying-tracing-sessions,Destroy>> the current
881 The man:lttng-destroy(1) command does not destroy the trace data; it
882 only destroys the state of the tracing session.
884 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
885 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
886 session>>). You need to stop tracing to make LTTng flush the remaining
887 trace data and make the trace readable.
889 . For the sake of this example, make the recorded trace accessible to
895 # chown -R $(whoami) /tmp/my-kernel-trace
899 See <<viewing-and-analyzing-your-traces,View and analyze the
900 recorded events>> to view the recorded events.
903 [[tracing-your-own-user-application]]
904 === Trace a user application
906 This section steps you through a simple example to trace a
907 _Hello world_ program written in C.
909 To create the traceable user application:
911 . Create the tracepoint provider header file, which defines the
912 tracepoints and the events they can generate:
918 #undef TRACEPOINT_PROVIDER
919 #define TRACEPOINT_PROVIDER hello_world
921 #undef TRACEPOINT_INCLUDE
922 #define TRACEPOINT_INCLUDE "./hello-tp.h"
924 #if !defined(_HELLO_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
927 #include <lttng/tracepoint.h>
937 ctf_string(my_string_field, my_string_arg)
938 ctf_integer(int, my_integer_field, my_integer_arg)
942 #endif /* _HELLO_TP_H */
944 #include <lttng/tracepoint-event.h>
948 . Create the tracepoint provider package source file:
954 #define TRACEPOINT_CREATE_PROBES
955 #define TRACEPOINT_DEFINE
957 #include "hello-tp.h"
961 . Build the tracepoint provider package:
966 $ gcc -c -I. hello-tp.c
970 . Create the _Hello World_ application source file:
977 #include "hello-tp.h"
979 int main(int argc, char *argv[])
983 puts("Hello, World!\nPress Enter to continue...");
986 * The following getchar() call is only placed here for the purpose
987 * of this demonstration, to pause the application in order for
988 * you to have time to list its tracepoints. It is not
994 * A tracepoint() call.
996 * Arguments, as defined in hello-tp.h:
998 * 1. Tracepoint provider name (required)
999 * 2. Tracepoint name (required)
1000 * 3. my_integer_arg (first user-defined argument)
1001 * 4. my_string_arg (second user-defined argument)
1003 * Notice the tracepoint provider and tracepoint names are
1004 * NOT strings: they are in fact parts of variables that the
1005 * macros in hello-tp.h create.
1007 tracepoint(hello_world, my_first_tracepoint, 23, "hi there!");
1009 for (x = 0; x < argc; ++x) {
1010 tracepoint(hello_world, my_first_tracepoint, x, argv[x]);
1013 puts("Quitting now!");
1014 tracepoint(hello_world, my_first_tracepoint, x * x, "x^2");
1021 . Build the application:
1030 . Link the application with the tracepoint provider package,
1031 `liblttng-ust`, and `libdl`:
1036 $ gcc -o hello hello.o hello-tp.o -llttng-ust -ldl
1040 Here's the whole build process:
1043 .User space tracing tutorial's build steps.
1044 image::ust-flow.png[]
1046 To trace the user application:
1048 . Run the application with a few arguments:
1053 $ ./hello world and beyond
1062 Press Enter to continue...
1066 . Start an LTTng <<lttng-sessiond,session daemon>>:
1071 $ lttng-sessiond --daemonize
1075 Note that a session daemon might already be running, for example as
1076 a service that the distribution's service manager started.
1078 . List the available user space tracepoints:
1083 $ lttng list --userspace
1087 You see the `hello_world:my_first_tracepoint` tracepoint listed
1088 under the `./hello` process.
1090 . Create a <<tracing-session,tracing session>>:
1095 $ lttng create my-user-space-session
1099 . Create an <<event,event rule>> which matches the
1100 `hello_world:my_first_tracepoint` event name:
1105 $ lttng enable-event --userspace hello_world:my_first_tracepoint
1109 . <<basic-tracing-session-control,Start tracing>>:
1118 . Go back to the running `hello` application and press Enter. The
1119 program executes all `tracepoint()` instrumentation points and exits.
1120 . <<creating-destroying-tracing-sessions,Destroy>> the current
1130 The man:lttng-destroy(1) command does not destroy the trace data; it
1131 only destroys the state of the tracing session.
1133 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
1134 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
1135 session>>). You need to stop tracing to make LTTng flush the remaining
1136 trace data and make the trace readable.
1138 By default, LTTng saves the traces in
1139 +$LTTNG_HOME/lttng-traces/__name__-__date__-__time__+,
1140 where +__name__+ is the tracing session name. The
1141 env:LTTNG_HOME environment variable defaults to `$HOME` if not set.
1143 See <<viewing-and-analyzing-your-traces,View and analyze the
1144 recorded events>> to view the recorded events.
1147 [[viewing-and-analyzing-your-traces]]
1148 === View and analyze the recorded events
1150 Once you have completed the <<tracing-the-linux-kernel,Trace the Linux
1151 kernel>> and <<tracing-your-own-user-application,Trace a user
1152 application>> tutorials, you can inspect the recorded events.
1154 Many tools are available to read LTTng traces:
1156 * **cmd:babeltrace** is a command-line utility which converts trace
1157 formats; it supports the format that LTTng produces, CTF, as well as a
1158 basic text output which can be ++grep++ed. The cmd:babeltrace command
1159 is part of the http://diamon.org/babeltrace[Babeltrace] project.
1160 * Babeltrace also includes
1161 **https://www.python.org/[Python] bindings** so
1162 that you can easily open and read an LTTng trace with your own script,
1163 benefiting from the power of Python.
1164 * http://tracecompass.org/[**Trace Compass**]
1165 is a graphical user interface for viewing and analyzing any type of
1166 logs or traces, including LTTng's.
1167 * https://github.com/lttng/lttng-analyses[**LTTng analyses**] is a
1168 project which includes many high-level analyses of LTTng kernel
1169 traces, like scheduling statistics, interrupt frequency distribution,
1170 top CPU usage, and more.
1172 NOTE: This section assumes that the traces recorded during the previous
1173 tutorials were saved to their default location, in the
1174 dir:{$LTTNG_HOME/lttng-traces} directory. The env:LTTNG_HOME
1175 environment variable defaults to `$HOME` if not set.
1178 [[viewing-and-analyzing-your-traces-bt]]
1179 ==== Use the cmd:babeltrace command-line tool
1181 The simplest way to list all the recorded events of a trace is to pass
1182 its path to cmd:babeltrace with no options:
1186 $ babeltrace ~/lttng-traces/my-user-space-session*
1189 cmd:babeltrace finds all traces recursively within the given path and
1190 prints all their events, merging them in chronological order.
1192 You can pipe the output of cmd:babeltrace into a tool like man:grep(1) for
1197 $ babeltrace /tmp/my-kernel-trace | grep _switch
1200 You can pipe the output of cmd:babeltrace into a tool like man:wc(1) to
1201 count the recorded events:
1205 $ babeltrace /tmp/my-kernel-trace | grep _open | wc --lines
1209 [[viewing-and-analyzing-your-traces-bt-python]]
1210 ==== Use the Babeltrace Python bindings
1212 The <<viewing-and-analyzing-your-traces-bt,text output of cmd:babeltrace>>
1213 is useful to isolate events by simple matching using man:grep(1) and
1214 similar utilities. However, more elaborate filters, such as keeping only
1215 event records with a field value falling within a specific range, are
1216 not trivial to write using a shell. Moreover, reductions and even the
1217 most basic computations involving multiple event records are virtually
1218 impossible to implement.
1220 Fortunately, Babeltrace ships with Python 3 bindings which makes it easy
1221 to read the event records of an LTTng trace sequentially and compute the
1222 desired information.
1224 The following script accepts an LTTng Linux kernel trace path as its
1225 first argument and prints the short names of the top 5 running processes
1226 on CPU 0 during the whole trace:
1231 from collections import Counter
1237 if len(sys.argv) != 2:
1238 msg = 'Usage: python3 {} TRACEPATH'.format(sys.argv[0])
1239 print(msg, file=sys.stderr)
1242 # A trace collection contains one or more traces
1243 col = babeltrace.TraceCollection()
1245 # Add the trace provided by the user (LTTng traces always have
1247 if col.add_trace(sys.argv[1], 'ctf') is None:
1248 raise RuntimeError('Cannot add trace')
1250 # This counter dict contains execution times:
1252 # task command name -> total execution time (ns)
1253 exec_times = Counter()
1255 # This contains the last `sched_switch` timestamp
1259 for event in col.events:
1260 # Keep only `sched_switch` events
1261 if event.name != 'sched_switch':
1264 # Keep only events which happened on CPU 0
1265 if event['cpu_id'] != 0:
1269 cur_ts = event.timestamp
1275 # Previous task command (short) name
1276 prev_comm = event['prev_comm']
1278 # Initialize entry in our dict if not yet done
1279 if prev_comm not in exec_times:
1280 exec_times[prev_comm] = 0
1282 # Compute previous command execution time
1283 diff = cur_ts - last_ts
1285 # Update execution time of this command
1286 exec_times[prev_comm] += diff
1288 # Update last timestamp
1292 for name, ns in exec_times.most_common(5):
1294 print('{:20}{} s'.format(name, s))
1299 if __name__ == '__main__':
1300 sys.exit(0 if top5proc() else 1)
1307 $ python3 top5proc.py /tmp/my-kernel-trace/kernel
1313 swapper/0 48.607245889 s
1314 chromium 7.192738188 s
1315 pavucontrol 0.709894415 s
1316 Compositor 0.660867933 s
1317 Xorg.bin 0.616753786 s
1320 Note that `swapper/0` is the "idle" process of CPU 0 on Linux; since we
1321 weren't using the CPU that much when tracing, its first position in the
1326 == [[understanding-lttng]]Core concepts
1328 From a user's perspective, the LTTng system is built on a few concepts,
1329 or objects, on which the <<lttng-cli,cmd:lttng command-line tool>>
1330 operates by sending commands to the <<lttng-sessiond,session daemon>>.
1331 Understanding how those objects relate to eachother is key in mastering
1334 The core concepts are:
1336 * <<tracing-session,Tracing session>>
1337 * <<domain,Tracing domain>>
1338 * <<channel,Channel and ring buffer>>
1339 * <<"event","Instrumentation point, event rule, event, and event record">>
1345 A _tracing session_ is a stateful dialogue between you and
1346 a <<lttng-sessiond,session daemon>>. You can
1347 <<creating-destroying-tracing-sessions,create a new tracing
1348 session>> with the `lttng create` command.
1350 Anything that you do when you control LTTng tracers happens within a
1351 tracing session. In particular, a tracing session:
1354 * Has its own set of trace files.
1355 * Has its own state of activity (started or stopped).
1356 * Has its own <<tracing-session-mode,mode>> (local, network streaming,
1358 * Has its own <<channel,channels>> which have their own
1359 <<event,event rules>>.
1362 .A _tracing session_ contains <<channel,channels>> that are members of <<domain,tracing domains>> and contain <<event,event rules>>.
1363 image::concepts.png[]
1365 Those attributes and objects are completely isolated between different
1368 A tracing session is analogous to a cash machine session:
1369 the operations you do on the banking system through the cash machine do
1370 not alter the data of other users of the same system. In the case of
1371 the cash machine, a session lasts as long as your bank card is inside.
1372 In the case of LTTng, a tracing session lasts from the `lttng create`
1373 command to the `lttng destroy` command.
1376 .Each Unix user has its own set of tracing sessions.
1377 image::many-sessions.png[]
1380 [[tracing-session-mode]]
1381 ==== Tracing session mode
1383 LTTng can send the generated trace data to different locations. The
1384 _tracing session mode_ dictates where to send it. The following modes
1385 are available in LTTng{nbsp}{revision}:
1388 LTTng writes the traces to the file system of the machine being traced
1391 Network streaming mode::
1392 LTTng sends the traces over the network to a
1393 <<lttng-relayd,relay daemon>> running on a remote system.
1396 LTTng does not write the traces by default. Instead, you can request
1397 LTTng to <<taking-a-snapshot,take a snapshot>>, that is, a copy of the
1398 current tracing buffers, and to write it to the target's file system
1399 or to send it over the network to a <<lttng-relayd,relay daemon>>
1400 running on a remote system.
1403 This mode is similar to the network streaming mode, but a live
1404 trace viewer can connect to the distant relay daemon to
1405 <<lttng-live,view event records as LTTng generates them>> by
1412 A _tracing domain_ is a namespace for event sources. A tracing domain
1413 has its own properties and features.
1415 There are currently five available tracing domains:
1419 * `java.util.logging` (JUL)
1423 You must specify a tracing domain when using some commands to avoid
1424 ambiguity. For example, since all the domains support named tracepoints
1425 as event sources (instrumentation points that you manually insert in the
1426 source code), you need to specify a tracing domain when
1427 <<enabling-disabling-events,creating an event rule>> because all the
1428 tracing domains could have tracepoints with the same names.
1430 Some features are reserved to specific tracing domains. Dynamic function
1431 entry and return instrumentation points, for example, are currently only
1432 supported in the Linux kernel tracing domain, but support for other
1433 tracing domains could be added in the future.
1435 You can create <<channel,channels>> in the Linux kernel and user space
1436 tracing domains. The other tracing domains have a single default
1441 === Channel and ring buffer
1443 A _channel_ is an object which is responsible for a set of ring buffers.
1444 Each ring buffer is divided into multiple sub-buffers. When an LTTng
1445 tracer emits an event, it can record it to one or more
1446 sub-buffers. The attributes of a channel determine what to do when
1447 there's no space left for a new event record because all sub-buffers
1448 are full, where to send a full sub-buffer, and other behaviours.
1450 A channel is always associated to a <<domain,tracing domain>>. The
1451 `java.util.logging` (JUL), log4j, and Python tracing domains each have
1452 a default channel which you cannot configure.
1454 A channel also owns <<event,event rules>>. When an LTTng tracer emits
1455 an event, it records it to the sub-buffers of all
1456 the enabled channels with a satisfied event rule, as long as those
1457 channels are part of active <<tracing-session,tracing sessions>>.
1460 [[channel-buffering-schemes]]
1461 ==== Per-user vs. per-process buffering schemes
1463 A channel has at least one ring buffer _per CPU_. LTTng always
1464 records an event to the ring buffer associated to the CPU on which it
1467 Two _buffering schemes_ are available when you
1468 <<enabling-disabling-channels,create a channel>> in the
1469 user space <<domain,tracing domain>>:
1471 Per-user buffering::
1472 Allocate one set of ring buffers--one per CPU--shared by all the
1473 instrumented processes of each Unix user.
1477 .Per-user buffering scheme.
1478 image::per-user-buffering.png[]
1481 Per-process buffering::
1482 Allocate one set of ring buffers--one per CPU--for each
1483 instrumented process.
1487 .Per-process buffering scheme.
1488 image::per-process-buffering.png[]
1491 The per-process buffering scheme tends to consume more memory than the
1492 per-user option because systems generally have more instrumented
1493 processes than Unix users running instrumented processes. However, the
1494 per-process buffering scheme ensures that one process having a high
1495 event throughput won't fill all the shared sub-buffers of the same
1498 The Linux kernel tracing domain has only one available buffering scheme
1499 which is to allocate a single set of ring buffers for the whole system.
1500 This scheme is similar to the per-user option, but with a single, global
1501 user "running" the kernel.
1504 [[channel-overwrite-mode-vs-discard-mode]]
1505 ==== Overwrite vs. discard event loss modes
1507 When an event occurs, LTTng records it to a specific sub-buffer (yellow
1508 arc in the following animation) of a specific channel's ring buffer.
1509 When there's no space left in a sub-buffer, the tracer marks it as
1510 consumable (red) and another, empty sub-buffer starts receiving the
1511 following event records. A <<lttng-consumerd,consumer daemon>>
1512 eventually consumes the marked sub-buffer (returns to white).
1515 [role="docsvg-channel-subbuf-anim"]
1520 In an ideal world, sub-buffers are consumed faster than they are filled,
1521 as is the case in the previous animation. In the real world,
1522 however, all sub-buffers can be full at some point, leaving no space to
1523 record the following events.
1525 By default, LTTng-modules and LTTng-UST are _non-blocking_ tracers: when
1526 no empty sub-buffer is available, it is acceptable to lose event records
1527 when the alternative would be to cause substantial delays in the
1528 instrumented application's execution. LTTng privileges performance over
1529 integrity; it aims at perturbing the traced system as little as possible
1530 in order to make tracing of subtle race conditions and rare interrupt
1533 Starting from LTTng{nbsp}2.10, the LTTng user space tracer, LTTng-UST,
1534 supports a _blocking mode_. See the <<blocking-timeout-example,blocking
1535 timeout example>> to learn how to use the blocking mode.
1537 When it comes to losing event records because no empty sub-buffer is
1538 available, or because the <<opt-blocking-timeout,blocking timeout>> is
1539 reached, the channel's _event loss mode_ determines what to do. The
1540 available event loss modes are:
1543 Drop the newest event records until a the tracer releases a
1546 This is the only available mode when you specify a
1547 <<opt-blocking-timeout,blocking timeout>>.
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>> (cmd:lttng-consumerd).
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_, cmd:lttng-consumerd, 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.10.tar.bz2 &&
3997 tar -xf lttng-ust-latest-2.10.tar.bz2 &&
3998 cd lttng-ust-2.10.* &&
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.10.tar.bz2 &&
4032 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
4033 cd lttng-tools-2.10.* &&
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.10.tar.bz2 &&
4056 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
4057 cd lttng-tools-2.10.* &&
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.10.tar.bz2 &&
5299 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
5300 cd lttng-modules-2.10.*
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:
5774 The man:lttng-destroy(1) command also runs the man:lttng-stop(1)
5775 command implicitly (see <<basic-tracing-session-control,Start and stop a
5776 tracing session>>). You need to stop tracing to make LTTng flush the
5777 remaining trace data and make the trace readable.
5780 [[list-instrumentation-points]]
5781 === List the available instrumentation points
5783 The <<lttng-sessiond,session daemon>> can query the running instrumented
5784 user applications and the Linux kernel to get a list of available
5785 instrumentation points. For the Linux kernel <<domain,tracing domain>>,
5786 they are tracepoints and system calls. For the user space tracing
5787 domain, they are tracepoints. For the other tracing domains, they are
5790 To list the available instrumentation points:
5792 * Use the man:lttng-list(1) command with the requested tracing domain's
5796 * opt:lttng-list(1):--kernel: Linux kernel tracepoints (your Unix user
5797 must be a root user, or it must be a member of the
5798 <<tracing-group,tracing group>>).
5799 * opt:lttng-list(1):--kernel with opt:lttng-list(1):--syscall: Linux
5800 kernel system calls (your Unix user must be a root user, or it must be
5801 a member of the tracing group).
5802 * opt:lttng-list(1):--userspace: user space tracepoints.
5803 * opt:lttng-list(1):--jul: `java.util.logging` loggers.
5804 * opt:lttng-list(1):--log4j: Apache log4j loggers.
5805 * opt:lttng-list(1):--python: Python loggers.
5808 .List the available user space tracepoints.
5812 $ lttng list --userspace
5816 .List the available Linux kernel system call tracepoints.
5820 $ lttng list --kernel --syscall
5825 [[enabling-disabling-events]]
5826 === Create and enable an event rule
5828 Once you <<creating-destroying-tracing-sessions,create a tracing
5829 session>>, you can create <<event,event rules>> with the
5830 man:lttng-enable-event(1) command.
5832 You specify each condition with a command-line option. The available
5833 condition options are shown in the following table.
5835 [role="growable",cols="asciidoc,asciidoc,default"]
5836 .Condition command-line options for the man:lttng-enable-event(1) command.
5838 |Option |Description |Applicable tracing domains
5844 . +--probe=__ADDR__+
5845 . +--function=__ADDR__+
5848 Instead of using the default _tracepoint_ instrumentation type, use:
5850 . A Linux system call.
5851 . A Linux https://lwn.net/Articles/132196/[KProbe] (symbol or address).
5852 . The entry and return points of a Linux function (symbol or address).
5856 |First positional argument.
5859 Tracepoint or system call name. In the case of a Linux KProbe or
5860 function, this is a custom name given to the event rule. With the
5861 JUL, log4j, and Python domains, this is a logger name.
5863 With a tracepoint, logger, or system call name, you can use the special
5864 `*` globbing character to match anything (for example, `sched_*`,
5872 . +--loglevel=__LEVEL__+
5873 . +--loglevel-only=__LEVEL__+
5876 . Match only tracepoints or log statements with a logging level at
5877 least as severe as +__LEVEL__+.
5878 . Match only tracepoints or log statements with a logging level
5879 equal to +__LEVEL__+.
5881 See man:lttng-enable-event(1) for the list of available logging level
5884 |User space, JUL, log4j, and Python.
5886 |+--exclude=__EXCLUSIONS__+
5889 When you use a `*` character at the end of the tracepoint or logger
5890 name (first positional argument), exclude the specific names in the
5891 comma-delimited list +__EXCLUSIONS__+.
5894 User space, JUL, log4j, and Python.
5896 |+--filter=__EXPR__+
5899 Match only events which satisfy the expression +__EXPR__+.
5901 See man:lttng-enable-event(1) to learn more about the syntax of a
5908 You attach an event rule to a <<channel,channel>> on creation. If you do
5909 not specify the channel with the opt:lttng-enable-event(1):--channel
5910 option, and if the event rule to create is the first in its
5911 <<domain,tracing domain>> for a given tracing session, then LTTng
5912 creates a _default channel_ for you. This default channel is reused in
5913 subsequent invocations of the man:lttng-enable-event(1) command for the
5914 same tracing domain.
5916 An event rule is always enabled at creation time.
5918 The following examples show how you can combine the previous
5919 command-line options to create simple to more complex event rules.
5921 .Create an event rule targetting a Linux kernel tracepoint (default channel).
5925 $ lttng enable-event --kernel sched_switch
5929 .Create an event rule matching four Linux kernel system calls (default channel).
5933 $ lttng enable-event --kernel --syscall open,write,read,close
5937 .Create event rules matching tracepoints with filter expressions (default channel).
5941 $ lttng enable-event --kernel sched_switch --filter='prev_comm == "bash"'
5946 $ lttng enable-event --kernel --all \
5947 --filter='$ctx.tid == 1988 || $ctx.tid == 1534'
5952 $ lttng enable-event --jul my_logger \
5953 --filter='$app.retriever:cur_msg_id > 3'
5956 IMPORTANT: Make sure to always quote the filter string when you
5957 use man:lttng(1) from a shell.
5960 .Create an event rule matching any user space tracepoint of a given tracepoint provider with a log level range (default channel).
5964 $ lttng enable-event --userspace my_app:'*' --loglevel=TRACE_INFO
5967 IMPORTANT: Make sure to always quote the wildcard character when you
5968 use man:lttng(1) from a shell.
5971 .Create an event rule matching multiple Python loggers with a wildcard and with exclusions (default channel).
5975 $ lttng enable-event --python my-app.'*' \
5976 --exclude='my-app.module,my-app.hello'
5980 .Create an event rule matching any Apache log4j logger with a specific log level (default channel).
5984 $ lttng enable-event --log4j --all --loglevel-only=LOG4J_WARN
5988 .Create an event rule attached to a specific channel matching a specific user space tracepoint provider and tracepoint.
5992 $ lttng enable-event --userspace my_app:my_tracepoint --channel=my-channel
5996 The event rules of a given channel form a whitelist: as soon as an
5997 emitted event passes one of them, LTTng can record the event. For
5998 example, an event named `my_app:my_tracepoint` emitted from a user space
5999 tracepoint with a `TRACE_ERROR` log level passes both of the following
6004 $ lttng enable-event --userspace my_app:my_tracepoint
6005 $ lttng enable-event --userspace my_app:my_tracepoint \
6006 --loglevel=TRACE_INFO
6009 The second event rule is redundant: the first one includes
6013 [[disable-event-rule]]
6014 === Disable an event rule
6016 To disable an event rule that you <<enabling-disabling-events,created>>
6017 previously, use the man:lttng-disable-event(1) command. This command
6018 disables _all_ the event rules (of a given tracing domain and channel)
6019 which match an instrumentation point. The other conditions are not
6020 supported as of LTTng{nbsp}{revision}.
6022 The LTTng tracer does not record an emitted event which passes
6023 a _disabled_ event rule.
6025 .Disable an event rule matching a Python logger (default channel).
6029 $ lttng disable-event --python my-logger
6033 .Disable an event rule matching all `java.util.logging` loggers (default channel).
6037 $ lttng disable-event --jul '*'
6041 .Disable _all_ the event rules of the default channel.
6043 The opt:lttng-disable-event(1):--all-events option is not, like the
6044 opt:lttng-enable-event(1):--all option of man:lttng-enable-event(1), the
6045 equivalent of the event name `*` (wildcard): it disables _all_ the event
6046 rules of a given channel.
6050 $ lttng disable-event --jul --all-events
6054 NOTE: You cannot delete an event rule once you create it.
6058 === Get the status of a tracing session
6060 To get the status of the current tracing session, that is, its
6061 parameters, its channels, event rules, and their attributes:
6063 * Use the man:lttng-status(1) command:
6073 To get the status of any tracing session:
6075 * Use the man:lttng-list(1) command with the tracing session's name:
6080 $ lttng list my-session
6084 Replace `my-session` with the desired tracing session's name.
6087 [[basic-tracing-session-control]]
6088 === Start and stop a tracing session
6090 Once you <<creating-destroying-tracing-sessions,create a tracing
6092 <<enabling-disabling-events,create one or more event rules>>,
6093 you can start and stop the tracers for this tracing session.
6095 To start tracing in the current tracing session:
6097 * Use the man:lttng-start(1) command:
6106 LTTng is very flexible: you can launch user applications before
6107 or after the you start the tracers. The tracers only record the events
6108 if they pass enabled event rules and if they occur while the tracers are
6111 To stop tracing in the current tracing session:
6113 * Use the man:lttng-stop(1) command:
6122 If there were <<channel-overwrite-mode-vs-discard-mode,lost event
6123 records>> or lost sub-buffers since the last time you ran
6124 man:lttng-start(1), warnings are printed when you run the
6125 man:lttng-stop(1) command.
6127 IMPORTANT: You need to stop tracing to make LTTng flush the remaining
6128 trace data and make the trace readable. Note that the
6129 man:lttng-destroy(1) command (see
6130 <<creating-destroying-tracing-sessions,Create and destroy a tracing
6131 session>>) also runs the man:lttng-stop(1) command implicitly.
6134 [[enabling-disabling-channels]]
6135 === Create a channel
6137 Once you create a tracing session, you can create a <<channel,channel>>
6138 with the man:lttng-enable-channel(1) command.
6140 Note that LTTng automatically creates a default channel when, for a
6141 given <<domain,tracing domain>>, no channels exist and you
6142 <<enabling-disabling-events,create>> the first event rule. This default
6143 channel is named `channel0` and its attributes are set to reasonable
6144 values. Therefore, you only need to create a channel when you need
6145 non-default attributes.
6147 You specify each non-default channel attribute with a command-line
6148 option when you use the man:lttng-enable-channel(1) command. The
6149 available command-line options are:
6151 [role="growable",cols="asciidoc,asciidoc"]
6152 .Command-line options for the man:lttng-enable-channel(1) command.
6154 |Option |Description
6160 <<channel-overwrite-mode-vs-discard-mode,event loss mode>> instead of
6161 the default _discard_ mode.
6163 |`--buffers-pid` (user space tracing domain only)
6166 Use the per-process <<channel-buffering-schemes,buffering scheme>>
6167 instead of the default per-user buffering scheme.
6169 |+--subbuf-size=__SIZE__+
6172 Allocate sub-buffers of +__SIZE__+ bytes (power of two), for each CPU,
6173 either for each Unix user (default), or for each instrumented process.
6175 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
6177 |+--num-subbuf=__COUNT__+
6180 Allocate +__COUNT__+ sub-buffers (power of two), for each CPU, either
6181 for each Unix user (default), or for each instrumented process.
6183 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
6185 |+--tracefile-size=__SIZE__+
6188 Set the maximum size of each trace file that this channel writes within
6189 a stream to +__SIZE__+ bytes instead of no maximum.
6191 See <<tracefile-rotation,Trace file count and size>>.
6193 |+--tracefile-count=__COUNT__+
6196 Limit the number of trace files that this channel creates to
6197 +__COUNT__+ channels instead of no limit.
6199 See <<tracefile-rotation,Trace file count and size>>.
6201 |+--switch-timer=__PERIODUS__+
6204 Set the <<channel-switch-timer,switch timer period>>
6205 to +__PERIODUS__+{nbsp}µs.
6207 |+--read-timer=__PERIODUS__+
6210 Set the <<channel-read-timer,read timer period>>
6211 to +__PERIODUS__+{nbsp}µs.
6213 |[[opt-blocking-timeout]]+--blocking-timeout=__TIMEOUTUS__+
6216 Set the timeout of user space applications which load LTTng-UST
6217 in blocking mode to +__TIMEOUTUS__+:
6220 Never block (non-blocking mode).
6223 Block forever until space is available in a sub-buffer to record
6226 __n__, a positive value::
6227 Wait for at most __n__ µs when trying to write into a sub-buffer.
6229 Note that, for this option to have any effect on an instrumented
6230 user space application, you need to run the application with a set
6231 env:LTTNG_UST_ALLOW_BLOCKING environment variable.
6233 |+--output=__TYPE__+ (Linux kernel tracing domain only)
6236 Set the channel's output type to +__TYPE__+, either `mmap` or `splice`.
6240 You can only create a channel in the Linux kernel and user space
6241 <<domain,tracing domains>>: other tracing domains have their own channel
6242 created on the fly when <<enabling-disabling-events,creating event
6247 Because of a current LTTng limitation, you must create all channels
6248 _before_ you <<basic-tracing-session-control,start tracing>> in a given
6249 tracing session, that is, before the first time you run
6252 Since LTTng automatically creates a default channel when you use the
6253 man:lttng-enable-event(1) command with a specific tracing domain, you
6254 cannot, for example, create a Linux kernel event rule, start tracing,
6255 and then create a user space event rule, because no user space channel
6256 exists yet and it's too late to create one.
6258 For this reason, make sure to configure your channels properly
6259 before starting the tracers for the first time!
6262 The following examples show how you can combine the previous
6263 command-line options to create simple to more complex channels.
6265 .Create a Linux kernel channel with default attributes.
6269 $ lttng enable-channel --kernel my-channel
6273 .Create a user space channel with 4 sub-buffers or 1{nbsp}MiB each, per CPU, per instrumented process.
6277 $ lttng enable-channel --userspace --num-subbuf=4 --subbuf-size=1M \
6278 --buffers-pid my-channel
6282 .[[blocking-timeout-example]]Create a default user space channel with an infinite blocking timeout.
6284 <<creating-destroying-tracing-sessions,Create a tracing-session>>,
6285 create the channel, <<enabling-disabling-events,create an event rule>>,
6286 and <<basic-tracing-session-control,start tracing>>:
6291 $ lttng enable-channel --userspace --blocking-timeout=inf blocking-channel
6292 $ lttng enable-event --userspace --channel=blocking-channel --all
6296 Run an application instrumented with LTTng-UST and allow it to block:
6300 $ LTTNG_UST_ALLOW_BLOCKING=1 my-app
6304 .Create a Linux kernel channel which rotates 8 trace files of 4{nbsp}MiB each for each stream
6308 $ lttng enable-channel --kernel --tracefile-count=8 \
6309 --tracefile-size=4194304 my-channel
6313 .Create a user space channel in overwrite (or _flight recorder_) mode.
6317 $ lttng enable-channel --userspace --overwrite my-channel
6321 You can <<enabling-disabling-events,create>> the same event rule in
6322 two different channels:
6326 $ lttng enable-event --userspace --channel=my-channel app:tp
6327 $ lttng enable-event --userspace --channel=other-channel app:tp
6330 If both channels are enabled, when a tracepoint named `app:tp` is
6331 reached, LTTng records two events, one for each channel.
6335 === Disable a channel
6337 To disable a specific channel that you <<enabling-disabling-channels,created>>
6338 previously, use the man:lttng-disable-channel(1) command.
6340 .Disable a specific Linux kernel channel.
6344 $ lttng disable-channel --kernel my-channel
6348 The state of a channel precedes the individual states of event rules
6349 attached to it: event rules which belong to a disabled channel, even if
6350 they are enabled, are also considered disabled.
6354 === Add context fields to a channel
6356 Event record fields in trace files provide important information about
6357 events that occured previously, but sometimes some external context may
6358 help you solve a problem faster. Examples of context fields are:
6360 * The **process ID**, **thread ID**, **process name**, and
6361 **process priority** of the thread in which the event occurs.
6362 * The **hostname** of the system on which the event occurs.
6363 * The current values of many possible **performance counters** using
6365 ** CPU cycles, stalled cycles, idle cycles, and the other cycle types.
6367 ** Branch instructions, misses, and loads.
6369 * Any context defined at the application level (supported for the
6370 JUL and log4j <<domain,tracing domains>>).
6372 To get the full list of available context fields, see
6373 `lttng add-context --list`. Some context fields are reserved for a
6374 specific <<domain,tracing domain>> (Linux kernel or user space).
6376 You add context fields to <<channel,channels>>. All the events
6377 that a channel with added context fields records contain those fields.
6379 To add context fields to one or all the channels of a given tracing
6382 * Use the man:lttng-add-context(1) command.
6384 .Add context fields to all the channels of the current tracing session.
6386 The following command line adds the virtual process identifier and
6387 the per-thread CPU cycles count fields to all the user space channels
6388 of the current tracing session.
6392 $ lttng add-context --userspace --type=vpid --type=perf:thread:cpu-cycles
6396 .Add performance counter context fields by raw ID
6398 See man:lttng-add-context(1) for the exact format of the context field
6399 type, which is partly compatible with the format used in
6404 $ lttng add-context --userspace --type=perf:thread:raw:r0110:test
6405 $ lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted
6409 .Add a context field to a specific channel.
6411 The following command line adds the thread identifier context field
6412 to the Linux kernel channel named `my-channel` in the current
6417 $ lttng add-context --kernel --channel=my-channel --type=tid
6421 .Add an application-specific context field to a specific channel.
6423 The following command line adds the `cur_msg_id` context field of the
6424 `retriever` context retriever for all the instrumented
6425 <<java-application,Java applications>> recording <<event,event records>>
6426 in the channel named `my-channel`:
6430 $ lttng add-context --kernel --channel=my-channel \
6431 --type='$app:retriever:cur_msg_id'
6434 IMPORTANT: Make sure to always quote the `$` character when you
6435 use man:lttng-add-context(1) from a shell.
6438 NOTE: You cannot remove context fields from a channel once you add it.
6443 === Track process IDs
6445 It's often useful to allow only specific process IDs (PIDs) to emit
6446 events. For example, you may wish to record all the system calls made by
6447 a given process (Ă la http://linux.die.net/man/1/strace[strace]).
6449 The man:lttng-track(1) and man:lttng-untrack(1) commands serve this
6450 purpose. Both commands operate on a whitelist of process IDs. You _add_
6451 entries to this whitelist with the man:lttng-track(1) command and remove
6452 entries with the man:lttng-untrack(1) command. Any process which has one
6453 of the PIDs in the whitelist is allowed to emit LTTng events which pass
6454 an enabled <<event,event rule>>.
6456 NOTE: The PID tracker tracks the _numeric process IDs_. Should a
6457 process with a given tracked ID exit and another process be given this
6458 ID, then the latter would also be allowed to emit events.
6460 .Track and untrack process IDs.
6462 For the sake of the following example, assume the target system has 16
6466 <<creating-destroying-tracing-sessions,create a tracing session>>,
6467 the whitelist contains all the possible PIDs:
6470 .All PIDs are tracked.
6471 image::track-all.png[]
6473 When the whitelist is full and you use the man:lttng-track(1) command to
6474 specify some PIDs to track, LTTng first clears the whitelist, then it
6475 tracks the specific PIDs. After:
6479 $ lttng track --pid=3,4,7,10,13
6485 .PIDs 3, 4, 7, 10, and 13 are tracked.
6486 image::track-3-4-7-10-13.png[]
6488 You can add more PIDs to the whitelist afterwards:
6492 $ lttng track --pid=1,15,16
6498 .PIDs 1, 15, and 16 are added to the whitelist.
6499 image::track-1-3-4-7-10-13-15-16.png[]
6501 The man:lttng-untrack(1) command removes entries from the PID tracker's
6502 whitelist. Given the previous example, the following command:
6506 $ lttng untrack --pid=3,7,10,13
6509 leads to this whitelist:
6512 .PIDs 3, 7, 10, and 13 are removed from the whitelist.
6513 image::track-1-4-15-16.png[]
6515 LTTng can track all possible PIDs again using the
6516 opt:lttng-track(1):--all option:
6520 $ lttng track --pid --all
6523 The result is, again:
6526 .All PIDs are tracked.
6527 image::track-all.png[]
6530 .Track only specific PIDs
6532 A very typical use case with PID tracking is to start with an empty
6533 whitelist, then <<basic-tracing-session-control,start the tracers>>, and
6534 then add PIDs manually while tracers are active. You can accomplish this
6535 by using the opt:lttng-untrack(1):--all option of the
6536 man:lttng-untrack(1) command to clear the whitelist after you
6537 <<creating-destroying-tracing-sessions,create a tracing session>>:
6541 $ lttng untrack --pid --all
6547 .No PIDs are tracked.
6548 image::untrack-all.png[]
6550 If you trace with this whitelist configuration, the tracer records no
6551 events for this <<domain,tracing domain>> because no processes are
6552 tracked. You can use the man:lttng-track(1) command as usual to track
6553 specific PIDs, for example:
6557 $ lttng track --pid=6,11
6563 .PIDs 6 and 11 are tracked.
6564 image::track-6-11.png[]
6569 [[saving-loading-tracing-session]]
6570 === Save and load tracing session configurations
6572 Configuring a <<tracing-session,tracing session>> can be long. Some of
6573 the tasks involved are:
6575 * <<enabling-disabling-channels,Create channels>> with
6576 specific attributes.
6577 * <<adding-context,Add context fields>> to specific channels.
6578 * <<enabling-disabling-events,Create event rules>> with specific log
6579 level and filter conditions.
6581 If you use LTTng to solve real world problems, chances are you have to
6582 record events using the same tracing session setup over and over,
6583 modifying a few variables each time in your instrumented program
6584 or environment. To avoid constant tracing session reconfiguration,
6585 the man:lttng(1) command-line tool can save and load tracing session
6586 configurations to/from XML files.
6588 To save a given tracing session configuration:
6590 * Use the man:lttng-save(1) command:
6595 $ lttng save my-session
6599 Replace `my-session` with the name of the tracing session to save.
6601 LTTng saves tracing session configurations to
6602 dir:{$LTTNG_HOME/.lttng/sessions} by default. Note that the
6603 env:LTTNG_HOME environment variable defaults to `$HOME` if not set. Use
6604 the opt:lttng-save(1):--output-path option to change this destination
6607 LTTng saves all configuration parameters, for example:
6609 * The tracing session name.
6610 * The trace data output path.
6611 * The channels with their state and all their attributes.
6612 * The context fields you added to channels.
6613 * The event rules with their state, log level and filter conditions.
6615 To load a tracing session:
6617 * Use the man:lttng-load(1) command:
6622 $ lttng load my-session
6626 Replace `my-session` with the name of the tracing session to load.
6628 When LTTng loads a configuration, it restores your saved tracing session
6629 as if you just configured it manually.
6631 See man:lttng(1) for the complete list of command-line options. You
6632 can also save and load all many sessions at a time, and decide in which
6633 directory to output the XML files.
6636 [[sending-trace-data-over-the-network]]
6637 === Send trace data over the network
6639 LTTng can send the recorded trace data to a remote system over the
6640 network instead of writing it to the local file system.
6642 To send the trace data over the network:
6644 . On the _remote_ system (which can also be the target system),
6645 start an LTTng <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)):
6654 . On the _target_ system, create a tracing session configured to
6655 send trace data over the network:
6660 $ lttng create my-session --set-url=net://remote-system
6664 Replace `remote-system` by the host name or IP address of the
6665 remote system. See man:lttng-create(1) for the exact URL format.
6667 . On the target system, use the man:lttng(1) command-line tool as usual.
6668 When tracing is active, the target's consumer daemon sends sub-buffers
6669 to the relay daemon running on the remote system instead of flushing
6670 them to the local file system. The relay daemon writes the received
6671 packets to the local file system.
6673 The relay daemon writes trace files to
6674 +$LTTNG_HOME/lttng-traces/__hostname__/__session__+ by default, where
6675 +__hostname__+ is the host name of the target system and +__session__+
6676 is the tracing session name. Note that the env:LTTNG_HOME environment
6677 variable defaults to `$HOME` if not set. Use the
6678 opt:lttng-relayd(8):--output option of man:lttng-relayd(8) to write
6679 trace files to another base directory.
6684 === View events as LTTng emits them (noch:{LTTng} live)
6686 LTTng live is a network protocol implemented by the <<lttng-relayd,relay
6687 daemon>> (man:lttng-relayd(8)) to allow compatible trace viewers to
6688 display events as LTTng emits them on the target system while tracing is
6691 The relay daemon creates a _tee_: it forwards the trace data to both
6692 the local file system and to connected live viewers:
6695 .The relay daemon creates a _tee_, forwarding the trace data to both trace files and a connected live viewer.
6700 . On the _target system_, create a <<tracing-session,tracing session>>
6706 $ lttng create my-session --live
6710 This spawns a local relay daemon.
6712 . Start the live viewer and configure it to connect to the relay
6713 daemon. For example, with http://diamon.org/babeltrace[Babeltrace]:
6718 $ babeltrace --input-format=lttng-live \
6719 net://localhost/host/hostname/my-session
6726 * `hostname` with the host name of the target system.
6727 * `my-session` with the name of the tracing session to view.
6730 . Configure the tracing session as usual with the man:lttng(1)
6731 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6733 You can list the available live tracing sessions with Babeltrace:
6737 $ babeltrace --input-format=lttng-live net://localhost
6740 You can start the relay daemon on another system. In this case, you need
6741 to specify the relay daemon's URL when you create the tracing session
6742 with the opt:lttng-create(1):--set-url option. You also need to replace
6743 `localhost` in the procedure above with the host name of the system on
6744 which the relay daemon is running.
6746 See man:lttng-create(1) and man:lttng-relayd(8) for the complete list of
6747 command-line options.
6751 [[taking-a-snapshot]]
6752 === Take a snapshot of the current sub-buffers of a tracing session
6754 The normal behavior of LTTng is to append full sub-buffers to growing
6755 trace data files. This is ideal to keep a full history of the events
6756 that occurred on the target system, but it can
6757 represent too much data in some situations. For example, you may wish
6758 to trace your application continuously until some critical situation
6759 happens, in which case you only need the latest few recorded
6760 events to perform the desired analysis, not multi-gigabyte trace files.
6762 With the man:lttng-snapshot(1) command, you can take a snapshot of the
6763 current sub-buffers of a given <<tracing-session,tracing session>>.
6764 LTTng can write the snapshot to the local file system or send it over
6769 . Create a tracing session in _snapshot mode_:
6774 $ lttng create my-session --snapshot
6778 The <<channel-overwrite-mode-vs-discard-mode,event loss mode>> of
6779 <<channel,channels>> created in this mode is automatically set to
6780 _overwrite_ (flight recorder mode).
6782 . Configure the tracing session as usual with the man:lttng(1)
6783 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6785 . **Optional**: When you need to take a snapshot,
6786 <<basic-tracing-session-control,stop tracing>>.
6788 You can take a snapshot when the tracers are active, but if you stop
6789 them first, you are sure that the data in the sub-buffers does not
6790 change before you actually take the snapshot.
6797 $ lttng snapshot record --name=my-first-snapshot
6801 LTTng writes the current sub-buffers of all the current tracing
6802 session's channels to trace files on the local file system. Those trace
6803 files have `my-first-snapshot` in their name.
6805 There is no difference between the format of a normal trace file and the
6806 format of a snapshot: viewers of LTTng traces also support LTTng
6809 By default, LTTng writes snapshot files to the path shown by
6810 `lttng snapshot list-output`. You can change this path or decide to send
6811 snapshots over the network using either:
6813 . An output path or URL that you specify when you create the
6815 . An snapshot output path or URL that you add using
6816 `lttng snapshot add-output`
6817 . An output path or URL that you provide directly to the
6818 `lttng snapshot record` command.
6820 Method 3 overrides method 2, which overrides method 1. When you
6821 specify a URL, a relay daemon must listen on a remote system (see
6822 <<sending-trace-data-over-the-network,Send trace data over the network>>).
6827 === Use the machine interface
6829 With any command of the man:lttng(1) command-line tool, you can set the
6830 opt:lttng(1):--mi option to `xml` (before the command name) to get an
6831 XML machine interface output, for example:
6835 $ lttng --mi=xml enable-event --kernel --syscall open
6838 A schema definition (XSD) is
6839 https://github.com/lttng/lttng-tools/blob/stable-2.10/src/common/mi-lttng-3.0.xsd[available]
6840 to ease the integration with external tools as much as possible.
6844 [[metadata-regenerate]]
6845 === Regenerate the metadata of an LTTng trace
6847 An LTTng trace, which is a http://diamon.org/ctf[CTF] trace, has both
6848 data stream files and a metadata file. This metadata file contains,
6849 amongst other things, information about the offset of the clock sources
6850 used to timestamp <<event,event records>> when tracing.
6852 If, once a <<tracing-session,tracing session>> is
6853 <<basic-tracing-session-control,started>>, a major
6854 https://en.wikipedia.org/wiki/Network_Time_Protocol[NTP] correction
6855 happens, the trace's clock offset also needs to be updated. You
6856 can use the `metadata` item of the man:lttng-regenerate(1) command
6859 The main use case of this command is to allow a system to boot with
6860 an incorrect wall time and trace it with LTTng before its wall time
6861 is corrected. Once the system is known to be in a state where its
6862 wall time is correct, it can run `lttng regenerate metadata`.
6864 To regenerate the metadata of an LTTng trace:
6866 * Use the `metadata` item of the man:lttng-regenerate(1) command:
6871 $ lttng regenerate metadata
6877 `lttng regenerate metadata` has the following limitations:
6879 * Tracing session <<creating-destroying-tracing-sessions,created>>
6881 * User space <<channel,channels>>, if any, are using
6882 <<channel-buffering-schemes,per-user buffering>>.
6887 [[regenerate-statedump]]
6888 === Regenerate the state dump of a tracing session
6890 The LTTng kernel and user space tracers generate state dump
6891 <<event,event records>> when the application starts or when you
6892 <<basic-tracing-session-control,start a tracing session>>. An analysis
6893 can use the state dump event records to set an initial state before it
6894 builds the rest of the state from the following event records.
6895 http://tracecompass.org/[Trace Compass] is a notable example of an
6896 application which uses the state dump of an LTTng trace.
6898 When you <<taking-a-snapshot,take a snapshot>>, it's possible that the
6899 state dump event records are not included in the snapshot because they
6900 were recorded to a sub-buffer that has been consumed or overwritten
6903 You can use the `lttng regenerate statedump` command to emit the state
6904 dump event records again.
6906 To regenerate the state dump of the current tracing session, provided
6907 create it in snapshot mode, before you take a snapshot:
6909 . Use the `statedump` item of the man:lttng-regenerate(1) command:
6914 $ lttng regenerate statedump
6918 . <<basic-tracing-session-control,Stop the tracing session>>:
6927 . <<taking-a-snapshot,Take a snapshot>>:
6932 $ lttng snapshot record --name=my-snapshot
6936 Depending on the event throughput, you should run steps 1 and 2
6937 as closely as possible.
6939 NOTE: To record the state dump events, you need to
6940 <<enabling-disabling-events,create event rules>> which enable them.
6941 LTTng-UST state dump tracepoints start with `lttng_ust_statedump:`.
6942 LTTng-modules state dump tracepoints start with `lttng_statedump_`.
6946 [[persistent-memory-file-systems]]
6947 === Record trace data on persistent memory file systems
6949 https://en.wikipedia.org/wiki/Non-volatile_random-access_memory[Non-volatile random-access memory]
6950 (NVRAM) is random-access memory that retains its information when power
6951 is turned off (non-volatile). Systems with such memory can store data
6952 structures in RAM and retrieve them after a reboot, without flushing
6953 to typical _storage_.
6955 Linux supports NVRAM file systems thanks to either
6956 http://pramfs.sourceforge.net/[PRAMFS] or
6957 https://www.kernel.org/doc/Documentation/filesystems/dax.txt[DAX]{nbsp}+{nbsp}http://lkml.iu.edu/hypermail/linux/kernel/1504.1/03463.html[pmem]
6958 (requires Linux 4.1+).
6960 This section does not describe how to operate such file systems;
6961 we assume that you have a working persistent memory file system.
6963 When you create a <<tracing-session,tracing session>>, you can specify
6964 the path of the shared memory holding the sub-buffers. If you specify a
6965 location on an NVRAM file system, then you can retrieve the latest
6966 recorded trace data when the system reboots after a crash.
6968 To record trace data on a persistent memory file system and retrieve the
6969 trace data after a system crash:
6971 . Create a tracing session with a sub-buffer shared memory path located
6972 on an NVRAM file system:
6977 $ lttng create my-session --shm-path=/path/to/shm
6981 . Configure the tracing session as usual with the man:lttng(1)
6982 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6984 . After a system crash, use the man:lttng-crash(1) command-line tool to
6985 view the trace data recorded on the NVRAM file system:
6990 $ lttng-crash /path/to/shm
6994 The binary layout of the ring buffer files is not exactly the same as
6995 the trace files layout. This is why you need to use man:lttng-crash(1)
6996 instead of your preferred trace viewer directly.
6998 To convert the ring buffer files to LTTng trace files:
7000 * Use the opt:lttng-crash(1):--extract option of man:lttng-crash(1):
7005 $ lttng-crash --extract=/path/to/trace /path/to/shm
7011 [[notif-trigger-api]]
7012 === Get notified when a channel's buffer usage is too high or too low
7014 With LTTng's $$C/C++$$ notification and trigger API, your user
7015 application can get notified when the buffer usage of one or more
7016 <<channel,channels>> becomes too low or too high. You can use this API
7017 and enable or disable <<event,event rules>> during tracing to avoid
7018 <<channel-overwrite-mode-vs-discard-mode,discarded event records>>.
7020 .Have a user application get notified when an LTTng channel's buffer usage is too high.
7022 In this example, we create and build an application which gets notified
7023 when the buffer usage of a specific LTTng channel is higher than
7024 75{nbsp}%. We only print that it is the case in the example, but we
7025 could as well use the API of <<liblttng-ctl-lttng,`liblttng-ctl`>> to
7026 disable event rules when this happens.
7028 . Create the application's C source file:
7036 #include <lttng/domain.h>
7037 #include <lttng/action/action.h>
7038 #include <lttng/action/notify.h>
7039 #include <lttng/condition/condition.h>
7040 #include <lttng/condition/buffer-usage.h>
7041 #include <lttng/condition/evaluation.h>
7042 #include <lttng/notification/channel.h>
7043 #include <lttng/notification/notification.h>
7044 #include <lttng/trigger/trigger.h>
7045 #include <lttng/endpoint.h>
7047 int main(int argc, char *argv[])
7049 int exit_status = 0;
7050 struct lttng_notification_channel *notification_channel;
7051 struct lttng_condition *condition;
7052 struct lttng_action *action;
7053 struct lttng_trigger *trigger;
7054 const char *tracing_session_name;
7055 const char *channel_name;
7058 tracing_session_name = argv[1];
7059 channel_name = argv[2];
7062 * Create a notification channel. A notification channel
7063 * connects the user application to the LTTng session daemon.
7064 * This notification channel can be used to listen to various
7065 * types of notifications.
7067 notification_channel = lttng_notification_channel_create(
7068 lttng_session_daemon_notification_endpoint);
7071 * Create a "high buffer usage" condition. In this case, the
7072 * condition is reached when the buffer usage is greater than or
7073 * equal to 75 %. We create the condition for a specific tracing
7074 * session name, channel name, and for the user space tracing
7077 * The "low buffer usage" condition type also exists.
7079 condition = lttng_condition_buffer_usage_high_create();
7080 lttng_condition_buffer_usage_set_threshold_ratio(condition, .75);
7081 lttng_condition_buffer_usage_set_session_name(
7082 condition, tracing_session_name);
7083 lttng_condition_buffer_usage_set_channel_name(condition,
7085 lttng_condition_buffer_usage_set_domain_type(condition,
7089 * Create an action (get a notification) to take when the
7090 * condition created above is reached.
7092 action = lttng_action_notify_create();
7095 * Create a trigger. A trigger associates a condition to an
7096 * action: the action is executed when the condition is reached.
7098 trigger = lttng_trigger_create(condition, action);
7100 /* Register the trigger to LTTng. */
7101 lttng_register_trigger(trigger);
7104 * Now that we have registered a trigger, a notification will be
7105 * emitted everytime its condition is met. To receive this
7106 * notification, we must subscribe to notifications that match
7107 * the same condition.
7109 lttng_notification_channel_subscribe(notification_channel,
7113 * Notification loop. You can put this in a dedicated thread to
7114 * avoid blocking the main thread.
7117 struct lttng_notification *notification;
7118 enum lttng_notification_channel_status status;
7119 const struct lttng_evaluation *notification_evaluation;
7120 const struct lttng_condition *notification_condition;
7121 double buffer_usage;
7123 /* Receive the next notification. */
7124 status = lttng_notification_channel_get_next_notification(
7125 notification_channel, ¬ification);
7128 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK:
7130 case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED:
7132 * The session daemon can drop notifications if
7133 * a monitoring application is not consuming the
7134 * notifications fast enough.
7137 case LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED:
7139 * The notification channel has been closed by the
7140 * session daemon. This is typically caused by a session
7141 * daemon shutting down.
7145 /* Unhandled conditions or errors. */
7151 * A notification provides, amongst other things:
7153 * * The condition that caused this notification to be
7155 * * The condition evaluation, which provides more
7156 * specific information on the evaluation of the
7159 * The condition evaluation provides the buffer usage
7160 * value at the moment the condition was reached.
7162 notification_condition = lttng_notification_get_condition(
7164 notification_evaluation = lttng_notification_get_evaluation(
7167 /* We're subscribed to only one condition. */
7168 assert(lttng_condition_get_type(notification_condition) ==
7169 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH);
7172 * Get the exact sampled buffer usage from the
7173 * condition evaluation.
7175 lttng_evaluation_buffer_usage_get_usage_ratio(
7176 notification_evaluation, &buffer_usage);
7179 * At this point, instead of printing a message, we
7180 * could do something to reduce the channel's buffer
7181 * usage, like disable specific events.
7183 printf("Buffer usage is %f %% in tracing session \"%s\", "
7184 "user space channel \"%s\".\n", buffer_usage * 100,
7185 tracing_session_name, channel_name);
7186 lttng_notification_destroy(notification);
7190 lttng_action_destroy(action);
7191 lttng_condition_destroy(condition);
7192 lttng_trigger_destroy(trigger);
7193 lttng_notification_channel_destroy(notification_channel);
7199 . Build the `notif-app` application, linking it to `liblttng-ctl`:
7204 $ gcc -o notif-app notif-app.c -llttng-ctl
7208 . <<creating-destroying-tracing-sessions,Create a tracing session>>,
7209 <<enabling-disabling-events,create an event rule>> matching all the
7210 user space tracepoints, and
7211 <<basic-tracing-session-control,start tracing>>:
7216 $ lttng create my-session
7217 $ lttng enable-event --userspace --all
7222 If you create the channel manually with the man:lttng-enable-channel(1)
7223 command, you can control how frequently are the current values of the
7224 channel's properties sampled to evaluate user conditions with the
7225 opt:lttng-enable-channel(1):--monitor-timer option.
7227 . Run the `notif-app` application. This program accepts the
7228 <<tracing-session,tracing session>> name and the user space channel
7229 name as its two first arguments. The channel which LTTng automatically
7230 creates with the man:lttng-enable-event(1) command above is named
7236 $ ./notif-app my-session channel0
7240 . In another terminal, run an application with a very high event
7241 throughput so that the 75{nbsp}% buffer usage condition is reached.
7243 In the first terminal, the application should print lines like this:
7246 Buffer usage is 81.45197 % in tracing session "my-session", user space
7250 If you don't see anything, try modifying the condition in
7251 path:{notif-app.c} to a lower value (0.1, for example), rebuilding it
7252 (step 2) and running it again (step 4).
7259 [[lttng-modules-ref]]
7260 === noch:{LTTng-modules}
7264 [[lttng-tracepoint-enum]]
7265 ==== `LTTNG_TRACEPOINT_ENUM()` usage
7267 Use the `LTTNG_TRACEPOINT_ENUM()` macro to define an enumeration:
7271 LTTNG_TRACEPOINT_ENUM(name, TP_ENUM_VALUES(entries))
7276 * `name` with the name of the enumeration (C identifier, unique
7277 amongst all the defined enumerations).
7278 * `entries` with a list of enumeration entries.
7280 The available enumeration entry macros are:
7282 +ctf_enum_value(__name__, __value__)+::
7283 Entry named +__name__+ mapped to the integral value +__value__+.
7285 +ctf_enum_range(__name__, __begin__, __end__)+::
7286 Entry named +__name__+ mapped to the range of integral values between
7287 +__begin__+ (included) and +__end__+ (included).
7289 +ctf_enum_auto(__name__)+::
7290 Entry named +__name__+ mapped to the integral value following the
7291 last mapping's value.
7293 The last value of a `ctf_enum_value()` entry is its +__value__+
7296 The last value of a `ctf_enum_range()` entry is its +__end__+ parameter.
7298 If `ctf_enum_auto()` is the first entry in the list, its integral
7301 Use the `ctf_enum()` <<lttng-modules-tp-fields,field definition macro>>
7302 to use a defined enumeration as a tracepoint field.
7304 .Define an enumeration with `LTTNG_TRACEPOINT_ENUM()`.
7308 LTTNG_TRACEPOINT_ENUM(
7311 ctf_enum_auto("AUTO: EXPECT 0")
7312 ctf_enum_value("VALUE: 23", 23)
7313 ctf_enum_value("VALUE: 27", 27)
7314 ctf_enum_auto("AUTO: EXPECT 28")
7315 ctf_enum_range("RANGE: 101 TO 303", 101, 303)
7316 ctf_enum_auto("AUTO: EXPECT 304")
7324 [[lttng-modules-tp-fields]]
7325 ==== Tracepoint fields macros (for `TP_FIELDS()`)
7327 [[tp-fast-assign]][[tp-struct-entry]]The available macros to define
7328 tracepoint fields, which must be listed within `TP_FIELDS()` in
7329 `LTTNG_TRACEPOINT_EVENT()`, are:
7331 [role="func-desc growable",cols="asciidoc,asciidoc"]
7332 .Available macros to define LTTng-modules tracepoint fields
7334 |Macro |Description and parameters
7337 +ctf_integer(__t__, __n__, __e__)+
7339 +ctf_integer_nowrite(__t__, __n__, __e__)+
7341 +ctf_user_integer(__t__, __n__, __e__)+
7343 +ctf_user_integer_nowrite(__t__, __n__, __e__)+
7345 Standard integer, displayed in base 10.
7348 Integer C type (`int`, `long`, `size_t`, ...).
7354 Argument expression.
7357 +ctf_integer_hex(__t__, __n__, __e__)+
7359 +ctf_user_integer_hex(__t__, __n__, __e__)+
7361 Standard integer, displayed in base 16.
7370 Argument expression.
7372 |+ctf_integer_oct(__t__, __n__, __e__)+
7374 Standard integer, displayed in base 8.
7383 Argument expression.
7386 +ctf_integer_network(__t__, __n__, __e__)+
7388 +ctf_user_integer_network(__t__, __n__, __e__)+
7390 Integer in network byte order (big-endian), displayed in base 10.
7399 Argument expression.
7402 +ctf_integer_network_hex(__t__, __n__, __e__)+
7404 +ctf_user_integer_network_hex(__t__, __n__, __e__)+
7406 Integer in network byte order, displayed in base 16.
7415 Argument expression.
7418 +ctf_enum(__N__, __t__, __n__, __e__)+
7420 +ctf_enum_nowrite(__N__, __t__, __n__, __e__)+
7422 +ctf_user_enum(__N__, __t__, __n__, __e__)+
7424 +ctf_user_enum_nowrite(__N__, __t__, __n__, __e__)+
7429 Name of a <<lttng-tracepoint-enum,previously defined enumeration>>.
7432 Integer C type (`int`, `long`, `size_t`, ...).
7438 Argument expression.
7441 +ctf_string(__n__, __e__)+
7443 +ctf_string_nowrite(__n__, __e__)+
7445 +ctf_user_string(__n__, __e__)+
7447 +ctf_user_string_nowrite(__n__, __e__)+
7449 Null-terminated string; undefined behavior if +__e__+ is `NULL`.
7455 Argument expression.
7458 +ctf_array(__t__, __n__, __e__, __s__)+
7460 +ctf_array_nowrite(__t__, __n__, __e__, __s__)+
7462 +ctf_user_array(__t__, __n__, __e__, __s__)+
7464 +ctf_user_array_nowrite(__t__, __n__, __e__, __s__)+
7466 Statically-sized array of integers.
7469 Array element C type.
7475 Argument expression.
7481 +ctf_array_bitfield(__t__, __n__, __e__, __s__)+
7483 +ctf_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7485 +ctf_user_array_bitfield(__t__, __n__, __e__, __s__)+
7487 +ctf_user_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7489 Statically-sized array of bits.
7491 The type of +__e__+ must be an integer type. +__s__+ is the number
7492 of elements of such type in +__e__+, not the number of bits.
7495 Array element C type.
7501 Argument expression.
7507 +ctf_array_text(__t__, __n__, __e__, __s__)+
7509 +ctf_array_text_nowrite(__t__, __n__, __e__, __s__)+
7511 +ctf_user_array_text(__t__, __n__, __e__, __s__)+
7513 +ctf_user_array_text_nowrite(__t__, __n__, __e__, __s__)+
7515 Statically-sized array, printed as text.
7517 The string does not need to be null-terminated.
7520 Array element C type (always `char`).
7526 Argument expression.
7532 +ctf_sequence(__t__, __n__, __e__, __T__, __E__)+
7534 +ctf_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7536 +ctf_user_sequence(__t__, __n__, __e__, __T__, __E__)+
7538 +ctf_user_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7540 Dynamically-sized array of integers.
7542 The type of +__E__+ must be unsigned.
7545 Array element C type.
7551 Argument expression.
7554 Length expression C type.
7560 +ctf_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7562 +ctf_user_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7564 Dynamically-sized array of integers, displayed in base 16.
7566 The type of +__E__+ must be unsigned.
7569 Array element C type.
7575 Argument expression.
7578 Length expression C type.
7583 |+ctf_sequence_network(__t__, __n__, __e__, __T__, __E__)+
7585 Dynamically-sized array of integers in network byte order (big-endian),
7586 displayed in base 10.
7588 The type of +__E__+ must be unsigned.
7591 Array element C type.
7597 Argument expression.
7600 Length expression C type.
7606 +ctf_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7608 +ctf_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7610 +ctf_user_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7612 +ctf_user_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7614 Dynamically-sized array of bits.
7616 The type of +__e__+ must be an integer type. +__s__+ is the number
7617 of elements of such type in +__e__+, not the number of bits.
7619 The type of +__E__+ must be unsigned.
7622 Array element C type.
7628 Argument expression.
7631 Length expression C type.
7637 +ctf_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7639 +ctf_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7641 +ctf_user_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7643 +ctf_user_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7645 Dynamically-sized array, displayed as text.
7647 The string does not need to be null-terminated.
7649 The type of +__E__+ must be unsigned.
7651 The behaviour is undefined if +__e__+ is `NULL`.
7654 Sequence element C type (always `char`).
7660 Argument expression.
7663 Length expression C type.
7669 Use the `_user` versions when the argument expression, `e`, is
7670 a user space address. In the cases of `ctf_user_integer*()` and
7671 `ctf_user_float*()`, `&e` must be a user space address, thus `e` must
7674 The `_nowrite` versions omit themselves from the session trace, but are
7675 otherwise identical. This means the `_nowrite` fields won't be written
7676 in the recorded trace. Their primary purpose is to make some
7677 of the event context available to the
7678 <<enabling-disabling-events,event filters>> without having to
7679 commit the data to sub-buffers.
7685 Terms related to LTTng and to tracing in general:
7688 The http://diamon.org/babeltrace[Babeltrace] project, which includes
7689 the cmd:babeltrace command, some libraries, and Python bindings.
7691 <<channel-buffering-schemes,buffering scheme>>::
7692 A layout of sub-buffers applied to a given channel.
7694 <<channel,channel>>::
7695 An entity which is responsible for a set of ring buffers.
7697 <<event,Event rules>> are always attached to a specific channel.
7700 A reference of time for a tracer.
7702 <<lttng-consumerd,consumer daemon>>::
7703 A process which is responsible for consuming the full sub-buffers
7704 and write them to a file system or send them over the network.
7706 <<channel-overwrite-mode-vs-discard-mode,discard mode>>:: The event loss
7707 mode in which the tracer _discards_ new event records when there's no
7708 sub-buffer space left to store them.
7711 The consequence of the execution of an instrumentation
7712 point, like a tracepoint that you manually place in some source code,
7713 or a Linux kernel KProbe.
7715 An event is said to _occur_ at a specific time. Different actions can
7716 be taken upon the occurrence of an event, like record the event's payload
7719 <<channel-overwrite-mode-vs-discard-mode,event loss mode>>::
7720 The mechanism by which event records of a given channel are lost
7721 (not recorded) when there is no sub-buffer space left to store them.
7723 [[def-event-name]]event name::
7724 The name of an event, which is also the name of the event record.
7725 This is also called the _instrumentation point name_.
7728 A record, in a trace, of the payload of an event which occured.
7730 <<event,event rule>>::
7731 Set of conditions which must be satisfied for one or more occuring
7732 events to be recorded.
7734 `java.util.logging`::
7736 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[core logging facilities].
7738 <<instrumenting,instrumentation>>::
7739 The use of LTTng probes to make a piece of software traceable.
7741 instrumentation point::
7742 A point in the execution path of a piece of software that, when
7743 reached by this execution, can emit an event.
7745 instrumentation point name::
7746 See _<<def-event-name,event name>>_.
7749 A http://logging.apache.org/log4j/1.2/[logging library] for Java
7750 developed by the Apache Software Foundation.
7753 Level of severity of a log statement or user space
7754 instrumentation point.
7757 The _Linux Trace Toolkit: next generation_ project.
7759 <<lttng-cli,cmd:lttng>>::
7760 A command-line tool provided by the LTTng-tools project which you
7761 can use to send and receive control messages to and from a
7765 The https://github.com/lttng/lttng-analyses[LTTng analyses] project,
7766 which is a set of analyzing programs that are used to obtain a
7767 higher level view of an LTTng trace.
7769 cmd:lttng-consumerd::
7770 The name of the consumer daemon program.
7773 A utility provided by the LTTng-tools project which can convert
7774 ring buffer files (usually
7775 <<persistent-memory-file-systems,saved on a persistent memory file system>>)
7778 LTTng Documentation::
7781 <<lttng-live,LTTng live>>::
7782 A communication protocol between the relay daemon and live viewers
7783 which makes it possible to see events "live", as they are received by
7786 <<lttng-modules,LTTng-modules>>::
7787 The https://github.com/lttng/lttng-modules[LTTng-modules] project,
7788 which contains the Linux kernel modules to make the Linux kernel
7789 instrumentation points available for LTTng tracing.
7792 The name of the relay daemon program.
7794 cmd:lttng-sessiond::
7795 The name of the session daemon program.
7798 The https://github.com/lttng/lttng-tools[LTTng-tools] project, which
7799 contains the various programs and libraries used to
7800 <<controlling-tracing,control tracing>>.
7802 <<lttng-ust,LTTng-UST>>::
7803 The https://github.com/lttng/lttng-ust[LTTng-UST] project, which
7804 contains libraries to instrument user applications.
7806 <<lttng-ust-agents,LTTng-UST Java agent>>::
7807 A Java package provided by the LTTng-UST project to allow the
7808 LTTng instrumentation of `java.util.logging` and Apache log4j 1.2
7811 <<lttng-ust-agents,LTTng-UST Python agent>>::
7812 A Python package provided by the LTTng-UST project to allow the
7813 LTTng instrumentation of Python logging statements.
7815 <<channel-overwrite-mode-vs-discard-mode,overwrite mode>>::
7816 The event loss mode in which new event records overwrite older
7817 event records when there's no sub-buffer space left to store them.
7819 <<channel-buffering-schemes,per-process buffering>>::
7820 A buffering scheme in which each instrumented process has its own
7821 sub-buffers for a given user space channel.
7823 <<channel-buffering-schemes,per-user buffering>>::
7824 A buffering scheme in which all the processes of a Unix user share the
7825 same sub-buffer for a given user space channel.
7827 <<lttng-relayd,relay daemon>>::
7828 A process which is responsible for receiving the trace data sent by
7829 a distant consumer daemon.
7832 A set of sub-buffers.
7834 <<lttng-sessiond,session daemon>>::
7835 A process which receives control commands from you and orchestrates
7836 the tracers and various LTTng daemons.
7838 <<taking-a-snapshot,snapshot>>::
7839 A copy of the current data of all the sub-buffers of a given tracing
7840 session, saved as trace files.
7843 One part of an LTTng ring buffer which contains event records.
7846 The time information attached to an event when it is emitted.
7849 A set of files which are the concatenations of one or more
7850 flushed sub-buffers.
7853 The action of recording the events emitted by an application
7854 or by a system, or to initiate such recording by controlling
7858 The http://tracecompass.org[Trace Compass] project and application.
7861 An instrumentation point using the tracepoint mechanism of the Linux
7862 kernel or of LTTng-UST.
7864 tracepoint definition::
7865 The definition of a single tracepoint.
7868 The name of a tracepoint.
7870 tracepoint provider::
7871 A set of functions providing tracepoints to an instrumented user
7874 Not to be confused with a _tracepoint provider package_: many tracepoint
7875 providers can exist within a tracepoint provider package.
7877 tracepoint provider package::
7878 One or more tracepoint providers compiled as an object file or as
7882 A software which records emitted events.
7884 <<domain,tracing domain>>::
7885 A namespace for event sources.
7887 <<tracing-group,tracing group>>::
7888 The Unix group in which a Unix user can be to be allowed to trace the
7891 <<tracing-session,tracing session>>::
7892 A stateful dialogue between you and a <<lttng-sessiond,session
7896 An application running in user space, as opposed to a Linux kernel
7897 module, for example.