1 The LTTng Documentation
2 =======================
3 Philippe Proulx <pproulx@efficios.com>
4 v2.11, 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{nbsp}{revision}?
77 LTTng{nbsp}{revision} bears the name _Lafontaine_. This modern
78 https://en.wikipedia.org/wiki/Saison[saison] from the
79 https://oshlag.com/[Oshlag] microbrewery is a refreshing--zesty--rice
80 beer with hints of fruit and spices. Some even say it makes for a great
81 https://en.wikipedia.org/wiki/Somaek[Somaek] when mixed with
82 Chamisul Soju, not that we've tried!
84 New features and changes in LTTng{nbsp}{revision}:
86 * Just like you can typically perform
87 https://en.wikipedia.org/wiki/Log_rotation[log rotation], you can
88 now <<session-rotation,_rotate_ a tracing session>>, that
89 is, according to man:lttng-rotate(1), archive the current trace
90 chunk (all the tracing session's trace data since the last rotation
91 or since its inception) so that LTTng does not manage it anymore.
93 Once LTTng archives a trace chunk, you are free to read it, modify it,
94 move it, or remove it.
96 You can rotate a tracing session immediately or set a rotation schedule
97 to automate rotations.
99 * When you <<enabling-disabling-events,create an event rule>>, the
100 filter expression syntax now supports the following new operators:
104 ** `<<` (bitwise left shift)
105 ** `>>` (bitwise right shift)
111 The syntax also supports array indexing with the usual square brackets:
114 regs[3][1] & 0xff7 == 0x240
117 There are peculiarities for both the new operators and the array
118 indexing brackets, like a custom precedence table and implicit casting.
119 See man:lttng-enable-event(1) to get all the details about the filter
122 * You can now dynamically instrument any application's or library's
123 function entry by symbol name thanks to the new
124 opt:lttng-enable-event(1):--userspace-probe option of
125 the `lttng enable-event` command:
129 $ lttng enable-event --kernel \
130 --userspace-probe=/usr/lib/libc.so.6:malloc libc_malloc
133 The option also supports tracing existing
134 https://www.sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps[SystemTap
135 Statically Defined Tracing] (SDT) probe (DTrace-style marker). For example,
136 given the following probe:
140 DTRACE_PROBE2("server", "accept-request", request_id, ip_addr);
143 You can trace this probe with:
146 $ lttng enable-event --kernel \
147 --userspace-probe=sdt:/path/to/server:server:accept-request \
148 server_accept_request
151 This feature makes use of Linux's
152 https://www.kernel.org/doc/Documentation/trace/uprobetracer.txt[uprobe]
153 mechanism, therefore you must use the `--userspace-probe`
154 instrumentation option with the opt:lttng-enable-event(1):--kernel
157 NOTE: As of LTTng{nbsp}{revision}, LTTng does not record function
158 parameters with the opt:lttng-enable-event(1):--userspace-probe option.
160 * Two new <<adding-context,context>> fields are available for Linux
161 kernel <<channel,channels>>:
164 ** `callstack-kernel`
168 Thanks to those, you can record the Linux kernel and user call stacks
169 when a kernel event occurs. For example:
173 $ lttng enable-event --kernel --syscall read
174 $ lttng add-context --kernel --type=callstack-kernel --type=callstack-user
177 When an man:open(2) system call occurs, LTTng attaches the kernel and
178 user call stacks to the recorded event.
180 NOTE: LTTng cannot always sample the user space call stack reliably.
181 For instance, LTTng cannot sample the call stack of user applications
182 and libraries compiled with the
183 https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html[`-fomit-frame pointer`]
184 option. In such a case, the tracing is not affected, but the sampled
185 user space call stack may only contain the user call stack's topmost
188 * The <<lttng-relayd,relay daemon>> is more efficient and presents fewer
189 connectivity issues, especially when a large number of targets send
190 trace data to a given relay daemon.
192 * User applications and libraries instrumented with
193 <<lttng-ust,LTTng-UST>> can now safely unload (man:dlclose(3)) a
195 <<building-tracepoint-providers-and-user-application,tracepoint
202 What is LTTng? As its name suggests, the _Linux Trace Toolkit: next
203 generation_ is a modern toolkit for tracing Linux systems and
204 applications. So your first question might be:
211 As the history of software engineering progressed and led to what
212 we now take for granted--complex, numerous and
213 interdependent software applications running in parallel on
214 sophisticated operating systems like Linux--the authors of such
215 components, software developers, began feeling a natural
216 urge to have tools that would ensure the robustness and good performance
217 of their masterpieces.
219 One major achievement in this field is, inarguably, the
220 https://www.gnu.org/software/gdb/[GNU debugger (GDB)],
221 an essential tool for developers to find and fix bugs. But even the best
222 debugger won't help make your software run faster, and nowadays, faster
223 software means either more work done by the same hardware, or cheaper
224 hardware for the same work.
226 A _profiler_ is often the tool of choice to identify performance
227 bottlenecks. Profiling is suitable to identify _where_ performance is
228 lost in a given software. The profiler outputs a profile, a statistical
229 summary of observed events, which you may use to discover which
230 functions took the most time to execute. However, a profiler won't
231 report _why_ some identified functions are the bottleneck. Bottlenecks
232 might only occur when specific conditions are met, conditions that are
233 sometimes impossible to capture by a statistical profiler, or impossible
234 to reproduce with an application altered by the overhead of an
235 event-based profiler. For a thorough investigation of software
236 performance issues, a history of execution is essential, with the
237 recorded values of variables and context fields you choose, and
238 with as little influence as possible on the instrumented software. This
239 is where tracing comes in handy.
241 _Tracing_ is a technique used to understand what goes on in a running
242 software system. The software used for tracing is called a _tracer_,
243 which is conceptually similar to a tape recorder. When recording,
244 specific instrumentation points placed in the software source code
245 generate events that are saved on a giant tape: a _trace_ file. You
246 can trace user applications and the operating system at the same time,
247 opening the possibility of resolving a wide range of problems that would
248 otherwise be extremely challenging.
250 Tracing is often compared to _logging_. However, tracers and loggers are
251 two different tools, serving two different purposes. Tracers are
252 designed to record much lower-level events that occur much more
253 frequently than log messages, often in the range of thousands per
254 second, with very little execution overhead. Logging is more appropriate
255 for a very high-level analysis of less frequent events: user accesses,
256 exceptional conditions (errors and warnings, for example), database
257 transactions, instant messaging communications, and such. Simply put,
258 logging is one of the many use cases that can be satisfied with tracing.
260 The list of recorded events inside a trace file can be read manually
261 like a log file for the maximum level of detail, but it is generally
262 much more interesting to perform application-specific analyses to
263 produce reduced statistics and graphs that are useful to resolve a
264 given problem. Trace viewers and analyzers are specialized tools
267 In the end, this is what LTTng is: a powerful, open source set of
268 tools to trace the Linux kernel and user applications at the same time.
269 LTTng is composed of several components actively maintained and
270 developed by its link:/community/#where[community].
273 [[lttng-alternatives]]
274 === Alternatives to noch:{LTTng}
276 Excluding proprietary solutions, a few competing software tracers
279 * https://github.com/dtrace4linux/linux[dtrace4linux] is a port of
280 Sun Microsystems's DTrace to Linux. The cmd:dtrace tool interprets
281 user scripts and is responsible for loading code into the
282 Linux kernel for further execution and collecting the outputted data.
283 * https://en.wikipedia.org/wiki/Berkeley_Packet_Filter[eBPF] is a
284 subsystem in the Linux kernel in which a virtual machine can execute
285 programs passed from the user space to the kernel. You can attach
286 such programs to tracepoints and kprobes thanks to a system call, and
287 they can output data to the user space when executed thanks to
288 different mechanisms (pipe, VM register values, and eBPF maps, to name
290 * https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace]
291 is the de facto function tracer of the Linux kernel. Its user
292 interface is a set of special files in sysfs.
293 * https://perf.wiki.kernel.org/[perf] is
294 a performance analyzing tool for Linux which supports hardware
295 performance counters, tracepoints, as well as other counters and
296 types of probes. perf's controlling utility is the cmd:perf command
298 * http://linux.die.net/man/1/strace[strace]
299 is a command-line utility which records system calls made by a
300 user process, as well as signal deliveries and changes of process
301 state. strace makes use of https://en.wikipedia.org/wiki/Ptrace[ptrace]
302 to fulfill its function.
303 * http://www.sysdig.org/[sysdig], like SystemTap, uses scripts to
304 analyze Linux kernel events. You write scripts, or _chisels_ in
305 sysdig's jargon, in Lua and sysdig executes them while it traces the
306 system or afterwards. sysdig's interface is the cmd:sysdig
307 command-line tool as well as the curses-based cmd:csysdig tool.
308 * https://sourceware.org/systemtap/[SystemTap] is a Linux kernel and
309 user space tracer which uses custom user scripts to produce plain text
310 traces. SystemTap converts the scripts to the C language, and then
311 compiles them as Linux kernel modules which are loaded to produce
312 trace data. SystemTap's primary user interface is the cmd:stap
315 The main distinctive features of LTTng is that it produces correlated
316 kernel and user space traces, as well as doing so with the lowest
317 overhead amongst other solutions. It produces trace files in the
318 http://diamon.org/ctf[CTF] format, a file format optimized
319 for the production and analyses of multi-gigabyte data.
321 LTTng is the result of more than 10{nbsp}years of active open source
322 development by a community of passionate developers.
323 LTTng{nbsp}{revision} is currently available on major desktop and server
326 The main interface for tracing control is a single command-line tool
327 named cmd:lttng. The latter can create several tracing sessions, enable
328 and disable events on the fly, filter events efficiently with custom
329 user expressions, start and stop tracing, and much more. LTTng can
330 record the traces on the file system or send them over the network, and
331 keep them totally or partially. You can view the traces once tracing
332 becomes inactive or in real-time.
334 <<installing-lttng,Install LTTng now>> and
335 <<getting-started,start tracing>>!
341 **LTTng** is a set of software <<plumbing,components>> which interact to
342 <<instrumenting,instrument>> the Linux kernel and user applications, and
343 to <<controlling-tracing,control tracing>> (start and stop
344 tracing, enable and disable event rules, and the rest). Those
345 components are bundled into the following packages:
347 * **LTTng-tools**: Libraries and command-line interface to
349 * **LTTng-modules**: Linux kernel modules to instrument and
351 * **LTTng-UST**: Libraries and Java/Python packages to instrument and
352 trace user applications.
354 Most distributions mark the LTTng-modules and LTTng-UST packages as
355 optional when installing LTTng-tools (which is always required). In the
356 following sections, we always provide the steps to install all three,
359 * You only need to install LTTng-modules if you intend to trace the
361 * You only need to install LTTng-UST if you intend to trace user
365 .Availability of LTTng{nbsp}{revision} for major Linux distributions as of 12 November 2018.
367 |Distribution |Available in releases |Alternatives
369 |https://www.ubuntu.com/[Ubuntu]
370 |Ubuntu{nbsp}14.04 _Trusty Tahr_, Ubuntu{nbsp}16.04 _Xenial Xerus_,
371 and Ubuntu{nbsp}18.04 _Bionic Beaver_:
372 <<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>.
373 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
375 |https://getfedora.org/[Fedora]
378 link:/docs/v2.10#doc-fedora[LTTng{nbsp}2.10 for Fedora{nbsp}27,
379 Fedora{nbsp}28, and Fedora{nbsp}29].
381 <<building-from-source,Build LTTng{nbsp}{revision} from source>>.
383 |https://www.debian.org/[Debian]
385 |link:/docs/v2.10#doc-debian[LTTng{nbsp}2.10 for Debian "buster" (testing)].
387 <<building-from-source,Build LTTng{nbsp}{revision} from source>>.
389 |https://www.archlinux.org/[Arch Linux]
391 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
393 |https://alpinelinux.org/[Alpine Linux]
396 link:/docs/v2.10#doc-alpine-linux[LTTng{nbsp}2.10 for
397 Alpine Linux{nbsp}3.7 and Alpine Linux{nbsp}3.8].
399 <<building-from-source,Build LTTng{nbsp}{revision} from source>>.
401 |https://www.opensuse.org/[openSUSE]
403 |link:/docs/v2.10#doc-opensuse[LTTng{nbsp}2.10 for openSUSE Leap{nbsp}15.0].
405 <<building-from-source,Build LTTng{nbsp}{revision} from source>>.
407 |https://www.redhat.com/[RHEL] and https://www.suse.com/[SLES]
408 |See http://packages.efficios.com/[EfficiOS Enterprise Packages].
411 |https://buildroot.org/[Buildroot]
414 link:/docs/v2.10#doc-buildroot[LTTng{nbsp}2.10 for Buildroot{nbsp}2018.02,
415 Buildroot{nbsp}2018.05, Buildroot{nbsp}2018.08, and Buildroot{nbsp}2018.11].
417 <<building-from-source,Build LTTng{nbsp}{revision} from source>>.
419 |http://www.openembedded.org/wiki/Main_Page[OpenEmbedded] and
420 https://www.yoctoproject.org/[Yocto]
422 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
427 === Ubuntu: noch:{LTTng} Stable {revision} PPA
429 The https://launchpad.net/~lttng/+archive/ubuntu/stable-{revision}[LTTng
430 Stable{nbsp}{revision} PPA] offers the latest stable
431 LTTng{nbsp}{revision} packages for:
433 * Ubuntu{nbsp}14.04 _Trusty Tahr_
434 * Ubuntu{nbsp}16.04 _Xenial Xerus_
435 * Ubuntu{nbsp}18.04 _Bionic Beaver_
437 To install LTTng{nbsp}{revision} from the LTTng Stable{nbsp}{revision} PPA:
439 . Add the LTTng Stable{nbsp}{revision} PPA repository and update the
445 # apt-add-repository ppa:lttng/stable-2.11
450 . Install the main LTTng{nbsp}{revision} packages:
455 # apt-get install lttng-tools
456 # apt-get install lttng-modules-dkms
457 # apt-get install liblttng-ust-dev
461 . **If you need to instrument and trace
462 <<java-application,Java applications>>**, install the LTTng-UST
468 # apt-get install liblttng-ust-agent-java
472 . **If you need to instrument and trace
473 <<python-application,Python{nbsp}3 applications>>**, install the
474 LTTng-UST Python agent:
479 # apt-get install python3-lttngust
484 [[enterprise-distributions]]
485 === RHEL, SUSE, and other enterprise distributions
487 To install LTTng on enterprise Linux distributions, such as Red Hat
488 Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SUSE), please
489 see http://packages.efficios.com/[EfficiOS Enterprise Packages].
492 [[building-from-source]]
493 === Build from source
495 To build and install LTTng{nbsp}{revision} from source:
497 . Using your distribution's package manager, or from source, install
498 the following dependencies of LTTng-tools and LTTng-UST:
501 * https://sourceforge.net/projects/libuuid/[libuuid]
502 * http://directory.fsf.org/wiki/Popt[popt]
503 * http://liburcu.org/[Userspace RCU]
504 * http://www.xmlsoft.org/[libxml2]
505 * **Optional**: https://github.com/numactl/numactl[numactl]
508 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
514 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.11.tar.bz2 &&
515 tar -xf lttng-modules-latest-2.11.tar.bz2 &&
516 cd lttng-modules-2.11.* &&
518 sudo make modules_install &&
523 . Download, build, and install the latest LTTng-UST{nbsp}{revision}:
529 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.11.tar.bz2 &&
530 tar -xf lttng-ust-latest-2.11.tar.bz2 &&
531 cd lttng-ust-2.11.* &&
539 Add `--disable-numa` to `./configure` if you don't have
540 https://github.com/numactl/numactl[numactl].
544 .Java and Python application tracing
546 If you need to instrument and trace <<java-application,Java
547 applications>>, pass the `--enable-java-agent-jul`,
548 `--enable-java-agent-log4j`, or `--enable-java-agent-all` options to the
549 `configure` script, depending on which Java logging framework you use.
551 If you need to instrument and trace <<python-application,Python
552 applications>>, pass the `--enable-python-agent` option to the
553 `configure` script. You can set the `PYTHON` environment variable to the
554 path to the Python interpreter for which to install the LTTng-UST Python
562 By default, LTTng-UST libraries are installed to
563 dir:{/usr/local/lib}, which is the de facto directory in which to
564 keep self-compiled and third-party libraries.
566 When <<building-tracepoint-providers-and-user-application,linking an
567 instrumented user application with `liblttng-ust`>>:
569 * Append `/usr/local/lib` to the env:LD_LIBRARY_PATH environment
571 * Pass the `-L/usr/local/lib` and `-Wl,-rpath,/usr/local/lib` options to
572 man:gcc(1), man:g++(1), or man:clang(1).
576 . Download, build, and install the latest LTTng-tools{nbsp}{revision}:
582 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.11.tar.bz2 &&
583 tar -xf lttng-tools-latest-2.11.tar.bz2 &&
584 cd lttng-tools-2.11.* &&
592 TIP: The https://github.com/eepp/vlttng[vlttng tool] can do all the
593 previous steps automatically for a given version of LTTng and confine
594 the installed files in a specific directory. This can be useful to test
595 LTTng without installing it on your system.
601 This is a short guide to get started quickly with LTTng kernel and user
604 Before you follow this guide, make sure to <<installing-lttng,install>>
607 This tutorial walks you through the steps to:
609 . <<tracing-the-linux-kernel,Trace the Linux kernel>>.
610 . <<tracing-your-own-user-application,Trace a user application>> written
612 . <<viewing-and-analyzing-your-traces,View and analyze the
616 [[tracing-the-linux-kernel]]
617 === Trace the Linux kernel
619 The following command lines start with the `#` prompt because you need
620 root privileges to trace the Linux kernel. You can also trace the kernel
621 as a regular user if your Unix user is a member of the
622 <<tracing-group,tracing group>>.
624 . Create a <<tracing-session,tracing session>> which writes its traces
625 to dir:{/tmp/my-kernel-trace}:
630 # lttng create my-kernel-session --output=/tmp/my-kernel-trace
634 . List the available kernel tracepoints and system calls:
639 # lttng list --kernel
640 # lttng list --kernel --syscall
644 . Create <<event,event rules>> which match the desired instrumentation
645 point names, for example the `sched_switch` and `sched_process_fork`
646 tracepoints, and the man:open(2) and man:close(2) system calls:
651 # lttng enable-event --kernel sched_switch,sched_process_fork
652 # lttng enable-event --kernel --syscall open,close
656 You can also create an event rule which matches _all_ the Linux kernel
657 tracepoints (this will generate a lot of data when tracing):
662 # lttng enable-event --kernel --all
666 . <<basic-tracing-session-control,Start tracing>>:
675 . Do some operation on your system for a few seconds. For example,
676 load a website, or list the files of a directory.
677 . <<creating-destroying-tracing-sessions,Destroy>> the current
687 The man:lttng-destroy(1) command does not destroy the trace data; it
688 only destroys the state of the tracing session.
690 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
691 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
692 session>>). You need to stop tracing to make LTTng flush the remaining
693 trace data and make the trace readable.
695 . For the sake of this example, make the recorded trace accessible to
701 # chown -R $(whoami) /tmp/my-kernel-trace
705 See <<viewing-and-analyzing-your-traces,View and analyze the
706 recorded events>> to view the recorded events.
709 [[tracing-your-own-user-application]]
710 === Trace a user application
712 This section steps you through a simple example to trace a
713 _Hello world_ program written in C.
715 To create the traceable user application:
717 . Create the tracepoint provider header file, which defines the
718 tracepoints and the events they can generate:
724 #undef TRACEPOINT_PROVIDER
725 #define TRACEPOINT_PROVIDER hello_world
727 #undef TRACEPOINT_INCLUDE
728 #define TRACEPOINT_INCLUDE "./hello-tp.h"
730 #if !defined(_HELLO_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
733 #include <lttng/tracepoint.h>
743 ctf_string(my_string_field, my_string_arg)
744 ctf_integer(int, my_integer_field, my_integer_arg)
748 #endif /* _HELLO_TP_H */
750 #include <lttng/tracepoint-event.h>
754 . Create the tracepoint provider package source file:
760 #define TRACEPOINT_CREATE_PROBES
761 #define TRACEPOINT_DEFINE
763 #include "hello-tp.h"
767 . Build the tracepoint provider package:
772 $ gcc -c -I. hello-tp.c
776 . Create the _Hello World_ application source file:
783 #include "hello-tp.h"
785 int main(int argc, char *argv[])
789 puts("Hello, World!\nPress Enter to continue...");
792 * The following getchar() call is only placed here for the purpose
793 * of this demonstration, to pause the application in order for
794 * you to have time to list its tracepoints. It is not
800 * A tracepoint() call.
802 * Arguments, as defined in hello-tp.h:
804 * 1. Tracepoint provider name (required)
805 * 2. Tracepoint name (required)
806 * 3. my_integer_arg (first user-defined argument)
807 * 4. my_string_arg (second user-defined argument)
809 * Notice the tracepoint provider and tracepoint names are
810 * NOT strings: they are in fact parts of variables that the
811 * macros in hello-tp.h create.
813 tracepoint(hello_world, my_first_tracepoint, 23, "hi there!");
815 for (x = 0; x < argc; ++x) {
816 tracepoint(hello_world, my_first_tracepoint, x, argv[x]);
819 puts("Quitting now!");
820 tracepoint(hello_world, my_first_tracepoint, x * x, "x^2");
827 . Build the application:
836 . Link the application with the tracepoint provider package,
837 `liblttng-ust`, and `libdl`:
842 $ gcc -o hello hello.o hello-tp.o -llttng-ust -ldl
846 Here's the whole build process:
849 .User space tracing tutorial's build steps.
850 image::ust-flow.png[]
852 To trace the user application:
854 . Run the application with a few arguments:
859 $ ./hello world and beyond
868 Press Enter to continue...
872 . Start an LTTng <<lttng-sessiond,session daemon>>:
877 $ lttng-sessiond --daemonize
881 Note that a session daemon might already be running, for example as
882 a service that the distribution's service manager started.
884 . List the available user space tracepoints:
889 $ lttng list --userspace
893 You see the `hello_world:my_first_tracepoint` tracepoint listed
894 under the `./hello` process.
896 . Create a <<tracing-session,tracing session>>:
901 $ lttng create my-user-space-session
905 . Create an <<event,event rule>> which matches the
906 `hello_world:my_first_tracepoint` event name:
911 $ lttng enable-event --userspace hello_world:my_first_tracepoint
915 . <<basic-tracing-session-control,Start tracing>>:
924 . Go back to the running `hello` application and press Enter. The
925 program executes all `tracepoint()` instrumentation points and exits.
926 . <<creating-destroying-tracing-sessions,Destroy>> the current
936 The man:lttng-destroy(1) command does not destroy the trace data; it
937 only destroys the state of the tracing session.
939 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
940 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
941 session>>). You need to stop tracing to make LTTng flush the remaining
942 trace data and make the trace readable.
944 By default, LTTng saves the traces in
945 +$LTTNG_HOME/lttng-traces/__name__-__date__-__time__+,
946 where +__name__+ is the tracing session name. The
947 env:LTTNG_HOME environment variable defaults to `$HOME` if not set.
949 See <<viewing-and-analyzing-your-traces,View and analyze the
950 recorded events>> to view the recorded events.
953 [[viewing-and-analyzing-your-traces]]
954 === View and analyze the recorded events
956 Once you have completed the <<tracing-the-linux-kernel,Trace the Linux
957 kernel>> and <<tracing-your-own-user-application,Trace a user
958 application>> tutorials, you can inspect the recorded events.
960 Many tools are available to read LTTng traces:
962 * **cmd:babeltrace** is a command-line utility which converts trace
963 formats; it supports the format that LTTng produces, CTF, as well as a
964 basic text output which can be ++grep++ed. The cmd:babeltrace command
965 is part of the http://diamon.org/babeltrace[Babeltrace] project.
966 * Babeltrace also includes
967 **https://www.python.org/[Python] bindings** so
968 that you can easily open and read an LTTng trace with your own script,
969 benefiting from the power of Python.
970 * http://tracecompass.org/[**Trace Compass**]
971 is a graphical user interface for viewing and analyzing any type of
972 logs or traces, including LTTng's.
973 * https://github.com/lttng/lttng-analyses[**LTTng analyses**] is a
974 project which includes many high-level analyses of LTTng kernel
975 traces, like scheduling statistics, interrupt frequency distribution,
976 top CPU usage, and more.
978 NOTE: This section assumes that LTTng saved the traces it recorded
979 during the previous tutorials to their default location, in the
980 dir:{$LTTNG_HOME/lttng-traces} directory. The env:LTTNG_HOME
981 environment variable defaults to `$HOME` if not set.
984 [[viewing-and-analyzing-your-traces-bt]]
985 ==== Use the cmd:babeltrace command-line tool
987 The simplest way to list all the recorded events of a trace is to pass
988 its path to cmd:babeltrace with no options:
992 $ babeltrace ~/lttng-traces/my-user-space-session*
995 cmd:babeltrace finds all traces recursively within the given path and
996 prints all their events, merging them in chronological order.
998 You can pipe the output of cmd:babeltrace into a tool like man:grep(1) for
1003 $ babeltrace /tmp/my-kernel-trace | grep _switch
1006 You can pipe the output of cmd:babeltrace into a tool like man:wc(1) to
1007 count the recorded events:
1011 $ babeltrace /tmp/my-kernel-trace | grep _open | wc --lines
1015 [[viewing-and-analyzing-your-traces-bt-python]]
1016 ==== Use the Babeltrace Python bindings
1018 The <<viewing-and-analyzing-your-traces-bt,text output of cmd:babeltrace>>
1019 is useful to isolate events by simple matching using man:grep(1) and
1020 similar utilities. However, more elaborate filters, such as keeping only
1021 event records with a field value falling within a specific range, are
1022 not trivial to write using a shell. Moreover, reductions and even the
1023 most basic computations involving multiple event records are virtually
1024 impossible to implement.
1026 Fortunately, Babeltrace ships with Python{nbsp}3 bindings which makes it
1027 easy to read the event records of an LTTng trace sequentially and
1028 compute the desired information.
1030 The following script accepts an LTTng Linux kernel trace path as its
1031 first argument and prints the short names of the top five running
1032 processes on CPU{nbsp}0 during the whole trace:
1037 from collections import Counter
1043 if len(sys.argv) != 2:
1044 msg = 'Usage: python3 {} TRACEPATH'.format(sys.argv[0])
1045 print(msg, file=sys.stderr)
1048 # A trace collection contains one or more traces
1049 col = babeltrace.TraceCollection()
1051 # Add the trace provided by the user (LTTng traces always have
1053 if col.add_trace(sys.argv[1], 'ctf') is None:
1054 raise RuntimeError('Cannot add trace')
1056 # This counter dict contains execution times:
1058 # task command name -> total execution time (ns)
1059 exec_times = Counter()
1061 # This contains the last `sched_switch` timestamp
1065 for event in col.events:
1066 # Keep only `sched_switch` events
1067 if event.name != 'sched_switch':
1070 # Keep only events which happened on CPU 0
1071 if event['cpu_id'] != 0:
1075 cur_ts = event.timestamp
1081 # Previous task command (short) name
1082 prev_comm = event['prev_comm']
1084 # Initialize entry in our dict if not yet done
1085 if prev_comm not in exec_times:
1086 exec_times[prev_comm] = 0
1088 # Compute previous command execution time
1089 diff = cur_ts - last_ts
1091 # Update execution time of this command
1092 exec_times[prev_comm] += diff
1094 # Update last timestamp
1098 for name, ns in exec_times.most_common(5):
1100 print('{:20}{} s'.format(name, s))
1105 if __name__ == '__main__':
1106 sys.exit(0 if top5proc() else 1)
1113 $ python3 top5proc.py /tmp/my-kernel-trace/kernel
1119 swapper/0 48.607245889 s
1120 chromium 7.192738188 s
1121 pavucontrol 0.709894415 s
1122 Compositor 0.660867933 s
1123 Xorg.bin 0.616753786 s
1126 Note that `swapper/0` is the "idle" process of CPU{nbsp}0 on Linux;
1127 since we weren't using the CPU that much when tracing, its first
1128 position in the list makes sense.
1132 == [[understanding-lttng]]Core concepts
1134 From a user's perspective, the LTTng system is built on a few concepts,
1135 or objects, on which the <<lttng-cli,cmd:lttng command-line tool>>
1136 operates by sending commands to the <<lttng-sessiond,session daemon>>.
1137 Understanding how those objects relate to eachother is key in mastering
1140 The core concepts are:
1142 * <<tracing-session,Tracing session>>
1143 * <<domain,Tracing domain>>
1144 * <<channel,Channel and ring buffer>>
1145 * <<"event","Instrumentation point, event rule, event, and event record">>
1151 A _tracing session_ is a stateful dialogue between you and
1152 a <<lttng-sessiond,session daemon>>. You can
1153 <<creating-destroying-tracing-sessions,create a new tracing
1154 session>> with the `lttng create` command.
1156 Anything that you do when you control LTTng tracers happens within a
1157 tracing session. In particular, a tracing session:
1160 * Has its own set of trace files.
1161 * Has its own state of activity (started or stopped).
1162 * Has its own <<tracing-session-mode,mode>> (local, network streaming,
1164 * Has its own <<channel,channels>> to which are associated their own
1165 <<event,event rules>>.
1168 .A _tracing session_ contains <<channel,channels>> that are members of <<domain,tracing domains>> and contain <<event,event rules>>.
1169 image::concepts.png[]
1171 Those attributes and objects are completely isolated between different
1174 A tracing session is analogous to a cash machine session:
1175 the operations you do on the banking system through the cash machine do
1176 not alter the data of other users of the same system. In the case of
1177 the cash machine, a session lasts as long as your bank card is inside.
1178 In the case of LTTng, a tracing session lasts from the `lttng create`
1179 command to the `lttng destroy` command.
1182 .Each Unix user has its own set of tracing sessions.
1183 image::many-sessions.png[]
1186 [[tracing-session-mode]]
1187 ==== Tracing session mode
1189 LTTng can send the generated trace data to different locations. The
1190 _tracing session mode_ dictates where to send it. The following modes
1191 are available in LTTng{nbsp}{revision}:
1194 LTTng writes the traces to the file system of the machine it traces
1197 Network streaming mode::
1198 LTTng sends the traces over the network to a
1199 <<lttng-relayd,relay daemon>> running on a remote system.
1202 LTTng does not write the traces by default. Instead, you can request
1203 LTTng to <<taking-a-snapshot,take a snapshot>>, that is, a copy of the
1204 tracing session's current sub-buffers, and to write it to the
1205 target's file system or to send it over the network to a
1206 <<lttng-relayd,relay daemon>> running on a remote system.
1209 This mode is similar to the network streaming mode, but a live
1210 trace viewer can connect to the distant relay daemon to
1211 <<lttng-live,view event records as LTTng generates them>>.
1217 A _tracing domain_ is a namespace for event sources. A tracing domain
1218 has its own properties and features.
1220 There are currently five available tracing domains:
1224 * `java.util.logging` (JUL)
1228 You must specify a tracing domain when using some commands to avoid
1229 ambiguity. For example, since all the domains support named tracepoints
1230 as event sources (instrumentation points that you manually insert in the
1231 source code), you need to specify a tracing domain when
1232 <<enabling-disabling-events,creating an event rule>> because all the
1233 tracing domains could have tracepoints with the same names.
1235 Some features are reserved to specific tracing domains. Dynamic function
1236 entry and return instrumentation points, for example, are currently only
1237 supported in the Linux kernel tracing domain, but support for other
1238 tracing domains could be added in the future.
1240 You can create <<channel,channels>> in the Linux kernel and user space
1241 tracing domains. The other tracing domains have a single default
1246 === Channel and ring buffer
1248 A _channel_ is an object which is responsible for a set of ring buffers.
1249 Each ring buffer is divided into multiple sub-buffers. When an LTTng
1250 tracer emits an event, it can record it to one or more
1251 sub-buffers. The attributes of a channel determine what to do when
1252 there's no space left for a new event record because all sub-buffers
1253 are full, where to send a full sub-buffer, and other behaviours.
1255 A channel is always associated to a <<domain,tracing domain>>. The
1256 `java.util.logging` (JUL), log4j, and Python tracing domains each have
1257 a default channel which you cannot configure.
1259 A channel also owns <<event,event rules>>. When an LTTng tracer emits
1260 an event, it records it to the sub-buffers of all
1261 the enabled channels with a satisfied event rule, as long as those
1262 channels are part of active <<tracing-session,tracing sessions>>.
1265 [[channel-buffering-schemes]]
1266 ==== Per-user vs. per-process buffering schemes
1268 A channel has at least one ring buffer _per CPU_. LTTng always
1269 records an event to the ring buffer associated to the CPU on which it
1272 Two _buffering schemes_ are available when you
1273 <<enabling-disabling-channels,create a channel>> in the
1274 user space <<domain,tracing domain>>:
1276 Per-user buffering::
1277 Allocate one set of ring buffers--one per CPU--shared by all the
1278 instrumented processes of each Unix user.
1282 .Per-user buffering scheme.
1283 image::per-user-buffering.png[]
1286 Per-process buffering::
1287 Allocate one set of ring buffers--one per CPU--for each
1288 instrumented process.
1292 .Per-process buffering scheme.
1293 image::per-process-buffering.png[]
1296 The per-process buffering scheme tends to consume more memory than the
1297 per-user option because systems generally have more instrumented
1298 processes than Unix users running instrumented processes. However, the
1299 per-process buffering scheme ensures that one process having a high
1300 event throughput won't fill all the shared sub-buffers of the same
1303 The Linux kernel tracing domain has only one available buffering scheme
1304 which is to allocate a single set of ring buffers for the whole system.
1305 This scheme is similar to the per-user option, but with a single, global
1306 user "running" the kernel.
1309 [[channel-overwrite-mode-vs-discard-mode]]
1310 ==== Overwrite vs. discard event record loss modes
1312 When an event occurs, LTTng records it to a specific sub-buffer (yellow
1313 arc in the following animations) of a specific channel's ring buffer.
1314 When there's no space left in a sub-buffer, the tracer marks it as
1315 consumable (red) and another, empty sub-buffer starts receiving the
1316 following event records. A <<lttng-consumerd,consumer daemon>>
1317 eventually consumes the marked sub-buffer (returns to white).
1320 [role="docsvg-channel-subbuf-anim"]
1325 In an ideal world, sub-buffers are consumed faster than they are filled,
1326 as it is the case in the previous animation. In the real world,
1327 however, all sub-buffers can be full at some point, leaving no space to
1328 record the following events.
1330 By default, LTTng-modules and LTTng-UST are _non-blocking_ tracers: when
1331 no empty sub-buffer is available, it is acceptable to lose event records
1332 when the alternative would be to cause substantial delays in the
1333 instrumented application's execution. LTTng privileges performance over
1334 integrity; it aims at perturbing the target system as little as possible
1335 in order to make tracing of subtle race conditions and rare interrupt
1338 Since LTTng{nbsp}2.10, the LTTng user space tracer, LTTng-UST, supports
1339 a _blocking mode_. See the <<blocking-timeout-example,blocking timeout
1340 example>> to learn how to use the blocking mode.
1342 When it comes to losing event records because no empty sub-buffer is
1343 available, or because the <<opt-blocking-timeout,blocking timeout>> is
1344 reached, the channel's _event record loss mode_ determines what to do.
1345 The available event record loss modes are:
1348 Drop the newest event records until a the tracer releases a
1351 This is the only available mode when you specify a
1352 <<opt-blocking-timeout,blocking timeout>>.
1355 Clear the sub-buffer containing the oldest event records and start
1356 writing the newest event records there.
1358 This mode is sometimes called _flight recorder mode_ because it's
1360 https://en.wikipedia.org/wiki/Flight_recorder[flight recorder]:
1361 always keep a fixed amount of the latest data.
1363 Which mechanism you should choose depends on your context: prioritize
1364 the newest or the oldest event records in the ring buffer?
1366 Beware that, in overwrite mode, the tracer abandons a _whole sub-buffer_
1367 as soon as a there's no space left for a new event record, whereas in
1368 discard mode, the tracer only discards the event record that doesn't
1371 In discard mode, LTTng increments a count of lost event records when an
1372 event record is lost and saves this count to the trace. In overwrite
1373 mode, since LTTng{nbsp}2.8, LTTng increments a count of lost sub-buffers
1374 when a sub-buffer is lost and saves this count to the trace. In this
1375 mode, LTTng does not write to the trace the exact number of lost event
1376 records in those lost sub-buffers. Trace analyses can use the trace's
1377 saved discarded event record and sub-buffer counts to decide whether or
1378 not to perform the analyses even if trace data is known to be missing.
1380 There are a few ways to decrease your probability of losing event
1382 <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>> shows
1383 how you can fine-tune the sub-buffer count and size of a channel to
1384 virtually stop losing event records, though at the cost of greater
1388 [[channel-subbuf-size-vs-subbuf-count]]
1389 ==== Sub-buffer count and size
1391 When you <<enabling-disabling-channels,create a channel>>, you can
1392 set its number of sub-buffers and their size.
1394 Note that there is noticeable CPU overhead introduced when
1395 switching sub-buffers (marking a full one as consumable and switching
1396 to an empty one for the following events to be recorded). Knowing this,
1397 the following list presents a few practical situations along with how
1398 to configure the sub-buffer count and size for them:
1400 * **High event throughput**: In general, prefer bigger sub-buffers to
1401 lower the risk of losing event records.
1403 Having bigger sub-buffers also ensures a lower
1404 <<channel-switch-timer,sub-buffer switching frequency>>.
1406 The number of sub-buffers is only meaningful if you create the channel
1407 in overwrite mode: in this case, if a sub-buffer overwrite happens, the
1408 other sub-buffers are left unaltered.
1410 * **Low event throughput**: In general, prefer smaller sub-buffers
1411 since the risk of losing event records is low.
1413 Because events occur less frequently, the sub-buffer switching frequency
1414 should remain low and thus the tracer's overhead should not be a
1417 * **Low memory system**: If your target system has a low memory
1418 limit, prefer fewer first, then smaller sub-buffers.
1420 Even if the system is limited in memory, you want to keep the
1421 sub-buffers as big as possible to avoid a high sub-buffer switching
1424 Note that LTTng uses http://diamon.org/ctf/[CTF] as its trace format,
1425 which means event data is very compact. For example, the average
1426 LTTng kernel event record weights about 32{nbsp}bytes. Thus, a
1427 sub-buffer size of 1{nbsp}MiB is considered big.
1429 The previous situations highlight the major trade-off between a few big
1430 sub-buffers and more, smaller sub-buffers: sub-buffer switching
1431 frequency vs. how much data is lost in overwrite mode. Assuming a
1432 constant event throughput and using the overwrite mode, the two
1433 following configurations have the same ring buffer total size:
1436 [role="docsvg-channel-subbuf-size-vs-count-anim"]
1441 * **Two sub-buffers of 4{nbsp}MiB each**: Expect a very low sub-buffer
1442 switching frequency, but if a sub-buffer overwrite happens, half of
1443 the event records so far (4{nbsp}MiB) are definitely lost.
1444 * **Eight sub-buffers of 1{nbsp}MiB each**: Expect four times the tracer's
1445 overhead as the previous configuration, but if a sub-buffer
1446 overwrite happens, only the eighth of event records so far are
1449 In discard mode, the sub-buffers count parameter is pointless: use two
1450 sub-buffers and set their size according to the requirements of your
1454 [[channel-switch-timer]]
1455 ==== Switch timer period
1457 The _switch timer period_ is an important configurable attribute of
1458 a channel to ensure periodic sub-buffer flushing.
1460 When the _switch timer_ expires, a sub-buffer switch happens. You can
1461 set the switch timer period attribute when you
1462 <<enabling-disabling-channels,create a channel>> to ensure that LTTng
1463 consumes and commits trace data to trace files or to a distant relay
1464 daemon periodically in case of a low event throughput.
1467 [role="docsvg-channel-switch-timer"]
1472 This attribute is also convenient when you use big sub-buffers to cope
1473 with a sporadic high event throughput, even if the throughput is
1477 [[channel-read-timer]]
1478 ==== Read timer period
1480 By default, the LTTng tracers use a notification mechanism to signal a
1481 full sub-buffer so that a consumer daemon can consume it. When such
1482 notifications must be avoided, for example in real-time applications,
1483 you can use the channel's _read timer_ instead. When the read timer
1484 fires, the <<lttng-consumerd,consumer daemon>> checks for full,
1485 consumable sub-buffers.
1488 [[tracefile-rotation]]
1489 ==== Trace file count and size
1491 By default, trace files can grow as large as needed. You can set the
1492 maximum size of each trace file that a channel writes when you
1493 <<enabling-disabling-channels,create a channel>>. When the size of
1494 a trace file reaches the channel's fixed maximum size, LTTng creates
1495 another file to contain the next event records. LTTng appends a file
1496 count to each trace file name in this case.
1498 If you set the trace file size attribute when you create a channel, the
1499 maximum number of trace files that LTTng creates is _unlimited_ by
1500 default. To limit them, you can also set a maximum number of trace
1501 files. When the number of trace files reaches the channel's fixed
1502 maximum count, the oldest trace file is overwritten. This mechanism is
1503 called _trace file rotation_.
1505 Even if you don't limit the trace file count, you cannot assume that
1506 LTTng doesn't manage any trace file. In other words, there is no safe
1507 way to know if LTTng still holds a given trace file open with the trace
1508 file rotation feature. The only way to obtain an unmanaged,
1509 self-contained LTTng trace before you
1510 <<creating-destroying-tracing-sessions,destroy>> the tracing session is
1511 with the <<session-rotation,tracing session rotation>> feature
1512 (available since LTTng{nbsp}2.11).
1516 === Instrumentation point, event rule, event, and event record
1518 An _event rule_ is a set of conditions which must be **all** satisfied
1519 for LTTng to record an occuring event.
1521 You set the conditions when you <<enabling-disabling-events,create
1524 You always attach an event rule to <<channel,channel>> when you create
1527 When an event passes the conditions of an event rule, LTTng records it
1528 in one of the attached channel's sub-buffers.
1530 The available conditions, as of LTTng{nbsp}{revision}, are:
1532 * The event rule _is enabled_.
1533 * The instrumentation point's type _is{nbsp}T_.
1534 * The instrumentation point's name (sometimes called _event name_)
1535 _matches{nbsp}N_, but _is not{nbsp}E_.
1536 * The instrumentation point's log level _is as severe as{nbsp}L_, or
1537 _is exactly{nbsp}L_.
1538 * The fields of the event's payload _satisfy_ a filter
1539 expression{nbsp}__F__.
1541 As you can see, all the conditions but the dynamic filter are related to
1542 the event rule's status or to the instrumentation point, not to the
1543 occurring events. This is why, without a filter, checking if an event
1544 passes an event rule is not a dynamic task: when you create or modify an
1545 event rule, all the tracers of its tracing domain enable or disable the
1546 instrumentation points themselves once. This is possible because the
1547 attributes of an instrumentation point (type, name, and log level) are
1548 defined statically. In other words, without a dynamic filter, the tracer
1549 _does not evaluate_ the arguments of an instrumentation point unless it
1550 matches an enabled event rule.
1552 Note that, for LTTng to record an event, the <<channel,channel>> to
1553 which a matching event rule is attached must also be enabled, and the
1554 <<tracing-session,tracing session>> owning this channel must be active
1558 .Logical path from an instrumentation point to an event record.
1559 image::event-rule.png[]
1561 .Event, event record, or event rule?
1563 With so many similar terms, it's easy to get confused.
1565 An **event** is the consequence of the execution of an _instrumentation
1566 point_, like a tracepoint that you manually place in some source code,
1567 or a Linux kernel kprobe. An event is said to _occur_ at a specific
1568 time. Different actions can be taken upon the occurrence of an event,
1569 like record the event's payload to a buffer.
1571 An **event record** is the representation of an event in a sub-buffer. A
1572 tracer is responsible for capturing the payload of an event, current
1573 context variables, the event's ID, and the event's timestamp. LTTng
1574 can append this sub-buffer to a trace file.
1576 An **event rule** is a set of conditions which must _all_ be satisfied
1577 for LTTng to record an occuring event. Events still occur without
1578 satisfying event rules, but LTTng does not record them.
1583 == Components of noch:{LTTng}
1585 The second _T_ in _LTTng_ stands for _toolkit_: it would be wrong
1586 to call LTTng a simple _tool_ since it is composed of multiple
1587 interacting components. This section describes those components,
1588 explains their respective roles, and shows how they connect together to
1589 form the LTTng ecosystem.
1591 The following diagram shows how the most important components of LTTng
1592 interact with user applications, the Linux kernel, and you:
1595 .Control and trace data paths between LTTng components.
1596 image::plumbing.png[]
1598 The LTTng project incorporates:
1600 * **LTTng-tools**: Libraries and command-line interface to
1601 control tracing sessions.
1602 ** <<lttng-sessiond,Session daemon>> (man:lttng-sessiond(8)).
1603 ** <<lttng-consumerd,Consumer daemon>> (cmd:lttng-consumerd).
1604 ** <<lttng-relayd,Relay daemon>> (man:lttng-relayd(8)).
1605 ** <<liblttng-ctl-lttng,Tracing control library>> (`liblttng-ctl`).
1606 ** <<lttng-cli,Tracing control command-line tool>> (man:lttng(1)).
1607 * **LTTng-UST**: Libraries and Java/Python packages to trace user
1609 ** <<lttng-ust,User space tracing library>> (`liblttng-ust`) and its
1610 headers to instrument and trace any native user application.
1611 ** <<prebuilt-ust-helpers,Preloadable user space tracing helpers>>:
1612 *** `liblttng-ust-libc-wrapper`
1613 *** `liblttng-ust-pthread-wrapper`
1614 *** `liblttng-ust-cyg-profile`
1615 *** `liblttng-ust-cyg-profile-fast`
1616 *** `liblttng-ust-dl`
1617 ** User space tracepoint provider source files generator command-line
1618 tool (man:lttng-gen-tp(1)).
1619 ** <<lttng-ust-agents,LTTng-UST Java agent>> to instrument and trace
1620 Java applications using `java.util.logging` or
1621 Apache log4j{nbsp}1.2 logging.
1622 ** <<lttng-ust-agents,LTTng-UST Python agent>> to instrument
1623 Python applications using the standard `logging` package.
1624 * **LTTng-modules**: <<lttng-modules,Linux kernel modules>> to trace
1626 ** LTTng kernel tracer module.
1627 ** Tracing ring buffer kernel modules.
1628 ** Probe kernel modules.
1629 ** LTTng logger kernel module.
1633 === Tracing control command-line interface
1636 .The tracing control command-line interface.
1637 image::plumbing-lttng-cli.png[]
1639 The _man:lttng(1) command-line tool_ is the standard user interface to
1640 control LTTng <<tracing-session,tracing sessions>>. The cmd:lttng tool
1641 is part of LTTng-tools.
1643 The cmd:lttng tool is linked with
1644 <<liblttng-ctl-lttng,`liblttng-ctl`>> to communicate with
1645 one or more <<lttng-sessiond,session daemons>> behind the scenes.
1647 The cmd:lttng tool has a Git-like interface:
1651 $ lttng <GENERAL OPTIONS> <COMMAND> <COMMAND OPTIONS>
1654 The <<controlling-tracing,Tracing control>> section explores the
1655 available features of LTTng using the cmd:lttng tool.
1658 [[liblttng-ctl-lttng]]
1659 === Tracing control library
1662 .The tracing control library.
1663 image::plumbing-liblttng-ctl.png[]
1665 The _LTTng control library_, `liblttng-ctl`, is used to communicate
1666 with a <<lttng-sessiond,session daemon>> using a C API that hides the
1667 underlying protocol's details. `liblttng-ctl` is part of LTTng-tools.
1669 The <<lttng-cli,cmd:lttng command-line tool>>
1670 is linked with `liblttng-ctl`.
1672 You can use `liblttng-ctl` in C or $$C++$$ source code by including its
1677 #include <lttng/lttng.h>
1680 Some objects are referenced by name (C string), such as tracing
1681 sessions, but most of them require to create a handle first using
1682 `lttng_create_handle()`.
1684 The best available developer documentation for `liblttng-ctl` is, as of
1685 LTTng{nbsp}{revision}, its installed header files. Every function and
1686 structure is thoroughly documented.
1690 === User space tracing library
1693 .The user space tracing library.
1694 image::plumbing-liblttng-ust.png[]
1696 The _user space tracing library_, `liblttng-ust` (see man:lttng-ust(3)),
1697 is the LTTng user space tracer. It receives commands from a
1698 <<lttng-sessiond,session daemon>>, for example to
1699 enable and disable specific instrumentation points, and writes event
1700 records to ring buffers shared with a
1701 <<lttng-consumerd,consumer daemon>>.
1702 `liblttng-ust` is part of LTTng-UST.
1704 Public C header files are installed beside `liblttng-ust` to
1705 instrument any <<c-application,C or $$C++$$ application>>.
1707 <<lttng-ust-agents,LTTng-UST agents>>, which are regular Java and Python
1708 packages, use their own library providing tracepoints which is
1709 linked with `liblttng-ust`.
1711 An application or library does not have to initialize `liblttng-ust`
1712 manually: its constructor does the necessary tasks to properly register
1713 to a session daemon. The initialization phase also enables the
1714 instrumentation points matching the <<event,event rules>> that you
1718 [[lttng-ust-agents]]
1719 === User space tracing agents
1722 .The user space tracing agents.
1723 image::plumbing-lttng-ust-agents.png[]
1725 The _LTTng-UST Java and Python agents_ are regular Java and Python
1726 packages which add LTTng tracing capabilities to the
1727 native logging frameworks. The LTTng-UST agents are part of LTTng-UST.
1729 In the case of Java, the
1730 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[`java.util.logging`
1731 core logging facilities] and
1732 https://logging.apache.org/log4j/1.2/[Apache log4j{nbsp}1.2] are supported.
1733 Note that Apache Log4{nbsp}2 is not supported.
1735 In the case of Python, the standard
1736 https://docs.python.org/3/library/logging.html[`logging`] package
1737 is supported. Both Python{nbsp}2 and Python{nbsp}3 modules can import the
1738 LTTng-UST Python agent package.
1740 The applications using the LTTng-UST agents are in the
1741 `java.util.logging` (JUL),
1742 log4j, and Python <<domain,tracing domains>>.
1744 Both agents use the same mechanism to trace the log statements. When an
1745 agent initializes, it creates a log handler that attaches to the root
1746 logger. The agent also registers to a <<lttng-sessiond,session daemon>>.
1747 When the application executes a log statement, the root logger passes it
1748 to the agent's log handler. The agent's log handler calls a native
1749 function in a tracepoint provider package shared library linked with
1750 <<lttng-ust,`liblttng-ust`>>, passing the formatted log message and
1751 other fields, like its logger name and its log level. This native
1752 function contains a user space instrumentation point, hence tracing the
1755 The log level condition of an
1756 <<event,event rule>> is considered when tracing
1757 a Java or a Python application, and it's compatible with the standard
1758 JUL, log4j, and Python log levels.
1762 === LTTng kernel modules
1765 .The LTTng kernel modules.
1766 image::plumbing-lttng-modules.png[]
1768 The _LTTng kernel modules_ are a set of Linux kernel modules
1769 which implement the kernel tracer of the LTTng project. The LTTng
1770 kernel modules are part of LTTng-modules.
1772 The LTTng kernel modules include:
1774 * A set of _probe_ modules.
1776 Each module attaches to a specific subsystem
1777 of the Linux kernel using its tracepoint instrument points. There are
1778 also modules to attach to the entry and return points of the Linux
1779 system call functions.
1781 * _Ring buffer_ modules.
1783 A ring buffer implementation is provided as kernel modules. The LTTng
1784 kernel tracer writes to the ring buffer; a
1785 <<lttng-consumerd,consumer daemon>> reads from the ring buffer.
1787 * The _LTTng kernel tracer_ module.
1788 * The _LTTng logger_ module.
1790 The LTTng logger module implements the special path:{/proc/lttng-logger}
1791 file so that any executable can generate LTTng events by opening and
1792 writing to this file.
1794 See <<proc-lttng-logger-abi,LTTng logger>>.
1796 Generally, you do not have to load the LTTng kernel modules manually
1797 (using man:modprobe(8), for example): a root <<lttng-sessiond,session
1798 daemon>> loads the necessary modules when starting. If you have extra
1799 probe modules, you can specify to load them to the session daemon on
1802 The LTTng kernel modules are installed in
1803 +/usr/lib/modules/__release__/extra+ by default, where +__release__+ is
1804 the kernel release (see `uname --kernel-release`).
1811 .The session daemon.
1812 image::plumbing-sessiond.png[]
1814 The _session daemon_, man:lttng-sessiond(8), is a daemon responsible for
1815 managing tracing sessions and for controlling the various components of
1816 LTTng. The session daemon is part of LTTng-tools.
1818 The session daemon sends control requests to and receives control
1821 * The <<lttng-ust,user space tracing library>>.
1823 Any instance of the user space tracing library first registers to
1824 a session daemon. Then, the session daemon can send requests to
1825 this instance, such as:
1828 ** Get the list of tracepoints.
1829 ** Share an <<event,event rule>> so that the user space tracing library
1830 can enable or disable tracepoints. Amongst the possible conditions
1831 of an event rule is a filter expression which `liblttng-ust` evalutes
1832 when an event occurs.
1833 ** Share <<channel,channel>> attributes and ring buffer locations.
1836 The session daemon and the user space tracing library use a Unix
1837 domain socket for their communication.
1839 * The <<lttng-ust-agents,user space tracing agents>>.
1841 Any instance of a user space tracing agent first registers to
1842 a session daemon. Then, the session daemon can send requests to
1843 this instance, such as:
1846 ** Get the list of loggers.
1847 ** Enable or disable a specific logger.
1850 The session daemon and the user space tracing agent use a TCP connection
1851 for their communication.
1853 * The <<lttng-modules,LTTng kernel tracer>>.
1854 * The <<lttng-consumerd,consumer daemon>>.
1856 The session daemon sends requests to the consumer daemon to instruct
1857 it where to send the trace data streams, amongst other information.
1859 * The <<lttng-relayd,relay daemon>>.
1861 The session daemon receives commands from the
1862 <<liblttng-ctl-lttng,tracing control library>>.
1864 The root session daemon loads the appropriate
1865 <<lttng-modules,LTTng kernel modules>> on startup. It also spawns
1866 a <<lttng-consumerd,consumer daemon>> as soon as you create
1867 an <<event,event rule>>.
1869 The session daemon does not send and receive trace data: this is the
1870 role of the <<lttng-consumerd,consumer daemon>> and
1871 <<lttng-relayd,relay daemon>>. It does, however, generate the
1872 http://diamon.org/ctf/[CTF] metadata stream.
1874 Each Unix user can have its own session daemon instance. The
1875 tracing sessions which different session daemons manage are completely
1878 The root user's session daemon is the only one which is
1879 allowed to control the LTTng kernel tracer, and its spawned consumer
1880 daemon is the only one which is allowed to consume trace data from the
1881 LTTng kernel tracer. Note, however, that any Unix user which is a member
1882 of the <<tracing-group,tracing group>> is allowed
1883 to create <<channel,channels>> in the
1884 Linux kernel <<domain,tracing domain>>, and thus to trace the Linux
1887 The <<lttng-cli,cmd:lttng command-line tool>> automatically starts a
1888 session daemon when using its `create` command if none is currently
1889 running. You can also start the session daemon manually.
1896 .The consumer daemon.
1897 image::plumbing-consumerd.png[]
1899 The _consumer daemon_, cmd:lttng-consumerd, is a daemon which shares
1900 ring buffers with user applications or with the LTTng kernel modules to
1901 collect trace data and send it to some location (on disk or to a
1902 <<lttng-relayd,relay daemon>> over the network). The consumer daemon
1903 is part of LTTng-tools.
1905 You do not start a consumer daemon manually: a consumer daemon is always
1906 spawned by a <<lttng-sessiond,session daemon>> as soon as you create an
1907 <<event,event rule>>, that is, before you start tracing. When you kill
1908 its owner session daemon, the consumer daemon also exits because it is
1909 the session daemon's child process. Command-line options of
1910 man:lttng-sessiond(8) target the consumer daemon process.
1912 There are up to two running consumer daemons per Unix user, whereas only
1913 one session daemon can run per user. This is because each process can be
1914 either 32-bit or 64-bit: if the target system runs a mixture of 32-bit
1915 and 64-bit processes, it is more efficient to have separate
1916 corresponding 32-bit and 64-bit consumer daemons. The root user is an
1917 exception: it can have up to _three_ running consumer daemons: 32-bit
1918 and 64-bit instances for its user applications, and one more
1919 reserved for collecting kernel trace data.
1927 image::plumbing-relayd.png[]
1929 The _relay daemon_, man:lttng-relayd(8), is a daemon acting as a bridge
1930 between remote session and consumer daemons, local trace files, and a
1931 remote live trace viewer. The relay daemon is part of LTTng-tools.
1933 The main purpose of the relay daemon is to implement a receiver of
1934 <<sending-trace-data-over-the-network,trace data over the network>>.
1935 This is useful when the target system does not have much file system
1936 space to record trace files locally.
1938 The relay daemon is also a server to which a
1939 <<lttng-live,live trace viewer>> can
1940 connect. The live trace viewer sends requests to the relay daemon to
1941 receive trace data as the target system emits events. The
1942 communication protocol is named _LTTng live_; it is used over TCP
1945 Note that you can start the relay daemon on the target system directly.
1946 This is the setup of choice when the use case is to view events as
1947 the target system emits them without the need of a remote system.
1951 == [[using-lttng]]Instrumentation
1953 There are many examples of tracing and monitoring in our everyday life:
1955 * You have access to real-time and historical weather reports and
1956 forecasts thanks to weather stations installed around the country.
1957 * You know your heart is safe thanks to an electrocardiogram.
1958 * You make sure not to drive your car too fast and to have enough fuel
1959 to reach your destination thanks to gauges visible on your dashboard.
1961 All the previous examples have something in common: they rely on
1962 **instruments**. Without the electrodes attached to the surface of your
1963 body's skin, cardiac monitoring is futile.
1965 LTTng, as a tracer, is no different from those real life examples. If
1966 you're about to trace a software system or, in other words, record its
1967 history of execution, you better have **instrumentation points** in the
1968 subject you're tracing, that is, the actual software.
1970 Various ways were developed to instrument a piece of software for LTTng
1971 tracing. The most straightforward one is to manually place
1972 instrumentation points, called _tracepoints_, in the software's source
1973 code. It is also possible to add instrumentation points dynamically in
1974 the Linux kernel <<domain,tracing domain>>.
1976 If you're only interested in tracing the Linux kernel, your
1977 instrumentation needs are probably already covered by LTTng's built-in
1978 <<lttng-modules,Linux kernel tracepoints>>. You may also wish to trace a
1979 user application which is already instrumented for LTTng tracing.
1980 In such cases, you can skip this whole section and read the topics of
1981 the <<controlling-tracing,Tracing control>> section.
1983 Many methods are available to instrument a piece of software for LTTng
1986 * <<c-application,User space instrumentation for C and $$C++$$
1988 * <<prebuilt-ust-helpers,Prebuilt user space tracing helpers>>.
1989 * <<java-application,User space Java agent>>.
1990 * <<python-application,User space Python agent>>.
1991 * <<proc-lttng-logger-abi,LTTng logger>>.
1992 * <<instrumenting-linux-kernel,LTTng kernel tracepoints>>.
1996 === [[cxx-application]]User space instrumentation for C and $$C++$$ applications
1998 The procedure to instrument a C or $$C++$$ user application with
1999 the <<lttng-ust,LTTng user space tracing library>>, `liblttng-ust`, is:
2001 . <<tracepoint-provider,Create the source files of a tracepoint provider
2003 . <<probing-the-application-source-code,Add tracepoints to
2004 the application's source code>>.
2005 . <<building-tracepoint-providers-and-user-application,Build and link
2006 a tracepoint provider package and the user application>>.
2008 If you need quick, man:printf(3)-like instrumentation, you can skip
2009 those steps and use <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>>
2012 IMPORTANT: You need to <<installing-lttng,install>> LTTng-UST to
2013 instrument a user application with `liblttng-ust`.
2016 [[tracepoint-provider]]
2017 ==== Create the source files of a tracepoint provider package
2019 A _tracepoint provider_ is a set of compiled functions which provide
2020 **tracepoints** to an application, the type of instrumentation point
2021 supported by LTTng-UST. Those functions can emit events with
2022 user-defined fields and serialize those events as event records to one
2023 or more LTTng-UST <<channel,channel>> sub-buffers. The `tracepoint()`
2024 macro, which you <<probing-the-application-source-code,insert in a user
2025 application's source code>>, calls those functions.
2027 A _tracepoint provider package_ is an object file (`.o`) or a shared
2028 library (`.so`) which contains one or more tracepoint providers.
2029 Its source files are:
2031 * One or more <<tpp-header,tracepoint provider header>> (`.h`).
2032 * A <<tpp-source,tracepoint provider package source>> (`.c`).
2034 A tracepoint provider package is dynamically linked with `liblttng-ust`,
2035 the LTTng user space tracer, at run time.
2038 .User application linked with `liblttng-ust` and containing a tracepoint provider.
2039 image::ust-app.png[]
2041 NOTE: If you need quick, man:printf(3)-like instrumentation, you can
2042 skip creating and using a tracepoint provider and use
2043 <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>> instead.
2047 ===== Create a tracepoint provider header file template
2049 A _tracepoint provider header file_ contains the tracepoint
2050 definitions of a tracepoint provider.
2052 To create a tracepoint provider header file:
2054 . Start from this template:
2058 .Tracepoint provider header file template (`.h` file extension).
2060 #undef TRACEPOINT_PROVIDER
2061 #define TRACEPOINT_PROVIDER provider_name
2063 #undef TRACEPOINT_INCLUDE
2064 #define TRACEPOINT_INCLUDE "./tp.h"
2066 #if !defined(_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
2069 #include <lttng/tracepoint.h>
2072 * Use TRACEPOINT_EVENT(), TRACEPOINT_EVENT_CLASS(),
2073 * TRACEPOINT_EVENT_INSTANCE(), and TRACEPOINT_LOGLEVEL() here.
2078 #include <lttng/tracepoint-event.h>
2084 * `provider_name` with the name of your tracepoint provider.
2085 * `"tp.h"` with the name of your tracepoint provider header file.
2087 . Below the `#include <lttng/tracepoint.h>` line, put your
2088 <<defining-tracepoints,tracepoint definitions>>.
2090 Your tracepoint provider name must be unique amongst all the possible
2091 tracepoint provider names used on the same target system. We
2092 suggest to include the name of your project or company in the name,
2093 for example, `org_lttng_my_project_tpp`.
2095 TIP: [[lttng-gen-tp]]You can use the man:lttng-gen-tp(1) tool to create
2096 this boilerplate for you. When using cmd:lttng-gen-tp, all you need to
2097 write are the <<defining-tracepoints,tracepoint definitions>>.
2100 [[defining-tracepoints]]
2101 ===== Create a tracepoint definition
2103 A _tracepoint definition_ defines, for a given tracepoint:
2105 * Its **input arguments**. They are the macro parameters that the
2106 `tracepoint()` macro accepts for this particular tracepoint
2107 in the user application's source code.
2108 * Its **output event fields**. They are the sources of event fields
2109 that form the payload of any event that the execution of the
2110 `tracepoint()` macro emits for this particular tracepoint.
2112 You can create a tracepoint definition by using the
2113 `TRACEPOINT_EVENT()` macro below the `#include <lttng/tracepoint.h>`
2115 <<tpp-header,tracepoint provider header file template>>.
2117 The syntax of the `TRACEPOINT_EVENT()` macro is:
2120 .`TRACEPOINT_EVENT()` macro syntax.
2123 /* Tracepoint provider name */
2126 /* Tracepoint name */
2129 /* Input arguments */
2134 /* Output event fields */
2143 * `provider_name` with your tracepoint provider name.
2144 * `tracepoint_name` with your tracepoint name.
2145 * `arguments` with the <<tpp-def-input-args,input arguments>>.
2146 * `fields` with the <<tpp-def-output-fields,output event field>>
2149 This tracepoint emits events named `provider_name:tracepoint_name`.
2152 .Event name's length limitation
2154 The concatenation of the tracepoint provider name and the
2155 tracepoint name must not exceed **254{nbsp}characters**. If it does, the
2156 instrumented application compiles and runs, but LTTng throws multiple
2157 warnings and you could experience serious issues.
2160 [[tpp-def-input-args]]The syntax of the `TP_ARGS()` macro is:
2163 .`TP_ARGS()` macro syntax.
2172 * `type` with the C type of the argument.
2173 * `arg_name` with the argument name.
2175 You can repeat `type` and `arg_name` up to 10{nbsp}times to have
2176 more than one argument.
2178 .`TP_ARGS()` usage with three arguments.
2190 The `TP_ARGS()` and `TP_ARGS(void)` forms are valid to create a
2191 tracepoint definition with no input arguments.
2193 [[tpp-def-output-fields]]The `TP_FIELDS()` macro contains a list of
2194 `ctf_*()` macros. Each `ctf_*()` macro defines one event field. See
2195 man:lttng-ust(3) for a complete description of the available `ctf_*()`
2196 macros. A `ctf_*()` macro specifies the type, size, and byte order of
2199 Each `ctf_*()` macro takes an _argument expression_ parameter. This is a
2200 C expression that the tracer evalutes at the `tracepoint()` macro site
2201 in the application's source code. This expression provides a field's
2202 source of data. The argument expression can include input argument names
2203 listed in the `TP_ARGS()` macro.
2205 Each `ctf_*()` macro also takes a _field name_ parameter. Field names
2206 must be unique within a given tracepoint definition.
2208 Here's a complete tracepoint definition example:
2210 .Tracepoint definition.
2212 The following tracepoint definition defines a tracepoint which takes
2213 three input arguments and has four output event fields.
2217 #include "my-custom-structure.h"
2223 const struct my_custom_structure*, my_custom_structure,
2228 ctf_string(query_field, query)
2229 ctf_float(double, ratio_field, ratio)
2230 ctf_integer(int, recv_size, my_custom_structure->recv_size)
2231 ctf_integer(int, send_size, my_custom_structure->send_size)
2236 You can refer to this tracepoint definition with the `tracepoint()`
2237 macro in your application's source code like this:
2241 tracepoint(my_provider, my_tracepoint,
2242 my_structure, some_ratio, the_query);
2246 NOTE: The LTTng tracer only evaluates tracepoint arguments at run time
2247 if they satisfy an enabled <<event,event rule>>.
2250 [[using-tracepoint-classes]]
2251 ===== Use a tracepoint class
2253 A _tracepoint class_ is a class of tracepoints which share the same
2254 output event field definitions. A _tracepoint instance_ is one
2255 instance of such a defined tracepoint class, with its own tracepoint
2258 The <<defining-tracepoints,`TRACEPOINT_EVENT()` macro>> is actually a
2259 shorthand which defines both a tracepoint class and a tracepoint
2260 instance at the same time.
2262 When you build a tracepoint provider package, the C or $$C++$$ compiler
2263 creates one serialization function for each **tracepoint class**. A
2264 serialization function is responsible for serializing the event fields
2265 of a tracepoint to a sub-buffer when tracing.
2267 For various performance reasons, when your situation requires multiple
2268 tracepoint definitions with different names, but with the same event
2269 fields, we recommend that you manually create a tracepoint class
2270 and instantiate as many tracepoint instances as needed. One positive
2271 effect of such a design, amongst other advantages, is that all
2272 tracepoint instances of the same tracepoint class reuse the same
2273 serialization function, thus reducing
2274 https://en.wikipedia.org/wiki/Cache_pollution[cache pollution].
2276 .Use a tracepoint class and tracepoint instances.
2278 Consider the following three tracepoint definitions:
2290 ctf_integer(int, userid, userid)
2291 ctf_integer(size_t, len, len)
2303 ctf_integer(int, userid, userid)
2304 ctf_integer(size_t, len, len)
2316 ctf_integer(int, userid, userid)
2317 ctf_integer(size_t, len, len)
2322 In this case, we create three tracepoint classes, with one implicit
2323 tracepoint instance for each of them: `get_account`, `get_settings`, and
2324 `get_transaction`. However, they all share the same event field names
2325 and types. Hence three identical, yet independent serialization
2326 functions are created when you build the tracepoint provider package.
2328 A better design choice is to define a single tracepoint class and three
2329 tracepoint instances:
2333 /* The tracepoint class */
2334 TRACEPOINT_EVENT_CLASS(
2335 /* Tracepoint provider name */
2338 /* Tracepoint class name */
2341 /* Input arguments */
2347 /* Output event fields */
2349 ctf_integer(int, userid, userid)
2350 ctf_integer(size_t, len, len)
2354 /* The tracepoint instances */
2355 TRACEPOINT_EVENT_INSTANCE(
2356 /* Tracepoint provider name */
2359 /* Tracepoint class name */
2362 /* Tracepoint name */
2365 /* Input arguments */
2371 TRACEPOINT_EVENT_INSTANCE(
2380 TRACEPOINT_EVENT_INSTANCE(
2393 [[assigning-log-levels]]
2394 ===== Assign a log level to a tracepoint definition
2396 You can assign an optional _log level_ to a
2397 <<defining-tracepoints,tracepoint definition>>.
2399 Assigning different levels of severity to tracepoint definitions can
2400 be useful: when you <<enabling-disabling-events,create an event rule>>,
2401 you can target tracepoints having a log level as severe as a specific
2404 The concept of LTTng-UST log levels is similar to the levels found
2405 in typical logging frameworks:
2407 * In a logging framework, the log level is given by the function
2408 or method name you use at the log statement site: `debug()`,
2409 `info()`, `warn()`, `error()`, and so on.
2410 * In LTTng-UST, you statically assign the log level to a tracepoint
2411 definition; any `tracepoint()` macro invocation which refers to
2412 this definition has this log level.
2414 You can assign a log level to a tracepoint definition with the
2415 `TRACEPOINT_LOGLEVEL()` macro. You must use this macro _after_ the
2416 <<defining-tracepoints,`TRACEPOINT_EVENT()`>> or
2417 <<using-tracepoint-classes,`TRACEPOINT_INSTANCE()`>> macro for a given
2420 The syntax of the `TRACEPOINT_LOGLEVEL()` macro is:
2423 .`TRACEPOINT_LOGLEVEL()` macro syntax.
2425 TRACEPOINT_LOGLEVEL(provider_name, tracepoint_name, log_level)
2430 * `provider_name` with the tracepoint provider name.
2431 * `tracepoint_name` with the tracepoint name.
2432 * `log_level` with the log level to assign to the tracepoint
2433 definition named `tracepoint_name` in the `provider_name`
2434 tracepoint provider.
2436 See man:lttng-ust(3) for a list of available log level names.
2438 .Assign the `TRACE_DEBUG_UNIT` log level to a tracepoint definition.
2442 /* Tracepoint definition */
2451 ctf_integer(int, userid, userid)
2452 ctf_integer(size_t, len, len)
2456 /* Log level assignment */
2457 TRACEPOINT_LOGLEVEL(my_app, get_transaction, TRACE_DEBUG_UNIT)
2463 ===== Create a tracepoint provider package source file
2465 A _tracepoint provider package source file_ is a C source file which
2466 includes a <<tpp-header,tracepoint provider header file>> to expand its
2467 macros into event serialization and other functions.
2469 You can always use the following tracepoint provider package source
2473 .Tracepoint provider package source file template.
2475 #define TRACEPOINT_CREATE_PROBES
2480 Replace `tp.h` with the name of your <<tpp-header,tracepoint provider
2481 header file>> name. You may also include more than one tracepoint
2482 provider header file here to create a tracepoint provider package
2483 holding more than one tracepoint providers.
2486 [[probing-the-application-source-code]]
2487 ==== Add tracepoints to an application's source code
2489 Once you <<tpp-header,create a tracepoint provider header file>>, you
2490 can use the `tracepoint()` macro in your application's
2491 source code to insert the tracepoints that this header
2492 <<defining-tracepoints,defines>>.
2494 The `tracepoint()` macro takes at least two parameters: the tracepoint
2495 provider name and the tracepoint name. The corresponding tracepoint
2496 definition defines the other parameters.
2498 .`tracepoint()` usage.
2500 The following <<defining-tracepoints,tracepoint definition>> defines a
2501 tracepoint which takes two input arguments and has two output event
2505 .Tracepoint provider header file.
2507 #include "my-custom-structure.h"
2514 const char*, cmd_name
2517 ctf_string(cmd_name, cmd_name)
2518 ctf_integer(int, number_of_args, argc)
2523 You can refer to this tracepoint definition with the `tracepoint()`
2524 macro in your application's source code like this:
2527 .Application's source file.
2531 int main(int argc, char* argv[])
2533 tracepoint(my_provider, my_tracepoint, argc, argv[0]);
2539 Note how the application's source code includes
2540 the tracepoint provider header file containing the tracepoint
2541 definitions to use, path:{tp.h}.
2544 .`tracepoint()` usage with a complex tracepoint definition.
2546 Consider this complex tracepoint definition, where multiple event
2547 fields refer to the same input arguments in their argument expression
2551 .Tracepoint provider header file.
2553 /* For `struct stat` */
2554 #include <sys/types.h>
2555 #include <sys/stat.h>
2567 ctf_integer(int, my_constant_field, 23 + 17)
2568 ctf_integer(int, my_int_arg_field, my_int_arg)
2569 ctf_integer(int, my_int_arg_field2, my_int_arg * my_int_arg)
2570 ctf_integer(int, sum4_field, my_str_arg[0] + my_str_arg[1] +
2571 my_str_arg[2] + my_str_arg[3])
2572 ctf_string(my_str_arg_field, my_str_arg)
2573 ctf_integer_hex(off_t, size_field, st->st_size)
2574 ctf_float(double, size_dbl_field, (double) st->st_size)
2575 ctf_sequence_text(char, half_my_str_arg_field, my_str_arg,
2576 size_t, strlen(my_str_arg) / 2)
2581 You can refer to this tracepoint definition with the `tracepoint()`
2582 macro in your application's source code like this:
2585 .Application's source file.
2587 #define TRACEPOINT_DEFINE
2594 stat("/etc/fstab", &s);
2595 tracepoint(my_provider, my_tracepoint, 23, "Hello, World!", &s);
2601 If you look at the event record that LTTng writes when tracing this
2602 program, assuming the file size of path:{/etc/fstab} is 301{nbsp}bytes,
2603 it should look like this:
2605 .Event record fields
2607 |Field's name |Field's value
2608 |`my_constant_field` |40
2609 |`my_int_arg_field` |23
2610 |`my_int_arg_field2` |529
2612 |`my_str_arg_field` |`Hello, World!`
2613 |`size_field` |0x12d
2614 |`size_dbl_field` |301.0
2615 |`half_my_str_arg_field` |`Hello,`
2619 Sometimes, the arguments you pass to `tracepoint()` are expensive to
2620 compute--they use the call stack, for example. To avoid this
2621 computation when the tracepoint is disabled, you can use the
2622 `tracepoint_enabled()` and `do_tracepoint()` macros.
2624 The syntax of the `tracepoint_enabled()` and `do_tracepoint()` macros
2628 .`tracepoint_enabled()` and `do_tracepoint()` macros syntax.
2630 tracepoint_enabled(provider_name, tracepoint_name)
2631 do_tracepoint(provider_name, tracepoint_name, ...)
2636 * `provider_name` with the tracepoint provider name.
2637 * `tracepoint_name` with the tracepoint name.
2639 `tracepoint_enabled()` returns a non-zero value if the tracepoint named
2640 `tracepoint_name` from the provider named `provider_name` is enabled
2643 `do_tracepoint()` is like `tracepoint()`, except that it doesn't check
2644 if the tracepoint is enabled. Using `tracepoint()` with
2645 `tracepoint_enabled()` is dangerous since `tracepoint()` also contains
2646 the `tracepoint_enabled()` check, thus a race condition is
2647 possible in this situation:
2650 .Possible race condition when using `tracepoint_enabled()` with `tracepoint()`.
2652 if (tracepoint_enabled(my_provider, my_tracepoint)) {
2653 stuff = prepare_stuff();
2656 tracepoint(my_provider, my_tracepoint, stuff);
2659 If the tracepoint is enabled after the condition, then `stuff` is not
2660 prepared: the emitted event will either contain wrong data, or the whole
2661 application could crash (segmentation fault, for example).
2663 NOTE: Neither `tracepoint_enabled()` nor `do_tracepoint()` have an
2664 `STAP_PROBEV()` call. If you need it, you must emit
2668 [[building-tracepoint-providers-and-user-application]]
2669 ==== Build and link a tracepoint provider package and an application
2671 Once you have one or more <<tpp-header,tracepoint provider header
2672 files>> and a <<tpp-source,tracepoint provider package source file>>,
2673 you can create the tracepoint provider package by compiling its source
2674 file. From here, multiple build and run scenarios are possible. The
2675 following table shows common application and library configurations
2676 along with the required command lines to achieve them.
2678 In the following diagrams, we use the following file names:
2681 Executable application.
2684 Application's object file.
2687 Tracepoint provider package object file.
2690 Tracepoint provider package archive file.
2693 Tracepoint provider package shared object file.
2696 User library object file.
2699 User library shared object file.
2701 We use the following symbols in the diagrams of table below:
2704 .Symbols used in the build scenario diagrams.
2705 image::ust-sit-symbols.png[]
2707 We assume that path:{.} is part of the env:LD_LIBRARY_PATH environment
2708 variable in the following instructions.
2710 [role="growable ust-scenarios",cols="asciidoc,asciidoc"]
2711 .Common tracepoint provider package scenarios.
2713 |Scenario |Instructions
2716 The instrumented application is statically linked with
2717 the tracepoint provider package object.
2719 image::ust-sit+app-linked-with-tp-o+app-instrumented.png[]
2722 include::../common/ust-sit-step-tp-o.txt[]
2724 To build the instrumented application:
2726 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2731 #define TRACEPOINT_DEFINE
2735 . Compile the application source file:
2744 . Build the application:
2749 $ gcc -o app app.o tpp.o -llttng-ust -ldl
2753 To run the instrumented application:
2755 * Start the application:
2765 The instrumented application is statically linked with the
2766 tracepoint provider package archive file.
2768 image::ust-sit+app-linked-with-tp-a+app-instrumented.png[]
2771 To create the tracepoint provider package archive file:
2773 . Compile the <<tpp-source,tracepoint provider package source file>>:
2782 . Create the tracepoint provider package archive file:
2787 $ ar rcs tpp.a tpp.o
2791 To build the instrumented application:
2793 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2798 #define TRACEPOINT_DEFINE
2802 . Compile the application source file:
2811 . Build the application:
2816 $ gcc -o app app.o tpp.a -llttng-ust -ldl
2820 To run the instrumented application:
2822 * Start the application:
2832 The instrumented application is linked with the tracepoint provider
2833 package shared object.
2835 image::ust-sit+app-linked-with-tp-so+app-instrumented.png[]
2838 include::../common/ust-sit-step-tp-so.txt[]
2840 To build the instrumented application:
2842 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2847 #define TRACEPOINT_DEFINE
2851 . Compile the application source file:
2860 . Build the application:
2865 $ gcc -o app app.o -ldl -L. -ltpp
2869 To run the instrumented application:
2871 * Start the application:
2881 The tracepoint provider package shared object is preloaded before the
2882 instrumented application starts.
2884 image::ust-sit+tp-so-preloaded+app-instrumented.png[]
2887 include::../common/ust-sit-step-tp-so.txt[]
2889 To build the instrumented application:
2891 . In path:{app.c}, before including path:{tpp.h}, add the
2897 #define TRACEPOINT_DEFINE
2898 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
2902 . Compile the application source file:
2911 . Build the application:
2916 $ gcc -o app app.o -ldl
2920 To run the instrumented application with tracing support:
2922 * Preload the tracepoint provider package shared object and
2923 start the application:
2928 $ LD_PRELOAD=./libtpp.so ./app
2932 To run the instrumented application without tracing support:
2934 * Start the application:
2944 The instrumented application dynamically loads the tracepoint provider
2945 package shared object.
2947 image::ust-sit+app-dlopens-tp-so+app-instrumented.png[]
2950 include::../common/ust-sit-step-tp-so.txt[]
2952 To build the instrumented application:
2954 . In path:{app.c}, before including path:{tpp.h}, add the
2960 #define TRACEPOINT_DEFINE
2961 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
2965 . Compile the application source file:
2974 . Build the application:
2979 $ gcc -o app app.o -ldl
2983 To run the instrumented application:
2985 * Start the application:
2995 The application is linked with the instrumented user library.
2997 The instrumented user library is statically linked with the tracepoint
2998 provider package object file.
3000 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-o+lib-instrumented.png[]
3003 include::../common/ust-sit-step-tp-o-fpic.txt[]
3005 To build the instrumented user library:
3007 . In path:{emon.c}, before including path:{tpp.h}, add the
3013 #define TRACEPOINT_DEFINE
3017 . Compile the user library source file:
3022 $ gcc -I. -fpic -c emon.c
3026 . Build the user library shared object:
3031 $ gcc -shared -o libemon.so emon.o tpp.o -llttng-ust -ldl
3035 To build the application:
3037 . Compile the application source file:
3046 . Build the application:
3051 $ gcc -o app app.o -L. -lemon
3055 To run the application:
3057 * Start the application:
3067 The application is linked with the instrumented user library.
3069 The instrumented user library is linked with the tracepoint provider
3070 package shared object.
3072 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3075 include::../common/ust-sit-step-tp-so.txt[]
3077 To build the instrumented user library:
3079 . In path:{emon.c}, before including path:{tpp.h}, add the
3085 #define TRACEPOINT_DEFINE
3089 . Compile the user library source file:
3094 $ gcc -I. -fpic -c emon.c
3098 . Build the user library shared object:
3103 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3107 To build the application:
3109 . Compile the application source file:
3118 . Build the application:
3123 $ gcc -o app app.o -L. -lemon
3127 To run the application:
3129 * Start the application:
3139 The tracepoint provider package shared object is preloaded before the
3142 The application is linked with the instrumented user library.
3144 image::ust-sit+tp-so-preloaded+app-linked-with-lib+lib-instrumented.png[]
3147 include::../common/ust-sit-step-tp-so.txt[]
3149 To build the instrumented user library:
3151 . In path:{emon.c}, before including path:{tpp.h}, add the
3157 #define TRACEPOINT_DEFINE
3158 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3162 . Compile the user library source file:
3167 $ gcc -I. -fpic -c emon.c
3171 . Build the user library shared object:
3176 $ gcc -shared -o libemon.so emon.o -ldl
3180 To build the application:
3182 . Compile the application source file:
3191 . Build the application:
3196 $ gcc -o app app.o -L. -lemon
3200 To run the application with tracing support:
3202 * Preload the tracepoint provider package shared object and
3203 start the application:
3208 $ LD_PRELOAD=./libtpp.so ./app
3212 To run the application without tracing support:
3214 * Start the application:
3224 The application is linked with the instrumented user library.
3226 The instrumented user library dynamically loads the tracepoint provider
3227 package shared object.
3229 image::ust-sit+app-linked-with-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3232 include::../common/ust-sit-step-tp-so.txt[]
3234 To build the instrumented user library:
3236 . In path:{emon.c}, before including path:{tpp.h}, add the
3242 #define TRACEPOINT_DEFINE
3243 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3247 . Compile the user library source file:
3252 $ gcc -I. -fpic -c emon.c
3256 . Build the user library shared object:
3261 $ gcc -shared -o libemon.so emon.o -ldl
3265 To build the application:
3267 . Compile the application source file:
3276 . Build the application:
3281 $ gcc -o app app.o -L. -lemon
3285 To run the application:
3287 * Start the application:
3297 The application dynamically loads the instrumented user library.
3299 The instrumented user library is linked with the tracepoint provider
3300 package shared object.
3302 image::ust-sit+app-dlopens-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3305 include::../common/ust-sit-step-tp-so.txt[]
3307 To build the instrumented user library:
3309 . In path:{emon.c}, before including path:{tpp.h}, add the
3315 #define TRACEPOINT_DEFINE
3319 . Compile the user library source file:
3324 $ gcc -I. -fpic -c emon.c
3328 . Build the user library shared object:
3333 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3337 To build the application:
3339 . Compile the application source file:
3348 . Build the application:
3353 $ gcc -o app app.o -ldl -L. -lemon
3357 To run the application:
3359 * Start the application:
3369 The application dynamically loads the instrumented user library.
3371 The instrumented user library dynamically loads the tracepoint provider
3372 package shared object.
3374 image::ust-sit+app-dlopens-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3377 include::../common/ust-sit-step-tp-so.txt[]
3379 To build the instrumented user library:
3381 . In path:{emon.c}, before including path:{tpp.h}, add the
3387 #define TRACEPOINT_DEFINE
3388 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3392 . Compile the user library source file:
3397 $ gcc -I. -fpic -c emon.c
3401 . Build the user library shared object:
3406 $ gcc -shared -o libemon.so emon.o -ldl
3410 To build the application:
3412 . Compile the application source file:
3421 . Build the application:
3426 $ gcc -o app app.o -ldl -L. -lemon
3430 To run the application:
3432 * Start the application:
3442 The tracepoint provider package shared object is preloaded before the
3445 The application dynamically loads the instrumented user library.
3447 image::ust-sit+tp-so-preloaded+app-dlopens-lib+lib-instrumented.png[]
3450 include::../common/ust-sit-step-tp-so.txt[]
3452 To build the instrumented user library:
3454 . In path:{emon.c}, before including path:{tpp.h}, add the
3460 #define TRACEPOINT_DEFINE
3461 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3465 . Compile the user library source file:
3470 $ gcc -I. -fpic -c emon.c
3474 . Build the user library shared object:
3479 $ gcc -shared -o libemon.so emon.o -ldl
3483 To build the application:
3485 . Compile the application source file:
3494 . Build the application:
3499 $ gcc -o app app.o -L. -lemon
3503 To run the application with tracing support:
3505 * Preload the tracepoint provider package shared object and
3506 start the application:
3511 $ LD_PRELOAD=./libtpp.so ./app
3515 To run the application without tracing support:
3517 * Start the application:
3527 The application is statically linked with the tracepoint provider
3528 package object file.
3530 The application is linked with the instrumented user library.
3532 image::ust-sit+app-linked-with-tp-o+app-linked-with-lib+lib-instrumented.png[]
3535 include::../common/ust-sit-step-tp-o.txt[]
3537 To build the instrumented user library:
3539 . In path:{emon.c}, before including path:{tpp.h}, add the
3545 #define TRACEPOINT_DEFINE
3549 . Compile the user library source file:
3554 $ gcc -I. -fpic -c emon.c
3558 . Build the user library shared object:
3563 $ gcc -shared -o libemon.so emon.o
3567 To build the application:
3569 . Compile the application source file:
3578 . Build the application:
3583 $ gcc -o app app.o tpp.o -llttng-ust -ldl -L. -lemon
3587 To run the instrumented application:
3589 * Start the application:
3599 The application is statically linked with the tracepoint provider
3600 package object file.
3602 The application dynamically loads the instrumented user library.
3604 image::ust-sit+app-linked-with-tp-o+app-dlopens-lib+lib-instrumented.png[]
3607 include::../common/ust-sit-step-tp-o.txt[]
3609 To build the application:
3611 . In path:{app.c}, before including path:{tpp.h}, add the following line:
3616 #define TRACEPOINT_DEFINE
3620 . Compile the application source file:
3629 . Build the application:
3634 $ gcc -Wl,--export-dynamic -o app app.o tpp.o \
3639 The `--export-dynamic` option passed to the linker is necessary for the
3640 dynamically loaded library to ``see'' the tracepoint symbols defined in
3643 To build the instrumented user library:
3645 . Compile the user library source file:
3650 $ gcc -I. -fpic -c emon.c
3654 . Build the user library shared object:
3659 $ gcc -shared -o libemon.so emon.o
3663 To run the application:
3665 * Start the application:
3676 [[using-lttng-ust-with-daemons]]
3677 ===== Use noch:{LTTng-UST} with daemons
3679 If your instrumented application calls man:fork(2), man:clone(2),
3680 or BSD's man:rfork(2), without a following man:exec(3)-family
3681 system call, you must preload the path:{liblttng-ust-fork.so} shared
3682 object when you start the application.
3686 $ LD_PRELOAD=liblttng-ust-fork.so ./my-app
3689 If your tracepoint provider package is
3690 a shared library which you also preload, you must put both
3691 shared objects in env:LD_PRELOAD:
3695 $ LD_PRELOAD=liblttng-ust-fork.so:/path/to/tp.so ./my-app
3701 ===== Use noch:{LTTng-UST} with applications which close file descriptors that don't belong to them
3703 If your instrumented application closes one or more file descriptors
3704 which it did not open itself, you must preload the
3705 path:{liblttng-ust-fd.so} shared object when you start the application:
3709 $ LD_PRELOAD=liblttng-ust-fd.so ./my-app
3712 Typical use cases include closing all the file descriptors after
3713 man:fork(2) or man:rfork(2) and buggy applications doing
3717 [[lttng-ust-pkg-config]]
3718 ===== Use noch:{pkg-config}
3720 On some distributions, LTTng-UST ships with a
3721 https://www.freedesktop.org/wiki/Software/pkg-config/[pkg-config]
3722 metadata file. If this is your case, then you can use cmd:pkg-config to
3723 build an application on the command line:
3727 $ gcc -o my-app my-app.o tp.o $(pkg-config --cflags --libs lttng-ust)
3731 [[instrumenting-32-bit-app-on-64-bit-system]]
3732 ===== [[advanced-instrumenting-techniques]]Build a 32-bit instrumented application for a 64-bit target system
3734 In order to trace a 32-bit application running on a 64-bit system,
3735 LTTng must use a dedicated 32-bit
3736 <<lttng-consumerd,consumer daemon>>.
3738 The following steps show how to build and install a 32-bit consumer
3739 daemon, which is _not_ part of the default 64-bit LTTng build, how to
3740 build and install the 32-bit LTTng-UST libraries, and how to build and
3741 link an instrumented 32-bit application in that context.
3743 To build a 32-bit instrumented application for a 64-bit target system,
3744 assuming you have a fresh target system with no installed Userspace RCU
3747 . Download, build, and install a 32-bit version of Userspace RCU:
3752 $ cd $(mktemp -d) &&
3753 wget http://lttng.org/files/urcu/userspace-rcu-latest-0.9.tar.bz2 &&
3754 tar -xf userspace-rcu-latest-0.9.tar.bz2 &&
3755 cd userspace-rcu-0.9.* &&
3756 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 &&
3758 sudo make install &&
3763 . Using your distribution's package manager, or from source, install
3764 the following 32-bit versions of the following dependencies of
3765 LTTng-tools and LTTng-UST:
3768 * https://sourceforge.net/projects/libuuid/[libuuid]
3769 * http://directory.fsf.org/wiki/Popt[popt]
3770 * http://www.xmlsoft.org/[libxml2]
3773 . Download, build, and install a 32-bit version of the latest
3774 LTTng-UST{nbsp}{revision}:
3779 $ cd $(mktemp -d) &&
3780 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.11.tar.bz2 &&
3781 tar -xf lttng-ust-latest-2.11.tar.bz2 &&
3782 cd lttng-ust-2.11.* &&
3783 ./configure --libdir=/usr/local/lib32 \
3784 CFLAGS=-m32 CXXFLAGS=-m32 \
3785 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' &&
3787 sudo make install &&
3794 Depending on your distribution,
3795 32-bit libraries could be installed at a different location than
3796 `/usr/lib32`. For example, Debian is known to install
3797 some 32-bit libraries in `/usr/lib/i386-linux-gnu`.
3799 In this case, make sure to set `LDFLAGS` to all the
3800 relevant 32-bit library paths, for example:
3804 $ LDFLAGS='-L/usr/lib/i386-linux-gnu -L/usr/lib32'
3808 . Download the latest LTTng-tools{nbsp}{revision}, build, and install
3809 the 32-bit consumer daemon:
3814 $ cd $(mktemp -d) &&
3815 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.11.tar.bz2 &&
3816 tar -xf lttng-tools-latest-2.11.tar.bz2 &&
3817 cd lttng-tools-2.11.* &&
3818 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 CXXFLAGS=-m32 \
3819 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' \
3820 --disable-bin-lttng --disable-bin-lttng-crash \
3821 --disable-bin-lttng-relayd --disable-bin-lttng-sessiond &&
3823 cd src/bin/lttng-consumerd &&
3824 sudo make install &&
3829 . From your distribution or from source,
3830 <<installing-lttng,install>> the 64-bit versions of
3831 LTTng-UST and Userspace RCU.
3832 . Download, build, and install the 64-bit version of the
3833 latest LTTng-tools{nbsp}{revision}:
3838 $ cd $(mktemp -d) &&
3839 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.11.tar.bz2 &&
3840 tar -xf lttng-tools-latest-2.11.tar.bz2 &&
3841 cd lttng-tools-2.11.* &&
3842 ./configure --with-consumerd32-libdir=/usr/local/lib32 \
3843 --with-consumerd32-bin=/usr/local/lib32/lttng/libexec/lttng-consumerd &&
3845 sudo make install &&
3850 . Pass the following options to man:gcc(1), man:g++(1), or man:clang(1)
3851 when linking your 32-bit application:
3854 -m32 -L/usr/lib32 -L/usr/local/lib32 \
3855 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32
3858 For example, let's rebuild the quick start example in
3859 <<tracing-your-own-user-application,Trace a user application>> as an
3860 instrumented 32-bit application:
3865 $ gcc -m32 -c -I. hello-tp.c
3866 $ gcc -m32 -c hello.c
3867 $ gcc -m32 -o hello hello.o hello-tp.o \
3868 -L/usr/lib32 -L/usr/local/lib32 \
3869 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32 \
3874 No special action is required to execute the 32-bit application and
3875 to trace it: use the command-line man:lttng(1) tool as usual.
3882 man:tracef(3) is a small LTTng-UST API designed for quick,
3883 man:printf(3)-like instrumentation without the burden of
3884 <<tracepoint-provider,creating>> and
3885 <<building-tracepoint-providers-and-user-application,building>>
3886 a tracepoint provider package.
3888 To use `tracef()` in your application:
3890 . In the C or C++ source files where you need to use `tracef()`,
3891 include `<lttng/tracef.h>`:
3896 #include <lttng/tracef.h>
3900 . In the application's source code, use `tracef()` like you would use
3908 tracef("my message: %d (%s)", my_integer, my_string);
3914 . Link your application with `liblttng-ust`:
3919 $ gcc -o app app.c -llttng-ust
3923 To trace the events that `tracef()` calls emit:
3925 * <<enabling-disabling-events,Create an event rule>> which matches the
3926 `lttng_ust_tracef:*` event name:
3931 $ lttng enable-event --userspace 'lttng_ust_tracef:*'
3936 .Limitations of `tracef()`
3938 The `tracef()` utility function was developed to make user space tracing
3939 super simple, albeit with notable disadvantages compared to
3940 <<defining-tracepoints,user-defined tracepoints>>:
3942 * All the emitted events have the same tracepoint provider and
3943 tracepoint names, respectively `lttng_ust_tracef` and `event`.
3944 * There is no static type checking.
3945 * The only event record field you actually get, named `msg`, is a string
3946 potentially containing the values you passed to `tracef()`
3947 using your own format string. This also means that you cannot filter
3948 events with a custom expression at run time because there are no
3950 * Since `tracef()` uses the C standard library's man:vasprintf(3)
3951 function behind the scenes to format the strings at run time, its
3952 expected performance is lower than with user-defined tracepoints,
3953 which do not require a conversion to a string.
3955 Taking this into consideration, `tracef()` is useful for some quick
3956 prototyping and debugging, but you should not consider it for any
3957 permanent and serious applicative instrumentation.
3963 ==== Use `tracelog()`
3965 The man:tracelog(3) API is very similar to <<tracef,`tracef()`>>, with
3966 the difference that it accepts an additional log level parameter.
3968 The goal of `tracelog()` is to ease the migration from logging to
3971 To use `tracelog()` in your application:
3973 . In the C or C++ source files where you need to use `tracelog()`,
3974 include `<lttng/tracelog.h>`:
3979 #include <lttng/tracelog.h>
3983 . In the application's source code, use `tracelog()` like you would use
3984 man:printf(3), except for the first parameter which is the log
3992 tracelog(TRACE_WARNING, "my message: %d (%s)",
3993 my_integer, my_string);
3999 See man:lttng-ust(3) for a list of available log level names.
4001 . Link your application with `liblttng-ust`:
4006 $ gcc -o app app.c -llttng-ust
4010 To trace the events that `tracelog()` calls emit with a log level
4011 _as severe as_ a specific log level:
4013 * <<enabling-disabling-events,Create an event rule>> which matches the
4014 `lttng_ust_tracelog:*` event name and a minimum level
4020 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
4021 --loglevel=TRACE_WARNING
4025 To trace the events that `tracelog()` calls emit with a
4026 _specific log level_:
4028 * Create an event rule which matches the `lttng_ust_tracelog:*`
4029 event name and a specific log level:
4034 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
4035 --loglevel-only=TRACE_INFO
4040 [[prebuilt-ust-helpers]]
4041 === Prebuilt user space tracing helpers
4043 The LTTng-UST package provides a few helpers in the form or preloadable
4044 shared objects which automatically instrument system functions and
4047 The helper shared objects are normally found in dir:{/usr/lib}. If you
4048 built LTTng-UST <<building-from-source,from source>>, they are probably
4049 located in dir:{/usr/local/lib}.
4051 The installed user space tracing helpers in LTTng-UST{nbsp}{revision}
4054 path:{liblttng-ust-libc-wrapper.so}::
4055 path:{liblttng-ust-pthread-wrapper.so}::
4056 <<liblttng-ust-libc-pthread-wrapper,C{nbsp}standard library
4057 memory and POSIX threads function tracing>>.
4059 path:{liblttng-ust-cyg-profile.so}::
4060 path:{liblttng-ust-cyg-profile-fast.so}::
4061 <<liblttng-ust-cyg-profile,Function entry and exit tracing>>.
4063 path:{liblttng-ust-dl.so}::
4064 <<liblttng-ust-dl,Dynamic linker tracing>>.
4066 To use a user space tracing helper with any user application:
4068 * Preload the helper shared object when you start the application:
4073 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so my-app
4077 You can preload more than one helper:
4082 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so:liblttng-ust-dl.so my-app
4088 [[liblttng-ust-libc-pthread-wrapper]]
4089 ==== Instrument C standard library memory and POSIX threads functions
4091 The path:{liblttng-ust-libc-wrapper.so} and
4092 path:{liblttng-ust-pthread-wrapper.so} helpers
4093 add instrumentation to some C standard library and POSIX
4097 .Functions instrumented by preloading path:{liblttng-ust-libc-wrapper.so}.
4099 |TP provider name |TP name |Instrumented function
4101 .6+|`lttng_ust_libc` |`malloc` |man:malloc(3)
4102 |`calloc` |man:calloc(3)
4103 |`realloc` |man:realloc(3)
4104 |`free` |man:free(3)
4105 |`memalign` |man:memalign(3)
4106 |`posix_memalign` |man:posix_memalign(3)
4110 .Functions instrumented by preloading path:{liblttng-ust-pthread-wrapper.so}.
4112 |TP provider name |TP name |Instrumented function
4114 .4+|`lttng_ust_pthread` |`pthread_mutex_lock_req` |man:pthread_mutex_lock(3p) (request time)
4115 |`pthread_mutex_lock_acq` |man:pthread_mutex_lock(3p) (acquire time)
4116 |`pthread_mutex_trylock` |man:pthread_mutex_trylock(3p)
4117 |`pthread_mutex_unlock` |man:pthread_mutex_unlock(3p)
4120 When you preload the shared object, it replaces the functions listed
4121 in the previous tables by wrappers which contain tracepoints and call
4122 the replaced functions.
4125 [[liblttng-ust-cyg-profile]]
4126 ==== Instrument function entry and exit
4128 The path:{liblttng-ust-cyg-profile*.so} helpers can add instrumentation
4129 to the entry and exit points of functions.
4131 man:gcc(1) and man:clang(1) have an option named
4132 https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html[`-finstrument-functions`]
4133 which generates instrumentation calls for entry and exit to functions.
4134 The LTTng-UST function tracing helpers,
4135 path:{liblttng-ust-cyg-profile.so} and
4136 path:{liblttng-ust-cyg-profile-fast.so}, take advantage of this feature
4137 to add tracepoints to the two generated functions (which contain
4138 `cyg_profile` in their names, hence the helper's name).
4140 To use the LTTng-UST function tracing helper, the source files to
4141 instrument must be built using the `-finstrument-functions` compiler
4144 There are two versions of the LTTng-UST function tracing helper:
4146 * **path:{liblttng-ust-cyg-profile-fast.so}** is a lightweight variant
4147 that you should only use when it can be _guaranteed_ that the
4148 complete event stream is recorded without any lost event record.
4149 Any kind of duplicate information is left out.
4151 Assuming no event record is lost, having only the function addresses on
4152 entry is enough to create a call graph, since an event record always
4153 contains the ID of the CPU that generated it.
4155 You can use a tool like man:addr2line(1) to convert function addresses
4156 back to source file names and line numbers.
4158 * **path:{liblttng-ust-cyg-profile.so}** is a more robust variant
4159 which also works in use cases where event records might get discarded or
4160 not recorded from application startup.
4161 In these cases, the trace analyzer needs more information to be
4162 able to reconstruct the program flow.
4164 See man:lttng-ust-cyg-profile(3) to learn more about the instrumentation
4165 points of this helper.
4167 All the tracepoints that this helper provides have the
4168 log level `TRACE_DEBUG_FUNCTION` (see man:lttng-ust(3)).
4170 TIP: It's sometimes a good idea to limit the number of source files that
4171 you compile with the `-finstrument-functions` option to prevent LTTng
4172 from writing an excessive amount of trace data at run time. When using
4173 man:gcc(1), you can use the
4174 `-finstrument-functions-exclude-function-list` option to avoid
4175 instrument entries and exits of specific function names.
4180 ==== Instrument the dynamic linker
4182 The path:{liblttng-ust-dl.so} helper adds instrumentation to the
4183 man:dlopen(3) and man:dlclose(3) function calls.
4185 See man:lttng-ust-dl(3) to learn more about the instrumentation points
4190 [[java-application]]
4191 === User space Java agent
4193 You can instrument any Java application which uses one of the following
4196 * The https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[**`java.util.logging`**]
4197 (JUL) core logging facilities.
4198 * http://logging.apache.org/log4j/1.2/[**Apache log4j{nbsp}1.2**], since
4199 LTTng{nbsp}2.6. Note that Apache Log4j{nbsp}2 is not supported.
4202 .LTTng-UST Java agent imported by a Java application.
4203 image::java-app.png[]
4205 Note that the methods described below are new in LTTng{nbsp}{revision}.
4206 Previous LTTng versions use another technique.
4208 NOTE: We use http://openjdk.java.net/[OpenJDK]{nbsp}8 for development
4209 and https://ci.lttng.org/[continuous integration], thus this version is
4210 directly supported. However, the LTTng-UST Java agent is also tested
4211 with OpenJDK{nbsp}7.
4216 ==== Use the LTTng-UST Java agent for `java.util.logging`
4218 To use the LTTng-UST Java agent in a Java application which uses
4219 `java.util.logging` (JUL):
4221 . In the Java application's source code, import the LTTng-UST
4222 log handler package for `java.util.logging`:
4227 import org.lttng.ust.agent.jul.LttngLogHandler;
4231 . Create an LTTng-UST JUL log handler:
4236 Handler lttngUstLogHandler = new LttngLogHandler();
4240 . Add this handler to the JUL loggers which should emit LTTng events:
4245 Logger myLogger = Logger.getLogger("some-logger");
4247 myLogger.addHandler(lttngUstLogHandler);
4251 . Use `java.util.logging` log statements and configuration as usual.
4252 The loggers with an attached LTTng-UST log handler can emit
4255 . Before exiting the application, remove the LTTng-UST log handler from
4256 the loggers attached to it and call its `close()` method:
4261 myLogger.removeHandler(lttngUstLogHandler);
4262 lttngUstLogHandler.close();
4266 This is not strictly necessary, but it is recommended for a clean
4267 disposal of the handler's resources.
4269 . Include the LTTng-UST Java agent's common and JUL-specific JAR files,
4270 path:{lttng-ust-agent-common.jar} and path:{lttng-ust-agent-jul.jar},
4272 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4273 path] when you build the Java application.
4275 The JAR files are typically located in dir:{/usr/share/java}.
4277 IMPORTANT: The LTTng-UST Java agent must be
4278 <<installing-lttng,installed>> for the logging framework your
4281 .Use the LTTng-UST Java agent for `java.util.logging`.
4286 import java.io.IOException;
4287 import java.util.logging.Handler;
4288 import java.util.logging.Logger;
4289 import org.lttng.ust.agent.jul.LttngLogHandler;
4293 private static final int answer = 42;
4295 public static void main(String[] argv) throws Exception
4298 Logger logger = Logger.getLogger("jello");
4300 // Create an LTTng-UST log handler
4301 Handler lttngUstLogHandler = new LttngLogHandler();
4303 // Add the LTTng-UST log handler to our logger
4304 logger.addHandler(lttngUstLogHandler);
4307 logger.info("some info");
4308 logger.warning("some warning");
4310 logger.finer("finer information; the answer is " + answer);
4312 logger.severe("error!");
4314 // Not mandatory, but cleaner
4315 logger.removeHandler(lttngUstLogHandler);
4316 lttngUstLogHandler.close();
4325 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4328 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4329 <<enabling-disabling-events,create an event rule>> matching the
4330 `jello` JUL logger, and <<basic-tracing-session-control,start tracing>>:
4335 $ lttng enable-event --jul jello
4339 Run the compiled class:
4343 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4346 <<basic-tracing-session-control,Stop tracing>> and inspect the
4356 In the resulting trace, an <<event,event record>> generated by a Java
4357 application using `java.util.logging` is named `lttng_jul:event` and
4358 has the following fields:
4361 Log record's message.
4367 Name of the class in which the log statement was executed.
4370 Name of the method in which the log statement was executed.
4373 Logging time (timestamp in milliseconds).
4376 Log level integer value.
4379 ID of the thread in which the log statement was executed.
4381 You can use the opt:lttng-enable-event(1):--loglevel or
4382 opt:lttng-enable-event(1):--loglevel-only option of the
4383 man:lttng-enable-event(1) command to target a range of JUL log levels
4384 or a specific JUL log level.
4389 ==== Use the LTTng-UST Java agent for Apache log4j
4391 To use the LTTng-UST Java agent in a Java application which uses
4392 Apache log4j{nbsp}1.2:
4394 . In the Java application's source code, import the LTTng-UST
4395 log appender package for Apache log4j:
4400 import org.lttng.ust.agent.log4j.LttngLogAppender;
4404 . Create an LTTng-UST log4j log appender:
4409 Appender lttngUstLogAppender = new LttngLogAppender();
4413 . Add this appender to the log4j loggers which should emit LTTng events:
4418 Logger myLogger = Logger.getLogger("some-logger");
4420 myLogger.addAppender(lttngUstLogAppender);
4424 . Use Apache log4j log statements and configuration as usual. The
4425 loggers with an attached LTTng-UST log appender can emit LTTng events.
4427 . Before exiting the application, remove the LTTng-UST log appender from
4428 the loggers attached to it and call its `close()` method:
4433 myLogger.removeAppender(lttngUstLogAppender);
4434 lttngUstLogAppender.close();
4438 This is not strictly necessary, but it is recommended for a clean
4439 disposal of the appender's resources.
4441 . Include the LTTng-UST Java agent's common and log4j-specific JAR
4442 files, path:{lttng-ust-agent-common.jar} and
4443 path:{lttng-ust-agent-log4j.jar}, in the
4444 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4445 path] when you build the Java application.
4447 The JAR files are typically located in dir:{/usr/share/java}.
4449 IMPORTANT: The LTTng-UST Java agent must be
4450 <<installing-lttng,installed>> for the logging framework your
4453 .Use the LTTng-UST Java agent for Apache log4j.
4458 import org.apache.log4j.Appender;
4459 import org.apache.log4j.Logger;
4460 import org.lttng.ust.agent.log4j.LttngLogAppender;
4464 private static final int answer = 42;
4466 public static void main(String[] argv) throws Exception
4469 Logger logger = Logger.getLogger("jello");
4471 // Create an LTTng-UST log appender
4472 Appender lttngUstLogAppender = new LttngLogAppender();
4474 // Add the LTTng-UST log appender to our logger
4475 logger.addAppender(lttngUstLogAppender);
4478 logger.info("some info");
4479 logger.warn("some warning");
4481 logger.debug("debug information; the answer is " + answer);
4483 logger.fatal("error!");
4485 // Not mandatory, but cleaner
4486 logger.removeAppender(lttngUstLogAppender);
4487 lttngUstLogAppender.close();
4493 Build this example (`$LOG4JPATH` is the path to the Apache log4j JAR
4498 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH Test.java
4501 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4502 <<enabling-disabling-events,create an event rule>> matching the
4503 `jello` log4j logger, and <<basic-tracing-session-control,start tracing>>:
4508 $ lttng enable-event --log4j jello
4512 Run the compiled class:
4516 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH:. Test
4519 <<basic-tracing-session-control,Stop tracing>> and inspect the
4529 In the resulting trace, an <<event,event record>> generated by a Java
4530 application using log4j is named `lttng_log4j:event` and
4531 has the following fields:
4534 Log record's message.
4540 Name of the class in which the log statement was executed.
4543 Name of the method in which the log statement was executed.
4546 Name of the file in which the executed log statement is located.
4549 Line number at which the log statement was executed.
4555 Log level integer value.
4558 Name of the Java thread in which the log statement was executed.
4560 You can use the opt:lttng-enable-event(1):--loglevel or
4561 opt:lttng-enable-event(1):--loglevel-only option of the
4562 man:lttng-enable-event(1) command to target a range of Apache log4j log levels
4563 or a specific log4j log level.
4567 [[java-application-context]]
4568 ==== Provide application-specific context fields in a Java application
4570 A Java application-specific context field is a piece of state provided
4571 by the application which <<adding-context,you can add>>, using the
4572 man:lttng-add-context(1) command, to each <<event,event record>>
4573 produced by the log statements of this application.
4575 For example, a given object might have a current request ID variable.
4576 You can create a context information retriever for this object and
4577 assign a name to this current request ID. You can then, using the
4578 man:lttng-add-context(1) command, add this context field by name to
4579 the JUL or log4j <<channel,channel>>.
4581 To provide application-specific context fields in a Java application:
4583 . In the Java application's source code, import the LTTng-UST
4584 Java agent context classes and interfaces:
4589 import org.lttng.ust.agent.context.ContextInfoManager;
4590 import org.lttng.ust.agent.context.IContextInfoRetriever;
4594 . Create a context information retriever class, that is, a class which
4595 implements the `IContextInfoRetriever` interface:
4600 class MyContextInfoRetriever implements IContextInfoRetriever
4603 public Object retrieveContextInfo(String key)
4605 if (key.equals("intCtx")) {
4607 } else if (key.equals("strContext")) {
4608 return "context value!";
4617 This `retrieveContextInfo()` method is the only member of the
4618 `IContextInfoRetriever` interface. Its role is to return the current
4619 value of a state by name to create a context field. The names of the
4620 context fields and which state variables they return depends on your
4623 All primitive types and objects are supported as context fields.
4624 When `retrieveContextInfo()` returns an object, the context field
4625 serializer calls its `toString()` method to add a string field to
4626 event records. The method can also return `null`, which means that
4627 no context field is available for the required name.
4629 . Register an instance of your context information retriever class to
4630 the context information manager singleton:
4635 IContextInfoRetriever cir = new MyContextInfoRetriever();
4636 ContextInfoManager cim = ContextInfoManager.getInstance();
4637 cim.registerContextInfoRetriever("retrieverName", cir);
4641 . Before exiting the application, remove your context information
4642 retriever from the context information manager singleton:
4647 ContextInfoManager cim = ContextInfoManager.getInstance();
4648 cim.unregisterContextInfoRetriever("retrieverName");
4652 This is not strictly necessary, but it is recommended for a clean
4653 disposal of some manager's resources.
4655 . Build your Java application with LTTng-UST Java agent support as
4656 usual, following the procedure for either the <<jul,JUL>> or
4657 <<log4j,Apache log4j>> framework.
4660 .Provide application-specific context fields in a Java application.
4665 import java.util.logging.Handler;
4666 import java.util.logging.Logger;
4667 import org.lttng.ust.agent.jul.LttngLogHandler;
4668 import org.lttng.ust.agent.context.ContextInfoManager;
4669 import org.lttng.ust.agent.context.IContextInfoRetriever;
4673 // Our context information retriever class
4674 private static class MyContextInfoRetriever
4675 implements IContextInfoRetriever
4678 public Object retrieveContextInfo(String key) {
4679 if (key.equals("intCtx")) {
4681 } else if (key.equals("strContext")) {
4682 return "context value!";
4689 private static final int answer = 42;
4691 public static void main(String args[]) throws Exception
4693 // Get the context information manager instance
4694 ContextInfoManager cim = ContextInfoManager.getInstance();
4696 // Create and register our context information retriever
4697 IContextInfoRetriever cir = new MyContextInfoRetriever();
4698 cim.registerContextInfoRetriever("myRetriever", cir);
4701 Logger logger = Logger.getLogger("jello");
4703 // Create an LTTng-UST log handler
4704 Handler lttngUstLogHandler = new LttngLogHandler();
4706 // Add the LTTng-UST log handler to our logger
4707 logger.addHandler(lttngUstLogHandler);
4710 logger.info("some info");
4711 logger.warning("some warning");
4713 logger.finer("finer information; the answer is " + answer);
4715 logger.severe("error!");
4717 // Not mandatory, but cleaner
4718 logger.removeHandler(lttngUstLogHandler);
4719 lttngUstLogHandler.close();
4720 cim.unregisterContextInfoRetriever("myRetriever");
4729 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4732 <<creating-destroying-tracing-sessions,Create a tracing session>>
4733 and <<enabling-disabling-events,create an event rule>> matching the
4739 $ lttng enable-event --jul jello
4742 <<adding-context,Add the application-specific context fields>> to the
4747 $ lttng add-context --jul --type='$app.myRetriever:intCtx'
4748 $ lttng add-context --jul --type='$app.myRetriever:strContext'
4751 <<basic-tracing-session-control,Start tracing>>:
4758 Run the compiled class:
4762 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4765 <<basic-tracing-session-control,Stop tracing>> and inspect the
4777 [[python-application]]
4778 === User space Python agent
4780 You can instrument a Python{nbsp}2 or Python{nbsp}3 application which
4782 https://docs.python.org/3/library/logging.html[`logging`] package.
4784 Each log statement emits an LTTng event once the
4785 application module imports the
4786 <<lttng-ust-agents,LTTng-UST Python agent>> package.
4789 .A Python application importing the LTTng-UST Python agent.
4790 image::python-app.png[]
4792 To use the LTTng-UST Python agent:
4794 . In the Python application's source code, import the LTTng-UST Python
4804 The LTTng-UST Python agent automatically adds its logging handler to the
4805 root logger at import time.
4807 Any log statement that the application executes before this import does
4808 not emit an LTTng event.
4810 IMPORTANT: The LTTng-UST Python agent must be
4811 <<installing-lttng,installed>>.
4813 . Use log statements and logging configuration as usual.
4814 Since the LTTng-UST Python agent adds a handler to the _root_
4815 logger, you can trace any log statement from any logger.
4817 .Use the LTTng-UST Python agent.
4828 logging.basicConfig()
4829 logger = logging.getLogger('my-logger')
4832 logger.debug('debug message')
4833 logger.info('info message')
4834 logger.warn('warn message')
4835 logger.error('error message')
4836 logger.critical('critical message')
4840 if __name__ == '__main__':
4844 NOTE: `logging.basicConfig()`, which adds to the root logger a basic
4845 logging handler which prints to the standard error stream, is not
4846 strictly required for LTTng-UST tracing to work, but in versions of
4847 Python preceding{nbsp}3.2, you could see a warning message which indicates
4848 that no handler exists for the logger `my-logger`.
4850 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4851 <<enabling-disabling-events,create an event rule>> matching the
4852 `my-logger` Python logger, and <<basic-tracing-session-control,start
4858 $ lttng enable-event --python my-logger
4862 Run the Python script:
4869 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
4879 In the resulting trace, an <<event,event record>> generated by a Python
4880 application is named `lttng_python:event` and has the following fields:
4883 Logging time (string).
4886 Log record's message.
4892 Name of the function in which the log statement was executed.
4895 Line number at which the log statement was executed.
4898 Log level integer value.
4901 ID of the Python thread in which the log statement was executed.
4904 Name of the Python thread in which the log statement was executed.
4906 You can use the opt:lttng-enable-event(1):--loglevel or
4907 opt:lttng-enable-event(1):--loglevel-only option of the
4908 man:lttng-enable-event(1) command to target a range of Python log levels
4909 or a specific Python log level.
4911 When an application imports the LTTng-UST Python agent, the agent tries
4912 to register to a <<lttng-sessiond,session daemon>>. Note that you must
4913 <<start-sessiond,start the session daemon>> _before_ you run the Python
4914 application. If a session daemon is found, the agent tries to register
4915 to it during five seconds, after which the application continues
4916 without LTTng tracing support. You can override this timeout value with
4917 the env:LTTNG_UST_PYTHON_REGISTER_TIMEOUT environment variable
4920 If the session daemon stops while a Python application with an imported
4921 LTTng-UST Python agent runs, the agent retries to connect and to
4922 register to a session daemon every three seconds. You can override this
4923 delay with the env:LTTNG_UST_PYTHON_REGISTER_RETRY_DELAY environment
4928 [[proc-lttng-logger-abi]]
4931 The `lttng-tracer` Linux kernel module, part of
4932 <<lttng-modules,LTTng-modules>>, creates the special LTTng logger file
4933 path:{/proc/lttng-logger} when it's loaded. Any application can write
4934 text data to this file to emit an LTTng event.
4937 .An application writes to the LTTng logger file to emit an LTTng event.
4938 image::lttng-logger.png[]
4940 The LTTng logger is the quickest method--not the most efficient,
4941 however--to add instrumentation to an application. It is designed
4942 mostly to instrument shell scripts:
4946 $ echo "Some message, some $variable" > /proc/lttng-logger
4949 Any event that the LTTng logger emits is named `lttng_logger` and
4950 belongs to the Linux kernel <<domain,tracing domain>>. However, unlike
4951 other instrumentation points in the kernel tracing domain, **any Unix
4952 user** can <<enabling-disabling-events,create an event rule>> which
4953 matches its event name, not only the root user or users in the
4954 <<tracing-group,tracing group>>.
4956 To use the LTTng logger:
4958 * From any application, write text data to the path:{/proc/lttng-logger}
4961 The `msg` field of `lttng_logger` event records contains the
4964 NOTE: The maximum message length of an LTTng logger event is
4965 1024{nbsp}bytes. Writing more than this makes the LTTng logger emit more
4966 than one event to contain the remaining data.
4968 You should not use the LTTng logger to trace a user application which
4969 can be instrumented in a more efficient way, namely:
4971 * <<c-application,C and $$C++$$ applications>>.
4972 * <<java-application,Java applications>>.
4973 * <<python-application,Python applications>>.
4975 .Use the LTTng logger.
4980 echo 'Hello, World!' > /proc/lttng-logger
4982 df --human-readable --print-type / > /proc/lttng-logger
4985 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4986 <<enabling-disabling-events,create an event rule>> matching the
4987 `lttng_logger` Linux kernel tracepoint, and
4988 <<basic-tracing-session-control,start tracing>>:
4993 $ lttng enable-event --kernel lttng_logger
4997 Run the Bash script:
5004 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
5015 [[instrumenting-linux-kernel]]
5016 === LTTng kernel tracepoints
5018 NOTE: This section shows how to _add_ instrumentation points to the
5019 Linux kernel. The kernel's subsystems are already thoroughly
5020 instrumented at strategic places for LTTng when you
5021 <<installing-lttng,install>> the <<lttng-modules,LTTng-modules>>
5025 There are two methods to instrument the Linux kernel:
5027 . <<linux-add-lttng-layer,Add an LTTng layer>> over an existing ftrace
5028 tracepoint which uses the `TRACE_EVENT()` API.
5030 Choose this if you want to instrumentation a Linux kernel tree with an
5031 instrumentation point compatible with ftrace, perf, and SystemTap.
5033 . Use an <<linux-lttng-tracepoint-event,LTTng-only approach>> to
5034 instrument an out-of-tree kernel module.
5036 Choose this if you don't need ftrace, perf, or SystemTap support.
5040 [[linux-add-lttng-layer]]
5041 ==== [[instrumenting-linux-kernel-itself]][[mainline-trace-event]][[lttng-adaptation-layer]]Add an LTTng layer to an existing ftrace tracepoint
5043 This section shows how to add an LTTng layer to existing ftrace
5044 instrumentation using the `TRACE_EVENT()` API.
5046 This section does not document the `TRACE_EVENT()` macro. You can
5047 read the following articles to learn more about this API:
5049 * http://lwn.net/Articles/379903/[Using the TRACE_EVENT() macro (Part{nbsp}1)]
5050 * http://lwn.net/Articles/381064/[Using the TRACE_EVENT() macro (Part{nbsp}2)]
5051 * http://lwn.net/Articles/383362/[Using the TRACE_EVENT() macro (Part{nbsp}3)]
5053 The following procedure assumes that your ftrace tracepoints are
5054 correctly defined in their own header and that they are created in
5055 one source file using the `CREATE_TRACE_POINTS` definition.
5057 To add an LTTng layer over an existing ftrace tracepoint:
5059 . Make sure the following kernel configuration options are
5065 * `CONFIG_HIGH_RES_TIMERS`
5066 * `CONFIG_TRACEPOINTS`
5069 . Build the Linux source tree with your custom ftrace tracepoints.
5070 . Boot the resulting Linux image on your target system.
5072 Confirm that the tracepoints exist by looking for their names in the
5073 dir:{/sys/kernel/debug/tracing/events/subsys} directory, where `subsys`
5074 is your subsystem's name.
5076 . Get a copy of the latest LTTng-modules{nbsp}{revision}:
5081 $ cd $(mktemp -d) &&
5082 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.11.tar.bz2 &&
5083 tar -xf lttng-modules-latest-2.11.tar.bz2 &&
5084 cd lttng-modules-2.11.*
5088 . In dir:{instrumentation/events/lttng-module}, relative to the root
5089 of the LTTng-modules source tree, create a header file named
5090 +__subsys__.h+ for your custom subsystem +__subsys__+ and write your
5091 LTTng-modules tracepoint definitions using the LTTng-modules
5094 Start with this template:
5098 .path:{instrumentation/events/lttng-module/my_subsys.h}
5101 #define TRACE_SYSTEM my_subsys
5103 #if !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ)
5104 #define _LTTNG_MY_SUBSYS_H
5106 #include "../../../probes/lttng-tracepoint-event.h"
5107 #include <linux/tracepoint.h>
5109 LTTNG_TRACEPOINT_EVENT(
5111 * Format is identical to TRACE_EVENT()'s version for the three
5112 * following macro parameters:
5115 TP_PROTO(int my_int, const char *my_string),
5116 TP_ARGS(my_int, my_string),
5118 /* LTTng-modules specific macros */
5120 ctf_integer(int, my_int_field, my_int)
5121 ctf_string(my_bar_field, my_bar)
5125 #endif /* !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ) */
5127 #include "../../../probes/define_trace.h"
5131 The entries in the `TP_FIELDS()` section are the list of fields for the
5132 LTTng tracepoint. This is similar to the `TP_STRUCT__entry()` part of
5133 ftrace's `TRACE_EVENT()` macro.
5135 See <<lttng-modules-tp-fields,Tracepoint fields macros>> for a
5136 complete description of the available `ctf_*()` macros.
5138 . Create the LTTng-modules probe's kernel module C source file,
5139 +probes/lttng-probe-__subsys__.c+, where +__subsys__+ is your
5144 .path:{probes/lttng-probe-my-subsys.c}
5146 #include <linux/module.h>
5147 #include "../lttng-tracer.h"
5150 * Build-time verification of mismatch between mainline
5151 * TRACE_EVENT() arguments and the LTTng-modules adaptation
5152 * layer LTTNG_TRACEPOINT_EVENT() arguments.
5154 #include <trace/events/my_subsys.h>
5156 /* Create LTTng tracepoint probes */
5157 #define LTTNG_PACKAGE_BUILD
5158 #define CREATE_TRACE_POINTS
5159 #define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
5161 #include "../instrumentation/events/lttng-module/my_subsys.h"
5163 MODULE_LICENSE("GPL and additional rights");
5164 MODULE_AUTHOR("Your name <your-email>");
5165 MODULE_DESCRIPTION("LTTng my_subsys probes");
5166 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
5167 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
5168 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
5169 LTTNG_MODULES_EXTRAVERSION);
5173 . Edit path:{probes/KBuild} and add your new kernel module object
5174 next to the existing ones:
5178 .path:{probes/KBuild}
5182 obj-m += lttng-probe-module.o
5183 obj-m += lttng-probe-power.o
5185 obj-m += lttng-probe-my-subsys.o
5191 . Build and install the LTTng kernel modules:
5196 $ make KERNELDIR=/path/to/linux
5197 # make modules_install && depmod -a
5201 Replace `/path/to/linux` with the path to the Linux source tree where
5202 you defined and used tracepoints with ftrace's `TRACE_EVENT()` macro.
5204 Note that you can also use the
5205 <<lttng-tracepoint-event-code,`LTTNG_TRACEPOINT_EVENT_CODE()` macro>>
5206 instead of `LTTNG_TRACEPOINT_EVENT()` to use custom local variables and
5207 C code that need to be executed before the event fields are recorded.
5209 The best way to learn how to use the previous LTTng-modules macros is to
5210 inspect the existing LTTng-modules tracepoint definitions in the
5211 dir:{instrumentation/events/lttng-module} header files. Compare them
5212 with the Linux kernel mainline versions in the
5213 dir:{include/trace/events} directory of the Linux source tree.
5217 [[lttng-tracepoint-event-code]]
5218 ===== Use custom C code to access the data for tracepoint fields
5220 Although we recommended to always use the
5221 <<lttng-adaptation-layer,`LTTNG_TRACEPOINT_EVENT()`>> macro to describe
5222 the arguments and fields of an LTTng-modules tracepoint when possible,
5223 sometimes you need a more complex process to access the data that the
5224 tracer records as event record fields. In other words, you need local
5225 variables and multiple C{nbsp}statements instead of simple
5226 argument-based expressions that you pass to the
5227 <<lttng-modules-tp-fields,`ctf_*()` macros of `TP_FIELDS()`>>.
5229 You can use the `LTTNG_TRACEPOINT_EVENT_CODE()` macro instead of
5230 `LTTNG_TRACEPOINT_EVENT()` to declare custom local variables and define
5231 a block of C{nbsp}code to be executed before LTTng records the fields.
5232 The structure of this macro is:
5235 .`LTTNG_TRACEPOINT_EVENT_CODE()` macro syntax.
5237 LTTNG_TRACEPOINT_EVENT_CODE(
5239 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5240 * version for the following three macro parameters:
5243 TP_PROTO(int my_int, const char *my_string),
5244 TP_ARGS(my_int, my_string),
5246 /* Declarations of custom local variables */
5249 unsigned long b = 0;
5250 const char *name = "(undefined)";
5251 struct my_struct *my_struct;
5255 * Custom code which uses both tracepoint arguments
5256 * (in TP_ARGS()) and local variables (in TP_locvar()).
5258 * Local variables are actually members of a structure pointed
5259 * to by the special variable tp_locvar.
5263 tp_locvar->a = my_int + 17;
5264 tp_locvar->my_struct = get_my_struct_at(tp_locvar->a);
5265 tp_locvar->b = my_struct_compute_b(tp_locvar->my_struct);
5266 tp_locvar->name = my_struct_get_name(tp_locvar->my_struct);
5267 put_my_struct(tp_locvar->my_struct);
5276 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5277 * version for this, except that tp_locvar members can be
5278 * used in the argument expression parameters of
5279 * the ctf_*() macros.
5282 ctf_integer(unsigned long, my_struct_b, tp_locvar->b)
5283 ctf_integer(int, my_struct_a, tp_locvar->a)
5284 ctf_string(my_string_field, my_string)
5285 ctf_string(my_struct_name, tp_locvar->name)
5290 IMPORTANT: The C code defined in `TP_code()` must not have any side
5291 effects when executed. In particular, the code must not allocate
5292 memory or get resources without deallocating this memory or putting
5293 those resources afterwards.
5296 [[instrumenting-linux-kernel-tracing]]
5297 ==== Load and unload a custom probe kernel module
5299 You must load a <<lttng-adaptation-layer,created LTTng-modules probe
5300 kernel module>> in the kernel before it can emit LTTng events.
5302 To load the default probe kernel modules and a custom probe kernel
5305 * Use the opt:lttng-sessiond(8):--extra-kmod-probes option to give extra
5306 probe modules to load when starting a root <<lttng-sessiond,session
5310 .Load the `my_subsys`, `usb`, and the default probe modules.
5314 # lttng-sessiond --extra-kmod-probes=my_subsys,usb
5319 You only need to pass the subsystem name, not the whole kernel module
5322 To load _only_ a given custom probe kernel module:
5324 * Use the opt:lttng-sessiond(8):--kmod-probes option to give the probe
5325 modules to load when starting a root session daemon:
5328 .Load only the `my_subsys` and `usb` probe modules.
5332 # lttng-sessiond --kmod-probes=my_subsys,usb
5337 To confirm that a probe module is loaded:
5344 $ lsmod | grep lttng_probe_usb
5348 To unload the loaded probe modules:
5350 * Kill the session daemon with `SIGTERM`:
5355 # pkill lttng-sessiond
5359 You can also use man:modprobe(8)'s `--remove` option if the session
5360 daemon terminates abnormally.
5363 [[controlling-tracing]]
5366 Once an application or a Linux kernel is
5367 <<instrumenting,instrumented>> for LTTng tracing,
5370 This section is divided in topics on how to use the various
5371 <<plumbing,components of LTTng>>, in particular the <<lttng-cli,cmd:lttng
5372 command-line tool>>, to _control_ the LTTng daemons and tracers.
5374 NOTE: In the following subsections, we refer to an man:lttng(1) command
5375 using its man page name. For example, instead of _Run the `create`
5376 command to..._, we use _Run the man:lttng-create(1) command to..._.
5380 === Start a session daemon
5382 In some situations, you need to run a <<lttng-sessiond,session daemon>>
5383 (man:lttng-sessiond(8)) _before_ you can use the man:lttng(1)
5386 You will see the following error when you run a command while no session
5390 Error: No session daemon is available
5393 The only command that automatically runs a session daemon is
5394 man:lttng-create(1), which you use to
5395 <<creating-destroying-tracing-sessions,create a tracing session>>. While
5396 this is most of the time the first operation that you do, sometimes it's
5397 not. Some examples are:
5399 * <<list-instrumentation-points,List the available instrumentation points>>.
5400 * <<saving-loading-tracing-session,Load a tracing session configuration>>.
5402 [[tracing-group]] Each Unix user must have its own running session
5403 daemon to trace user applications. The session daemon that the root user
5404 starts is the only one allowed to control the LTTng kernel tracer. Users
5405 that are part of the _tracing group_ can control the root session
5406 daemon. The default tracing group name is `tracing`; you can set it to
5407 something else with the opt:lttng-sessiond(8):--group option when you
5408 start the root session daemon.
5410 To start a user session daemon:
5412 * Run man:lttng-sessiond(8):
5417 $ lttng-sessiond --daemonize
5421 To start the root session daemon:
5423 * Run man:lttng-sessiond(8) as the root user:
5428 # lttng-sessiond --daemonize
5432 In both cases, remove the opt:lttng-sessiond(8):--daemonize option to
5433 start the session daemon in foreground.
5435 To stop a session daemon, use man:kill(1) on its process ID (standard
5438 Note that some Linux distributions could manage the LTTng session daemon
5439 as a service. In this case, you should use the service manager to
5440 start, restart, and stop session daemons.
5443 [[creating-destroying-tracing-sessions]]
5444 === Create and destroy a tracing session
5446 Almost all the LTTng control operations happen in the scope of
5447 a <<tracing-session,tracing session>>, which is the dialogue between the
5448 <<lttng-sessiond,session daemon>> and you.
5450 To create a tracing session with a generated name:
5452 * Use the man:lttng-create(1) command:
5461 The created tracing session's name is `auto` followed by the
5464 To create a tracing session with a specific name:
5466 * Use the optional argument of the man:lttng-create(1) command:
5471 $ lttng create my-session
5475 Replace `my-session` with the specific tracing session name.
5477 LTTng appends the creation date to the created tracing session's name.
5479 LTTng writes the traces of a tracing session in
5480 +$LTTNG_HOME/lttng-trace/__name__+ by default, where +__name__+ is the
5481 name of the tracing session. Note that the env:LTTNG_HOME environment
5482 variable defaults to `$HOME` if not set.
5484 To output LTTng traces to a non-default location:
5486 * Use the opt:lttng-create(1):--output option of the man:lttng-create(1) command:
5491 $ lttng create my-session --output=/tmp/some-directory
5495 You may create as many tracing sessions as you wish.
5497 To list all the existing tracing sessions for your Unix user:
5499 * Use the man:lttng-list(1) command:
5508 When you create a tracing session, it is set as the _current tracing
5509 session_. The following man:lttng(1) commands operate on the current
5510 tracing session when you don't specify one:
5512 [role="list-3-cols"]
5513 * man:lttng-add-context(1)
5514 * man:lttng-destroy(1)
5515 * man:lttng-disable-channel(1)
5516 * man:lttng-disable-event(1)
5517 * man:lttng-disable-rotation(1)
5518 * man:lttng-enable-channel(1)
5519 * man:lttng-enable-event(1)
5520 * man:lttng-enable-rotation(1)
5522 * man:lttng-regenerate(1)
5523 * man:lttng-rotate(1)
5525 * man:lttng-snapshot(1)
5526 * man:lttng-start(1)
5527 * man:lttng-status(1)
5529 * man:lttng-track(1)
5530 * man:lttng-untrack(1)
5533 To change the current tracing session:
5535 * Use the man:lttng-set-session(1) command:
5540 $ lttng set-session new-session
5544 Replace `new-session` by the name of the new current tracing session.
5546 When you are done tracing in a given tracing session, you can destroy
5547 it. This operation frees the resources taken by the tracing session
5548 to destroy; it does not destroy the trace data that LTTng wrote for
5549 this tracing session.
5551 To destroy the current tracing session:
5553 * Use the man:lttng-destroy(1) command:
5562 The man:lttng-destroy(1) command also runs the man:lttng-stop(1)
5563 command implicitly (see <<basic-tracing-session-control,Start and stop a
5564 tracing session>>). You need to stop tracing to make LTTng flush the
5565 remaining trace data and make the trace readable.
5568 [[list-instrumentation-points]]
5569 === List the available instrumentation points
5571 The <<lttng-sessiond,session daemon>> can query the running instrumented
5572 user applications and the Linux kernel to get a list of available
5573 instrumentation points. For the Linux kernel <<domain,tracing domain>>,
5574 they are tracepoints and system calls. For the user space tracing
5575 domain, they are tracepoints. For the other tracing domains, they are
5578 To list the available instrumentation points:
5580 * Use the man:lttng-list(1) command with the requested tracing domain's
5584 * opt:lttng-list(1):--kernel: Linux kernel tracepoints (your Unix user
5585 must be a root user, or it must be a member of the
5586 <<tracing-group,tracing group>>).
5587 * opt:lttng-list(1):--kernel with opt:lttng-list(1):--syscall: Linux
5588 kernel system calls (your Unix user must be a root user, or it must be
5589 a member of the tracing group).
5590 * opt:lttng-list(1):--userspace: user space tracepoints.
5591 * opt:lttng-list(1):--jul: `java.util.logging` loggers.
5592 * opt:lttng-list(1):--log4j: Apache log4j loggers.
5593 * opt:lttng-list(1):--python: Python loggers.
5596 .List the available user space tracepoints.
5600 $ lttng list --userspace
5604 .List the available Linux kernel system call tracepoints.
5608 $ lttng list --kernel --syscall
5613 [[enabling-disabling-events]]
5614 === Create and enable an event rule
5616 Once you <<creating-destroying-tracing-sessions,create a tracing
5617 session>>, you can create <<event,event rules>> with the
5618 man:lttng-enable-event(1) command.
5620 You specify each condition with a command-line option. The available
5621 condition arguments are shown in the following table.
5623 [role="growable",cols="asciidoc,asciidoc,default"]
5624 .Condition command-line arguments for the man:lttng-enable-event(1) command.
5626 |Argument |Description |Applicable tracing domains
5632 . +--probe=__ADDR__+
5633 . +--function=__ADDR__+
5634 . +--userspace-probe=__PATH__:__SYMBOL__+
5635 . +--userspace-probe=sdt:__PATH__:__PROVIDER__:__NAME__+
5638 Instead of using the default _tracepoint_ instrumentation type, use:
5640 . A Linux system call (entry and exit).
5641 . A Linux https://lwn.net/Articles/132196/[kprobe] (symbol or address).
5642 . The entry and return points of a Linux function (symbol or address).
5643 . The entry point of a user application or library function (path to
5644 application/library and symbol).
5645 . A https://www.sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps[SystemTap
5646 Statically Defined Tracing] (SDT) probe (path to application/library,
5647 provider and probe names).
5651 |First positional argument.
5654 Tracepoint or system call name.
5656 With the opt:lttng-enable-event(1):--probe,
5657 opt:lttng-enable-event(1):--function, and
5658 opt:lttng-enable-event(1):--userspace-probe options, this is a custom
5659 name given to the event rule. With the JUL, log4j, and Python domains,
5660 this is a logger name.
5662 With a tracepoint, logger, or system call name, you can use the special
5663 `*` globbing character to match anything (for example, `sched_*`,
5671 . +--loglevel=__LEVEL__+
5672 . +--loglevel-only=__LEVEL__+
5675 . Match only tracepoints or log statements with a logging level at
5676 least as severe as +__LEVEL__+.
5677 . Match only tracepoints or log statements with a logging level
5678 equal to +__LEVEL__+.
5680 See man:lttng-enable-event(1) for the list of available logging level
5683 |User space, JUL, log4j, and Python.
5685 |+--exclude=__EXCLUSIONS__+
5688 When you use a `*` character at the end of the tracepoint or logger
5689 name (first positional argument), exclude the specific names in the
5690 comma-delimited list +__EXCLUSIONS__+.
5693 User space, JUL, log4j, and Python.
5695 |+--filter=__EXPR__+
5698 Match only events which satisfy the expression +__EXPR__+.
5700 See man:lttng-enable-event(1) to learn more about the syntax of a
5707 You attach an event rule to a <<channel,channel>> on creation. If you do
5708 not specify the channel with the opt:lttng-enable-event(1):--channel
5709 option, and if the event rule to create is the first in its
5710 <<domain,tracing domain>> for a given tracing session, then LTTng
5711 creates a _default channel_ for you. This default channel is reused in
5712 subsequent invocations of the man:lttng-enable-event(1) command for the
5713 same tracing domain.
5715 An event rule is always enabled at creation time.
5717 The following examples show how you can combine the previous
5718 command-line options to create simple to more complex event rules.
5720 .Create an event rule targetting a Linux kernel tracepoint (default channel).
5724 $ lttng enable-event --kernel sched_switch
5728 .Create an event rule matching four Linux kernel system calls (default channel).
5732 $ lttng enable-event --kernel --syscall open,write,read,close
5736 .Create event rules matching tracepoints with filter expressions (default channel).
5740 $ lttng enable-event --kernel sched_switch --filter='prev_comm == "bash"'
5745 $ lttng enable-event --kernel --all \
5746 --filter='$ctx.tid == 1988 || $ctx.tid == 1534'
5751 $ lttng enable-event --jul my_logger \
5752 --filter='$app.retriever:cur_msg_id > 3'
5755 IMPORTANT: Make sure to always quote the filter string when you
5756 use man:lttng(1) from a shell.
5759 .Create an event rule matching any user space tracepoint of a given tracepoint provider with a log level range (default channel).
5763 $ lttng enable-event --userspace my_app:'*' --loglevel=TRACE_INFO
5766 IMPORTANT: Make sure to always quote the wildcard character when you
5767 use man:lttng(1) from a shell.
5770 .Create an event rule matching multiple Python loggers with a wildcard and with exclusions (default channel).
5774 $ lttng enable-event --python my-app.'*' \
5775 --exclude='my-app.module,my-app.hello'
5779 .Create an event rule matching any Apache log4j logger with a specific log level (default channel).
5783 $ lttng enable-event --log4j --all --loglevel-only=LOG4J_WARN
5787 .Create an event rule attached to a specific channel matching a specific user space tracepoint provider and tracepoint.
5791 $ lttng enable-event --userspace my_app:my_tracepoint --channel=my-channel
5795 .Create an event rule matching the `malloc` function entry in path:{/usr/lib/libc.so.6}:
5799 $ lttng enable-event --kernel --userspace-probe=/usr/lib/libc.so.6:malloc \
5804 .Create an event rule matching the `server`/`accept_request` https://www.sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps[SDT probe] in path:{/usr/bin/serv}:
5808 $ lttng enable-event --kernel --userspace-probe=sdt:serv:server:accept_request \
5809 server_accept_request
5813 The event rules of a given channel form a whitelist: as soon as an
5814 emitted event passes one of them, LTTng can record the event. For
5815 example, an event named `my_app:my_tracepoint` emitted from a user space
5816 tracepoint with a `TRACE_ERROR` log level passes both of the following
5821 $ lttng enable-event --userspace my_app:my_tracepoint
5822 $ lttng enable-event --userspace my_app:my_tracepoint \
5823 --loglevel=TRACE_INFO
5826 The second event rule is redundant: the first one includes
5830 [[disable-event-rule]]
5831 === Disable an event rule
5833 To disable an event rule that you <<enabling-disabling-events,created>>
5834 previously, use the man:lttng-disable-event(1) command. This command
5835 disables _all_ the event rules (of a given tracing domain and channel)
5836 which match an instrumentation point. The other conditions are not
5837 supported as of LTTng{nbsp}{revision}.
5839 The LTTng tracer does not record an emitted event which passes
5840 a _disabled_ event rule.
5842 .Disable an event rule matching a Python logger (default channel).
5846 $ lttng disable-event --python my-logger
5850 .Disable an event rule matching all `java.util.logging` loggers (default channel).
5854 $ lttng disable-event --jul '*'
5858 .Disable _all_ the event rules of the default channel.
5860 The opt:lttng-disable-event(1):--all-events option is not, like the
5861 opt:lttng-enable-event(1):--all option of man:lttng-enable-event(1), the
5862 equivalent of the event name `*` (wildcard): it disables _all_ the event
5863 rules of a given channel.
5867 $ lttng disable-event --jul --all-events
5871 NOTE: You cannot delete an event rule once you create it.
5875 === Get the status of a tracing session
5877 To get the status of the current tracing session, that is, its
5878 parameters, its channels, event rules, and their attributes:
5880 * Use the man:lttng-status(1) command:
5890 To get the status of any tracing session:
5892 * Use the man:lttng-list(1) command with the tracing session's name:
5897 $ lttng list my-session
5901 Replace `my-session` with the desired tracing session's name.
5904 [[basic-tracing-session-control]]
5905 === Start and stop a tracing session
5907 Once you <<creating-destroying-tracing-sessions,create a tracing
5909 <<enabling-disabling-events,create one or more event rules>>,
5910 you can start and stop the tracers for this tracing session.
5912 To start tracing in the current tracing session:
5914 * Use the man:lttng-start(1) command:
5923 LTTng is very flexible: you can launch user applications before
5924 or after the you start the tracers. The tracers only record the events
5925 if they pass enabled event rules and if they occur while the tracers are
5928 To stop tracing in the current tracing session:
5930 * Use the man:lttng-stop(1) command:
5939 If there were <<channel-overwrite-mode-vs-discard-mode,lost event
5940 records>> or lost sub-buffers since the last time you ran
5941 man:lttng-start(1), warnings are printed when you run the
5942 man:lttng-stop(1) command.
5944 IMPORTANT: You need to stop tracing to make LTTng flush the remaining
5945 trace data and make the trace readable. Note that the
5946 man:lttng-destroy(1) command (see
5947 <<creating-destroying-tracing-sessions,Create and destroy a tracing
5948 session>>) also runs the man:lttng-stop(1) command implicitly.
5951 [[enabling-disabling-channels]]
5952 === Create a channel
5954 Once you create a tracing session, you can create a <<channel,channel>>
5955 with the man:lttng-enable-channel(1) command.
5957 Note that LTTng automatically creates a default channel when, for a
5958 given <<domain,tracing domain>>, no channels exist and you
5959 <<enabling-disabling-events,create>> the first event rule. This default
5960 channel is named `channel0` and its attributes are set to reasonable
5961 values. Therefore, you only need to create a channel when you need
5962 non-default attributes.
5964 You specify each non-default channel attribute with a command-line
5965 option when you use the man:lttng-enable-channel(1) command. The
5966 available command-line options are:
5968 [role="growable",cols="asciidoc,asciidoc"]
5969 .Command-line options for the man:lttng-enable-channel(1) command.
5971 |Option |Description
5977 <<channel-overwrite-mode-vs-discard-mode,event record loss mode>> instead
5978 of the default _discard_ mode.
5980 |`--buffers-pid` (user space tracing domain only)
5983 Use the per-process <<channel-buffering-schemes,buffering scheme>>
5984 instead of the default per-user buffering scheme.
5986 |+--subbuf-size=__SIZE__+
5989 Allocate sub-buffers of +__SIZE__+ bytes (power of two), for each CPU,
5990 either for each Unix user (default), or for each instrumented process.
5992 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
5994 |+--num-subbuf=__COUNT__+
5997 Allocate +__COUNT__+ sub-buffers (power of two), for each CPU, either
5998 for each Unix user (default), or for each instrumented process.
6000 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
6002 |+--tracefile-size=__SIZE__+
6005 Set the maximum size of each trace file that this channel writes within
6006 a stream to +__SIZE__+ bytes instead of no maximum.
6008 See <<tracefile-rotation,Trace file count and size>>.
6010 |+--tracefile-count=__COUNT__+
6013 Limit the number of trace files that this channel creates to
6014 +__COUNT__+ channels instead of no limit.
6016 See <<tracefile-rotation,Trace file count and size>>.
6018 |+--switch-timer=__PERIODUS__+
6021 Set the <<channel-switch-timer,switch timer period>>
6022 to +__PERIODUS__+{nbsp}µs.
6024 |+--read-timer=__PERIODUS__+
6027 Set the <<channel-read-timer,read timer period>>
6028 to +__PERIODUS__+{nbsp}µs.
6030 |[[opt-blocking-timeout]]+--blocking-timeout=__TIMEOUTUS__+
6033 Set the timeout of user space applications which load LTTng-UST
6034 in blocking mode to +__TIMEOUTUS__+:
6037 Never block (non-blocking mode).
6040 Block forever until space is available in a sub-buffer to record
6043 __n__, a positive value::
6044 Wait for at most __n__ µs when trying to write into a sub-buffer.
6046 Note that, for this option to have any effect on an instrumented
6047 user space application, you need to run the application with a set
6048 env:LTTNG_UST_ALLOW_BLOCKING environment variable.
6050 |+--output=__TYPE__+ (Linux kernel tracing domain only)
6053 Set the channel's output type to +__TYPE__+, either `mmap` or `splice`.
6057 You can only create a channel in the Linux kernel and user space
6058 <<domain,tracing domains>>: other tracing domains have their own channel
6059 created on the fly when <<enabling-disabling-events,creating event
6064 Because of a current LTTng limitation, you must create all channels
6065 _before_ you <<basic-tracing-session-control,start tracing>> in a given
6066 tracing session, that is, before the first time you run
6069 Since LTTng automatically creates a default channel when you use the
6070 man:lttng-enable-event(1) command with a specific tracing domain, you
6071 cannot, for example, create a Linux kernel event rule, start tracing,
6072 and then create a user space event rule, because no user space channel
6073 exists yet and it's too late to create one.
6075 For this reason, make sure to configure your channels properly
6076 before starting the tracers for the first time!
6079 The following examples show how you can combine the previous
6080 command-line options to create simple to more complex channels.
6082 .Create a Linux kernel channel with default attributes.
6086 $ lttng enable-channel --kernel my-channel
6090 .Create a user space channel with four sub-buffers or 1{nbsp}MiB each, per CPU, per instrumented process.
6094 $ lttng enable-channel --userspace --num-subbuf=4 --subbuf-size=1M \
6095 --buffers-pid my-channel
6099 .[[blocking-timeout-example]]Create a default user space channel with an infinite blocking timeout.
6101 <<creating-destroying-tracing-sessions,Create a tracing-session>>,
6102 create the channel, <<enabling-disabling-events,create an event rule>>,
6103 and <<basic-tracing-session-control,start tracing>>:
6108 $ lttng enable-channel --userspace --blocking-timeout=inf blocking-channel
6109 $ lttng enable-event --userspace --channel=blocking-channel --all
6113 Run an application instrumented with LTTng-UST and allow it to block:
6117 $ LTTNG_UST_ALLOW_BLOCKING=1 my-app
6121 .Create a Linux kernel channel which rotates eight trace files of 4{nbsp}MiB each for each stream
6125 $ lttng enable-channel --kernel --tracefile-count=8 \
6126 --tracefile-size=4194304 my-channel
6130 .Create a user space channel in overwrite (or _flight recorder_) mode.
6134 $ lttng enable-channel --userspace --overwrite my-channel
6138 You can <<enabling-disabling-events,create>> the same event rule in
6139 two different channels:
6143 $ lttng enable-event --userspace --channel=my-channel app:tp
6144 $ lttng enable-event --userspace --channel=other-channel app:tp
6147 If both channels are enabled, when a tracepoint named `app:tp` is
6148 reached, LTTng records two events, one for each channel.
6152 === Disable a channel
6154 To disable a specific channel that you <<enabling-disabling-channels,created>>
6155 previously, use the man:lttng-disable-channel(1) command.
6157 .Disable a specific Linux kernel channel.
6161 $ lttng disable-channel --kernel my-channel
6165 The state of a channel precedes the individual states of event rules
6166 attached to it: event rules which belong to a disabled channel, even if
6167 they are enabled, are also considered disabled.
6171 === Add context fields to a channel
6173 Event record fields in trace files provide important information about
6174 events that occured previously, but sometimes some external context may
6175 help you solve a problem faster. Examples of context fields are:
6177 * The **process ID**, **thread ID**, **process name**, and
6178 **process priority** of the thread in which the event occurs.
6179 * The **hostname** of the system on which the event occurs.
6180 * The Linux kernel and user call stacks (since
6181 LTTng{nbsp}{revision}).
6182 * The current values of many possible **performance counters** using
6184 ** CPU cycles, stalled cycles, idle cycles, and the other cycle types.
6186 ** Branch instructions, misses, and loads.
6188 * Any context defined at the application level (supported for the
6189 JUL and log4j <<domain,tracing domains>>).
6191 To get the full list of available context fields, see
6192 `lttng add-context --list`. Some context fields are reserved for a
6193 specific <<domain,tracing domain>> (Linux kernel or user space).
6195 You add context fields to <<channel,channels>>. All the events
6196 that a channel with added context fields records contain those fields.
6198 To add context fields to one or all the channels of a given tracing
6201 * Use the man:lttng-add-context(1) command.
6203 .Add context fields to all the channels of the current tracing session.
6205 The following command line adds the virtual process identifier and
6206 the per-thread CPU cycles count fields to all the user space channels
6207 of the current tracing session.
6211 $ lttng add-context --userspace --type=vpid --type=perf:thread:cpu-cycles
6215 .Add performance counter context fields by raw ID
6217 See man:lttng-add-context(1) for the exact format of the context field
6218 type, which is partly compatible with the format used in
6223 $ lttng add-context --userspace --type=perf:thread:raw:r0110:test
6224 $ lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted
6228 .Add context fields to a specific channel.
6230 The following command line adds the thread identifier and user call
6231 stack context fields to the Linux kernel channel named `my-channel` in
6232 the current tracing session.
6236 $ lttng add-context --kernel --channel=my-channel \
6237 --type=tid --type=callstack-user
6241 .Add an application-specific context field to a specific channel.
6243 The following command line adds the `cur_msg_id` context field of the
6244 `retriever` context retriever for all the instrumented
6245 <<java-application,Java applications>> recording <<event,event records>>
6246 in the channel named `my-channel`:
6250 $ lttng add-context --kernel --channel=my-channel \
6251 --type='$app:retriever:cur_msg_id'
6254 IMPORTANT: Make sure to always quote the `$` character when you
6255 use man:lttng-add-context(1) from a shell.
6258 NOTE: You cannot remove context fields from a channel once you add it.
6263 === Track process IDs
6265 It's often useful to allow only specific process IDs (PIDs) to emit
6266 events. For example, you may wish to record all the system calls made by
6267 a given process (Ă la http://linux.die.net/man/1/strace[strace]).
6269 The man:lttng-track(1) and man:lttng-untrack(1) commands serve this
6270 purpose. Both commands operate on a whitelist of process IDs. You _add_
6271 entries to this whitelist with the man:lttng-track(1) command and remove
6272 entries with the man:lttng-untrack(1) command. Any process which has one
6273 of the PIDs in the whitelist is allowed to emit LTTng events which pass
6274 an enabled <<event,event rule>>.
6276 NOTE: The PID tracker tracks the _numeric process IDs_. Should a
6277 process with a given tracked ID exit and another process be given this
6278 ID, then the latter would also be allowed to emit events.
6280 .Track and untrack process IDs.
6282 For the sake of the following example, assume the target system has
6283 16{nbsp}possible PIDs.
6286 <<creating-destroying-tracing-sessions,create a tracing session>>,
6287 the whitelist contains all the possible PIDs:
6290 .All PIDs are tracked.
6291 image::track-all.png[]
6293 When the whitelist is full and you use the man:lttng-track(1) command to
6294 specify some PIDs to track, LTTng first clears the whitelist, then it
6295 tracks the specific PIDs. After:
6299 $ lttng track --pid=3,4,7,10,13
6305 .PIDs 3, 4, 7, 10, and 13 are tracked.
6306 image::track-3-4-7-10-13.png[]
6308 You can add more PIDs to the whitelist afterwards:
6312 $ lttng track --pid=1,15,16
6318 .PIDs 1, 15, and 16 are added to the whitelist.
6319 image::track-1-3-4-7-10-13-15-16.png[]
6321 The man:lttng-untrack(1) command removes entries from the PID tracker's
6322 whitelist. Given the previous example, the following command:
6326 $ lttng untrack --pid=3,7,10,13
6329 leads to this whitelist:
6332 .PIDs 3, 7, 10, and 13 are removed from the whitelist.
6333 image::track-1-4-15-16.png[]
6335 LTTng can track all possible PIDs again using the
6336 opt:lttng-track(1):--all option:
6340 $ lttng track --pid --all
6343 The result is, again:
6346 .All PIDs are tracked.
6347 image::track-all.png[]
6350 .Track only specific PIDs
6352 A very typical use case with PID tracking is to start with an empty
6353 whitelist, then <<basic-tracing-session-control,start the tracers>>, and
6354 then add PIDs manually while tracers are active. You can accomplish this
6355 by using the opt:lttng-untrack(1):--all option of the
6356 man:lttng-untrack(1) command to clear the whitelist after you
6357 <<creating-destroying-tracing-sessions,create a tracing session>>:
6361 $ lttng untrack --pid --all
6367 .No PIDs are tracked.
6368 image::untrack-all.png[]
6370 If you trace with this whitelist configuration, the tracer records no
6371 events for this <<domain,tracing domain>> because no processes are
6372 tracked. You can use the man:lttng-track(1) command as usual to track
6373 specific PIDs, for example:
6377 $ lttng track --pid=6,11
6383 .PIDs 6 and 11 are tracked.
6384 image::track-6-11.png[]
6389 [[saving-loading-tracing-session]]
6390 === Save and load tracing session configurations
6392 Configuring a <<tracing-session,tracing session>> can be long. Some of
6393 the tasks involved are:
6395 * <<enabling-disabling-channels,Create channels>> with
6396 specific attributes.
6397 * <<adding-context,Add context fields>> to specific channels.
6398 * <<enabling-disabling-events,Create event rules>> with specific log
6399 level and filter conditions.
6401 If you use LTTng to solve real world problems, chances are you have to
6402 record events using the same tracing session setup over and over,
6403 modifying a few variables each time in your instrumented program
6404 or environment. To avoid constant tracing session reconfiguration,
6405 the man:lttng(1) command-line tool can save and load tracing session
6406 configurations to/from XML files.
6408 To save a given tracing session configuration:
6410 * Use the man:lttng-save(1) command:
6415 $ lttng save my-session
6419 Replace `my-session` with the name of the tracing session to save.
6421 LTTng saves tracing session configurations to
6422 dir:{$LTTNG_HOME/.lttng/sessions} by default. Note that the
6423 env:LTTNG_HOME environment variable defaults to `$HOME` if not set. Use
6424 the opt:lttng-save(1):--output-path option to change this destination
6427 LTTng saves all configuration parameters, for example:
6429 * The tracing session name.
6430 * The trace data output path.
6431 * The channels with their state and all their attributes.
6432 * The context fields you added to channels.
6433 * The event rules with their state, log level and filter conditions.
6435 To load a tracing session:
6437 * Use the man:lttng-load(1) command:
6442 $ lttng load my-session
6446 Replace `my-session` with the name of the tracing session to load.
6448 When LTTng loads a configuration, it restores your saved tracing session
6449 as if you just configured it manually.
6451 See man:lttng(1) for the complete list of command-line options. You
6452 can also save and load all many sessions at a time, and decide in which
6453 directory to output the XML files.
6456 [[sending-trace-data-over-the-network]]
6457 === Send trace data over the network
6459 LTTng can send the recorded trace data to a remote system over the
6460 network instead of writing it to the local file system.
6462 To send the trace data over the network:
6464 . On the _remote_ system (which can also be the target system),
6465 start an LTTng <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)):
6474 . On the _target_ system, create a tracing session configured to
6475 send trace data over the network:
6480 $ lttng create my-session --set-url=net://remote-system
6484 Replace `remote-system` by the host name or IP address of the
6485 remote system. See man:lttng-create(1) for the exact URL format.
6487 . On the target system, use the man:lttng(1) command-line tool as usual.
6488 When tracing is active, the target's consumer daemon sends sub-buffers
6489 to the relay daemon running on the remote system instead of flushing
6490 them to the local file system. The relay daemon writes the received
6491 packets to the local file system.
6493 The relay daemon writes trace files to
6494 +$LTTNG_HOME/lttng-traces/__hostname__/__session__+ by default, where
6495 +__hostname__+ is the host name of the target system and +__session__+
6496 is the tracing session name. Note that the env:LTTNG_HOME environment
6497 variable defaults to `$HOME` if not set. Use the
6498 opt:lttng-relayd(8):--output option of man:lttng-relayd(8) to write
6499 trace files to another base directory.
6504 === View events as LTTng emits them (noch:{LTTng} live)
6506 LTTng live is a network protocol implemented by the <<lttng-relayd,relay
6507 daemon>> (man:lttng-relayd(8)) to allow compatible trace viewers to
6508 display events as LTTng emits them on the target system while tracing is
6511 The relay daemon creates a _tee_: it forwards the trace data to both
6512 the local file system and to connected live viewers:
6515 .The relay daemon creates a _tee_, forwarding the trace data to both trace files and a connected live viewer.
6520 . On the _target system_, create a <<tracing-session,tracing session>>
6526 $ lttng create my-session --live
6530 This spawns a local relay daemon.
6532 . Start the live viewer and configure it to connect to the relay
6533 daemon. For example, with http://diamon.org/babeltrace[Babeltrace]:
6538 $ babeltrace --input-format=lttng-live \
6539 net://localhost/host/hostname/my-session
6546 * `hostname` with the host name of the target system.
6547 * `my-session` with the name of the tracing session to view.
6550 . Configure the tracing session as usual with the man:lttng(1)
6551 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6553 You can list the available live tracing sessions with Babeltrace:
6557 $ babeltrace --input-format=lttng-live net://localhost
6560 You can start the relay daemon on another system. In this case, you need
6561 to specify the relay daemon's URL when you create the tracing session
6562 with the opt:lttng-create(1):--set-url option. You also need to replace
6563 `localhost` in the procedure above with the host name of the system on
6564 which the relay daemon is running.
6566 See man:lttng-create(1) and man:lttng-relayd(8) for the complete list of
6567 command-line options.
6571 [[taking-a-snapshot]]
6572 === Take a snapshot of the current sub-buffers of a tracing session
6574 The normal behavior of LTTng is to append full sub-buffers to growing
6575 trace data files. This is ideal to keep a full history of the events
6576 that occurred on the target system, but it can
6577 represent too much data in some situations. For example, you may wish
6578 to trace your application continuously until some critical situation
6579 happens, in which case you only need the latest few recorded
6580 events to perform the desired analysis, not multi-gigabyte trace files.
6582 With the man:lttng-snapshot(1) command, you can take a snapshot of the
6583 current sub-buffers of a given <<tracing-session,tracing session>>.
6584 LTTng can write the snapshot to the local file system or send it over
6588 .A snapshot is a copy of the current sub-buffers, which are not cleared after the operation.
6589 image::snapshot.png[]
6591 If you wish to create unmanaged, self-contained, non-overlapping
6592 trace chunk archives instead of a simple copy of the current
6593 sub-buffers, see the <<session-rotation,tracing session rotation>>
6594 feature (available since LTTng{nbsp}2.11).
6598 . Create a tracing session in _snapshot mode_:
6603 $ lttng create my-session --snapshot
6607 The <<channel-overwrite-mode-vs-discard-mode,event record loss mode>> of
6608 <<channel,channels>> created in this mode is automatically set to
6609 _overwrite_ (flight recorder mode).
6611 . Configure the tracing session as usual with the man:lttng(1)
6612 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6614 . **Optional**: When you need to take a snapshot,
6615 <<basic-tracing-session-control,stop tracing>>.
6617 You can take a snapshot when the tracers are active, but if you stop
6618 them first, you are sure that the data in the sub-buffers does not
6619 change before you actually take the snapshot.
6626 $ lttng snapshot record --name=my-first-snapshot
6630 LTTng writes the current sub-buffers of all the current tracing
6631 session's channels to trace files on the local file system. Those trace
6632 files have `my-first-snapshot` in their name.
6634 There is no difference between the format of a normal trace file and the
6635 format of a snapshot: viewers of LTTng traces also support LTTng
6638 By default, LTTng writes snapshot files to the path shown by
6639 `lttng snapshot list-output`. You can change this path or decide to send
6640 snapshots over the network using either:
6642 . An output path or URL that you specify when you
6643 <<creating-destroying-tracing-sessions,create the tracing session>>.
6644 . A snapshot output path or URL that you add using
6645 `lttng snapshot add-output`.
6646 . An output path or URL that you provide directly to the
6647 `lttng snapshot record` command.
6649 Method{nbsp}3 overrides method{nbsp}2, which overrides method 1. When
6650 you specify a URL, a relay daemon must listen on a remote system (see
6651 <<sending-trace-data-over-the-network,Send trace data over the
6656 [[session-rotation]]
6657 === Archive the current trace chunk (rotate a tracing session)
6659 The <<taking-a-snapshot,snapshot user guide>> shows how you can dump
6660 a tracing session's current sub-buffers to the file system or send them
6661 over the network. When you take a snapshot, LTTng does not clear the
6662 tracing session's ring buffers: if you take another snapshot immediately
6663 after, both snapshots could contain overlapping trace data.
6665 Inspired by https://en.wikipedia.org/wiki/Log_rotation[log rotation],
6666 _tracing session rotation_ is a feature which appends the content of the
6667 ring buffers to what's already on the file system or sent over the
6668 network since the tracing session's creation or since the last
6669 rotation, and then clears those ring buffers to avoid trace data
6672 What LTTng is about to write when performing a tracing session rotation
6673 is called the _current trace chunk_. When this current trace chunk is
6674 written to the file system or sent over the network, it is called a
6675 _trace chunk archive_. Therefore, a tracing session rotation _archives_
6676 the current trace chunk.
6679 .A tracing session rotation operation _archives_ the current trace chunk.
6680 image::rotation.png[]
6682 A trace chunk archive is a self-contained LTTng trace and is not managed
6683 anymore by LTTng: you can read it, modify it, move it, or remove it.
6685 There are two methods to perform a tracing session rotation:
6686 immediately or automatically.
6688 To perform an immediate tracing session rotation:
6690 . <<creating-destroying-tracing-sessions,Create a tracing session>>
6691 in _normal mode_ or _network streaming mode_
6692 (only those two creation modes support tracing session rotation):
6697 $ lttng create my-session
6701 . <<enabling-disabling-events,Create one or more event rules>>
6702 and <<basic-tracing-session-control,start tracing>>:
6707 $ lttng enable-event --kernel sched_'*'
6712 . When needed, immediately rotate the current tracing session:
6721 The cmd:lttng-rotate command prints the path to the created trace
6722 chunk archive. See man:lttng-rotate(1) to learn about the format
6723 of trace chunk archive directory names.
6725 You can perform other immediate rotations while the tracing session is
6726 active. It is guaranteed that all the trace chunk archives do not
6727 contain overlapping trace data. You can also perform an immediate
6728 rotation once the tracing session is
6729 <<basic-tracing-session-control,stopped>>.
6731 . When you are done tracing,
6732 <<creating-destroying-tracing-sessions,destroy the current tracing
6742 The tracing session destruction operation creates one last trace
6743 chunk archive from the current trace chunk.
6745 An automatic tracing session rotation is a rotation which LTTng
6746 performs automatically based on one of the following conditions:
6748 * A timer with a configured period times out.
6749 * The total size of the flushed part of the current trace chunk
6750 becomes greater than or equal to a configured value.
6752 To configure a future, automatic tracing session rotation, you need
6753 to set a _rotation schedule_.
6755 To set a rotation schedule:
6757 . <<creating-destroying-tracing-sessions,Create a tracing session>>
6758 in _normal mode_ or _network streaming mode_
6759 (only those two creation modes support tracing session rotation):
6764 $ lttng create my-session
6768 . <<enabling-disabling-events,Create one or more event rules>>:
6773 $ lttng enable-event --kernel sched_'*'
6777 . Set a tracing session rotation schedule:
6782 $ lttng enable-rotation --timer=12s
6786 In this example, we set a rotation schedule so that LTTng performs a
6787 tracing session rotation every 12{nbsp}seconds.
6789 See man:lttng-enable-rotation(1) to learn more about other ways to set a
6792 . <<basic-tracing-session-control,Start tracing>>:
6801 LTTng performs tracing session rotations automatically while the tracing
6802 session is active thanks to the rotation schedule.
6804 . When you are done tracing,
6805 <<creating-destroying-tracing-sessions,destroy the current tracing
6815 The tracing session destruction operation creates one last trace chunk
6816 archive from the current trace chunk.
6818 You can use man:lttng-disable-rotation(1) to unset an a tracing session
6821 NOTE: man:lttng-rotate(1) and man:lttng-enable-rotation(1) list
6822 limitations regarding those two commands.
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.11/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{nbsp}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{nbsp}2) and running it again (step{nbsp}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{nbsp}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{nbsp}16.
7370 Argument expression.
7372 |+ctf_integer_oct(__t__, __n__, __e__)+
7374 Standard integer, displayed in base{nbsp}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{nbsp}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{nbsp}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{nbsp}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{nbsp}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, libraries, and Python bindings.
7691 [[def-buffering-scheme]]<<channel-buffering-schemes,buffering scheme>>::
7692 A layout of <<def-sub-buffer,sub-buffers>> applied to a given channel.
7694 <<channel,channel>>::
7695 An entity which is responsible for a set of
7696 <<def-ring-buffer,ring buffers>>.
7698 <<event,Event rules>> are always attached to a specific channel.
7701 A source of time for a <<def-tracer,tracer>>.
7703 <<lttng-consumerd,consumer daemon>>::
7704 A process which is responsible for consuming the full
7705 <<def-sub-buffer,sub-buffers>> and write them to a file system or
7706 send them over the network.
7708 [[def-current-trace-chunk]]current trace chunk::
7709 A <<def-trace-chunk,trace chunk>> which includes the current content
7710 of all the <<tracing-session,tracing session>>'s
7711 <<def-sub-buffer,sub-buffers>> and the stream files produced since the
7712 latest event amongst:
7714 * The creation of the tracing session.
7715 * The last <<session-rotation,tracing session rotation>>, if any.
7717 <<channel-overwrite-mode-vs-discard-mode,discard mode>>:: The event
7718 record loss mode in which the <<def-tracer,tracer>> _discards_ new
7719 event records when there's no
7720 <<def-sub-buffer,sub-buffer>> space left to store them.
7722 [[def-event]]event::
7723 The consequence of the execution of an
7724 <<def-instrumentation-point,instrumentation point>>, like a
7725 <<def-tracepoint,tracepoint>> that you manually place in some source
7726 code, or a Linux kernel kprobe.
7728 An event is said to _occur_ at a specific time. Different actions can
7729 be taken upon the occurrence of an event, like record the event's payload
7730 to a <<def-sub-buffer,sub-buffer>>.
7732 [[def-event-name]]event name::
7733 The name of an event, which is also the name of the event record.
7734 This is also called the _instrumentation point name_.
7736 [[def-event-record]]event record::
7737 A record, in a <<def-trace,trace>>, of the payload of an event
7740 [[def-event-record-loss-mode]]<<channel-overwrite-mode-vs-discard-mode,event record loss mode>>::
7741 The mechanism by which event records of a given <<channel,channel>>
7742 are lost (not recorded) when there is no <<def-sub-buffer,sub-buffer>>
7743 space left to store them.
7745 <<event,event rule>>::
7746 Set of conditions which must be satisfied for one or more occuring
7747 events to be recorded.
7749 `java.util.logging`::
7751 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[core logging facilities].
7753 <<instrumenting,instrumentation>>::
7754 The use of LTTng probes to make a piece of software traceable.
7756 [[def-instrumentation-point]]instrumentation point::
7757 A point in the execution path of a piece of software that, when
7758 reached by this execution, can emit an <<def-event,event>>.
7760 instrumentation point name::
7761 See _<<def-event-name,event name>>_.
7764 A http://logging.apache.org/log4j/1.2/[logging library] for Java
7765 developed by the Apache Software Foundation.
7768 Level of severity of a log statement or user space
7769 instrumentation point.
7772 The _Linux Trace Toolkit: next generation_ project.
7774 <<lttng-cli,cmd:lttng>>::
7775 A command-line tool provided by the LTTng-tools project which you
7776 can use to send and receive control messages to and from a
7780 The https://github.com/lttng/lttng-analyses[LTTng analyses] project,
7781 which is a set of analyzing programs that are used to obtain a
7782 higher level view of an LTTng <<def-trace,trace>>.
7784 cmd:lttng-consumerd::
7785 The name of the consumer daemon program.
7788 A utility provided by the LTTng-tools project which can convert
7789 <<def-ring-buffer,ring buffer>> files (usually
7790 <<persistent-memory-file-systems,saved on a persistent memory file system>>)
7791 to <<def-trace,trace>> files.
7793 LTTng Documentation::
7796 <<lttng-live,LTTng live>>::
7797 A communication protocol between the <<lttng-relayd,relay daemon>> and
7798 live viewers which makes it possible to see <<def-event-record,event
7799 records>> "live", as they are received by the relay daemon.
7801 <<lttng-modules,LTTng-modules>>::
7802 The https://github.com/lttng/lttng-modules[LTTng-modules] project,
7803 which contains the Linux kernel modules to make the Linux kernel
7804 <<def-instrumentation-point,instrumentation points>> available for
7808 The name of the <<lttng-relayd,relay daemon>> program.
7810 cmd:lttng-sessiond::
7811 The name of the <<lttng-sessiond,session daemon>> program.
7814 The https://github.com/lttng/lttng-tools[LTTng-tools] project, which
7815 contains the various programs and libraries used to
7816 <<controlling-tracing,control tracing>>.
7818 <<lttng-ust,LTTng-UST>>::
7819 The https://github.com/lttng/lttng-ust[LTTng-UST] project, which
7820 contains libraries to instrument
7821 <<def-user-application,user applications>>.
7823 <<lttng-ust-agents,LTTng-UST Java agent>>::
7824 A Java package provided by the LTTng-UST project to allow the
7825 LTTng instrumentation of `java.util.logging` and Apache log4j{nbsp}1.2
7828 <<lttng-ust-agents,LTTng-UST Python agent>>::
7829 A Python package provided by the LTTng-UST project to allow the
7830 LTTng instrumentation of Python logging statements.
7832 <<channel-overwrite-mode-vs-discard-mode,overwrite mode>>::
7833 The <<def-event-record-loss-mode,event record loss mode>> in which new
7834 <<def-event-record,event records>> _overwrite_ older event records
7835 when there's no <<def-sub-buffer,sub-buffer>> space left to store
7838 <<channel-buffering-schemes,per-process buffering>>::
7839 A <<def-buffering-scheme,buffering scheme>> in which each instrumented
7840 process has its own <<def-sub-buffer,sub-buffers>> for a given user
7841 space <<channel,channel>>.
7843 <<channel-buffering-schemes,per-user buffering>>::
7844 A <<def-buffering-scheme,buffering scheme>> in which all the processes
7845 of a Unix user share the same <<def-sub-buffer,sub-buffers>> for a
7846 given user space <<channel,channel>>.
7848 <<lttng-relayd,relay daemon>>::
7849 A process which is responsible for receiving the <<def-trace,trace>>
7850 data sent by a distant <<lttng-consumerd,consumer daemon>>.
7852 [[def-ring-buffer]]ring buffer::
7853 A set of <<def-sub-buffer,sub-buffers>>.
7856 See _<<def-tracing-session-rotation,tracing session rotation>>_.
7858 <<lttng-sessiond,session daemon>>::
7859 A process which receives control commands from you and orchestrates
7860 the <<def-tracer,tracers>> and various LTTng daemons.
7862 <<taking-a-snapshot,snapshot>>::
7863 A copy of the current data of all the <<def-sub-buffer,sub-buffers>>
7864 of a given <<tracing-session,tracing session>>, saved as
7865 <<def-trace,trace>> files.
7867 [[def-sub-buffer]]sub-buffer::
7868 One part of an LTTng <<def-ring-buffer,ring buffer>> which contains
7869 <<def-event-record,event records>>.
7872 The time information attached to an
7873 <<def-event,event>> when it is emitted.
7875 [[def-trace]]trace (_noun_)::
7878 * One http://diamon.org/ctf/[CTF] metadata stream file.
7879 * One or more CTF data stream files which are the concatenations of one
7880 or more flushed <<def-sub-buffer,sub-buffers>>.
7883 The action of recording the <<def-event,events>> emitted by an
7884 application or by a system, or to initiate such recording by
7885 controlling a tracer.
7887 [[def-trace-chunk]]trace chunk::
7888 A self-contained trace which is part of a <<tracing-session,tracing
7889 session>>. Each <<session-rotation, tracing session rotation>>
7890 produces a trace chunk archive.
7892 trace chunk archive::
7893 The result of a <<session-rotation, tracing session rotation>>. A
7894 trace chunk archive is not managed by LTTng, even if its containing
7895 <<tracing-session,tracing session>> is still active: you are free to
7896 read it, modify it, move it, or remove it.
7899 The http://tracecompass.org[Trace Compass] project and application.
7901 [[def-tracepoint]]tracepoint::
7902 An instrumentation point using the tracepoint mechanism of the Linux
7903 kernel or of LTTng-UST.
7905 tracepoint definition::
7906 The definition of a single tracepoint.
7909 The name of a tracepoint.
7911 tracepoint provider::
7912 A set of functions providing tracepoints to an instrumented user
7915 Not to be confused with a _tracepoint provider package_: many tracepoint
7916 providers can exist within a tracepoint provider package.
7918 tracepoint provider package::
7919 One or more tracepoint providers compiled as an
7920 https://en.wikipedia.org/wiki/Object_file[object file] or as
7921 a link:https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries[shared library].
7923 [[def-tracer]]tracer::
7924 A software which records emitted <<def-event,events>>.
7926 <<domain,tracing domain>>::
7927 A namespace for <<def-event,event>> sources.
7929 <<tracing-group,tracing group>>::
7930 The Unix group in which a Unix user can be to be allowed to trace the
7933 [[def-tracing-session-rotation]]<<tracing-session,tracing session>>::
7934 A stateful dialogue between you and a <<lttng-sessiond,session
7937 <<session-rotation,tracing session rotation>>::
7938 The action of archiving the
7939 <<def-current-trace-chunk,current trace chunk>> of a
7940 <<tracing-session,tracing session>>.
7942 [[def-user-application]]user application::
7943 An application running in user space, as opposed to a Linux kernel
7944 module, for example.