1 The LTTng Documentation
2 =======================
3 Philippe Proulx <pproulx@efficios.com>
7 include::../common/copyright.txt[]
10 include::../common/warning-not-maintained.txt[]
13 include::../common/welcome.txt[]
16 include::../common/audience.txt[]
20 === What's in this documentation?
22 The LTTng Documentation is divided into the following sections:
24 * **<<nuts-and-bolts,Nuts and bolts>>** explains the
25 rudiments of software tracing and the rationale behind the
28 You can skip this section if you’re familiar with software tracing and
29 with the LTTng project.
31 * **<<installing-lttng,Installation>>** describes the steps to
32 install the LTTng packages on common Linux distributions and from
35 You can skip this section if you already properly installed LTTng on
38 * **<<getting-started,Quick start>>** is a concise guide to
39 getting started quickly with LTTng kernel and user space tracing.
41 We recommend this section if you're new to LTTng or to software tracing
44 You can skip this section if you're not new to LTTng.
46 * **<<core-concepts,Core concepts>>** explains the concepts at
49 It's a good idea to become familiar with the core concepts
50 before attempting to use the toolkit.
52 * **<<plumbing,Components of LTTng>>** describes the various components
53 of the LTTng machinery, like the daemons, the libraries, and the
54 command-line interface.
55 * **<<instrumenting,Instrumentation>>** shows different ways to
56 instrument user applications and the Linux kernel.
58 Instrumenting source code is essential to provide a meaningful
61 You can skip this section if you do not have a programming background.
63 * **<<controlling-tracing,Tracing control>>** is divided into topics
64 which demonstrate how to use the vast array of features that
65 LTTng{nbsp}{revision} offers.
66 * **<<reference,Reference>>** contains reference tables.
67 * **<<glossary,Glossary>>** is a specialized dictionary of terms related
68 to LTTng or to the field of software tracing.
71 include::../common/convention.txt[]
74 include::../common/acknowledgements.txt[]
78 == What's new in LTTng {revision}?
80 LTTng{nbsp}{revision} bears the name _KeKriek_. From
81 http://brasseriedunham.com/[Brasserie Dunham], the _**KeKriek**_ is a
82 sour mashed golden wheat ale fermented with local sour cherries from
83 Tougas orchards. Fresh sweet cherry notes with some tartness, lively
84 carbonation with a dry finish.
86 New features and changes in LTTng{nbsp}{revision}:
88 * **Tracing control**:
89 ** You can put more than one wildcard special character (`*`), and not
90 only at the end, when you <<enabling-disabling-events,create an event
91 rule>>, in both the instrumentation point name and the literal
93 link:/man/1/lttng-enable-event/v{revision}/#doc-filter-syntax[filter expressions]:
98 # lttng enable-event --kernel 'x86_*_local_timer_*' \
99 --filter='name == "*a*b*c*d*e" && count >= 23'
106 $ lttng enable-event --userspace '*_my_org:*msg*'
110 ** New trigger and notification API for
111 <<liblttng-ctl-lttng,`liblttng-ctl`>>. This new subsystem allows you
112 to register triggers which emit a notification when a given
113 condition is satisfied. As of LTTng{nbsp}{revision}, only
114 <<channel,channel>> buffer usage conditions are available.
115 Documentation is available in the
116 https://github.com/lttng/lttng-tools/tree/stable-{revision}/include/lttng[`liblttng-ctl`
118 <<notif-trigger-api,Get notified when a channel's buffer usage is too
121 ** You can now embed the whole textual LTTng-tools man pages into the
122 executables at build time with the `--enable-embedded-help`
123 configuration option. Thanks to this option, you don't need the
124 http://www.methods.co.nz/asciidoc/[AsciiDoc] and
125 https://directory.fsf.org/wiki/Xmlto[xmlto] tools at build time, and
126 a manual pager at run time, to get access to this documentation.
128 * **User space tracing**:
129 ** New blocking mode: an LTTng-UST tracepoint can now block until
130 <<channel,sub-buffer>> space is available instead of discarding event
131 records in <<channel-overwrite-mode-vs-discard-mode,discard mode>>.
132 With this feature, you can be sure that no event records are
133 discarded during your application's execution at the expense of
136 For example, the following command lines create a user space tracing
137 channel with an infinite blocking timeout and run an application
138 instrumented with LTTng-UST which is explicitly allowed to block:
144 $ lttng enable-channel --userspace --blocking-timeout=inf blocking-channel
145 $ lttng enable-event --userspace --channel=blocking-channel --all
147 $ LTTNG_UST_ALLOW_BLOCKING=1 my-app
151 See the complete <<blocking-timeout-example,blocking timeout example>>.
153 * **Linux kernel tracing**:
154 ** Linux 4.10, 4.11, and 4.12 support.
155 ** The thread state dump events recorded by LTTng-modules now contain
156 the task's CPU identifier. This improves the precision of the
157 scheduler model for analyses.
158 ** Extended man:socketpair(2) system call tracing data.
164 What is LTTng? As its name suggests, the _Linux Trace Toolkit: next
165 generation_ is a modern toolkit for tracing Linux systems and
166 applications. So your first question might be:
173 As the history of software engineering progressed and led to what
174 we now take for granted--complex, numerous and
175 interdependent software applications running in parallel on
176 sophisticated operating systems like Linux--the authors of such
177 components, software developers, began feeling a natural
178 urge to have tools that would ensure the robustness and good performance
179 of their masterpieces.
181 One major achievement in this field is, inarguably, the
182 https://www.gnu.org/software/gdb/[GNU debugger (GDB)],
183 an essential tool for developers to find and fix bugs. But even the best
184 debugger won't help make your software run faster, and nowadays, faster
185 software means either more work done by the same hardware, or cheaper
186 hardware for the same work.
188 A _profiler_ is often the tool of choice to identify performance
189 bottlenecks. Profiling is suitable to identify _where_ performance is
190 lost in a given software. The profiler outputs a profile, a statistical
191 summary of observed events, which you may use to discover which
192 functions took the most time to execute. However, a profiler won't
193 report _why_ some identified functions are the bottleneck. Bottlenecks
194 might only occur when specific conditions are met, conditions that are
195 sometimes impossible to capture by a statistical profiler, or impossible
196 to reproduce with an application altered by the overhead of an
197 event-based profiler. For a thorough investigation of software
198 performance issues, a history of execution is essential, with the
199 recorded values of variables and context fields you choose, and
200 with as little influence as possible on the instrumented software. This
201 is where tracing comes in handy.
203 _Tracing_ is a technique used to understand what goes on in a running
204 software system. The software used for tracing is called a _tracer_,
205 which is conceptually similar to a tape recorder. When recording,
206 specific instrumentation points placed in the software source code
207 generate events that are saved on a giant tape: a _trace_ file. You
208 can trace user applications and the operating system at the same time,
209 opening the possibility of resolving a wide range of problems that would
210 otherwise be extremely challenging.
212 Tracing is often compared to _logging_. However, tracers and loggers are
213 two different tools, serving two different purposes. Tracers are
214 designed to record much lower-level events that occur much more
215 frequently than log messages, often in the range of thousands per
216 second, with very little execution overhead. Logging is more appropriate
217 for a very high-level analysis of less frequent events: user accesses,
218 exceptional conditions (errors and warnings, for example), database
219 transactions, instant messaging communications, and such. Simply put,
220 logging is one of the many use cases that can be satisfied with tracing.
222 The list of recorded events inside a trace file can be read manually
223 like a log file for the maximum level of detail, but it is generally
224 much more interesting to perform application-specific analyses to
225 produce reduced statistics and graphs that are useful to resolve a
226 given problem. Trace viewers and analyzers are specialized tools
229 In the end, this is what LTTng is: a powerful, open source set of
230 tools to trace the Linux kernel and user applications at the same time.
231 LTTng is composed of several components actively maintained and
232 developed by its link:/community/#where[community].
235 [[lttng-alternatives]]
236 === Alternatives to noch:{LTTng}
238 Excluding proprietary solutions, a few competing software tracers
241 * https://github.com/dtrace4linux/linux[dtrace4linux] is a port of
242 Sun Microsystems's DTrace to Linux. The cmd:dtrace tool interprets
243 user scripts and is responsible for loading code into the
244 Linux kernel for further execution and collecting the outputted data.
245 * https://en.wikipedia.org/wiki/Berkeley_Packet_Filter[eBPF] is a
246 subsystem in the Linux kernel in which a virtual machine can execute
247 programs passed from the user space to the kernel. You can attach
248 such programs to tracepoints and KProbes thanks to a system call, and
249 they can output data to the user space when executed thanks to
250 different mechanisms (pipe, VM register values, and eBPF maps, to name
252 * https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace]
253 is the de facto function tracer of the Linux kernel. Its user
254 interface is a set of special files in sysfs.
255 * https://perf.wiki.kernel.org/[perf] is
256 a performance analyzing tool for Linux which supports hardware
257 performance counters, tracepoints, as well as other counters and
258 types of probes. perf's controlling utility is the cmd:perf command
260 * http://linux.die.net/man/1/strace[strace]
261 is a command-line utility which records system calls made by a
262 user process, as well as signal deliveries and changes of process
263 state. strace makes use of https://en.wikipedia.org/wiki/Ptrace[ptrace]
264 to fulfill its function.
265 * http://www.sysdig.org/[sysdig], like SystemTap, uses scripts to
266 analyze Linux kernel events. You write scripts, or _chisels_ in
267 sysdig's jargon, in Lua and sysdig executes them while the system is
268 being traced or afterwards. sysdig's interface is the cmd:sysdig
269 command-line tool as well as the curses-based cmd:csysdig tool.
270 * https://sourceware.org/systemtap/[SystemTap] is a Linux kernel and
271 user space tracer which uses custom user scripts to produce plain text
272 traces. SystemTap converts the scripts to the C language, and then
273 compiles them as Linux kernel modules which are loaded to produce
274 trace data. SystemTap's primary user interface is the cmd:stap
277 The main distinctive features of LTTng is that it produces correlated
278 kernel and user space traces, as well as doing so with the lowest
279 overhead amongst other solutions. It produces trace files in the
280 http://diamon.org/ctf[CTF] format, a file format optimized
281 for the production and analyses of multi-gigabyte data.
283 LTTng is the result of more than 10 years of active open source
284 development by a community of passionate developers.
285 LTTng{nbsp}{revision} is currently available on major desktop and server
288 The main interface for tracing control is a single command-line tool
289 named cmd:lttng. The latter can create several tracing sessions, enable
290 and disable events on the fly, filter events efficiently with custom
291 user expressions, start and stop tracing, and much more. LTTng can
292 record the traces on the file system or send them over the network, and
293 keep them totally or partially. You can view the traces once tracing
294 becomes inactive or in real-time.
296 <<installing-lttng,Install LTTng now>> and
297 <<getting-started,start tracing>>!
303 include::../common/warning-no-installation.txt[]
305 **LTTng** is a set of software <<plumbing,components>> which interact to
306 <<instrumenting,instrument>> the Linux kernel and user applications, and
307 to <<controlling-tracing,control tracing>> (start and stop
308 tracing, enable and disable event rules, and the rest). Those
309 components are bundled into the following packages:
311 * **LTTng-tools**: Libraries and command-line interface to
313 * **LTTng-modules**: Linux kernel modules to instrument and
315 * **LTTng-UST**: Libraries and Java/Python packages to instrument and
316 trace user applications.
318 Most distributions mark the LTTng-modules and LTTng-UST packages as
319 optional when installing LTTng-tools (which is always required). Note
322 * You only need to install LTTng-modules if you intend to trace the
324 * You only need to install LTTng-UST if you intend to trace user
328 [[building-from-source]]
329 === Build from source
331 To build and install LTTng{nbsp}{revision} from source:
333 . Using your distribution's package manager, or from source, install
334 the following dependencies of LTTng-tools and LTTng-UST:
337 * https://sourceforge.net/projects/libuuid/[libuuid]
338 * http://directory.fsf.org/wiki/Popt[popt]
339 * http://liburcu.org/[Userspace RCU]
340 * http://www.xmlsoft.org/[libxml2]
343 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
349 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
350 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
351 cd lttng-modules-2.10.* &&
353 sudo make modules_install &&
358 . Download, build, and install the latest LTTng-UST{nbsp}{revision}:
364 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.10.tar.bz2 &&
365 tar -xf lttng-ust-latest-2.10.tar.bz2 &&
366 cd lttng-ust-2.10.* &&
376 .Java and Python application tracing
378 If you need to instrument and trace <<java-application,Java
379 applications>>, pass the `--enable-java-agent-jul`,
380 `--enable-java-agent-log4j`, or `--enable-java-agent-all` options to the
381 `configure` script, depending on which Java logging framework you use.
383 If you need to instrument and trace <<python-application,Python
384 applications>>, pass the `--enable-python-agent` option to the
385 `configure` script. You can set the `PYTHON` environment variable to the
386 path to the Python interpreter for which to install the LTTng-UST Python
394 By default, LTTng-UST libraries are installed to
395 dir:{/usr/local/lib}, which is the de facto directory in which to
396 keep self-compiled and third-party libraries.
398 When <<building-tracepoint-providers-and-user-application,linking an
399 instrumented user application with `liblttng-ust`>>:
401 * Append `/usr/local/lib` to the env:LD_LIBRARY_PATH environment
403 * Pass the `-L/usr/local/lib` and `-Wl,-rpath,/usr/local/lib` options to
404 man:gcc(1), man:g++(1), or man:clang(1).
408 . Download, build, and install the latest LTTng-tools{nbsp}{revision}:
414 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.10.tar.bz2 &&
415 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
416 cd lttng-tools-2.10.* &&
424 TIP: The https://github.com/eepp/vlttng[vlttng tool] can do all the
425 previous steps automatically for a given version of LTTng and confine
426 the installed files in a specific directory. This can be useful to test
427 LTTng without installing it on your system.
433 This is a short guide to get started quickly with LTTng kernel and user
436 Before you follow this guide, make sure to <<installing-lttng,install>>
439 This tutorial walks you through the steps to:
441 . <<tracing-the-linux-kernel,Trace the Linux kernel>>.
442 . <<tracing-your-own-user-application,Trace a user application>> written
444 . <<viewing-and-analyzing-your-traces,View and analyze the
448 [[tracing-the-linux-kernel]]
449 === Trace the Linux kernel
451 The following command lines start with the `#` prompt because you need
452 root privileges to trace the Linux kernel. You can also trace the kernel
453 as a regular user if your Unix user is a member of the
454 <<tracing-group,tracing group>>.
456 . Create a <<tracing-session,tracing session>> which writes its traces
457 to dir:{/tmp/my-kernel-trace}:
462 # lttng create my-kernel-session --output=/tmp/my-kernel-trace
466 . List the available kernel tracepoints and system calls:
471 # lttng list --kernel
472 # lttng list --kernel --syscall
476 . Create <<event,event rules>> which match the desired instrumentation
477 point names, for example the `sched_switch` and `sched_process_fork`
478 tracepoints, and the man:open(2) and man:close(2) system calls:
483 # lttng enable-event --kernel sched_switch,sched_process_fork
484 # lttng enable-event --kernel --syscall open,close
488 You can also create an event rule which matches _all_ the Linux kernel
489 tracepoints (this will generate a lot of data when tracing):
494 # lttng enable-event --kernel --all
498 . <<basic-tracing-session-control,Start tracing>>:
507 . Do some operation on your system for a few seconds. For example,
508 load a website, or list the files of a directory.
509 . <<creating-destroying-tracing-sessions,Destroy>> the current
519 The man:lttng-destroy(1) command does not destroy the trace data; it
520 only destroys the state of the tracing session.
522 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
523 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
524 session>>). You need to stop tracing to make LTTng flush the remaining
525 trace data and make the trace readable.
527 . For the sake of this example, make the recorded trace accessible to
533 # chown -R $(whoami) /tmp/my-kernel-trace
537 See <<viewing-and-analyzing-your-traces,View and analyze the
538 recorded events>> to view the recorded events.
541 [[tracing-your-own-user-application]]
542 === Trace a user application
544 This section steps you through a simple example to trace a
545 _Hello world_ program written in C.
547 To create the traceable user application:
549 . Create the tracepoint provider header file, which defines the
550 tracepoints and the events they can generate:
556 #undef TRACEPOINT_PROVIDER
557 #define TRACEPOINT_PROVIDER hello_world
559 #undef TRACEPOINT_INCLUDE
560 #define TRACEPOINT_INCLUDE "./hello-tp.h"
562 #if !defined(_HELLO_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
565 #include <lttng/tracepoint.h>
575 ctf_string(my_string_field, my_string_arg)
576 ctf_integer(int, my_integer_field, my_integer_arg)
580 #endif /* _HELLO_TP_H */
582 #include <lttng/tracepoint-event.h>
586 . Create the tracepoint provider package source file:
592 #define TRACEPOINT_CREATE_PROBES
593 #define TRACEPOINT_DEFINE
595 #include "hello-tp.h"
599 . Build the tracepoint provider package:
604 $ gcc -c -I. hello-tp.c
608 . Create the _Hello World_ application source file:
615 #include "hello-tp.h"
617 int main(int argc, char *argv[])
621 puts("Hello, World!\nPress Enter to continue...");
624 * The following getchar() call is only placed here for the purpose
625 * of this demonstration, to pause the application in order for
626 * you to have time to list its tracepoints. It is not
632 * A tracepoint() call.
634 * Arguments, as defined in hello-tp.h:
636 * 1. Tracepoint provider name (required)
637 * 2. Tracepoint name (required)
638 * 3. my_integer_arg (first user-defined argument)
639 * 4. my_string_arg (second user-defined argument)
641 * Notice the tracepoint provider and tracepoint names are
642 * NOT strings: they are in fact parts of variables that the
643 * macros in hello-tp.h create.
645 tracepoint(hello_world, my_first_tracepoint, 23, "hi there!");
647 for (x = 0; x < argc; ++x) {
648 tracepoint(hello_world, my_first_tracepoint, x, argv[x]);
651 puts("Quitting now!");
652 tracepoint(hello_world, my_first_tracepoint, x * x, "x^2");
659 . Build the application:
668 . Link the application with the tracepoint provider package,
669 `liblttng-ust`, and `libdl`:
674 $ gcc -o hello hello.o hello-tp.o -llttng-ust -ldl
678 Here's the whole build process:
681 .User space tracing tutorial's build steps.
682 image::ust-flow.png[]
684 To trace the user application:
686 . Run the application with a few arguments:
691 $ ./hello world and beyond
700 Press Enter to continue...
704 . Start an LTTng <<lttng-sessiond,session daemon>>:
709 $ lttng-sessiond --daemonize
713 Note that a session daemon might already be running, for example as
714 a service that the distribution's service manager started.
716 . List the available user space tracepoints:
721 $ lttng list --userspace
725 You see the `hello_world:my_first_tracepoint` tracepoint listed
726 under the `./hello` process.
728 . Create a <<tracing-session,tracing session>>:
733 $ lttng create my-user-space-session
737 . Create an <<event,event rule>> which matches the
738 `hello_world:my_first_tracepoint` event name:
743 $ lttng enable-event --userspace hello_world:my_first_tracepoint
747 . <<basic-tracing-session-control,Start tracing>>:
756 . Go back to the running `hello` application and press Enter. The
757 program executes all `tracepoint()` instrumentation points and exits.
758 . <<creating-destroying-tracing-sessions,Destroy>> the current
768 The man:lttng-destroy(1) command does not destroy the trace data; it
769 only destroys the state of the tracing session.
771 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
772 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
773 session>>). You need to stop tracing to make LTTng flush the remaining
774 trace data and make the trace readable.
776 By default, LTTng saves the traces in
777 +$LTTNG_HOME/lttng-traces/__name__-__date__-__time__+,
778 where +__name__+ is the tracing session name. The
779 env:LTTNG_HOME environment variable defaults to `$HOME` if not set.
781 See <<viewing-and-analyzing-your-traces,View and analyze the
782 recorded events>> to view the recorded events.
785 [[viewing-and-analyzing-your-traces]]
786 === View and analyze the recorded events
788 Once you have completed the <<tracing-the-linux-kernel,Trace the Linux
789 kernel>> and <<tracing-your-own-user-application,Trace a user
790 application>> tutorials, you can inspect the recorded events.
792 Many tools are available to read LTTng traces:
794 * **cmd:babeltrace** is a command-line utility which converts trace
795 formats; it supports the format that LTTng produces, CTF, as well as a
796 basic text output which can be ++grep++ed. The cmd:babeltrace command
797 is part of the http://diamon.org/babeltrace[Babeltrace] project.
798 * Babeltrace also includes
799 **https://www.python.org/[Python] bindings** so
800 that you can easily open and read an LTTng trace with your own script,
801 benefiting from the power of Python.
802 * http://tracecompass.org/[**Trace Compass**]
803 is a graphical user interface for viewing and analyzing any type of
804 logs or traces, including LTTng's.
805 * https://github.com/lttng/lttng-analyses[**LTTng analyses**] is a
806 project which includes many high-level analyses of LTTng kernel
807 traces, like scheduling statistics, interrupt frequency distribution,
808 top CPU usage, and more.
810 NOTE: This section assumes that the traces recorded during the previous
811 tutorials were saved to their default location, in the
812 dir:{$LTTNG_HOME/lttng-traces} directory. The env:LTTNG_HOME
813 environment variable defaults to `$HOME` if not set.
816 [[viewing-and-analyzing-your-traces-bt]]
817 ==== Use the cmd:babeltrace command-line tool
819 The simplest way to list all the recorded events of a trace is to pass
820 its path to cmd:babeltrace with no options:
824 $ babeltrace ~/lttng-traces/my-user-space-session*
827 cmd:babeltrace finds all traces recursively within the given path and
828 prints all their events, merging them in chronological order.
830 You can pipe the output of cmd:babeltrace into a tool like man:grep(1) for
835 $ babeltrace /tmp/my-kernel-trace | grep _switch
838 You can pipe the output of cmd:babeltrace into a tool like man:wc(1) to
839 count the recorded events:
843 $ babeltrace /tmp/my-kernel-trace | grep _open | wc --lines
847 [[viewing-and-analyzing-your-traces-bt-python]]
848 ==== Use the Babeltrace Python bindings
850 The <<viewing-and-analyzing-your-traces-bt,text output of cmd:babeltrace>>
851 is useful to isolate events by simple matching using man:grep(1) and
852 similar utilities. However, more elaborate filters, such as keeping only
853 event records with a field value falling within a specific range, are
854 not trivial to write using a shell. Moreover, reductions and even the
855 most basic computations involving multiple event records are virtually
856 impossible to implement.
858 Fortunately, Babeltrace ships with Python 3 bindings which makes it easy
859 to read the event records of an LTTng trace sequentially and compute the
862 The following script accepts an LTTng Linux kernel trace path as its
863 first argument and prints the short names of the top 5 running processes
864 on CPU 0 during the whole trace:
869 from collections import Counter
875 if len(sys.argv) != 2:
876 msg = 'Usage: python3 {} TRACEPATH'.format(sys.argv[0])
877 print(msg, file=sys.stderr)
880 # A trace collection contains one or more traces
881 col = babeltrace.TraceCollection()
883 # Add the trace provided by the user (LTTng traces always have
885 if col.add_trace(sys.argv[1], 'ctf') is None:
886 raise RuntimeError('Cannot add trace')
888 # This counter dict contains execution times:
890 # task command name -> total execution time (ns)
891 exec_times = Counter()
893 # This contains the last `sched_switch` timestamp
897 for event in col.events:
898 # Keep only `sched_switch` events
899 if event.name != 'sched_switch':
902 # Keep only events which happened on CPU 0
903 if event['cpu_id'] != 0:
907 cur_ts = event.timestamp
913 # Previous task command (short) name
914 prev_comm = event['prev_comm']
916 # Initialize entry in our dict if not yet done
917 if prev_comm not in exec_times:
918 exec_times[prev_comm] = 0
920 # Compute previous command execution time
921 diff = cur_ts - last_ts
923 # Update execution time of this command
924 exec_times[prev_comm] += diff
926 # Update last timestamp
930 for name, ns in exec_times.most_common(5):
932 print('{:20}{} s'.format(name, s))
937 if __name__ == '__main__':
938 sys.exit(0 if top5proc() else 1)
945 $ python3 top5proc.py /tmp/my-kernel-trace/kernel
951 swapper/0 48.607245889 s
952 chromium 7.192738188 s
953 pavucontrol 0.709894415 s
954 Compositor 0.660867933 s
955 Xorg.bin 0.616753786 s
958 Note that `swapper/0` is the "idle" process of CPU 0 on Linux; since we
959 weren't using the CPU that much when tracing, its first position in the
964 == [[understanding-lttng]]Core concepts
966 From a user's perspective, the LTTng system is built on a few concepts,
967 or objects, on which the <<lttng-cli,cmd:lttng command-line tool>>
968 operates by sending commands to the <<lttng-sessiond,session daemon>>.
969 Understanding how those objects relate to eachother is key in mastering
972 The core concepts are:
974 * <<tracing-session,Tracing session>>
975 * <<domain,Tracing domain>>
976 * <<channel,Channel and ring buffer>>
977 * <<"event","Instrumentation point, event rule, event, and event record">>
983 A _tracing session_ is a stateful dialogue between you and
984 a <<lttng-sessiond,session daemon>>. You can
985 <<creating-destroying-tracing-sessions,create a new tracing
986 session>> with the `lttng create` command.
988 Anything that you do when you control LTTng tracers happens within a
989 tracing session. In particular, a tracing session:
992 * Has its own set of trace files.
993 * Has its own state of activity (started or stopped).
994 * Has its own <<tracing-session-mode,mode>> (local, network streaming,
996 * Has its own <<channel,channels>> which have their own
997 <<event,event rules>>.
1000 .A _tracing session_ contains <<channel,channels>> that are members of <<domain,tracing domains>> and contain <<event,event rules>>.
1001 image::concepts.png[]
1003 Those attributes and objects are completely isolated between different
1006 A tracing session is analogous to a cash machine session:
1007 the operations you do on the banking system through the cash machine do
1008 not alter the data of other users of the same system. In the case of
1009 the cash machine, a session lasts as long as your bank card is inside.
1010 In the case of LTTng, a tracing session lasts from the `lttng create`
1011 command to the `lttng destroy` command.
1014 .Each Unix user has its own set of tracing sessions.
1015 image::many-sessions.png[]
1018 [[tracing-session-mode]]
1019 ==== Tracing session mode
1021 LTTng can send the generated trace data to different locations. The
1022 _tracing session mode_ dictates where to send it. The following modes
1023 are available in LTTng{nbsp}{revision}:
1026 LTTng writes the traces to the file system of the machine being traced
1029 Network streaming mode::
1030 LTTng sends the traces over the network to a
1031 <<lttng-relayd,relay daemon>> running on a remote system.
1034 LTTng does not write the traces by default. Instead, you can request
1035 LTTng to <<taking-a-snapshot,take a snapshot>>, that is, a copy of the
1036 current tracing buffers, and to write it to the target's file system
1037 or to send it over the network to a <<lttng-relayd,relay daemon>>
1038 running on a remote system.
1041 This mode is similar to the network streaming mode, but a live
1042 trace viewer can connect to the distant relay daemon to
1043 <<lttng-live,view event records as LTTng generates them>> by
1050 A _tracing domain_ is a namespace for event sources. A tracing domain
1051 has its own properties and features.
1053 There are currently five available tracing domains:
1057 * `java.util.logging` (JUL)
1061 You must specify a tracing domain when using some commands to avoid
1062 ambiguity. For example, since all the domains support named tracepoints
1063 as event sources (instrumentation points that you manually insert in the
1064 source code), you need to specify a tracing domain when
1065 <<enabling-disabling-events,creating an event rule>> because all the
1066 tracing domains could have tracepoints with the same names.
1068 Some features are reserved to specific tracing domains. Dynamic function
1069 entry and return instrumentation points, for example, are currently only
1070 supported in the Linux kernel tracing domain, but support for other
1071 tracing domains could be added in the future.
1073 You can create <<channel,channels>> in the Linux kernel and user space
1074 tracing domains. The other tracing domains have a single default
1079 === Channel and ring buffer
1081 A _channel_ is an object which is responsible for a set of ring buffers.
1082 Each ring buffer is divided into multiple sub-buffers. When an LTTng
1083 tracer emits an event, it can record it to one or more
1084 sub-buffers. The attributes of a channel determine what to do when
1085 there's no space left for a new event record because all sub-buffers
1086 are full, where to send a full sub-buffer, and other behaviours.
1088 A channel is always associated to a <<domain,tracing domain>>. The
1089 `java.util.logging` (JUL), log4j, and Python tracing domains each have
1090 a default channel which you cannot configure.
1092 A channel also owns <<event,event rules>>. When an LTTng tracer emits
1093 an event, it records it to the sub-buffers of all
1094 the enabled channels with a satisfied event rule, as long as those
1095 channels are part of active <<tracing-session,tracing sessions>>.
1098 [[channel-buffering-schemes]]
1099 ==== Per-user vs. per-process buffering schemes
1101 A channel has at least one ring buffer _per CPU_. LTTng always
1102 records an event to the ring buffer associated to the CPU on which it
1105 Two _buffering schemes_ are available when you
1106 <<enabling-disabling-channels,create a channel>> in the
1107 user space <<domain,tracing domain>>:
1109 Per-user buffering::
1110 Allocate one set of ring buffers--one per CPU--shared by all the
1111 instrumented processes of each Unix user.
1115 .Per-user buffering scheme.
1116 image::per-user-buffering.png[]
1119 Per-process buffering::
1120 Allocate one set of ring buffers--one per CPU--for each
1121 instrumented process.
1125 .Per-process buffering scheme.
1126 image::per-process-buffering.png[]
1129 The per-process buffering scheme tends to consume more memory than the
1130 per-user option because systems generally have more instrumented
1131 processes than Unix users running instrumented processes. However, the
1132 per-process buffering scheme ensures that one process having a high
1133 event throughput won't fill all the shared sub-buffers of the same
1136 The Linux kernel tracing domain has only one available buffering scheme
1137 which is to allocate a single set of ring buffers for the whole system.
1138 This scheme is similar to the per-user option, but with a single, global
1139 user "running" the kernel.
1142 [[channel-overwrite-mode-vs-discard-mode]]
1143 ==== Overwrite vs. discard event loss modes
1145 When an event occurs, LTTng records it to a specific sub-buffer (yellow
1146 arc in the following animation) of a specific channel's ring buffer.
1147 When there's no space left in a sub-buffer, the tracer marks it as
1148 consumable (red) and another, empty sub-buffer starts receiving the
1149 following event records. A <<lttng-consumerd,consumer daemon>>
1150 eventually consumes the marked sub-buffer (returns to white).
1153 [role="docsvg-channel-subbuf-anim"]
1158 In an ideal world, sub-buffers are consumed faster than they are filled,
1159 as is the case in the previous animation. In the real world,
1160 however, all sub-buffers can be full at some point, leaving no space to
1161 record the following events.
1163 By default, LTTng-modules and LTTng-UST are _non-blocking_ tracers: when
1164 no empty sub-buffer is available, it is acceptable to lose event records
1165 when the alternative would be to cause substantial delays in the
1166 instrumented application's execution. LTTng privileges performance over
1167 integrity; it aims at perturbing the traced system as little as possible
1168 in order to make tracing of subtle race conditions and rare interrupt
1171 Starting from LTTng{nbsp}2.10, the LTTng user space tracer, LTTng-UST,
1172 supports a _blocking mode_. See the <<blocking-timeout-example,blocking
1173 timeout example>> to learn how to use the blocking mode.
1175 When it comes to losing event records because no empty sub-buffer is
1176 available, or because the <<opt-blocking-timeout,blocking timeout>> is
1177 reached, the channel's _event loss mode_ determines what to do. The
1178 available event loss modes are:
1181 Drop the newest event records until a the tracer releases a
1184 This is the only available mode when you specify a
1185 <<opt-blocking-timeout,blocking timeout>>.
1188 Clear the sub-buffer containing the oldest event records and start
1189 writing the newest event records there.
1191 This mode is sometimes called _flight recorder mode_ because it's
1193 https://en.wikipedia.org/wiki/Flight_recorder[flight recorder]:
1194 always keep a fixed amount of the latest data.
1196 Which mechanism you should choose depends on your context: prioritize
1197 the newest or the oldest event records in the ring buffer?
1199 Beware that, in overwrite mode, the tracer abandons a _whole sub-buffer_
1200 as soon as a there's no space left for a new event record, whereas in
1201 discard mode, the tracer only discards the event record that doesn't
1204 In discard mode, LTTng increments a count of lost event records when an
1205 event record is lost and saves this count to the trace. In overwrite
1206 mode, since LTTng 2.8, LTTng increments a count of lost sub-buffers when
1207 a sub-buffer is lost and saves this count to the trace. In this mode,
1208 the exact number of lost event records in those lost sub-buffers is not
1209 saved to the trace. Trace analyses can use the trace's saved discarded
1210 event record and sub-buffer counts to decide whether or not to perform
1211 the analyses even if trace data is known to be missing.
1213 There are a few ways to decrease your probability of losing event
1215 <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>> shows
1216 how you can fine-tune the sub-buffer count and size of a channel to
1217 virtually stop losing event records, though at the cost of greater
1221 [[channel-subbuf-size-vs-subbuf-count]]
1222 ==== Sub-buffer count and size
1224 When you <<enabling-disabling-channels,create a channel>>, you can
1225 set its number of sub-buffers and their size.
1227 Note that there is noticeable CPU overhead introduced when
1228 switching sub-buffers (marking a full one as consumable and switching
1229 to an empty one for the following events to be recorded). Knowing this,
1230 the following list presents a few practical situations along with how
1231 to configure the sub-buffer count and size for them:
1233 * **High event throughput**: In general, prefer bigger sub-buffers to
1234 lower the risk of losing event records.
1236 Having bigger sub-buffers also ensures a lower
1237 <<channel-switch-timer,sub-buffer switching frequency>>.
1239 The number of sub-buffers is only meaningful if you create the channel
1240 in overwrite mode: in this case, if a sub-buffer overwrite happens, the
1241 other sub-buffers are left unaltered.
1243 * **Low event throughput**: In general, prefer smaller sub-buffers
1244 since the risk of losing event records is low.
1246 Because events occur less frequently, the sub-buffer switching frequency
1247 should remain low and thus the tracer's overhead should not be a
1250 * **Low memory system**: If your target system has a low memory
1251 limit, prefer fewer first, then smaller sub-buffers.
1253 Even if the system is limited in memory, you want to keep the
1254 sub-buffers as big as possible to avoid a high sub-buffer switching
1257 Note that LTTng uses http://diamon.org/ctf/[CTF] as its trace format,
1258 which means event data is very compact. For example, the average
1259 LTTng kernel event record weights about 32{nbsp}bytes. Thus, a
1260 sub-buffer size of 1{nbsp}MiB is considered big.
1262 The previous situations highlight the major trade-off between a few big
1263 sub-buffers and more, smaller sub-buffers: sub-buffer switching
1264 frequency vs. how much data is lost in overwrite mode. Assuming a
1265 constant event throughput and using the overwrite mode, the two
1266 following configurations have the same ring buffer total size:
1269 [role="docsvg-channel-subbuf-size-vs-count-anim"]
1274 * **2 sub-buffers of 4{nbsp}MiB each**: Expect a very low sub-buffer
1275 switching frequency, but if a sub-buffer overwrite happens, half of
1276 the event records so far (4{nbsp}MiB) are definitely lost.
1277 * **8 sub-buffers of 1{nbsp}MiB each**: Expect 4{nbsp}times the tracer's
1278 overhead as the previous configuration, but if a sub-buffer
1279 overwrite happens, only the eighth of event records so far are
1282 In discard mode, the sub-buffers count parameter is pointless: use two
1283 sub-buffers and set their size according to the requirements of your
1287 [[channel-switch-timer]]
1288 ==== Switch timer period
1290 The _switch timer period_ is an important configurable attribute of
1291 a channel to ensure periodic sub-buffer flushing.
1293 When the _switch timer_ expires, a sub-buffer switch happens. You can
1294 set the switch timer period attribute when you
1295 <<enabling-disabling-channels,create a channel>> to ensure that event
1296 data is consumed and committed to trace files or to a distant relay
1297 daemon periodically in case of a low event throughput.
1300 [role="docsvg-channel-switch-timer"]
1305 This attribute is also convenient when you use big sub-buffers to cope
1306 with a sporadic high event throughput, even if the throughput is
1310 [[channel-read-timer]]
1311 ==== Read timer period
1313 By default, the LTTng tracers use a notification mechanism to signal a
1314 full sub-buffer so that a consumer daemon can consume it. When such
1315 notifications must be avoided, for example in real-time applications,
1316 you can use the channel's _read timer_ instead. When the read timer
1317 fires, the <<lttng-consumerd,consumer daemon>> checks for full,
1318 consumable sub-buffers.
1321 [[tracefile-rotation]]
1322 ==== Trace file count and size
1324 By default, trace files can grow as large as needed. You can set the
1325 maximum size of each trace file that a channel writes when you
1326 <<enabling-disabling-channels,create a channel>>. When the size of
1327 a trace file reaches the channel's fixed maximum size, LTTng creates
1328 another file to contain the next event records. LTTng appends a file
1329 count to each trace file name in this case.
1331 If you set the trace file size attribute when you create a channel, the
1332 maximum number of trace files that LTTng creates is _unlimited_ by
1333 default. To limit them, you can also set a maximum number of trace
1334 files. When the number of trace files reaches the channel's fixed
1335 maximum count, the oldest trace file is overwritten. This mechanism is
1336 called _trace file rotation_.
1340 === Instrumentation point, event rule, event, and event record
1342 An _event rule_ is a set of conditions which must be **all** satisfied
1343 for LTTng to record an occuring event.
1345 You set the conditions when you <<enabling-disabling-events,create
1348 You always attach an event rule to <<channel,channel>> when you create
1351 When an event passes the conditions of an event rule, LTTng records it
1352 in one of the attached channel's sub-buffers.
1354 The available conditions, as of LTTng{nbsp}{revision}, are:
1356 * The event rule _is enabled_.
1357 * The instrumentation point's type _is{nbsp}T_.
1358 * The instrumentation point's name (sometimes called _event name_)
1359 _matches{nbsp}N_, but _is not{nbsp}E_.
1360 * The instrumentation point's log level _is as severe as{nbsp}L_, or
1361 _is exactly{nbsp}L_.
1362 * The fields of the event's payload _satisfy_ a filter
1363 expression{nbsp}__F__.
1365 As you can see, all the conditions but the dynamic filter are related to
1366 the event rule's status or to the instrumentation point, not to the
1367 occurring events. This is why, without a filter, checking if an event
1368 passes an event rule is not a dynamic task: when you create or modify an
1369 event rule, all the tracers of its tracing domain enable or disable the
1370 instrumentation points themselves once. This is possible because the
1371 attributes of an instrumentation point (type, name, and log level) are
1372 defined statically. In other words, without a dynamic filter, the tracer
1373 _does not evaluate_ the arguments of an instrumentation point unless it
1374 matches an enabled event rule.
1376 Note that, for LTTng to record an event, the <<channel,channel>> to
1377 which a matching event rule is attached must also be enabled, and the
1378 tracing session owning this channel must be active.
1381 .Logical path from an instrumentation point to an event record.
1382 image::event-rule.png[]
1384 .Event, event record, or event rule?
1386 With so many similar terms, it's easy to get confused.
1388 An **event** is the consequence of the execution of an _instrumentation
1389 point_, like a tracepoint that you manually place in some source code,
1390 or a Linux kernel KProbe. An event is said to _occur_ at a specific
1391 time. Different actions can be taken upon the occurrence of an event,
1392 like record the event's payload to a buffer.
1394 An **event record** is the representation of an event in a sub-buffer. A
1395 tracer is responsible for capturing the payload of an event, current
1396 context variables, the event's ID, and the event's timestamp. LTTng
1397 can append this sub-buffer to a trace file.
1399 An **event rule** is a set of conditions which must all be satisfied for
1400 LTTng to record an occuring event. Events still occur without
1401 satisfying event rules, but LTTng does not record them.
1406 == Components of noch:{LTTng}
1408 The second _T_ in _LTTng_ stands for _toolkit_: it would be wrong
1409 to call LTTng a simple _tool_ since it is composed of multiple
1410 interacting components. This section describes those components,
1411 explains their respective roles, and shows how they connect together to
1412 form the LTTng ecosystem.
1414 The following diagram shows how the most important components of LTTng
1415 interact with user applications, the Linux kernel, and you:
1418 .Control and trace data paths between LTTng components.
1419 image::plumbing.png[]
1421 The LTTng project incorporates:
1423 * **LTTng-tools**: Libraries and command-line interface to
1424 control tracing sessions.
1425 ** <<lttng-sessiond,Session daemon>> (man:lttng-sessiond(8)).
1426 ** <<lttng-consumerd,Consumer daemon>> (cmd:lttng-consumerd).
1427 ** <<lttng-relayd,Relay daemon>> (man:lttng-relayd(8)).
1428 ** <<liblttng-ctl-lttng,Tracing control library>> (`liblttng-ctl`).
1429 ** <<lttng-cli,Tracing control command-line tool>> (man:lttng(1)).
1430 * **LTTng-UST**: Libraries and Java/Python packages to trace user
1432 ** <<lttng-ust,User space tracing library>> (`liblttng-ust`) and its
1433 headers to instrument and trace any native user application.
1434 ** <<prebuilt-ust-helpers,Preloadable user space tracing helpers>>:
1435 *** `liblttng-ust-libc-wrapper`
1436 *** `liblttng-ust-pthread-wrapper`
1437 *** `liblttng-ust-cyg-profile`
1438 *** `liblttng-ust-cyg-profile-fast`
1439 *** `liblttng-ust-dl`
1440 ** User space tracepoint provider source files generator command-line
1441 tool (man:lttng-gen-tp(1)).
1442 ** <<lttng-ust-agents,LTTng-UST Java agent>> to instrument and trace
1443 Java applications using `java.util.logging` or
1444 Apache log4j 1.2 logging.
1445 ** <<lttng-ust-agents,LTTng-UST Python agent>> to instrument
1446 Python applications using the standard `logging` package.
1447 * **LTTng-modules**: <<lttng-modules,Linux kernel modules>> to trace
1449 ** LTTng kernel tracer module.
1450 ** Tracing ring buffer kernel modules.
1451 ** Probe kernel modules.
1452 ** LTTng logger kernel module.
1456 === Tracing control command-line interface
1459 .The tracing control command-line interface.
1460 image::plumbing-lttng-cli.png[]
1462 The _man:lttng(1) command-line tool_ is the standard user interface to
1463 control LTTng <<tracing-session,tracing sessions>>. The cmd:lttng tool
1464 is part of LTTng-tools.
1466 The cmd:lttng tool is linked with
1467 <<liblttng-ctl-lttng,`liblttng-ctl`>> to communicate with
1468 one or more <<lttng-sessiond,session daemons>> behind the scenes.
1470 The cmd:lttng tool has a Git-like interface:
1474 $ lttng <GENERAL OPTIONS> <COMMAND> <COMMAND OPTIONS>
1477 The <<controlling-tracing,Tracing control>> section explores the
1478 available features of LTTng using the cmd:lttng tool.
1481 [[liblttng-ctl-lttng]]
1482 === Tracing control library
1485 .The tracing control library.
1486 image::plumbing-liblttng-ctl.png[]
1488 The _LTTng control library_, `liblttng-ctl`, is used to communicate
1489 with a <<lttng-sessiond,session daemon>> using a C API that hides the
1490 underlying protocol's details. `liblttng-ctl` is part of LTTng-tools.
1492 The <<lttng-cli,cmd:lttng command-line tool>>
1493 is linked with `liblttng-ctl`.
1495 You can use `liblttng-ctl` in C or $$C++$$ source code by including its
1500 #include <lttng/lttng.h>
1503 Some objects are referenced by name (C string), such as tracing
1504 sessions, but most of them require to create a handle first using
1505 `lttng_create_handle()`.
1507 The best available developer documentation for `liblttng-ctl` is, as of
1508 LTTng{nbsp}{revision}, its installed header files. Every function and
1509 structure is thoroughly documented.
1513 === User space tracing library
1516 .The user space tracing library.
1517 image::plumbing-liblttng-ust.png[]
1519 The _user space tracing library_, `liblttng-ust` (see man:lttng-ust(3)),
1520 is the LTTng user space tracer. It receives commands from a
1521 <<lttng-sessiond,session daemon>>, for example to
1522 enable and disable specific instrumentation points, and writes event
1523 records to ring buffers shared with a
1524 <<lttng-consumerd,consumer daemon>>.
1525 `liblttng-ust` is part of LTTng-UST.
1527 Public C header files are installed beside `liblttng-ust` to
1528 instrument any <<c-application,C or $$C++$$ application>>.
1530 <<lttng-ust-agents,LTTng-UST agents>>, which are regular Java and Python
1531 packages, use their own library providing tracepoints which is
1532 linked with `liblttng-ust`.
1534 An application or library does not have to initialize `liblttng-ust`
1535 manually: its constructor does the necessary tasks to properly register
1536 to a session daemon. The initialization phase also enables the
1537 instrumentation points matching the <<event,event rules>> that you
1541 [[lttng-ust-agents]]
1542 === User space tracing agents
1545 .The user space tracing agents.
1546 image::plumbing-lttng-ust-agents.png[]
1548 The _LTTng-UST Java and Python agents_ are regular Java and Python
1549 packages which add LTTng tracing capabilities to the
1550 native logging frameworks. The LTTng-UST agents are part of LTTng-UST.
1552 In the case of Java, the
1553 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[`java.util.logging`
1554 core logging facilities] and
1555 https://logging.apache.org/log4j/1.2/[Apache log4j 1.2] are supported.
1556 Note that Apache Log4{nbsp}2 is not supported.
1558 In the case of Python, the standard
1559 https://docs.python.org/3/library/logging.html[`logging`] package
1560 is supported. Both Python 2 and Python 3 modules can import the
1561 LTTng-UST Python agent package.
1563 The applications using the LTTng-UST agents are in the
1564 `java.util.logging` (JUL),
1565 log4j, and Python <<domain,tracing domains>>.
1567 Both agents use the same mechanism to trace the log statements. When an
1568 agent is initialized, it creates a log handler that attaches to the root
1569 logger. The agent also registers to a <<lttng-sessiond,session daemon>>.
1570 When the application executes a log statement, it is passed to the
1571 agent's log handler by the root logger. The agent's log handler calls a
1572 native function in a tracepoint provider package shared library linked
1573 with <<lttng-ust,`liblttng-ust`>>, passing the formatted log message and
1574 other fields, like its logger name and its log level. This native
1575 function contains a user space instrumentation point, hence tracing the
1578 The log level condition of an
1579 <<event,event rule>> is considered when tracing
1580 a Java or a Python application, and it's compatible with the standard
1581 JUL, log4j, and Python log levels.
1585 === LTTng kernel modules
1588 .The LTTng kernel modules.
1589 image::plumbing-lttng-modules.png[]
1591 The _LTTng kernel modules_ are a set of Linux kernel modules
1592 which implement the kernel tracer of the LTTng project. The LTTng
1593 kernel modules are part of LTTng-modules.
1595 The LTTng kernel modules include:
1597 * A set of _probe_ modules.
1599 Each module attaches to a specific subsystem
1600 of the Linux kernel using its tracepoint instrument points. There are
1601 also modules to attach to the entry and return points of the Linux
1602 system call functions.
1604 * _Ring buffer_ modules.
1606 A ring buffer implementation is provided as kernel modules. The LTTng
1607 kernel tracer writes to the ring buffer; a
1608 <<lttng-consumerd,consumer daemon>> reads from the ring buffer.
1610 * The _LTTng kernel tracer_ module.
1611 * The _LTTng logger_ module.
1613 The LTTng logger module implements the special path:{/proc/lttng-logger}
1614 file so that any executable can generate LTTng events by opening and
1615 writing to this file.
1617 See <<proc-lttng-logger-abi,LTTng logger>>.
1619 Generally, you do not have to load the LTTng kernel modules manually
1620 (using man:modprobe(8), for example): a root <<lttng-sessiond,session
1621 daemon>> loads the necessary modules when starting. If you have extra
1622 probe modules, you can specify to load them to the session daemon on
1625 The LTTng kernel modules are installed in
1626 +/usr/lib/modules/__release__/extra+ by default, where +__release__+ is
1627 the kernel release (see `uname --kernel-release`).
1634 .The session daemon.
1635 image::plumbing-sessiond.png[]
1637 The _session daemon_, man:lttng-sessiond(8), is a daemon responsible for
1638 managing tracing sessions and for controlling the various components of
1639 LTTng. The session daemon is part of LTTng-tools.
1641 The session daemon sends control requests to and receives control
1644 * The <<lttng-ust,user space tracing library>>.
1646 Any instance of the user space tracing library first registers to
1647 a session daemon. Then, the session daemon can send requests to
1648 this instance, such as:
1651 ** Get the list of tracepoints.
1652 ** Share an <<event,event rule>> so that the user space tracing library
1653 can enable or disable tracepoints. Amongst the possible conditions
1654 of an event rule is a filter expression which `liblttng-ust` evalutes
1655 when an event occurs.
1656 ** Share <<channel,channel>> attributes and ring buffer locations.
1659 The session daemon and the user space tracing library use a Unix
1660 domain socket for their communication.
1662 * The <<lttng-ust-agents,user space tracing agents>>.
1664 Any instance of a user space tracing agent first registers to
1665 a session daemon. Then, the session daemon can send requests to
1666 this instance, such as:
1669 ** Get the list of loggers.
1670 ** Enable or disable a specific logger.
1673 The session daemon and the user space tracing agent use a TCP connection
1674 for their communication.
1676 * The <<lttng-modules,LTTng kernel tracer>>.
1677 * The <<lttng-consumerd,consumer daemon>>.
1679 The session daemon sends requests to the consumer daemon to instruct
1680 it where to send the trace data streams, amongst other information.
1682 * The <<lttng-relayd,relay daemon>>.
1684 The session daemon receives commands from the
1685 <<liblttng-ctl-lttng,tracing control library>>.
1687 The root session daemon loads the appropriate
1688 <<lttng-modules,LTTng kernel modules>> on startup. It also spawns
1689 a <<lttng-consumerd,consumer daemon>> as soon as you create
1690 an <<event,event rule>>.
1692 The session daemon does not send and receive trace data: this is the
1693 role of the <<lttng-consumerd,consumer daemon>> and
1694 <<lttng-relayd,relay daemon>>. It does, however, generate the
1695 http://diamon.org/ctf/[CTF] metadata stream.
1697 Each Unix user can have its own session daemon instance. The
1698 tracing sessions managed by different session daemons are completely
1701 The root user's session daemon is the only one which is
1702 allowed to control the LTTng kernel tracer, and its spawned consumer
1703 daemon is the only one which is allowed to consume trace data from the
1704 LTTng kernel tracer. Note, however, that any Unix user which is a member
1705 of the <<tracing-group,tracing group>> is allowed
1706 to create <<channel,channels>> in the
1707 Linux kernel <<domain,tracing domain>>, and thus to trace the Linux
1710 The <<lttng-cli,cmd:lttng command-line tool>> automatically starts a
1711 session daemon when using its `create` command if none is currently
1712 running. You can also start the session daemon manually.
1719 .The consumer daemon.
1720 image::plumbing-consumerd.png[]
1722 The _consumer daemon_, cmd:lttng-consumerd, is a daemon which shares
1723 ring buffers with user applications or with the LTTng kernel modules to
1724 collect trace data and send it to some location (on disk or to a
1725 <<lttng-relayd,relay daemon>> over the network). The consumer daemon
1726 is part of LTTng-tools.
1728 You do not start a consumer daemon manually: a consumer daemon is always
1729 spawned by a <<lttng-sessiond,session daemon>> as soon as you create an
1730 <<event,event rule>>, that is, before you start tracing. When you kill
1731 its owner session daemon, the consumer daemon also exits because it is
1732 the session daemon's child process. Command-line options of
1733 man:lttng-sessiond(8) target the consumer daemon process.
1735 There are up to two running consumer daemons per Unix user, whereas only
1736 one session daemon can run per user. This is because each process can be
1737 either 32-bit or 64-bit: if the target system runs a mixture of 32-bit
1738 and 64-bit processes, it is more efficient to have separate
1739 corresponding 32-bit and 64-bit consumer daemons. The root user is an
1740 exception: it can have up to _three_ running consumer daemons: 32-bit
1741 and 64-bit instances for its user applications, and one more
1742 reserved for collecting kernel trace data.
1750 image::plumbing-relayd.png[]
1752 The _relay daemon_, man:lttng-relayd(8), is a daemon acting as a bridge
1753 between remote session and consumer daemons, local trace files, and a
1754 remote live trace viewer. The relay daemon is part of LTTng-tools.
1756 The main purpose of the relay daemon is to implement a receiver of
1757 <<sending-trace-data-over-the-network,trace data over the network>>.
1758 This is useful when the target system does not have much file system
1759 space to record trace files locally.
1761 The relay daemon is also a server to which a
1762 <<lttng-live,live trace viewer>> can
1763 connect. The live trace viewer sends requests to the relay daemon to
1764 receive trace data as the target system emits events. The
1765 communication protocol is named _LTTng live_; it is used over TCP
1768 Note that you can start the relay daemon on the target system directly.
1769 This is the setup of choice when the use case is to view events as
1770 the target system emits them without the need of a remote system.
1774 == [[using-lttng]]Instrumentation
1776 There are many examples of tracing and monitoring in our everyday life:
1778 * You have access to real-time and historical weather reports and
1779 forecasts thanks to weather stations installed around the country.
1780 * You know your heart is safe thanks to an electrocardiogram.
1781 * You make sure not to drive your car too fast and to have enough fuel
1782 to reach your destination thanks to gauges visible on your dashboard.
1784 All the previous examples have something in common: they rely on
1785 **instruments**. Without the electrodes attached to the surface of your
1786 body's skin, cardiac monitoring is futile.
1788 LTTng, as a tracer, is no different from those real life examples. If
1789 you're about to trace a software system or, in other words, record its
1790 history of execution, you better have **instrumentation points** in the
1791 subject you're tracing, that is, the actual software.
1793 Various ways were developed to instrument a piece of software for LTTng
1794 tracing. The most straightforward one is to manually place
1795 instrumentation points, called _tracepoints_, in the software's source
1796 code. It is also possible to add instrumentation points dynamically in
1797 the Linux kernel <<domain,tracing domain>>.
1799 If you're only interested in tracing the Linux kernel, your
1800 instrumentation needs are probably already covered by LTTng's built-in
1801 <<lttng-modules,Linux kernel tracepoints>>. You may also wish to trace a
1802 user application which is already instrumented for LTTng tracing.
1803 In such cases, you can skip this whole section and read the topics of
1804 the <<controlling-tracing,Tracing control>> section.
1806 Many methods are available to instrument a piece of software for LTTng
1809 * <<c-application,User space instrumentation for C and $$C++$$
1811 * <<prebuilt-ust-helpers,Prebuilt user space tracing helpers>>.
1812 * <<java-application,User space Java agent>>.
1813 * <<python-application,User space Python agent>>.
1814 * <<proc-lttng-logger-abi,LTTng logger>>.
1815 * <<instrumenting-linux-kernel,LTTng kernel tracepoints>>.
1819 === [[cxx-application]]User space instrumentation for C and $$C++$$ applications
1821 The procedure to instrument a C or $$C++$$ user application with
1822 the <<lttng-ust,LTTng user space tracing library>>, `liblttng-ust`, is:
1824 . <<tracepoint-provider,Create the source files of a tracepoint provider
1826 . <<probing-the-application-source-code,Add tracepoints to
1827 the application's source code>>.
1828 . <<building-tracepoint-providers-and-user-application,Build and link
1829 a tracepoint provider package and the user application>>.
1831 If you need quick, man:printf(3)-like instrumentation, you can skip
1832 those steps and use <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>>
1835 IMPORTANT: You need to <<installing-lttng,install>> LTTng-UST to
1836 instrument a user application with `liblttng-ust`.
1839 [[tracepoint-provider]]
1840 ==== Create the source files of a tracepoint provider package
1842 A _tracepoint provider_ is a set of compiled functions which provide
1843 **tracepoints** to an application, the type of instrumentation point
1844 supported by LTTng-UST. Those functions can emit events with
1845 user-defined fields and serialize those events as event records to one
1846 or more LTTng-UST <<channel,channel>> sub-buffers. The `tracepoint()`
1847 macro, which you <<probing-the-application-source-code,insert in a user
1848 application's source code>>, calls those functions.
1850 A _tracepoint provider package_ is an object file (`.o`) or a shared
1851 library (`.so`) which contains one or more tracepoint providers.
1852 Its source files are:
1854 * One or more <<tpp-header,tracepoint provider header>> (`.h`).
1855 * A <<tpp-source,tracepoint provider package source>> (`.c`).
1857 A tracepoint provider package is dynamically linked with `liblttng-ust`,
1858 the LTTng user space tracer, at run time.
1861 .User application linked with `liblttng-ust` and containing a tracepoint provider.
1862 image::ust-app.png[]
1864 NOTE: If you need quick, man:printf(3)-like instrumentation, you can
1865 skip creating and using a tracepoint provider and use
1866 <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>> instead.
1870 ===== Create a tracepoint provider header file template
1872 A _tracepoint provider header file_ contains the tracepoint
1873 definitions of a tracepoint provider.
1875 To create a tracepoint provider header file:
1877 . Start from this template:
1881 .Tracepoint provider header file template (`.h` file extension).
1883 #undef TRACEPOINT_PROVIDER
1884 #define TRACEPOINT_PROVIDER provider_name
1886 #undef TRACEPOINT_INCLUDE
1887 #define TRACEPOINT_INCLUDE "./tp.h"
1889 #if !defined(_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
1892 #include <lttng/tracepoint.h>
1895 * Use TRACEPOINT_EVENT(), TRACEPOINT_EVENT_CLASS(),
1896 * TRACEPOINT_EVENT_INSTANCE(), and TRACEPOINT_LOGLEVEL() here.
1901 #include <lttng/tracepoint-event.h>
1907 * `provider_name` with the name of your tracepoint provider.
1908 * `"tp.h"` with the name of your tracepoint provider header file.
1910 . Below the `#include <lttng/tracepoint.h>` line, put your
1911 <<defining-tracepoints,tracepoint definitions>>.
1913 Your tracepoint provider name must be unique amongst all the possible
1914 tracepoint provider names used on the same target system. We
1915 suggest to include the name of your project or company in the name,
1916 for example, `org_lttng_my_project_tpp`.
1918 TIP: [[lttng-gen-tp]]You can use the man:lttng-gen-tp(1) tool to create
1919 this boilerplate for you. When using cmd:lttng-gen-tp, all you need to
1920 write are the <<defining-tracepoints,tracepoint definitions>>.
1923 [[defining-tracepoints]]
1924 ===== Create a tracepoint definition
1926 A _tracepoint definition_ defines, for a given tracepoint:
1928 * Its **input arguments**. They are the macro parameters that the
1929 `tracepoint()` macro accepts for this particular tracepoint
1930 in the user application's source code.
1931 * Its **output event fields**. They are the sources of event fields
1932 that form the payload of any event that the execution of the
1933 `tracepoint()` macro emits for this particular tracepoint.
1935 You can create a tracepoint definition by using the
1936 `TRACEPOINT_EVENT()` macro below the `#include <lttng/tracepoint.h>`
1938 <<tpp-header,tracepoint provider header file template>>.
1940 The syntax of the `TRACEPOINT_EVENT()` macro is:
1943 .`TRACEPOINT_EVENT()` macro syntax.
1946 /* Tracepoint provider name */
1949 /* Tracepoint name */
1952 /* Input arguments */
1957 /* Output event fields */
1966 * `provider_name` with your tracepoint provider name.
1967 * `tracepoint_name` with your tracepoint name.
1968 * `arguments` with the <<tpp-def-input-args,input arguments>>.
1969 * `fields` with the <<tpp-def-output-fields,output event field>>
1972 This tracepoint emits events named `provider_name:tracepoint_name`.
1975 .Event name's length limitation
1977 The concatenation of the tracepoint provider name and the
1978 tracepoint name must not exceed **254 characters**. If it does, the
1979 instrumented application compiles and runs, but LTTng throws multiple
1980 warnings and you could experience serious issues.
1983 [[tpp-def-input-args]]The syntax of the `TP_ARGS()` macro is:
1986 .`TP_ARGS()` macro syntax.
1995 * `type` with the C type of the argument.
1996 * `arg_name` with the argument name.
1998 You can repeat `type` and `arg_name` up to 10 times to have
1999 more than one argument.
2001 .`TP_ARGS()` usage with three arguments.
2013 The `TP_ARGS()` and `TP_ARGS(void)` forms are valid to create a
2014 tracepoint definition with no input arguments.
2016 [[tpp-def-output-fields]]The `TP_FIELDS()` macro contains a list of
2017 `ctf_*()` macros. Each `ctf_*()` macro defines one event field. See
2018 man:lttng-ust(3) for a complete description of the available `ctf_*()`
2019 macros. A `ctf_*()` macro specifies the type, size, and byte order of
2022 Each `ctf_*()` macro takes an _argument expression_ parameter. This is a
2023 C expression that the tracer evalutes at the `tracepoint()` macro site
2024 in the application's source code. This expression provides a field's
2025 source of data. The argument expression can include input argument names
2026 listed in the `TP_ARGS()` macro.
2028 Each `ctf_*()` macro also takes a _field name_ parameter. Field names
2029 must be unique within a given tracepoint definition.
2031 Here's a complete tracepoint definition example:
2033 .Tracepoint definition.
2035 The following tracepoint definition defines a tracepoint which takes
2036 three input arguments and has four output event fields.
2040 #include "my-custom-structure.h"
2046 const struct my_custom_structure*, my_custom_structure,
2051 ctf_string(query_field, query)
2052 ctf_float(double, ratio_field, ratio)
2053 ctf_integer(int, recv_size, my_custom_structure->recv_size)
2054 ctf_integer(int, send_size, my_custom_structure->send_size)
2059 You can refer to this tracepoint definition with the `tracepoint()`
2060 macro in your application's source code like this:
2064 tracepoint(my_provider, my_tracepoint,
2065 my_structure, some_ratio, the_query);
2069 NOTE: The LTTng tracer only evaluates tracepoint arguments at run time
2070 if they satisfy an enabled <<event,event rule>>.
2073 [[using-tracepoint-classes]]
2074 ===== Use a tracepoint class
2076 A _tracepoint class_ is a class of tracepoints which share the same
2077 output event field definitions. A _tracepoint instance_ is one
2078 instance of such a defined tracepoint class, with its own tracepoint
2081 The <<defining-tracepoints,`TRACEPOINT_EVENT()` macro>> is actually a
2082 shorthand which defines both a tracepoint class and a tracepoint
2083 instance at the same time.
2085 When you build a tracepoint provider package, the C or $$C++$$ compiler
2086 creates one serialization function for each **tracepoint class**. A
2087 serialization function is responsible for serializing the event fields
2088 of a tracepoint to a sub-buffer when tracing.
2090 For various performance reasons, when your situation requires multiple
2091 tracepoint definitions with different names, but with the same event
2092 fields, we recommend that you manually create a tracepoint class
2093 and instantiate as many tracepoint instances as needed. One positive
2094 effect of such a design, amongst other advantages, is that all
2095 tracepoint instances of the same tracepoint class reuse the same
2096 serialization function, thus reducing
2097 https://en.wikipedia.org/wiki/Cache_pollution[cache pollution].
2099 .Use a tracepoint class and tracepoint instances.
2101 Consider the following three tracepoint definitions:
2113 ctf_integer(int, userid, userid)
2114 ctf_integer(size_t, len, len)
2126 ctf_integer(int, userid, userid)
2127 ctf_integer(size_t, len, len)
2139 ctf_integer(int, userid, userid)
2140 ctf_integer(size_t, len, len)
2145 In this case, we create three tracepoint classes, with one implicit
2146 tracepoint instance for each of them: `get_account`, `get_settings`, and
2147 `get_transaction`. However, they all share the same event field names
2148 and types. Hence three identical, yet independent serialization
2149 functions are created when you build the tracepoint provider package.
2151 A better design choice is to define a single tracepoint class and three
2152 tracepoint instances:
2156 /* The tracepoint class */
2157 TRACEPOINT_EVENT_CLASS(
2158 /* Tracepoint provider name */
2161 /* Tracepoint class name */
2164 /* Input arguments */
2170 /* Output event fields */
2172 ctf_integer(int, userid, userid)
2173 ctf_integer(size_t, len, len)
2177 /* The tracepoint instances */
2178 TRACEPOINT_EVENT_INSTANCE(
2179 /* Tracepoint provider name */
2182 /* Tracepoint class name */
2185 /* Tracepoint name */
2188 /* Input arguments */
2194 TRACEPOINT_EVENT_INSTANCE(
2203 TRACEPOINT_EVENT_INSTANCE(
2216 [[assigning-log-levels]]
2217 ===== Assign a log level to a tracepoint definition
2219 You can assign an optional _log level_ to a
2220 <<defining-tracepoints,tracepoint definition>>.
2222 Assigning different levels of severity to tracepoint definitions can
2223 be useful: when you <<enabling-disabling-events,create an event rule>>,
2224 you can target tracepoints having a log level as severe as a specific
2227 The concept of LTTng-UST log levels is similar to the levels found
2228 in typical logging frameworks:
2230 * In a logging framework, the log level is given by the function
2231 or method name you use at the log statement site: `debug()`,
2232 `info()`, `warn()`, `error()`, and so on.
2233 * In LTTng-UST, you statically assign the log level to a tracepoint
2234 definition; any `tracepoint()` macro invocation which refers to
2235 this definition has this log level.
2237 You can assign a log level to a tracepoint definition with the
2238 `TRACEPOINT_LOGLEVEL()` macro. You must use this macro _after_ the
2239 <<defining-tracepoints,`TRACEPOINT_EVENT()`>> or
2240 <<using-tracepoint-classes,`TRACEPOINT_INSTANCE()`>> macro for a given
2243 The syntax of the `TRACEPOINT_LOGLEVEL()` macro is:
2246 .`TRACEPOINT_LOGLEVEL()` macro syntax.
2248 TRACEPOINT_LOGLEVEL(provider_name, tracepoint_name, log_level)
2253 * `provider_name` with the tracepoint provider name.
2254 * `tracepoint_name` with the tracepoint name.
2255 * `log_level` with the log level to assign to the tracepoint
2256 definition named `tracepoint_name` in the `provider_name`
2257 tracepoint provider.
2259 See man:lttng-ust(3) for a list of available log level names.
2261 .Assign the `TRACE_DEBUG_UNIT` log level to a tracepoint definition.
2265 /* Tracepoint definition */
2274 ctf_integer(int, userid, userid)
2275 ctf_integer(size_t, len, len)
2279 /* Log level assignment */
2280 TRACEPOINT_LOGLEVEL(my_app, get_transaction, TRACE_DEBUG_UNIT)
2286 ===== Create a tracepoint provider package source file
2288 A _tracepoint provider package source file_ is a C source file which
2289 includes a <<tpp-header,tracepoint provider header file>> to expand its
2290 macros into event serialization and other functions.
2292 You can always use the following tracepoint provider package source
2296 .Tracepoint provider package source file template.
2298 #define TRACEPOINT_CREATE_PROBES
2303 Replace `tp.h` with the name of your <<tpp-header,tracepoint provider
2304 header file>> name. You may also include more than one tracepoint
2305 provider header file here to create a tracepoint provider package
2306 holding more than one tracepoint providers.
2309 [[probing-the-application-source-code]]
2310 ==== Add tracepoints to an application's source code
2312 Once you <<tpp-header,create a tracepoint provider header file>>, you
2313 can use the `tracepoint()` macro in your application's
2314 source code to insert the tracepoints that this header
2315 <<defining-tracepoints,defines>>.
2317 The `tracepoint()` macro takes at least two parameters: the tracepoint
2318 provider name and the tracepoint name. The corresponding tracepoint
2319 definition defines the other parameters.
2321 .`tracepoint()` usage.
2323 The following <<defining-tracepoints,tracepoint definition>> defines a
2324 tracepoint which takes two input arguments and has two output event
2328 .Tracepoint provider header file.
2330 #include "my-custom-structure.h"
2337 const char*, cmd_name
2340 ctf_string(cmd_name, cmd_name)
2341 ctf_integer(int, number_of_args, argc)
2346 You can refer to this tracepoint definition with the `tracepoint()`
2347 macro in your application's source code like this:
2350 .Application's source file.
2354 int main(int argc, char* argv[])
2356 tracepoint(my_provider, my_tracepoint, argc, argv[0]);
2362 Note how the application's source code includes
2363 the tracepoint provider header file containing the tracepoint
2364 definitions to use, path:{tp.h}.
2367 .`tracepoint()` usage with a complex tracepoint definition.
2369 Consider this complex tracepoint definition, where multiple event
2370 fields refer to the same input arguments in their argument expression
2374 .Tracepoint provider header file.
2376 /* For `struct stat` */
2377 #include <sys/types.h>
2378 #include <sys/stat.h>
2390 ctf_integer(int, my_constant_field, 23 + 17)
2391 ctf_integer(int, my_int_arg_field, my_int_arg)
2392 ctf_integer(int, my_int_arg_field2, my_int_arg * my_int_arg)
2393 ctf_integer(int, sum4_field, my_str_arg[0] + my_str_arg[1] +
2394 my_str_arg[2] + my_str_arg[3])
2395 ctf_string(my_str_arg_field, my_str_arg)
2396 ctf_integer_hex(off_t, size_field, st->st_size)
2397 ctf_float(double, size_dbl_field, (double) st->st_size)
2398 ctf_sequence_text(char, half_my_str_arg_field, my_str_arg,
2399 size_t, strlen(my_str_arg) / 2)
2404 You can refer to this tracepoint definition with the `tracepoint()`
2405 macro in your application's source code like this:
2408 .Application's source file.
2410 #define TRACEPOINT_DEFINE
2417 stat("/etc/fstab", &s);
2418 tracepoint(my_provider, my_tracepoint, 23, "Hello, World!", &s);
2424 If you look at the event record that LTTng writes when tracing this
2425 program, assuming the file size of path:{/etc/fstab} is 301{nbsp}bytes,
2426 it should look like this:
2428 .Event record fields
2430 |Field's name |Field's value
2431 |`my_constant_field` |40
2432 |`my_int_arg_field` |23
2433 |`my_int_arg_field2` |529
2435 |`my_str_arg_field` |`Hello, World!`
2436 |`size_field` |0x12d
2437 |`size_dbl_field` |301.0
2438 |`half_my_str_arg_field` |`Hello,`
2442 Sometimes, the arguments you pass to `tracepoint()` are expensive to
2443 compute--they use the call stack, for example. To avoid this
2444 computation when the tracepoint is disabled, you can use the
2445 `tracepoint_enabled()` and `do_tracepoint()` macros.
2447 The syntax of the `tracepoint_enabled()` and `do_tracepoint()` macros
2451 .`tracepoint_enabled()` and `do_tracepoint()` macros syntax.
2453 tracepoint_enabled(provider_name, tracepoint_name)
2454 do_tracepoint(provider_name, tracepoint_name, ...)
2459 * `provider_name` with the tracepoint provider name.
2460 * `tracepoint_name` with the tracepoint name.
2462 `tracepoint_enabled()` returns a non-zero value if the tracepoint named
2463 `tracepoint_name` from the provider named `provider_name` is enabled
2466 `do_tracepoint()` is like `tracepoint()`, except that it doesn't check
2467 if the tracepoint is enabled. Using `tracepoint()` with
2468 `tracepoint_enabled()` is dangerous since `tracepoint()` also contains
2469 the `tracepoint_enabled()` check, thus a race condition is
2470 possible in this situation:
2473 .Possible race condition when using `tracepoint_enabled()` with `tracepoint()`.
2475 if (tracepoint_enabled(my_provider, my_tracepoint)) {
2476 stuff = prepare_stuff();
2479 tracepoint(my_provider, my_tracepoint, stuff);
2482 If the tracepoint is enabled after the condition, then `stuff` is not
2483 prepared: the emitted event will either contain wrong data, or the whole
2484 application could crash (segmentation fault, for example).
2486 NOTE: Neither `tracepoint_enabled()` nor `do_tracepoint()` have an
2487 `STAP_PROBEV()` call. If you need it, you must emit
2491 [[building-tracepoint-providers-and-user-application]]
2492 ==== Build and link a tracepoint provider package and an application
2494 Once you have one or more <<tpp-header,tracepoint provider header
2495 files>> and a <<tpp-source,tracepoint provider package source file>>,
2496 you can create the tracepoint provider package by compiling its source
2497 file. From here, multiple build and run scenarios are possible. The
2498 following table shows common application and library configurations
2499 along with the required command lines to achieve them.
2501 In the following diagrams, we use the following file names:
2504 Executable application.
2507 Application's object file.
2510 Tracepoint provider package object file.
2513 Tracepoint provider package archive file.
2516 Tracepoint provider package shared object file.
2519 User library object file.
2522 User library shared object file.
2524 We use the following symbols in the diagrams of table below:
2527 .Symbols used in the build scenario diagrams.
2528 image::ust-sit-symbols.png[]
2530 We assume that path:{.} is part of the env:LD_LIBRARY_PATH environment
2531 variable in the following instructions.
2533 [role="growable ust-scenarios",cols="asciidoc,asciidoc"]
2534 .Common tracepoint provider package scenarios.
2536 |Scenario |Instructions
2539 The instrumented application is statically linked with
2540 the tracepoint provider package object.
2542 image::ust-sit+app-linked-with-tp-o+app-instrumented.png[]
2545 include::../common/ust-sit-step-tp-o.txt[]
2547 To build the instrumented application:
2549 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2554 #define TRACEPOINT_DEFINE
2558 . Compile the application source file:
2567 . Build the application:
2572 $ gcc -o app app.o tpp.o -llttng-ust -ldl
2576 To run the instrumented application:
2578 * Start the application:
2588 The instrumented application is statically linked with the
2589 tracepoint provider package archive file.
2591 image::ust-sit+app-linked-with-tp-a+app-instrumented.png[]
2594 To create the tracepoint provider package archive file:
2596 . Compile the <<tpp-source,tracepoint provider package source file>>:
2605 . Create the tracepoint provider package archive file:
2610 $ ar rcs tpp.a tpp.o
2614 To build the instrumented application:
2616 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2621 #define TRACEPOINT_DEFINE
2625 . Compile the application source file:
2634 . Build the application:
2639 $ gcc -o app app.o tpp.a -llttng-ust -ldl
2643 To run the instrumented application:
2645 * Start the application:
2655 The instrumented application is linked with the tracepoint provider
2656 package shared object.
2658 image::ust-sit+app-linked-with-tp-so+app-instrumented.png[]
2661 include::../common/ust-sit-step-tp-so.txt[]
2663 To build the instrumented application:
2665 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2670 #define TRACEPOINT_DEFINE
2674 . Compile the application source file:
2683 . Build the application:
2688 $ gcc -o app app.o -ldl -L. -ltpp
2692 To run the instrumented application:
2694 * Start the application:
2704 The tracepoint provider package shared object is preloaded before the
2705 instrumented application starts.
2707 image::ust-sit+tp-so-preloaded+app-instrumented.png[]
2710 include::../common/ust-sit-step-tp-so.txt[]
2712 To build the instrumented application:
2714 . In path:{app.c}, before including path:{tpp.h}, add the
2720 #define TRACEPOINT_DEFINE
2721 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
2725 . Compile the application source file:
2734 . Build the application:
2739 $ gcc -o app app.o -ldl
2743 To run the instrumented application with tracing support:
2745 * Preload the tracepoint provider package shared object and
2746 start the application:
2751 $ LD_PRELOAD=./libtpp.so ./app
2755 To run the instrumented application without tracing support:
2757 * Start the application:
2767 The instrumented application dynamically loads the tracepoint provider
2768 package shared object.
2770 See the <<dlclose-warning,warning about `dlclose()`>>.
2772 image::ust-sit+app-dlopens-tp-so+app-instrumented.png[]
2775 include::../common/ust-sit-step-tp-so.txt[]
2777 To build the instrumented application:
2779 . In path:{app.c}, before including path:{tpp.h}, add the
2785 #define TRACEPOINT_DEFINE
2786 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
2790 . Compile the application source file:
2799 . Build the application:
2804 $ gcc -o app app.o -ldl
2808 To run the instrumented application:
2810 * Start the application:
2820 The application is linked with the instrumented user library.
2822 The instrumented user library is statically linked with the tracepoint
2823 provider package object file.
2825 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-o+lib-instrumented.png[]
2828 include::../common/ust-sit-step-tp-o-fpic.txt[]
2830 To build the instrumented user library:
2832 . In path:{emon.c}, before including path:{tpp.h}, add the
2838 #define TRACEPOINT_DEFINE
2842 . Compile the user library source file:
2847 $ gcc -I. -fpic -c emon.c
2851 . Build the user library shared object:
2856 $ gcc -shared -o libemon.so emon.o tpp.o -llttng-ust -ldl
2860 To build the application:
2862 . Compile the application source file:
2871 . Build the application:
2876 $ gcc -o app app.o -L. -lemon
2880 To run the application:
2882 * Start the application:
2892 The application is linked with the instrumented user library.
2894 The instrumented user library is linked with the tracepoint provider
2895 package shared object.
2897 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-so+lib-instrumented.png[]
2900 include::../common/ust-sit-step-tp-so.txt[]
2902 To build the instrumented user library:
2904 . In path:{emon.c}, before including path:{tpp.h}, add the
2910 #define TRACEPOINT_DEFINE
2914 . Compile the user library source file:
2919 $ gcc -I. -fpic -c emon.c
2923 . Build the user library shared object:
2928 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
2932 To build the application:
2934 . Compile the application source file:
2943 . Build the application:
2948 $ gcc -o app app.o -L. -lemon
2952 To run the application:
2954 * Start the application:
2964 The tracepoint provider package shared object is preloaded before the
2967 The application is linked with the instrumented user library.
2969 image::ust-sit+tp-so-preloaded+app-linked-with-lib+lib-instrumented.png[]
2972 include::../common/ust-sit-step-tp-so.txt[]
2974 To build the instrumented user library:
2976 . In path:{emon.c}, before including path:{tpp.h}, add the
2982 #define TRACEPOINT_DEFINE
2983 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
2987 . Compile the user library source file:
2992 $ gcc -I. -fpic -c emon.c
2996 . Build the user library shared object:
3001 $ gcc -shared -o libemon.so emon.o -ldl
3005 To build the application:
3007 . Compile the application source file:
3016 . Build the application:
3021 $ gcc -o app app.o -L. -lemon
3025 To run the application with tracing support:
3027 * Preload the tracepoint provider package shared object and
3028 start the application:
3033 $ LD_PRELOAD=./libtpp.so ./app
3037 To run the application without tracing support:
3039 * Start the application:
3049 The application is linked with the instrumented user library.
3051 The instrumented user library dynamically loads the tracepoint provider
3052 package shared object.
3054 See the <<dlclose-warning,warning about `dlclose()`>>.
3056 image::ust-sit+app-linked-with-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3059 include::../common/ust-sit-step-tp-so.txt[]
3061 To build the instrumented user library:
3063 . In path:{emon.c}, before including path:{tpp.h}, add the
3069 #define TRACEPOINT_DEFINE
3070 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3074 . Compile the user library source file:
3079 $ gcc -I. -fpic -c emon.c
3083 . Build the user library shared object:
3088 $ gcc -shared -o libemon.so emon.o -ldl
3092 To build the application:
3094 . Compile the application source file:
3103 . Build the application:
3108 $ gcc -o app app.o -L. -lemon
3112 To run the application:
3114 * Start the application:
3124 The application dynamically loads the instrumented user library.
3126 The instrumented user library is linked with the tracepoint provider
3127 package shared object.
3129 See the <<dlclose-warning,warning about `dlclose()`>>.
3131 image::ust-sit+app-dlopens-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3134 include::../common/ust-sit-step-tp-so.txt[]
3136 To build the instrumented user library:
3138 . In path:{emon.c}, before including path:{tpp.h}, add the
3144 #define TRACEPOINT_DEFINE
3148 . Compile the user library source file:
3153 $ gcc -I. -fpic -c emon.c
3157 . Build the user library shared object:
3162 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3166 To build the application:
3168 . Compile the application source file:
3177 . Build the application:
3182 $ gcc -o app app.o -ldl -L. -lemon
3186 To run the application:
3188 * Start the application:
3198 The application dynamically loads the instrumented user library.
3200 The instrumented user library dynamically loads the tracepoint provider
3201 package shared object.
3203 See the <<dlclose-warning,warning about `dlclose()`>>.
3205 image::ust-sit+app-dlopens-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3208 include::../common/ust-sit-step-tp-so.txt[]
3210 To build the instrumented user library:
3212 . In path:{emon.c}, before including path:{tpp.h}, add the
3218 #define TRACEPOINT_DEFINE
3219 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3223 . Compile the user library source file:
3228 $ gcc -I. -fpic -c emon.c
3232 . Build the user library shared object:
3237 $ gcc -shared -o libemon.so emon.o -ldl
3241 To build the application:
3243 . Compile the application source file:
3252 . Build the application:
3257 $ gcc -o app app.o -ldl -L. -lemon
3261 To run the application:
3263 * Start the application:
3273 The tracepoint provider package shared object is preloaded before the
3276 The application dynamically loads the instrumented user library.
3278 image::ust-sit+tp-so-preloaded+app-dlopens-lib+lib-instrumented.png[]
3281 include::../common/ust-sit-step-tp-so.txt[]
3283 To build the instrumented user library:
3285 . In path:{emon.c}, before including path:{tpp.h}, add the
3291 #define TRACEPOINT_DEFINE
3292 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3296 . Compile the user library source file:
3301 $ gcc -I. -fpic -c emon.c
3305 . Build the user library shared object:
3310 $ gcc -shared -o libemon.so emon.o -ldl
3314 To build the application:
3316 . Compile the application source file:
3325 . Build the application:
3330 $ gcc -o app app.o -L. -lemon
3334 To run the application with tracing support:
3336 * Preload the tracepoint provider package shared object and
3337 start the application:
3342 $ LD_PRELOAD=./libtpp.so ./app
3346 To run the application without tracing support:
3348 * Start the application:
3358 The application is statically linked with the tracepoint provider
3359 package object file.
3361 The application is linked with the instrumented user library.
3363 image::ust-sit+app-linked-with-tp-o+app-linked-with-lib+lib-instrumented.png[]
3366 include::../common/ust-sit-step-tp-o.txt[]
3368 To build the instrumented user library:
3370 . In path:{emon.c}, before including path:{tpp.h}, add the
3376 #define TRACEPOINT_DEFINE
3380 . Compile the user library source file:
3385 $ gcc -I. -fpic -c emon.c
3389 . Build the user library shared object:
3394 $ gcc -shared -o libemon.so emon.o
3398 To build the application:
3400 . Compile the application source file:
3409 . Build the application:
3414 $ gcc -o app app.o tpp.o -llttng-ust -ldl -L. -lemon
3418 To run the instrumented application:
3420 * Start the application:
3430 The application is statically linked with the tracepoint provider
3431 package object file.
3433 The application dynamically loads the instrumented user library.
3435 image::ust-sit+app-linked-with-tp-o+app-dlopens-lib+lib-instrumented.png[]
3438 include::../common/ust-sit-step-tp-o.txt[]
3440 To build the application:
3442 . In path:{app.c}, before including path:{tpp.h}, add the following line:
3447 #define TRACEPOINT_DEFINE
3451 . Compile the application source file:
3460 . Build the application:
3465 $ gcc -Wl,--export-dynamic -o app app.o tpp.o \
3470 The `--export-dynamic` option passed to the linker is necessary for the
3471 dynamically loaded library to ``see'' the tracepoint symbols defined in
3474 To build the instrumented user library:
3476 . Compile the user library source file:
3481 $ gcc -I. -fpic -c emon.c
3485 . Build the user library shared object:
3490 $ gcc -shared -o libemon.so emon.o
3494 To run the application:
3496 * Start the application:
3508 .Do not use man:dlclose(3) on a tracepoint provider package
3510 Never use man:dlclose(3) on any shared object which:
3512 * Is linked with, statically or dynamically, a tracepoint provider
3514 * Calls man:dlopen(3) itself to dynamically open a tracepoint provider
3515 package shared object.
3517 This is currently considered **unsafe** due to a lack of reference
3518 counting from LTTng-UST to the shared object.
3520 A known workaround (available since glibc 2.2) is to use the
3521 `RTLD_NODELETE` flag when calling man:dlopen(3) initially. This has the
3522 effect of not unloading the loaded shared object, even if man:dlclose(3)
3525 You can also preload the tracepoint provider package shared object with
3526 the env:LD_PRELOAD environment variable to overcome this limitation.
3530 [[using-lttng-ust-with-daemons]]
3531 ===== Use noch:{LTTng-UST} with daemons
3533 If your instrumented application calls man:fork(2), man:clone(2),
3534 or BSD's man:rfork(2), without a following man:exec(3)-family
3535 system call, you must preload the path:{liblttng-ust-fork.so} shared
3536 object when you start the application.
3540 $ LD_PRELOAD=liblttng-ust-fork.so ./my-app
3543 If your tracepoint provider package is
3544 a shared library which you also preload, you must put both
3545 shared objects in env:LD_PRELOAD:
3549 $ LD_PRELOAD=liblttng-ust-fork.so:/path/to/tp.so ./my-app
3555 ===== Use noch:{LTTng-UST} with applications which close file descriptors that don't belong to them
3557 If your instrumented application closes one or more file descriptors
3558 which it did not open itself, you must preload the
3559 path:{liblttng-ust-fd.so} shared object when you start the application:
3563 $ LD_PRELOAD=liblttng-ust-fd.so ./my-app
3566 Typical use cases include closing all the file descriptors after
3567 man:fork(2) or man:rfork(2) and buggy applications doing
3571 [[lttng-ust-pkg-config]]
3572 ===== Use noch:{pkg-config}
3574 On some distributions, LTTng-UST ships with a
3575 https://www.freedesktop.org/wiki/Software/pkg-config/[pkg-config]
3576 metadata file. If this is your case, then you can use cmd:pkg-config to
3577 build an application on the command line:
3581 $ gcc -o my-app my-app.o tp.o $(pkg-config --cflags --libs lttng-ust)
3585 [[instrumenting-32-bit-app-on-64-bit-system]]
3586 ===== [[advanced-instrumenting-techniques]]Build a 32-bit instrumented application for a 64-bit target system
3588 In order to trace a 32-bit application running on a 64-bit system,
3589 LTTng must use a dedicated 32-bit
3590 <<lttng-consumerd,consumer daemon>>.
3592 The following steps show how to build and install a 32-bit consumer
3593 daemon, which is _not_ part of the default 64-bit LTTng build, how to
3594 build and install the 32-bit LTTng-UST libraries, and how to build and
3595 link an instrumented 32-bit application in that context.
3597 To build a 32-bit instrumented application for a 64-bit target system,
3598 assuming you have a fresh target system with no installed Userspace RCU
3601 . Download, build, and install a 32-bit version of Userspace RCU:
3606 $ cd $(mktemp -d) &&
3607 wget http://lttng.org/files/urcu/userspace-rcu-latest-0.9.tar.bz2 &&
3608 tar -xf userspace-rcu-latest-0.9.tar.bz2 &&
3609 cd userspace-rcu-0.9.* &&
3610 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 &&
3612 sudo make install &&
3617 . Using your distribution's package manager, or from source, install
3618 the following 32-bit versions of the following dependencies of
3619 LTTng-tools and LTTng-UST:
3622 * https://sourceforge.net/projects/libuuid/[libuuid]
3623 * http://directory.fsf.org/wiki/Popt[popt]
3624 * http://www.xmlsoft.org/[libxml2]
3627 . Download, build, and install a 32-bit version of the latest
3628 LTTng-UST{nbsp}{revision}:
3633 $ cd $(mktemp -d) &&
3634 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.10.tar.bz2 &&
3635 tar -xf lttng-ust-latest-2.10.tar.bz2 &&
3636 cd lttng-ust-2.10.* &&
3637 ./configure --libdir=/usr/local/lib32 \
3638 CFLAGS=-m32 CXXFLAGS=-m32 \
3639 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' &&
3641 sudo make install &&
3648 Depending on your distribution,
3649 32-bit libraries could be installed at a different location than
3650 `/usr/lib32`. For example, Debian is known to install
3651 some 32-bit libraries in `/usr/lib/i386-linux-gnu`.
3653 In this case, make sure to set `LDFLAGS` to all the
3654 relevant 32-bit library paths, for example:
3658 $ LDFLAGS='-L/usr/lib/i386-linux-gnu -L/usr/lib32'
3662 . Download the latest LTTng-tools{nbsp}{revision}, build, and install
3663 the 32-bit consumer daemon:
3668 $ cd $(mktemp -d) &&
3669 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.10.tar.bz2 &&
3670 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
3671 cd lttng-tools-2.10.* &&
3672 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 CXXFLAGS=-m32 \
3673 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' \
3674 --disable-bin-lttng --disable-bin-lttng-crash \
3675 --disable-bin-lttng-relayd --disable-bin-lttng-sessiond &&
3677 cd src/bin/lttng-consumerd &&
3678 sudo make install &&
3683 . From your distribution or from source,
3684 <<installing-lttng,install>> the 64-bit versions of
3685 LTTng-UST and Userspace RCU.
3686 . Download, build, and install the 64-bit version of the
3687 latest LTTng-tools{nbsp}{revision}:
3692 $ cd $(mktemp -d) &&
3693 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.10.tar.bz2 &&
3694 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
3695 cd lttng-tools-2.10.* &&
3696 ./configure --with-consumerd32-libdir=/usr/local/lib32 \
3697 --with-consumerd32-bin=/usr/local/lib32/lttng/libexec/lttng-consumerd &&
3699 sudo make install &&
3704 . Pass the following options to man:gcc(1), man:g++(1), or man:clang(1)
3705 when linking your 32-bit application:
3708 -m32 -L/usr/lib32 -L/usr/local/lib32 \
3709 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32
3712 For example, let's rebuild the quick start example in
3713 <<tracing-your-own-user-application,Trace a user application>> as an
3714 instrumented 32-bit application:
3719 $ gcc -m32 -c -I. hello-tp.c
3720 $ gcc -m32 -c hello.c
3721 $ gcc -m32 -o hello hello.o hello-tp.o \
3722 -L/usr/lib32 -L/usr/local/lib32 \
3723 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32 \
3728 No special action is required to execute the 32-bit application and
3729 to trace it: use the command-line man:lttng(1) tool as usual.
3736 man:tracef(3) is a small LTTng-UST API designed for quick,
3737 man:printf(3)-like instrumentation without the burden of
3738 <<tracepoint-provider,creating>> and
3739 <<building-tracepoint-providers-and-user-application,building>>
3740 a tracepoint provider package.
3742 To use `tracef()` in your application:
3744 . In the C or C++ source files where you need to use `tracef()`,
3745 include `<lttng/tracef.h>`:
3750 #include <lttng/tracef.h>
3754 . In the application's source code, use `tracef()` like you would use
3762 tracef("my message: %d (%s)", my_integer, my_string);
3768 . Link your application with `liblttng-ust`:
3773 $ gcc -o app app.c -llttng-ust
3777 To trace the events that `tracef()` calls emit:
3779 * <<enabling-disabling-events,Create an event rule>> which matches the
3780 `lttng_ust_tracef:*` event name:
3785 $ lttng enable-event --userspace 'lttng_ust_tracef:*'
3790 .Limitations of `tracef()`
3792 The `tracef()` utility function was developed to make user space tracing
3793 super simple, albeit with notable disadvantages compared to
3794 <<defining-tracepoints,user-defined tracepoints>>:
3796 * All the emitted events have the same tracepoint provider and
3797 tracepoint names, respectively `lttng_ust_tracef` and `event`.
3798 * There is no static type checking.
3799 * The only event record field you actually get, named `msg`, is a string
3800 potentially containing the values you passed to `tracef()`
3801 using your own format string. This also means that you cannot filter
3802 events with a custom expression at run time because there are no
3804 * Since `tracef()` uses the C standard library's man:vasprintf(3)
3805 function behind the scenes to format the strings at run time, its
3806 expected performance is lower than with user-defined tracepoints,
3807 which do not require a conversion to a string.
3809 Taking this into consideration, `tracef()` is useful for some quick
3810 prototyping and debugging, but you should not consider it for any
3811 permanent and serious applicative instrumentation.
3817 ==== Use `tracelog()`
3819 The man:tracelog(3) API is very similar to <<tracef,`tracef()`>>, with
3820 the difference that it accepts an additional log level parameter.
3822 The goal of `tracelog()` is to ease the migration from logging to
3825 To use `tracelog()` in your application:
3827 . In the C or C++ source files where you need to use `tracelog()`,
3828 include `<lttng/tracelog.h>`:
3833 #include <lttng/tracelog.h>
3837 . In the application's source code, use `tracelog()` like you would use
3838 man:printf(3), except for the first parameter which is the log
3846 tracelog(TRACE_WARNING, "my message: %d (%s)",
3847 my_integer, my_string);
3853 See man:lttng-ust(3) for a list of available log level names.
3855 . Link your application with `liblttng-ust`:
3860 $ gcc -o app app.c -llttng-ust
3864 To trace the events that `tracelog()` calls emit with a log level
3865 _as severe as_ a specific log level:
3867 * <<enabling-disabling-events,Create an event rule>> which matches the
3868 `lttng_ust_tracelog:*` event name and a minimum level
3874 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
3875 --loglevel=TRACE_WARNING
3879 To trace the events that `tracelog()` calls emit with a
3880 _specific log level_:
3882 * Create an event rule which matches the `lttng_ust_tracelog:*`
3883 event name and a specific log level:
3888 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
3889 --loglevel-only=TRACE_INFO
3894 [[prebuilt-ust-helpers]]
3895 === Prebuilt user space tracing helpers
3897 The LTTng-UST package provides a few helpers in the form or preloadable
3898 shared objects which automatically instrument system functions and
3901 The helper shared objects are normally found in dir:{/usr/lib}. If you
3902 built LTTng-UST <<building-from-source,from source>>, they are probably
3903 located in dir:{/usr/local/lib}.
3905 The installed user space tracing helpers in LTTng-UST{nbsp}{revision}
3908 path:{liblttng-ust-libc-wrapper.so}::
3909 path:{liblttng-ust-pthread-wrapper.so}::
3910 <<liblttng-ust-libc-pthread-wrapper,C{nbsp}standard library
3911 memory and POSIX threads function tracing>>.
3913 path:{liblttng-ust-cyg-profile.so}::
3914 path:{liblttng-ust-cyg-profile-fast.so}::
3915 <<liblttng-ust-cyg-profile,Function entry and exit tracing>>.
3917 path:{liblttng-ust-dl.so}::
3918 <<liblttng-ust-dl,Dynamic linker tracing>>.
3920 To use a user space tracing helper with any user application:
3922 * Preload the helper shared object when you start the application:
3927 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so my-app
3931 You can preload more than one helper:
3936 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so:liblttng-ust-dl.so my-app
3942 [[liblttng-ust-libc-pthread-wrapper]]
3943 ==== Instrument C standard library memory and POSIX threads functions
3945 The path:{liblttng-ust-libc-wrapper.so} and
3946 path:{liblttng-ust-pthread-wrapper.so} helpers
3947 add instrumentation to some C standard library and POSIX
3951 .Functions instrumented by preloading path:{liblttng-ust-libc-wrapper.so}.
3953 |TP provider name |TP name |Instrumented function
3955 .6+|`lttng_ust_libc` |`malloc` |man:malloc(3)
3956 |`calloc` |man:calloc(3)
3957 |`realloc` |man:realloc(3)
3958 |`free` |man:free(3)
3959 |`memalign` |man:memalign(3)
3960 |`posix_memalign` |man:posix_memalign(3)
3964 .Functions instrumented by preloading path:{liblttng-ust-pthread-wrapper.so}.
3966 |TP provider name |TP name |Instrumented function
3968 .4+|`lttng_ust_pthread` |`pthread_mutex_lock_req` |man:pthread_mutex_lock(3p) (request time)
3969 |`pthread_mutex_lock_acq` |man:pthread_mutex_lock(3p) (acquire time)
3970 |`pthread_mutex_trylock` |man:pthread_mutex_trylock(3p)
3971 |`pthread_mutex_unlock` |man:pthread_mutex_unlock(3p)
3974 When you preload the shared object, it replaces the functions listed
3975 in the previous tables by wrappers which contain tracepoints and call
3976 the replaced functions.
3979 [[liblttng-ust-cyg-profile]]
3980 ==== Instrument function entry and exit
3982 The path:{liblttng-ust-cyg-profile*.so} helpers can add instrumentation
3983 to the entry and exit points of functions.
3985 man:gcc(1) and man:clang(1) have an option named
3986 https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html[`-finstrument-functions`]
3987 which generates instrumentation calls for entry and exit to functions.
3988 The LTTng-UST function tracing helpers,
3989 path:{liblttng-ust-cyg-profile.so} and
3990 path:{liblttng-ust-cyg-profile-fast.so}, take advantage of this feature
3991 to add tracepoints to the two generated functions (which contain
3992 `cyg_profile` in their names, hence the helper's name).
3994 To use the LTTng-UST function tracing helper, the source files to
3995 instrument must be built using the `-finstrument-functions` compiler
3998 There are two versions of the LTTng-UST function tracing helper:
4000 * **path:{liblttng-ust-cyg-profile-fast.so}** is a lightweight variant
4001 that you should only use when it can be _guaranteed_ that the
4002 complete event stream is recorded without any lost event record.
4003 Any kind of duplicate information is left out.
4005 Assuming no event record is lost, having only the function addresses on
4006 entry is enough to create a call graph, since an event record always
4007 contains the ID of the CPU that generated it.
4009 You can use a tool like man:addr2line(1) to convert function addresses
4010 back to source file names and line numbers.
4012 * **path:{liblttng-ust-cyg-profile.so}** is a more robust variant
4013 which also works in use cases where event records might get discarded or
4014 not recorded from application startup.
4015 In these cases, the trace analyzer needs more information to be
4016 able to reconstruct the program flow.
4018 See man:lttng-ust-cyg-profile(3) to learn more about the instrumentation
4019 points of this helper.
4021 All the tracepoints that this helper provides have the
4022 log level `TRACE_DEBUG_FUNCTION` (see man:lttng-ust(3)).
4024 TIP: It's sometimes a good idea to limit the number of source files that
4025 you compile with the `-finstrument-functions` option to prevent LTTng
4026 from writing an excessive amount of trace data at run time. When using
4027 man:gcc(1), you can use the
4028 `-finstrument-functions-exclude-function-list` option to avoid
4029 instrument entries and exits of specific function names.
4034 ==== Instrument the dynamic linker
4036 The path:{liblttng-ust-dl.so} helper adds instrumentation to the
4037 man:dlopen(3) and man:dlclose(3) function calls.
4039 See man:lttng-ust-dl(3) to learn more about the instrumentation points
4044 [[java-application]]
4045 === User space Java agent
4047 You can instrument any Java application which uses one of the following
4050 * The https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[**`java.util.logging`**]
4051 (JUL) core logging facilities.
4052 * http://logging.apache.org/log4j/1.2/[**Apache log4j 1.2**], since
4053 LTTng 2.6. Note that Apache Log4j{nbsp}2 is not supported.
4056 .LTTng-UST Java agent imported by a Java application.
4057 image::java-app.png[]
4059 Note that the methods described below are new in LTTng{nbsp}2.8.
4060 Previous LTTng versions use another technique.
4062 NOTE: We use http://openjdk.java.net/[OpenJDK]{nbsp}8 for development
4063 and https://ci.lttng.org/[continuous integration], thus this version is
4064 directly supported. However, the LTTng-UST Java agent is also tested
4065 with OpenJDK{nbsp}7.
4070 ==== Use the LTTng-UST Java agent for `java.util.logging`
4072 To use the LTTng-UST Java agent in a Java application which uses
4073 `java.util.logging` (JUL):
4075 . In the Java application's source code, import the LTTng-UST
4076 log handler package for `java.util.logging`:
4081 import org.lttng.ust.agent.jul.LttngLogHandler;
4085 . Create an LTTng-UST JUL log handler:
4090 Handler lttngUstLogHandler = new LttngLogHandler();
4094 . Add this handler to the JUL loggers which should emit LTTng events:
4099 Logger myLogger = Logger.getLogger("some-logger");
4101 myLogger.addHandler(lttngUstLogHandler);
4105 . Use `java.util.logging` log statements and configuration as usual.
4106 The loggers with an attached LTTng-UST log handler can emit
4109 . Before exiting the application, remove the LTTng-UST log handler from
4110 the loggers attached to it and call its `close()` method:
4115 myLogger.removeHandler(lttngUstLogHandler);
4116 lttngUstLogHandler.close();
4120 This is not strictly necessary, but it is recommended for a clean
4121 disposal of the handler's resources.
4123 . Include the LTTng-UST Java agent's common and JUL-specific JAR files,
4124 path:{lttng-ust-agent-common.jar} and path:{lttng-ust-agent-jul.jar},
4126 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4127 path] when you build the Java application.
4129 The JAR files are typically located in dir:{/usr/share/java}.
4131 IMPORTANT: The LTTng-UST Java agent must be
4132 <<installing-lttng,installed>> for the logging framework your
4135 .Use the LTTng-UST Java agent for `java.util.logging`.
4140 import java.io.IOException;
4141 import java.util.logging.Handler;
4142 import java.util.logging.Logger;
4143 import org.lttng.ust.agent.jul.LttngLogHandler;
4147 private static final int answer = 42;
4149 public static void main(String[] argv) throws Exception
4152 Logger logger = Logger.getLogger("jello");
4154 // Create an LTTng-UST log handler
4155 Handler lttngUstLogHandler = new LttngLogHandler();
4157 // Add the LTTng-UST log handler to our logger
4158 logger.addHandler(lttngUstLogHandler);
4161 logger.info("some info");
4162 logger.warning("some warning");
4164 logger.finer("finer information; the answer is " + answer);
4166 logger.severe("error!");
4168 // Not mandatory, but cleaner
4169 logger.removeHandler(lttngUstLogHandler);
4170 lttngUstLogHandler.close();
4179 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4182 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4183 <<enabling-disabling-events,create an event rule>> matching the
4184 `jello` JUL logger, and <<basic-tracing-session-control,start tracing>>:
4189 $ lttng enable-event --jul jello
4193 Run the compiled class:
4197 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4200 <<basic-tracing-session-control,Stop tracing>> and inspect the
4210 In the resulting trace, an <<event,event record>> generated by a Java
4211 application using `java.util.logging` is named `lttng_jul:event` and
4212 has the following fields:
4215 Log record's message.
4221 Name of the class in which the log statement was executed.
4224 Name of the method in which the log statement was executed.
4227 Logging time (timestamp in milliseconds).
4230 Log level integer value.
4233 ID of the thread in which the log statement was executed.
4235 You can use the opt:lttng-enable-event(1):--loglevel or
4236 opt:lttng-enable-event(1):--loglevel-only option of the
4237 man:lttng-enable-event(1) command to target a range of JUL log levels
4238 or a specific JUL log level.
4243 ==== Use the LTTng-UST Java agent for Apache log4j
4245 To use the LTTng-UST Java agent in a Java application which uses
4248 . In the Java application's source code, import the LTTng-UST
4249 log appender package for Apache log4j:
4254 import org.lttng.ust.agent.log4j.LttngLogAppender;
4258 . Create an LTTng-UST log4j log appender:
4263 Appender lttngUstLogAppender = new LttngLogAppender();
4267 . Add this appender to the log4j loggers which should emit LTTng events:
4272 Logger myLogger = Logger.getLogger("some-logger");
4274 myLogger.addAppender(lttngUstLogAppender);
4278 . Use Apache log4j log statements and configuration as usual. The
4279 loggers with an attached LTTng-UST log appender can emit LTTng events.
4281 . Before exiting the application, remove the LTTng-UST log appender from
4282 the loggers attached to it and call its `close()` method:
4287 myLogger.removeAppender(lttngUstLogAppender);
4288 lttngUstLogAppender.close();
4292 This is not strictly necessary, but it is recommended for a clean
4293 disposal of the appender's resources.
4295 . Include the LTTng-UST Java agent's common and log4j-specific JAR
4296 files, path:{lttng-ust-agent-common.jar} and
4297 path:{lttng-ust-agent-log4j.jar}, in the
4298 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4299 path] when you build the Java application.
4301 The JAR files are typically located in dir:{/usr/share/java}.
4303 IMPORTANT: The LTTng-UST Java agent must be
4304 <<installing-lttng,installed>> for the logging framework your
4307 .Use the LTTng-UST Java agent for Apache log4j.
4312 import org.apache.log4j.Appender;
4313 import org.apache.log4j.Logger;
4314 import org.lttng.ust.agent.log4j.LttngLogAppender;
4318 private static final int answer = 42;
4320 public static void main(String[] argv) throws Exception
4323 Logger logger = Logger.getLogger("jello");
4325 // Create an LTTng-UST log appender
4326 Appender lttngUstLogAppender = new LttngLogAppender();
4328 // Add the LTTng-UST log appender to our logger
4329 logger.addAppender(lttngUstLogAppender);
4332 logger.info("some info");
4333 logger.warn("some warning");
4335 logger.debug("debug information; the answer is " + answer);
4337 logger.fatal("error!");
4339 // Not mandatory, but cleaner
4340 logger.removeAppender(lttngUstLogAppender);
4341 lttngUstLogAppender.close();
4347 Build this example (`$LOG4JPATH` is the path to the Apache log4j JAR
4352 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH Test.java
4355 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4356 <<enabling-disabling-events,create an event rule>> matching the
4357 `jello` log4j logger, and <<basic-tracing-session-control,start tracing>>:
4362 $ lttng enable-event --log4j jello
4366 Run the compiled class:
4370 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH:. Test
4373 <<basic-tracing-session-control,Stop tracing>> and inspect the
4383 In the resulting trace, an <<event,event record>> generated by a Java
4384 application using log4j is named `lttng_log4j:event` and
4385 has the following fields:
4388 Log record's message.
4394 Name of the class in which the log statement was executed.
4397 Name of the method in which the log statement was executed.
4400 Name of the file in which the executed log statement is located.
4403 Line number at which the log statement was executed.
4409 Log level integer value.
4412 Name of the Java thread in which the log statement was executed.
4414 You can use the opt:lttng-enable-event(1):--loglevel or
4415 opt:lttng-enable-event(1):--loglevel-only option of the
4416 man:lttng-enable-event(1) command to target a range of Apache log4j log levels
4417 or a specific log4j log level.
4421 [[java-application-context]]
4422 ==== Provide application-specific context fields in a Java application
4424 A Java application-specific context field is a piece of state provided
4425 by the application which <<adding-context,you can add>>, using the
4426 man:lttng-add-context(1) command, to each <<event,event record>>
4427 produced by the log statements of this application.
4429 For example, a given object might have a current request ID variable.
4430 You can create a context information retriever for this object and
4431 assign a name to this current request ID. You can then, using the
4432 man:lttng-add-context(1) command, add this context field by name to
4433 the JUL or log4j <<channel,channel>>.
4435 To provide application-specific context fields in a Java application:
4437 . In the Java application's source code, import the LTTng-UST
4438 Java agent context classes and interfaces:
4443 import org.lttng.ust.agent.context.ContextInfoManager;
4444 import org.lttng.ust.agent.context.IContextInfoRetriever;
4448 . Create a context information retriever class, that is, a class which
4449 implements the `IContextInfoRetriever` interface:
4454 class MyContextInfoRetriever implements IContextInfoRetriever
4457 public Object retrieveContextInfo(String key)
4459 if (key.equals("intCtx")) {
4461 } else if (key.equals("strContext")) {
4462 return "context value!";
4471 This `retrieveContextInfo()` method is the only member of the
4472 `IContextInfoRetriever` interface. Its role is to return the current
4473 value of a state by name to create a context field. The names of the
4474 context fields and which state variables they return depends on your
4477 All primitive types and objects are supported as context fields.
4478 When `retrieveContextInfo()` returns an object, the context field
4479 serializer calls its `toString()` method to add a string field to
4480 event records. The method can also return `null`, which means that
4481 no context field is available for the required name.
4483 . Register an instance of your context information retriever class to
4484 the context information manager singleton:
4489 IContextInfoRetriever cir = new MyContextInfoRetriever();
4490 ContextInfoManager cim = ContextInfoManager.getInstance();
4491 cim.registerContextInfoRetriever("retrieverName", cir);
4495 . Before exiting the application, remove your context information
4496 retriever from the context information manager singleton:
4501 ContextInfoManager cim = ContextInfoManager.getInstance();
4502 cim.unregisterContextInfoRetriever("retrieverName");
4506 This is not strictly necessary, but it is recommended for a clean
4507 disposal of some manager's resources.
4509 . Build your Java application with LTTng-UST Java agent support as
4510 usual, following the procedure for either the <<jul,JUL>> or
4511 <<log4j,Apache log4j>> framework.
4514 .Provide application-specific context fields in a Java application.
4519 import java.util.logging.Handler;
4520 import java.util.logging.Logger;
4521 import org.lttng.ust.agent.jul.LttngLogHandler;
4522 import org.lttng.ust.agent.context.ContextInfoManager;
4523 import org.lttng.ust.agent.context.IContextInfoRetriever;
4527 // Our context information retriever class
4528 private static class MyContextInfoRetriever
4529 implements IContextInfoRetriever
4532 public Object retrieveContextInfo(String key) {
4533 if (key.equals("intCtx")) {
4535 } else if (key.equals("strContext")) {
4536 return "context value!";
4543 private static final int answer = 42;
4545 public static void main(String args[]) throws Exception
4547 // Get the context information manager instance
4548 ContextInfoManager cim = ContextInfoManager.getInstance();
4550 // Create and register our context information retriever
4551 IContextInfoRetriever cir = new MyContextInfoRetriever();
4552 cim.registerContextInfoRetriever("myRetriever", cir);
4555 Logger logger = Logger.getLogger("jello");
4557 // Create an LTTng-UST log handler
4558 Handler lttngUstLogHandler = new LttngLogHandler();
4560 // Add the LTTng-UST log handler to our logger
4561 logger.addHandler(lttngUstLogHandler);
4564 logger.info("some info");
4565 logger.warning("some warning");
4567 logger.finer("finer information; the answer is " + answer);
4569 logger.severe("error!");
4571 // Not mandatory, but cleaner
4572 logger.removeHandler(lttngUstLogHandler);
4573 lttngUstLogHandler.close();
4574 cim.unregisterContextInfoRetriever("myRetriever");
4583 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4586 <<creating-destroying-tracing-sessions,Create a tracing session>>
4587 and <<enabling-disabling-events,create an event rule>> matching the
4593 $ lttng enable-event --jul jello
4596 <<adding-context,Add the application-specific context fields>> to the
4601 $ lttng add-context --jul --type='$app.myRetriever:intCtx'
4602 $ lttng add-context --jul --type='$app.myRetriever:strContext'
4605 <<basic-tracing-session-control,Start tracing>>:
4612 Run the compiled class:
4616 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4619 <<basic-tracing-session-control,Stop tracing>> and inspect the
4631 [[python-application]]
4632 === User space Python agent
4634 You can instrument a Python 2 or Python 3 application which uses the
4635 standard https://docs.python.org/3/library/logging.html[`logging`]
4638 Each log statement emits an LTTng event once the
4639 application module imports the
4640 <<lttng-ust-agents,LTTng-UST Python agent>> package.
4643 .A Python application importing the LTTng-UST Python agent.
4644 image::python-app.png[]
4646 To use the LTTng-UST Python agent:
4648 . In the Python application's source code, import the LTTng-UST Python
4658 The LTTng-UST Python agent automatically adds its logging handler to the
4659 root logger at import time.
4661 Any log statement that the application executes before this import does
4662 not emit an LTTng event.
4664 IMPORTANT: The LTTng-UST Python agent must be
4665 <<installing-lttng,installed>>.
4667 . Use log statements and logging configuration as usual.
4668 Since the LTTng-UST Python agent adds a handler to the _root_
4669 logger, you can trace any log statement from any logger.
4671 .Use the LTTng-UST Python agent.
4682 logging.basicConfig()
4683 logger = logging.getLogger('my-logger')
4686 logger.debug('debug message')
4687 logger.info('info message')
4688 logger.warn('warn message')
4689 logger.error('error message')
4690 logger.critical('critical message')
4694 if __name__ == '__main__':
4698 NOTE: `logging.basicConfig()`, which adds to the root logger a basic
4699 logging handler which prints to the standard error stream, is not
4700 strictly required for LTTng-UST tracing to work, but in versions of
4701 Python preceding 3.2, you could see a warning message which indicates
4702 that no handler exists for the logger `my-logger`.
4704 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4705 <<enabling-disabling-events,create an event rule>> matching the
4706 `my-logger` Python logger, and <<basic-tracing-session-control,start
4712 $ lttng enable-event --python my-logger
4716 Run the Python script:
4723 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
4733 In the resulting trace, an <<event,event record>> generated by a Python
4734 application is named `lttng_python:event` and has the following fields:
4737 Logging time (string).
4740 Log record's message.
4746 Name of the function in which the log statement was executed.
4749 Line number at which the log statement was executed.
4752 Log level integer value.
4755 ID of the Python thread in which the log statement was executed.
4758 Name of the Python thread in which the log statement was executed.
4760 You can use the opt:lttng-enable-event(1):--loglevel or
4761 opt:lttng-enable-event(1):--loglevel-only option of the
4762 man:lttng-enable-event(1) command to target a range of Python log levels
4763 or a specific Python log level.
4765 When an application imports the LTTng-UST Python agent, the agent tries
4766 to register to a <<lttng-sessiond,session daemon>>. Note that you must
4767 <<start-sessiond,start the session daemon>> _before_ you run the Python
4768 application. If a session daemon is found, the agent tries to register
4769 to it during 5{nbsp}seconds, after which the application continues
4770 without LTTng tracing support. You can override this timeout value with
4771 the env:LTTNG_UST_PYTHON_REGISTER_TIMEOUT environment variable
4774 If the session daemon stops while a Python application with an imported
4775 LTTng-UST Python agent runs, the agent retries to connect and to
4776 register to a session daemon every 3{nbsp}seconds. You can override this
4777 delay with the env:LTTNG_UST_PYTHON_REGISTER_RETRY_DELAY environment
4782 [[proc-lttng-logger-abi]]
4785 The `lttng-tracer` Linux kernel module, part of
4786 <<lttng-modules,LTTng-modules>>, creates the special LTTng logger file
4787 path:{/proc/lttng-logger} when it's loaded. Any application can write
4788 text data to this file to emit an LTTng event.
4791 .An application writes to the LTTng logger file to emit an LTTng event.
4792 image::lttng-logger.png[]
4794 The LTTng logger is the quickest method--not the most efficient,
4795 however--to add instrumentation to an application. It is designed
4796 mostly to instrument shell scripts:
4800 $ echo "Some message, some $variable" > /proc/lttng-logger
4803 Any event that the LTTng logger emits is named `lttng_logger` and
4804 belongs to the Linux kernel <<domain,tracing domain>>. However, unlike
4805 other instrumentation points in the kernel tracing domain, **any Unix
4806 user** can <<enabling-disabling-events,create an event rule>> which
4807 matches its event name, not only the root user or users in the
4808 <<tracing-group,tracing group>>.
4810 To use the LTTng logger:
4812 * From any application, write text data to the path:{/proc/lttng-logger}
4815 The `msg` field of `lttng_logger` event records contains the
4818 NOTE: The maximum message length of an LTTng logger event is
4819 1024{nbsp}bytes. Writing more than this makes the LTTng logger emit more
4820 than one event to contain the remaining data.
4822 You should not use the LTTng logger to trace a user application which
4823 can be instrumented in a more efficient way, namely:
4825 * <<c-application,C and $$C++$$ applications>>.
4826 * <<java-application,Java applications>>.
4827 * <<python-application,Python applications>>.
4829 .Use the LTTng logger.
4834 echo 'Hello, World!' > /proc/lttng-logger
4836 df --human-readable --print-type / > /proc/lttng-logger
4839 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4840 <<enabling-disabling-events,create an event rule>> matching the
4841 `lttng_logger` Linux kernel tracepoint, and
4842 <<basic-tracing-session-control,start tracing>>:
4847 $ lttng enable-event --kernel lttng_logger
4851 Run the Bash script:
4858 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
4869 [[instrumenting-linux-kernel]]
4870 === LTTng kernel tracepoints
4872 NOTE: This section shows how to _add_ instrumentation points to the
4873 Linux kernel. The kernel's subsystems are already thoroughly
4874 instrumented at strategic places for LTTng when you
4875 <<installing-lttng,install>> the <<lttng-modules,LTTng-modules>>
4879 There are two methods to instrument the Linux kernel:
4881 . <<linux-add-lttng-layer,Add an LTTng layer>> over an existing ftrace
4882 tracepoint which uses the `TRACE_EVENT()` API.
4884 Choose this if you want to instrumentation a Linux kernel tree with an
4885 instrumentation point compatible with ftrace, perf, and SystemTap.
4887 . Use an <<linux-lttng-tracepoint-event,LTTng-only approach>> to
4888 instrument an out-of-tree kernel module.
4890 Choose this if you don't need ftrace, perf, or SystemTap support.
4894 [[linux-add-lttng-layer]]
4895 ==== [[instrumenting-linux-kernel-itself]][[mainline-trace-event]][[lttng-adaptation-layer]]Add an LTTng layer to an existing ftrace tracepoint
4897 This section shows how to add an LTTng layer to existing ftrace
4898 instrumentation using the `TRACE_EVENT()` API.
4900 This section does not document the `TRACE_EVENT()` macro. You can
4901 read the following articles to learn more about this API:
4903 * http://lwn.net/Articles/379903/[Using the TRACE_EVENT() macro (Part 1)]
4904 * http://lwn.net/Articles/381064/[Using the TRACE_EVENT() macro (Part 2)]
4905 * http://lwn.net/Articles/383362/[Using the TRACE_EVENT() macro (Part 3)]
4907 The following procedure assumes that your ftrace tracepoints are
4908 correctly defined in their own header and that they are created in
4909 one source file using the `CREATE_TRACE_POINTS` definition.
4911 To add an LTTng layer over an existing ftrace tracepoint:
4913 . Make sure the following kernel configuration options are
4919 * `CONFIG_HIGH_RES_TIMERS`
4920 * `CONFIG_TRACEPOINTS`
4923 . Build the Linux source tree with your custom ftrace tracepoints.
4924 . Boot the resulting Linux image on your target system.
4926 Confirm that the tracepoints exist by looking for their names in the
4927 dir:{/sys/kernel/debug/tracing/events/subsys} directory, where `subsys`
4928 is your subsystem's name.
4930 . Get a copy of the latest LTTng-modules{nbsp}{revision}:
4935 $ cd $(mktemp -d) &&
4936 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
4937 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
4938 cd lttng-modules-2.10.*
4942 . In dir:{instrumentation/events/lttng-module}, relative to the root
4943 of the LTTng-modules source tree, create a header file named
4944 +__subsys__.h+ for your custom subsystem +__subsys__+ and write your
4945 LTTng-modules tracepoint definitions using the LTTng-modules
4948 Start with this template:
4952 .path:{instrumentation/events/lttng-module/my_subsys.h}
4955 #define TRACE_SYSTEM my_subsys
4957 #if !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ)
4958 #define _LTTNG_MY_SUBSYS_H
4960 #include "../../../probes/lttng-tracepoint-event.h"
4961 #include <linux/tracepoint.h>
4963 LTTNG_TRACEPOINT_EVENT(
4965 * Format is identical to TRACE_EVENT()'s version for the three
4966 * following macro parameters:
4969 TP_PROTO(int my_int, const char *my_string),
4970 TP_ARGS(my_int, my_string),
4972 /* LTTng-modules specific macros */
4974 ctf_integer(int, my_int_field, my_int)
4975 ctf_string(my_bar_field, my_bar)
4979 #endif /* !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ) */
4981 #include "../../../probes/define_trace.h"
4985 The entries in the `TP_FIELDS()` section are the list of fields for the
4986 LTTng tracepoint. This is similar to the `TP_STRUCT__entry()` part of
4987 ftrace's `TRACE_EVENT()` macro.
4989 See <<lttng-modules-tp-fields,Tracepoint fields macros>> for a
4990 complete description of the available `ctf_*()` macros.
4992 . Create the LTTng-modules probe's kernel module C source file,
4993 +probes/lttng-probe-__subsys__.c+, where +__subsys__+ is your
4998 .path:{probes/lttng-probe-my-subsys.c}
5000 #include <linux/module.h>
5001 #include "../lttng-tracer.h"
5004 * Build-time verification of mismatch between mainline
5005 * TRACE_EVENT() arguments and the LTTng-modules adaptation
5006 * layer LTTNG_TRACEPOINT_EVENT() arguments.
5008 #include <trace/events/my_subsys.h>
5010 /* Create LTTng tracepoint probes */
5011 #define LTTNG_PACKAGE_BUILD
5012 #define CREATE_TRACE_POINTS
5013 #define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
5015 #include "../instrumentation/events/lttng-module/my_subsys.h"
5017 MODULE_LICENSE("GPL and additional rights");
5018 MODULE_AUTHOR("Your name <your-email>");
5019 MODULE_DESCRIPTION("LTTng my_subsys probes");
5020 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
5021 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
5022 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
5023 LTTNG_MODULES_EXTRAVERSION);
5027 . Edit path:{probes/KBuild} and add your new kernel module object
5028 next to the existing ones:
5032 .path:{probes/KBuild}
5036 obj-m += lttng-probe-module.o
5037 obj-m += lttng-probe-power.o
5039 obj-m += lttng-probe-my-subsys.o
5045 . Build and install the LTTng kernel modules:
5050 $ make KERNELDIR=/path/to/linux
5051 # make modules_install && depmod -a
5055 Replace `/path/to/linux` with the path to the Linux source tree where
5056 you defined and used tracepoints with ftrace's `TRACE_EVENT()` macro.
5058 Note that you can also use the
5059 <<lttng-tracepoint-event-code,`LTTNG_TRACEPOINT_EVENT_CODE()` macro>>
5060 instead of `LTTNG_TRACEPOINT_EVENT()` to use custom local variables and
5061 C code that need to be executed before the event fields are recorded.
5063 The best way to learn how to use the previous LTTng-modules macros is to
5064 inspect the existing LTTng-modules tracepoint definitions in the
5065 dir:{instrumentation/events/lttng-module} header files. Compare them
5066 with the Linux kernel mainline versions in the
5067 dir:{include/trace/events} directory of the Linux source tree.
5071 [[lttng-tracepoint-event-code]]
5072 ===== Use custom C code to access the data for tracepoint fields
5074 Although we recommended to always use the
5075 <<lttng-adaptation-layer,`LTTNG_TRACEPOINT_EVENT()`>> macro to describe
5076 the arguments and fields of an LTTng-modules tracepoint when possible,
5077 sometimes you need a more complex process to access the data that the
5078 tracer records as event record fields. In other words, you need local
5079 variables and multiple C{nbsp}statements instead of simple
5080 argument-based expressions that you pass to the
5081 <<lttng-modules-tp-fields,`ctf_*()` macros of `TP_FIELDS()`>>.
5083 You can use the `LTTNG_TRACEPOINT_EVENT_CODE()` macro instead of
5084 `LTTNG_TRACEPOINT_EVENT()` to declare custom local variables and define
5085 a block of C{nbsp}code to be executed before LTTng records the fields.
5086 The structure of this macro is:
5089 .`LTTNG_TRACEPOINT_EVENT_CODE()` macro syntax.
5091 LTTNG_TRACEPOINT_EVENT_CODE(
5093 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5094 * version for the following three macro parameters:
5097 TP_PROTO(int my_int, const char *my_string),
5098 TP_ARGS(my_int, my_string),
5100 /* Declarations of custom local variables */
5103 unsigned long b = 0;
5104 const char *name = "(undefined)";
5105 struct my_struct *my_struct;
5109 * Custom code which uses both tracepoint arguments
5110 * (in TP_ARGS()) and local variables (in TP_locvar()).
5112 * Local variables are actually members of a structure pointed
5113 * to by the special variable tp_locvar.
5117 tp_locvar->a = my_int + 17;
5118 tp_locvar->my_struct = get_my_struct_at(tp_locvar->a);
5119 tp_locvar->b = my_struct_compute_b(tp_locvar->my_struct);
5120 tp_locvar->name = my_struct_get_name(tp_locvar->my_struct);
5121 put_my_struct(tp_locvar->my_struct);
5130 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5131 * version for this, except that tp_locvar members can be
5132 * used in the argument expression parameters of
5133 * the ctf_*() macros.
5136 ctf_integer(unsigned long, my_struct_b, tp_locvar->b)
5137 ctf_integer(int, my_struct_a, tp_locvar->a)
5138 ctf_string(my_string_field, my_string)
5139 ctf_string(my_struct_name, tp_locvar->name)
5144 IMPORTANT: The C code defined in `TP_code()` must not have any side
5145 effects when executed. In particular, the code must not allocate
5146 memory or get resources without deallocating this memory or putting
5147 those resources afterwards.
5150 [[instrumenting-linux-kernel-tracing]]
5151 ==== Load and unload a custom probe kernel module
5153 You must load a <<lttng-adaptation-layer,created LTTng-modules probe
5154 kernel module>> in the kernel before it can emit LTTng events.
5156 To load the default probe kernel modules and a custom probe kernel
5159 * Use the opt:lttng-sessiond(8):--extra-kmod-probes option to give extra
5160 probe modules to load when starting a root <<lttng-sessiond,session
5164 .Load the `my_subsys`, `usb`, and the default probe modules.
5168 # lttng-sessiond --extra-kmod-probes=my_subsys,usb
5173 You only need to pass the subsystem name, not the whole kernel module
5176 To load _only_ a given custom probe kernel module:
5178 * Use the opt:lttng-sessiond(8):--kmod-probes option to give the probe
5179 modules to load when starting a root session daemon:
5182 .Load only the `my_subsys` and `usb` probe modules.
5186 # lttng-sessiond --kmod-probes=my_subsys,usb
5191 To confirm that a probe module is loaded:
5198 $ lsmod | grep lttng_probe_usb
5202 To unload the loaded probe modules:
5204 * Kill the session daemon with `SIGTERM`:
5209 # pkill lttng-sessiond
5213 You can also use man:modprobe(8)'s `--remove` option if the session
5214 daemon terminates abnormally.
5217 [[controlling-tracing]]
5220 Once an application or a Linux kernel is
5221 <<instrumenting,instrumented>> for LTTng tracing,
5224 This section is divided in topics on how to use the various
5225 <<plumbing,components of LTTng>>, in particular the <<lttng-cli,cmd:lttng
5226 command-line tool>>, to _control_ the LTTng daemons and tracers.
5228 NOTE: In the following subsections, we refer to an man:lttng(1) command
5229 using its man page name. For example, instead of _Run the `create`
5230 command to..._, we use _Run the man:lttng-create(1) command to..._.
5234 === Start a session daemon
5236 In some situations, you need to run a <<lttng-sessiond,session daemon>>
5237 (man:lttng-sessiond(8)) _before_ you can use the man:lttng(1)
5240 You will see the following error when you run a command while no session
5244 Error: No session daemon is available
5247 The only command that automatically runs a session daemon is
5248 man:lttng-create(1), which you use to
5249 <<creating-destroying-tracing-sessions,create a tracing session>>. While
5250 this is most of the time the first operation that you do, sometimes it's
5251 not. Some examples are:
5253 * <<list-instrumentation-points,List the available instrumentation points>>.
5254 * <<saving-loading-tracing-session,Load a tracing session configuration>>.
5256 [[tracing-group]] Each Unix user must have its own running session
5257 daemon to trace user applications. The session daemon that the root user
5258 starts is the only one allowed to control the LTTng kernel tracer. Users
5259 that are part of the _tracing group_ can control the root session
5260 daemon. The default tracing group name is `tracing`; you can set it to
5261 something else with the opt:lttng-sessiond(8):--group option when you
5262 start the root session daemon.
5264 To start a user session daemon:
5266 * Run man:lttng-sessiond(8):
5271 $ lttng-sessiond --daemonize
5275 To start the root session daemon:
5277 * Run man:lttng-sessiond(8) as the root user:
5282 # lttng-sessiond --daemonize
5286 In both cases, remove the opt:lttng-sessiond(8):--daemonize option to
5287 start the session daemon in foreground.
5289 To stop a session daemon, use man:kill(1) on its process ID (standard
5292 Note that some Linux distributions could manage the LTTng session daemon
5293 as a service. In this case, you should use the service manager to
5294 start, restart, and stop session daemons.
5297 [[creating-destroying-tracing-sessions]]
5298 === Create and destroy a tracing session
5300 Almost all the LTTng control operations happen in the scope of
5301 a <<tracing-session,tracing session>>, which is the dialogue between the
5302 <<lttng-sessiond,session daemon>> and you.
5304 To create a tracing session with a generated name:
5306 * Use the man:lttng-create(1) command:
5315 The created tracing session's name is `auto` followed by the
5318 To create a tracing session with a specific name:
5320 * Use the optional argument of the man:lttng-create(1) command:
5325 $ lttng create my-session
5329 Replace `my-session` with the specific tracing session name.
5331 LTTng appends the creation date to the created tracing session's name.
5333 LTTng writes the traces of a tracing session in
5334 +$LTTNG_HOME/lttng-trace/__name__+ by default, where +__name__+ is the
5335 name of the tracing session. Note that the env:LTTNG_HOME environment
5336 variable defaults to `$HOME` if not set.
5338 To output LTTng traces to a non-default location:
5340 * Use the opt:lttng-create(1):--output option of the man:lttng-create(1) command:
5345 $ lttng create my-session --output=/tmp/some-directory
5349 You may create as many tracing sessions as you wish.
5351 To list all the existing tracing sessions for your Unix user:
5353 * Use the man:lttng-list(1) command:
5362 When you create a tracing session, it is set as the _current tracing
5363 session_. The following man:lttng(1) commands operate on the current
5364 tracing session when you don't specify one:
5366 [role="list-3-cols"]
5383 To change the current tracing session:
5385 * Use the man:lttng-set-session(1) command:
5390 $ lttng set-session new-session
5394 Replace `new-session` by the name of the new current tracing session.
5396 When you are done tracing in a given tracing session, you can destroy
5397 it. This operation frees the resources taken by the tracing session
5398 to destroy; it does not destroy the trace data that LTTng wrote for
5399 this tracing session.
5401 To destroy the current tracing session:
5403 * Use the man:lttng-destroy(1) command:
5412 The man:lttng-destroy(1) command also runs the man:lttng-stop(1)
5413 command implicitly (see <<basic-tracing-session-control,Start and stop a
5414 tracing session>>). You need to stop tracing to make LTTng flush the
5415 remaining trace data and make the trace readable.
5418 [[list-instrumentation-points]]
5419 === List the available instrumentation points
5421 The <<lttng-sessiond,session daemon>> can query the running instrumented
5422 user applications and the Linux kernel to get a list of available
5423 instrumentation points. For the Linux kernel <<domain,tracing domain>>,
5424 they are tracepoints and system calls. For the user space tracing
5425 domain, they are tracepoints. For the other tracing domains, they are
5428 To list the available instrumentation points:
5430 * Use the man:lttng-list(1) command with the requested tracing domain's
5434 * opt:lttng-list(1):--kernel: Linux kernel tracepoints (your Unix user
5435 must be a root user, or it must be a member of the
5436 <<tracing-group,tracing group>>).
5437 * opt:lttng-list(1):--kernel with opt:lttng-list(1):--syscall: Linux
5438 kernel system calls (your Unix user must be a root user, or it must be
5439 a member of the tracing group).
5440 * opt:lttng-list(1):--userspace: user space tracepoints.
5441 * opt:lttng-list(1):--jul: `java.util.logging` loggers.
5442 * opt:lttng-list(1):--log4j: Apache log4j loggers.
5443 * opt:lttng-list(1):--python: Python loggers.
5446 .List the available user space tracepoints.
5450 $ lttng list --userspace
5454 .List the available Linux kernel system call tracepoints.
5458 $ lttng list --kernel --syscall
5463 [[enabling-disabling-events]]
5464 === Create and enable an event rule
5466 Once you <<creating-destroying-tracing-sessions,create a tracing
5467 session>>, you can create <<event,event rules>> with the
5468 man:lttng-enable-event(1) command.
5470 You specify each condition with a command-line option. The available
5471 condition options are shown in the following table.
5473 [role="growable",cols="asciidoc,asciidoc,default"]
5474 .Condition command-line options for the man:lttng-enable-event(1) command.
5476 |Option |Description |Applicable tracing domains
5482 . +--probe=__ADDR__+
5483 . +--function=__ADDR__+
5486 Instead of using the default _tracepoint_ instrumentation type, use:
5488 . A Linux system call.
5489 . A Linux https://lwn.net/Articles/132196/[KProbe] (symbol or address).
5490 . The entry and return points of a Linux function (symbol or address).
5494 |First positional argument.
5497 Tracepoint or system call name. In the case of a Linux KProbe or
5498 function, this is a custom name given to the event rule. With the
5499 JUL, log4j, and Python domains, this is a logger name.
5501 With a tracepoint, logger, or system call name, you can use the special
5502 `*` globbing character to match anything (for example, `sched_*`,
5510 . +--loglevel=__LEVEL__+
5511 . +--loglevel-only=__LEVEL__+
5514 . Match only tracepoints or log statements with a logging level at
5515 least as severe as +__LEVEL__+.
5516 . Match only tracepoints or log statements with a logging level
5517 equal to +__LEVEL__+.
5519 See man:lttng-enable-event(1) for the list of available logging level
5522 |User space, JUL, log4j, and Python.
5524 |+--exclude=__EXCLUSIONS__+
5527 When you use a `*` character at the end of the tracepoint or logger
5528 name (first positional argument), exclude the specific names in the
5529 comma-delimited list +__EXCLUSIONS__+.
5532 User space, JUL, log4j, and Python.
5534 |+--filter=__EXPR__+
5537 Match only events which satisfy the expression +__EXPR__+.
5539 See man:lttng-enable-event(1) to learn more about the syntax of a
5546 You attach an event rule to a <<channel,channel>> on creation. If you do
5547 not specify the channel with the opt:lttng-enable-event(1):--channel
5548 option, and if the event rule to create is the first in its
5549 <<domain,tracing domain>> for a given tracing session, then LTTng
5550 creates a _default channel_ for you. This default channel is reused in
5551 subsequent invocations of the man:lttng-enable-event(1) command for the
5552 same tracing domain.
5554 An event rule is always enabled at creation time.
5556 The following examples show how you can combine the previous
5557 command-line options to create simple to more complex event rules.
5559 .Create an event rule targetting a Linux kernel tracepoint (default channel).
5563 $ lttng enable-event --kernel sched_switch
5567 .Create an event rule matching four Linux kernel system calls (default channel).
5571 $ lttng enable-event --kernel --syscall open,write,read,close
5575 .Create event rules matching tracepoints with filter expressions (default channel).
5579 $ lttng enable-event --kernel sched_switch --filter='prev_comm == "bash"'
5584 $ lttng enable-event --kernel --all \
5585 --filter='$ctx.tid == 1988 || $ctx.tid == 1534'
5590 $ lttng enable-event --jul my_logger \
5591 --filter='$app.retriever:cur_msg_id > 3'
5594 IMPORTANT: Make sure to always quote the filter string when you
5595 use man:lttng(1) from a shell.
5598 .Create an event rule matching any user space tracepoint of a given tracepoint provider with a log level range (default channel).
5602 $ lttng enable-event --userspace my_app:'*' --loglevel=TRACE_INFO
5605 IMPORTANT: Make sure to always quote the wildcard character when you
5606 use man:lttng(1) from a shell.
5609 .Create an event rule matching multiple Python loggers with a wildcard and with exclusions (default channel).
5613 $ lttng enable-event --python my-app.'*' \
5614 --exclude='my-app.module,my-app.hello'
5618 .Create an event rule matching any Apache log4j logger with a specific log level (default channel).
5622 $ lttng enable-event --log4j --all --loglevel-only=LOG4J_WARN
5626 .Create an event rule attached to a specific channel matching a specific user space tracepoint provider and tracepoint.
5630 $ lttng enable-event --userspace my_app:my_tracepoint --channel=my-channel
5634 The event rules of a given channel form a whitelist: as soon as an
5635 emitted event passes one of them, LTTng can record the event. For
5636 example, an event named `my_app:my_tracepoint` emitted from a user space
5637 tracepoint with a `TRACE_ERROR` log level passes both of the following
5642 $ lttng enable-event --userspace my_app:my_tracepoint
5643 $ lttng enable-event --userspace my_app:my_tracepoint \
5644 --loglevel=TRACE_INFO
5647 The second event rule is redundant: the first one includes
5651 [[disable-event-rule]]
5652 === Disable an event rule
5654 To disable an event rule that you <<enabling-disabling-events,created>>
5655 previously, use the man:lttng-disable-event(1) command. This command
5656 disables _all_ the event rules (of a given tracing domain and channel)
5657 which match an instrumentation point. The other conditions are not
5658 supported as of LTTng{nbsp}{revision}.
5660 The LTTng tracer does not record an emitted event which passes
5661 a _disabled_ event rule.
5663 .Disable an event rule matching a Python logger (default channel).
5667 $ lttng disable-event --python my-logger
5671 .Disable an event rule matching all `java.util.logging` loggers (default channel).
5675 $ lttng disable-event --jul '*'
5679 .Disable _all_ the event rules of the default channel.
5681 The opt:lttng-disable-event(1):--all-events option is not, like the
5682 opt:lttng-enable-event(1):--all option of man:lttng-enable-event(1), the
5683 equivalent of the event name `*` (wildcard): it disables _all_ the event
5684 rules of a given channel.
5688 $ lttng disable-event --jul --all-events
5692 NOTE: You cannot delete an event rule once you create it.
5696 === Get the status of a tracing session
5698 To get the status of the current tracing session, that is, its
5699 parameters, its channels, event rules, and their attributes:
5701 * Use the man:lttng-status(1) command:
5711 To get the status of any tracing session:
5713 * Use the man:lttng-list(1) command with the tracing session's name:
5718 $ lttng list my-session
5722 Replace `my-session` with the desired tracing session's name.
5725 [[basic-tracing-session-control]]
5726 === Start and stop a tracing session
5728 Once you <<creating-destroying-tracing-sessions,create a tracing
5730 <<enabling-disabling-events,create one or more event rules>>,
5731 you can start and stop the tracers for this tracing session.
5733 To start tracing in the current tracing session:
5735 * Use the man:lttng-start(1) command:
5744 LTTng is very flexible: you can launch user applications before
5745 or after the you start the tracers. The tracers only record the events
5746 if they pass enabled event rules and if they occur while the tracers are
5749 To stop tracing in the current tracing session:
5751 * Use the man:lttng-stop(1) command:
5760 If there were <<channel-overwrite-mode-vs-discard-mode,lost event
5761 records>> or lost sub-buffers since the last time you ran
5762 man:lttng-start(1), warnings are printed when you run the
5763 man:lttng-stop(1) command.
5765 IMPORTANT: You need to stop tracing to make LTTng flush the remaining
5766 trace data and make the trace readable. Note that the
5767 man:lttng-destroy(1) command (see
5768 <<creating-destroying-tracing-sessions,Create and destroy a tracing
5769 session>>) also runs the man:lttng-stop(1) command implicitly.
5772 [[enabling-disabling-channels]]
5773 === Create a channel
5775 Once you create a tracing session, you can create a <<channel,channel>>
5776 with the man:lttng-enable-channel(1) command.
5778 Note that LTTng automatically creates a default channel when, for a
5779 given <<domain,tracing domain>>, no channels exist and you
5780 <<enabling-disabling-events,create>> the first event rule. This default
5781 channel is named `channel0` and its attributes are set to reasonable
5782 values. Therefore, you only need to create a channel when you need
5783 non-default attributes.
5785 You specify each non-default channel attribute with a command-line
5786 option when you use the man:lttng-enable-channel(1) command. The
5787 available command-line options are:
5789 [role="growable",cols="asciidoc,asciidoc"]
5790 .Command-line options for the man:lttng-enable-channel(1) command.
5792 |Option |Description
5798 <<channel-overwrite-mode-vs-discard-mode,event loss mode>> instead of
5799 the default _discard_ mode.
5801 |`--buffers-pid` (user space tracing domain only)
5804 Use the per-process <<channel-buffering-schemes,buffering scheme>>
5805 instead of the default per-user buffering scheme.
5807 |+--subbuf-size=__SIZE__+
5810 Allocate sub-buffers of +__SIZE__+ bytes (power of two), for each CPU,
5811 either for each Unix user (default), or for each instrumented process.
5813 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
5815 |+--num-subbuf=__COUNT__+
5818 Allocate +__COUNT__+ sub-buffers (power of two), for each CPU, either
5819 for each Unix user (default), or for each instrumented process.
5821 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
5823 |+--tracefile-size=__SIZE__+
5826 Set the maximum size of each trace file that this channel writes within
5827 a stream to +__SIZE__+ bytes instead of no maximum.
5829 See <<tracefile-rotation,Trace file count and size>>.
5831 |+--tracefile-count=__COUNT__+
5834 Limit the number of trace files that this channel creates to
5835 +__COUNT__+ channels instead of no limit.
5837 See <<tracefile-rotation,Trace file count and size>>.
5839 |+--switch-timer=__PERIODUS__+
5842 Set the <<channel-switch-timer,switch timer period>>
5843 to +__PERIODUS__+{nbsp}µs.
5845 |+--read-timer=__PERIODUS__+
5848 Set the <<channel-read-timer,read timer period>>
5849 to +__PERIODUS__+{nbsp}µs.
5851 |[[opt-blocking-timeout]]+--blocking-timeout=__TIMEOUTUS__+
5854 Set the timeout of user space applications which load LTTng-UST
5855 in blocking mode to +__TIMEOUTUS__+:
5858 Never block (non-blocking mode).
5861 Block forever until space is available in a sub-buffer to record
5864 __n__, a positive value::
5865 Wait for at most __n__ µs when trying to write into a sub-buffer.
5867 Note that, for this option to have any effect on an instrumented
5868 user space application, you need to run the application with a set
5869 env:LTTNG_UST_ALLOW_BLOCKING environment variable.
5871 |+--output=__TYPE__+ (Linux kernel tracing domain only)
5874 Set the channel's output type to +__TYPE__+, either `mmap` or `splice`.
5878 You can only create a channel in the Linux kernel and user space
5879 <<domain,tracing domains>>: other tracing domains have their own channel
5880 created on the fly when <<enabling-disabling-events,creating event
5885 Because of a current LTTng limitation, you must create all channels
5886 _before_ you <<basic-tracing-session-control,start tracing>> in a given
5887 tracing session, that is, before the first time you run
5890 Since LTTng automatically creates a default channel when you use the
5891 man:lttng-enable-event(1) command with a specific tracing domain, you
5892 cannot, for example, create a Linux kernel event rule, start tracing,
5893 and then create a user space event rule, because no user space channel
5894 exists yet and it's too late to create one.
5896 For this reason, make sure to configure your channels properly
5897 before starting the tracers for the first time!
5900 The following examples show how you can combine the previous
5901 command-line options to create simple to more complex channels.
5903 .Create a Linux kernel channel with default attributes.
5907 $ lttng enable-channel --kernel my-channel
5911 .Create a user space channel with 4 sub-buffers or 1{nbsp}MiB each, per CPU, per instrumented process.
5915 $ lttng enable-channel --userspace --num-subbuf=4 --subbuf-size=1M \
5916 --buffers-pid my-channel
5920 .[[blocking-timeout-example]]Create a default user space channel with an infinite blocking timeout.
5922 <<creating-destroying-tracing-sessions,Create a tracing-session>>,
5923 create the channel, <<enabling-disabling-events,create an event rule>>,
5924 and <<basic-tracing-session-control,start tracing>>:
5929 $ lttng enable-channel --userspace --blocking-timeout=inf blocking-channel
5930 $ lttng enable-event --userspace --channel=blocking-channel --all
5934 Run an application instrumented with LTTng-UST and allow it to block:
5938 $ LTTNG_UST_ALLOW_BLOCKING=1 my-app
5942 .Create a Linux kernel channel which rotates 8 trace files of 4{nbsp}MiB each for each stream
5946 $ lttng enable-channel --kernel --tracefile-count=8 \
5947 --tracefile-size=4194304 my-channel
5951 .Create a user space channel in overwrite (or _flight recorder_) mode.
5955 $ lttng enable-channel --userspace --overwrite my-channel
5959 You can <<enabling-disabling-events,create>> the same event rule in
5960 two different channels:
5964 $ lttng enable-event --userspace --channel=my-channel app:tp
5965 $ lttng enable-event --userspace --channel=other-channel app:tp
5968 If both channels are enabled, when a tracepoint named `app:tp` is
5969 reached, LTTng records two events, one for each channel.
5973 === Disable a channel
5975 To disable a specific channel that you <<enabling-disabling-channels,created>>
5976 previously, use the man:lttng-disable-channel(1) command.
5978 .Disable a specific Linux kernel channel.
5982 $ lttng disable-channel --kernel my-channel
5986 The state of a channel precedes the individual states of event rules
5987 attached to it: event rules which belong to a disabled channel, even if
5988 they are enabled, are also considered disabled.
5992 === Add context fields to a channel
5994 Event record fields in trace files provide important information about
5995 events that occured previously, but sometimes some external context may
5996 help you solve a problem faster. Examples of context fields are:
5998 * The **process ID**, **thread ID**, **process name**, and
5999 **process priority** of the thread in which the event occurs.
6000 * The **hostname** of the system on which the event occurs.
6001 * The current values of many possible **performance counters** using
6003 ** CPU cycles, stalled cycles, idle cycles, and the other cycle types.
6005 ** Branch instructions, misses, and loads.
6007 * Any context defined at the application level (supported for the
6008 JUL and log4j <<domain,tracing domains>>).
6010 To get the full list of available context fields, see
6011 `lttng add-context --list`. Some context fields are reserved for a
6012 specific <<domain,tracing domain>> (Linux kernel or user space).
6014 You add context fields to <<channel,channels>>. All the events
6015 that a channel with added context fields records contain those fields.
6017 To add context fields to one or all the channels of a given tracing
6020 * Use the man:lttng-add-context(1) command.
6022 .Add context fields to all the channels of the current tracing session.
6024 The following command line adds the virtual process identifier and
6025 the per-thread CPU cycles count fields to all the user space channels
6026 of the current tracing session.
6030 $ lttng add-context --userspace --type=vpid --type=perf:thread:cpu-cycles
6034 .Add performance counter context fields by raw ID
6036 See man:lttng-add-context(1) for the exact format of the context field
6037 type, which is partly compatible with the format used in
6042 $ lttng add-context --userspace --type=perf:thread:raw:r0110:test
6043 $ lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted
6047 .Add a context field to a specific channel.
6049 The following command line adds the thread identifier context field
6050 to the Linux kernel channel named `my-channel` in the current
6055 $ lttng add-context --kernel --channel=my-channel --type=tid
6059 .Add an application-specific context field to a specific channel.
6061 The following command line adds the `cur_msg_id` context field of the
6062 `retriever` context retriever for all the instrumented
6063 <<java-application,Java applications>> recording <<event,event records>>
6064 in the channel named `my-channel`:
6068 $ lttng add-context --kernel --channel=my-channel \
6069 --type='$app:retriever:cur_msg_id'
6072 IMPORTANT: Make sure to always quote the `$` character when you
6073 use man:lttng-add-context(1) from a shell.
6076 NOTE: You cannot remove context fields from a channel once you add it.
6081 === Track process IDs
6083 It's often useful to allow only specific process IDs (PIDs) to emit
6084 events. For example, you may wish to record all the system calls made by
6085 a given process (Ă la http://linux.die.net/man/1/strace[strace]).
6087 The man:lttng-track(1) and man:lttng-untrack(1) commands serve this
6088 purpose. Both commands operate on a whitelist of process IDs. You _add_
6089 entries to this whitelist with the man:lttng-track(1) command and remove
6090 entries with the man:lttng-untrack(1) command. Any process which has one
6091 of the PIDs in the whitelist is allowed to emit LTTng events which pass
6092 an enabled <<event,event rule>>.
6094 NOTE: The PID tracker tracks the _numeric process IDs_. Should a
6095 process with a given tracked ID exit and another process be given this
6096 ID, then the latter would also be allowed to emit events.
6098 .Track and untrack process IDs.
6100 For the sake of the following example, assume the target system has 16
6104 <<creating-destroying-tracing-sessions,create a tracing session>>,
6105 the whitelist contains all the possible PIDs:
6108 .All PIDs are tracked.
6109 image::track-all.png[]
6111 When the whitelist is full and you use the man:lttng-track(1) command to
6112 specify some PIDs to track, LTTng first clears the whitelist, then it
6113 tracks the specific PIDs. After:
6117 $ lttng track --pid=3,4,7,10,13
6123 .PIDs 3, 4, 7, 10, and 13 are tracked.
6124 image::track-3-4-7-10-13.png[]
6126 You can add more PIDs to the whitelist afterwards:
6130 $ lttng track --pid=1,15,16
6136 .PIDs 1, 15, and 16 are added to the whitelist.
6137 image::track-1-3-4-7-10-13-15-16.png[]
6139 The man:lttng-untrack(1) command removes entries from the PID tracker's
6140 whitelist. Given the previous example, the following command:
6144 $ lttng untrack --pid=3,7,10,13
6147 leads to this whitelist:
6150 .PIDs 3, 7, 10, and 13 are removed from the whitelist.
6151 image::track-1-4-15-16.png[]
6153 LTTng can track all possible PIDs again using the
6154 opt:lttng-track(1):--all option:
6158 $ lttng track --pid --all
6161 The result is, again:
6164 .All PIDs are tracked.
6165 image::track-all.png[]
6168 .Track only specific PIDs
6170 A very typical use case with PID tracking is to start with an empty
6171 whitelist, then <<basic-tracing-session-control,start the tracers>>, and
6172 then add PIDs manually while tracers are active. You can accomplish this
6173 by using the opt:lttng-untrack(1):--all option of the
6174 man:lttng-untrack(1) command to clear the whitelist after you
6175 <<creating-destroying-tracing-sessions,create a tracing session>>:
6179 $ lttng untrack --pid --all
6185 .No PIDs are tracked.
6186 image::untrack-all.png[]
6188 If you trace with this whitelist configuration, the tracer records no
6189 events for this <<domain,tracing domain>> because no processes are
6190 tracked. You can use the man:lttng-track(1) command as usual to track
6191 specific PIDs, for example:
6195 $ lttng track --pid=6,11
6201 .PIDs 6 and 11 are tracked.
6202 image::track-6-11.png[]
6207 [[saving-loading-tracing-session]]
6208 === Save and load tracing session configurations
6210 Configuring a <<tracing-session,tracing session>> can be long. Some of
6211 the tasks involved are:
6213 * <<enabling-disabling-channels,Create channels>> with
6214 specific attributes.
6215 * <<adding-context,Add context fields>> to specific channels.
6216 * <<enabling-disabling-events,Create event rules>> with specific log
6217 level and filter conditions.
6219 If you use LTTng to solve real world problems, chances are you have to
6220 record events using the same tracing session setup over and over,
6221 modifying a few variables each time in your instrumented program
6222 or environment. To avoid constant tracing session reconfiguration,
6223 the man:lttng(1) command-line tool can save and load tracing session
6224 configurations to/from XML files.
6226 To save a given tracing session configuration:
6228 * Use the man:lttng-save(1) command:
6233 $ lttng save my-session
6237 Replace `my-session` with the name of the tracing session to save.
6239 LTTng saves tracing session configurations to
6240 dir:{$LTTNG_HOME/.lttng/sessions} by default. Note that the
6241 env:LTTNG_HOME environment variable defaults to `$HOME` if not set. Use
6242 the opt:lttng-save(1):--output-path option to change this destination
6245 LTTng saves all configuration parameters, for example:
6247 * The tracing session name.
6248 * The trace data output path.
6249 * The channels with their state and all their attributes.
6250 * The context fields you added to channels.
6251 * The event rules with their state, log level and filter conditions.
6253 To load a tracing session:
6255 * Use the man:lttng-load(1) command:
6260 $ lttng load my-session
6264 Replace `my-session` with the name of the tracing session to load.
6266 When LTTng loads a configuration, it restores your saved tracing session
6267 as if you just configured it manually.
6269 See man:lttng(1) for the complete list of command-line options. You
6270 can also save and load all many sessions at a time, and decide in which
6271 directory to output the XML files.
6274 [[sending-trace-data-over-the-network]]
6275 === Send trace data over the network
6277 LTTng can send the recorded trace data to a remote system over the
6278 network instead of writing it to the local file system.
6280 To send the trace data over the network:
6282 . On the _remote_ system (which can also be the target system),
6283 start an LTTng <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)):
6292 . On the _target_ system, create a tracing session configured to
6293 send trace data over the network:
6298 $ lttng create my-session --set-url=net://remote-system
6302 Replace `remote-system` by the host name or IP address of the
6303 remote system. See man:lttng-create(1) for the exact URL format.
6305 . On the target system, use the man:lttng(1) command-line tool as usual.
6306 When tracing is active, the target's consumer daemon sends sub-buffers
6307 to the relay daemon running on the remote system instead of flushing
6308 them to the local file system. The relay daemon writes the received
6309 packets to the local file system.
6311 The relay daemon writes trace files to
6312 +$LTTNG_HOME/lttng-traces/__hostname__/__session__+ by default, where
6313 +__hostname__+ is the host name of the target system and +__session__+
6314 is the tracing session name. Note that the env:LTTNG_HOME environment
6315 variable defaults to `$HOME` if not set. Use the
6316 opt:lttng-relayd(8):--output option of man:lttng-relayd(8) to write
6317 trace files to another base directory.
6322 === View events as LTTng emits them (noch:{LTTng} live)
6324 LTTng live is a network protocol implemented by the <<lttng-relayd,relay
6325 daemon>> (man:lttng-relayd(8)) to allow compatible trace viewers to
6326 display events as LTTng emits them on the target system while tracing is
6329 The relay daemon creates a _tee_: it forwards the trace data to both
6330 the local file system and to connected live viewers:
6333 .The relay daemon creates a _tee_, forwarding the trace data to both trace files and a connected live viewer.
6338 . On the _target system_, create a <<tracing-session,tracing session>>
6344 $ lttng create my-session --live
6348 This spawns a local relay daemon.
6350 . Start the live viewer and configure it to connect to the relay
6351 daemon. For example, with http://diamon.org/babeltrace[Babeltrace]:
6356 $ babeltrace --input-format=lttng-live \
6357 net://localhost/host/hostname/my-session
6364 * `hostname` with the host name of the target system.
6365 * `my-session` with the name of the tracing session to view.
6368 . Configure the tracing session as usual with the man:lttng(1)
6369 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6371 You can list the available live tracing sessions with Babeltrace:
6375 $ babeltrace --input-format=lttng-live net://localhost
6378 You can start the relay daemon on another system. In this case, you need
6379 to specify the relay daemon's URL when you create the tracing session
6380 with the opt:lttng-create(1):--set-url option. You also need to replace
6381 `localhost` in the procedure above with the host name of the system on
6382 which the relay daemon is running.
6384 See man:lttng-create(1) and man:lttng-relayd(8) for the complete list of
6385 command-line options.
6389 [[taking-a-snapshot]]
6390 === Take a snapshot of the current sub-buffers of a tracing session
6392 The normal behavior of LTTng is to append full sub-buffers to growing
6393 trace data files. This is ideal to keep a full history of the events
6394 that occurred on the target system, but it can
6395 represent too much data in some situations. For example, you may wish
6396 to trace your application continuously until some critical situation
6397 happens, in which case you only need the latest few recorded
6398 events to perform the desired analysis, not multi-gigabyte trace files.
6400 With the man:lttng-snapshot(1) command, you can take a snapshot of the
6401 current sub-buffers of a given <<tracing-session,tracing session>>.
6402 LTTng can write the snapshot to the local file system or send it over
6407 . Create a tracing session in _snapshot mode_:
6412 $ lttng create my-session --snapshot
6416 The <<channel-overwrite-mode-vs-discard-mode,event loss mode>> of
6417 <<channel,channels>> created in this mode is automatically set to
6418 _overwrite_ (flight recorder mode).
6420 . Configure the tracing session as usual with the man:lttng(1)
6421 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6423 . **Optional**: When you need to take a snapshot,
6424 <<basic-tracing-session-control,stop tracing>>.
6426 You can take a snapshot when the tracers are active, but if you stop
6427 them first, you are sure that the data in the sub-buffers does not
6428 change before you actually take the snapshot.
6435 $ lttng snapshot record --name=my-first-snapshot
6439 LTTng writes the current sub-buffers of all the current tracing
6440 session's channels to trace files on the local file system. Those trace
6441 files have `my-first-snapshot` in their name.
6443 There is no difference between the format of a normal trace file and the
6444 format of a snapshot: viewers of LTTng traces also support LTTng
6447 By default, LTTng writes snapshot files to the path shown by
6448 `lttng snapshot list-output`. You can change this path or decide to send
6449 snapshots over the network using either:
6451 . An output path or URL that you specify when you create the
6453 . An snapshot output path or URL that you add using
6454 `lttng snapshot add-output`
6455 . An output path or URL that you provide directly to the
6456 `lttng snapshot record` command.
6458 Method 3 overrides method 2, which overrides method 1. When you
6459 specify a URL, a relay daemon must listen on a remote system (see
6460 <<sending-trace-data-over-the-network,Send trace data over the network>>).
6465 === Use the machine interface
6467 With any command of the man:lttng(1) command-line tool, you can set the
6468 opt:lttng(1):--mi option to `xml` (before the command name) to get an
6469 XML machine interface output, for example:
6473 $ lttng --mi=xml enable-event --kernel --syscall open
6476 A schema definition (XSD) is
6477 https://github.com/lttng/lttng-tools/blob/stable-2.10/src/common/mi-lttng-3.0.xsd[available]
6478 to ease the integration with external tools as much as possible.
6482 [[metadata-regenerate]]
6483 === Regenerate the metadata of an LTTng trace
6485 An LTTng trace, which is a http://diamon.org/ctf[CTF] trace, has both
6486 data stream files and a metadata file. This metadata file contains,
6487 amongst other things, information about the offset of the clock sources
6488 used to timestamp <<event,event records>> when tracing.
6490 If, once a <<tracing-session,tracing session>> is
6491 <<basic-tracing-session-control,started>>, a major
6492 https://en.wikipedia.org/wiki/Network_Time_Protocol[NTP] correction
6493 happens, the trace's clock offset also needs to be updated. You
6494 can use the `metadata` item of the man:lttng-regenerate(1) command
6497 The main use case of this command is to allow a system to boot with
6498 an incorrect wall time and trace it with LTTng before its wall time
6499 is corrected. Once the system is known to be in a state where its
6500 wall time is correct, it can run `lttng regenerate metadata`.
6502 To regenerate the metadata of an LTTng trace:
6504 * Use the `metadata` item of the man:lttng-regenerate(1) command:
6509 $ lttng regenerate metadata
6515 `lttng regenerate metadata` has the following limitations:
6517 * Tracing session <<creating-destroying-tracing-sessions,created>>
6519 * User space <<channel,channels>>, if any, are using
6520 <<channel-buffering-schemes,per-user buffering>>.
6525 [[regenerate-statedump]]
6526 === Regenerate the state dump of a tracing session
6528 The LTTng kernel and user space tracers generate state dump
6529 <<event,event records>> when the application starts or when you
6530 <<basic-tracing-session-control,start a tracing session>>. An analysis
6531 can use the state dump event records to set an initial state before it
6532 builds the rest of the state from the following event records.
6533 http://tracecompass.org/[Trace Compass] is a notable example of an
6534 application which uses the state dump of an LTTng trace.
6536 When you <<taking-a-snapshot,take a snapshot>>, it's possible that the
6537 state dump event records are not included in the snapshot because they
6538 were recorded to a sub-buffer that has been consumed or overwritten
6541 You can use the `lttng regenerate statedump` command to emit the state
6542 dump event records again.
6544 To regenerate the state dump of the current tracing session, provided
6545 create it in snapshot mode, before you take a snapshot:
6547 . Use the `statedump` item of the man:lttng-regenerate(1) command:
6552 $ lttng regenerate statedump
6556 . <<basic-tracing-session-control,Stop the tracing session>>:
6565 . <<taking-a-snapshot,Take a snapshot>>:
6570 $ lttng snapshot record --name=my-snapshot
6574 Depending on the event throughput, you should run steps 1 and 2
6575 as closely as possible.
6577 NOTE: To record the state dump events, you need to
6578 <<enabling-disabling-events,create event rules>> which enable them.
6579 LTTng-UST state dump tracepoints start with `lttng_ust_statedump:`.
6580 LTTng-modules state dump tracepoints start with `lttng_statedump_`.
6584 [[persistent-memory-file-systems]]
6585 === Record trace data on persistent memory file systems
6587 https://en.wikipedia.org/wiki/Non-volatile_random-access_memory[Non-volatile random-access memory]
6588 (NVRAM) is random-access memory that retains its information when power
6589 is turned off (non-volatile). Systems with such memory can store data
6590 structures in RAM and retrieve them after a reboot, without flushing
6591 to typical _storage_.
6593 Linux supports NVRAM file systems thanks to either
6594 http://pramfs.sourceforge.net/[PRAMFS] or
6595 https://www.kernel.org/doc/Documentation/filesystems/dax.txt[DAX]{nbsp}+{nbsp}http://lkml.iu.edu/hypermail/linux/kernel/1504.1/03463.html[pmem]
6596 (requires Linux 4.1+).
6598 This section does not describe how to operate such file systems;
6599 we assume that you have a working persistent memory file system.
6601 When you create a <<tracing-session,tracing session>>, you can specify
6602 the path of the shared memory holding the sub-buffers. If you specify a
6603 location on an NVRAM file system, then you can retrieve the latest
6604 recorded trace data when the system reboots after a crash.
6606 To record trace data on a persistent memory file system and retrieve the
6607 trace data after a system crash:
6609 . Create a tracing session with a sub-buffer shared memory path located
6610 on an NVRAM file system:
6615 $ lttng create my-session --shm-path=/path/to/shm
6619 . Configure the tracing session as usual with the man:lttng(1)
6620 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6622 . After a system crash, use the man:lttng-crash(1) command-line tool to
6623 view the trace data recorded on the NVRAM file system:
6628 $ lttng-crash /path/to/shm
6632 The binary layout of the ring buffer files is not exactly the same as
6633 the trace files layout. This is why you need to use man:lttng-crash(1)
6634 instead of your preferred trace viewer directly.
6636 To convert the ring buffer files to LTTng trace files:
6638 * Use the opt:lttng-crash(1):--extract option of man:lttng-crash(1):
6643 $ lttng-crash --extract=/path/to/trace /path/to/shm
6649 [[notif-trigger-api]]
6650 === Get notified when a channel's buffer usage is too high or too low
6652 With LTTng's $$C/C++$$ notification and trigger API, your user
6653 application can get notified when the buffer usage of one or more
6654 <<channel,channels>> becomes too low or too high. You can use this API
6655 and enable or disable <<event,event rules>> during tracing to avoid
6656 <<channel-overwrite-mode-vs-discard-mode,discarded event records>>.
6658 .Have a user application get notified when an LTTng channel's buffer usage is too high.
6660 In this example, we create and build an application which gets notified
6661 when the buffer usage of a specific LTTng channel is higher than
6662 75{nbsp}%. We only print that it is the case in the example, but we
6663 could as well use the API of <<liblttng-ctl-lttng,`liblttng-ctl`>> to
6664 disable event rules when this happens.
6666 . Create the application's C source file:
6674 #include <lttng/domain.h>
6675 #include <lttng/action/action.h>
6676 #include <lttng/action/notify.h>
6677 #include <lttng/condition/condition.h>
6678 #include <lttng/condition/buffer-usage.h>
6679 #include <lttng/condition/evaluation.h>
6680 #include <lttng/notification/channel.h>
6681 #include <lttng/notification/notification.h>
6682 #include <lttng/trigger/trigger.h>
6683 #include <lttng/endpoint.h>
6685 int main(int argc, char *argv[])
6687 int exit_status = 0;
6688 struct lttng_notification_channel *notification_channel;
6689 struct lttng_condition *condition;
6690 struct lttng_action *action;
6691 struct lttng_trigger *trigger;
6692 const char *tracing_session_name;
6693 const char *channel_name;
6696 tracing_session_name = argv[1];
6697 channel_name = argv[2];
6700 * Create a notification channel. A notification channel
6701 * connects the user application to the LTTng session daemon.
6702 * This notification channel can be used to listen to various
6703 * types of notifications.
6705 notification_channel = lttng_notification_channel_create(
6706 lttng_session_daemon_notification_endpoint);
6709 * Create a "high buffer usage" condition. In this case, the
6710 * condition is reached when the buffer usage is greater than or
6711 * equal to 75 %. We create the condition for a specific tracing
6712 * session name, channel name, and for the user space tracing
6715 * The "low buffer usage" condition type also exists.
6717 condition = lttng_condition_buffer_usage_high_create();
6718 lttng_condition_buffer_usage_set_threshold_ratio(condition, .75);
6719 lttng_condition_buffer_usage_set_session_name(
6720 condition, tracing_session_name);
6721 lttng_condition_buffer_usage_set_channel_name(condition,
6723 lttng_condition_buffer_usage_set_domain_type(condition,
6727 * Create an action (get a notification) to take when the
6728 * condition created above is reached.
6730 action = lttng_action_notify_create();
6733 * Create a trigger. A trigger associates a condition to an
6734 * action: the action is executed when the condition is reached.
6736 trigger = lttng_trigger_create(condition, action);
6738 /* Register the trigger to LTTng. */
6739 lttng_register_trigger(trigger);
6742 * Now that we have registered a trigger, a notification will be
6743 * emitted everytime its condition is met. To receive this
6744 * notification, we must subscribe to notifications that match
6745 * the same condition.
6747 lttng_notification_channel_subscribe(notification_channel,
6751 * Notification loop. You can put this in a dedicated thread to
6752 * avoid blocking the main thread.
6755 struct lttng_notification *notification;
6756 enum lttng_notification_channel_status status;
6757 const struct lttng_evaluation *notification_evaluation;
6758 const struct lttng_condition *notification_condition;
6759 double buffer_usage;
6761 /* Receive the next notification. */
6762 status = lttng_notification_channel_get_next_notification(
6763 notification_channel, ¬ification);
6766 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK:
6768 case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED:
6770 * The session daemon can drop notifications if
6771 * a monitoring application is not consuming the
6772 * notifications fast enough.
6775 case LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED:
6777 * The notification channel has been closed by the
6778 * session daemon. This is typically caused by a session
6779 * daemon shutting down.
6783 /* Unhandled conditions or errors. */
6789 * A notification provides, amongst other things:
6791 * * The condition that caused this notification to be
6793 * * The condition evaluation, which provides more
6794 * specific information on the evaluation of the
6797 * The condition evaluation provides the buffer usage
6798 * value at the moment the condition was reached.
6800 notification_condition = lttng_notification_get_condition(
6802 notification_evaluation = lttng_notification_get_evaluation(
6805 /* We're subscribed to only one condition. */
6806 assert(lttng_condition_get_type(notification_condition) ==
6807 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH);
6810 * Get the exact sampled buffer usage from the
6811 * condition evaluation.
6813 lttng_evaluation_buffer_usage_get_usage_ratio(
6814 notification_evaluation, &buffer_usage);
6817 * At this point, instead of printing a message, we
6818 * could do something to reduce the channel's buffer
6819 * usage, like disable specific events.
6821 printf("Buffer usage is %f %% in tracing session \"%s\", "
6822 "user space channel \"%s\".\n", buffer_usage * 100,
6823 tracing_session_name, channel_name);
6824 lttng_notification_destroy(notification);
6828 lttng_action_destroy(action);
6829 lttng_condition_destroy(condition);
6830 lttng_trigger_destroy(trigger);
6831 lttng_notification_channel_destroy(notification_channel);
6837 . Build the `notif-app` application, linking it to `liblttng-ctl`:
6842 $ gcc -o notif-app notif-app.c -llttng-ctl
6846 . <<creating-destroying-tracing-sessions,Create a tracing session>>,
6847 <<enabling-disabling-events,create an event rule>> matching all the
6848 user space tracepoints, and
6849 <<basic-tracing-session-control,start tracing>>:
6854 $ lttng create my-session
6855 $ lttng enable-event --userspace --all
6860 If you create the channel manually with the man:lttng-enable-channel(1)
6861 command, you can control how frequently are the current values of the
6862 channel's properties sampled to evaluate user conditions with the
6863 opt:lttng-enable-channel(1):--monitor-timer option.
6865 . Run the `notif-app` application. This program accepts the
6866 <<tracing-session,tracing session>> name and the user space channel
6867 name as its two first arguments. The channel which LTTng automatically
6868 creates with the man:lttng-enable-event(1) command above is named
6874 $ ./notif-app my-session channel0
6878 . In another terminal, run an application with a very high event
6879 throughput so that the 75{nbsp}% buffer usage condition is reached.
6881 In the first terminal, the application should print lines like this:
6884 Buffer usage is 81.45197 % in tracing session "my-session", user space
6888 If you don't see anything, try modifying the condition in
6889 path:{notif-app.c} to a lower value (0.1, for example), rebuilding it
6890 (step 2) and running it again (step 4).
6897 [[lttng-modules-ref]]
6898 === noch:{LTTng-modules}
6902 [[lttng-tracepoint-enum]]
6903 ==== `LTTNG_TRACEPOINT_ENUM()` usage
6905 Use the `LTTNG_TRACEPOINT_ENUM()` macro to define an enumeration:
6909 LTTNG_TRACEPOINT_ENUM(name, TP_ENUM_VALUES(entries))
6914 * `name` with the name of the enumeration (C identifier, unique
6915 amongst all the defined enumerations).
6916 * `entries` with a list of enumeration entries.
6918 The available enumeration entry macros are:
6920 +ctf_enum_value(__name__, __value__)+::
6921 Entry named +__name__+ mapped to the integral value +__value__+.
6923 +ctf_enum_range(__name__, __begin__, __end__)+::
6924 Entry named +__name__+ mapped to the range of integral values between
6925 +__begin__+ (included) and +__end__+ (included).
6927 +ctf_enum_auto(__name__)+::
6928 Entry named +__name__+ mapped to the integral value following the
6929 last mapping's value.
6931 The last value of a `ctf_enum_value()` entry is its +__value__+
6934 The last value of a `ctf_enum_range()` entry is its +__end__+ parameter.
6936 If `ctf_enum_auto()` is the first entry in the list, its integral
6939 Use the `ctf_enum()` <<lttng-modules-tp-fields,field definition macro>>
6940 to use a defined enumeration as a tracepoint field.
6942 .Define an enumeration with `LTTNG_TRACEPOINT_ENUM()`.
6946 LTTNG_TRACEPOINT_ENUM(
6949 ctf_enum_auto("AUTO: EXPECT 0")
6950 ctf_enum_value("VALUE: 23", 23)
6951 ctf_enum_value("VALUE: 27", 27)
6952 ctf_enum_auto("AUTO: EXPECT 28")
6953 ctf_enum_range("RANGE: 101 TO 303", 101, 303)
6954 ctf_enum_auto("AUTO: EXPECT 304")
6962 [[lttng-modules-tp-fields]]
6963 ==== Tracepoint fields macros (for `TP_FIELDS()`)
6965 [[tp-fast-assign]][[tp-struct-entry]]The available macros to define
6966 tracepoint fields, which must be listed within `TP_FIELDS()` in
6967 `LTTNG_TRACEPOINT_EVENT()`, are:
6969 [role="func-desc growable",cols="asciidoc,asciidoc"]
6970 .Available macros to define LTTng-modules tracepoint fields
6972 |Macro |Description and parameters
6975 +ctf_integer(__t__, __n__, __e__)+
6977 +ctf_integer_nowrite(__t__, __n__, __e__)+
6979 +ctf_user_integer(__t__, __n__, __e__)+
6981 +ctf_user_integer_nowrite(__t__, __n__, __e__)+
6983 Standard integer, displayed in base 10.
6986 Integer C type (`int`, `long`, `size_t`, ...).
6992 Argument expression.
6995 +ctf_integer_hex(__t__, __n__, __e__)+
6997 +ctf_user_integer_hex(__t__, __n__, __e__)+
6999 Standard integer, displayed in base 16.
7008 Argument expression.
7010 |+ctf_integer_oct(__t__, __n__, __e__)+
7012 Standard integer, displayed in base 8.
7021 Argument expression.
7024 +ctf_integer_network(__t__, __n__, __e__)+
7026 +ctf_user_integer_network(__t__, __n__, __e__)+
7028 Integer in network byte order (big-endian), displayed in base 10.
7037 Argument expression.
7040 +ctf_integer_network_hex(__t__, __n__, __e__)+
7042 +ctf_user_integer_network_hex(__t__, __n__, __e__)+
7044 Integer in network byte order, displayed in base 16.
7053 Argument expression.
7056 +ctf_enum(__N__, __t__, __n__, __e__)+
7058 +ctf_enum_nowrite(__N__, __t__, __n__, __e__)+
7060 +ctf_user_enum(__N__, __t__, __n__, __e__)+
7062 +ctf_user_enum_nowrite(__N__, __t__, __n__, __e__)+
7067 Name of a <<lttng-tracepoint-enum,previously defined enumeration>>.
7070 Integer C type (`int`, `long`, `size_t`, ...).
7076 Argument expression.
7079 +ctf_string(__n__, __e__)+
7081 +ctf_string_nowrite(__n__, __e__)+
7083 +ctf_user_string(__n__, __e__)+
7085 +ctf_user_string_nowrite(__n__, __e__)+
7087 Null-terminated string; undefined behavior if +__e__+ is `NULL`.
7093 Argument expression.
7096 +ctf_array(__t__, __n__, __e__, __s__)+
7098 +ctf_array_nowrite(__t__, __n__, __e__, __s__)+
7100 +ctf_user_array(__t__, __n__, __e__, __s__)+
7102 +ctf_user_array_nowrite(__t__, __n__, __e__, __s__)+
7104 Statically-sized array of integers.
7107 Array element C type.
7113 Argument expression.
7119 +ctf_array_bitfield(__t__, __n__, __e__, __s__)+
7121 +ctf_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7123 +ctf_user_array_bitfield(__t__, __n__, __e__, __s__)+
7125 +ctf_user_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7127 Statically-sized array of bits.
7129 The type of +__e__+ must be an integer type. +__s__+ is the number
7130 of elements of such type in +__e__+, not the number of bits.
7133 Array element C type.
7139 Argument expression.
7145 +ctf_array_text(__t__, __n__, __e__, __s__)+
7147 +ctf_array_text_nowrite(__t__, __n__, __e__, __s__)+
7149 +ctf_user_array_text(__t__, __n__, __e__, __s__)+
7151 +ctf_user_array_text_nowrite(__t__, __n__, __e__, __s__)+
7153 Statically-sized array, printed as text.
7155 The string does not need to be null-terminated.
7158 Array element C type (always `char`).
7164 Argument expression.
7170 +ctf_sequence(__t__, __n__, __e__, __T__, __E__)+
7172 +ctf_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7174 +ctf_user_sequence(__t__, __n__, __e__, __T__, __E__)+
7176 +ctf_user_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7178 Dynamically-sized array of integers.
7180 The type of +__E__+ must be unsigned.
7183 Array element C type.
7189 Argument expression.
7192 Length expression C type.
7198 +ctf_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7200 +ctf_user_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7202 Dynamically-sized array of integers, displayed in base 16.
7204 The type of +__E__+ must be unsigned.
7207 Array element C type.
7213 Argument expression.
7216 Length expression C type.
7221 |+ctf_sequence_network(__t__, __n__, __e__, __T__, __E__)+
7223 Dynamically-sized array of integers in network byte order (big-endian),
7224 displayed in base 10.
7226 The type of +__E__+ must be unsigned.
7229 Array element C type.
7235 Argument expression.
7238 Length expression C type.
7244 +ctf_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7246 +ctf_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7248 +ctf_user_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7250 +ctf_user_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7252 Dynamically-sized array of bits.
7254 The type of +__e__+ must be an integer type. +__s__+ is the number
7255 of elements of such type in +__e__+, not the number of bits.
7257 The type of +__E__+ must be unsigned.
7260 Array element C type.
7266 Argument expression.
7269 Length expression C type.
7275 +ctf_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7277 +ctf_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7279 +ctf_user_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7281 +ctf_user_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7283 Dynamically-sized array, displayed as text.
7285 The string does not need to be null-terminated.
7287 The type of +__E__+ must be unsigned.
7289 The behaviour is undefined if +__e__+ is `NULL`.
7292 Sequence element C type (always `char`).
7298 Argument expression.
7301 Length expression C type.
7307 Use the `_user` versions when the argument expression, `e`, is
7308 a user space address. In the cases of `ctf_user_integer*()` and
7309 `ctf_user_float*()`, `&e` must be a user space address, thus `e` must
7312 The `_nowrite` versions omit themselves from the session trace, but are
7313 otherwise identical. This means the `_nowrite` fields won't be written
7314 in the recorded trace. Their primary purpose is to make some
7315 of the event context available to the
7316 <<enabling-disabling-events,event filters>> without having to
7317 commit the data to sub-buffers.
7323 Terms related to LTTng and to tracing in general:
7326 The http://diamon.org/babeltrace[Babeltrace] project, which includes
7327 the cmd:babeltrace command, some libraries, and Python bindings.
7329 <<channel-buffering-schemes,buffering scheme>>::
7330 A layout of sub-buffers applied to a given channel.
7332 <<channel,channel>>::
7333 An entity which is responsible for a set of ring buffers.
7335 <<event,Event rules>> are always attached to a specific channel.
7338 A reference of time for a tracer.
7340 <<lttng-consumerd,consumer daemon>>::
7341 A process which is responsible for consuming the full sub-buffers
7342 and write them to a file system or send them over the network.
7344 <<channel-overwrite-mode-vs-discard-mode,discard mode>>:: The event loss
7345 mode in which the tracer _discards_ new event records when there's no
7346 sub-buffer space left to store them.
7349 The consequence of the execution of an instrumentation
7350 point, like a tracepoint that you manually place in some source code,
7351 or a Linux kernel KProbe.
7353 An event is said to _occur_ at a specific time. Different actions can
7354 be taken upon the occurrence of an event, like record the event's payload
7357 <<channel-overwrite-mode-vs-discard-mode,event loss mode>>::
7358 The mechanism by which event records of a given channel are lost
7359 (not recorded) when there is no sub-buffer space left to store them.
7361 [[def-event-name]]event name::
7362 The name of an event, which is also the name of the event record.
7363 This is also called the _instrumentation point name_.
7366 A record, in a trace, of the payload of an event which occured.
7368 <<event,event rule>>::
7369 Set of conditions which must be satisfied for one or more occuring
7370 events to be recorded.
7372 `java.util.logging`::
7374 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[core logging facilities].
7376 <<instrumenting,instrumentation>>::
7377 The use of LTTng probes to make a piece of software traceable.
7379 instrumentation point::
7380 A point in the execution path of a piece of software that, when
7381 reached by this execution, can emit an event.
7383 instrumentation point name::
7384 See _<<def-event-name,event name>>_.
7387 A http://logging.apache.org/log4j/1.2/[logging library] for Java
7388 developed by the Apache Software Foundation.
7391 Level of severity of a log statement or user space
7392 instrumentation point.
7395 The _Linux Trace Toolkit: next generation_ project.
7397 <<lttng-cli,cmd:lttng>>::
7398 A command-line tool provided by the LTTng-tools project which you
7399 can use to send and receive control messages to and from a
7403 The https://github.com/lttng/lttng-analyses[LTTng analyses] project,
7404 which is a set of analyzing programs that are used to obtain a
7405 higher level view of an LTTng trace.
7407 cmd:lttng-consumerd::
7408 The name of the consumer daemon program.
7411 A utility provided by the LTTng-tools project which can convert
7412 ring buffer files (usually
7413 <<persistent-memory-file-systems,saved on a persistent memory file system>>)
7416 LTTng Documentation::
7419 <<lttng-live,LTTng live>>::
7420 A communication protocol between the relay daemon and live viewers
7421 which makes it possible to see events "live", as they are received by
7424 <<lttng-modules,LTTng-modules>>::
7425 The https://github.com/lttng/lttng-modules[LTTng-modules] project,
7426 which contains the Linux kernel modules to make the Linux kernel
7427 instrumentation points available for LTTng tracing.
7430 The name of the relay daemon program.
7432 cmd:lttng-sessiond::
7433 The name of the session daemon program.
7436 The https://github.com/lttng/lttng-tools[LTTng-tools] project, which
7437 contains the various programs and libraries used to
7438 <<controlling-tracing,control tracing>>.
7440 <<lttng-ust,LTTng-UST>>::
7441 The https://github.com/lttng/lttng-ust[LTTng-UST] project, which
7442 contains libraries to instrument user applications.
7444 <<lttng-ust-agents,LTTng-UST Java agent>>::
7445 A Java package provided by the LTTng-UST project to allow the
7446 LTTng instrumentation of `java.util.logging` and Apache log4j 1.2
7449 <<lttng-ust-agents,LTTng-UST Python agent>>::
7450 A Python package provided by the LTTng-UST project to allow the
7451 LTTng instrumentation of Python logging statements.
7453 <<channel-overwrite-mode-vs-discard-mode,overwrite mode>>::
7454 The event loss mode in which new event records overwrite older
7455 event records when there's no sub-buffer space left to store them.
7457 <<channel-buffering-schemes,per-process buffering>>::
7458 A buffering scheme in which each instrumented process has its own
7459 sub-buffers for a given user space channel.
7461 <<channel-buffering-schemes,per-user buffering>>::
7462 A buffering scheme in which all the processes of a Unix user share the
7463 same sub-buffer for a given user space channel.
7465 <<lttng-relayd,relay daemon>>::
7466 A process which is responsible for receiving the trace data sent by
7467 a distant consumer daemon.
7470 A set of sub-buffers.
7472 <<lttng-sessiond,session daemon>>::
7473 A process which receives control commands from you and orchestrates
7474 the tracers and various LTTng daemons.
7476 <<taking-a-snapshot,snapshot>>::
7477 A copy of the current data of all the sub-buffers of a given tracing
7478 session, saved as trace files.
7481 One part of an LTTng ring buffer which contains event records.
7484 The time information attached to an event when it is emitted.
7487 A set of files which are the concatenations of one or more
7488 flushed sub-buffers.
7491 The action of recording the events emitted by an application
7492 or by a system, or to initiate such recording by controlling
7496 The http://tracecompass.org[Trace Compass] project and application.
7499 An instrumentation point using the tracepoint mechanism of the Linux
7500 kernel or of LTTng-UST.
7502 tracepoint definition::
7503 The definition of a single tracepoint.
7506 The name of a tracepoint.
7508 tracepoint provider::
7509 A set of functions providing tracepoints to an instrumented user
7512 Not to be confused with a _tracepoint provider package_: many tracepoint
7513 providers can exist within a tracepoint provider package.
7515 tracepoint provider package::
7516 One or more tracepoint providers compiled as an object file or as
7520 A software which records emitted events.
7522 <<domain,tracing domain>>::
7523 A namespace for event sources.
7525 <<tracing-group,tracing group>>::
7526 The Unix group in which a Unix user can be to be allowed to trace the
7529 <<tracing-session,tracing session>>::
7530 A stateful dialogue between you and a <<lttng-sessiond,session
7534 An application running in user space, as opposed to a Linux kernel
7535 module, for example.