1 The LTTng Documentation
2 =======================
3 Philippe Proulx <pproulx@efficios.com>
7 include::../common/copyright.txt[]
10 include::../common/welcome.txt[]
13 include::../common/audience.txt[]
17 === What's in this documentation?
19 The LTTng Documentation is divided into the following sections:
21 * **<<nuts-and-bolts,Nuts and bolts>>** explains the
22 rudiments of software tracing and the rationale behind the
25 Skip this section if you’re familiar with software tracing and with the
28 * **<<installing-lttng,Installation>>** describes the steps to
29 install the LTTng packages on common Linux distributions and from
32 Skip this section if you already properly installed LTTng on your target
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 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 Skip this section if you don't 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 _Ta Meilleure_, a Northeast IPA
78 beer brewed by https://lagabiere.com/[Lagabière]. Translating to ``Your
79 best one'', this beer gives out strong aromas of passion fruit, lemon,
80 and peaches. Tastewise, expect a lot of fruit, a creamy texture, and a
81 smooth lingering hop bitterness.
83 New features and changes in LTTng{nbsp}{revision}:
87 * Clear the contents of one or more <<tracing-session,tracing sessions>>
88 without having to destroy and reconfigure them
89 with the new man:lttng-clear(1) command.
91 This is especially useful to clear a tracing session's tracing data
92 between attempts to reproduce a problem.
94 See <<clear,Clear a tracing session>>.
96 * Before LTTng{nbsp}{revision}, the man:lttng-track(1) and
97 man:lttng-untrack(1) commands used to add and remove process IDs
98 (PIDs) to a whitelist so that LTTng would only trace processes with
101 LTTng{nbsp}{revision} adds Unix user IDs (UIDs) and Unix group IDs
102 (GIDs) to the available <<pid-tracking,process attributes to track>>.
103 You can specify numeric user/group IDs and user/group names to track,
108 $ lttng track --userspace --vuid=http,999 --vgid=mysql,9
111 While you can also track UIDs and GIDs with the
112 opt:lttng-enable-event(1):--filter option of the `enable-event` command,
113 this dedicated process attribute tracking approach reduces tracing
114 overhead and prevents the creation of <<def-sub-buffer,sub-buffers>> for
115 the users and groups which LTTng doesn't track.
117 In the command manual pages, the term ``whitelist'' is renamed to
118 ``inclusion set'' to clarify the concept.
120 * The <<lttng-relayd,relay daemon>> can now maintain many files
121 virtually opened without using as many file descriptors (FD). It does
122 so by closing and reopening FDs as needed.
124 This feature is meant as a workaround for users who can't bump the
125 system limit because of permission restrictions.
127 The new opt:lttng-relayd(8):--fd-pool-size relay daemon option
128 sets the maximum number of simultaneously opened file descriptors
129 (using the soft `RLIMIT_NOFILE` resource limit of the process by
130 default; see man:getrlimit(2)).
132 * By default, the relay daemon writes its traces under a predefined
134 +$LTTNG_HOME/lttng-traces/__host__/__session__/__domain__+, with:
141 <<tracing-session,Tracing session>> name.
144 <<domain,Tracing domain>> name (`ust` or `kernel`).
147 Change this hierarchy to group traces by tracing session name rather
149 (+$LTTNG_HOME/lttng-traces/__session__/__host__/__domain__+) with the
150 new relay daemon's opt:lttng-relayd(8):--group-output-by-session option.
152 This feature is especially useful if you're tracing two or more hosts,
153 having different hostnames, which share the same tracing session name as
154 part of their configuration. In this scenario, you can use a descriptive
155 tracing session name (for example, `connection-hang`) across a fleet of
156 machines streaming to a single relay daemon.
158 * The relay daemon has a new opt:lttng-relayd(8):--working-directory
159 option to override its working directory.
161 Linux kernel tracing::
163 * New instrumentation hooks to trace the entry and exit tracepoints of
164 the network reception code paths of the Linux kernel.
166 Use the resulting event records to identify the bounds of a network
167 reception and link the events that occur in the interim (for example,
168 wake-ups) to a specific network reception instance. You can also
169 analyze the network stack's latency thanks to those event records.
171 * The `irqaction` structure's `thread` field, which specifies the
172 process to wake up when a threaded interrupt request (IRQ) occurs, is
173 now part of the `lttng_statedump_interrupt` event record.
175 Use this information to discover which processes handle the various
176 IRQs. You can also associate the events occurring in the context of
177 those processes with their respective IRQ.
179 * New `lttng_statedump_cpu_topology` tracepoint to record the active
182 Use this information to discover which CPUs are SMT siblings or part of
183 the same socket. As of LTTng{nbsp}{revision}, only the x86 architecture
184 is supported since all architectures describe their topologies
187 The tracepoint's `architecture` field is statically defined and exists
188 for all architecture implementations. Analysis tools can therefore
189 anticipate the event record's layout.
191 Event record example:
195 lttng_statedump_cpu_topology:
201 model_name: Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz
207 * New product UUID metadata environment field, `product_uuid`,
208 which LTTng copies from the
209 https://en.wikipedia.org/wiki/Desktop_Management_Interface[Desktop
210 Management Interface] (DMI).
212 Use this environment field to uniquely identify a machine (virtual or
213 physical) in order to correlate traces from multiple virtual machines.
219 What is LTTng? As its name suggests, the _Linux Trace Toolkit: next
220 generation_ is a modern toolkit for tracing Linux systems and
221 applications. So your first question might be:
228 As the history of software engineering progressed and led to what
229 we now take for granted--complex, numerous and
230 interdependent software applications running in parallel on
231 sophisticated operating systems like Linux--the authors of such
232 components, software developers, began feeling a natural
233 urge to have tools that would ensure the robustness and good performance
234 of their masterpieces.
236 One major achievement in this field is, inarguably, the
237 https://www.gnu.org/software/gdb/[GNU debugger (GDB)],
238 an essential tool for developers to find and fix bugs. But even the best
239 debugger won't help make your software run faster, and nowadays, faster
240 software means either more work done by the same hardware, or cheaper
241 hardware for the same work.
243 A _profiler_ is often the tool of choice to identify performance
244 bottlenecks. Profiling is suitable to identify _where_ performance is
245 lost in a given software. The profiler outputs a profile, a statistical
246 summary of observed events, which you may use to discover which
247 functions took the most time to execute. However, a profiler won't
248 report _why_ some identified functions are the bottleneck. Bottlenecks
249 might only occur when specific conditions are met, conditions that are
250 sometimes impossible to capture by a statistical profiler, or impossible
251 to reproduce with an application altered by the overhead of an
252 event-based profiler. For a thorough investigation of software
253 performance issues, a history of execution is essential, with the
254 recorded values of variables and context fields you choose, and
255 with as little influence as possible on the instrumented software. This
256 is where tracing comes in handy.
258 _Tracing_ is a technique used to understand what goes on in a running
259 software system. The software used for tracing is called a _tracer_,
260 which is conceptually similar to a tape recorder. When recording,
261 specific instrumentation points placed in the software source code
262 generate events that are saved on a giant tape: a _trace_ file. You
263 can trace user applications and the operating system at the same time,
264 opening the possibility of resolving a wide range of problems that would
265 otherwise be extremely challenging.
267 Tracing is often compared to _logging_. However, tracers and loggers are
268 two different tools, serving two different purposes. Tracers are
269 designed to record much lower-level events that occur much more
270 frequently than log messages, often in the range of thousands per
271 second, with very little execution overhead. Logging is more appropriate
272 for a very high-level analysis of less frequent events: user accesses,
273 exceptional conditions (errors and warnings, for example), database
274 transactions, instant messaging communications, and such. Simply put,
275 logging is one of the many use cases that can be satisfied with tracing.
277 The list of recorded events inside a trace file can be read manually
278 like a log file for the maximum level of detail, but it is generally
279 much more interesting to perform application-specific analyses to
280 produce reduced statistics and graphs that are useful to resolve a
281 given problem. Trace viewers and analyzers are specialized tools
284 In the end, this is what LTTng is: a powerful, open source set of
285 tools to trace the Linux kernel and user applications at the same time.
286 LTTng is composed of several components actively maintained and
287 developed by its link:/community/#where[community].
290 [[lttng-alternatives]]
291 === Alternatives to noch:{LTTng}
293 Excluding proprietary solutions, a few competing software tracers
296 https://github.com/dtrace4linux/linux[dtrace4linux]::
297 A port of Sun Microsystems's DTrace to Linux.
299 The cmd:dtrace tool interprets user scripts and is responsible for
300 loading code into the Linux kernel for further execution and collecting
303 https://en.wikipedia.org/wiki/Berkeley_Packet_Filter[eBPF]::
304 A subsystem in the Linux kernel in which a virtual machine can
305 execute programs passed from the user space to the kernel.
307 You can attach such programs to tracepoints and kprobes thanks to a
308 system call, and they can output data to the user space when executed
309 thanks to different mechanisms (pipe, VM register values, and eBPF maps,
312 https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace]::
313 The de facto function tracer of the Linux kernel.
315 Its user interface is a set of special files in sysfs.
317 https://perf.wiki.kernel.org/[perf]::
318 A performance analysis tool for Linux which supports hardware
319 performance counters, tracepoints, as well as other counters and
322 perf's controlling utility is the cmd:perf command line/text UI tool.
324 http://linux.die.net/man/1/strace[strace]::
325 A command-line utility which records system calls made by a
326 user process, as well as signal deliveries and changes of process
329 strace makes use of https://en.wikipedia.org/wiki/Ptrace[ptrace] to
330 fulfill its function.
332 http://www.sysdig.org/[sysdig]::
333 Like SystemTap, uses scripts to analyze Linux kernel events.
335 You write scripts, or _chisels_ in sysdig's jargon, in Lua and sysdig
336 executes them while it traces the system or afterwards. sysdig's
337 interface is the cmd:sysdig command-line tool as well as the text
338 UI-based cmd:csysdig tool.
340 https://sourceware.org/systemtap/[SystemTap]::
341 A Linux kernel and user space tracer which uses custom user scripts
342 to produce plain text traces.
344 SystemTap converts the scripts to the C language, and then compiles them
345 as Linux kernel modules which are loaded to produce trace data.
346 SystemTap's primary user interface is the cmd:stap command-line tool.
348 The main distinctive features of LTTng is that it produces correlated
349 kernel and user space traces, as well as doing so with the lowest
350 overhead amongst other solutions. It produces trace files in the
351 http://diamon.org/ctf[CTF] format, a file format optimized
352 for the production and analyses of multi-gigabyte data.
354 LTTng is the result of more than 10{nbsp}years of active open source
355 development by a community of passionate developers. LTTng is currently
356 available on major desktop and server Linux distributions.
358 The main interface for tracing control is a single command-line tool
359 named cmd:lttng. The latter can create several tracing sessions, enable
360 and disable events on the fly, filter events efficiently with custom
361 user expressions, start and stop tracing, and much more. LTTng can
362 record the traces on the file system or send them over the network, and
363 keep them totally or partially. You can view the traces once tracing
364 becomes inactive or in real-time.
366 <<installing-lttng,Install LTTng now>> and
367 <<getting-started,start tracing>>!
373 **LTTng** is a set of software <<plumbing,components>> which interact to
374 <<instrumenting,instrument>> the Linux kernel and user applications, and
375 to <<controlling-tracing,control tracing>> (start and stop
376 tracing, enable and disable event rules, and the rest). Those
377 components are bundled into the following packages:
380 Libraries and command-line interface to control tracing.
383 Linux kernel modules to instrument and trace the kernel.
386 Libraries and Java/Python packages to instrument and trace user
389 Most distributions mark the LTTng-modules and LTTng-UST packages as
390 optional when installing LTTng-tools (which is always required). In the
391 following sections, we always provide the steps to install all three,
394 * You only need to install LTTng-modules if you intend to trace the
396 * You only need to install LTTng-UST if you intend to trace user
401 As of 1 April 2020, LTTng{nbsp}{revision} isn't available
402 as distribution packages, except for <<arch-linux,Arch Linux>>.
404 <<building-from-source,Build LTTng{nbsp}{revision} from source>>
405 to install and use it.
412 LTTng-UST{nbsp}{revision} is available in Arch Linux's _community_
413 repository, while LTTng-tools{nbsp}{revision} and
414 LTTng-modules{nbsp}{revision} are available in the
415 https://aur.archlinux.org/[AUR].
417 To install LTTng{nbsp}{revision} on Arch Linux, using
418 https://github.com/Jguer/yay[yay] for the AUR packages:
420 . Install the main LTTng{nbsp}{revision} packages:
425 # pacman -Sy lttng-ust
426 $ yay -Sy lttng-tools
427 $ yay -Sy lttng-modules
431 . **If you need to instrument and trace <<python-application,Python
432 applications>>**, install the LTTng-UST Python agent:
437 # pacman -Sy python-lttngust
438 # pacman -Sy python2-lttngust
443 [[building-from-source]]
444 === Build from source
446 To build and install LTTng{nbsp}{revision} from source:
448 . Using your distribution's package manager, or from source, install
449 the following dependencies of LTTng-tools and LTTng-UST:
452 * https://sourceforge.net/projects/libuuid/[libuuid]
453 * http://directory.fsf.org/wiki/Popt[popt]
454 * http://liburcu.org/[Userspace RCU]
455 * http://www.xmlsoft.org/[libxml2]
456 * **Optional**: https://github.com/numactl/numactl[numactl]
459 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
465 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.12.tar.bz2 &&
466 tar -xf lttng-modules-latest-2.12.tar.bz2 &&
467 cd lttng-modules-2.12.* &&
469 sudo make modules_install &&
474 . Download, build, and install the latest LTTng-UST{nbsp}{revision}:
480 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.12.tar.bz2 &&
481 tar -xf lttng-ust-latest-2.12.tar.bz2 &&
482 cd lttng-ust-2.12.* &&
490 Add `--disable-numa` to `./configure` if you don't have
491 https://github.com/numactl/numactl[numactl].
495 .Java and Python application tracing
497 If you need to instrument and trace <<java-application,Java
498 applications>>, pass the `--enable-java-agent-jul`,
499 `--enable-java-agent-log4j`, or `--enable-java-agent-all` options to the
500 `configure` script, depending on which Java logging framework you use.
502 If you need to instrument and trace <<python-application,Python
503 applications>>, pass the `--enable-python-agent` option to the
504 `configure` script. You can set the `PYTHON` environment variable to the
505 path to the Python interpreter for which to install the LTTng-UST Python
513 By default, LTTng-UST libraries are installed to
514 dir:{/usr/local/lib}, which is the de facto directory in which to
515 keep self-compiled and third-party libraries.
517 When <<building-tracepoint-providers-and-user-application,linking an
518 instrumented user application with `liblttng-ust`>>:
520 * Append `/usr/local/lib` to the env:LD_LIBRARY_PATH environment
522 * Pass the `-L/usr/local/lib` and `-Wl,-rpath,/usr/local/lib` options to
523 man:gcc(1), man:g++(1), or man:clang(1).
527 . Download, build, and install the latest LTTng-tools{nbsp}{revision}:
533 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.12.tar.bz2 &&
534 tar -xf lttng-tools-latest-2.12.tar.bz2 &&
535 cd lttng-tools-2.12.* &&
543 TIP: The https://github.com/eepp/vlttng[vlttng tool] can do all the
544 previous steps automatically for a given version of LTTng and confine
545 the installed files in a specific directory. This can be useful to test
546 LTTng without installing it on your system.
552 This is a short guide to get started quickly with LTTng kernel and user
555 Before you follow this guide, make sure to <<installing-lttng,install>>
558 This tutorial walks you through the steps to:
560 . <<tracing-the-linux-kernel,Trace the Linux kernel>>.
561 . <<tracing-your-own-user-application,Trace a user application>> written
563 . <<viewing-and-analyzing-your-traces,View and analyze the
567 [[tracing-the-linux-kernel]]
568 === Trace the Linux kernel
570 The following command lines start with the `#` prompt because you need
571 root privileges to trace the Linux kernel. You can also trace the kernel
572 as a regular user if your Unix user is a member of the
573 <<tracing-group,tracing group>>.
575 . Create a <<tracing-session,tracing session>> which writes its traces
576 to dir:{/tmp/my-kernel-trace}:
581 # lttng create my-kernel-session --output=/tmp/my-kernel-trace
585 . List the available kernel tracepoints and system calls:
590 # lttng list --kernel
591 # lttng list --kernel --syscall
595 . Create <<event,event rules>> which match the desired instrumentation
596 point names, for example the `sched_switch` and `sched_process_fork`
597 tracepoints, and the man:open(2) and man:close(2) system calls:
602 # lttng enable-event --kernel sched_switch,sched_process_fork
603 # lttng enable-event --kernel --syscall open,close
607 Create an event rule which matches _all_ the Linux kernel
608 tracepoints with the opt:lttng-enable-event(1):--all option
609 (this will generate a lot of data when tracing):
614 # lttng enable-event --kernel --all
618 . <<basic-tracing-session-control,Start tracing>>:
627 . Do some operation on your system for a few seconds. For example,
628 load a website, or list the files of a directory.
629 . <<creating-destroying-tracing-sessions,Destroy>> the current
639 The man:lttng-destroy(1) command doesn't destroy the trace data; it
640 only destroys the state of the tracing session.
642 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
643 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
644 session>>). You need to stop tracing to make LTTng flush the remaining
645 trace data and make the trace readable.
647 . For the sake of this example, make the recorded trace accessible to
653 # chown -R $(whoami) /tmp/my-kernel-trace
657 See <<viewing-and-analyzing-your-traces,View and analyze the
658 recorded events>> to view the recorded events.
661 [[tracing-your-own-user-application]]
662 === Trace a user application
664 This section steps you through a simple example to trace a
665 _Hello world_ program written in C.
667 To create the traceable user application:
669 . Create the tracepoint provider header file, which defines the
670 tracepoints and the events they can generate:
676 #undef TRACEPOINT_PROVIDER
677 #define TRACEPOINT_PROVIDER hello_world
679 #undef TRACEPOINT_INCLUDE
680 #define TRACEPOINT_INCLUDE "./hello-tp.h"
682 #if !defined(_HELLO_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
685 #include <lttng/tracepoint.h>
695 ctf_string(my_string_field, my_string_arg)
696 ctf_integer(int, my_integer_field, my_integer_arg)
700 #endif /* _HELLO_TP_H */
702 #include <lttng/tracepoint-event.h>
706 . Create the tracepoint provider package source file:
712 #define TRACEPOINT_CREATE_PROBES
713 #define TRACEPOINT_DEFINE
715 #include "hello-tp.h"
719 . Build the tracepoint provider package:
724 $ gcc -c -I. hello-tp.c
728 . Create the _Hello World_ application source file:
735 #include "hello-tp.h"
737 int main(int argc, char *argv[])
741 puts("Hello, World!\nPress Enter to continue...");
744 * The following getchar() call is only placed here for the purpose
745 * of this demonstration, to pause the application in order for
746 * you to have time to list its tracepoints. It's not needed
752 * A tracepoint() call.
754 * Arguments, as defined in hello-tp.h:
756 * 1. Tracepoint provider name (required)
757 * 2. Tracepoint name (required)
758 * 3. my_integer_arg (first user-defined argument)
759 * 4. my_string_arg (second user-defined argument)
761 * Notice the tracepoint provider and tracepoint names are
762 * NOT strings: they are in fact parts of variables that the
763 * macros in hello-tp.h create.
765 tracepoint(hello_world, my_first_tracepoint, 23, "hi there!");
767 for (x = 0; x < argc; ++x) {
768 tracepoint(hello_world, my_first_tracepoint, x, argv[x]);
771 puts("Quitting now!");
772 tracepoint(hello_world, my_first_tracepoint, x * x, "x^2");
779 . Build the application:
788 . Link the application with the tracepoint provider package,
789 `liblttng-ust`, and `libdl`:
794 $ gcc -o hello hello.o hello-tp.o -llttng-ust -ldl
798 Here's the whole build process:
801 .User space tracing tutorial's build steps.
802 image::ust-flow.png[]
804 To trace the user application:
806 . Run the application with a few arguments:
811 $ ./hello world and beyond
820 Press Enter to continue...
824 . Start an LTTng <<lttng-sessiond,session daemon>>:
829 $ lttng-sessiond --daemonize
833 Note that a session daemon might already be running, for example as
834 a service that the distribution's service manager started.
836 . List the available user space tracepoints:
841 $ lttng list --userspace
845 You see the `hello_world:my_first_tracepoint` tracepoint listed
846 under the `./hello` process.
848 . Create a <<tracing-session,tracing session>>:
853 $ lttng create my-user-space-session
857 . Create an <<event,event rule>> which matches the
858 `hello_world:my_first_tracepoint` event name:
863 $ lttng enable-event --userspace hello_world:my_first_tracepoint
867 . <<basic-tracing-session-control,Start tracing>>:
876 . Go back to the running `hello` application and press Enter. The
877 program executes all `tracepoint()` instrumentation points and exits.
878 . <<creating-destroying-tracing-sessions,Destroy>> the current
888 The man:lttng-destroy(1) command doesn't destroy the trace data; it
889 only destroys the state of the tracing session.
891 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
892 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
893 session>>). You need to stop tracing to make LTTng flush the remaining
894 trace data and make the trace readable.
896 By default, LTTng saves the traces in
897 +$LTTNG_HOME/lttng-traces/__name__-__date__-__time__+,
898 where +__name__+ is the tracing session name. The
899 env:LTTNG_HOME environment variable defaults to `$HOME` if not set.
901 See <<viewing-and-analyzing-your-traces,View and analyze the
902 recorded events>> to view the recorded events.
905 [[viewing-and-analyzing-your-traces]]
906 === View and analyze the recorded events
908 Once you have completed the <<tracing-the-linux-kernel,Trace the Linux
909 kernel>> and <<tracing-your-own-user-application,Trace a user
910 application>> tutorials, you can inspect the recorded events.
912 There are many tools you can use to read LTTng traces:
914 https://babeltrace.org/[Babeltrace{nbsp}2]::
915 A rich, flexible trace manipulation toolkit which includes
916 a versatile command-line interface
917 (https://babeltrace.org/docs/v2.0/man1/babeltrace2.1/[cmd:babeltrace2]),
918 a https://babeltrace.org/docs/v2.0/libbabeltrace2/[C library],
919 and https://babeltrace.org/docs/v2.0/python/bt2/[Python{nbsp}3 bindings]
920 so that you can easily process or convert an LTTng trace with
923 The Babeltrace{nbsp}2 project ships with a
924 https://babeltrace.org/docs/v2.0/man7/babeltrace2-plugin-ctf.7/[plugin]
925 which supports the format of the traces which LTTng produces,
926 https://diamon.org/ctf/[CTF].
928 http://tracecompass.org/[Trace Compass]::
929 A graphical user interface for viewing and analyzing any type of
930 logs or traces, including LTTng's.
932 https://github.com/lttng/lttng-analyses[**LTTng analyses**]::
933 An experimental project which includes many high-level analyses of
934 LTTng kernel traces, like scheduling statistics, interrupt
935 frequency distribution, top CPU usage, and more.
937 NOTE: This section assumes that LTTng saved the traces it recorded
938 during the previous tutorials to their default location, in the
939 dir:{$LTTNG_HOME/lttng-traces} directory. The env:LTTNG_HOME
940 environment variable defaults to `$HOME` if not set.
943 [[viewing-and-analyzing-your-traces-bt]]
944 ==== Use the cmd:babeltrace2 command-line tool
946 The simplest way to list all the recorded events of an LTTng trace is to
948 https://babeltrace.org/docs/v2.0/man1/babeltrace2.1/[cmd:babeltrace2]
953 $ babeltrace2 ~/lttng-traces/my-user-space-session*
956 cmd:babeltrace2 finds all traces recursively within the given path and
957 prints all their events, sorting them chronologically.
959 Pipe the output of cmd:babeltrace2 into a tool like man:grep(1) for
964 $ babeltrace2 /tmp/my-kernel-trace | grep _switch
967 Pipe the output of cmd:babeltrace2 into a tool like man:wc(1) to count
972 $ babeltrace2 /tmp/my-kernel-trace | grep _open | wc --lines
976 [[viewing-and-analyzing-your-traces-bt-python]]
977 ==== Use the Babeltrace{nbsp}2 Python bindings
979 The <<viewing-and-analyzing-your-traces-bt,text output of
980 cmd:babeltrace2>> is useful to isolate events by simple matching using
981 man:grep(1) and similar utilities. However, more elaborate filters, such
982 as keeping only event records with a field value falling within a
983 specific range, are not trivial to write using a shell. Moreover,
984 reductions and even the most basic computations involving multiple event
985 records are virtually impossible to implement.
987 Fortunately, Babeltrace{nbsp}2 ships with
988 https://babeltrace.org/docs/v2.0/python/bt2/[Python{nbsp}3 bindings]
989 which make it easy to read the event records of an LTTng trace
990 sequentially and compute the desired information.
992 The following script accepts an LTTng Linux kernel trace path as its
993 first argument and prints the short names of the top five running
994 processes on CPU{nbsp}0 during the whole trace:
1004 # Get the trace path from the first command-line argument.
1005 it = bt2.TraceCollectionMessageIterator(sys.argv[1])
1007 # This counter dictionary will hold execution times:
1009 # Task command name -> Total execution time (ns)
1010 exec_times = collections.Counter()
1012 # This holds the last `sched_switch` timestamp.
1016 # We only care about event messages.
1017 if type(msg) is not bt2._EventMessageConst:
1020 # Event message's event.
1023 # Keep only `sched_switch` events.
1024 if event.cls.name != 'sched_switch':
1027 # Keep only events which occurred on CPU 0.
1028 if event.packet.context_field['cpu_id'] != 0:
1031 # Event timestamp (ns).
1032 cur_ts = msg.default_clock_snapshot.ns_from_origin
1038 # Previous task command's (short) name.
1039 prev_comm = str(event.payload_field['prev_comm'])
1041 # Initialize an entry in our dictionary if not yet done.
1042 if prev_comm not in exec_times:
1043 exec_times[prev_comm] = 0
1045 # Compute previous command execution time.
1046 diff = cur_ts - last_ts
1048 # Update execution time of this command.
1049 exec_times[prev_comm] += diff
1051 # Update last timestamp.
1055 for name, ns in exec_times.most_common(5):
1056 print('{:20}{} s'.format(name, ns / 1e9))
1059 if __name__ == '__main__':
1067 $ python3 top5proc.py /tmp/my-kernel-trace/kernel
1073 swapper/0 48.607245889 s
1074 chromium 7.192738188 s
1075 pavucontrol 0.709894415 s
1076 Compositor 0.660867933 s
1077 Xorg.bin 0.616753786 s
1080 Note that `swapper/0` is the ``idle'' process of CPU{nbsp}0 on Linux;
1081 since we weren't using the CPU that much when tracing, its first
1082 position in the list makes sense.
1086 == [[understanding-lttng]]Core concepts
1088 From a user's perspective, the LTTng system is built on a few concepts,
1089 or objects, on which the <<lttng-cli,cmd:lttng command-line tool>>
1090 operates by sending commands to the <<lttng-sessiond,session daemon>>.
1091 Understanding how those objects relate to eachother is key in mastering
1094 The core concepts are:
1096 * <<tracing-session,Tracing session>>
1097 * <<domain,Tracing domain>>
1098 * <<channel,Channel and ring buffer>>
1099 * <<"event","Instrumentation point, event rule, event, and event record">>
1105 A _tracing session_ is a stateful dialogue between you and
1106 a <<lttng-sessiond,session daemon>>. You can
1107 <<creating-destroying-tracing-sessions,create a new tracing
1108 session>> with the `lttng create` command.
1110 Most of what you do when you control LTTng tracers happens within a
1111 tracing session. In particular, a tracing session:
1114 * Has its own set of trace files.
1115 * Has its own state of activity (started or stopped).
1116 * Has its own <<tracing-session-mode,mode>> (local, network streaming,
1118 * Has its own <<channel,channels>> to which are associated their own
1119 <<event,event rules>>.
1120 * Has its own <<pid-tracking,process attribute tracking>> inclusion
1124 .A _tracing session_ contains <<channel,channels>> that are members of <<domain,tracing domains>> and contain <<event,event rules>>.
1125 image::concepts.png[]
1127 Those attributes and objects are completely isolated between different
1130 A tracing session is analogous to a cash machine session:
1131 the operations you do on the banking system through the cash machine do
1132 not alter the data of other users of the same system. In the case of
1133 the cash machine, a session lasts as long as your bank card is inside.
1134 In the case of LTTng, a tracing session lasts from the `lttng create`
1135 command to the `lttng destroy` command.
1138 .Each Unix user has its own set of tracing sessions.
1139 image::many-sessions.png[]
1142 [[tracing-session-mode]]
1143 ==== Tracing session mode
1145 LTTng can send the generated trace data to different locations. The
1146 _tracing session mode_ dictates where to send it. The following modes
1147 are available in LTTng{nbsp}{revision}:
1150 LTTng writes the traces to the file system of the machine it traces
1153 Network streaming mode::
1154 LTTng sends the traces over the network to a
1155 <<lttng-relayd,relay daemon>> running on a remote system.
1158 LTTng doesn't write the traces by default.
1160 Instead, you can request LTTng to <<taking-a-snapshot,take a snapshot>>,
1161 that is, a copy of the tracing session's current sub-buffers, and to
1162 write it to the target's file system or to send it over the network to a
1163 <<lttng-relayd,relay daemon>> running on a remote system.
1166 This mode is similar to the network streaming mode, but a live
1167 trace viewer can connect to the distant relay daemon to
1168 <<lttng-live,view event records as LTTng generates them>>.
1174 A _tracing domain_ is a namespace for event sources. A tracing domain
1175 has its own properties and features.
1177 There are currently five available tracing domains:
1181 * `java.util.logging` (JUL)
1185 You must specify a tracing domain when using some commands to avoid
1186 ambiguity. For example, since all the domains support named tracepoints
1187 as event sources (instrumentation points that you manually insert in the
1188 source code), you need to specify a tracing domain when
1189 <<enabling-disabling-events,creating an event rule>> because all the
1190 tracing domains could have tracepoints with the same names.
1192 You can create <<channel,channels>> in the Linux kernel and user space
1193 tracing domains. The other tracing domains have a single default
1198 === Channel and ring buffer
1200 A _channel_ is an object which is responsible for a set of ring buffers.
1201 Each ring buffer is divided into multiple sub-buffers. When an LTTng
1202 tracer emits an event, it can record it to one or more
1203 sub-buffers. The attributes of a channel determine what to do when
1204 there's no space left for a new event record because all sub-buffers
1205 are full, where to send a full sub-buffer, and other behaviours.
1207 A channel is always associated to a <<domain,tracing domain>>. The
1208 `java.util.logging` (JUL), log4j, and Python tracing domains each have
1209 a default channel which you can't configure.
1211 A channel also owns <<event,event rules>>. When an LTTng tracer emits
1212 an event, it records it to the sub-buffers of all
1213 the enabled channels with a satisfied event rule, as long as those
1214 channels are part of active <<tracing-session,tracing sessions>>.
1217 [[channel-buffering-schemes]]
1218 ==== Per-user vs. per-process buffering schemes
1220 A channel has at least one ring buffer _per CPU_. LTTng always
1221 records an event to the ring buffer associated to the CPU on which it
1224 Two _buffering schemes_ are available when you
1225 <<enabling-disabling-channels,create a channel>> in the
1226 user space <<domain,tracing domain>>:
1228 Per-user buffering::
1229 Allocate one set of ring buffers--one per CPU--shared by all the
1230 instrumented processes of each Unix user.
1234 .Per-user buffering scheme.
1235 image::per-user-buffering.png[]
1238 Per-process buffering::
1239 Allocate one set of ring buffers--one per CPU--for each
1240 instrumented process.
1244 .Per-process buffering scheme.
1245 image::per-process-buffering.png[]
1248 The per-process buffering scheme tends to consume more memory than the
1249 per-user option because systems generally have more instrumented
1250 processes than Unix users running instrumented processes. However, the
1251 per-process buffering scheme ensures that one process having a high
1252 event throughput won't fill all the shared sub-buffers of the same
1255 The Linux kernel tracing domain has only one available buffering scheme
1256 which is to allocate a single set of ring buffers for the whole system.
1257 This scheme is similar to the per-user option, but with a single, global
1258 user ``running'' the kernel.
1261 [[channel-overwrite-mode-vs-discard-mode]]
1262 ==== Overwrite vs. discard event record loss modes
1264 When an event occurs, LTTng records it to a specific sub-buffer (yellow
1265 arc in the following animations) of a specific channel's ring buffer.
1266 When there's no space left in a sub-buffer, the tracer marks it as
1267 consumable (red) and another, empty sub-buffer starts receiving the
1268 following event records. A <<lttng-consumerd,consumer daemon>>
1269 eventually consumes the marked sub-buffer (returns to white).
1272 [role="docsvg-channel-subbuf-anim"]
1277 In an ideal world, sub-buffers are consumed faster than they are filled,
1278 as it is the case in the previous animation. In the real world,
1279 however, all sub-buffers can be full at some point, leaving no space to
1280 record the following events.
1282 By default, LTTng-modules and LTTng-UST are _non-blocking_ tracers: when
1283 no empty sub-buffer is available, it is acceptable to lose event records
1284 when the alternative would be to cause substantial delays in the
1285 instrumented application's execution. LTTng privileges performance over
1286 integrity; it aims at perturbing the target system as little as possible
1287 in order to make tracing of subtle race conditions and rare interrupt
1290 Since LTTng{nbsp}2.10, the LTTng user space tracer, LTTng-UST, supports
1291 a _blocking mode_. See the <<blocking-timeout-example,blocking timeout
1292 example>> to learn how to use the blocking mode.
1294 When it comes to losing event records because no empty sub-buffer is
1295 available, or because the <<opt-blocking-timeout,blocking timeout>> is
1296 reached, the channel's _event record loss mode_ determines what to do.
1297 The available event record loss modes are:
1300 Drop the newest event records until the tracer releases a sub-buffer.
1302 This is the only available mode when you specify a
1303 <<opt-blocking-timeout,blocking timeout>>.
1306 Clear the sub-buffer containing the oldest event records and start
1307 writing the newest event records there.
1309 This mode is sometimes called _flight recorder mode_ because it's
1311 https://en.wikipedia.org/wiki/Flight_recorder[flight recorder]:
1312 always keep a fixed amount of the latest data.
1314 Which mechanism you should choose depends on your context: prioritize
1315 the newest or the oldest event records in the ring buffer?
1317 Beware that, in overwrite mode, the tracer abandons a _whole sub-buffer_
1318 as soon as a there's no space left for a new event record, whereas in
1319 discard mode, the tracer only discards the event record that doesn't
1322 In discard mode, LTTng increments a count of lost event records when an
1323 event record is lost and saves this count to the trace. In overwrite
1324 mode, since LTTng{nbsp}2.8, LTTng increments a count of lost sub-buffers
1325 when a sub-buffer is lost and saves this count to the trace. In this
1326 mode, LTTng doesn't write to the trace the exact number of lost event
1327 records in those lost sub-buffers. Trace analyses can use the trace's
1328 saved discarded event record and sub-buffer counts to decide whether or
1329 not to perform the analyses even if trace data is known to be missing.
1331 There are a few ways to decrease your probability of losing event
1333 <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>> shows
1334 how to fine-tune the sub-buffer count and size of a channel to virtually
1335 stop losing event records, though at the cost of greater memory usage.
1338 [[channel-subbuf-size-vs-subbuf-count]]
1339 ==== Sub-buffer count and size
1341 When you <<enabling-disabling-channels,create a channel>>, you can
1342 set its number of sub-buffers and their size.
1344 Note that there is noticeable CPU overhead introduced when
1345 switching sub-buffers (marking a full one as consumable and switching
1346 to an empty one for the following events to be recorded). Knowing this,
1347 the following list presents a few practical situations along with how
1348 to configure the sub-buffer count and size for them:
1350 * **High event throughput**: In general, prefer bigger sub-buffers to
1351 lower the risk of losing event records.
1353 Having bigger sub-buffers also ensures a lower
1354 <<channel-switch-timer,sub-buffer switching frequency>>.
1356 The number of sub-buffers is only meaningful if you create the channel
1357 in overwrite mode: in this case, if a sub-buffer overwrite happens, the
1358 other sub-buffers are left unaltered.
1360 * **Low event throughput**: In general, prefer smaller sub-buffers
1361 since the risk of losing event records is low.
1363 Because events occur less frequently, the sub-buffer switching frequency
1364 should remain low and thus the tracer's overhead shouldn't be a
1367 * **Low memory system**: If your target system has a low memory
1368 limit, prefer fewer first, then smaller sub-buffers.
1370 Even if the system is limited in memory, you want to keep the
1371 sub-buffers as big as possible to avoid a high sub-buffer switching
1374 Note that LTTng uses http://diamon.org/ctf/[CTF] as its trace format,
1375 which means event data is very compact. For example, the average
1376 LTTng kernel event record weights about 32{nbsp}bytes. Thus, a
1377 sub-buffer size of 1{nbsp}MiB is considered big.
1379 The previous situations highlight the major trade-off between a few big
1380 sub-buffers and more, smaller sub-buffers: sub-buffer switching
1381 frequency vs. how much data is lost in overwrite mode. Assuming a
1382 constant event throughput and using the overwrite mode, the two
1383 following configurations have the same ring buffer total size:
1386 [role="docsvg-channel-subbuf-size-vs-count-anim"]
1391 * **Two sub-buffers of 4{nbsp}MiB each**: Expect a very low sub-buffer
1392 switching frequency, but if a sub-buffer overwrite happens, half of
1393 the event records so far (4{nbsp}MiB) are definitely lost.
1394 * **Eight sub-buffers of 1{nbsp}MiB each**: Expect four times the tracer's
1395 overhead as the previous configuration, but if a sub-buffer
1396 overwrite happens, only the eighth of event records so far are
1399 In discard mode, the sub-buffers count parameter is pointless: use two
1400 sub-buffers and set their size according to the requirements of your
1404 [[channel-switch-timer]]
1405 ==== Switch timer period
1407 The _switch timer period_ is an important configurable attribute of
1408 a channel to ensure periodic sub-buffer flushing.
1410 When the _switch timer_ expires, a sub-buffer switch happens. Set
1411 the switch timer period attribute when you
1412 <<enabling-disabling-channels,create a channel>> to ensure that LTTng
1413 consumes and commits trace data to trace files or to a distant relay
1414 daemon periodically in case of a low event throughput.
1417 [role="docsvg-channel-switch-timer"]
1422 This attribute is also convenient when you use big sub-buffers to cope
1423 with a sporadic high event throughput, even if the throughput is
1427 [[channel-read-timer]]
1428 ==== Read timer period
1430 By default, the LTTng tracers use a notification mechanism to signal a
1431 full sub-buffer so that a consumer daemon can consume it. When such
1432 notifications must be avoided, for example in real-time applications,
1433 use the channel's _read timer_ instead. When the read timer fires, the
1434 <<lttng-consumerd,consumer daemon>> checks for full, consumable
1438 [[tracefile-rotation]]
1439 ==== Trace file count and size
1441 By default, trace files can grow as large as needed. Set the
1442 maximum size of each trace file that a channel writes when you
1443 <<enabling-disabling-channels,create a channel>>. When the size of
1444 a trace file reaches the channel's fixed maximum size, LTTng creates
1445 another file to contain the next event records. LTTng appends a file
1446 count to each trace file name in this case.
1448 If you set the trace file size attribute when you create a channel, the
1449 maximum number of trace files that LTTng creates is _unlimited_ by
1450 default. To limit them, set a maximum number of trace files. When the
1451 number of trace files reaches the channel's fixed maximum count, the
1452 oldest trace file is overwritten. This mechanism is called _trace file
1457 Even if you don't limit the trace file count, you can't assume that
1458 LTTng doesn't manage any trace file.
1460 In other words, there is no safe way to know if LTTng still holds a
1461 given trace file open with the trace file rotation feature.
1463 The only way to obtain an unmanaged, self-contained LTTng trace before
1464 you <<creating-destroying-tracing-sessions,destroy>> the tracing session
1465 is with the <<session-rotation,tracing session rotation>> feature
1466 (available since LTTng{nbsp}2.11).
1471 === Instrumentation point, event rule, event, and event record
1473 An _event rule_ is a set of conditions which must be **all** satisfied
1474 for LTTng to record an occuring event.
1476 You set the conditions when you <<enabling-disabling-events,create
1479 You always attach an event rule to a <<channel,channel>> when you create
1482 When an event passes the conditions of an event rule, LTTng records it
1483 in one of the attached channel's sub-buffers.
1485 The available conditions, as of LTTng{nbsp}{revision}, are:
1487 * The event rule _is enabled_.
1488 * The instrumentation point's type _is{nbsp}T_.
1489 * The instrumentation point's name (sometimes called _event name_)
1490 _matches{nbsp}N_, but _isn't{nbsp}E_.
1491 * The instrumentation point's log level _is as severe as{nbsp}L_, or
1492 _is exactly{nbsp}L_.
1493 * The fields of the event's payload _satisfy_ a filter
1494 expression{nbsp}__F__.
1496 As you can see, all the conditions but the dynamic filter are related to
1497 the event rule's status or to the instrumentation point, not to the
1498 occurring events. This is why, without a filter, checking if an event
1499 passes an event rule isn't a dynamic task: when you create or modify an
1500 event rule, all the tracers of its tracing domain enable or disable the
1501 instrumentation points themselves once. This is possible because the
1502 attributes of an instrumentation point (type, name, and log level) are
1503 defined statically. In other words, without a dynamic filter, the tracer
1504 _doesn't evaluate_ the arguments of an instrumentation point unless it
1505 matches an enabled event rule.
1507 Note that, for LTTng to record an event, the <<channel,channel>> to
1508 which a matching event rule is attached must also be enabled, and the
1509 <<tracing-session,tracing session>> owning this channel must be active
1513 .Logical path from an instrumentation point to an event record.
1514 image::event-rule.png[]
1516 .Event, event record, or event rule?
1518 With so many similar terms, it's easy to get confused.
1520 An **event** is the consequence of the execution of an _instrumentation
1521 point_, like a tracepoint that you manually place in some source code,
1522 or a Linux kernel kprobe. An event is said to _occur_ at a specific
1523 time. Different actions can be taken upon the occurrence of an event,
1524 like record the event's payload to a buffer.
1526 An **event record** is the representation of an event in a sub-buffer. A
1527 tracer is responsible for capturing the payload of an event, current
1528 context variables, the event's ID, and the event's timestamp. LTTng
1529 can append this sub-buffer to a trace file.
1531 An **event rule** is a set of conditions which must _all_ be satisfied
1532 for LTTng to record an occuring event. Events still occur without
1533 satisfying event rules, but LTTng doesn't record them.
1538 == Components of noch:{LTTng}
1540 The second _T_ in _LTTng_ stands for _toolkit_: it would be wrong
1541 to call LTTng a simple _tool_ since it is composed of multiple
1542 interacting components. This section describes those components,
1543 explains their respective roles, and shows how they connect together to
1544 form the LTTng ecosystem.
1546 The following diagram shows how the most important components of LTTng
1547 interact with user applications, the Linux kernel, and you:
1550 .Control and trace data paths between LTTng components.
1551 image::plumbing.png[]
1553 The LTTng project incorporates:
1555 * **LTTng-tools**: Libraries and command-line interface to
1556 control tracing sessions.
1557 ** <<lttng-sessiond,Session daemon>> (man:lttng-sessiond(8)).
1558 ** <<lttng-consumerd,Consumer daemon>> (cmd:lttng-consumerd).
1559 ** <<lttng-relayd,Relay daemon>> (man:lttng-relayd(8)).
1560 ** <<liblttng-ctl-lttng,Tracing control library>> (`liblttng-ctl`).
1561 ** <<lttng-cli,Tracing control command-line tool>> (man:lttng(1)).
1562 * **LTTng-UST**: Libraries and Java/Python packages to trace user
1564 ** <<lttng-ust,User space tracing library>> (`liblttng-ust`) and its
1565 headers to instrument and trace any native user application.
1566 ** <<prebuilt-ust-helpers,Preloadable user space tracing helpers>>:
1567 *** `liblttng-ust-libc-wrapper`
1568 *** `liblttng-ust-pthread-wrapper`
1569 *** `liblttng-ust-cyg-profile`
1570 *** `liblttng-ust-cyg-profile-fast`
1571 *** `liblttng-ust-dl`
1572 ** User space tracepoint provider source files generator command-line
1573 tool (man:lttng-gen-tp(1)).
1574 ** <<lttng-ust-agents,LTTng-UST Java agent>> to instrument and trace
1575 Java applications using `java.util.logging` or
1576 Apache log4j{nbsp}1.2 logging.
1577 ** <<lttng-ust-agents,LTTng-UST Python agent>> to instrument
1578 Python applications using the standard `logging` package.
1579 * **LTTng-modules**: <<lttng-modules,Linux kernel modules>> to trace
1581 ** LTTng kernel tracer module.
1582 ** Tracing ring buffer kernel modules.
1583 ** Probe kernel modules.
1584 ** LTTng logger kernel module.
1588 === Tracing control command-line interface
1591 .The tracing control command-line interface.
1592 image::plumbing-lttng-cli.png[]
1594 The _man:lttng(1) command-line tool_ is the standard user interface to
1595 control LTTng <<tracing-session,tracing sessions>>. The cmd:lttng tool
1596 is part of LTTng-tools.
1598 The cmd:lttng tool is linked with
1599 <<liblttng-ctl-lttng,`liblttng-ctl`>> to communicate with
1600 one or more <<lttng-sessiond,session daemons>> behind the scenes.
1602 The cmd:lttng tool has a Git-like interface:
1606 $ lttng <GENERAL OPTIONS> <COMMAND> <COMMAND OPTIONS>
1609 The <<controlling-tracing,Tracing control>> section explores the
1610 available features of LTTng using the cmd:lttng tool.
1613 [[liblttng-ctl-lttng]]
1614 === Tracing control library
1617 .The tracing control library.
1618 image::plumbing-liblttng-ctl.png[]
1620 The _LTTng control library_, `liblttng-ctl`, is used to communicate
1621 with a <<lttng-sessiond,session daemon>> using a C API that hides the
1622 underlying protocol's details. `liblttng-ctl` is part of LTTng-tools.
1624 The <<lttng-cli,cmd:lttng command-line tool>>
1625 is linked with `liblttng-ctl`.
1627 Use `liblttng-ctl` in C or $$C++$$ source code by including its
1632 #include <lttng/lttng.h>
1635 Some objects are referenced by name (C string), such as tracing
1636 sessions, but most of them require to create a handle first using
1637 `lttng_create_handle()`.
1639 As of LTTng{nbsp}{revision}, the best available developer documentation for
1640 `liblttng-ctl` is its installed header files. Every function and structure is
1641 thoroughly documented.
1645 === User space tracing library
1648 .The user space tracing library.
1649 image::plumbing-liblttng-ust.png[]
1651 The _user space tracing library_, `liblttng-ust` (see man:lttng-ust(3)),
1652 is the LTTng user space tracer. It receives commands from a
1653 <<lttng-sessiond,session daemon>>, for example to
1654 enable and disable specific instrumentation points, and writes event
1655 records to ring buffers shared with a
1656 <<lttng-consumerd,consumer daemon>>.
1657 `liblttng-ust` is part of LTTng-UST.
1659 Public C header files are installed beside `liblttng-ust` to
1660 instrument any <<c-application,C or $$C++$$ application>>.
1662 <<lttng-ust-agents,LTTng-UST agents>>, which are regular Java and Python
1663 packages, use their own library providing tracepoints which is
1664 linked with `liblttng-ust`.
1666 An application or library doesn't have to initialize `liblttng-ust`
1667 manually: its constructor does the necessary tasks to properly register
1668 to a session daemon. The initialization phase also enables the
1669 instrumentation points matching the <<event,event rules>> that you
1673 [[lttng-ust-agents]]
1674 === User space tracing agents
1677 .The user space tracing agents.
1678 image::plumbing-lttng-ust-agents.png[]
1680 The _LTTng-UST Java and Python agents_ are regular Java and Python
1681 packages which add LTTng tracing capabilities to the
1682 native logging frameworks. The LTTng-UST agents are part of LTTng-UST.
1684 In the case of Java, the
1685 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[`java.util.logging`
1686 core logging facilities] and
1687 https://logging.apache.org/log4j/1.2/[Apache log4j{nbsp}1.2] are supported.
1688 Note that Apache Log4{nbsp}2 isn't supported.
1690 In the case of Python, the standard
1691 https://docs.python.org/3/library/logging.html[`logging`] package
1692 is supported. Both Python{nbsp}2 and Python{nbsp}3 modules can import the
1693 LTTng-UST Python agent package.
1695 The applications using the LTTng-UST agents are in the
1696 `java.util.logging` (JUL),
1697 log4j, and Python <<domain,tracing domains>>.
1699 Both agents use the same mechanism to trace the log statements. When an
1700 agent initializes, it creates a log handler that attaches to the root
1701 logger. The agent also registers to a <<lttng-sessiond,session daemon>>.
1702 When the application executes a log statement, the root logger passes it
1703 to the agent's log handler. The agent's log handler calls a native
1704 function in a tracepoint provider package shared library linked with
1705 <<lttng-ust,`liblttng-ust`>>, passing the formatted log message and
1706 other fields, like its logger name and its log level. This native
1707 function contains a user space instrumentation point, hence tracing the
1710 The log level condition of an
1711 <<event,event rule>> is considered when tracing
1712 a Java or a Python application, and it's compatible with the standard
1713 JUL, log4j, and Python log levels.
1717 === LTTng kernel modules
1720 .The LTTng kernel modules.
1721 image::plumbing-lttng-modules.png[]
1723 The _LTTng kernel modules_ are a set of Linux kernel modules
1724 which implement the kernel tracer of the LTTng project. The LTTng
1725 kernel modules are part of LTTng-modules.
1727 The LTTng kernel modules include:
1729 * A set of _probe_ modules.
1731 Each module attaches to a specific subsystem
1732 of the Linux kernel using its tracepoint instrument points. There are
1733 also modules to attach to the entry and return points of the Linux
1734 system call functions.
1736 * _Ring buffer_ modules.
1738 A ring buffer implementation is provided as kernel modules. The LTTng
1739 kernel tracer writes to the ring buffer; a
1740 <<lttng-consumerd,consumer daemon>> reads from the ring buffer.
1742 * The _LTTng kernel tracer_ module.
1743 * The _LTTng logger_ module.
1745 The LTTng logger module implements the special path:{/proc/lttng-logger}
1746 (and path:{/dev/lttng-logger} since LTTng{nbsp}2.11) files so that any
1747 executable can generate LTTng events by opening and writing to those
1750 See <<proc-lttng-logger-abi,LTTng logger>>.
1752 Generally, you don't have to load the LTTng kernel modules manually
1753 (using man:modprobe(8), for example): a root <<lttng-sessiond,session
1754 daemon>> loads the necessary modules when starting. If you have extra
1755 probe modules, you can specify to load them to the session daemon on
1758 The LTTng kernel modules are installed in
1759 +/usr/lib/modules/__release__/extra+ by default, where +__release__+ is
1760 the kernel release (see `uname --kernel-release`).
1767 .The session daemon.
1768 image::plumbing-sessiond.png[]
1770 The _session daemon_, man:lttng-sessiond(8), is a daemon responsible for
1771 managing tracing sessions and for controlling the various components of
1772 LTTng. The session daemon is part of LTTng-tools.
1774 The session daemon sends control requests to and receives control
1777 * The <<lttng-ust,user space tracing library>>.
1779 Any instance of the user space tracing library first registers to
1780 a session daemon. Then, the session daemon can send requests to
1781 this instance, such as:
1784 ** Get the list of tracepoints.
1785 ** Share an <<event,event rule>> so that the user space tracing library
1786 can enable or disable tracepoints. Amongst the possible conditions
1787 of an event rule is a filter expression which `liblttng-ust` evalutes
1788 when an event occurs.
1789 ** Share <<channel,channel>> attributes and ring buffer locations.
1792 The session daemon and the user space tracing library use a Unix
1793 domain socket for their communication.
1795 * The <<lttng-ust-agents,user space tracing agents>>.
1797 Any instance of a user space tracing agent first registers to
1798 a session daemon. Then, the session daemon can send requests to
1799 this instance, such as:
1802 ** Get the list of loggers.
1803 ** Enable or disable a specific logger.
1806 The session daemon and the user space tracing agent use a TCP connection
1807 for their communication.
1809 * The <<lttng-modules,LTTng kernel tracer>>.
1810 * The <<lttng-consumerd,consumer daemon>>.
1812 The session daemon sends requests to the consumer daemon to instruct
1813 it where to send the trace data streams, amongst other information.
1815 * The <<lttng-relayd,relay daemon>>.
1817 The session daemon receives commands from the
1818 <<liblttng-ctl-lttng,tracing control library>>.
1820 The root session daemon loads the appropriate
1821 <<lttng-modules,LTTng kernel modules>> on startup. It also spawns
1822 a <<lttng-consumerd,consumer daemon>> as soon as you create
1823 an <<event,event rule>>.
1825 The session daemon doesn't send and receive trace data: this is the
1826 role of the <<lttng-consumerd,consumer daemon>> and
1827 <<lttng-relayd,relay daemon>>. It does, however, generate the
1828 http://diamon.org/ctf/[CTF] metadata stream.
1830 Each Unix user can have its own session daemon instance. The
1831 tracing sessions which different session daemons manage are completely
1834 The root user's session daemon is the only one which is
1835 allowed to control the LTTng kernel tracer, and its spawned consumer
1836 daemon is the only one which is allowed to consume trace data from the
1837 LTTng kernel tracer. Note, however, that any Unix user which is a member
1838 of the <<tracing-group,tracing group>> is allowed
1839 to create <<channel,channels>> in the
1840 Linux kernel <<domain,tracing domain>>, and thus to trace the Linux
1843 The <<lttng-cli,cmd:lttng command-line tool>> automatically starts a
1844 session daemon when using its `create` command if none is currently
1845 running. You can also start the session daemon manually.
1852 .The consumer daemon.
1853 image::plumbing-consumerd.png[]
1855 The _consumer daemon_, cmd:lttng-consumerd, is a daemon which shares
1856 ring buffers with user applications or with the LTTng kernel modules to
1857 collect trace data and send it to some location (on disk or to a
1858 <<lttng-relayd,relay daemon>> over the network). The consumer daemon
1859 is part of LTTng-tools.
1861 You don't start a consumer daemon manually: a consumer daemon is always
1862 spawned by a <<lttng-sessiond,session daemon>> as soon as you create an
1863 <<event,event rule>>, that is, before you start tracing. When you kill
1864 its owner session daemon, the consumer daemon also exits because it is
1865 the session daemon's child process. Command-line options of
1866 man:lttng-sessiond(8) target the consumer daemon process.
1868 There are up to two running consumer daemons per Unix user, whereas only
1869 one session daemon can run per user. This is because each process can be
1870 either 32-bit or 64-bit: if the target system runs a mixture of 32-bit
1871 and 64-bit processes, it is more efficient to have separate
1872 corresponding 32-bit and 64-bit consumer daemons. The root user is an
1873 exception: it can have up to _three_ running consumer daemons: 32-bit
1874 and 64-bit instances for its user applications, and one more
1875 reserved for collecting kernel trace data.
1883 image::plumbing-relayd.png[]
1885 The _relay daemon_, man:lttng-relayd(8), is a daemon acting as a bridge
1886 between remote session and consumer daemons, local trace files, and a
1887 remote live trace viewer. The relay daemon is part of LTTng-tools.
1889 The main purpose of the relay daemon is to implement a receiver of
1890 <<sending-trace-data-over-the-network,trace data over the network>>.
1891 This is useful when the target system doesn't have much file system
1892 space to record trace files locally.
1894 The relay daemon is also a server to which a
1895 <<lttng-live,live trace viewer>> can
1896 connect. The live trace viewer sends requests to the relay daemon to
1897 receive trace data as the target system emits events. The
1898 communication protocol is named _LTTng live_; it is used over TCP
1901 Note that you can start the relay daemon on the target system directly.
1902 This is the setup of choice when the use case is to view events as
1903 the target system emits them without the need of a remote system.
1907 == [[using-lttng]]Instrumentation
1909 There are many examples of tracing and monitoring in our everyday life:
1911 * You have access to real-time and historical weather reports and
1912 forecasts thanks to weather stations installed around the country.
1913 * You know your heart is safe thanks to an electrocardiogram.
1914 * You make sure not to drive your car too fast and to have enough fuel
1915 to reach your destination thanks to gauges visible on your dashboard.
1917 All the previous examples have something in common: they rely on
1918 **instruments**. Without the electrodes attached to the surface of your
1919 body's skin, cardiac monitoring is futile.
1921 LTTng, as a tracer, is no different from those real life examples. If
1922 you're about to trace a software system or, in other words, record its
1923 history of execution, you better have **instrumentation points** in the
1924 subject you're tracing, that is, the actual software.
1926 Various ways were developed to instrument a piece of software for LTTng
1927 tracing. The most straightforward one is to manually place
1928 instrumentation points, called _tracepoints_, in the software's source
1929 code. It is also possible to add instrumentation points dynamically in
1930 the Linux kernel <<domain,tracing domain>>.
1932 If you're only interested in tracing the Linux kernel, your
1933 instrumentation needs are probably already covered by LTTng's built-in
1934 <<lttng-modules,Linux kernel tracepoints>>. You may also wish to trace a
1935 user application which is already instrumented for LTTng tracing.
1936 In such cases, skip this whole section and read the topics of
1937 the <<controlling-tracing,Tracing control>> section.
1939 Many methods are available to instrument a piece of software for LTTng
1942 * <<c-application,User space instrumentation for C and $$C++$$
1944 * <<prebuilt-ust-helpers,Prebuilt user space tracing helpers>>.
1945 * <<java-application,User space Java agent>>.
1946 * <<python-application,User space Python agent>>.
1947 * <<proc-lttng-logger-abi,LTTng logger>>.
1948 * <<instrumenting-linux-kernel,LTTng kernel tracepoints>>.
1952 === [[cxx-application]]User space instrumentation for C and $$C++$$ applications
1954 The procedure to instrument a C or $$C++$$ user application with
1955 the <<lttng-ust,LTTng user space tracing library>>, `liblttng-ust`, is:
1957 . <<tracepoint-provider,Create the source files of a tracepoint provider
1959 . <<probing-the-application-source-code,Add tracepoints to
1960 the application's source code>>.
1961 . <<building-tracepoint-providers-and-user-application,Build and link
1962 a tracepoint provider package and the user application>>.
1964 If you need quick, man:printf(3)-like instrumentation, skip
1965 those steps and use <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>>
1968 IMPORTANT: You need to <<installing-lttng,install>> LTTng-UST to
1969 instrument a user application with `liblttng-ust`.
1972 [[tracepoint-provider]]
1973 ==== Create the source files of a tracepoint provider package
1975 A _tracepoint provider_ is a set of compiled functions which provide
1976 **tracepoints** to an application, the type of instrumentation point
1977 supported by LTTng-UST. Those functions can emit events with
1978 user-defined fields and serialize those events as event records to one
1979 or more LTTng-UST <<channel,channel>> sub-buffers. The `tracepoint()`
1980 macro, which you <<probing-the-application-source-code,insert in a user
1981 application's source code>>, calls those functions.
1983 A _tracepoint provider package_ is an object file (`.o`) or a shared
1984 library (`.so`) which contains one or more tracepoint providers.
1985 Its source files are:
1987 * One or more <<tpp-header,tracepoint provider header>> (`.h`).
1988 * A <<tpp-source,tracepoint provider package source>> (`.c`).
1990 A tracepoint provider package is dynamically linked with `liblttng-ust`,
1991 the LTTng user space tracer, at run time.
1994 .User application linked with `liblttng-ust` and containing a tracepoint provider.
1995 image::ust-app.png[]
1997 NOTE: If you need quick, man:printf(3)-like instrumentation,
1998 skip creating and using a tracepoint provider and use
1999 <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>> instead.
2003 ===== Create a tracepoint provider header file template
2005 A _tracepoint provider header file_ contains the tracepoint
2006 definitions of a tracepoint provider.
2008 To create a tracepoint provider header file:
2010 . Start from this template:
2014 .Tracepoint provider header file template (`.h` file extension).
2016 #undef TRACEPOINT_PROVIDER
2017 #define TRACEPOINT_PROVIDER provider_name
2019 #undef TRACEPOINT_INCLUDE
2020 #define TRACEPOINT_INCLUDE "./tp.h"
2022 #if !defined(_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
2025 #include <lttng/tracepoint.h>
2028 * Use TRACEPOINT_EVENT(), TRACEPOINT_EVENT_CLASS(),
2029 * TRACEPOINT_EVENT_INSTANCE(), and TRACEPOINT_LOGLEVEL() here.
2034 #include <lttng/tracepoint-event.h>
2040 * `provider_name` with the name of your tracepoint provider.
2041 * `"tp.h"` with the name of your tracepoint provider header file.
2043 . Below the `#include <lttng/tracepoint.h>` line, put your
2044 <<defining-tracepoints,tracepoint definitions>>.
2046 Your tracepoint provider name must be unique amongst all the possible
2047 tracepoint provider names used on the same target system. We
2048 suggest to include the name of your project or company in the name,
2049 for example, `org_lttng_my_project_tpp`.
2051 TIP: [[lttng-gen-tp]]Use the man:lttng-gen-tp(1) tool to create
2052 this boilerplate for you. When using cmd:lttng-gen-tp, all you need to
2053 write are the <<defining-tracepoints,tracepoint definitions>>.
2056 [[defining-tracepoints]]
2057 ===== Create a tracepoint definition
2059 A _tracepoint definition_ defines, for a given tracepoint:
2061 * Its **input arguments**. They are the macro parameters that the
2062 `tracepoint()` macro accepts for this particular tracepoint
2063 in the user application's source code.
2064 * Its **output event fields**. They are the sources of event fields
2065 that form the payload of any event that the execution of the
2066 `tracepoint()` macro emits for this particular tracepoint.
2068 Create a tracepoint definition by using the
2069 `TRACEPOINT_EVENT()` macro below the `#include <lttng/tracepoint.h>`
2071 <<tpp-header,tracepoint provider header file template>>.
2073 The syntax of the `TRACEPOINT_EVENT()` macro is:
2076 .`TRACEPOINT_EVENT()` macro syntax.
2079 /* Tracepoint provider name */
2082 /* Tracepoint name */
2085 /* Input arguments */
2090 /* Output event fields */
2099 * `provider_name` with your tracepoint provider name.
2100 * `tracepoint_name` with your tracepoint name.
2101 * `arguments` with the <<tpp-def-input-args,input arguments>>.
2102 * `fields` with the <<tpp-def-output-fields,output event field>>
2105 This tracepoint emits events named `provider_name:tracepoint_name`.
2108 .Event name's length limitation
2110 The concatenation of the tracepoint provider name and the
2111 tracepoint name must not exceed **254{nbsp}characters**. If it does, the
2112 instrumented application compiles and runs, but LTTng throws multiple
2113 warnings and you could experience serious issues.
2116 [[tpp-def-input-args]]The syntax of the `TP_ARGS()` macro is:
2119 .`TP_ARGS()` macro syntax.
2128 * `type` with the C type of the argument.
2129 * `arg_name` with the argument name.
2131 You can repeat `type` and `arg_name` up to 10{nbsp}times to have more
2134 .`TP_ARGS()` usage with three arguments.
2146 The `TP_ARGS()` and `TP_ARGS(void)` forms are valid to create a
2147 tracepoint definition with no input arguments.
2149 [[tpp-def-output-fields]]The `TP_FIELDS()` macro contains a list of
2150 `ctf_*()` macros. Each `ctf_*()` macro defines one event field. See
2151 man:lttng-ust(3) for a complete description of the available `ctf_*()`
2152 macros. A `ctf_*()` macro specifies the type, size, and byte order of
2155 Each `ctf_*()` macro takes an _argument expression_ parameter. This is a
2156 C expression that the tracer evalutes at the `tracepoint()` macro site
2157 in the application's source code. This expression provides a field's
2158 source of data. The argument expression can include input argument names
2159 listed in the `TP_ARGS()` macro.
2161 Each `ctf_*()` macro also takes a _field name_ parameter. Field names
2162 must be unique within a given tracepoint definition.
2164 Here's a complete tracepoint definition example:
2166 .Tracepoint definition.
2168 The following tracepoint definition defines a tracepoint which takes
2169 three input arguments and has four output event fields.
2173 #include "my-custom-structure.h"
2179 const struct my_custom_structure*, my_custom_structure,
2184 ctf_string(query_field, query)
2185 ctf_float(double, ratio_field, ratio)
2186 ctf_integer(int, recv_size, my_custom_structure->recv_size)
2187 ctf_integer(int, send_size, my_custom_structure->send_size)
2192 Refer to this tracepoint definition with the `tracepoint()` macro in
2193 your application's source code like this:
2197 tracepoint(my_provider, my_tracepoint,
2198 my_structure, some_ratio, the_query);
2202 NOTE: The LTTng tracer only evaluates tracepoint arguments at run time
2203 if they satisfy an enabled <<event,event rule>>.
2206 [[using-tracepoint-classes]]
2207 ===== Use a tracepoint class
2209 A _tracepoint class_ is a class of tracepoints which share the same
2210 output event field definitions. A _tracepoint instance_ is one
2211 instance of such a defined tracepoint class, with its own tracepoint
2214 The <<defining-tracepoints,`TRACEPOINT_EVENT()` macro>> is actually a
2215 shorthand which defines both a tracepoint class and a tracepoint
2216 instance at the same time.
2218 When you build a tracepoint provider package, the C or $$C++$$ compiler
2219 creates one serialization function for each **tracepoint class**. A
2220 serialization function is responsible for serializing the event fields
2221 of a tracepoint to a sub-buffer when tracing.
2223 For various performance reasons, when your situation requires multiple
2224 tracepoint definitions with different names, but with the same event
2225 fields, we recommend that you manually create a tracepoint class
2226 and instantiate as many tracepoint instances as needed. One positive
2227 effect of such a design, amongst other advantages, is that all
2228 tracepoint instances of the same tracepoint class reuse the same
2229 serialization function, thus reducing
2230 https://en.wikipedia.org/wiki/Cache_pollution[cache pollution].
2232 .Use a tracepoint class and tracepoint instances.
2234 Consider the following three tracepoint definitions:
2246 ctf_integer(int, userid, userid)
2247 ctf_integer(size_t, len, len)
2259 ctf_integer(int, userid, userid)
2260 ctf_integer(size_t, len, len)
2272 ctf_integer(int, userid, userid)
2273 ctf_integer(size_t, len, len)
2278 In this case, we create three tracepoint classes, with one implicit
2279 tracepoint instance for each of them: `get_account`, `get_settings`, and
2280 `get_transaction`. However, they all share the same event field names
2281 and types. Hence three identical, yet independent serialization
2282 functions are created when you build the tracepoint provider package.
2284 A better design choice is to define a single tracepoint class and three
2285 tracepoint instances:
2289 /* The tracepoint class */
2290 TRACEPOINT_EVENT_CLASS(
2291 /* Tracepoint provider name */
2294 /* Tracepoint class name */
2297 /* Input arguments */
2303 /* Output event fields */
2305 ctf_integer(int, userid, userid)
2306 ctf_integer(size_t, len, len)
2310 /* The tracepoint instances */
2311 TRACEPOINT_EVENT_INSTANCE(
2312 /* Tracepoint provider name */
2315 /* Tracepoint class name */
2318 /* Tracepoint name */
2321 /* Input arguments */
2327 TRACEPOINT_EVENT_INSTANCE(
2336 TRACEPOINT_EVENT_INSTANCE(
2349 [[assigning-log-levels]]
2350 ===== Assign a log level to a tracepoint definition
2352 Assign a _log level_ to a <<defining-tracepoints,tracepoint definition>>
2353 with the `TRACEPOINT_LOGLEVEL()` macro.
2355 Assigning different levels of severity to tracepoint definitions can
2356 be useful: when you <<enabling-disabling-events,create an event rule>>,
2357 you can target tracepoints having a log level as severe as a specific
2360 The concept of LTTng-UST log levels is similar to the levels found
2361 in typical logging frameworks:
2363 * In a logging framework, the log level is given by the function
2364 or method name you use at the log statement site: `debug()`,
2365 `info()`, `warn()`, `error()`, and so on.
2366 * In LTTng-UST, you statically assign the log level to a tracepoint
2367 definition; any `tracepoint()` macro invocation which refers to
2368 this definition has this log level.
2370 You must use `TRACEPOINT_LOGLEVEL()` _after_ the
2371 <<defining-tracepoints,`TRACEPOINT_EVENT()`>> or
2372 <<using-tracepoint-classes,`TRACEPOINT_INSTANCE()`>> macro for a given
2375 The syntax of the `TRACEPOINT_LOGLEVEL()` macro is:
2378 .`TRACEPOINT_LOGLEVEL()` macro syntax.
2380 TRACEPOINT_LOGLEVEL(provider_name, tracepoint_name, log_level)
2385 * `provider_name` with the tracepoint provider name.
2386 * `tracepoint_name` with the tracepoint name.
2387 * `log_level` with the log level to assign to the tracepoint
2388 definition named `tracepoint_name` in the `provider_name`
2389 tracepoint provider.
2391 See man:lttng-ust(3) for a list of available log level names.
2393 .Assign the `TRACE_DEBUG_UNIT` log level to a tracepoint definition.
2397 /* Tracepoint definition */
2406 ctf_integer(int, userid, userid)
2407 ctf_integer(size_t, len, len)
2411 /* Log level assignment */
2412 TRACEPOINT_LOGLEVEL(my_app, get_transaction, TRACE_DEBUG_UNIT)
2418 ===== Create a tracepoint provider package source file
2420 A _tracepoint provider package source file_ is a C source file which
2421 includes a <<tpp-header,tracepoint provider header file>> to expand its
2422 macros into event serialization and other functions.
2424 Use the following tracepoint provider package source file template:
2427 .Tracepoint provider package source file template.
2429 #define TRACEPOINT_CREATE_PROBES
2434 Replace `tp.h` with the name of your <<tpp-header,tracepoint provider
2435 header file>> name. You may also include more than one tracepoint
2436 provider header file here to create a tracepoint provider package
2437 holding more than one tracepoint providers.
2440 [[probing-the-application-source-code]]
2441 ==== Add tracepoints to an application's source code
2443 Once you <<tpp-header,create a tracepoint provider header file>>,
2444 use the `tracepoint()` macro in your application's source code to insert
2445 the tracepoints that this header <<defining-tracepoints,defines>>.
2447 The `tracepoint()` macro takes at least two parameters: the tracepoint
2448 provider name and the tracepoint name. The corresponding tracepoint
2449 definition defines the other parameters.
2451 .`tracepoint()` usage.
2453 The following <<defining-tracepoints,tracepoint definition>> defines a
2454 tracepoint which takes two input arguments and has two output event
2458 .Tracepoint provider header file.
2460 #include "my-custom-structure.h"
2467 const char*, cmd_name
2470 ctf_string(cmd_name, cmd_name)
2471 ctf_integer(int, number_of_args, argc)
2476 Refer to this tracepoint definition with the `tracepoint()` macro in
2477 your application's source code like this:
2480 .Application's source file.
2484 int main(int argc, char* argv[])
2486 tracepoint(my_provider, my_tracepoint, argc, argv[0]);
2492 Note how the application's source code includes
2493 the tracepoint provider header file containing the tracepoint
2494 definitions to use, path:{tp.h}.
2497 .`tracepoint()` usage with a complex tracepoint definition.
2499 Consider this complex tracepoint definition, where multiple event
2500 fields refer to the same input arguments in their argument expression
2504 .Tracepoint provider header file.
2506 /* For `struct stat` */
2507 #include <sys/types.h>
2508 #include <sys/stat.h>
2520 ctf_integer(int, my_constant_field, 23 + 17)
2521 ctf_integer(int, my_int_arg_field, my_int_arg)
2522 ctf_integer(int, my_int_arg_field2, my_int_arg * my_int_arg)
2523 ctf_integer(int, sum4_field, my_str_arg[0] + my_str_arg[1] +
2524 my_str_arg[2] + my_str_arg[3])
2525 ctf_string(my_str_arg_field, my_str_arg)
2526 ctf_integer_hex(off_t, size_field, st->st_size)
2527 ctf_float(double, size_dbl_field, (double) st->st_size)
2528 ctf_sequence_text(char, half_my_str_arg_field, my_str_arg,
2529 size_t, strlen(my_str_arg) / 2)
2534 Refer to this tracepoint definition with the `tracepoint()` macro in
2535 your application's source code like this:
2538 .Application's source file.
2540 #define TRACEPOINT_DEFINE
2547 stat("/etc/fstab", &s);
2548 tracepoint(my_provider, my_tracepoint, 23, "Hello, World!", &s);
2554 If you look at the event record that LTTng writes when tracing this
2555 program, assuming the file size of path:{/etc/fstab} is 301{nbsp}bytes,
2556 it should look like this:
2558 .Event record fields
2560 |Field's name |Field's value
2561 |`my_constant_field` |40
2562 |`my_int_arg_field` |23
2563 |`my_int_arg_field2` |529
2565 |`my_str_arg_field` |`Hello, World!`
2566 |`size_field` |0x12d
2567 |`size_dbl_field` |301.0
2568 |`half_my_str_arg_field` |`Hello,`
2572 Sometimes, the arguments you pass to `tracepoint()` are expensive to
2573 compute--they use the call stack, for example. To avoid this computation
2574 when the tracepoint is disabled, use the `tracepoint_enabled()` and
2575 `do_tracepoint()` macros.
2577 The syntax of the `tracepoint_enabled()` and `do_tracepoint()` macros
2581 .`tracepoint_enabled()` and `do_tracepoint()` macros syntax.
2583 tracepoint_enabled(provider_name, tracepoint_name)
2584 do_tracepoint(provider_name, tracepoint_name, ...)
2589 * `provider_name` with the tracepoint provider name.
2590 * `tracepoint_name` with the tracepoint name.
2592 `tracepoint_enabled()` returns a non-zero value if the tracepoint named
2593 `tracepoint_name` from the provider named `provider_name` is enabled
2596 `do_tracepoint()` is like `tracepoint()`, except that it doesn't check
2597 if the tracepoint is enabled. Using `tracepoint()` with
2598 `tracepoint_enabled()` is dangerous since `tracepoint()` also contains
2599 the `tracepoint_enabled()` check, thus a race condition is
2600 possible in this situation:
2603 .Possible race condition when using `tracepoint_enabled()` with `tracepoint()`.
2605 if (tracepoint_enabled(my_provider, my_tracepoint)) {
2606 stuff = prepare_stuff();
2609 tracepoint(my_provider, my_tracepoint, stuff);
2612 If the tracepoint is enabled after the condition, then `stuff` isn't
2613 prepared: the emitted event will either contain wrong data, or the whole
2614 application could crash (segmentation fault, for example).
2616 NOTE: Neither `tracepoint_enabled()` nor `do_tracepoint()` have an
2617 `STAP_PROBEV()` call. If you need it, you must emit
2621 [[building-tracepoint-providers-and-user-application]]
2622 ==== Build and link a tracepoint provider package and an application
2624 Once you have one or more <<tpp-header,tracepoint provider header
2625 files>> and a <<tpp-source,tracepoint provider package source file>>,
2626 create the tracepoint provider package by compiling its source
2627 file. From here, multiple build and run scenarios are possible. The
2628 following table shows common application and library configurations
2629 along with the required command lines to achieve them.
2631 In the following diagrams, we use the following file names:
2634 Executable application.
2637 Application's object file.
2640 Tracepoint provider package object file.
2643 Tracepoint provider package archive file.
2646 Tracepoint provider package shared object file.
2649 User library object file.
2652 User library shared object file.
2654 We use the following symbols in the diagrams of table below:
2657 .Symbols used in the build scenario diagrams.
2658 image::ust-sit-symbols.png[]
2660 We assume that path:{.} is part of the env:LD_LIBRARY_PATH environment
2661 variable in the following instructions.
2663 [role="growable ust-scenarios",cols="asciidoc,asciidoc"]
2664 .Common tracepoint provider package scenarios.
2666 |Scenario |Instructions
2669 The instrumented application is statically linked with
2670 the tracepoint provider package object.
2672 image::ust-sit+app-linked-with-tp-o+app-instrumented.png[]
2675 include::../common/ust-sit-step-tp-o.txt[]
2677 To build the instrumented application:
2679 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2684 #define TRACEPOINT_DEFINE
2688 . Compile the application source file:
2697 . Build the application:
2702 $ gcc -o app app.o tpp.o -llttng-ust -ldl
2706 To run the instrumented application:
2708 * Start the application:
2718 The instrumented application is statically linked with the
2719 tracepoint provider package archive file.
2721 image::ust-sit+app-linked-with-tp-a+app-instrumented.png[]
2724 To create the tracepoint provider package archive file:
2726 . Compile the <<tpp-source,tracepoint provider package source file>>:
2735 . Create the tracepoint provider package archive file:
2740 $ ar rcs tpp.a tpp.o
2744 To build the instrumented application:
2746 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2751 #define TRACEPOINT_DEFINE
2755 . Compile the application source file:
2764 . Build the application:
2769 $ gcc -o app app.o tpp.a -llttng-ust -ldl
2773 To run the instrumented application:
2775 * Start the application:
2785 The instrumented application is linked with the tracepoint provider
2786 package shared object.
2788 image::ust-sit+app-linked-with-tp-so+app-instrumented.png[]
2791 include::../common/ust-sit-step-tp-so.txt[]
2793 To build the instrumented application:
2795 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2800 #define TRACEPOINT_DEFINE
2804 . Compile the application source file:
2813 . Build the application:
2818 $ gcc -o app app.o -ldl -L. -ltpp
2822 To run the instrumented application:
2824 * Start the application:
2834 The tracepoint provider package shared object is preloaded before the
2835 instrumented application starts.
2837 image::ust-sit+tp-so-preloaded+app-instrumented.png[]
2840 include::../common/ust-sit-step-tp-so.txt[]
2842 To build the instrumented application:
2844 . In path:{app.c}, before including path:{tpp.h}, add the
2850 #define TRACEPOINT_DEFINE
2851 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
2855 . Compile the application source file:
2864 . Build the application:
2869 $ gcc -o app app.o -ldl
2873 To run the instrumented application with tracing support:
2875 * Preload the tracepoint provider package shared object and
2876 start the application:
2881 $ LD_PRELOAD=./libtpp.so ./app
2885 To run the instrumented application without tracing support:
2887 * Start the application:
2897 The instrumented application dynamically loads the tracepoint provider
2898 package shared object.
2900 image::ust-sit+app-dlopens-tp-so+app-instrumented.png[]
2903 include::../common/ust-sit-step-tp-so.txt[]
2905 To build the instrumented application:
2907 . In path:{app.c}, before including path:{tpp.h}, add the
2913 #define TRACEPOINT_DEFINE
2914 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
2918 . Compile the application source file:
2927 . Build the application:
2932 $ gcc -o app app.o -ldl
2936 To run the instrumented application:
2938 * Start the application:
2948 The application is linked with the instrumented user library.
2950 The instrumented user library is statically linked with the tracepoint
2951 provider package object file.
2953 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-o+lib-instrumented.png[]
2956 include::../common/ust-sit-step-tp-o-fpic.txt[]
2958 To build the instrumented user library:
2960 . In path:{emon.c}, before including path:{tpp.h}, add the
2966 #define TRACEPOINT_DEFINE
2970 . Compile the user library source file:
2975 $ gcc -I. -fpic -c emon.c
2979 . Build the user library shared object:
2984 $ gcc -shared -o libemon.so emon.o tpp.o -llttng-ust -ldl
2988 To build the application:
2990 . Compile the application source file:
2999 . Build the application:
3004 $ gcc -o app app.o -L. -lemon
3008 To run the application:
3010 * Start the application:
3020 The application is linked with the instrumented user library.
3022 The instrumented user library is linked with the tracepoint provider
3023 package shared object.
3025 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3028 include::../common/ust-sit-step-tp-so.txt[]
3030 To build the instrumented user library:
3032 . In path:{emon.c}, before including path:{tpp.h}, add the
3038 #define TRACEPOINT_DEFINE
3042 . Compile the user library source file:
3047 $ gcc -I. -fpic -c emon.c
3051 . Build the user library shared object:
3056 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3060 To build the application:
3062 . Compile the application source file:
3071 . Build the application:
3076 $ gcc -o app app.o -L. -lemon
3080 To run the application:
3082 * Start the application:
3092 The tracepoint provider package shared object is preloaded before the
3095 The application is linked with the instrumented user library.
3097 image::ust-sit+tp-so-preloaded+app-linked-with-lib+lib-instrumented.png[]
3100 include::../common/ust-sit-step-tp-so.txt[]
3102 To build the instrumented user library:
3104 . In path:{emon.c}, before including path:{tpp.h}, add the
3110 #define TRACEPOINT_DEFINE
3111 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3115 . Compile the user library source file:
3120 $ gcc -I. -fpic -c emon.c
3124 . Build the user library shared object:
3129 $ gcc -shared -o libemon.so emon.o -ldl
3133 To build the application:
3135 . Compile the application source file:
3144 . Build the application:
3149 $ gcc -o app app.o -L. -lemon
3153 To run the application with tracing support:
3155 * Preload the tracepoint provider package shared object and
3156 start the application:
3161 $ LD_PRELOAD=./libtpp.so ./app
3165 To run the application without tracing support:
3167 * Start the application:
3177 The application is linked with the instrumented user library.
3179 The instrumented user library dynamically loads the tracepoint provider
3180 package shared object.
3182 image::ust-sit+app-linked-with-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3185 include::../common/ust-sit-step-tp-so.txt[]
3187 To build the instrumented user library:
3189 . In path:{emon.c}, before including path:{tpp.h}, add the
3195 #define TRACEPOINT_DEFINE
3196 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3200 . Compile the user library source file:
3205 $ gcc -I. -fpic -c emon.c
3209 . Build the user library shared object:
3214 $ gcc -shared -o libemon.so emon.o -ldl
3218 To build the application:
3220 . Compile the application source file:
3229 . Build the application:
3234 $ gcc -o app app.o -L. -lemon
3238 To run the application:
3240 * Start the application:
3250 The application dynamically loads the instrumented user library.
3252 The instrumented user library is linked with the tracepoint provider
3253 package shared object.
3255 image::ust-sit+app-dlopens-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3258 include::../common/ust-sit-step-tp-so.txt[]
3260 To build the instrumented user library:
3262 . In path:{emon.c}, before including path:{tpp.h}, add the
3268 #define TRACEPOINT_DEFINE
3272 . Compile the user library source file:
3277 $ gcc -I. -fpic -c emon.c
3281 . Build the user library shared object:
3286 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3290 To build the application:
3292 . Compile the application source file:
3301 . Build the application:
3306 $ gcc -o app app.o -ldl -L. -lemon
3310 To run the application:
3312 * Start the application:
3322 The application dynamically loads the instrumented user library.
3324 The instrumented user library dynamically loads the tracepoint provider
3325 package shared object.
3327 image::ust-sit+app-dlopens-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3330 include::../common/ust-sit-step-tp-so.txt[]
3332 To build the instrumented user library:
3334 . In path:{emon.c}, before including path:{tpp.h}, add the
3340 #define TRACEPOINT_DEFINE
3341 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3345 . Compile the user library source file:
3350 $ gcc -I. -fpic -c emon.c
3354 . Build the user library shared object:
3359 $ gcc -shared -o libemon.so emon.o -ldl
3363 To build the application:
3365 . Compile the application source file:
3374 . Build the application:
3379 $ gcc -o app app.o -ldl -L. -lemon
3383 To run the application:
3385 * Start the application:
3395 The tracepoint provider package shared object is preloaded before the
3398 The application dynamically loads the instrumented user library.
3400 image::ust-sit+tp-so-preloaded+app-dlopens-lib+lib-instrumented.png[]
3403 include::../common/ust-sit-step-tp-so.txt[]
3405 To build the instrumented user library:
3407 . In path:{emon.c}, before including path:{tpp.h}, add the
3413 #define TRACEPOINT_DEFINE
3414 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3418 . Compile the user library source file:
3423 $ gcc -I. -fpic -c emon.c
3427 . Build the user library shared object:
3432 $ gcc -shared -o libemon.so emon.o -ldl
3436 To build the application:
3438 . Compile the application source file:
3447 . Build the application:
3452 $ gcc -o app app.o -L. -lemon
3456 To run the application with tracing support:
3458 * Preload the tracepoint provider package shared object and
3459 start the application:
3464 $ LD_PRELOAD=./libtpp.so ./app
3468 To run the application without tracing support:
3470 * Start the application:
3480 The application is statically linked with the tracepoint provider
3481 package object file.
3483 The application is linked with the instrumented user library.
3485 image::ust-sit+app-linked-with-tp-o+app-linked-with-lib+lib-instrumented.png[]
3488 include::../common/ust-sit-step-tp-o.txt[]
3490 To build the instrumented user library:
3492 . In path:{emon.c}, before including path:{tpp.h}, add the
3498 #define TRACEPOINT_DEFINE
3502 . Compile the user library source file:
3507 $ gcc -I. -fpic -c emon.c
3511 . Build the user library shared object:
3516 $ gcc -shared -o libemon.so emon.o
3520 To build the application:
3522 . Compile the application source file:
3531 . Build the application:
3536 $ gcc -o app app.o tpp.o -llttng-ust -ldl -L. -lemon
3540 To run the instrumented application:
3542 * Start the application:
3552 The application is statically linked with the tracepoint provider
3553 package object file.
3555 The application dynamically loads the instrumented user library.
3557 image::ust-sit+app-linked-with-tp-o+app-dlopens-lib+lib-instrumented.png[]
3560 include::../common/ust-sit-step-tp-o.txt[]
3562 To build the application:
3564 . In path:{app.c}, before including path:{tpp.h}, add the following line:
3569 #define TRACEPOINT_DEFINE
3573 . Compile the application source file:
3582 . Build the application:
3587 $ gcc -Wl,--export-dynamic -o app app.o tpp.o \
3592 The `--export-dynamic` option passed to the linker is necessary for the
3593 dynamically loaded library to ``see'' the tracepoint symbols defined in
3596 To build the instrumented user library:
3598 . Compile the user library source file:
3603 $ gcc -I. -fpic -c emon.c
3607 . Build the user library shared object:
3612 $ gcc -shared -o libemon.so emon.o
3616 To run the application:
3618 * Start the application:
3629 [[using-lttng-ust-with-daemons]]
3630 ===== Use noch:{LTTng-UST} with daemons
3632 If your instrumented application calls man:fork(2), man:clone(2),
3633 or BSD's man:rfork(2), without a following man:exec(3)-family
3634 system call, you must preload the path:{liblttng-ust-fork.so} shared
3635 object when you start the application.
3639 $ LD_PRELOAD=liblttng-ust-fork.so ./my-app
3642 If your tracepoint provider package is
3643 a shared library which you also preload, you must put both
3644 shared objects in env:LD_PRELOAD:
3648 $ LD_PRELOAD=liblttng-ust-fork.so:/path/to/tp.so ./my-app
3654 ===== Use noch:{LTTng-UST} with applications which close file descriptors that don't belong to them
3656 If your instrumented application closes one or more file descriptors
3657 which it did not open itself, you must preload the
3658 path:{liblttng-ust-fd.so} shared object when you start the application:
3662 $ LD_PRELOAD=liblttng-ust-fd.so ./my-app
3665 Typical use cases include closing all the file descriptors after
3666 man:fork(2) or man:rfork(2) and buggy applications doing
3670 [[lttng-ust-pkg-config]]
3671 ===== Use noch:{pkg-config}
3673 On some distributions, LTTng-UST ships with a
3674 https://www.freedesktop.org/wiki/Software/pkg-config/[pkg-config]
3675 metadata file. If this is your case, then use cmd:pkg-config to
3676 build an application on the command line:
3680 $ gcc -o my-app my-app.o tp.o $(pkg-config --cflags --libs lttng-ust)
3684 [[instrumenting-32-bit-app-on-64-bit-system]]
3685 ===== [[advanced-instrumenting-techniques]]Build a 32-bit instrumented application for a 64-bit target system
3687 In order to trace a 32-bit application running on a 64-bit system,
3688 LTTng must use a dedicated 32-bit
3689 <<lttng-consumerd,consumer daemon>>.
3691 The following steps show how to build and install a 32-bit consumer
3692 daemon, which is _not_ part of the default 64-bit LTTng build, how to
3693 build and install the 32-bit LTTng-UST libraries, and how to build and
3694 link an instrumented 32-bit application in that context.
3696 To build a 32-bit instrumented application for a 64-bit target system,
3697 assuming you have a fresh target system with no installed Userspace RCU
3700 . Download, build, and install a 32-bit version of Userspace RCU:
3705 $ cd $(mktemp -d) &&
3706 wget http://lttng.org/files/urcu/userspace-rcu-latest-0.9.tar.bz2 &&
3707 tar -xf userspace-rcu-latest-0.9.tar.bz2 &&
3708 cd userspace-rcu-0.9.* &&
3709 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 &&
3711 sudo make install &&
3716 . Using your distribution's package manager, or from source, install
3717 the following 32-bit versions of the following dependencies of
3718 LTTng-tools and LTTng-UST:
3721 * https://sourceforge.net/projects/libuuid/[libuuid]
3722 * http://directory.fsf.org/wiki/Popt[popt]
3723 * http://www.xmlsoft.org/[libxml2]
3726 . Download, build, and install a 32-bit version of the latest
3727 LTTng-UST{nbsp}{revision}:
3732 $ cd $(mktemp -d) &&
3733 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.12.tar.bz2 &&
3734 tar -xf lttng-ust-latest-2.12.tar.bz2 &&
3735 cd lttng-ust-2.12.* &&
3736 ./configure --libdir=/usr/local/lib32 \
3737 CFLAGS=-m32 CXXFLAGS=-m32 \
3738 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' &&
3740 sudo make install &&
3747 Depending on your distribution,
3748 32-bit libraries could be installed at a different location than
3749 `/usr/lib32`. For example, Debian is known to install
3750 some 32-bit libraries in `/usr/lib/i386-linux-gnu`.
3752 In this case, make sure to set `LDFLAGS` to all the
3753 relevant 32-bit library paths, for example:
3757 $ LDFLAGS='-L/usr/lib/i386-linux-gnu -L/usr/lib32'
3761 . Download the latest LTTng-tools{nbsp}{revision}, build, and install
3762 the 32-bit consumer daemon:
3767 $ cd $(mktemp -d) &&
3768 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.12.tar.bz2 &&
3769 tar -xf lttng-tools-latest-2.12.tar.bz2 &&
3770 cd lttng-tools-2.12.* &&
3771 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 CXXFLAGS=-m32 \
3772 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' \
3773 --disable-bin-lttng --disable-bin-lttng-crash \
3774 --disable-bin-lttng-relayd --disable-bin-lttng-sessiond &&
3776 cd src/bin/lttng-consumerd &&
3777 sudo make install &&
3782 . From your distribution or from source,
3783 <<installing-lttng,install>> the 64-bit versions of
3784 LTTng-UST and Userspace RCU.
3785 . Download, build, and install the 64-bit version of the
3786 latest LTTng-tools{nbsp}{revision}:
3791 $ cd $(mktemp -d) &&
3792 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.12.tar.bz2 &&
3793 tar -xf lttng-tools-latest-2.12.tar.bz2 &&
3794 cd lttng-tools-2.12.* &&
3795 ./configure --with-consumerd32-libdir=/usr/local/lib32 \
3796 --with-consumerd32-bin=/usr/local/lib32/lttng/libexec/lttng-consumerd &&
3798 sudo make install &&
3803 . Pass the following options to man:gcc(1), man:g++(1), or man:clang(1)
3804 when linking your 32-bit application:
3807 -m32 -L/usr/lib32 -L/usr/local/lib32 \
3808 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32
3811 For example, let's rebuild the quick start example in
3812 <<tracing-your-own-user-application,Trace a user application>> as an
3813 instrumented 32-bit application:
3818 $ gcc -m32 -c -I. hello-tp.c
3819 $ gcc -m32 -c hello.c
3820 $ gcc -m32 -o hello hello.o hello-tp.o \
3821 -L/usr/lib32 -L/usr/local/lib32 \
3822 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32 \
3827 No special action is required to execute the 32-bit application and
3828 to trace it: use the command-line man:lttng(1) tool as usual.
3835 man:tracef(3) is a small LTTng-UST API designed for quick,
3836 man:printf(3)-like instrumentation without the burden of
3837 <<tracepoint-provider,creating>> and
3838 <<building-tracepoint-providers-and-user-application,building>>
3839 a tracepoint provider package.
3841 To use `tracef()` in your application:
3843 . In the C or C++ source files where you need to use `tracef()`,
3844 include `<lttng/tracef.h>`:
3849 #include <lttng/tracef.h>
3853 . In the application's source code, use `tracef()` like you would use
3861 tracef("my message: %d (%s)", my_integer, my_string);
3867 . Link your application with `liblttng-ust`:
3872 $ gcc -o app app.c -llttng-ust
3876 To trace the events that `tracef()` calls emit:
3878 * <<enabling-disabling-events,Create an event rule>> which matches the
3879 `lttng_ust_tracef:*` event name:
3884 $ lttng enable-event --userspace 'lttng_ust_tracef:*'
3889 .Limitations of `tracef()`
3891 The `tracef()` utility function was developed to make user space tracing
3892 super simple, albeit with notable disadvantages compared to
3893 <<defining-tracepoints,user-defined tracepoints>>:
3895 * All the emitted events have the same tracepoint provider and
3896 tracepoint names, respectively `lttng_ust_tracef` and `event`.
3897 * There is no static type checking.
3898 * The only event record field you actually get, named `msg`, is a string
3899 potentially containing the values you passed to `tracef()`
3900 using your own format string. This also means that you can't filter
3901 events with a custom expression at run time because there are no
3903 * Since `tracef()` uses the C standard library's man:vasprintf(3)
3904 function behind the scenes to format the strings at run time, its
3905 expected performance is lower than with user-defined tracepoints,
3906 which don't require a conversion to a string.
3908 Taking this into consideration, `tracef()` is useful for some quick
3909 prototyping and debugging, but you shouldn't consider it for any
3910 permanent and serious applicative instrumentation.
3916 ==== Use `tracelog()`
3918 The man:tracelog(3) API is very similar to <<tracef,`tracef()`>>, with
3919 the difference that it accepts an additional log level parameter.
3921 The goal of `tracelog()` is to ease the migration from logging to
3924 To use `tracelog()` in your application:
3926 . In the C or C++ source files where you need to use `tracelog()`,
3927 include `<lttng/tracelog.h>`:
3932 #include <lttng/tracelog.h>
3936 . In the application's source code, use `tracelog()` like you would use
3937 man:printf(3), except for the first parameter which is the log
3945 tracelog(TRACE_WARNING, "my message: %d (%s)",
3946 my_integer, my_string);
3952 See man:lttng-ust(3) for a list of available log level names.
3954 . Link your application with `liblttng-ust`:
3959 $ gcc -o app app.c -llttng-ust
3963 To trace the events that `tracelog()` calls emit with a log level
3964 _as severe as_ a specific log level:
3966 * <<enabling-disabling-events,Create an event rule>> which matches the
3967 `lttng_ust_tracelog:*` event name and a minimum level
3973 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
3974 --loglevel=TRACE_WARNING
3978 To trace the events that `tracelog()` calls emit with a
3979 _specific log level_:
3981 * Create an event rule which matches the `lttng_ust_tracelog:*`
3982 event name and a specific log level:
3987 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
3988 --loglevel-only=TRACE_INFO
3993 [[prebuilt-ust-helpers]]
3994 === Prebuilt user space tracing helpers
3996 The LTTng-UST package provides a few helpers in the form or preloadable
3997 shared objects which automatically instrument system functions and
4000 The helper shared objects are normally found in dir:{/usr/lib}. If you
4001 built LTTng-UST <<building-from-source,from source>>, they are probably
4002 located in dir:{/usr/local/lib}.
4004 The installed user space tracing helpers in LTTng-UST{nbsp}{revision}
4007 path:{liblttng-ust-libc-wrapper.so}::
4008 path:{liblttng-ust-pthread-wrapper.so}::
4009 <<liblttng-ust-libc-pthread-wrapper,C{nbsp}standard library
4010 memory and POSIX threads function tracing>>.
4012 path:{liblttng-ust-cyg-profile.so}::
4013 path:{liblttng-ust-cyg-profile-fast.so}::
4014 <<liblttng-ust-cyg-profile,Function entry and exit tracing>>.
4016 path:{liblttng-ust-dl.so}::
4017 <<liblttng-ust-dl,Dynamic linker tracing>>.
4019 To use a user space tracing helper with any user application:
4021 * Preload the helper shared object when you start the application:
4026 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so my-app
4030 You can preload more than one helper:
4035 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so:liblttng-ust-dl.so my-app
4041 [[liblttng-ust-libc-pthread-wrapper]]
4042 ==== Instrument C standard library memory and POSIX threads functions
4044 The path:{liblttng-ust-libc-wrapper.so} and
4045 path:{liblttng-ust-pthread-wrapper.so} helpers
4046 add instrumentation to some C standard library and POSIX
4050 .Functions instrumented by preloading path:{liblttng-ust-libc-wrapper.so}.
4052 |TP provider name |TP name |Instrumented function
4054 .6+|`lttng_ust_libc` |`malloc` |man:malloc(3)
4055 |`calloc` |man:calloc(3)
4056 |`realloc` |man:realloc(3)
4057 |`free` |man:free(3)
4058 |`memalign` |man:memalign(3)
4059 |`posix_memalign` |man:posix_memalign(3)
4063 .Functions instrumented by preloading path:{liblttng-ust-pthread-wrapper.so}.
4065 |TP provider name |TP name |Instrumented function
4067 .4+|`lttng_ust_pthread` |`pthread_mutex_lock_req` |man:pthread_mutex_lock(3p) (request time)
4068 |`pthread_mutex_lock_acq` |man:pthread_mutex_lock(3p) (acquire time)
4069 |`pthread_mutex_trylock` |man:pthread_mutex_trylock(3p)
4070 |`pthread_mutex_unlock` |man:pthread_mutex_unlock(3p)
4073 When you preload the shared object, it replaces the functions listed
4074 in the previous tables by wrappers which contain tracepoints and call
4075 the replaced functions.
4078 [[liblttng-ust-cyg-profile]]
4079 ==== Instrument function entry and exit
4081 The path:{liblttng-ust-cyg-profile*.so} helpers can add instrumentation
4082 to the entry and exit points of functions.
4084 man:gcc(1) and man:clang(1) have an option named
4085 https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html[`-finstrument-functions`]
4086 which generates instrumentation calls for entry and exit to functions.
4087 The LTTng-UST function tracing helpers,
4088 path:{liblttng-ust-cyg-profile.so} and
4089 path:{liblttng-ust-cyg-profile-fast.so}, take advantage of this feature
4090 to add tracepoints to the two generated functions (which contain
4091 `cyg_profile` in their names, hence the helper's name).
4093 To use the LTTng-UST function tracing helper, the source files to
4094 instrument must be built using the `-finstrument-functions` compiler
4097 There are two versions of the LTTng-UST function tracing helper:
4099 * **path:{liblttng-ust-cyg-profile-fast.so}** is a lightweight variant
4100 that you should only use when it can be _guaranteed_ that the
4101 complete event stream is recorded without any lost event record.
4102 Any kind of duplicate information is left out.
4104 Assuming no event record is lost, having only the function addresses on
4105 entry is enough to create a call graph, since an event record always
4106 contains the ID of the CPU that generated it.
4108 Use a tool like man:addr2line(1) to convert function addresses back to
4109 source file names and line numbers.
4111 * **path:{liblttng-ust-cyg-profile.so}** is a more robust variant
4112 which also works in use cases where event records might get discarded or
4113 not recorded from application startup.
4114 In these cases, the trace analyzer needs more information to be
4115 able to reconstruct the program flow.
4117 See man:lttng-ust-cyg-profile(3) to learn more about the instrumentation
4118 points of this helper.
4120 All the tracepoints that this helper provides have the
4121 log level `TRACE_DEBUG_FUNCTION` (see man:lttng-ust(3)).
4123 TIP: It's sometimes a good idea to limit the number of source files that
4124 you compile with the `-finstrument-functions` option to prevent LTTng
4125 from writing an excessive amount of trace data at run time. When using
4127 `-finstrument-functions-exclude-function-list` option to avoid
4128 instrument entries and exits of specific function names.
4133 ==== Instrument the dynamic linker
4135 The path:{liblttng-ust-dl.so} helper adds instrumentation to the
4136 man:dlopen(3) and man:dlclose(3) function calls.
4138 See man:lttng-ust-dl(3) to learn more about the instrumentation points
4143 [[java-application]]
4144 === User space Java agent
4146 You can instrument any Java application which uses one of the following
4149 * The https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[**`java.util.logging`**]
4150 (JUL) core logging facilities.
4151 * http://logging.apache.org/log4j/1.2/[**Apache log4j{nbsp}1.2**], since
4152 LTTng{nbsp}2.6. Note that Apache Log4j{nbsp}2 isn't supported.
4155 .LTTng-UST Java agent imported by a Java application.
4156 image::java-app.png[]
4158 Note that the methods described below are new in LTTng{nbsp}2.8.
4159 Previous LTTng versions use another technique.
4161 NOTE: We use http://openjdk.java.net/[OpenJDK]{nbsp}8 for development
4162 and https://ci.lttng.org/[continuous integration], thus this version is
4163 directly supported. However, the LTTng-UST Java agent is also tested
4164 with OpenJDK{nbsp}7.
4169 ==== Use the LTTng-UST Java agent for `java.util.logging`
4171 To use the LTTng-UST Java agent in a Java application which uses
4172 `java.util.logging` (JUL):
4174 . In the Java application's source code, import the LTTng-UST
4175 log handler package for `java.util.logging`:
4180 import org.lttng.ust.agent.jul.LttngLogHandler;
4184 . Create an LTTng-UST JUL log handler:
4189 Handler lttngUstLogHandler = new LttngLogHandler();
4193 . Add this handler to the JUL loggers which should emit LTTng events:
4198 Logger myLogger = Logger.getLogger("some-logger");
4200 myLogger.addHandler(lttngUstLogHandler);
4204 . Use `java.util.logging` log statements and configuration as usual.
4205 The loggers with an attached LTTng-UST log handler can emit
4208 . Before exiting the application, remove the LTTng-UST log handler from
4209 the loggers attached to it and call its `close()` method:
4214 myLogger.removeHandler(lttngUstLogHandler);
4215 lttngUstLogHandler.close();
4219 This isn't strictly necessary, but it is recommended for a clean
4220 disposal of the handler's resources.
4222 . Include the LTTng-UST Java agent's common and JUL-specific JAR files,
4223 path:{lttng-ust-agent-common.jar} and path:{lttng-ust-agent-jul.jar},
4225 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4226 path] when you build the Java application.
4228 The JAR files are typically located in dir:{/usr/share/java}.
4230 IMPORTANT: The LTTng-UST Java agent must be
4231 <<installing-lttng,installed>> for the logging framework your
4234 .Use the LTTng-UST Java agent for `java.util.logging`.
4239 import java.io.IOException;
4240 import java.util.logging.Handler;
4241 import java.util.logging.Logger;
4242 import org.lttng.ust.agent.jul.LttngLogHandler;
4246 private static final int answer = 42;
4248 public static void main(String[] argv) throws Exception
4251 Logger logger = Logger.getLogger("jello");
4253 // Create an LTTng-UST log handler
4254 Handler lttngUstLogHandler = new LttngLogHandler();
4256 // Add the LTTng-UST log handler to our logger
4257 logger.addHandler(lttngUstLogHandler);
4260 logger.info("some info");
4261 logger.warning("some warning");
4263 logger.finer("finer information; the answer is " + answer);
4265 logger.severe("error!");
4267 // Not mandatory, but cleaner
4268 logger.removeHandler(lttngUstLogHandler);
4269 lttngUstLogHandler.close();
4278 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4281 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4282 <<enabling-disabling-events,create an event rule>> matching the
4283 `jello` JUL logger, and <<basic-tracing-session-control,start tracing>>:
4288 $ lttng enable-event --jul jello
4292 Run the compiled class:
4296 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4299 <<basic-tracing-session-control,Stop tracing>> and inspect the
4309 In the resulting trace, an <<event,event record>> generated by a Java
4310 application using `java.util.logging` is named `lttng_jul:event` and
4311 has the following fields:
4314 Log record's message.
4320 Name of the class in which the log statement was executed.
4323 Name of the method in which the log statement was executed.
4326 Logging time (timestamp in milliseconds).
4329 Log level integer value.
4332 ID of the thread in which the log statement was executed.
4334 Use the opt:lttng-enable-event(1):--loglevel or
4335 opt:lttng-enable-event(1):--loglevel-only option of the
4336 man:lttng-enable-event(1) command to target a range of JUL log levels
4337 or a specific JUL log level.
4342 ==== Use the LTTng-UST Java agent for Apache log4j
4344 To use the LTTng-UST Java agent in a Java application which uses
4345 Apache log4j{nbsp}1.2:
4347 . In the Java application's source code, import the LTTng-UST
4348 log appender package for Apache log4j:
4353 import org.lttng.ust.agent.log4j.LttngLogAppender;
4357 . Create an LTTng-UST log4j log appender:
4362 Appender lttngUstLogAppender = new LttngLogAppender();
4366 . Add this appender to the log4j loggers which should emit LTTng events:
4371 Logger myLogger = Logger.getLogger("some-logger");
4373 myLogger.addAppender(lttngUstLogAppender);
4377 . Use Apache log4j log statements and configuration as usual. The
4378 loggers with an attached LTTng-UST log appender can emit LTTng events.
4380 . Before exiting the application, remove the LTTng-UST log appender from
4381 the loggers attached to it and call its `close()` method:
4386 myLogger.removeAppender(lttngUstLogAppender);
4387 lttngUstLogAppender.close();
4391 This isn't strictly necessary, but it is recommended for a clean
4392 disposal of the appender's resources.
4394 . Include the LTTng-UST Java agent's common and log4j-specific JAR
4395 files, path:{lttng-ust-agent-common.jar} and
4396 path:{lttng-ust-agent-log4j.jar}, in the
4397 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4398 path] when you build the Java application.
4400 The JAR files are typically located in dir:{/usr/share/java}.
4402 IMPORTANT: The LTTng-UST Java agent must be
4403 <<installing-lttng,installed>> for the logging framework your
4406 .Use the LTTng-UST Java agent for Apache log4j.
4411 import org.apache.log4j.Appender;
4412 import org.apache.log4j.Logger;
4413 import org.lttng.ust.agent.log4j.LttngLogAppender;
4417 private static final int answer = 42;
4419 public static void main(String[] argv) throws Exception
4422 Logger logger = Logger.getLogger("jello");
4424 // Create an LTTng-UST log appender
4425 Appender lttngUstLogAppender = new LttngLogAppender();
4427 // Add the LTTng-UST log appender to our logger
4428 logger.addAppender(lttngUstLogAppender);
4431 logger.info("some info");
4432 logger.warn("some warning");
4434 logger.debug("debug information; the answer is " + answer);
4436 logger.fatal("error!");
4438 // Not mandatory, but cleaner
4439 logger.removeAppender(lttngUstLogAppender);
4440 lttngUstLogAppender.close();
4446 Build this example (`$LOG4JPATH` is the path to the Apache log4j JAR
4451 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH Test.java
4454 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4455 <<enabling-disabling-events,create an event rule>> matching the
4456 `jello` log4j logger, and <<basic-tracing-session-control,start tracing>>:
4461 $ lttng enable-event --log4j jello
4465 Run the compiled class:
4469 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH:. Test
4472 <<basic-tracing-session-control,Stop tracing>> and inspect the
4482 In the resulting trace, an <<event,event record>> generated by a Java
4483 application using log4j is named `lttng_log4j:event` and
4484 has the following fields:
4487 Log record's message.
4493 Name of the class in which the log statement was executed.
4496 Name of the method in which the log statement was executed.
4499 Name of the file in which the executed log statement is located.
4502 Line number at which the log statement was executed.
4508 Log level integer value.
4511 Name of the Java thread in which the log statement was executed.
4513 Use the opt:lttng-enable-event(1):--loglevel or
4514 opt:lttng-enable-event(1):--loglevel-only option of the
4515 man:lttng-enable-event(1) command to target a range of Apache log4j
4516 log levels or a specific log4j log level.
4520 [[java-application-context]]
4521 ==== Provide application-specific context fields in a Java application
4523 A Java application-specific context field is a piece of state provided
4524 by the application which <<adding-context,you can add>>, using the
4525 man:lttng-add-context(1) command, to each <<event,event record>>
4526 produced by the log statements of this application.
4528 For example, a given object might have a current request ID variable.
4529 You can create a context information retriever for this object and
4530 assign a name to this current request ID. You can then, using the
4531 man:lttng-add-context(1) command, add this context field by name to
4532 the JUL or log4j <<channel,channel>>.
4534 To provide application-specific context fields in a Java application:
4536 . In the Java application's source code, import the LTTng-UST
4537 Java agent context classes and interfaces:
4542 import org.lttng.ust.agent.context.ContextInfoManager;
4543 import org.lttng.ust.agent.context.IContextInfoRetriever;
4547 . Create a context information retriever class, that is, a class which
4548 implements the `IContextInfoRetriever` interface:
4553 class MyContextInfoRetriever implements IContextInfoRetriever
4556 public Object retrieveContextInfo(String key)
4558 if (key.equals("intCtx")) {
4560 } else if (key.equals("strContext")) {
4561 return "context value!";
4570 This `retrieveContextInfo()` method is the only member of the
4571 `IContextInfoRetriever` interface. Its role is to return the current
4572 value of a state by name to create a context field. The names of the
4573 context fields and which state variables they return depends on your
4576 All primitive types and objects are supported as context fields.
4577 When `retrieveContextInfo()` returns an object, the context field
4578 serializer calls its `toString()` method to add a string field to
4579 event records. The method can also return `null`, which means that
4580 no context field is available for the required name.
4582 . Register an instance of your context information retriever class to
4583 the context information manager singleton:
4588 IContextInfoRetriever cir = new MyContextInfoRetriever();
4589 ContextInfoManager cim = ContextInfoManager.getInstance();
4590 cim.registerContextInfoRetriever("retrieverName", cir);
4594 . Before exiting the application, remove your context information
4595 retriever from the context information manager singleton:
4600 ContextInfoManager cim = ContextInfoManager.getInstance();
4601 cim.unregisterContextInfoRetriever("retrieverName");
4605 This isn't strictly necessary, but it is recommended for a clean
4606 disposal of some manager's resources.
4608 . Build your Java application with LTTng-UST Java agent support as
4609 usual, following the procedure for either the <<jul,JUL>> or
4610 <<log4j,Apache log4j>> framework.
4613 .Provide application-specific context fields in a Java application.
4618 import java.util.logging.Handler;
4619 import java.util.logging.Logger;
4620 import org.lttng.ust.agent.jul.LttngLogHandler;
4621 import org.lttng.ust.agent.context.ContextInfoManager;
4622 import org.lttng.ust.agent.context.IContextInfoRetriever;
4626 // Our context information retriever class
4627 private static class MyContextInfoRetriever
4628 implements IContextInfoRetriever
4631 public Object retrieveContextInfo(String key) {
4632 if (key.equals("intCtx")) {
4634 } else if (key.equals("strContext")) {
4635 return "context value!";
4642 private static final int answer = 42;
4644 public static void main(String args[]) throws Exception
4646 // Get the context information manager instance
4647 ContextInfoManager cim = ContextInfoManager.getInstance();
4649 // Create and register our context information retriever
4650 IContextInfoRetriever cir = new MyContextInfoRetriever();
4651 cim.registerContextInfoRetriever("myRetriever", cir);
4654 Logger logger = Logger.getLogger("jello");
4656 // Create an LTTng-UST log handler
4657 Handler lttngUstLogHandler = new LttngLogHandler();
4659 // Add the LTTng-UST log handler to our logger
4660 logger.addHandler(lttngUstLogHandler);
4663 logger.info("some info");
4664 logger.warning("some warning");
4666 logger.finer("finer information; the answer is " + answer);
4668 logger.severe("error!");
4670 // Not mandatory, but cleaner
4671 logger.removeHandler(lttngUstLogHandler);
4672 lttngUstLogHandler.close();
4673 cim.unregisterContextInfoRetriever("myRetriever");
4682 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4685 <<creating-destroying-tracing-sessions,Create a tracing session>>
4686 and <<enabling-disabling-events,create an event rule>> matching the
4692 $ lttng enable-event --jul jello
4695 <<adding-context,Add the application-specific context fields>> to the
4700 $ lttng add-context --jul --type='$app.myRetriever:intCtx'
4701 $ lttng add-context --jul --type='$app.myRetriever:strContext'
4704 <<basic-tracing-session-control,Start tracing>>:
4711 Run the compiled class:
4715 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4718 <<basic-tracing-session-control,Stop tracing>> and inspect the
4730 [[python-application]]
4731 === User space Python agent
4733 You can instrument a Python{nbsp}2 or Python{nbsp}3 application which
4735 https://docs.python.org/3/library/logging.html[`logging`] package.
4737 Each log statement emits an LTTng event once the
4738 application module imports the
4739 <<lttng-ust-agents,LTTng-UST Python agent>> package.
4742 .A Python application importing the LTTng-UST Python agent.
4743 image::python-app.png[]
4745 To use the LTTng-UST Python agent:
4747 . In the Python application's source code, import the LTTng-UST Python
4757 The LTTng-UST Python agent automatically adds its logging handler to the
4758 root logger at import time.
4760 Any log statement that the application executes before this import does
4761 not emit an LTTng event.
4763 IMPORTANT: The LTTng-UST Python agent must be
4764 <<installing-lttng,installed>>.
4766 . Use log statements and logging configuration as usual.
4767 Since the LTTng-UST Python agent adds a handler to the _root_
4768 logger, you can trace any log statement from any logger.
4770 .Use the LTTng-UST Python agent.
4781 logging.basicConfig()
4782 logger = logging.getLogger('my-logger')
4785 logger.debug('debug message')
4786 logger.info('info message')
4787 logger.warn('warn message')
4788 logger.error('error message')
4789 logger.critical('critical message')
4793 if __name__ == '__main__':
4797 NOTE: `logging.basicConfig()`, which adds to the root logger a basic
4798 logging handler which prints to the standard error stream, isn't
4799 strictly required for LTTng-UST tracing to work, but in versions of
4800 Python preceding{nbsp}3.2, you could see a warning message which indicates
4801 that no handler exists for the logger `my-logger`.
4803 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4804 <<enabling-disabling-events,create an event rule>> matching the
4805 `my-logger` Python logger, and <<basic-tracing-session-control,start
4811 $ lttng enable-event --python my-logger
4815 Run the Python script:
4822 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
4832 In the resulting trace, an <<event,event record>> generated by a Python
4833 application is named `lttng_python:event` and has the following fields:
4836 Logging time (string).
4839 Log record's message.
4845 Name of the function in which the log statement was executed.
4848 Line number at which the log statement was executed.
4851 Log level integer value.
4854 ID of the Python thread in which the log statement was executed.
4857 Name of the Python thread in which the log statement was executed.
4859 Use the opt:lttng-enable-event(1):--loglevel or
4860 opt:lttng-enable-event(1):--loglevel-only option of the
4861 man:lttng-enable-event(1) command to target a range of Python log levels
4862 or a specific Python log level.
4864 When an application imports the LTTng-UST Python agent, the agent tries
4865 to register to a <<lttng-sessiond,session daemon>>. Note that you must
4866 <<start-sessiond,start the session daemon>> _before_ you run the Python
4867 application. If a session daemon is found, the agent tries to register
4868 to it during five seconds, after which the application continues
4869 without LTTng tracing support. Override this timeout value with
4870 the env:LTTNG_UST_PYTHON_REGISTER_TIMEOUT environment variable
4873 If the session daemon stops while a Python application with an imported
4874 LTTng-UST Python agent runs, the agent retries to connect and to
4875 register to a session daemon every three seconds. Override this
4876 delay with the env:LTTNG_UST_PYTHON_REGISTER_RETRY_DELAY environment
4881 [[proc-lttng-logger-abi]]
4884 The `lttng-tracer` Linux kernel module, part of
4885 <<lttng-modules,LTTng-modules>>, creates the special LTTng logger files
4886 path:{/proc/lttng-logger} and path:{/dev/lttng-logger} (since
4887 LTTng{nbsp}2.11) when it's loaded. Any application can write text data
4888 to any of those files to emit an LTTng event.
4891 .An application writes to the LTTng logger file to emit an LTTng event.
4892 image::lttng-logger.png[]
4894 The LTTng logger is the quickest method--not the most efficient,
4895 however--to add instrumentation to an application. It is designed
4896 mostly to instrument shell scripts:
4900 $ echo "Some message, some $variable" > /dev/lttng-logger
4903 Any event that the LTTng logger emits is named `lttng_logger` and
4904 belongs to the Linux kernel <<domain,tracing domain>>. However, unlike
4905 other instrumentation points in the kernel tracing domain, **any Unix
4906 user** can <<enabling-disabling-events,create an event rule>> which
4907 matches its event name, not only the root user or users in the
4908 <<tracing-group,tracing group>>.
4910 To use the LTTng logger:
4912 * From any application, write text data to the path:{/dev/lttng-logger}
4915 The `msg` field of `lttng_logger` event records contains the
4918 NOTE: The maximum message length of an LTTng logger event is
4919 1024{nbsp}bytes. Writing more than this makes the LTTng logger emit more
4920 than one event to contain the remaining data.
4922 You shouldn't use the LTTng logger to trace a user application which
4923 can be instrumented in a more efficient way, namely:
4925 * <<c-application,C and $$C++$$ applications>>.
4926 * <<java-application,Java applications>>.
4927 * <<python-application,Python applications>>.
4929 .Use the LTTng logger.
4934 echo 'Hello, World!' > /dev/lttng-logger
4936 df --human-readable --print-type / > /dev/lttng-logger
4939 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4940 <<enabling-disabling-events,create an event rule>> matching the
4941 `lttng_logger` Linux kernel tracepoint, and
4942 <<basic-tracing-session-control,start tracing>>:
4947 $ lttng enable-event --kernel lttng_logger
4951 Run the Bash script:
4958 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
4969 [[instrumenting-linux-kernel]]
4970 === LTTng kernel tracepoints
4972 NOTE: This section shows how to _add_ instrumentation points to the
4973 Linux kernel. The kernel's subsystems are already thoroughly
4974 instrumented at strategic places for LTTng when you
4975 <<installing-lttng,install>> the <<lttng-modules,LTTng-modules>>
4979 There are two methods to instrument the Linux kernel:
4981 . <<linux-add-lttng-layer,Add an LTTng layer>> over an existing ftrace
4982 tracepoint which uses the `TRACE_EVENT()` API.
4984 Choose this if you want to instrumentation a Linux kernel tree with an
4985 instrumentation point compatible with ftrace, perf, and SystemTap.
4987 . Use an <<linux-lttng-tracepoint-event,LTTng-only approach>> to
4988 instrument an out-of-tree kernel module.
4990 Choose this if you don't need ftrace, perf, or SystemTap support.
4994 [[linux-add-lttng-layer]]
4995 ==== [[instrumenting-linux-kernel-itself]][[mainline-trace-event]][[lttng-adaptation-layer]]Add an LTTng layer to an existing ftrace tracepoint
4997 This section shows how to add an LTTng layer to existing ftrace
4998 instrumentation using the `TRACE_EVENT()` API.
5000 This section doesn't document the `TRACE_EVENT()` macro. Read the
5001 following articles to learn more about this API:
5003 * http://lwn.net/Articles/379903/[Using the TRACE_EVENT() macro (Part{nbsp}1)]
5004 * http://lwn.net/Articles/381064/[Using the TRACE_EVENT() macro (Part{nbsp}2)]
5005 * http://lwn.net/Articles/383362/[Using the TRACE_EVENT() macro (Part{nbsp}3)]
5007 The following procedure assumes that your ftrace tracepoints are
5008 correctly defined in their own header and that they are created in
5009 one source file using the `CREATE_TRACE_POINTS` definition.
5011 To add an LTTng layer over an existing ftrace tracepoint:
5013 . Make sure the following kernel configuration options are
5019 * `CONFIG_HIGH_RES_TIMERS`
5020 * `CONFIG_TRACEPOINTS`
5023 . Build the Linux source tree with your custom ftrace tracepoints.
5024 . Boot the resulting Linux image on your target system.
5026 Confirm that the tracepoints exist by looking for their names in the
5027 dir:{/sys/kernel/debug/tracing/events/subsys} directory, where `subsys`
5028 is your subsystem's name.
5030 . Get a copy of the latest LTTng-modules{nbsp}{revision}:
5035 $ cd $(mktemp -d) &&
5036 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.12.tar.bz2 &&
5037 tar -xf lttng-modules-latest-2.12.tar.bz2 &&
5038 cd lttng-modules-2.12.*
5042 . In dir:{instrumentation/events/lttng-module}, relative to the root
5043 of the LTTng-modules source tree, create a header file named
5044 +__subsys__.h+ for your custom subsystem +__subsys__+ and write your
5045 LTTng-modules tracepoint definitions using the LTTng-modules
5048 Start with this template:
5052 .path:{instrumentation/events/lttng-module/my_subsys.h}
5055 #define TRACE_SYSTEM my_subsys
5057 #if !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ)
5058 #define _LTTNG_MY_SUBSYS_H
5060 #include "../../../probes/lttng-tracepoint-event.h"
5061 #include <linux/tracepoint.h>
5063 LTTNG_TRACEPOINT_EVENT(
5065 * Format is identical to TRACE_EVENT()'s version for the three
5066 * following macro parameters:
5069 TP_PROTO(int my_int, const char *my_string),
5070 TP_ARGS(my_int, my_string),
5072 /* LTTng-modules specific macros */
5074 ctf_integer(int, my_int_field, my_int)
5075 ctf_string(my_bar_field, my_bar)
5079 #endif /* !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ) */
5081 #include "../../../probes/define_trace.h"
5085 The entries in the `TP_FIELDS()` section are the list of fields for the
5086 LTTng tracepoint. This is similar to the `TP_STRUCT__entry()` part of
5087 ftrace's `TRACE_EVENT()` macro.
5089 See <<lttng-modules-tp-fields,Tracepoint fields macros>> for a
5090 complete description of the available `ctf_*()` macros.
5092 . Create the LTTng-modules probe's kernel module C source file,
5093 +probes/lttng-probe-__subsys__.c+, where +__subsys__+ is your
5098 .path:{probes/lttng-probe-my-subsys.c}
5100 #include <linux/module.h>
5101 #include "../lttng-tracer.h"
5104 * Build-time verification of mismatch between mainline
5105 * TRACE_EVENT() arguments and the LTTng-modules adaptation
5106 * layer LTTNG_TRACEPOINT_EVENT() arguments.
5108 #include <trace/events/my_subsys.h>
5110 /* Create LTTng tracepoint probes */
5111 #define LTTNG_PACKAGE_BUILD
5112 #define CREATE_TRACE_POINTS
5113 #define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
5115 #include "../instrumentation/events/lttng-module/my_subsys.h"
5117 MODULE_LICENSE("GPL and additional rights");
5118 MODULE_AUTHOR("Your name <your-email>");
5119 MODULE_DESCRIPTION("LTTng my_subsys probes");
5120 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
5121 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
5122 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
5123 LTTNG_MODULES_EXTRAVERSION);
5127 . Edit path:{probes/KBuild} and add your new kernel module object
5128 next to the existing ones:
5132 .path:{probes/KBuild}
5136 obj-m += lttng-probe-module.o
5137 obj-m += lttng-probe-power.o
5139 obj-m += lttng-probe-my-subsys.o
5145 . Build and install the LTTng kernel modules:
5150 $ make KERNELDIR=/path/to/linux
5151 # make modules_install && depmod -a
5155 Replace `/path/to/linux` with the path to the Linux source tree where
5156 you defined and used tracepoints with ftrace's `TRACE_EVENT()` macro.
5158 Note that you can also use the
5159 <<lttng-tracepoint-event-code,`LTTNG_TRACEPOINT_EVENT_CODE()` macro>>
5160 instead of `LTTNG_TRACEPOINT_EVENT()` to use custom local variables and
5161 C code that need to be executed before the event fields are recorded.
5163 The best way to learn how to use the previous LTTng-modules macros is to
5164 inspect the existing LTTng-modules tracepoint definitions in the
5165 dir:{instrumentation/events/lttng-module} header files. Compare them
5166 with the Linux kernel mainline versions in the
5167 dir:{include/trace/events} directory of the Linux source tree.
5171 [[lttng-tracepoint-event-code]]
5172 ===== Use custom C code to access the data for tracepoint fields
5174 Although we recommended to always use the
5175 <<lttng-adaptation-layer,`LTTNG_TRACEPOINT_EVENT()`>> macro to describe
5176 the arguments and fields of an LTTng-modules tracepoint when possible,
5177 sometimes you need a more complex process to access the data that the
5178 tracer records as event record fields. In other words, you need local
5179 variables and multiple C{nbsp}statements instead of simple
5180 argument-based expressions that you pass to the
5181 <<lttng-modules-tp-fields,`ctf_*()` macros of `TP_FIELDS()`>>.
5183 Use the `LTTNG_TRACEPOINT_EVENT_CODE()` macro instead of
5184 `LTTNG_TRACEPOINT_EVENT()` to declare custom local variables and define
5185 a block of C{nbsp}code to be executed before LTTng records the fields.
5186 The structure of this macro is:
5189 .`LTTNG_TRACEPOINT_EVENT_CODE()` macro syntax.
5191 LTTNG_TRACEPOINT_EVENT_CODE(
5193 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5194 * version for the following three macro parameters:
5197 TP_PROTO(int my_int, const char *my_string),
5198 TP_ARGS(my_int, my_string),
5200 /* Declarations of custom local variables */
5203 unsigned long b = 0;
5204 const char *name = "(undefined)";
5205 struct my_struct *my_struct;
5209 * Custom code which uses both tracepoint arguments
5210 * (in TP_ARGS()) and local variables (in TP_locvar()).
5212 * Local variables are actually members of a structure pointed
5213 * to by the special variable tp_locvar.
5217 tp_locvar->a = my_int + 17;
5218 tp_locvar->my_struct = get_my_struct_at(tp_locvar->a);
5219 tp_locvar->b = my_struct_compute_b(tp_locvar->my_struct);
5220 tp_locvar->name = my_struct_get_name(tp_locvar->my_struct);
5221 put_my_struct(tp_locvar->my_struct);
5230 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5231 * version for this, except that tp_locvar members can be
5232 * used in the argument expression parameters of
5233 * the ctf_*() macros.
5236 ctf_integer(unsigned long, my_struct_b, tp_locvar->b)
5237 ctf_integer(int, my_struct_a, tp_locvar->a)
5238 ctf_string(my_string_field, my_string)
5239 ctf_string(my_struct_name, tp_locvar->name)
5244 IMPORTANT: The C code defined in `TP_code()` must not have any side
5245 effects when executed. In particular, the code must not allocate
5246 memory or get resources without deallocating this memory or putting
5247 those resources afterwards.
5250 [[instrumenting-linux-kernel-tracing]]
5251 ==== Load and unload a custom probe kernel module
5253 You must load a <<lttng-adaptation-layer,created LTTng-modules probe
5254 kernel module>> in the kernel before it can emit LTTng events.
5256 To load the default probe kernel modules and a custom probe kernel
5259 * Use the opt:lttng-sessiond(8):--extra-kmod-probes option to give extra
5260 probe modules to load when starting a root <<lttng-sessiond,session
5264 .Load the `my_subsys`, `usb`, and the default probe modules.
5268 # lttng-sessiond --extra-kmod-probes=my_subsys,usb
5273 You only need to pass the subsystem name, not the whole kernel module
5276 To load _only_ a given custom probe kernel module:
5278 * Use the opt:lttng-sessiond(8):--kmod-probes option to give the probe
5279 modules to load when starting a root session daemon:
5282 .Load only the `my_subsys` and `usb` probe modules.
5286 # lttng-sessiond --kmod-probes=my_subsys,usb
5291 To confirm that a probe module is loaded:
5298 $ lsmod | grep lttng_probe_usb
5302 To unload the loaded probe modules:
5304 * Kill the session daemon with `SIGTERM`:
5309 # pkill lttng-sessiond
5313 You can also use man:modprobe(8)'s `--remove` option if the session
5314 daemon terminates abnormally.
5317 [[controlling-tracing]]
5320 Once an application or a Linux kernel is
5321 <<instrumenting,instrumented>> for LTTng tracing,
5324 This section is divided in topics on how to use the various
5325 <<plumbing,components of LTTng>>, in particular the <<lttng-cli,cmd:lttng
5326 command-line tool>>, to _control_ the LTTng daemons and tracers.
5328 NOTE: In the following subsections, we refer to an man:lttng(1) command
5329 using its man page name. For example, instead of _Run the `create`
5330 command to..._, we use _Run the man:lttng-create(1) command to..._.
5334 === Start a session daemon
5336 In some situations, you need to run a <<lttng-sessiond,session daemon>>
5337 (man:lttng-sessiond(8)) _before_ you can use the man:lttng(1)
5340 You will see the following error when you run a command while no session
5344 Error: No session daemon is available
5347 The only command that automatically runs a session daemon is
5348 man:lttng-create(1), which you use to
5349 <<creating-destroying-tracing-sessions,create a tracing session>>. While
5350 this is most of the time the first operation that you do, sometimes it's
5351 not. Some examples are:
5353 * <<list-instrumentation-points,List the available instrumentation points>>.
5354 * <<saving-loading-tracing-session,Load a tracing session configuration>>.
5356 [[tracing-group]] Each Unix user must have its own running session
5357 daemon to trace user applications. The session daemon that the root user
5358 starts is the only one allowed to control the LTTng kernel tracer. Users
5359 that are part of the _tracing group_ can control the root session
5360 daemon. The default tracing group name is `tracing`; set it to something
5361 else with the opt:lttng-sessiond(8):--group option when you start the
5362 root session daemon.
5364 To start a user session daemon:
5366 * Run man:lttng-sessiond(8):
5371 $ lttng-sessiond --daemonize
5375 To start the root session daemon:
5377 * Run man:lttng-sessiond(8) as the root user:
5382 # lttng-sessiond --daemonize
5386 In both cases, remove the opt:lttng-sessiond(8):--daemonize option to
5387 start the session daemon in foreground.
5389 To stop a session daemon, use man:kill(1) on its process ID (standard
5392 Note that some Linux distributions could manage the LTTng session daemon
5393 as a service. In this case, you should use the service manager to
5394 start, restart, and stop session daemons.
5397 [[creating-destroying-tracing-sessions]]
5398 === Create and destroy a tracing session
5400 Almost all the LTTng control operations happen in the scope of
5401 a <<tracing-session,tracing session>>, which is the dialogue between the
5402 <<lttng-sessiond,session daemon>> and you.
5404 To create a tracing session with a generated name:
5406 * Use the man:lttng-create(1) command:
5415 The created tracing session's name is `auto` followed by the
5418 To create a tracing session with a specific name:
5420 * Use the optional argument of the man:lttng-create(1) command:
5425 $ lttng create my-session
5429 Replace `my-session` with the specific tracing session name.
5431 LTTng appends the creation date to the created tracing session's name.
5433 LTTng writes the traces of a tracing session in
5434 +$LTTNG_HOME/lttng-trace/__name__+ by default, where +__name__+ is the
5435 name of the tracing session. Note that the env:LTTNG_HOME environment
5436 variable defaults to `$HOME` if not set.
5438 To output LTTng traces to a non-default location:
5440 * Use the opt:lttng-create(1):--output option of the man:lttng-create(1) command:
5445 $ lttng create my-session --output=/tmp/some-directory
5449 You may create as many tracing sessions as you wish.
5451 To list all the existing tracing sessions for your Unix user:
5453 * Use the man:lttng-list(1) command:
5462 [[cur-tracing-session]]When you create a tracing session, it is set as
5463 the _current tracing session_. The following man:lttng(1) commands
5464 operate on the current tracing session when you don't specify one:
5466 [role="list-3-cols"]
5467 * man:lttng-add-context(1)
5468 * man:lttng-clear(1)
5469 * man:lttng-destroy(1)
5470 * man:lttng-disable-channel(1)
5471 * man:lttng-disable-event(1)
5472 * man:lttng-disable-rotation(1)
5473 * man:lttng-enable-channel(1)
5474 * man:lttng-enable-event(1)
5475 * man:lttng-enable-rotation(1)
5477 * man:lttng-regenerate(1)
5478 * man:lttng-rotate(1)
5480 * man:lttng-snapshot(1)
5481 * man:lttng-start(1)
5482 * man:lttng-status(1)
5484 * man:lttng-track(1)
5485 * man:lttng-untrack(1)
5488 To change the current tracing session:
5490 * Use the man:lttng-set-session(1) command:
5495 $ lttng set-session new-session
5499 Replace `new-session` by the name of the new current tracing session.
5501 When you're done tracing in a given tracing session, destroy it. This
5502 operation frees the resources taken by the tracing session to destroy;
5503 it doesn't destroy the trace data that LTTng wrote for this tracing
5504 session (see <<clear,Clear a tracing session>> for one way to do this).
5506 To destroy the current tracing session:
5508 * Use the man:lttng-destroy(1) command:
5517 The man:lttng-destroy(1) command also runs the man:lttng-stop(1)
5518 command implicitly (see <<basic-tracing-session-control,Start and stop a
5519 tracing session>>). You need to stop tracing to make LTTng flush the
5520 remaining trace data and make the trace readable.
5523 [[list-instrumentation-points]]
5524 === List the available instrumentation points
5526 The <<lttng-sessiond,session daemon>> can query the running instrumented
5527 user applications and the Linux kernel to get a list of available
5528 instrumentation points. For the Linux kernel <<domain,tracing domain>>,
5529 they are tracepoints and system calls. For the user space tracing
5530 domain, they are tracepoints. For the other tracing domains, they are
5533 To list the available instrumentation points:
5535 * Use the man:lttng-list(1) command with the requested tracing domain's
5539 opt:lttng-list(1):--kernel::
5540 Linux kernel tracepoints (your Unix user must be a root user, or it
5541 must be a member of the <<tracing-group,tracing group>>).
5543 opt:lttng-list(1):--kernel with opt:lttng-list(1):--syscall::
5544 Linux kernel system calls (your Unix user must be a root user, or it
5545 must be a member of the tracing group).
5547 opt:lttng-list(1):--userspace::
5548 User space tracepoints.
5550 opt:lttng-list(1):--jul::
5551 `java.util.logging` loggers.
5553 opt:lttng-list(1):--log4j::
5554 Apache log4j loggers.
5556 opt:lttng-list(1):--python::
5560 .List the available user space tracepoints.
5564 $ lttng list --userspace
5568 .List the available Linux kernel system call tracepoints.
5572 $ lttng list --kernel --syscall
5577 [[enabling-disabling-events]]
5578 === Create and enable an event rule
5580 Once you <<creating-destroying-tracing-sessions,create a tracing
5581 session>>, you can create <<event,event rules>> with the
5582 man:lttng-enable-event(1) command.
5584 You specify each condition with a command-line option. The available
5585 condition arguments are shown in the following table.
5587 [role="growable",cols="asciidoc,asciidoc,default"]
5588 .Condition command-line arguments for the man:lttng-enable-event(1) command.
5590 |Argument |Description |Applicable tracing domains
5596 . +--probe=__ADDR__+
5597 . +--function=__ADDR__+
5598 . +--userspace-probe=__PATH__:__SYMBOL__+
5599 . +--userspace-probe=sdt:__PATH__:__PROVIDER__:__NAME__+
5602 Instead of using the default _tracepoint_ instrumentation type, use:
5604 . A Linux system call (entry and exit).
5605 . A Linux https://lwn.net/Articles/132196/[kprobe] (symbol or address).
5606 . The entry and return points of a Linux function (symbol or address).
5607 . The entry point of a user application or library function (path to
5608 application/library and symbol).
5609 . A https://www.sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps[SystemTap
5610 Statically Defined Tracing] (USDT) probe (path to application/library,
5611 provider and probe names).
5615 |First positional argument.
5618 Tracepoint or system call name.
5620 With the opt:lttng-enable-event(1):--probe,
5621 opt:lttng-enable-event(1):--function, and
5622 opt:lttng-enable-event(1):--userspace-probe options, this is a custom
5623 name given to the event rule. With the JUL, log4j, and Python domains,
5624 this is a logger name.
5626 With a tracepoint, logger, or system call name, use the special
5627 `*` globbing character to match anything (for example, `sched_*`,
5635 . +--loglevel=__LEVEL__+
5636 . +--loglevel-only=__LEVEL__+
5639 . Match only tracepoints or log statements with a logging level at
5640 least as severe as +__LEVEL__+.
5641 . Match only tracepoints or log statements with a logging level
5642 equal to +__LEVEL__+.
5644 See man:lttng-enable-event(1) for the list of available logging level
5647 |User space, JUL, log4j, and Python.
5649 |+--exclude=__EXCLUSIONS__+
5652 When you use a `*` character at the end of the tracepoint or logger
5653 name (first positional argument), exclude the specific names in the
5654 comma-delimited list +__EXCLUSIONS__+.
5657 User space, JUL, log4j, and Python.
5659 |+--filter=__EXPR__+
5662 Match only events which satisfy the expression +__EXPR__+.
5664 See man:lttng-enable-event(1) to learn more about the syntax of a
5671 You attach an event rule to a <<channel,channel>> on creation. If you do
5672 not specify the channel with the opt:lttng-enable-event(1):--channel
5673 option, and if the event rule to create is the first in its
5674 <<domain,tracing domain>> for a given tracing session, then LTTng
5675 creates a _default channel_ for you. This default channel is reused in
5676 subsequent invocations of the man:lttng-enable-event(1) command for the
5677 same tracing domain.
5679 An event rule is always enabled at creation time.
5681 The following examples show how to combine the previous
5682 command-line options to create simple to more complex event rules.
5684 .Create an event rule targetting a Linux kernel tracepoint (default channel).
5688 $ lttng enable-event --kernel sched_switch
5692 .Create an event rule matching four Linux kernel system calls (default channel).
5696 $ lttng enable-event --kernel --syscall open,write,read,close
5700 .Create event rules matching tracepoints with filter expressions (default channel).
5704 $ lttng enable-event --kernel sched_switch --filter='prev_comm == "bash"'
5709 $ lttng enable-event --kernel --all \
5710 --filter='$ctx.tid == 1988 || $ctx.tid == 1534'
5715 $ lttng enable-event --jul my_logger \
5716 --filter='$app.retriever:cur_msg_id > 3'
5719 IMPORTANT: Make sure to always quote the filter string when you
5720 use man:lttng(1) from a shell.
5722 See also <<pid-tracking,Track process attributes>> which offers another,
5723 more efficient filtering mechanism for process ID, user ID, and group
5727 .Create an event rule matching any user space tracepoint of a given tracepoint provider with a log level range (default channel).
5731 $ lttng enable-event --userspace my_app:'*' --loglevel=TRACE_INFO
5734 IMPORTANT: Make sure to always quote the wildcard character when you
5735 use man:lttng(1) from a shell.
5738 .Create an event rule matching multiple Python loggers with a wildcard and with exclusions (default channel).
5742 $ lttng enable-event --python my-app.'*' \
5743 --exclude='my-app.module,my-app.hello'
5747 .Create an event rule matching any Apache log4j logger with a specific log level (default channel).
5751 $ lttng enable-event --log4j --all --loglevel-only=LOG4J_WARN
5755 .Create an event rule attached to a specific channel matching a specific user space tracepoint provider and tracepoint.
5759 $ lttng enable-event --userspace my_app:my_tracepoint --channel=my-channel
5763 .Create an event rule matching the `malloc` function entry in path:{/usr/lib/libc.so.6}:
5767 $ lttng enable-event --kernel --userspace-probe=/usr/lib/libc.so.6:malloc \
5772 .Create an event rule matching the `server`/`accept_request` https://www.sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps[USDT probe] in path:{/usr/bin/serv}:
5776 $ lttng enable-event --kernel --userspace-probe=sdt:serv:server:accept_request \
5777 server_accept_request
5781 The event rules of a given channel form a whitelist: as soon as an
5782 emitted event passes one of them, LTTng can record the event. For
5783 example, an event named `my_app:my_tracepoint` emitted from a user space
5784 tracepoint with a `TRACE_ERROR` log level passes both of the following
5789 $ lttng enable-event --userspace my_app:my_tracepoint
5790 $ lttng enable-event --userspace my_app:my_tracepoint \
5791 --loglevel=TRACE_INFO
5794 The second event rule is redundant: the first one includes
5798 [[disable-event-rule]]
5799 === Disable an event rule
5801 To disable an event rule that you <<enabling-disabling-events,created>>
5802 previously, use the man:lttng-disable-event(1) command. This command
5803 disables _all_ the event rules (of a given tracing domain and channel)
5804 which match an instrumentation point. The other conditions aren't
5805 supported as of LTTng{nbsp}{revision}.
5807 The LTTng tracer doesn't record an emitted event which passes
5808 a _disabled_ event rule.
5810 .Disable an event rule matching a Python logger (default channel).
5814 $ lttng disable-event --python my-logger
5818 .Disable an event rule matching all `java.util.logging` loggers (default channel).
5822 $ lttng disable-event --jul '*'
5826 .Disable _all_ the event rules of the default channel.
5828 The opt:lttng-disable-event(1):--all-events option isn't, like the
5829 opt:lttng-enable-event(1):--all option of man:lttng-enable-event(1), the
5830 equivalent of the event name `*` (wildcard): it disables _all_ the event
5831 rules of a given channel.
5835 $ lttng disable-event --jul --all-events
5839 NOTE: You can't delete an event rule once you create it.
5843 === Get the status of a tracing session
5845 To get the status of the <<cur-tracing-session,current tracing
5846 session>>, that is, its parameters, its channels, event rules, and their
5849 * Use the man:lttng-status(1) command:
5858 To get the status of any tracing session:
5860 * Use the man:lttng-list(1) command with the tracing session's name:
5865 $ lttng list my-session
5869 Replace `my-session` with the desired tracing session's name.
5872 [[basic-tracing-session-control]]
5873 === Start and stop a tracing session
5875 Once you <<creating-destroying-tracing-sessions,create a tracing
5877 <<enabling-disabling-events,create one or more event rules>>,
5878 you can start and stop the tracers for this tracing session.
5880 To start tracing in the <<cur-tracing-session,current tracing session>>:
5882 * Use the man:lttng-start(1) command:
5891 LTTng is very flexible: you can launch user applications before
5892 or after the you start the tracers. The tracers only record the events
5893 if they pass enabled event rules and if they occur while the tracers are
5896 To stop tracing in the current tracing session:
5898 * Use the man:lttng-stop(1) command:
5907 If there were <<channel-overwrite-mode-vs-discard-mode,lost event
5908 records>> or lost sub-buffers since the last time you ran
5909 man:lttng-start(1), warnings are printed when you run the
5910 man:lttng-stop(1) command.
5912 IMPORTANT: You need to stop tracing to make LTTng flush the remaining
5913 trace data and make the trace readable. Note that the
5914 man:lttng-destroy(1) command (see
5915 <<creating-destroying-tracing-sessions,Create and destroy a tracing
5916 session>>) also runs the man:lttng-stop(1) command implicitly.
5920 === Clear a tracing session
5922 You might need to remove all the current tracing data of one or more
5923 <<tracing-session,tracing sessions>> between multiple attempts to
5924 reproduce a problem without interrupting the LTTng tracing activity.
5926 To clear the tracing data of the
5927 <<cur-tracing-session,current tracing session>>:
5929 * Use the man:lttng-clear(1) command:
5938 To clear the tracing data of all the tracing sessions:
5940 * Use the `lttng clear` command with the opt:lttng-clear(1):--all
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 can't, 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 to 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 <<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.
6177 Examples of context fields are:
6179 * The **process ID**, **thread ID**, **process name**, and
6180 **process priority** of the thread in which the event occurs.
6181 * The **hostname** of the system on which the event occurs.
6182 * The Linux kernel and user call stacks (since
6184 * The current values of many possible **performance counters** using
6186 ** CPU cycles, stalled cycles, idle cycles, and the other cycle types.
6188 ** Branch instructions, misses, and loads.
6190 * Any context defined at the application level (supported for the
6191 JUL and log4j <<domain,tracing domains>>).
6193 To get the full list of available context fields, see
6194 `lttng add-context --list`. Some context fields are reserved for a
6195 specific <<domain,tracing domain>> (Linux kernel or user space).
6197 You add context fields to <<channel,channels>>. All the events
6198 that a channel with added context fields records contain those fields.
6200 To add context fields to one or all the channels of a given tracing
6203 * Use the man:lttng-add-context(1) command.
6205 .Add context fields to all the channels of the current tracing session.
6207 The following command line adds the virtual process identifier and
6208 the per-thread CPU cycles count fields to all the user space channels
6210 <<cur-tracing-session,current tracing session>>.
6214 $ lttng add-context --userspace --type=vpid --type=perf:thread:cpu-cycles
6218 .Add performance counter context fields by raw ID
6220 See man:lttng-add-context(1) for the exact format of the context field
6221 type, which is partly compatible with the format used in
6226 $ lttng add-context --userspace --type=perf:thread:raw:r0110:test
6227 $ lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted
6231 .Add context fields to a specific channel.
6233 The following command line adds the thread identifier and user call
6234 stack context fields to the Linux kernel channel named `my-channel` in
6235 the current tracing session.
6239 $ lttng add-context --kernel --channel=my-channel \
6240 --type=tid --type=callstack-user
6244 .Add an application-specific context field to a specific channel.
6246 The following command line adds the `cur_msg_id` context field of the
6247 `retriever` context retriever for all the instrumented
6248 <<java-application,Java applications>> recording <<event,event records>>
6249 in the channel named `my-channel`:
6253 $ lttng add-context --kernel --channel=my-channel \
6254 --type='$app:retriever:cur_msg_id'
6257 IMPORTANT: Make sure to always quote the `$` character when you
6258 use man:lttng-add-context(1) from a shell.
6261 NOTE: You can't remove context fields from a channel once you add it.
6266 === Track process attributes
6268 It's often useful to only allow processes with specific attributes to
6269 emit events. For example, you may wish to record all the system calls
6270 which a given process makes (à la
6271 http://linux.die.net/man/1/strace[strace]).
6273 The man:lttng-track(1) and man:lttng-untrack(1) commands serve this
6274 purpose. Both commands operate on _inclusion sets_ of process attribute
6275 values. The available process attribute types are:
6277 Linux kernel <<domain,tracing domain>> only::
6281 * Virtual process ID (VPID).
6283 This is the PID as seen by the application.
6285 * Unix user ID (UID) (since LTTng{nbsp}2.12).
6287 * Virtual Unix user ID (VUID) (since LTTng{nbsp}2.12).
6289 This is the UID as seen by the application.
6291 * Unix group ID (GID) (since LTTng{nbsp}2.12).
6293 * Virtual Unix group ID (VGID) (since LTTng{nbsp}2.12).
6295 This is the GID as seen by the application.
6298 User space tracing domain::
6301 * VUID (since LTTng{nbsp}2.12).
6302 * VGID (since LTTng{nbsp}2.12).
6304 Each tracing domain has one inclusion set per process attribute type:
6305 the Linux kernel tracing domain has six while the user space tracing
6308 For a given event which passes an enabled <<event,event rule>> to be
6309 recorded, _all_ the attributes of its executing process must be part of
6310 the inclusion sets of the event rule's tracing domain.
6312 Add entries to an inclusion set with the man:lttng-track(1) command and
6313 remove entries with the man:lttng-untrack(1) command. A process
6314 attribute is _tracked_ when it's part of an inclusion set and
6315 _untracked_ otherwise.
6319 The process attribute values are _numeric_.
6321 Should a process with a given tracked process ID, for example, exit, and
6322 then a new process be given this ID, then the latter would also be
6323 allowed to emit events.
6325 With the `lttng track` command, you can add Unix user and group _names_
6326 to the user and group inclusion sets: the <<lttng-sessiond,session
6327 daemon>> finds the corresponding UID, VUID, GID, or VGID once on
6328 _addition_ to the inclusion set. This means that if you rename the user
6329 or group after you run `lttng track`, its user/group ID remains tracked.
6332 .Track and untrack virtual process IDs.
6334 For the sake of the following example, assume the target system has
6335 16{nbsp}possible VPIDs.
6338 <<creating-destroying-tracing-sessions,create a tracing session>>,
6339 the user space VPID inclusion set contains _all_ the possible VPIDs:
6342 .All VPIDs are tracked.
6343 image::track-all.png[]
6345 When the inclusion set is full and you use the man:lttng-track(1)
6346 command to specify some VPIDs to track, LTTng first clears the inclusion
6347 set, and then it adds the specific VPIDs to track. After:
6351 $ lttng track --userspace --vpid=3,4,7,10,13
6354 the VPID inclusion set is:
6357 .VPIDs 3, 4, 7, 10, and 13 are tracked.
6358 image::track-3-4-7-10-13.png[]
6360 Add more VPIDs to the inclusion set afterwards:
6364 $ lttng track --userspace --vpid=1,15,16
6370 .VPIDs 1, 15, and 16 are added to the inclusion set.
6371 image::track-1-3-4-7-10-13-15-16.png[]
6373 The man:lttng-untrack(1) command removes entries from process attribute
6374 inclusion sets. Given the previous example, the following command:
6378 $ lttng untrack --userspace --vpid=3,7,10,13
6381 leads to this VPID inclusion set:
6384 .VPIDs 3, 7, 10, and 13 are removed from the inclusion set.
6385 image::track-1-4-15-16.png[]
6387 LTTng can track all the possible VPIDs again using the
6388 opt:lttng-track(1):--all option:
6392 $ lttng track --userspace --vpid --all
6395 The result is, again:
6398 .All VPIDs are tracked.
6399 image::track-all.png[]
6402 .Track only specific process attributes.
6404 A typical use case with process attribute tracking is to start with an
6405 empty inclusion set, then <<basic-tracing-session-control,start the
6406 tracers>>, and then add entries manually while the tracers are active.
6408 Use the opt:lttng-untrack(1):--all option of the
6409 man:lttng-untrack(1) command to clear the inclusion set after you
6410 <<creating-destroying-tracing-sessions,create a tracing session>>, for
6411 example (with UIDs):
6415 $ lttng untrack --kernel --uid --all
6421 .No UIDs are tracked.
6422 image::untrack-all.png[]
6424 If you trace with this inclusion set configuration, the LTTng kernel
6425 tracer records no events within the <<cur-tracing-session,current
6426 tracing session>> because it doesn't track any UID. Use the
6427 man:lttng-track(1) command as usual to track specific UIDs when you need
6432 $ lttng track --kernel --uid=http,11
6438 .UIDs 6 (`http`) and 11 are tracked.
6439 image::track-6-11.png[]
6444 [[saving-loading-tracing-session]]
6445 === Save and load tracing session configurations
6447 Configuring a <<tracing-session,tracing session>> can be long. Some of
6448 the tasks involved are:
6450 * <<enabling-disabling-channels,Create channels>> with
6451 specific attributes.
6452 * <<adding-context,Add context fields>> to specific channels.
6453 * <<enabling-disabling-events,Create event rules>> with specific log
6454 level and filter conditions.
6456 If you use LTTng to solve real world problems, chances are you have to
6457 record events using the same tracing session setup over and over,
6458 modifying a few variables each time in your instrumented program
6459 or environment. To avoid constant tracing session reconfiguration,
6460 the man:lttng(1) command-line tool can save and load tracing session
6461 configurations to/from XML files.
6463 To save a given tracing session configuration:
6465 * Use the man:lttng-save(1) command:
6470 $ lttng save my-session
6474 Replace `my-session` with the name of the tracing session to save.
6476 LTTng saves tracing session configurations to
6477 dir:{$LTTNG_HOME/.lttng/sessions} by default. Note that the
6478 env:LTTNG_HOME environment variable defaults to `$HOME` if not set. Use
6479 the opt:lttng-save(1):--output-path option to change this destination
6482 LTTng saves all configuration parameters, for example:
6484 * The tracing session name.
6485 * The trace data output path.
6486 * The channels with their state and all their attributes.
6487 * The context fields you added to channels.
6488 * The event rules with their state, log level and filter conditions.
6490 To load a tracing session:
6492 * Use the man:lttng-load(1) command:
6497 $ lttng load my-session
6501 Replace `my-session` with the name of the tracing session to load.
6503 When LTTng loads a configuration, it restores your saved tracing session
6504 as if you just configured it manually.
6506 See man:lttng-load(1) for the complete list of command-line options. You
6507 can also save and load many sessions at a time, and decide in which
6508 directory to output the XML files.
6511 [[sending-trace-data-over-the-network]]
6512 === Send trace data over the network
6514 LTTng can send the recorded trace data to a remote system over the
6515 network instead of writing it to the local file system.
6517 To send the trace data over the network:
6519 . On the _remote_ system (which can also be the target system),
6520 start an LTTng <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)):
6529 . On the _target_ system, create a tracing session configured to
6530 send trace data over the network:
6535 $ lttng create my-session --set-url=net://remote-system
6539 Replace `remote-system` by the host name or IP address of the
6540 remote system. See man:lttng-create(1) for the exact URL format.
6542 . On the target system, use the man:lttng(1) command-line tool as usual.
6543 When tracing is active, the target's consumer daemon sends sub-buffers
6544 to the relay daemon running on the remote system instead of flushing
6545 them to the local file system. The relay daemon writes the received
6546 packets to the local file system.
6548 The relay daemon writes trace files to
6549 +$LTTNG_HOME/lttng-traces/__hostname__/__session__+ by default, where
6550 +__hostname__+ is the host name of the target system and +__session__+
6551 is the tracing session name. Note that the env:LTTNG_HOME environment
6552 variable defaults to `$HOME` if not set. Use the
6553 opt:lttng-relayd(8):--output option of man:lttng-relayd(8) to write
6554 trace files to another base directory.
6559 === View events as LTTng emits them (noch:{LTTng} live)
6561 LTTng live is a network protocol implemented by the <<lttng-relayd,relay
6562 daemon>> (man:lttng-relayd(8)) to allow compatible trace viewers to
6563 display events as LTTng emits them on the target system while tracing is
6566 The relay daemon creates a _tee_: it forwards the trace data to both
6567 the local file system and to connected live viewers:
6570 .The relay daemon creates a _tee_, forwarding the trace data to both trace files and a connected live viewer.
6575 . On the _target system_, create a <<tracing-session,tracing session>>
6581 $ lttng create my-session --live
6585 This spawns a local relay daemon.
6587 . Start the live viewer and configure it to connect to the relay
6588 daemon. For example, with
6589 https://babeltrace.org/docs/v2.0/man1/babeltrace2.1/[cmd:babeltrace2]:
6594 $ babeltrace2 net://localhost/host/hostname/my-session
6601 * `hostname` with the host name of the target system.
6602 * `my-session` with the name of the tracing session to view.
6605 . Configure the tracing session as usual with the man:lttng(1)
6606 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6608 List the available live tracing sessions with Babeltrace{nbsp}2:
6612 $ babeltrace2 net://localhost
6615 You can start the relay daemon on another system. In this case, you need
6616 to specify the relay daemon's URL when you create the tracing session
6617 with the opt:lttng-create(1):--set-url option. You also need to replace
6618 `localhost` in the procedure above with the host name of the system on
6619 which the relay daemon is running.
6621 See man:lttng-create(1) and man:lttng-relayd(8) for the complete list of
6622 command-line options.
6626 [[taking-a-snapshot]]
6627 === Take a snapshot of the current sub-buffers of a tracing session
6629 The normal behavior of LTTng is to append full sub-buffers to growing
6630 trace data files. This is ideal to keep a full history of the events
6631 that occurred on the target system, but it can
6632 represent too much data in some situations. For example, you may wish
6633 to trace your application continuously until some critical situation
6634 happens, in which case you only need the latest few recorded
6635 events to perform the desired analysis, not multi-gigabyte trace files.
6637 With the man:lttng-snapshot(1) command, you can take a snapshot of the
6638 current sub-buffers of a given <<tracing-session,tracing session>>.
6639 LTTng can write the snapshot to the local file system or send it over
6643 .A snapshot is a copy of the current sub-buffers, which aren't cleared after the operation.
6644 image::snapshot.png[]
6646 If you wish to create unmanaged, self-contained, non-overlapping
6647 trace chunk archives instead of a simple copy of the current
6648 sub-buffers, see the <<session-rotation,tracing session rotation>>
6649 feature (available since LTTng{nbsp}2.11).
6653 . Create a tracing session in _snapshot mode_:
6658 $ lttng create my-session --snapshot
6662 The <<channel-overwrite-mode-vs-discard-mode,event record loss mode>> of
6663 <<channel,channels>> created in this mode is automatically set to
6664 _overwrite_ (flight recorder mode).
6666 . Configure the tracing session as usual with the man:lttng(1)
6667 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6669 . **Optional**: When you need to take a snapshot,
6670 <<basic-tracing-session-control,stop tracing>>.
6672 You can take a snapshot when the tracers are active, but if you stop
6673 them first, you're sure that the data in the sub-buffers doesn't
6674 change before you actually take the snapshot.
6681 $ lttng snapshot record --name=my-first-snapshot
6685 LTTng writes the current sub-buffers of all the
6686 <<cur-tracing-session,current tracing session>>'s channels to
6687 trace files on the local file system. Those trace files have
6688 `my-first-snapshot` in their name.
6690 There is no difference between the format of a normal trace file and the
6691 format of a snapshot: viewers of LTTng traces also support LTTng
6694 By default, LTTng writes snapshot files to the path shown by
6695 `lttng snapshot list-output`. You can change this path or decide to send
6696 snapshots over the network using either:
6698 . An output path or URL that you specify when you
6699 <<creating-destroying-tracing-sessions,create the tracing session>>.
6700 . A snapshot output path or URL that you add using
6701 `lttng snapshot add-output`.
6702 . An output path or URL that you provide directly to the
6703 `lttng snapshot record` command.
6705 Method{nbsp}3 overrides method{nbsp}2, which overrides method 1. When
6706 you specify a URL, a relay daemon must listen on a remote system (see
6707 <<sending-trace-data-over-the-network,Send trace data over the
6712 [[session-rotation]]
6713 === Archive the current trace chunk (rotate a tracing session)
6715 The <<taking-a-snapshot,snapshot user guide>> shows how to dump
6716 a tracing session's current sub-buffers to the file system or send them
6717 over the network. When you take a snapshot, LTTng doesn't clear the
6718 tracing session's ring buffers: if you take another snapshot immediately
6719 after, both snapshots could contain overlapping trace data.
6721 Inspired by https://en.wikipedia.org/wiki/Log_rotation[log rotation],
6722 _tracing session rotation_ is a feature which appends the content of the
6723 ring buffers to what's already on the file system or sent over the
6724 network since the tracing session's creation or since the last
6725 rotation, and then clears those ring buffers to avoid trace data
6728 What LTTng is about to write when performing a tracing session rotation
6729 is called the _current trace chunk_. When this current trace chunk is
6730 written to the file system or sent over the network, it becomes a _trace
6731 chunk archive_. Therefore, a tracing session rotation _archives_ the
6732 current trace chunk.
6735 .A tracing session rotation operation _archives_ the current trace chunk.
6736 image::rotation.png[]
6738 A trace chunk archive is a self-contained LTTng trace which LTTng
6739 doesn't manage anymore: you can read it, modify it, move it, or remove
6742 There are two methods to perform a tracing session rotation: immediately
6743 or with a rotation schedule.
6745 To perform an immediate tracing session rotation:
6747 . <<creating-destroying-tracing-sessions,Create a tracing session>>
6748 in _normal mode_ or _network streaming mode_
6749 (only those two creation modes support tracing session rotation):
6754 $ lttng create my-session
6758 . <<enabling-disabling-events,Create one or more event rules>>
6759 and <<basic-tracing-session-control,start tracing>>:
6764 $ lttng enable-event --kernel sched_'*'
6769 . When needed, immediately rotate the
6770 <<cur-tracing-session,current tracing session>>:
6779 The cmd:lttng-rotate command prints the path to the created trace
6780 chunk archive. See man:lttng-rotate(1) to learn about the format
6781 of trace chunk archive directory names.
6783 Perform other immediate rotations while the tracing session is
6784 active. It is guaranteed that all the trace chunk archives don't
6785 contain overlapping trace data. You can also perform an immediate
6786 rotation once you have <<basic-tracing-session-control,stopped>> the
6789 . When you're done tracing,
6790 <<creating-destroying-tracing-sessions,destroy the current tracing
6800 The tracing session destruction operation creates one last trace
6801 chunk archive from the current trace chunk.
6803 A tracing session rotation schedule is a planned rotation which LTTng
6804 performs automatically based on one of the following conditions:
6806 * A timer with a configured period times out.
6808 * The total size of the flushed part of the current trace chunk
6809 becomes greater than or equal to a configured value.
6811 To schedule a tracing session rotation, set a _rotation schedule_:
6813 . <<creating-destroying-tracing-sessions,Create a tracing session>>
6814 in _normal mode_ or _network streaming mode_
6815 (only those two creation modes support tracing session rotation):
6820 $ lttng create my-session
6824 . <<enabling-disabling-events,Create one or more event rules>>:
6829 $ lttng enable-event --kernel sched_'*'
6833 . Set a tracing session rotation schedule:
6838 $ lttng enable-rotation --timer=10s
6842 In this example, we set a rotation schedule so that LTTng performs a
6843 tracing session rotation every ten seconds.
6845 See man:lttng-enable-rotation(1) to learn more about other ways to set a
6848 . <<basic-tracing-session-control,Start tracing>>:
6857 LTTng performs tracing session rotations automatically while the tracing
6858 session is active thanks to the rotation schedule.
6860 . When you're done tracing,
6861 <<creating-destroying-tracing-sessions,destroy the current tracing
6871 The tracing session destruction operation creates one last trace chunk
6872 archive from the current trace chunk.
6874 Use man:lttng-disable-rotation(1) to unset a tracing session
6877 NOTE: man:lttng-rotate(1) and man:lttng-enable-rotation(1) list
6878 limitations regarding those two commands.
6883 === Use the machine interface
6885 With any command of the man:lttng(1) command-line tool, set the
6886 opt:lttng(1):--mi option to `xml` (before the command name) to get an
6887 XML machine interface output, for example:
6891 $ lttng --mi=xml enable-event --kernel --syscall open
6894 A schema definition (XSD) is
6895 https://github.com/lttng/lttng-tools/blob/stable-2.12/src/common/mi-lttng-3.0.xsd[available]
6896 to ease the integration with external tools as much as possible.
6900 [[metadata-regenerate]]
6901 === Regenerate the metadata of an LTTng trace
6903 An LTTng trace, which is a http://diamon.org/ctf[CTF] trace, has both
6904 data stream files and a metadata file. This metadata file contains,
6905 amongst other things, information about the offset of the clock sources
6906 used to timestamp <<event,event records>> when tracing.
6908 If, once a <<tracing-session,tracing session>> is
6909 <<basic-tracing-session-control,started>>, a major
6910 https://en.wikipedia.org/wiki/Network_Time_Protocol[NTP] correction
6911 happens, the trace's clock offset also needs to be updated. Use
6912 the `metadata` item of the man:lttng-regenerate(1) command to do so.
6914 The main use case of this command is to allow a system to boot with
6915 an incorrect wall time and trace it with LTTng before its wall time
6916 is corrected. Once the system is known to be in a state where its
6917 wall time is correct, it can run `lttng regenerate metadata`.
6919 To regenerate the metadata of an LTTng trace:
6921 * Use the `metadata` item of the man:lttng-regenerate(1) command:
6926 $ lttng regenerate metadata
6932 `lttng regenerate metadata` has the following limitations:
6934 * Tracing session <<creating-destroying-tracing-sessions,created>>
6936 * User space <<channel,channels>>, if any, are using
6937 <<channel-buffering-schemes,per-user buffering>>.
6942 [[regenerate-statedump]]
6943 === Regenerate the state dump of a tracing session
6945 The LTTng kernel and user space tracers generate state dump
6946 <<event,event records>> when the application starts or when you
6947 <<basic-tracing-session-control,start a tracing session>>. An analysis
6948 can use the state dump event records to set an initial state before it
6949 builds the rest of the state from the following event records.
6950 http://tracecompass.org/[Trace Compass] is a notable example of an
6951 application which uses the state dump of an LTTng trace.
6953 When you <<taking-a-snapshot,take a snapshot>>, it's possible that the
6954 state dump event records aren't included in the snapshot because they
6955 were recorded to a sub-buffer that has been consumed or overwritten
6958 Use the `lttng regenerate statedump` command to emit the state
6959 dump event records again.
6961 To regenerate the state dump of the current tracing session, provided
6962 create it in snapshot mode, before you take a snapshot:
6964 . Use the `statedump` item of the man:lttng-regenerate(1) command:
6969 $ lttng regenerate statedump
6973 . <<basic-tracing-session-control,Stop the tracing session>>:
6982 . <<taking-a-snapshot,Take a snapshot>>:
6987 $ lttng snapshot record --name=my-snapshot
6991 Depending on the event throughput, you should run steps 1 and 2
6992 as closely as possible.
6994 NOTE: To record the state dump events, you need to
6995 <<enabling-disabling-events,create event rules>> which enable them.
6996 LTTng-UST state dump tracepoints start with `lttng_ust_statedump:`.
6997 LTTng-modules state dump tracepoints start with `lttng_statedump_`.
7001 [[persistent-memory-file-systems]]
7002 === Record trace data on persistent memory file systems
7004 https://en.wikipedia.org/wiki/Non-volatile_random-access_memory[Non-volatile random-access memory]
7005 (NVRAM) is random-access memory that retains its information when power
7006 is turned off (non-volatile). Systems with such memory can store data
7007 structures in RAM and retrieve them after a reboot, without flushing
7008 to typical _storage_.
7010 Linux supports NVRAM file systems thanks to either
7011 http://pramfs.sourceforge.net/[PRAMFS] or
7012 https://www.kernel.org/doc/Documentation/filesystems/dax.txt[DAX]{nbsp}+{nbsp}http://lkml.iu.edu/hypermail/linux/kernel/1504.1/03463.html[pmem]
7013 (requires Linux{nbsp}4.1+).
7015 This section doesn't describe how to operate such file systems;
7016 we assume that you have a working persistent memory file system.
7018 When you create a <<tracing-session,tracing session>>, you can specify
7019 the path of the shared memory holding the sub-buffers. If you specify a
7020 location on an NVRAM file system, then you can retrieve the latest
7021 recorded trace data when the system reboots after a crash.
7023 To record trace data on a persistent memory file system and retrieve the
7024 trace data after a system crash:
7026 . Create a tracing session with a sub-buffer shared memory path located
7027 on an NVRAM file system:
7032 $ lttng create my-session --shm-path=/path/to/shm
7036 . Configure the tracing session as usual with the man:lttng(1)
7037 command-line tool, and <<basic-tracing-session-control,start tracing>>.
7039 . After a system crash, use the man:lttng-crash(1) command-line tool to
7040 view the trace data recorded on the NVRAM file system:
7045 $ lttng-crash /path/to/shm
7049 The binary layout of the ring buffer files isn't exactly the same as
7050 the trace files layout. This is why you need to use man:lttng-crash(1)
7051 instead of your preferred trace viewer directly.
7053 To convert the ring buffer files to LTTng trace files:
7055 * Use the opt:lttng-crash(1):--extract option of man:lttng-crash(1):
7060 $ lttng-crash --extract=/path/to/trace /path/to/shm
7066 [[notif-trigger-api]]
7067 === Get notified when a channel's buffer usage is too high or too low
7069 With LTTng's $$C/C++$$ notification and trigger API, your user
7070 application can get notified when the buffer usage of one or more
7071 <<channel,channels>> becomes too low or too high. Use this API
7072 and enable or disable <<event,event rules>> during tracing to avoid
7073 <<channel-overwrite-mode-vs-discard-mode,discarded event records>>.
7075 .Have a user application get notified when an LTTng channel's buffer usage is too high.
7077 In this example, we create and build an application which gets notified
7078 when the buffer usage of a specific LTTng channel is higher than
7079 75{nbsp}%. We only print that it is the case in the example, but we
7080 could as well use the API of <<liblttng-ctl-lttng,`liblttng-ctl`>> to
7081 disable event rules when this happens.
7083 . Create the application's C source file:
7091 #include <lttng/domain.h>
7092 #include <lttng/action/action.h>
7093 #include <lttng/action/notify.h>
7094 #include <lttng/condition/condition.h>
7095 #include <lttng/condition/buffer-usage.h>
7096 #include <lttng/condition/evaluation.h>
7097 #include <lttng/notification/channel.h>
7098 #include <lttng/notification/notification.h>
7099 #include <lttng/trigger/trigger.h>
7100 #include <lttng/endpoint.h>
7102 int main(int argc, char *argv[])
7104 int exit_status = 0;
7105 struct lttng_notification_channel *notification_channel;
7106 struct lttng_condition *condition;
7107 struct lttng_action *action;
7108 struct lttng_trigger *trigger;
7109 const char *tracing_session_name;
7110 const char *channel_name;
7113 tracing_session_name = argv[1];
7114 channel_name = argv[2];
7117 * Create a notification channel. A notification channel
7118 * connects the user application to the LTTng session daemon.
7119 * This notification channel can be used to listen to various
7120 * types of notifications.
7122 notification_channel = lttng_notification_channel_create(
7123 lttng_session_daemon_notification_endpoint);
7126 * Create a "high buffer usage" condition. In this case, the
7127 * condition is reached when the buffer usage is greater than or
7128 * equal to 75 %. We create the condition for a specific tracing
7129 * session name, channel name, and for the user space tracing
7132 * The "low buffer usage" condition type also exists.
7134 condition = lttng_condition_buffer_usage_high_create();
7135 lttng_condition_buffer_usage_set_threshold_ratio(condition, .75);
7136 lttng_condition_buffer_usage_set_session_name(
7137 condition, tracing_session_name);
7138 lttng_condition_buffer_usage_set_channel_name(condition,
7140 lttng_condition_buffer_usage_set_domain_type(condition,
7144 * Create an action (get a notification) to take when the
7145 * condition created above is reached.
7147 action = lttng_action_notify_create();
7150 * Create a trigger. A trigger associates a condition to an
7151 * action: the action is executed when the condition is reached.
7153 trigger = lttng_trigger_create(condition, action);
7155 /* Register the trigger to LTTng. */
7156 lttng_register_trigger(trigger);
7159 * Now that we have registered a trigger, a notification will be
7160 * emitted everytime its condition is met. To receive this
7161 * notification, we must subscribe to notifications that match
7162 * the same condition.
7164 lttng_notification_channel_subscribe(notification_channel,
7168 * Notification loop. Put this in a dedicated thread to avoid
7169 * blocking the main thread.
7172 struct lttng_notification *notification;
7173 enum lttng_notification_channel_status status;
7174 const struct lttng_evaluation *notification_evaluation;
7175 const struct lttng_condition *notification_condition;
7176 double buffer_usage;
7178 /* Receive the next notification. */
7179 status = lttng_notification_channel_get_next_notification(
7180 notification_channel, ¬ification);
7183 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK:
7185 case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED:
7187 * The session daemon can drop notifications if a monitoring
7188 * application isn't consuming the notifications fast
7192 case LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED:
7194 * The notification channel has been closed by the
7195 * session daemon. This is typically caused by a session
7196 * daemon shutting down.
7200 /* Unhandled conditions or errors. */
7206 * A notification provides, amongst other things:
7208 * * The condition that caused this notification to be
7210 * * The condition evaluation, which provides more
7211 * specific information on the evaluation of the
7214 * The condition evaluation provides the buffer usage
7215 * value at the moment the condition was reached.
7217 notification_condition = lttng_notification_get_condition(
7219 notification_evaluation = lttng_notification_get_evaluation(
7222 /* We're subscribed to only one condition. */
7223 assert(lttng_condition_get_type(notification_condition) ==
7224 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH);
7227 * Get the exact sampled buffer usage from the
7228 * condition evaluation.
7230 lttng_evaluation_buffer_usage_get_usage_ratio(
7231 notification_evaluation, &buffer_usage);
7234 * At this point, instead of printing a message, we
7235 * could do something to reduce the channel's buffer
7236 * usage, like disable specific events.
7238 printf("Buffer usage is %f %% in tracing session \"%s\", "
7239 "user space channel \"%s\".\n", buffer_usage * 100,
7240 tracing_session_name, channel_name);
7241 lttng_notification_destroy(notification);
7245 lttng_action_destroy(action);
7246 lttng_condition_destroy(condition);
7247 lttng_trigger_destroy(trigger);
7248 lttng_notification_channel_destroy(notification_channel);
7254 . Build the `notif-app` application, linking it to `liblttng-ctl`:
7259 $ gcc -o notif-app notif-app.c -llttng-ctl
7263 . <<creating-destroying-tracing-sessions,Create a tracing session>>,
7264 <<enabling-disabling-events,create an event rule>> matching all the
7265 user space tracepoints, and
7266 <<basic-tracing-session-control,start tracing>>:
7271 $ lttng create my-session
7272 $ lttng enable-event --userspace --all
7277 If you create the channel manually with the man:lttng-enable-channel(1)
7278 command, control how frequently are the current values of the
7279 channel's properties sampled to evaluate user conditions with the
7280 opt:lttng-enable-channel(1):--monitor-timer option.
7282 . Run the `notif-app` application. This program accepts the
7283 <<tracing-session,tracing session>> name and the user space channel
7284 name as its two first arguments. The channel which LTTng automatically
7285 creates with the man:lttng-enable-event(1) command above is named
7291 $ ./notif-app my-session channel0
7295 . In another terminal, run an application with a very high event
7296 throughput so that the 75{nbsp}% buffer usage condition is reached.
7298 In the first terminal, the application should print lines like this:
7301 Buffer usage is 81.45197 % in tracing session "my-session", user space
7305 If you don't see anything, try modifying the condition in
7306 path:{notif-app.c} to a lower value (0.1, for example), rebuilding it
7307 (step{nbsp}2) and running it again (step{nbsp}4).
7314 [[lttng-modules-ref]]
7315 === noch:{LTTng-modules}
7319 [[lttng-tracepoint-enum]]
7320 ==== `LTTNG_TRACEPOINT_ENUM()` usage
7322 Use the `LTTNG_TRACEPOINT_ENUM()` macro to define an enumeration:
7326 LTTNG_TRACEPOINT_ENUM(name, TP_ENUM_VALUES(entries))
7331 * `name` with the name of the enumeration (C identifier, unique
7332 amongst all the defined enumerations).
7333 * `entries` with a list of enumeration entries.
7335 The available enumeration entry macros are:
7337 +ctf_enum_value(__name__, __value__)+::
7338 Entry named +__name__+ mapped to the integral value +__value__+.
7340 +ctf_enum_range(__name__, __begin__, __end__)+::
7341 Entry named +__name__+ mapped to the range of integral values between
7342 +__begin__+ (included) and +__end__+ (included).
7344 +ctf_enum_auto(__name__)+::
7345 Entry named +__name__+ mapped to the integral value following the
7346 last mapping's value.
7348 The last value of a `ctf_enum_value()` entry is its +__value__+
7351 The last value of a `ctf_enum_range()` entry is its +__end__+ parameter.
7353 If `ctf_enum_auto()` is the first entry in the list, its integral
7356 Use the `ctf_enum()` <<lttng-modules-tp-fields,field definition macro>>
7357 to use a defined enumeration as a tracepoint field.
7359 .Define an enumeration with `LTTNG_TRACEPOINT_ENUM()`.
7363 LTTNG_TRACEPOINT_ENUM(
7366 ctf_enum_auto("AUTO: EXPECT 0")
7367 ctf_enum_value("VALUE: 23", 23)
7368 ctf_enum_value("VALUE: 27", 27)
7369 ctf_enum_auto("AUTO: EXPECT 28")
7370 ctf_enum_range("RANGE: 101 TO 303", 101, 303)
7371 ctf_enum_auto("AUTO: EXPECT 304")
7379 [[lttng-modules-tp-fields]]
7380 ==== Tracepoint fields macros (for `TP_FIELDS()`)
7382 [[tp-fast-assign]][[tp-struct-entry]]The available macros to define
7383 tracepoint fields, which must be listed within `TP_FIELDS()` in
7384 `LTTNG_TRACEPOINT_EVENT()`, are:
7386 [role="func-desc growable",cols="asciidoc,asciidoc"]
7387 .Available macros to define LTTng-modules tracepoint fields
7389 |Macro |Description and parameters
7392 +ctf_integer(__t__, __n__, __e__)+
7394 +ctf_integer_nowrite(__t__, __n__, __e__)+
7396 +ctf_user_integer(__t__, __n__, __e__)+
7398 +ctf_user_integer_nowrite(__t__, __n__, __e__)+
7400 Standard integer, displayed in base{nbsp}10.
7403 Integer C type (`int`, `long`, `size_t`, ...).
7409 Argument expression.
7412 +ctf_integer_hex(__t__, __n__, __e__)+
7414 +ctf_user_integer_hex(__t__, __n__, __e__)+
7416 Standard integer, displayed in base{nbsp}16.
7425 Argument expression.
7427 |+ctf_integer_oct(__t__, __n__, __e__)+
7429 Standard integer, displayed in base{nbsp}8.
7438 Argument expression.
7441 +ctf_integer_network(__t__, __n__, __e__)+
7443 +ctf_user_integer_network(__t__, __n__, __e__)+
7445 Integer in network byte order (big-endian), displayed in base{nbsp}10.
7454 Argument expression.
7457 +ctf_integer_network_hex(__t__, __n__, __e__)+
7459 +ctf_user_integer_network_hex(__t__, __n__, __e__)+
7461 Integer in network byte order, displayed in base{nbsp}16.
7470 Argument expression.
7473 +ctf_enum(__N__, __t__, __n__, __e__)+
7475 +ctf_enum_nowrite(__N__, __t__, __n__, __e__)+
7477 +ctf_user_enum(__N__, __t__, __n__, __e__)+
7479 +ctf_user_enum_nowrite(__N__, __t__, __n__, __e__)+
7484 Name of a <<lttng-tracepoint-enum,previously defined enumeration>>.
7487 Integer C type (`int`, `long`, `size_t`, ...).
7493 Argument expression.
7496 +ctf_string(__n__, __e__)+
7498 +ctf_string_nowrite(__n__, __e__)+
7500 +ctf_user_string(__n__, __e__)+
7502 +ctf_user_string_nowrite(__n__, __e__)+
7504 Null-terminated string; undefined behavior if +__e__+ is `NULL`.
7510 Argument expression.
7513 +ctf_array(__t__, __n__, __e__, __s__)+
7515 +ctf_array_nowrite(__t__, __n__, __e__, __s__)+
7517 +ctf_user_array(__t__, __n__, __e__, __s__)+
7519 +ctf_user_array_nowrite(__t__, __n__, __e__, __s__)+
7521 Statically-sized array of integers.
7524 Array element C type.
7530 Argument expression.
7536 +ctf_array_bitfield(__t__, __n__, __e__, __s__)+
7538 +ctf_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7540 +ctf_user_array_bitfield(__t__, __n__, __e__, __s__)+
7542 +ctf_user_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7544 Statically-sized array of bits.
7546 The type of +__e__+ must be an integer type. +__s__+ is the number
7547 of elements of such type in +__e__+, not the number of bits.
7550 Array element C type.
7556 Argument expression.
7562 +ctf_array_text(__t__, __n__, __e__, __s__)+
7564 +ctf_array_text_nowrite(__t__, __n__, __e__, __s__)+
7566 +ctf_user_array_text(__t__, __n__, __e__, __s__)+
7568 +ctf_user_array_text_nowrite(__t__, __n__, __e__, __s__)+
7570 Statically-sized array, printed as text.
7572 The string doesn't need to be null-terminated.
7575 Array element C type (always `char`).
7581 Argument expression.
7587 +ctf_sequence(__t__, __n__, __e__, __T__, __E__)+
7589 +ctf_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7591 +ctf_user_sequence(__t__, __n__, __e__, __T__, __E__)+
7593 +ctf_user_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7595 Dynamically-sized array of integers.
7597 The type of +__E__+ must be unsigned.
7600 Array element C type.
7606 Argument expression.
7609 Length expression C type.
7615 +ctf_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7617 +ctf_user_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7619 Dynamically-sized array of integers, displayed in base{nbsp}16.
7621 The type of +__E__+ must be unsigned.
7624 Array element C type.
7630 Argument expression.
7633 Length expression C type.
7638 |+ctf_sequence_network(__t__, __n__, __e__, __T__, __E__)+
7640 Dynamically-sized array of integers in network byte order (big-endian),
7641 displayed in base{nbsp}10.
7643 The type of +__E__+ must be unsigned.
7646 Array element C type.
7652 Argument expression.
7655 Length expression C type.
7661 +ctf_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7663 +ctf_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7665 +ctf_user_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7667 +ctf_user_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7669 Dynamically-sized array of bits.
7671 The type of +__e__+ must be an integer type. +__s__+ is the number
7672 of elements of such type in +__e__+, not the number of bits.
7674 The type of +__E__+ must be unsigned.
7677 Array element C type.
7683 Argument expression.
7686 Length expression C type.
7692 +ctf_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7694 +ctf_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7696 +ctf_user_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7698 +ctf_user_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7700 Dynamically-sized array, displayed as text.
7702 The string doesn't need to be null-terminated.
7704 The type of +__E__+ must be unsigned.
7706 The behaviour is undefined if +__e__+ is `NULL`.
7709 Sequence element C type (always `char`).
7715 Argument expression.
7718 Length expression C type.
7724 Use the `_user` versions when the argument expression, `e`, is
7725 a user space address. In the cases of `ctf_user_integer*()` and
7726 `ctf_user_float*()`, `&e` must be a user space address, thus `e` must
7729 The `_nowrite` versions omit themselves from the session trace, but are
7730 otherwise identical. This means the `_nowrite` fields won't be written
7731 in the recorded trace. Their primary purpose is to make some
7732 of the event context available to the
7733 <<enabling-disabling-events,event filters>> without having to
7734 commit the data to sub-buffers.
7740 Terms related to LTTng and to tracing in general:
7743 The http://diamon.org/babeltrace[Babeltrace] project, which includes:
7746 https://babeltrace.org/docs/v2.0/man1/babeltrace2.1/[cmd:babeltrace2]
7747 command-line interface.
7748 * The libbabeltrace2 library which offers a
7749 https://babeltrace.org/docs/v2.0/libbabeltrace2/[C API].
7750 * https://babeltrace.org/docs/v2.0/python/bt2/[Python{nbsp}3 bindings].
7753 [[def-buffering-scheme]]<<channel-buffering-schemes,buffering scheme>>::
7754 A layout of <<def-sub-buffer,sub-buffers>> applied to a given channel.
7756 [[def-channel]]<<channel,channel>>::
7757 An entity which is responsible for a set of
7758 <<def-ring-buffer,ring buffers>>.
7760 <<def-event-rule,Event rules>> are always attached to a specific
7764 A source of time for a <<def-tracer,tracer>>.
7766 [[def-consumer-daemon]]<<lttng-consumerd,consumer daemon>>::
7767 A process which is responsible for consuming the full
7768 <<def-sub-buffer,sub-buffers>> and write them to a file system or
7769 send them over the network.
7771 [[def-current-trace-chunk]]current trace chunk::
7772 A <<def-trace-chunk,trace chunk>> which includes the current content
7773 of all the <<def-tracing-session-rotation,tracing session>>'s
7774 <<def-sub-buffer,sub-buffers>> and the stream files produced since the
7775 latest event amongst:
7777 * The creation of the <<def-tracing-session,tracing session>>.
7778 * The last tracing session rotation, if any.
7780 <<channel-overwrite-mode-vs-discard-mode,discard mode>>::
7781 The <<def-event-record-loss-mode,event record loss mode>> in which
7782 the <<def-tracer,tracer>> _discards_ new event records when there's no
7783 <<def-sub-buffer,sub-buffer>> space left to store them.
7785 [[def-event]]event::
7786 The consequence of the execution of an
7787 <<def-instrumentation-point,instrumentation point>>, like a
7788 <<def-tracepoint,tracepoint>> that you manually place in some source
7789 code, or a Linux kernel kprobe.
7791 An event is said to _occur_ at a specific time. <<def-lttng,LTTng>> can
7792 take various actions upon the occurrence of an event, like record the
7793 event's payload to a <<def-sub-buffer,sub-buffer>>.
7795 [[def-event-name]]event name::
7796 The name of an <<def-event,event>>, which is also the name of the
7797 <<def-event-record,event record>>.
7799 This is also called the _instrumentation point name_.
7801 [[def-event-record]]event record::
7802 A record, in a <<def-trace,trace>>, of the payload of an
7803 <<def-event,event>> which occured.
7805 [[def-event-record-loss-mode]]<<channel-overwrite-mode-vs-discard-mode,event record loss mode>>::
7806 The mechanism by which event records of a given
7807 <<def-channel,channel>> are lost (not recorded) when there is no
7808 <<def-sub-buffer,sub-buffer>> space left to store them.
7810 [[def-event-rule]]<<event,event rule>>::
7811 Set of conditions which must be satisfied for one or more occuring
7812 <<def-event,events>> to be recorded.
7814 [[def-incl-set]]inclusion set::
7815 In the <<pid-tracking,process attribute tracking>> context: a
7816 set of <<def-proc-attr,process attributes>> of a given type.
7818 <<instrumenting,instrumentation>>::
7819 The use of <<def-lttng,LTTng>> probes to make a piece of software
7822 [[def-instrumentation-point]]instrumentation point::
7823 A point in the execution path of a piece of software that, when
7824 reached by this execution, can emit an <<def-event,event>>.
7826 instrumentation point name::
7827 See _<<def-event-name,event name>>_.
7829 `java.util.logging`::
7831 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[core logging facilities].
7834 A http://logging.apache.org/log4j/1.2/[logging library] for Java
7835 developed by the Apache Software Foundation.
7838 Level of severity of a log statement or user space
7839 <<def-instrumentation-point,instrumentation point>>.
7841 [[def-lttng]]LTTng::
7842 The _Linux Trace Toolkit: next generation_ project.
7844 <<lttng-cli,cmd:lttng>>::
7845 A command-line tool provided by the <<def-lttng-tools,LTTng-tools>>
7846 project which you can use to send and receive control messages to and
7847 from a <<def-session-daemon,session daemon>>.
7850 The https://github.com/lttng/lttng-analyses[LTTng analyses] project,
7851 which is a set of analyzing programs that you can use to obtain a
7852 higher level view of an <<def-lttng,LTTng>> <<def-trace,trace>>.
7854 cmd:lttng-consumerd::
7855 The name of the <<def-consumer-daemon,consumer daemon>> program.
7858 A utility provided by the <<def-lttng-tools,LTTng-tools>> project
7859 which can convert <<def-ring-buffer,ring buffer>> files (usually
7860 <<persistent-memory-file-systems,saved on a persistent memory file
7861 system>>) to <<def-trace,trace>> files.
7863 See man:lttng-crash(1).
7865 LTTng Documentation::
7868 <<lttng-live,LTTng live>>::
7869 A communication protocol between the <<lttng-relayd,relay daemon>> and
7870 live viewers which makes it possible to see <<def-event-record,event
7871 records>> ``live'', as they are received by the
7872 <<def-relay-daemon,relay daemon>>.
7874 <<lttng-modules,LTTng-modules>>::
7875 The https://github.com/lttng/lttng-modules[LTTng-modules] project,
7876 which contains the Linux kernel modules to make the Linux kernel
7877 <<def-instrumentation-point,instrumentation points>> available for
7878 <<def-lttng,LTTng>> tracing.
7881 The name of the <<def-relay-daemon,relay daemon>> program.
7883 cmd:lttng-sessiond::
7884 The name of the <<def-session-daemon,session daemon>> program.
7886 [[def-lttng-tools]]LTTng-tools::
7887 The https://github.com/lttng/lttng-tools[LTTng-tools] project, which
7888 contains the various programs and libraries used to
7889 <<controlling-tracing,control tracing>>.
7891 [[def-lttng-ust]]<<lttng-ust,LTTng-UST>>::
7892 The https://github.com/lttng/lttng-ust[LTTng-UST] project, which
7893 contains libraries to instrument
7894 <<def-user-application,user applications>>.
7896 <<lttng-ust-agents,LTTng-UST Java agent>>::
7897 A Java package provided by the <<def-lttng-ust,LTTng-UST>> project to
7898 allow the LTTng instrumentation of `java.util.logging` and Apache
7899 log4j{nbsp}1.2 logging statements.
7901 <<lttng-ust-agents,LTTng-UST Python agent>>::
7902 A Python package provided by the <<def-lttng-ust,LTTng-UST>> project
7903 to allow the <<def-lttng,LTTng>> instrumentation of Python logging
7906 <<channel-overwrite-mode-vs-discard-mode,overwrite mode>>::
7907 The <<def-event-record-loss-mode,event record loss mode>> in which new
7908 <<def-event-record,event records>> _overwrite_ older event records
7909 when there's no <<def-sub-buffer,sub-buffer>> space left to store
7912 <<channel-buffering-schemes,per-process buffering>>::
7913 A <<def-buffering-scheme,buffering scheme>> in which each instrumented
7914 process has its own <<def-sub-buffer,sub-buffers>> for a given user
7915 space <<def-channel,channel>>.
7917 <<channel-buffering-schemes,per-user buffering>>::
7918 A <<def-buffering-scheme,buffering scheme>> in which all the processes
7919 of a Unix user share the same <<def-sub-buffer,sub-buffers>> for a
7920 given user space <<def-channel,channel>>.
7922 [[def-proc-attr]]process attribute::
7923 In the <<pid-tracking,process attribute tracking>> context:
7926 * A virtual process ID.
7928 * A virtual Unix user ID.
7930 * A virtual Unix group ID.
7932 [[def-relay-daemon]]<<lttng-relayd,relay daemon>>::
7933 A process which is responsible for receiving the <<def-trace,trace>>
7934 data which a distant <<def-consumer-daemon,consumer daemon>> sends.
7936 [[def-ring-buffer]]ring buffer::
7937 A set of <<def-sub-buffer,sub-buffers>>.
7940 See _<<def-tracing-session-rotation,tracing session rotation>>_.
7942 [[def-session-daemon]]<<lttng-sessiond,session daemon>>::
7943 A process which receives control commands from you and orchestrates
7944 the <<def-tracer,tracers>> and various <<def-lttng,LTTng>> daemons.
7946 <<taking-a-snapshot,snapshot>>::
7947 A copy of the current data of all the <<def-sub-buffer,sub-buffers>>
7948 of a given <<def-tracing-session,tracing session>>, saved as
7949 <<def-trace,trace>> files.
7951 [[def-sub-buffer]]sub-buffer::
7952 One part of an <<def-lttng,LTTng>> <<def-ring-buffer,ring buffer>>
7953 which contains <<def-event-record,event records>>.
7956 The time information attached to an <<def-event,event>> when it is
7959 [[def-trace]]trace (_noun_)::
7962 * One http://diamon.org/ctf/[CTF] metadata stream file.
7963 * One or more CTF data stream files which are the concatenations of one
7964 or more flushed <<def-sub-buffer,sub-buffers>>.
7966 [[def-trace-verb]]trace (_verb_)::
7967 The action of recording the <<def-event,events>> emitted by an
7968 application or by a system, or to initiate such recording by
7969 controlling a <<def-tracer,tracer>>.
7971 [[def-trace-chunk]]trace chunk::
7972 A self-contained <<def-trace,trace>> which is part of a
7973 <<def-tracing-session,tracing session>>. Each
7974 <<def-tracing-session-rotation, tracing session rotation>> produces a
7975 <<def-trace-chunk-archive,trace chunk archive>>.
7977 [[def-trace-chunk-archive]]trace chunk archive::
7978 The result of a <<def-tracing-session-rotation, tracing session rotation>>.
7980 <<def-lttng,LTTng>> doesn't manage any trace chunk archive, even if its
7981 containing <<def-tracing-session,tracing session>> is still active: you
7982 are free to read it, modify it, move it, or remove it.
7985 The http://tracecompass.org[Trace Compass] project and application.
7987 [[def-tracepoint]]tracepoint::
7988 An instrumentation point using the tracepoint mechanism of the Linux
7989 kernel or of <<def-lttng-ust,LTTng-UST>>.
7991 tracepoint definition::
7992 The definition of a single <<def-tracepoint,tracepoint>>.
7995 The name of a <<def-tracepoint,tracepoint>>.
7997 [[def-tracepoint-provider]]tracepoint provider::
7998 A set of functions providing <<def-tracepoint,tracepoints>> to an
7999 instrumented <<def-user-application,user application>>.
8001 Not to be confused with a <<def-tracepoint-provider-package,tracepoint
8002 provider package>>: many tracepoint providers can exist within a
8003 tracepoint provider package.
8005 [[def-tracepoint-provider-package]]tracepoint provider package::
8006 One or more <<def-tracepoint-provider,tracepoint providers>> compiled
8007 as an https://en.wikipedia.org/wiki/Object_file[object file] or as a
8008 link:https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries[shared
8011 [[def-tracer]]tracer::
8012 A software which records emitted <<def-event,events>>.
8014 <<domain,tracing domain>>::
8015 A namespace for <<def-event,event>> sources.
8017 <<tracing-group,tracing group>>::
8018 The Unix group in which a Unix user can be to be allowed to
8019 <<def-trace-verb,trace>> the Linux kernel.
8021 [[def-tracing-session]]<<tracing-session,tracing session>>::
8022 A stateful dialogue between you and a <<lttng-sessiond,session daemon>>.
8024 [[def-tracing-session-rotation]]<<session-rotation,tracing session rotation>>::
8025 The action of archiving the
8026 <<def-current-trace-chunk,current trace chunk>> of a
8027 <<def-tracing-session,tracing session>>.
8029 tracked <<def-proc-attr,process attribute>>::
8030 A process attribute which is part of an <<def-incl-set,inclusion
8033 untracked process attribute::
8034 A process attribute which isn't part of an <<def-incl-set,inclusion
8037 [[def-user-application]]user application::
8038 An application running in user space, as opposed to a Linux kernel
8039 module, for example.