1 The LTTng Documentation
2 =======================
3 Philippe Proulx <pproulx@efficios.com>
7 include::../common/copyright.txt[]
10 include::../common/welcome.txt[]
13 include::../common/audience.txt[]
17 === What's in this documentation?
19 The LTTng Documentation is divided into the following sections:
21 * **<<nuts-and-bolts,Nuts and bolts>>** explains the
22 rudiments of software tracing and the rationale behind the
25 You can skip this section if you’re familiar with software tracing and
26 with the LTTng project.
28 * **<<installing-lttng,Installation>>** describes the steps to
29 install the LTTng packages on common Linux distributions and from
32 You can skip this section if you already properly installed LTTng on
35 * **<<getting-started,Quick start>>** is a concise guide to
36 getting started quickly with LTTng kernel and user space tracing.
38 We recommend this section if you're new to LTTng or to software tracing
41 You can skip this section if you're not new to LTTng.
43 * **<<core-concepts,Core concepts>>** explains the concepts at
46 It's a good idea to become familiar with the core concepts
47 before attempting to use the toolkit.
49 * **<<plumbing,Components of LTTng>>** describes the various components
50 of the LTTng machinery, like the daemons, the libraries, and the
51 command-line interface.
52 * **<<instrumenting,Instrumentation>>** shows different ways to
53 instrument user applications and the Linux kernel.
55 Instrumenting source code is essential to provide a meaningful
58 You can skip this section if you do not have a programming background.
60 * **<<controlling-tracing,Tracing control>>** is divided into topics
61 which demonstrate how to use the vast array of features that
62 LTTng{nbsp}{revision} offers.
63 * **<<reference,Reference>>** contains reference tables.
64 * **<<glossary,Glossary>>** is a specialized dictionary of terms related
65 to LTTng or to the field of software tracing.
68 include::../common/convention.txt[]
71 include::../common/acknowledgements.txt[]
75 == What's new in LTTng {revision}?
77 LTTng{nbsp}{revision} bears the name _Isseki Nicho_. The result of a
78 collaboration between http://www.dieuduciel.com/[Dieu du Ciel!] and
79 Nagano-based Shiga Kogen,
80 https://www.beeradvocate.com/beer/profile/1141/53111/[_**Isseki
81 Nicho**_] is a strong Imperial Dark Saison offering a rich roasted malt
82 flavor combined with a complex fruity finish typical of Saison yeasts.
84 New features and changes in LTTng{nbsp}{revision}:
86 * **Tracing control**:
87 ** You can attach <<java-application-context,Java application-specific
88 context fields>> to a <<channel,channel>> with the
89 man:lttng-add-context(1) command:
94 $ lttng add-context --jul --type='$app.retriever:cur_msg_id'
98 Here, `$app` is the prefix of all application-specific context fields,
99 `retriever` names a _context information retriever_ defined at the
100 application level, and `cur_msg_id` names a context field read from this
103 Both the `java.util.logging` and Apache log4j <<domain,tracing domains>>
106 ** You can use Java application-specific <<adding-context,context>>
107 fields in the <<enabling-disabling-events,filter expression>> of an
108 <<event,event rule>>:
113 $ lttng enable-event --log4j my_logger \
114 --filter='$app.retriever:cur_msg_id == 23'
118 ** New `lttng status` command which is the equivalent of +lttng list
119 __CUR__+, where +__CUR__+ is the name of the current
120 <<tracing-session,tracing session>>.
122 See man:lttng-status(1).
124 ** New `lttng metadata regenerate` command to
125 <<metadata-regenerate,regenerate the metadata file of an LTTng
126 trace>> at any moment. This command is meant to be used to resample
127 the wall time following a major
128 https://en.wikipedia.org/wiki/Network_Time_Protocol[NTP] correction
129 so that a system which boots with an incorrect wall time can be
130 traced before its wall time is NTP-corrected.
132 See man:lttng-metadata(1).
134 ** New command-line interface warnings when <<event,event records>> or
135 whole sub-buffers are
136 <<channel-overwrite-mode-vs-discard-mode,lost>>. The warning messages
137 are printed when a <<tracing-session,tracing session>> is
138 <<basic-tracing-session-control,stopped>> (man:lttng-stop(1)
141 * **User space tracing**:
142 ** Shared object base address dump in order to map <<event,event
143 records>> to original source location (file and line number).
145 If you attach the `ip` and `vpid` <<adding-context,context fields>> to a
146 user space <<channel,channel>> and if you use the
147 <<liblttng-ust-dl,path:{liblttng-ust-dl.so} helper>>, you can retrieve
148 the source location where a given event record was generated.
150 The http://diamon.org/babeltrace/[Babeltrace] trace viewer supports this
151 state dump and those context fields since version 1.4 to print the
152 source location of a given event record. http://tracecompass.org/[Trace
153 Compass] also supports this since version 2.0.
155 ** A <<java-application,Java application>> which uses
156 `java.util.logging` now adds an LTTng-UST log handler to the desired
159 The previous workflow was to initialize the LTTng-UST Java agent
160 by calling `LTTngAgent.getLTTngAgent()`. This had the effect of adding
161 an LTTng-UST log handler to the root loggers.
163 ** A <<java-application,Java application>> which uses Apache log4j now
164 adds an LTTng-UST log appender to the desired log4j loggers.
166 The previous workflow was to initialize the LTTng-UST Java agent
167 by calling `LTTngAgent.getLTTngAgent()`. This had the effect of adding
168 an LTTng-UST appender to the root loggers.
170 ** Any <<java-application,Java application>> can provide
171 <<java-application-context,dynamic context fields>> while running
172 thanks to a new API provided by the <<lttng-ust-agents,LTTng-UST Java
173 agent>>. You can require LTTng to record specific context fields in
174 event records, and you can use them in the filter expression of
175 <<event,event rules>>.
177 * **Linux kernel tracing**:
178 ** The LTTng kernel modules can now be built into a Linux kernel image,
179 that is, not as loadable modules.
182 https://github.com/lttng/lttng-modules/blob/stable-{revision}/README.md#kernel-built-in-support[`README.md`]
185 ** New instrumentation:
186 *** ARM64 architecture support.
188 *** x86 `irq_vectors`.
189 ** New <<adding-context,context fields>>:
192 *** `need_reschedule`
193 *** `migratable` (specific to RT-Preempt)
194 ** Clock source plugin support for advanced cases where a custom source
195 of time is needed to timestamp LTTng event records.
197 See https://github.com/lttng/lttng-modules/blob/stable-{revision}/lttng-clock.h[`lttng-clock.h`]
198 for an overview of the small API.
201 ** The link:/man[man pages] of the man:lttng(1) command-line tool are
202 split into one man page per command (à la Git), for example:
207 $ man lttng-enable-event
211 You can also use the `--help` option of any man:lttng(1) command to
214 The content and formatting of all the LTTng man pages has improved
221 What is LTTng? As its name suggests, the _Linux Trace Toolkit: next
222 generation_ is a modern toolkit for tracing Linux systems and
223 applications. So your first question might be:
230 As the history of software engineering progressed and led to what
231 we now take for granted--complex, numerous and
232 interdependent software applications running in parallel on
233 sophisticated operating systems like Linux--the authors of such
234 components, software developers, began feeling a natural
235 urge to have tools that would ensure the robustness and good performance
236 of their masterpieces.
238 One major achievement in this field is, inarguably, the
239 https://www.gnu.org/software/gdb/[GNU debugger (GDB)],
240 an essential tool for developers to find and fix bugs. But even the best
241 debugger won't help make your software run faster, and nowadays, faster
242 software means either more work done by the same hardware, or cheaper
243 hardware for the same work.
245 A _profiler_ is often the tool of choice to identify performance
246 bottlenecks. Profiling is suitable to identify _where_ performance is
247 lost in a given software. The profiler outputs a profile, a statistical
248 summary of observed events, which you may use to discover which
249 functions took the most time to execute. However, a profiler won't
250 report _why_ some identified functions are the bottleneck. Bottlenecks
251 might only occur when specific conditions are met, conditions that are
252 sometimes impossible to capture by a statistical profiler, or impossible
253 to reproduce with an application altered by the overhead of an
254 event-based profiler. For a thorough investigation of software
255 performance issues, a history of execution is essential, with the
256 recorded values of variables and context fields you choose, and
257 with as little influence as possible on the instrumented software. This
258 is where tracing comes in handy.
260 _Tracing_ is a technique used to understand what goes on in a running
261 software system. The software used for tracing is called a _tracer_,
262 which is conceptually similar to a tape recorder. When recording,
263 specific instrumentation points placed in the software source code
264 generate events that are saved on a giant tape: a _trace_ file. You
265 can trace user applications and the operating system at the same time,
266 opening the possibility of resolving a wide range of problems that would
267 otherwise be extremely challenging.
269 Tracing is often compared to _logging_. However, tracers and loggers are
270 two different tools, serving two different purposes. Tracers are
271 designed to record much lower-level events that occur much more
272 frequently than log messages, often in the range of thousands per
273 second, with very little execution overhead. Logging is more appropriate
274 for a very high-level analysis of less frequent events: user accesses,
275 exceptional conditions (errors and warnings, for example), database
276 transactions, instant messaging communications, and such. Simply put,
277 logging is one of the many use cases that can be satisfied with tracing.
279 The list of recorded events inside a trace file can be read manually
280 like a log file for the maximum level of detail, but it is generally
281 much more interesting to perform application-specific analyses to
282 produce reduced statistics and graphs that are useful to resolve a
283 given problem. Trace viewers and analyzers are specialized tools
286 In the end, this is what LTTng is: a powerful, open source set of
287 tools to trace the Linux kernel and user applications at the same time.
288 LTTng is composed of several components actively maintained and
289 developed by its link:/community/#where[community].
292 [[lttng-alternatives]]
293 === Alternatives to noch:{LTTng}
295 Excluding proprietary solutions, a few competing software tracers
298 * https://github.com/dtrace4linux/linux[dtrace4linux] is a port of
299 Sun Microsystems's DTrace to Linux. The cmd:dtrace tool interprets
300 user scripts and is responsible for loading code into the
301 Linux kernel for further execution and collecting the outputted data.
302 * https://en.wikipedia.org/wiki/Berkeley_Packet_Filter[eBPF] is a
303 subsystem in the Linux kernel in which a virtual machine can execute
304 programs passed from the user space to the kernel. You can attach
305 such programs to tracepoints and KProbes thanks to a system call, and
306 they can output data to the user space when executed thanks to
307 different mechanisms (pipe, VM register values, and eBPF maps, to name
309 * https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace]
310 is the de facto function tracer of the Linux kernel. Its user
311 interface is a set of special files in sysfs.
312 * https://perf.wiki.kernel.org/[perf] is
313 a performance analyzing tool for Linux which supports hardware
314 performance counters, tracepoints, as well as other counters and
315 types of probes. perf's controlling utility is the cmd:perf command
317 * http://linux.die.net/man/1/strace[strace]
318 is a command-line utility which records system calls made by a
319 user process, as well as signal deliveries and changes of process
320 state. strace makes use of https://en.wikipedia.org/wiki/Ptrace[ptrace]
321 to fulfill its function.
322 * http://www.sysdig.org/[sysdig], like SystemTap, uses scripts to
323 analyze Linux kernel events. You write scripts, or _chisels_ in
324 sysdig's jargon, in Lua and sysdig executes them while the system is
325 being traced or afterwards. sysdig's interface is the cmd:sysdig
326 command-line tool as well as the curses-based cmd:csysdig tool.
327 * https://sourceware.org/systemtap/[SystemTap] is a Linux kernel and
328 user space tracer which uses custom user scripts to produce plain text
329 traces. SystemTap converts the scripts to the C language, and then
330 compiles them as Linux kernel modules which are loaded to produce
331 trace data. SystemTap's primary user interface is the cmd:stap
334 The main distinctive features of LTTng is that it produces correlated
335 kernel and user space traces, as well as doing so with the lowest
336 overhead amongst other solutions. It produces trace files in the
337 http://diamon.org/ctf[CTF] format, a file format optimized
338 for the production and analyses of multi-gigabyte data.
340 LTTng is the result of more than 10 years of active open source
341 development by a community of passionate developers.
342 LTTng{nbsp}{revision} is currently available on major desktop and server
345 The main interface for tracing control is a single command-line tool
346 named cmd:lttng. The latter can create several tracing sessions, enable
347 and disable events on the fly, filter events efficiently with custom
348 user expressions, start and stop tracing, and much more. LTTng can
349 record the traces on the file system or send them over the network, and
350 keep them totally or partially. You can view the traces once tracing
351 becomes inactive or in real-time.
353 <<installing-lttng,Install LTTng now>> and
354 <<getting-started,start tracing>>!
360 **LTTng** is a set of software <<plumbing,components>> which interact to
361 <<instrumenting,instrument>> the Linux kernel and user applications, and
362 to <<controlling-tracing,control tracing>> (start and stop
363 tracing, enable and disable event rules, and the rest). Those
364 components are bundled into the following packages:
366 * **LTTng-tools**: Libraries and command-line interface to
368 * **LTTng-modules**: Linux kernel modules to instrument and
370 * **LTTng-UST**: Libraries and Java/Python packages to instrument and
371 trace user applications.
373 Most distributions mark the LTTng-modules and LTTng-UST packages as
374 optional when installing LTTng-tools (which is always required). In the
375 following sections, we always provide the steps to install all three,
378 * You only need to install LTTng-modules if you intend to trace the
380 * You only need to install LTTng-UST if you intend to trace user
384 .Availability of LTTng{nbsp}{revision} for major Linux distributions as of 2 December 2016.
386 |Distribution |Available in releases |Alternatives
388 |https://www.ubuntu.com/[Ubuntu]
389 |<<ubuntu,Ubuntu{nbsp}16.10 _Yakkety Yak_>>.
390 |LTTng{nbsp}{revision} for Ubuntu{nbsp}14.04 _Trusty Tahr_
391 and Ubuntu{nbsp}16.04 _Xenial Xerus_:
392 <<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>.
394 LTTng{nbsp}2.9 for Ubuntu{nbsp}14.04 _Trusty Tahr_
395 and Ubuntu{nbsp}16.04 _Xenial Xerus_:
396 link:/docs/v2.9#doc-ubuntu-ppa[use the LTTng Stable{nbsp}2.9 PPA].
398 <<building-from-source,Build LTTng{nbsp}{revision} from source>> for
399 other Ubuntu releases.
401 |https://getfedora.org/[Fedora]
402 |<<fedora,Fedora{nbsp}25>>.
403 |<<building-from-source,Build LTTng{nbsp}{revision} from source>> for
404 other Fedora releases.
406 |https://www.debian.org/[Debian]
407 |<<debian,Debian "stretch" (testing)>>.
408 |<<building-from-source,Build LTTng{nbsp}{revision} from source>> for
409 previous Debian releases.
411 |https://www.opensuse.org/[openSUSE]
413 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
415 |https://www.archlinux.org/[Arch Linux]
417 |link:/docs/v2.9#doc-arch-linux[LTTng{nbsp}2.9 from the AUR].
419 |https://alpinelinux.org/[Alpine Linux]
420 |<<alpine-linux,Alpine Linux "edge">>.
421 |LTTng{nbsp}{revision} for Alpine Linux{nbsp}3.5 (not released yet).
423 <<building-from-source,Build LTTng{nbsp}{revision} from source>> for
424 other Alpine Linux releases.
426 |https://www.redhat.com/[RHEL] and https://www.suse.com/[SLES]
427 |See http://packages.efficios.com/[EfficiOS Enterprise Packages].
430 |https://buildroot.org/[Buildroot]
431 |<<buildroot,Buildroot 2016.11>>.
432 |<<building-from-source,Build LTTng{nbsp}{revision} from source>> for
433 other Buildroot releases.
435 |http://www.openembedded.org/wiki/Main_Page[OpenEmbedded] and
436 https://www.yoctoproject.org/[Yocto]
437 |<<oe-yocto,Yocto Project{nbsp}2.2 _Morty_>> (`openembedded-core` layer).
438 |<<building-from-source,Build LTTng{nbsp}{revision} from source>> for
439 other OpenEmbedded releases.
444 === [[ubuntu-official-repositories]]Ubuntu
446 LTTng{nbsp}{revision} is available on Ubuntu{nbsp}16.10 _Yakkety Yak_.
447 For previous releases of Ubuntu, <<ubuntu-ppa,use the LTTng
448 Stable{nbsp}{revision} PPA>>.
450 To install LTTng{nbsp}{revision} on Ubuntu{nbsp}16.10 _Yakkety Yak_:
452 . Install the main LTTng{nbsp}{revision} packages:
457 # apt-get install lttng-tools
458 # apt-get install lttng-modules-dkms
459 # apt-get install liblttng-ust-dev
463 . **If you need to instrument and trace
464 <<java-application,Java applications>>**, install the LTTng-UST
470 # apt-get install liblttng-ust-agent-java
474 . **If you need to instrument and trace
475 <<python-application,Python{nbsp}3 applications>>**, install the
476 LTTng-UST Python agent:
481 # apt-get install python3-lttngust
487 ==== noch:{LTTng} Stable {revision} PPA
489 The https://launchpad.net/~lttng/+archive/ubuntu/stable-{revision}[LTTng
490 Stable{nbsp}{revision} PPA] offers the latest stable
491 LTTng{nbsp}{revision} packages for:
493 * Ubuntu{nbsp}14.04 _Trusty Tahr_
494 * Ubuntu{nbsp}16.04 _Xenial Xerus_
496 To install LTTng{nbsp}{revision} from the LTTng Stable{nbsp}{revision} PPA:
498 . Add the LTTng Stable{nbsp}{revision} PPA repository and update the
504 # apt-add-repository ppa:lttng/stable-2.8
509 . Install the main LTTng{nbsp}{revision} packages:
514 # apt-get install lttng-tools
515 # apt-get install lttng-modules-dkms
516 # apt-get install liblttng-ust-dev
520 . **If you need to instrument and trace
521 <<java-application,Java applications>>**, install the LTTng-UST
527 # apt-get install liblttng-ust-agent-java
531 . **If you need to instrument and trace
532 <<python-application,Python{nbsp}3 applications>>**, install the
533 LTTng-UST Python agent:
538 # apt-get install python3-lttngust
546 To install LTTng{nbsp}{revision} on Fedora{nbsp}25:
548 . Install the LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision}
554 # yum install lttng-tools
555 # yum install lttng-ust
559 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
565 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.8.tar.bz2 &&
566 tar -xf lttng-modules-latest-2.8.tar.bz2 &&
567 cd lttng-modules-2.8.* &&
569 sudo make modules_install &&
575 .Java and Python application instrumentation and tracing
577 If you need to instrument and trace <<java-application,Java
578 applications>> on openSUSE, you need to build and install
579 LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass
580 the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or
581 `--enable-java-agent-all` options to the `configure` script, depending
582 on which Java logging framework you use.
584 If you need to instrument and trace <<python-application,Python
585 applications>> on openSUSE, you need to build and install
586 LTTng-UST{nbsp}{revision} from source and pass the
587 `--enable-python-agent` option to the `configure` script.
594 To install LTTng{nbsp}{revision} on Debian "stretch" (testing):
596 . Install the main LTTng{nbsp}{revision} packages:
601 # apt-get install lttng-modules-dkms
602 # apt-get install liblttng-ust-dev
603 # apt-get install lttng-tools
607 . **If you need to instrument and trace <<java-application,Java
608 applications>>**, install the LTTng-UST Java agent:
613 # apt-get install liblttng-ust-agent-java
617 . **If you need to instrument and trace <<python-application,Python
618 applications>>**, install the LTTng-UST Python agent:
623 # apt-get install python3-lttngust
631 To install LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision} on
634 . Make sure your system is
635 https://wiki.alpinelinux.org/wiki/Edge[configured for "edge"].
636 . Enable the _testing_ repository by uncommenting the corresponding
637 line in path:{/etc/apk/repositories}.
638 . Add the LTTng packages:
643 # apk add lttng-tools
644 # apk add lttng-ust-dev
648 To install LTTng-modules{nbsp}{revision} (Linux kernel tracing support)
649 on Alpine Linux "edge":
651 . Add the vanilla Linux kernel:
656 # apk add linux-vanilla linux-vanilla-dev
660 . Reboot with the vanilla Linux kernel.
661 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
667 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.8.tar.bz2 &&
668 tar -xf lttng-modules-latest-2.8.tar.bz2 &&
669 cd lttng-modules-2.8.* &&
671 sudo make modules_install &&
677 [[enterprise-distributions]]
678 === RHEL, SUSE, and other enterprise distributions
680 To install LTTng on enterprise Linux distributions, such as Red Hat
681 Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SUSE), please
682 see http://packages.efficios.com/[EfficiOS Enterprise Packages].
688 To install LTTng{nbsp}{revision} on Buildroot{nbsp}2016.11:
690 . Launch the Buildroot configuration tool:
699 . In **Kernel**, check **Linux kernel**.
700 . In **Toolchain**, check **Enable WCHAR support**.
701 . In **Target packages**{nbsp}→ **Debugging, profiling and benchmark**,
702 check **lttng-modules** and **lttng-tools**.
703 . In **Target packages**{nbsp}→ **Libraries**{nbsp}→
704 **Other**, check **lttng-libust**.
708 === OpenEmbedded and Yocto
710 LTTng{nbsp}{revision} recipes are available in the
711 http://layers.openembedded.org/layerindex/branch/master/layer/openembedded-core/[`openembedded-core`]
712 layer for Yocto Project{nbsp}2.2 _Morty_ under the following names:
718 With BitBake, the simplest way to include LTTng recipes in your target
719 image is to add them to `IMAGE_INSTALL_append` in path:{conf/local.conf}:
722 IMAGE_INSTALL_append = " lttng-tools lttng-modules lttng-ust"
727 . Select a machine and an image recipe.
728 . Click **Edit image recipe**.
729 . Under the **All recipes** tab, search for **lttng**.
730 . Check the desired LTTng recipes.
733 .Java and Python application instrumentation and tracing
735 If you need to instrument and trace <<java-application,Java
736 applications>> on openSUSE, you need to build and install
737 LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass
738 the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or
739 `--enable-java-agent-all` options to the `configure` script, depending
740 on which Java logging framework you use.
742 If you need to instrument and trace <<python-application,Python
743 applications>> on openSUSE, you need to build and install
744 LTTng-UST{nbsp}{revision} from source and pass the
745 `--enable-python-agent` option to the `configure` script.
749 [[building-from-source]]
750 === Build from source
752 To build and install LTTng{nbsp}{revision} from source:
754 . Using your distribution's package manager, or from source, install
755 the following dependencies of LTTng-tools and LTTng-UST:
758 * https://sourceforge.net/projects/libuuid/[libuuid]
759 * http://directory.fsf.org/wiki/Popt[popt]
760 * http://liburcu.org/[Userspace RCU]
761 * http://www.xmlsoft.org/[libxml2]
764 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
770 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.8.tar.bz2 &&
771 tar -xf lttng-modules-latest-2.8.tar.bz2 &&
772 cd lttng-modules-2.8.* &&
774 sudo make modules_install &&
779 . Download, build, and install the latest LTTng-UST{nbsp}{revision}:
785 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.8.tar.bz2 &&
786 tar -xf lttng-ust-latest-2.8.tar.bz2 &&
787 cd lttng-ust-2.8.* &&
797 .Java and Python application tracing
799 If you need to instrument and trace <<java-application,Java
800 applications>>, pass the `--enable-java-agent-jul`,
801 `--enable-java-agent-log4j`, or `--enable-java-agent-all` options to the
802 `configure` script, depending on which Java logging framework you use.
804 If you need to instrument and trace <<python-application,Python
805 applications>>, pass the `--enable-python-agent` option to the
806 `configure` script. You can set the `PYTHON` environment variable to the
807 path to the Python interpreter for which to install the LTTng-UST Python
815 By default, LTTng-UST libraries are installed to
816 dir:{/usr/local/lib}, which is the de facto directory in which to
817 keep self-compiled and third-party libraries.
819 When <<building-tracepoint-providers-and-user-application,linking an
820 instrumented user application with `liblttng-ust`>>:
822 * Append `/usr/local/lib` to the env:LD_LIBRARY_PATH environment
824 * Pass the `-L/usr/local/lib` and `-Wl,-rpath,/usr/local/lib` options to
825 man:gcc(1), man:g++(1), or man:clang(1).
829 . Download, build, and install the latest LTTng-tools{nbsp}{revision}:
835 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.8.tar.bz2 &&
836 tar -xf lttng-tools-latest-2.8.tar.bz2 &&
837 cd lttng-tools-2.8.* &&
845 TIP: The https://github.com/eepp/vlttng[vlttng tool] can do all the
846 previous steps automatically for a given version of LTTng and confine
847 the installed files in a specific directory. This can be useful to test
848 LTTng without installing it on your system.
854 This is a short guide to get started quickly with LTTng kernel and user
857 Before you follow this guide, make sure to <<installing-lttng,install>>
860 This tutorial walks you through the steps to:
862 . <<tracing-the-linux-kernel,Trace the Linux kernel>>.
863 . <<tracing-your-own-user-application,Trace a user application>> written
865 . <<viewing-and-analyzing-your-traces,View and analyze the
869 [[tracing-the-linux-kernel]]
870 === Trace the Linux kernel
872 The following command lines start with the `#` prompt because you need
873 root privileges to trace the Linux kernel. You can also trace the kernel
874 as a regular user if your Unix user is a member of the
875 <<tracing-group,tracing group>>.
877 . Create a <<tracing-session,tracing session>> which writes its traces
878 to dir:{/tmp/my-kernel-trace}:
883 # lttng create my-kernel-session --output=/tmp/my-kernel-trace
887 . List the available kernel tracepoints and system calls:
892 # lttng list --kernel
893 # lttng list --kernel --syscall
897 . Create <<event,event rules>> which match the desired instrumentation
898 point names, for example the `sched_switch` and `sched_process_fork`
899 tracepoints, and the man:open(2) and man:close(2) system calls:
904 # lttng enable-event --kernel sched_switch,sched_process_fork
905 # lttng enable-event --kernel --syscall open,close
909 You can also create an event rule which matches _all_ the Linux kernel
910 tracepoints (this will generate a lot of data when tracing):
915 # lttng enable-event --kernel --all
919 . <<basic-tracing-session-control,Start tracing>>:
928 . Do some operation on your system for a few seconds. For example,
929 load a website, or list the files of a directory.
930 . <<basic-tracing-session-control,Stop tracing>> and destroy the
941 The man:lttng-destroy(1) command does not destroy the trace data; it
942 only destroys the state of the tracing session.
944 . For the sake of this example, make the recorded trace accessible to
950 sudo chown -R $(whoami) /tmp/my-kernel-trace
954 See <<viewing-and-analyzing-your-traces,View and analyze the
955 recorded events>> to view the recorded events.
958 [[tracing-your-own-user-application]]
959 === Trace a user application
961 This section steps you through a simple example to trace a
962 _Hello world_ program written in C.
964 To create the traceable user application:
966 . Create the tracepoint provider header file, which defines the
967 tracepoints and the events they can generate:
973 #undef TRACEPOINT_PROVIDER
974 #define TRACEPOINT_PROVIDER hello_world
976 #undef TRACEPOINT_INCLUDE
977 #define TRACEPOINT_INCLUDE "./hello-tp.h"
979 #if !defined(_HELLO_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
982 #include <lttng/tracepoint.h>
992 ctf_string(my_string_field, my_string_arg)
993 ctf_integer(int, my_integer_field, my_integer_arg)
997 #endif /* _HELLO_TP_H */
999 #include <lttng/tracepoint-event.h>
1003 . Create the tracepoint provider package source file:
1009 #define TRACEPOINT_CREATE_PROBES
1010 #define TRACEPOINT_DEFINE
1012 #include "hello-tp.h"
1016 . Build the tracepoint provider package:
1021 $ gcc -c -I. hello-tp.c
1025 . Create the _Hello World_ application source file:
1032 #include "hello-tp.h"
1034 int main(int argc, char *argv[])
1038 puts("Hello, World!\nPress Enter to continue...");
1041 * The following getchar() call is only placed here for the purpose
1042 * of this demonstration, to pause the application in order for
1043 * you to have time to list its tracepoints. It is not
1049 * A tracepoint() call.
1051 * Arguments, as defined in hello-tp.h:
1053 * 1. Tracepoint provider name (required)
1054 * 2. Tracepoint name (required)
1055 * 3. my_integer_arg (first user-defined argument)
1056 * 4. my_string_arg (second user-defined argument)
1058 * Notice the tracepoint provider and tracepoint names are
1059 * NOT strings: they are in fact parts of variables that the
1060 * macros in hello-tp.h create.
1062 tracepoint(hello_world, my_first_tracepoint, 23, "hi there!");
1064 for (x = 0; x < argc; ++x) {
1065 tracepoint(hello_world, my_first_tracepoint, x, argv[x]);
1068 puts("Quitting now!");
1069 tracepoint(hello_world, my_first_tracepoint, x * x, "x^2");
1076 . Build the application:
1085 . Link the application with the tracepoint provider package,
1086 `liblttng-ust`, and `libdl`:
1091 $ gcc -o hello hello.o hello-tp.o -llttng-ust -ldl
1095 Here's the whole build process:
1098 .User space tracing tutorial's build steps.
1099 image::ust-flow.png[]
1101 To trace the user application:
1103 . Run the application with a few arguments:
1108 $ ./hello world and beyond
1117 Press Enter to continue...
1121 . Start an LTTng <<lttng-sessiond,session daemon>>:
1126 $ lttng-sessiond --daemonize
1130 Note that a session daemon might already be running, for example as
1131 a service that the distribution's service manager started.
1133 . List the available user space tracepoints:
1138 $ lttng list --userspace
1142 You see the `hello_world:my_first_tracepoint` tracepoint listed
1143 under the `./hello` process.
1145 . Create a <<tracing-session,tracing session>>:
1150 $ lttng create my-user-space-session
1154 . Create an <<event,event rule>> which matches the
1155 `hello_world:my_first_tracepoint` event name:
1160 $ lttng enable-event --userspace hello_world:my_first_tracepoint
1164 . <<basic-tracing-session-control,Start tracing>>:
1173 . Go back to the running `hello` application and press Enter. The
1174 program executes all `tracepoint()` instrumentation points and exits.
1175 . <<basic-tracing-session-control,Stop tracing>> and destroy the
1186 The man:lttng-destroy(1) command does not destroy the trace data; it
1187 only destroys the state of the tracing session.
1189 By default, LTTng saves the traces in
1190 +$LTTNG_HOME/lttng-traces/__name__-__date__-__time__+,
1191 where +__name__+ is the tracing session name. The
1192 env:LTTNG_HOME environment variable defaults to `$HOME` if not set.
1194 See <<viewing-and-analyzing-your-traces,View and analyze the
1195 recorded events>> to view the recorded events.
1198 [[viewing-and-analyzing-your-traces]]
1199 === View and analyze the recorded events
1201 Once you have completed the <<tracing-the-linux-kernel,Trace the Linux
1202 kernel>> and <<tracing-your-own-user-application,Trace a user
1203 application>> tutorials, you can inspect the recorded events.
1205 Many tools are available to read LTTng traces:
1207 * **cmd:babeltrace** is a command-line utility which converts trace
1208 formats; it supports the format that LTTng produces, CTF, as well as a
1209 basic text output which can be ++grep++ed. The cmd:babeltrace command
1210 is part of the http://diamon.org/babeltrace[Babeltrace] project.
1211 * Babeltrace also includes
1212 **https://www.python.org/[Python] bindings** so
1213 that you can easily open and read an LTTng trace with your own script,
1214 benefiting from the power of Python.
1215 * http://tracecompass.org/[**Trace Compass**]
1216 is a graphical user interface for viewing and analyzing any type of
1217 logs or traces, including LTTng's.
1218 * https://github.com/lttng/lttng-analyses[**LTTng analyses**] is a
1219 project which includes many high-level analyses of LTTng kernel
1220 traces, like scheduling statistics, interrupt frequency distribution,
1221 top CPU usage, and more.
1223 NOTE: This section assumes that the traces recorded during the previous
1224 tutorials were saved to their default location, in the
1225 dir:{$LTTNG_HOME/lttng-traces} directory. The env:LTTNG_HOME
1226 environment variable defaults to `$HOME` if not set.
1229 [[viewing-and-analyzing-your-traces-bt]]
1230 ==== Use the cmd:babeltrace command-line tool
1232 The simplest way to list all the recorded events of a trace is to pass
1233 its path to cmd:babeltrace with no options:
1237 $ babeltrace ~/lttng-traces/my-user-space-session*
1240 cmd:babeltrace finds all traces recursively within the given path and
1241 prints all their events, merging them in chronological order.
1243 You can pipe the output of cmd:babeltrace into a tool like man:grep(1) for
1248 $ babeltrace /tmp/my-kernel-trace | grep _switch
1251 You can pipe the output of cmd:babeltrace into a tool like man:wc(1) to
1252 count the recorded events:
1256 $ babeltrace /tmp/my-kernel-trace | grep _open | wc --lines
1260 [[viewing-and-analyzing-your-traces-bt-python]]
1261 ==== Use the Babeltrace Python bindings
1263 The <<viewing-and-analyzing-your-traces-bt,text output of cmd:babeltrace>>
1264 is useful to isolate events by simple matching using man:grep(1) and
1265 similar utilities. However, more elaborate filters, such as keeping only
1266 event records with a field value falling within a specific range, are
1267 not trivial to write using a shell. Moreover, reductions and even the
1268 most basic computations involving multiple event records are virtually
1269 impossible to implement.
1271 Fortunately, Babeltrace ships with Python 3 bindings which makes it easy
1272 to read the event records of an LTTng trace sequentially and compute the
1273 desired information.
1275 The following script accepts an LTTng Linux kernel trace path as its
1276 first argument and prints the short names of the top 5 running processes
1277 on CPU 0 during the whole trace:
1282 from collections import Counter
1288 if len(sys.argv) != 2:
1289 msg = 'Usage: python3 {} TRACEPATH'.format(sys.argv[0])
1290 print(msg, file=sys.stderr)
1293 # A trace collection contains one or more traces
1294 col = babeltrace.TraceCollection()
1296 # Add the trace provided by the user (LTTng traces always have
1298 if col.add_trace(sys.argv[1], 'ctf') is None:
1299 raise RuntimeError('Cannot add trace')
1301 # This counter dict contains execution times:
1303 # task command name -> total execution time (ns)
1304 exec_times = Counter()
1306 # This contains the last `sched_switch` timestamp
1310 for event in col.events:
1311 # Keep only `sched_switch` events
1312 if event.name != 'sched_switch':
1315 # Keep only events which happened on CPU 0
1316 if event['cpu_id'] != 0:
1320 cur_ts = event.timestamp
1326 # Previous task command (short) name
1327 prev_comm = event['prev_comm']
1329 # Initialize entry in our dict if not yet done
1330 if prev_comm not in exec_times:
1331 exec_times[prev_comm] = 0
1333 # Compute previous command execution time
1334 diff = cur_ts - last_ts
1336 # Update execution time of this command
1337 exec_times[prev_comm] += diff
1339 # Update last timestamp
1343 for name, ns in exec_times.most_common(5):
1345 print('{:20}{} s'.format(name, s))
1350 if __name__ == '__main__':
1351 sys.exit(0 if top5proc() else 1)
1358 $ python3 top5proc.py /tmp/my-kernel-trace/kernel
1364 swapper/0 48.607245889 s
1365 chromium 7.192738188 s
1366 pavucontrol 0.709894415 s
1367 Compositor 0.660867933 s
1368 Xorg.bin 0.616753786 s
1371 Note that `swapper/0` is the "idle" process of CPU 0 on Linux; since we
1372 weren't using the CPU that much when tracing, its first position in the
1377 == [[understanding-lttng]]Core concepts
1379 From a user's perspective, the LTTng system is built on a few concepts,
1380 or objects, on which the <<lttng-cli,cmd:lttng command-line tool>>
1381 operates by sending commands to the <<lttng-sessiond,session daemon>>.
1382 Understanding how those objects relate to eachother is key in mastering
1385 The core concepts are:
1387 * <<tracing-session,Tracing session>>
1388 * <<domain,Tracing domain>>
1389 * <<channel,Channel and ring buffer>>
1390 * <<"event","Instrumentation point, event rule, event, and event record">>
1396 A _tracing session_ is a stateful dialogue between you and
1397 a <<lttng-sessiond,session daemon>>. You can
1398 <<creating-destroying-tracing-sessions,create a new tracing
1399 session>> with the `lttng create` command.
1401 Anything that you do when you control LTTng tracers happens within a
1402 tracing session. In particular, a tracing session:
1405 * Has its own set of trace files.
1406 * Has its own state of activity (started or stopped).
1407 * Has its own <<tracing-session-mode,mode>> (local, network streaming,
1409 * Has its own <<channel,channels>> which have their own
1410 <<event,event rules>>.
1413 .A _tracing session_ contains <<channel,channels>> that are members of <<domain,tracing domains>> and contain <<event,event rules>>.
1414 image::concepts.png[]
1416 Those attributes and objects are completely isolated between different
1419 A tracing session is analogous to a cash machine session:
1420 the operations you do on the banking system through the cash machine do
1421 not alter the data of other users of the same system. In the case of
1422 the cash machine, a session lasts as long as your bank card is inside.
1423 In the case of LTTng, a tracing session lasts from the `lttng create`
1424 command to the `lttng destroy` command.
1427 .Each Unix user has its own set of tracing sessions.
1428 image::many-sessions.png[]
1431 [[tracing-session-mode]]
1432 ==== Tracing session mode
1434 LTTng can send the generated trace data to different locations. The
1435 _tracing session mode_ dictates where to send it. The following modes
1436 are available in LTTng{nbsp}{revision}:
1439 LTTng writes the traces to the file system of the machine being traced
1442 Network streaming mode::
1443 LTTng sends the traces over the network to a
1444 <<lttng-relayd,relay daemon>> running on a remote system.
1447 LTTng does not write the traces by default. Instead, you can request
1448 LTTng to <<taking-a-snapshot,take a snapshot>>, that is, a copy of the
1449 current tracing buffers, and to write it to the target's file system
1450 or to send it over the network to a <<lttng-relayd,relay daemon>>
1451 running on a remote system.
1454 This mode is similar to the network streaming mode, but a live
1455 trace viewer can connect to the distant relay daemon to
1456 <<lttng-live,view event records as LTTng generates them>> by
1463 A _tracing domain_ is a namespace for event sources. A tracing domain
1464 has its own properties and features.
1466 There are currently five available tracing domains:
1470 * `java.util.logging` (JUL)
1474 You must specify a tracing domain when using some commands to avoid
1475 ambiguity. For example, since all the domains support named tracepoints
1476 as event sources (instrumentation points that you manually insert in the
1477 source code), you need to specify a tracing domain when
1478 <<enabling-disabling-events,creating an event rule>> because all the
1479 tracing domains could have tracepoints with the same names.
1481 Some features are reserved to specific tracing domains. Dynamic function
1482 entry and return instrumentation points, for example, are currently only
1483 supported in the Linux kernel tracing domain, but support for other
1484 tracing domains could be added in the future.
1486 You can create <<channel,channels>> in the Linux kernel and user space
1487 tracing domains. The other tracing domains have a single default
1492 === Channel and ring buffer
1494 A _channel_ is an object which is responsible for a set of ring buffers.
1495 Each ring buffer is divided into multiple sub-buffers. When an LTTng
1496 tracer emits an event, it can record it to one or more
1497 sub-buffers. The attributes of a channel determine what to do when
1498 there's no space left for a new event record because all sub-buffers
1499 are full, where to send a full sub-buffer, and other behaviours.
1501 A channel is always associated to a <<domain,tracing domain>>. The
1502 `java.util.logging` (JUL), log4j, and Python tracing domains each have
1503 a default channel which you cannot configure.
1505 A channel also owns <<event,event rules>>. When an LTTng tracer emits
1506 an event, it records it to the sub-buffers of all
1507 the enabled channels with a satisfied event rule, as long as those
1508 channels are part of active <<tracing-session,tracing sessions>>.
1511 [[channel-buffering-schemes]]
1512 ==== Per-user vs. per-process buffering schemes
1514 A channel has at least one ring buffer _per CPU_. LTTng always
1515 records an event to the ring buffer associated to the CPU on which it
1518 Two _buffering schemes_ are available when you
1519 <<enabling-disabling-channels,create a channel>> in the
1520 user space <<domain,tracing domain>>:
1522 Per-user buffering::
1523 Allocate one set of ring buffers--one per CPU--shared by all the
1524 instrumented processes of each Unix user.
1528 .Per-user buffering scheme.
1529 image::per-user-buffering.png[]
1532 Per-process buffering::
1533 Allocate one set of ring buffers--one per CPU--for each
1534 instrumented process.
1538 .Per-process buffering scheme.
1539 image::per-process-buffering.png[]
1542 The per-process buffering scheme tends to consume more memory than the
1543 per-user option because systems generally have more instrumented
1544 processes than Unix users running instrumented processes. However, the
1545 per-process buffering scheme ensures that one process having a high
1546 event throughput won't fill all the shared sub-buffers of the same
1549 The Linux kernel tracing domain has only one available buffering scheme
1550 which is to allocate a single set of ring buffers for the whole system.
1551 This scheme is similar to the per-user option, but with a single, global
1552 user "running" the kernel.
1555 [[channel-overwrite-mode-vs-discard-mode]]
1556 ==== Overwrite vs. discard event loss modes
1558 When an event occurs, LTTng records it to a specific sub-buffer (yellow
1559 arc in the following animation) of a specific channel's ring buffer.
1560 When there's no space left in a sub-buffer, the tracer marks it as
1561 consumable (red) and another, empty sub-buffer starts receiving the
1562 following event records. A <<lttng-consumerd,consumer daemon>>
1563 eventually consumes the marked sub-buffer (returns to white).
1566 [role="docsvg-channel-subbuf-anim"]
1571 In an ideal world, sub-buffers are consumed faster than they are filled,
1572 as is the case in the previous animation. In the real world,
1573 however, all sub-buffers can be full at some point, leaving no space to
1574 record the following events.
1576 By design, LTTng is a _non-blocking_ tracer: when no empty sub-buffer is
1577 available, it is acceptable to lose event records when the alternative
1578 would be to cause substantial delays in the instrumented application's
1579 execution. LTTng privileges performance over integrity; it aims at
1580 perturbing the traced system as little as possible in order to make
1581 tracing of subtle race conditions and rare interrupt cascades possible.
1583 When it comes to losing event records because no empty sub-buffer is
1584 available, the channel's _event loss mode_ determines what to do. The
1585 available event loss modes are:
1588 Drop the newest event records until a the tracer
1589 releases a sub-buffer.
1592 Clear the sub-buffer containing the oldest event records and start
1593 writing the newest event records there.
1595 This mode is sometimes called _flight recorder mode_ because it's
1597 https://en.wikipedia.org/wiki/Flight_recorder[flight recorder]:
1598 always keep a fixed amount of the latest data.
1600 Which mechanism you should choose depends on your context: prioritize
1601 the newest or the oldest event records in the ring buffer?
1603 Beware that, in overwrite mode, the tracer abandons a whole sub-buffer
1604 as soon as a there's no space left for a new event record, whereas in
1605 discard mode, the tracer only discards the event record that doesn't
1608 In discard mode, LTTng increments a count of lost event records when
1609 an event record is lost and saves this count to the trace. In
1610 overwrite mode, LTTng keeps no information when it overwrites a
1611 sub-buffer before consuming it.
1613 There are a few ways to decrease your probability of losing event
1615 <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>> shows
1616 how you can fine-une the sub-buffer count and size of a channel to
1617 virtually stop losing event records, though at the cost of greater
1621 [[channel-subbuf-size-vs-subbuf-count]]
1622 ==== Sub-buffer count and size
1624 When you <<enabling-disabling-channels,create a channel>>, you can
1625 set its number of sub-buffers and their size.
1627 Note that there is noticeable CPU overhead introduced when
1628 switching sub-buffers (marking a full one as consumable and switching
1629 to an empty one for the following events to be recorded). Knowing this,
1630 the following list presents a few practical situations along with how
1631 to configure the sub-buffer count and size for them:
1633 * **High event throughput**: In general, prefer bigger sub-buffers to
1634 lower the risk of losing event records.
1636 Having bigger sub-buffers also ensures a lower sub-buffer switching
1639 The number of sub-buffers is only meaningful if you create the channel
1640 in overwrite mode: in this case, if a sub-buffer overwrite happens, the
1641 other sub-buffers are left unaltered.
1643 * **Low event throughput**: In general, prefer smaller sub-buffers
1644 since the risk of losing event records is low.
1646 Because events occur less frequently, the sub-buffer switching frequency
1647 should remain low and thus the tracer's overhead should not be a
1650 * **Low memory system**: If your target system has a low memory
1651 limit, prefer fewer first, then smaller sub-buffers.
1653 Even if the system is limited in memory, you want to keep the
1654 sub-buffers as big as possible to avoid a high sub-buffer switching
1657 Note that LTTng uses http://diamon.org/ctf/[CTF] as its trace format,
1658 which means event data is very compact. For example, the average
1659 LTTng kernel event record weights about 32{nbsp}bytes. Thus, a
1660 sub-buffer size of 1{nbsp}MiB is considered big.
1662 The previous situations highlight the major trade-off between a few big
1663 sub-buffers and more, smaller sub-buffers: sub-buffer switching
1664 frequency vs. how much data is lost in overwrite mode. Assuming a
1665 constant event throughput and using the overwrite mode, the two
1666 following configurations have the same ring buffer total size:
1669 [role="docsvg-channel-subbuf-size-vs-count-anim"]
1674 * **2 sub-buffers of 4{nbsp}MiB each**: Expect a very low sub-buffer
1675 switching frequency, but if a sub-buffer overwrite happens, half of
1676 the event records so far (4{nbsp}MiB) are definitely lost.
1677 * **8 sub-buffers of 1{nbsp}MiB each**: Expect 4{nbsp}times the tracer's
1678 overhead as the previous configuration, but if a sub-buffer
1679 overwrite happens, only the eighth of event records so far are
1682 In discard mode, the sub-buffers count parameter is pointless: use two
1683 sub-buffers and set their size according to the requirements of your
1687 [[channel-switch-timer]]
1688 ==== Switch timer period
1690 The _switch timer period_ is an important configurable attribute of
1691 a channel to ensure periodic sub-buffer flushing.
1693 When the _switch timer_ expires, a sub-buffer switch happens. You can
1694 set the switch timer period attribute when you
1695 <<enabling-disabling-channels,create a channel>> to ensure that event
1696 data is consumed and committed to trace files or to a distant relay
1697 daemon periodically in case of a low event throughput.
1700 [role="docsvg-channel-switch-timer"]
1705 This attribute is also convenient when you use big sub-buffers to cope
1706 with a sporadic high event throughput, even if the throughput is
1710 [[channel-read-timer]]
1711 ==== Read timer period
1713 By default, the LTTng tracers use a notification mechanism to signal a
1714 full sub-buffer so that a consumer daemon can consume it. When such
1715 notifications must be avoided, for example in real-time applications,
1716 you can use the channel's _read timer_ instead. When the read timer
1717 fires, the <<lttng-consumerd,consumer daemon>> checks for full,
1718 consumable sub-buffers.
1721 [[tracefile-rotation]]
1722 ==== Trace file count and size
1724 By default, trace files can grow as large as needed. You can set the
1725 maximum size of each trace file that a channel writes when you
1726 <<enabling-disabling-channels,create a channel>>. When the size of
1727 a trace file reaches the channel's fixed maximum size, LTTng creates
1728 another file to contain the next event records. LTTng appends a file
1729 count to each trace file name in this case.
1731 If you set the trace file size attribute when you create a channel, the
1732 maximum number of trace files that LTTng creates is _unlimited_ by
1733 default. To limit them, you can also set a maximum number of trace
1734 files. When the number of trace files reaches the channel's fixed
1735 maximum count, the oldest trace file is overwritten. This mechanism is
1736 called _trace file rotation_.
1740 === Instrumentation point, event rule, event, and event record
1742 An _event rule_ is a set of conditions which must be **all** satisfied
1743 for LTTng to record an occuring event.
1745 You set the conditions when you <<enabling-disabling-events,create
1748 You always attach an event rule to <<channel,channel>> when you create
1751 When an event passes the conditions of an event rule, LTTng records it
1752 in one of the attached channel's sub-buffers.
1754 The available conditions, as of LTTng{nbsp}{revision}, are:
1756 * The event rule _is enabled_.
1757 * The instrumentation point's type _is{nbsp}T_.
1758 * The instrumentation point's name (sometimes called _event name_)
1759 _matches{nbsp}N_, but _is not{nbsp}E_.
1760 * The instrumentation point's log level _is as severe as{nbsp}L_, or
1761 _is exactly{nbsp}L_.
1762 * The fields of the event's payload _satisfy_ a filter
1763 expression{nbsp}__F__.
1765 As you can see, all the conditions but the dynamic filter are related to
1766 the event rule's status or to the instrumentation point, not to the
1767 occurring events. This is why, without a filter, checking if an event
1768 passes an event rule is not a dynamic task: when you create or modify an
1769 event rule, all the tracers of its tracing domain enable or disable the
1770 instrumentation points themselves once. This is possible because the
1771 attributes of an instrumentation point (type, name, and log level) are
1772 defined statically. In other words, without a dynamic filter, the tracer
1773 _does not evaluate_ the arguments of an instrumentation point unless it
1774 matches an enabled event rule.
1776 Note that, for LTTng to record an event, the <<channel,channel>> to
1777 which a matching event rule is attached must also be enabled, and the
1778 tracing session owning this channel must be active.
1781 .Logical path from an instrumentation point to an event record.
1782 image::event-rule.png[]
1784 .Event, event record, or event rule?
1786 With so many similar terms, it's easy to get confused.
1788 An **event** is the consequence of the execution of an _instrumentation
1789 point_, like a tracepoint that you manually place in some source code,
1790 or a Linux kernel KProbe. An event is said to _occur_ at a specific
1791 time. Different actions can be taken upon the occurance of an event,
1792 like record the event's payload to a buffer.
1794 An **event record** is the representation of an event in a sub-buffer. A
1795 tracer is responsible for capturing the payload of an event, current
1796 context variables, the event's ID, and the event's timestamp. LTTng
1797 can append this sub-buffer to a trace file.
1799 An **event rule** is a set of conditions which must all be satisfied for
1800 LTTng to record an occuring event. Events still occur without
1801 satisfying event rules, but LTTng does not record them.
1806 == Components of noch:{LTTng}
1808 The second _T_ in _LTTng_ stands for _toolkit_: it would be wrong
1809 to call LTTng a simple _tool_ since it is composed of multiple
1810 interacting components. This section describes those components,
1811 explains their respective roles, and shows how they connect together to
1812 form the LTTng ecosystem.
1814 The following diagram shows how the most important components of LTTng
1815 interact with user applications, the Linux kernel, and you:
1818 .Control and trace data paths between LTTng components.
1819 image::plumbing.png[]
1821 The LTTng project incorporates:
1823 * **LTTng-tools**: Libraries and command-line interface to
1824 control tracing sessions.
1825 ** <<lttng-sessiond,Session daemon>> (man:lttng-sessiond(8)).
1826 ** <<lttng-consumerd,Consumer daemon>> (man:lttng-consumerd(8)).
1827 ** <<lttng-relayd,Relay daemon>> (man:lttng-relayd(8)).
1828 ** <<liblttng-ctl-lttng,Tracing control library>> (`liblttng-ctl`).
1829 ** <<lttng-cli,Tracing control command-line tool>> (man:lttng(1)).
1830 * **LTTng-UST**: Libraries and Java/Python packages to trace user
1832 ** <<lttng-ust,User space tracing library>> (`liblttng-ust`) and its
1833 headers to instrument and trace any native user application.
1834 ** <<prebuilt-ust-helpers,Preloadable user space tracing helpers>>:
1835 *** `liblttng-ust-libc-wrapper`
1836 *** `liblttng-ust-pthread-wrapper`
1837 *** `liblttng-ust-cyg-profile`
1838 *** `liblttng-ust-cyg-profile-fast`
1839 *** `liblttng-ust-dl`
1840 ** User space tracepoint provider source files generator command-line
1841 tool (man:lttng-gen-tp(1)).
1842 ** <<lttng-ust-agents,LTTng-UST Java agent>> to instrument and trace
1843 Java applications using `java.util.logging` or
1844 Apache log4j 1.2 logging.
1845 ** <<lttng-ust-agents,LTTng-UST Python agent>> to instrument
1846 Python applications using the standard `logging` package.
1847 * **LTTng-modules**: <<lttng-modules,Linux kernel modules>> to trace
1849 ** LTTng kernel tracer module.
1850 ** Tracing ring buffer kernel modules.
1851 ** Probe kernel modules.
1852 ** LTTng logger kernel module.
1856 === Tracing control command-line interface
1859 .The tracing control command-line interface.
1860 image::plumbing-lttng-cli.png[]
1862 The _man:lttng(1) command-line tool_ is the standard user interface to
1863 control LTTng <<tracing-session,tracing sessions>>. The cmd:lttng tool
1864 is part of LTTng-tools.
1866 The cmd:lttng tool is linked with
1867 <<liblttng-ctl-lttng,`liblttng-ctl`>> to communicate with
1868 one or more <<lttng-sessiond,session daemons>> behind the scenes.
1870 The cmd:lttng tool has a Git-like interface:
1874 $ lttng <GENERAL OPTIONS> <COMMAND> <COMMAND OPTIONS>
1877 The <<controlling-tracing,Tracing control>> section explores the
1878 available features of LTTng using the cmd:lttng tool.
1881 [[liblttng-ctl-lttng]]
1882 === Tracing control library
1885 .The tracing control library.
1886 image::plumbing-liblttng-ctl.png[]
1888 The _LTTng control library_, `liblttng-ctl`, is used to communicate
1889 with a <<lttng-sessiond,session daemon>> using a C API that hides the
1890 underlying protocol's details. `liblttng-ctl` is part of LTTng-tools.
1892 The <<lttng-cli,cmd:lttng command-line tool>>
1893 is linked with `liblttng-ctl`.
1895 You can use `liblttng-ctl` in C or $$C++$$ source code by including its
1900 #include <lttng/lttng.h>
1903 Some objects are referenced by name (C string), such as tracing
1904 sessions, but most of them require to create a handle first using
1905 `lttng_create_handle()`.
1907 The best available developer documentation for `liblttng-ctl` is, as of
1908 LTTng{nbsp}{revision}, its installed header files. Every function and
1909 structure is thoroughly documented.
1913 === User space tracing library
1916 .The user space tracing library.
1917 image::plumbing-liblttng-ust.png[]
1919 The _user space tracing library_, `liblttng-ust` (see man:lttng-ust(3)),
1920 is the LTTng user space tracer. It receives commands from a
1921 <<lttng-sessiond,session daemon>>, for example to
1922 enable and disable specific instrumentation points, and writes event
1923 records to ring buffers shared with a
1924 <<lttng-consumerd,consumer daemon>>.
1925 `liblttng-ust` is part of LTTng-UST.
1927 Public C header files are installed beside `liblttng-ust` to
1928 instrument any <<c-application,C or $$C++$$ application>>.
1930 <<lttng-ust-agents,LTTng-UST agents>>, which are regular Java and Python
1931 packages, use their own library providing tracepoints which is
1932 linked with `liblttng-ust`.
1934 An application or library does not have to initialize `liblttng-ust`
1935 manually: its constructor does the necessary tasks to properly register
1936 to a session daemon. The initialization phase also enables the
1937 instrumentation points matching the <<event,event rules>> that you
1941 [[lttng-ust-agents]]
1942 === User space tracing agents
1945 .The user space tracing agents.
1946 image::plumbing-lttng-ust-agents.png[]
1948 The _LTTng-UST Java and Python agents_ are regular Java and Python
1949 packages which add LTTng tracing capabilities to the
1950 native logging frameworks. The LTTng-UST agents are part of LTTng-UST.
1952 In the case of Java, the
1953 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[`java.util.logging`
1954 core logging facilities] and
1955 https://logging.apache.org/log4j/1.2/[Apache log4j 1.2] are supported.
1956 Note that Apache Log4{nbsp}2 is not supported.
1958 In the case of Python, the standard
1959 https://docs.python.org/3/library/logging.html[`logging`] package
1960 is supported. Both Python 2 and Python 3 modules can import the
1961 LTTng-UST Python agent package.
1963 The applications using the LTTng-UST agents are in the
1964 `java.util.logging` (JUL),
1965 log4j, and Python <<domain,tracing domains>>.
1967 Both agents use the same mechanism to trace the log statements. When an
1968 agent is initialized, it creates a log handler that attaches to the root
1969 logger. The agent also registers to a <<lttng-sessiond,session daemon>>.
1970 When the application executes a log statement, it is passed to the
1971 agent's log handler by the root logger. The agent's log handler calls a
1972 native function in a tracepoint provider package shared library linked
1973 with <<lttng-ust,`liblttng-ust`>>, passing the formatted log message and
1974 other fields, like its logger name and its log level. This native
1975 function contains a user space instrumentation point, hence tracing the
1978 The log level condition of an
1979 <<event,event rule>> is considered when tracing
1980 a Java or a Python application, and it's compatible with the standard
1981 JUL, log4j, and Python log levels.
1985 === LTTng kernel modules
1988 .The LTTng kernel modules.
1989 image::plumbing-lttng-modules.png[]
1991 The _LTTng kernel modules_ are a set of Linux kernel modules
1992 which implement the kernel tracer of the LTTng project. The LTTng
1993 kernel modules are part of LTTng-modules.
1995 The LTTng kernel modules include:
1997 * A set of _probe_ modules.
1999 Each module attaches to a specific subsystem
2000 of the Linux kernel using its tracepoint instrument points. There are
2001 also modules to attach to the entry and return points of the Linux
2002 system call functions.
2004 * _Ring buffer_ modules.
2006 A ring buffer implementation is provided as kernel modules. The LTTng
2007 kernel tracer writes to the ring buffer; a
2008 <<lttng-consumerd,consumer daemon>> reads from the ring buffer.
2010 * The _LTTng kernel tracer_ module.
2011 * The _LTTng logger_ module.
2013 The LTTng logger module implements the special path:{/proc/lttng-logger}
2014 file so that any executable can generate LTTng events by opening and
2015 writing to this file.
2017 See <<proc-lttng-logger-abi,LTTng logger>>.
2019 Generally, you do not have to load the LTTng kernel modules manually
2020 (using man:modprobe(8), for example): a root <<lttng-sessiond,session
2021 daemon>> loads the necessary modules when starting. If you have extra
2022 probe modules, you can specify to load them to the session daemon on
2025 The LTTng kernel modules are installed in
2026 +/usr/lib/modules/__release__/extra+ by default, where +__release__+ is
2027 the kernel release (see `uname --kernel-release`).
2034 .The session daemon.
2035 image::plumbing-sessiond.png[]
2037 The _session daemon_, man:lttng-sessiond(8), is a daemon responsible for
2038 managing tracing sessions and for controlling the various components of
2039 LTTng. The session daemon is part of LTTng-tools.
2041 The session daemon sends control requests to and receives control
2044 * The <<lttng-ust,user space tracing library>>.
2046 Any instance of the user space tracing library first registers to
2047 a session daemon. Then, the session daemon can send requests to
2048 this instance, such as:
2051 ** Get the list of tracepoints.
2052 ** Share an <<event,event rule>> so that the user space tracing library
2053 can enable or disable tracepoints. Amongst the possible conditions
2054 of an event rule is a filter expression which `liblttng-ust` evalutes
2055 when an event occurs.
2056 ** Share <<channel,channel>> attributes and ring buffer locations.
2059 The session daemon and the user space tracing library use a Unix
2060 domain socket for their communication.
2062 * The <<lttng-ust-agents,user space tracing agents>>.
2064 Any instance of a user space tracing agent first registers to
2065 a session daemon. Then, the session daemon can send requests to
2066 this instance, such as:
2069 ** Get the list of loggers.
2070 ** Enable or disable a specific logger.
2073 The session daemon and the user space tracing agent use a TCP connection
2074 for their communication.
2076 * The <<lttng-modules,LTTng kernel tracer>>.
2077 * The <<lttng-consumerd,consumer daemon>>.
2079 The session daemon sends requests to the consumer daemon to instruct
2080 it where to send the trace data streams, amongst other information.
2082 * The <<lttng-relayd,relay daemon>>.
2084 The session daemon receives commands from the
2085 <<liblttng-ctl-lttng,tracing control library>>.
2087 The root session daemon loads the appropriate
2088 <<lttng-modules,LTTng kernel modules>> on startup. It also spawns
2089 a <<lttng-consumerd,consumer daemon>> as soon as you create
2090 an <<event,event rule>>.
2092 The session daemon does not send and receive trace data: this is the
2093 role of the <<lttng-consumerd,consumer daemon>> and
2094 <<lttng-relayd,relay daemon>>. It does, however, generate the
2095 http://diamon.org/ctf/[CTF] metadata stream.
2097 Each Unix user can have its own session daemon instance. The
2098 tracing sessions managed by different session daemons are completely
2101 The root user's session daemon is the only one which is
2102 allowed to control the LTTng kernel tracer, and its spawned consumer
2103 daemon is the only one which is allowed to consume trace data from the
2104 LTTng kernel tracer. Note, however, that any Unix user which is a member
2105 of the <<tracing-group,tracing group>> is allowed
2106 to create <<channel,channels>> in the
2107 Linux kernel <<domain,tracing domain>>, and thus to trace the Linux
2110 The <<lttng-cli,cmd:lttng command-line tool>> automatically starts a
2111 session daemon when using its `create` command if none is currently
2112 running. You can also start the session daemon manually.
2119 .The consumer daemon.
2120 image::plumbing-consumerd.png[]
2122 The _consumer daemon_, man:lttng-consumerd(8), is a daemon which shares
2123 ring buffers with user applications or with the LTTng kernel modules to
2124 collect trace data and send it to some location (on disk or to a
2125 <<lttng-relayd,relay daemon>> over the network). The consumer daemon
2126 is part of LTTng-tools.
2128 You do not start a consumer daemon manually: a consumer daemon is always
2129 spawned by a <<lttng-sessiond,session daemon>> as soon as you create an
2130 <<event,event rule>>, that is, before you start tracing. When you kill
2131 its owner session daemon, the consumer daemon also exits because it is
2132 the session daemon's child process. Command-line options of
2133 man:lttng-sessiond(8) target the consumer daemon process.
2135 There are up to two running consumer daemons per Unix user, whereas only
2136 one session daemon can run per user. This is because each process can be
2137 either 32-bit or 64-bit: if the target system runs a mixture of 32-bit
2138 and 64-bit processes, it is more efficient to have separate
2139 corresponding 32-bit and 64-bit consumer daemons. The root user is an
2140 exception: it can have up to _three_ running consumer daemons: 32-bit
2141 and 64-bit instances for its user applications, and one more
2142 reserved for collecting kernel trace data.
2150 image::plumbing-relayd.png[]
2152 The _relay daemon_, man:lttng-relayd(8), is a daemon acting as a bridge
2153 between remote session and consumer daemons, local trace files, and a
2154 remote live trace viewer. The relay daemon is part of LTTng-tools.
2156 The main purpose of the relay daemon is to implement a receiver of
2157 <<sending-trace-data-over-the-network,trace data over the network>>.
2158 This is useful when the target system does not have much file system
2159 space to record trace files locally.
2161 The relay daemon is also a server to which a
2162 <<lttng-live,live trace viewer>> can
2163 connect. The live trace viewer sends requests to the relay daemon to
2164 receive trace data as the target system emits events. The
2165 communication protocol is named _LTTng live_; it is used over TCP
2168 Note that you can start the relay daemon on the target system directly.
2169 This is the setup of choice when the use case is to view events as
2170 the target system emits them without the need of a remote system.
2174 == [[using-lttng]]Instrumentation
2176 There are many examples of tracing and monitoring in our everyday life:
2178 * You have access to real-time and historical weather reports and
2179 forecasts thanks to weather stations installed around the country.
2180 * You know your heart is safe thanks to an electrocardiogram.
2181 * You make sure not to drive your car too fast and to have enough fuel
2182 to reach your destination thanks to gauges visible on your dashboard.
2184 All the previous examples have something in common: they rely on
2185 **instruments**. Without the electrodes attached to the surface of your
2186 body's skin, cardiac monitoring is futile.
2188 LTTng, as a tracer, is no different from those real life examples. If
2189 you're about to trace a software system or, in other words, record its
2190 history of execution, you better have **instrumentation points** in the
2191 subject you're tracing, that is, the actual software.
2193 Various ways were developed to instrument a piece of software for LTTng
2194 tracing. The most straightforward one is to manually place
2195 instrumentation points, called _tracepoints_, in the software's source
2196 code. It is also possible to add instrumentation points dynamically in
2197 the Linux kernel <<domain,tracing domain>>.
2199 If you're only interested in tracing the Linux kernel, your
2200 instrumentation needs are probably already covered by LTTng's built-in
2201 <<lttng-modules,Linux kernel tracepoints>>. You may also wish to trace a
2202 user application which is already instrumented for LTTng tracing.
2203 In such cases, you can skip this whole section and read the topics of
2204 the <<controlling-tracing,Tracing control>> section.
2206 Many methods are available to instrument a piece of software for LTTng
2209 * <<c-application,User space instrumentation for C and $$C++$$
2211 * <<prebuilt-ust-helpers,Prebuilt user space tracing helpers>>.
2212 * <<java-application,User space Java agent>>.
2213 * <<python-application,User space Python agent>>.
2214 * <<proc-lttng-logger-abi,LTTng logger>>.
2215 * <<instrumenting-linux-kernel,LTTng kernel tracepoints>>.
2219 === [[cxx-application]]User space instrumentation for C and $$C++$$ applications
2221 The procedure to instrument a C or $$C++$$ user application with
2222 the <<lttng-ust,LTTng user space tracing library>>, `liblttng-ust`, is:
2224 . <<tracepoint-provider,Create the source files of a tracepoint provider
2226 . <<probing-the-application-source-code,Add tracepoints to
2227 the application's source code>>.
2228 . <<building-tracepoint-providers-and-user-application,Build and link
2229 a tracepoint provider package and the user application>>.
2231 If you need quick, man:printf(3)-like instrumentation, you can skip
2232 those steps and use <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>>
2235 IMPORTANT: You need to <<installing-lttng,install>> LTTng-UST to
2236 instrument a user application with `liblttng-ust`.
2239 [[tracepoint-provider]]
2240 ==== Create the source files of a tracepoint provider package
2242 A _tracepoint provider_ is a set of compiled functions which provide
2243 **tracepoints** to an application, the type of instrumentation point
2244 supported by LTTng-UST. Those functions can emit events with
2245 user-defined fields and serialize those events as event records to one
2246 or more LTTng-UST <<channel,channel>> sub-buffers. The `tracepoint()`
2247 macro, which you <<probing-the-application-source-code,insert in a user
2248 application's source code>>, calls those functions.
2250 A _tracepoint provider package_ is an object file (`.o`) or a shared
2251 library (`.so`) which contains one or more tracepoint providers.
2252 Its source files are:
2254 * One or more <<tpp-header,tracepoint provider header>> (`.h`).
2255 * A <<tpp-source,tracepoint provider package source>> (`.c`).
2257 A tracepoint provider package is dynamically linked with `liblttng-ust`,
2258 the LTTng user space tracer, at run time.
2261 .User application linked with `liblttng-ust` and containing a tracepoint provider.
2262 image::ust-app.png[]
2264 NOTE: If you need quick, man:printf(3)-like instrumentation, you can
2265 skip creating and using a tracepoint provider and use
2266 <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>> instead.
2270 ===== Create a tracepoint provider header file template
2272 A _tracepoint provider header file_ contains the tracepoint
2273 definitions of a tracepoint provider.
2275 To create a tracepoint provider header file:
2277 . Start from this template:
2281 .Tracepoint provider header file template (`.h` file extension).
2283 #undef TRACEPOINT_PROVIDER
2284 #define TRACEPOINT_PROVIDER provider_name
2286 #undef TRACEPOINT_INCLUDE
2287 #define TRACEPOINT_INCLUDE "./tp.h"
2289 #if !defined(_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
2292 #include <lttng/tracepoint.h>
2295 * Use TRACEPOINT_EVENT(), TRACEPOINT_EVENT_CLASS(),
2296 * TRACEPOINT_EVENT_INSTANCE(), and TRACEPOINT_LOGLEVEL() here.
2301 #include <lttng/tracepoint-event.h>
2307 * `provider_name` with the name of your tracepoint provider.
2308 * `"tp.h"` with the name of your tracepoint provider header file.
2310 . Below the `#include <lttng/tracepoint.h>` line, put your
2311 <<defining-tracepoints,tracepoint definitions>>.
2313 Your tracepoint provider name must be unique amongst all the possible
2314 tracepoint provider names used on the same target system. We
2315 suggest to include the name of your project or company in the name,
2316 for example, `org_lttng_my_project_tpp`.
2318 TIP: [[lttng-gen-tp]]You can use the man:lttng-gen-tp(1) tool to create
2319 this boilerplate for you. When using cmd:lttng-gen-tp, all you need to
2320 write are the <<defining-tracepoints,tracepoint definitions>>.
2323 [[defining-tracepoints]]
2324 ===== Create a tracepoint definition
2326 A _tracepoint definition_ defines, for a given tracepoint:
2328 * Its **input arguments**. They are the macro parameters that the
2329 `tracepoint()` macro accepts for this particular tracepoint
2330 in the user application's source code.
2331 * Its **output event fields**. They are the sources of event fields
2332 that form the payload of any event that the execution of the
2333 `tracepoint()` macro emits for this particular tracepoint.
2335 You can create a tracepoint definition by using the
2336 `TRACEPOINT_EVENT()` macro below the `#include <lttng/tracepoint.h>`
2338 <<tpp-header,tracepoint provider header file template>>.
2340 The syntax of the `TRACEPOINT_EVENT()` macro is:
2343 .`TRACEPOINT_EVENT()` macro syntax.
2346 /* Tracepoint provider name */
2349 /* Tracepoint name */
2352 /* Input arguments */
2357 /* Output event fields */
2366 * `provider_name` with your tracepoint provider name.
2367 * `tracepoint_name` with your tracepoint name.
2368 * `arguments` with the <<tpp-def-input-args,input arguments>>.
2369 * `fields` with the <<tpp-def-output-fields,output event field>>
2372 This tracepoint emits events named `provider_name:tracepoint_name`.
2375 .Event name's length limitation
2377 The concatenation of the tracepoint provider name and the
2378 tracepoint name must not exceed **254 characters**. If it does, the
2379 instrumented application compiles and runs, but LTTng throws multiple
2380 warnings and you could experience serious issues.
2383 [[tpp-def-input-args]]The syntax of the `TP_ARGS()` macro is:
2386 .`TP_ARGS()` macro syntax.
2395 * `type` with the C type of the argument.
2396 * `arg_name` with the argument name.
2398 You can repeat `type` and `arg_name` up to 10 times to have
2399 more than one argument.
2401 .`TP_ARGS()` usage with three arguments.
2413 The `TP_ARGS()` and `TP_ARGS(void)` forms are valid to create a
2414 tracepoint definition with no input arguments.
2416 [[tpp-def-output-fields]]The `TP_FIELDS()` macro contains a list of
2417 `ctf_*()` macros. Each `ctf_*()` macro defines one event field. See
2418 man:lttng-ust(3) for a complete description of the available `ctf_*()`
2419 macros. A `ctf_*()` macro specifies the type, size, and byte order of
2422 Each `ctf_*()` macro takes an _argument expression_ parameter. This is a
2423 C expression that the tracer evalutes at the `tracepoint()` macro site
2424 in the application's source code. This expression provides a field's
2425 source of data. The argument expression can include input argument names
2426 listed in the `TP_ARGS()` macro.
2428 Each `ctf_*()` macro also takes a _field name_ parameter. Field names
2429 must be unique within a given tracepoint definition.
2431 Here's a complete tracepoint definition example:
2433 .Tracepoint definition.
2435 The following tracepoint definition defines a tracepoint which takes
2436 three input arguments and has four output event fields.
2440 #include "my-custom-structure.h"
2446 const struct my_custom_structure*, my_custom_structure,
2451 ctf_string(query_field, query)
2452 ctf_float(double, ratio_field, ratio)
2453 ctf_integer(int, recv_size, my_custom_structure->recv_size)
2454 ctf_integer(int, send_size, my_custom_structure->send_size)
2459 You can refer to this tracepoint definition with the `tracepoint()`
2460 macro in your application's source code like this:
2464 tracepoint(my_provider, my_tracepoint,
2465 my_structure, some_ratio, the_query);
2469 NOTE: The LTTng tracer only evaluates tracepoint arguments at run time
2470 if they satisfy an enabled <<event,event rule>>.
2473 [[using-tracepoint-classes]]
2474 ===== Use a tracepoint class
2476 A _tracepoint class_ is a class of tracepoints which share the same
2477 output event field definitions. A _tracepoint instance_ is one
2478 instance of such a defined tracepoint class, with its own tracepoint
2481 The <<defining-tracepoints,`TRACEPOINT_EVENT()` macro>> is actually a
2482 shorthand which defines both a tracepoint class and a tracepoint
2483 instance at the same time.
2485 When you build a tracepoint provider package, the C or $$C++$$ compiler
2486 creates one serialization function for each **tracepoint class**. A
2487 serialization function is responsible for serializing the event fields
2488 of a tracepoint to a sub-buffer when tracing.
2490 For various performance reasons, when your situation requires multiple
2491 tracepoint definitions with different names, but with the same event
2492 fields, we recommend that you manually create a tracepoint class
2493 and instantiate as many tracepoint instances as needed. One positive
2494 effect of such a design, amongst other advantages, is that all
2495 tracepoint instances of the same tracepoint class reuse the same
2496 serialization function, thus reducing
2497 https://en.wikipedia.org/wiki/Cache_pollution[cache pollution].
2499 .Use a tracepoint class and tracepoint instances.
2501 Consider the following three tracepoint definitions:
2513 ctf_integer(int, userid, userid)
2514 ctf_integer(size_t, len, len)
2526 ctf_integer(int, userid, userid)
2527 ctf_integer(size_t, len, len)
2539 ctf_integer(int, userid, userid)
2540 ctf_integer(size_t, len, len)
2545 In this case, we create three tracepoint classes, with one implicit
2546 tracepoint instance for each of them: `get_account`, `get_settings`, and
2547 `get_transaction`. However, they all share the same event field names
2548 and types. Hence three identical, yet independent serialization
2549 functions are created when you build the tracepoint provider package.
2551 A better design choice is to define a single tracepoint class and three
2552 tracepoint instances:
2556 /* The tracepoint class */
2557 TRACEPOINT_EVENT_CLASS(
2558 /* Tracepoint provider name */
2561 /* Tracepoint class name */
2564 /* Input arguments */
2570 /* Output event fields */
2572 ctf_integer(int, userid, userid)
2573 ctf_integer(size_t, len, len)
2577 /* The tracepoint instances */
2578 TRACEPOINT_EVENT_INSTANCE(
2579 /* Tracepoint provider name */
2582 /* Tracepoint class name */
2585 /* Tracepoint name */
2588 /* Input arguments */
2594 TRACEPOINT_EVENT_INSTANCE(
2603 TRACEPOINT_EVENT_INSTANCE(
2616 [[assigning-log-levels]]
2617 ===== Assign a log level to a tracepoint definition
2619 You can assign an optional _log level_ to a
2620 <<defining-tracepoints,tracepoint definition>>.
2622 Assigning different levels of severity to tracepoint definitions can
2623 be useful: when you <<enabling-disabling-events,create an event rule>>,
2624 you can target tracepoints having a log level as severe as a specific
2627 The concept of LTTng-UST log levels is similar to the levels found
2628 in typical logging frameworks:
2630 * In a logging framework, the log level is given by the function
2631 or method name you use at the log statement site: `debug()`,
2632 `info()`, `warn()`, `error()`, and so on.
2633 * In LTTng-UST, you statically assign the log level to a tracepoint
2634 definition; any `tracepoint()` macro invocation which refers to
2635 this definition has this log level.
2637 You can assign a log level to a tracepoint definition with the
2638 `TRACEPOINT_LOGLEVEL()` macro. You must use this macro _after_ the
2639 <<defining-tracepoints,`TRACEPOINT_EVENT()`>> or
2640 <<using-tracepoint-classes,`TRACEPOINT_INSTANCE()`>> macro for a given
2643 The syntax of the `TRACEPOINT_LOGLEVEL()` macro is:
2646 .`TRACEPOINT_LOGLEVEL()` macro syntax.
2648 TRACEPOINT_LOGLEVEL(provider_name, tracepoint_name, log_level)
2653 * `provider_name` with the tracepoint provider name.
2654 * `tracepoint_name` with the tracepoint name.
2655 * `log_level` with the log level to assign to the tracepoint
2656 definition named `tracepoint_name` in the `provider_name`
2657 tracepoint provider.
2659 See man:lttng-ust(3) for a list of available log level names.
2661 .Assign the `TRACE_DEBUG_UNIT` log level to a tracepoint definition.
2665 /* Tracepoint definition */
2674 ctf_integer(int, userid, userid)
2675 ctf_integer(size_t, len, len)
2679 /* Log level assignment */
2680 TRACEPOINT_LOGLEVEL(my_app, get_transaction, TRACE_DEBUG_UNIT)
2686 ===== Create a tracepoint provider package source file
2688 A _tracepoint provider package source file_ is a C source file which
2689 includes a <<tpp-header,tracepoint provider header file>> to expand its
2690 macros into event serialization and other functions.
2692 You can always use the following tracepoint provider package source
2696 .Tracepoint provider package source file template.
2698 #define TRACEPOINT_CREATE_PROBES
2703 Replace `tp.h` with the name of your <<tpp-header,tracepoint provider
2704 header file>> name. You may also include more than one tracepoint
2705 provider header file here to create a tracepoint provider package
2706 holding more than one tracepoint providers.
2709 [[probing-the-application-source-code]]
2710 ==== Add tracepoints to an application's source code
2712 Once you <<tpp-header,create a tracepoint provider header file>>, you
2713 can use the `tracepoint()` macro in your application's
2714 source code to insert the tracepoints that this header
2715 <<defining-tracepoints,defines>>.
2717 The `tracepoint()` macro takes at least two parameters: the tracepoint
2718 provider name and the tracepoint name. The corresponding tracepoint
2719 definition defines the other parameters.
2721 .`tracepoint()` usage.
2723 The following <<defining-tracepoints,tracepoint definition>> defines a
2724 tracepoint which takes two input arguments and has two output event
2728 .Tracepoint provider header file.
2730 #include "my-custom-structure.h"
2737 const char*, cmd_name
2740 ctf_string(cmd_name, cmd_name)
2741 ctf_integer(int, number_of_args, argc)
2746 You can refer to this tracepoint definition with the `tracepoint()`
2747 macro in your application's source code like this:
2750 .Application's source file.
2754 int main(int argc, char* argv[])
2756 tracepoint(my_provider, my_tracepoint, argc, argv[0]);
2762 Note how the application's source code includes
2763 the tracepoint provider header file containing the tracepoint
2764 definitions to use, path:{tp.h}.
2767 .`tracepoint()` usage with a complex tracepoint definition.
2769 Consider this complex tracepoint definition, where multiple event
2770 fields refer to the same input arguments in their argument expression
2774 .Tracepoint provider header file.
2776 /* For `struct stat` */
2777 #include <sys/types.h>
2778 #include <sys/stat.h>
2790 ctf_integer(int, my_constant_field, 23 + 17)
2791 ctf_integer(int, my_int_arg_field, my_int_arg)
2792 ctf_integer(int, my_int_arg_field2, my_int_arg * my_int_arg)
2793 ctf_integer(int, sum4_field, my_str_arg[0] + my_str_arg[1] +
2794 my_str_arg[2] + my_str_arg[3])
2795 ctf_string(my_str_arg_field, my_str_arg)
2796 ctf_integer_hex(off_t, size_field, st->st_size)
2797 ctf_float(double, size_dbl_field, (double) st->st_size)
2798 ctf_sequence_text(char, half_my_str_arg_field, my_str_arg,
2799 size_t, strlen(my_str_arg) / 2)
2804 You can refer to this tracepoint definition with the `tracepoint()`
2805 macro in your application's source code like this:
2808 .Application's source file.
2810 #define TRACEPOINT_DEFINE
2817 stat("/etc/fstab", &s);
2818 tracepoint(my_provider, my_tracepoint, 23, "Hello, World!", &s);
2824 If you look at the event record that LTTng writes when tracing this
2825 program, assuming the file size of path:{/etc/fstab} is 301{nbsp}bytes,
2826 it should look like this:
2828 .Event record fields
2830 |Field's name |Field's value
2831 |`my_constant_field` |40
2832 |`my_int_arg_field` |23
2833 |`my_int_arg_field2` |529
2835 |`my_str_arg_field` |`Hello, World!`
2836 |`size_field` |0x12d
2837 |`size_dbl_field` |301.0
2838 |`half_my_str_arg_field` |`Hello,`
2842 Sometimes, the arguments you pass to `tracepoint()` are expensive to
2843 compute--they use the call stack, for example. To avoid this
2844 computation when the tracepoint is disabled, you can use the
2845 `tracepoint_enabled()` and `do_tracepoint()` macros.
2847 The syntax of the `tracepoint_enabled()` and `do_tracepoint()` macros
2851 .`tracepoint_enabled()` and `do_tracepoint()` macros syntax.
2853 tracepoint_enabled(provider_name, tracepoint_name)
2854 do_tracepoint(provider_name, tracepoint_name, ...)
2859 * `provider_name` with the tracepoint provider name.
2860 * `tracepoint_name` with the tracepoint name.
2862 `tracepoint_enabled()` returns a non-zero value if the tracepoint named
2863 `tracepoint_name` from the provider named `provider_name` is enabled
2866 `do_tracepoint()` is like `tracepoint()`, except that it doesn't check
2867 if the tracepoint is enabled. Using `tracepoint()` with
2868 `tracepoint_enabled()` is dangerous since `tracepoint()` also contains
2869 the `tracepoint_enabled()` check, thus a race condition is
2870 possible in this situation:
2873 .Possible race condition when using `tracepoint_enabled()` with `tracepoint()`.
2875 if (tracepoint_enabled(my_provider, my_tracepoint)) {
2876 stuff = prepare_stuff();
2879 tracepoint(my_provider, my_tracepoint, stuff);
2882 If the tracepoint is enabled after the condition, then `stuff` is not
2883 prepared: the emitted event will either contain wrong data, or the whole
2884 application could crash (segmentation fault, for example).
2886 NOTE: Neither `tracepoint_enabled()` nor `do_tracepoint()` have an
2887 `STAP_PROBEV()` call. If you need it, you must emit
2891 [[building-tracepoint-providers-and-user-application]]
2892 ==== Build and link a tracepoint provider package and an application
2894 Once you have one or more <<tpp-header,tracepoint provider header
2895 files>> and a <<tpp-source,tracepoint provider package source file>>,
2896 you can create the tracepoint provider package by compiling its source
2897 file. From here, multiple build and run scenarios are possible. The
2898 following table shows common application and library configurations
2899 along with the required command lines to achieve them.
2901 In the following diagrams, we use the following file names:
2904 Executable application.
2907 Application's object file.
2910 Tracepoint provider package object file.
2913 Tracepoint provider package archive file.
2916 Tracepoint provider package shared object file.
2919 User library object file.
2922 User library shared object file.
2924 We use the following symbols in the diagrams of table below:
2927 .Symbols used in the build scenario diagrams.
2928 image::ust-sit-symbols.png[]
2930 We assume that path:{.} is part of the env:LD_LIBRARY_PATH environment
2931 variable in the following instructions.
2933 [role="growable ust-scenarios",cols="asciidoc,asciidoc"]
2934 .Common tracepoint provider package scenarios.
2936 |Scenario |Instructions
2939 The instrumented application is statically linked with
2940 the tracepoint provider package object.
2942 image::ust-sit+app-linked-with-tp-o+app-instrumented.png[]
2945 include::../common/ust-sit-step-tp-o.txt[]
2947 To build the instrumented application:
2949 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2954 #define TRACEPOINT_DEFINE
2958 . Compile the application source file:
2967 . Build the application:
2972 $ gcc -o app app.o tpp.o -llttng-ust -ldl
2976 To run the instrumented application:
2978 * Start the application:
2988 The instrumented application is statically linked with the
2989 tracepoint provider package archive file.
2991 image::ust-sit+app-linked-with-tp-a+app-instrumented.png[]
2994 To create the tracepoint provider package archive file:
2996 . Compile the <<tpp-source,tracepoint provider package source file>>:
3005 . Create the tracepoint provider package archive file:
3010 $ ar rcs tpp.a tpp.o
3014 To build the instrumented application:
3016 . In path:{app.c}, before including path:{tpp.h}, add the following line:
3021 #define TRACEPOINT_DEFINE
3025 . Compile the application source file:
3034 . Build the application:
3039 $ gcc -o app app.o tpp.a -llttng-ust -ldl
3043 To run the instrumented application:
3045 * Start the application:
3055 The instrumented application is linked with the tracepoint provider
3056 package shared object.
3058 image::ust-sit+app-linked-with-tp-so+app-instrumented.png[]
3061 include::../common/ust-sit-step-tp-so.txt[]
3063 To build the instrumented application:
3065 . In path:{app.c}, before including path:{tpp.h}, add the following line:
3070 #define TRACEPOINT_DEFINE
3074 . Compile the application source file:
3083 . Build the application:
3088 $ gcc -o app app.o -ldl -L. -ltpp
3092 To run the instrumented application:
3094 * Start the application:
3104 The tracepoint provider package shared object is preloaded before the
3105 instrumented application starts.
3107 image::ust-sit+tp-so-preloaded+app-instrumented.png[]
3110 include::../common/ust-sit-step-tp-so.txt[]
3112 To build the instrumented application:
3114 . In path:{app.c}, before including path:{tpp.h}, add the
3120 #define TRACEPOINT_DEFINE
3121 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3125 . Compile the application source file:
3134 . Build the application:
3139 $ gcc -o app app.o -ldl
3143 To run the instrumented application with tracing support:
3145 * Preload the tracepoint provider package shared object and
3146 start the application:
3151 $ LD_PRELOAD=./libtpp.so ./app
3155 To run the instrumented application without tracing support:
3157 * Start the application:
3167 The instrumented application dynamically loads the tracepoint provider
3168 package shared object.
3170 See the <<dlclose-warning,warning about `dlclose()`>>.
3172 image::ust-sit+app-dlopens-tp-so+app-instrumented.png[]
3175 include::../common/ust-sit-step-tp-so.txt[]
3177 To build the instrumented application:
3179 . In path:{app.c}, before including path:{tpp.h}, add the
3185 #define TRACEPOINT_DEFINE
3186 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3190 . Compile the application source file:
3199 . Build the application:
3204 $ gcc -o app app.o -ldl
3208 To run the instrumented application:
3210 * Start the application:
3220 The application is linked with the instrumented user library.
3222 The instrumented user library is statically linked with the tracepoint
3223 provider package object file.
3225 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-o+lib-instrumented.png[]
3228 include::../common/ust-sit-step-tp-o-fpic.txt[]
3230 To build the instrumented user library:
3232 . In path:{emon.c}, before including path:{tpp.h}, add the
3238 #define TRACEPOINT_DEFINE
3242 . Compile the user library source file:
3247 $ gcc -I. -fpic -c emon.c
3251 . Build the user library shared object:
3256 $ gcc -shared -o libemon.so emon.o tpp.o -llttng-ust -ldl
3260 To build the application:
3262 . Compile the application source file:
3271 . Build the application:
3276 $ gcc -o app app.o -L. -lemon
3280 To run the application:
3282 * Start the application:
3292 The application is linked with the instrumented user library.
3294 The instrumented user library is linked with the tracepoint provider
3295 package shared object.
3297 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3300 include::../common/ust-sit-step-tp-so.txt[]
3302 To build the instrumented user library:
3304 . In path:{emon.c}, before including path:{tpp.h}, add the
3310 #define TRACEPOINT_DEFINE
3314 . Compile the user library source file:
3319 $ gcc -I. -fpic -c emon.c
3323 . Build the user library shared object:
3328 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3332 To build the application:
3334 . Compile the application source file:
3343 . Build the application:
3348 $ gcc -o app app.o -L. -lemon
3352 To run the application:
3354 * Start the application:
3364 The tracepoint provider package shared object is preloaded before the
3367 The application is linked with the instrumented user library.
3369 image::ust-sit+tp-so-preloaded+app-linked-with-lib+lib-instrumented.png[]
3372 include::../common/ust-sit-step-tp-so.txt[]
3374 To build the instrumented user library:
3376 . In path:{emon.c}, before including path:{tpp.h}, add the
3382 #define TRACEPOINT_DEFINE
3383 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3387 . Compile the user library source file:
3392 $ gcc -I. -fpic -c emon.c
3396 . Build the user library shared object:
3401 $ gcc -shared -o libemon.so emon.o -ldl
3405 To build the application:
3407 . Compile the application source file:
3416 . Build the application:
3421 $ gcc -o app app.o -L. -lemon
3425 To run the application with tracing support:
3427 * Preload the tracepoint provider package shared object and
3428 start the application:
3433 $ LD_PRELOAD=./libtpp.so ./app
3437 To run the application without tracing support:
3439 * Start the application:
3449 The application is linked with the instrumented user library.
3451 The instrumented user library dynamically loads the tracepoint provider
3452 package shared object.
3454 See the <<dlclose-warning,warning about `dlclose()`>>.
3456 image::ust-sit+app-linked-with-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3459 include::../common/ust-sit-step-tp-so.txt[]
3461 To build the instrumented user library:
3463 . In path:{emon.c}, before including path:{tpp.h}, add the
3469 #define TRACEPOINT_DEFINE
3470 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3474 . Compile the user library source file:
3479 $ gcc -I. -fpic -c emon.c
3483 . Build the user library shared object:
3488 $ gcc -shared -o libemon.so emon.o -ldl
3492 To build the application:
3494 . Compile the application source file:
3503 . Build the application:
3508 $ gcc -o app app.o -L. -lemon
3512 To run the application:
3514 * Start the application:
3524 The application dynamically loads the instrumented user library.
3526 The instrumented user library is linked with the tracepoint provider
3527 package shared object.
3529 See the <<dlclose-warning,warning about `dlclose()`>>.
3531 image::ust-sit+app-dlopens-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3534 include::../common/ust-sit-step-tp-so.txt[]
3536 To build the instrumented user library:
3538 . In path:{emon.c}, before including path:{tpp.h}, add the
3544 #define TRACEPOINT_DEFINE
3548 . Compile the user library source file:
3553 $ gcc -I. -fpic -c emon.c
3557 . Build the user library shared object:
3562 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3566 To build the application:
3568 . Compile the application source file:
3577 . Build the application:
3582 $ gcc -o app app.o -ldl -L. -lemon
3586 To run the application:
3588 * Start the application:
3598 The application dynamically loads the instrumented user library.
3600 The instrumented user library dynamically loads the tracepoint provider
3601 package shared object.
3603 See the <<dlclose-warning,warning about `dlclose()`>>.
3605 image::ust-sit+app-dlopens-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3608 include::../common/ust-sit-step-tp-so.txt[]
3610 To build the instrumented user library:
3612 . In path:{emon.c}, before including path:{tpp.h}, add the
3618 #define TRACEPOINT_DEFINE
3619 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3623 . Compile the user library source file:
3628 $ gcc -I. -fpic -c emon.c
3632 . Build the user library shared object:
3637 $ gcc -shared -o libemon.so emon.o -ldl
3641 To build the application:
3643 . Compile the application source file:
3652 . Build the application:
3657 $ gcc -o app app.o -ldl -L. -lemon
3661 To run the application:
3663 * Start the application:
3673 The tracepoint provider package shared object is preloaded before the
3676 The application dynamically loads the instrumented user library.
3678 image::ust-sit+tp-so-preloaded+app-dlopens-lib+lib-instrumented.png[]
3681 include::../common/ust-sit-step-tp-so.txt[]
3683 To build the instrumented user library:
3685 . In path:{emon.c}, before including path:{tpp.h}, add the
3691 #define TRACEPOINT_DEFINE
3692 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3696 . Compile the user library source file:
3701 $ gcc -I. -fpic -c emon.c
3705 . Build the user library shared object:
3710 $ gcc -shared -o libemon.so emon.o -ldl
3714 To build the application:
3716 . Compile the application source file:
3725 . Build the application:
3730 $ gcc -o app app.o -L. -lemon
3734 To run the application with tracing support:
3736 * Preload the tracepoint provider package shared object and
3737 start the application:
3742 $ LD_PRELOAD=./libtpp.so ./app
3746 To run the application without tracing support:
3748 * Start the application:
3758 The application is statically linked with the tracepoint provider
3759 package object file.
3761 The application is linked with the instrumented user library.
3763 image::ust-sit+app-linked-with-tp-o+app-linked-with-lib+lib-instrumented.png[]
3766 include::../common/ust-sit-step-tp-o.txt[]
3768 To build the instrumented user library:
3770 . In path:{emon.c}, before including path:{tpp.h}, add the
3776 #define TRACEPOINT_DEFINE
3780 . Compile the user library source file:
3785 $ gcc -I. -fpic -c emon.c
3789 . Build the user library shared object:
3794 $ gcc -shared -o libemon.so emon.o
3798 To build the application:
3800 . Compile the application source file:
3809 . Build the application:
3814 $ gcc -o app app.o tpp.o -llttng-ust -ldl -L. -lemon
3818 To run the instrumented application:
3820 * Start the application:
3830 The application is statically linked with the tracepoint provider
3831 package object file.
3833 The application dynamically loads the instrumented user library.
3835 image::ust-sit+app-linked-with-tp-o+app-dlopens-lib+lib-instrumented.png[]
3838 include::../common/ust-sit-step-tp-o.txt[]
3840 To build the application:
3842 . In path:{app.c}, before including path:{tpp.h}, add the following line:
3847 #define TRACEPOINT_DEFINE
3851 . Compile the application source file:
3860 . Build the application:
3865 $ gcc -Wl,--export-dynamic -o app app.o tpp.o \
3870 The `--export-dynamic` option passed to the linker is necessary for the
3871 dynamically loaded library to ``see'' the tracepoint symbols defined in
3874 To build the instrumented user library:
3876 . Compile the user library source file:
3881 $ gcc -I. -fpic -c emon.c
3885 . Build the user library shared object:
3890 $ gcc -shared -o libemon.so emon.o
3894 To run the application:
3896 * Start the application:
3908 .Do not use man:dlclose(3) on a tracepoint provider package
3910 Never use man:dlclose(3) on any shared object which:
3912 * Is linked with, statically or dynamically, a tracepoint provider
3914 * Calls man:dlopen(3) itself to dynamically open a tracepoint provider
3915 package shared object.
3917 This is currently considered **unsafe** due to a lack of reference
3918 counting from LTTng-UST to the shared object.
3920 A known workaround (available since glibc 2.2) is to use the
3921 `RTLD_NODELETE` flag when calling man:dlopen(3) initially. This has the
3922 effect of not unloading the loaded shared object, even if man:dlclose(3)
3925 You can also preload the tracepoint provider package shared object with
3926 the env:LD_PRELOAD environment variable to overcome this limitation.
3930 [[using-lttng-ust-with-daemons]]
3931 ===== Use noch:{LTTng-UST} with daemons
3933 If your instrumented application calls man:fork(2), man:clone(2),
3934 or BSD's man:rfork(2), without a following man:exec(3)-family
3935 system call, you must preload the path:{liblttng-ust-fork.so} shared
3936 object when starting the application.
3940 $ LD_PRELOAD=liblttng-ust-fork.so ./my-app
3943 If your tracepoint provider package is
3944 a shared library which you also preload, you must put both
3945 shared objects in env:LD_PRELOAD:
3949 $ LD_PRELOAD=liblttng-ust-fork.so:/path/to/tp.so ./my-app
3953 [[lttng-ust-pkg-config]]
3954 ===== Use noch:{pkg-config}
3956 On some distributions, LTTng-UST ships with a
3957 https://www.freedesktop.org/wiki/Software/pkg-config/[pkg-config]
3958 metadata file. If this is your case, then you can use cmd:pkg-config to
3959 build an application on the command line:
3963 $ gcc -o my-app my-app.o tp.o $(pkg-config --cflags --libs lttng-ust)
3967 [[instrumenting-32-bit-app-on-64-bit-system]]
3968 ===== [[advanced-instrumenting-techniques]]Build a 32-bit instrumented application for a 64-bit target system
3970 In order to trace a 32-bit application running on a 64-bit system,
3971 LTTng must use a dedicated 32-bit
3972 <<lttng-consumerd,consumer daemon>>.
3974 The following steps show how to build and install a 32-bit consumer
3975 daemon, which is _not_ part of the default 64-bit LTTng build, how to
3976 build and install the 32-bit LTTng-UST libraries, and how to build and
3977 link an instrumented 32-bit application in that context.
3979 To build a 32-bit instrumented application for a 64-bit target system,
3980 assuming you have a fresh target system with no installed Userspace RCU
3983 . Download, build, and install a 32-bit version of Userspace RCU:
3988 $ cd $(mktemp -d) &&
3989 wget http://lttng.org/files/urcu/userspace-rcu-latest-0.9.tar.bz2 &&
3990 tar -xf userspace-rcu-latest-0.9.tar.bz2 &&
3991 cd userspace-rcu-0.9.* &&
3992 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 &&
3994 sudo make install &&
3999 . Using your distribution's package manager, or from source, install
4000 the following 32-bit versions of the following dependencies of
4001 LTTng-tools and LTTng-UST:
4004 * https://sourceforge.net/projects/libuuid/[libuuid]
4005 * http://directory.fsf.org/wiki/Popt[popt]
4006 * http://www.xmlsoft.org/[libxml2]
4009 . Download, build, and install a 32-bit version of the latest
4010 LTTng-UST{nbsp}{revision}:
4015 $ cd $(mktemp -d) &&
4016 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.8.tar.bz2 &&
4017 tar -xf lttng-ust-latest-2.8.tar.bz2 &&
4018 cd lttng-ust-2.8.* &&
4019 ./configure --libdir=/usr/local/lib32 \
4020 CFLAGS=-m32 CXXFLAGS=-m32 \
4021 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' &&
4023 sudo make install &&
4030 Depending on your distribution,
4031 32-bit libraries could be installed at a different location than
4032 `/usr/lib32`. For example, Debian is known to install
4033 some 32-bit libraries in `/usr/lib/i386-linux-gnu`.
4035 In this case, make sure to set `LDFLAGS` to all the
4036 relevant 32-bit library paths, for example:
4040 $ LDFLAGS='-L/usr/lib/i386-linux-gnu -L/usr/lib32'
4044 . Download the latest LTTng-tools{nbsp}{revision}, build, and install
4045 the 32-bit consumer daemon:
4050 $ cd $(mktemp -d) &&
4051 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.8.tar.bz2 &&
4052 tar -xf lttng-tools-latest-2.8.tar.bz2 &&
4053 cd lttng-tools-2.8.* &&
4054 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 CXXFLAGS=-m32 \
4055 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' \
4056 --disable-bin-lttng --disable-bin-lttng-crash \
4057 --disable-bin-lttng-relayd --disable-bin-lttng-sessiond &&
4059 cd src/bin/lttng-consumerd &&
4060 sudo make install &&
4065 . From your distribution or from source,
4066 <<installing-lttng,install>> the 64-bit versions of
4067 LTTng-UST and Userspace RCU.
4068 . Download, build, and install the 64-bit version of the
4069 latest LTTng-tools{nbsp}{revision}:
4074 $ cd $(mktemp -d) &&
4075 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.8.tar.bz2 &&
4076 tar -xf lttng-tools-latest-2.8.tar.bz2 &&
4077 cd lttng-tools-2.8.* &&
4078 ./configure --with-consumerd32-libdir=/usr/local/lib32 \
4079 --with-consumerd32-bin=/usr/local/lib32/lttng/libexec/lttng-consumerd &&
4081 sudo make install &&
4086 . Pass the following options to man:gcc(1), man:g++(1), or man:clang(1)
4087 when linking your 32-bit application:
4090 -m32 -L/usr/lib32 -L/usr/local/lib32 \
4091 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32
4094 For example, let's rebuild the quick start example in
4095 <<tracing-your-own-user-application,Trace a user application>> as an
4096 instrumented 32-bit application:
4101 $ gcc -m32 -c -I. hello-tp.c
4102 $ gcc -m32 -c hello.c
4103 $ gcc -m32 -o hello hello.o hello-tp.o \
4104 -L/usr/lib32 -L/usr/local/lib32 \
4105 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32 \
4110 No special action is required to execute the 32-bit application and
4111 to trace it: use the command-line man:lttng(1) tool as usual.
4118 man:tracef(3) is a small LTTng-UST API designed for quick,
4119 man:printf(3)-like instrumentation without the burden of
4120 <<tracepoint-provider,creating>> and
4121 <<building-tracepoint-providers-and-user-application,building>>
4122 a tracepoint provider package.
4124 To use `tracef()` in your application:
4126 . In the C or C++ source files where you need to use `tracef()`,
4127 include `<lttng/tracef.h>`:
4132 #include <lttng/tracef.h>
4136 . In the application's source code, use `tracef()` like you would use
4144 tracef("my message: %d (%s)", my_integer, my_string);
4150 . Link your application with `liblttng-ust`:
4155 $ gcc -o app app.c -llttng-ust
4159 To trace the events that `tracef()` calls emit:
4161 * <<enabling-disabling-events,Create an event rule>> which matches the
4162 `lttng_ust_tracef:*` event name:
4167 $ lttng enable-event --userspace 'lttng_ust_tracef:*'
4172 .Limitations of `tracef()`
4174 The `tracef()` utility function was developed to make user space tracing
4175 super simple, albeit with notable disadvantages compared to
4176 <<defining-tracepoints,user-defined tracepoints>>:
4178 * All the emitted events have the same tracepoint provider and
4179 tracepoint names, respectively `lttng_ust_tracef` and `event`.
4180 * There is no static type checking.
4181 * The only event record field you actually get, named `msg`, is a string
4182 potentially containing the values you passed to `tracef()`
4183 using your own format string. This also means that you cannot filter
4184 events with a custom expression at run time because there are no
4186 * Since `tracef()` uses the C standard library's man:vasprintf(3)
4187 function behind the scenes to format the strings at run time, its
4188 expected performance is lower than with user-defined tracepoints,
4189 which do not require a conversion to a string.
4191 Taking this into consideration, `tracef()` is useful for some quick
4192 prototyping and debugging, but you should not consider it for any
4193 permanent and serious applicative instrumentation.
4199 ==== Use `tracelog()`
4201 The man:tracelog(3) API is very similar to <<tracef,`tracef()`>>, with
4202 the difference that it accepts an additional log level parameter.
4204 The goal of `tracelog()` is to ease the migration from logging to
4207 To use `tracelog()` in your application:
4209 . In the C or C++ source files where you need to use `tracelog()`,
4210 include `<lttng/tracelog.h>`:
4215 #include <lttng/tracelog.h>
4219 . In the application's source code, use `tracelog()` like you would use
4220 man:printf(3), except for the first parameter which is the log
4228 tracelog(TRACE_WARNING, "my message: %d (%s)",
4229 my_integer, my_string);
4235 See man:lttng-ust(3) for a list of available log level names.
4237 . Link your application with `liblttng-ust`:
4242 $ gcc -o app app.c -llttng-ust
4246 To trace the events that `tracelog()` calls emit with a log level
4247 _as severe as_ a specific log level:
4249 * <<enabling-disabling-events,Create an event rule>> which matches the
4250 `lttng_ust_tracelog:*` event name and a minimum level
4256 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
4257 --loglevel=TRACE_WARNING
4261 To trace the events that `tracelog()` calls emit with a
4262 _specific log level_:
4264 * Create an event rule which matches the `lttng_ust_tracelog:*`
4265 event name and a specific log level:
4270 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
4271 --loglevel-only=TRACE_INFO
4276 [[prebuilt-ust-helpers]]
4277 === Prebuilt user space tracing helpers
4279 The LTTng-UST package provides a few helpers in the form or preloadable
4280 shared objects which automatically instrument system functions and
4283 The helper shared objects are normally found in dir:{/usr/lib}. If you
4284 built LTTng-UST <<building-from-source,from source>>, they are probably
4285 located in dir:{/usr/local/lib}.
4287 The installed user space tracing helpers in LTTng-UST{nbsp}{revision}
4290 path:{liblttng-ust-libc-wrapper.so}::
4291 path:{liblttng-ust-pthread-wrapper.so}::
4292 <<liblttng-ust-libc-pthread-wrapper,C{nbsp}standard library
4293 memory and POSIX threads function tracing>>.
4295 path:{liblttng-ust-cyg-profile.so}::
4296 path:{liblttng-ust-cyg-profile-fast.so}::
4297 <<liblttng-ust-cyg-profile,Function entry and exit tracing>>.
4299 path:{liblttng-ust-dl.so}::
4300 <<liblttng-ust-dl,Dynamic linker tracing>>.
4302 To use a user space tracing helper with any user application:
4304 * Preload the helper shared object when you start the application:
4309 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so my-app
4313 You can preload more than one helper:
4318 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so:liblttng-ust-dl.so my-app
4324 [[liblttng-ust-libc-pthread-wrapper]]
4325 ==== Instrument C standard library memory and POSIX threads functions
4327 The path:{liblttng-ust-libc-wrapper.so} and
4328 path:{liblttng-ust-pthread-wrapper.so} helpers
4329 add instrumentation to some C standard library and POSIX
4333 .Functions instrumented by preloading path:{liblttng-ust-libc-wrapper.so}.
4335 |TP provider name |TP name |Instrumented function
4337 .6+|`lttng_ust_libc` |`malloc` |man:malloc(3)
4338 |`calloc` |man:calloc(3)
4339 |`realloc` |man:realloc(3)
4340 |`free` |man:free(3)
4341 |`memalign` |man:memalign(3)
4342 |`posix_memalign` |man:posix_memalign(3)
4346 .Functions instrumented by preloading path:{liblttng-ust-pthread-wrapper.so}.
4348 |TP provider name |TP name |Instrumented function
4350 .4+|`lttng_ust_pthread` |`pthread_mutex_lock_req` |man:pthread_mutex_lock(3p) (request time)
4351 |`pthread_mutex_lock_acq` |man:pthread_mutex_lock(3p) (acquire time)
4352 |`pthread_mutex_trylock` |man:pthread_mutex_trylock(3p)
4353 |`pthread_mutex_unlock` |man:pthread_mutex_unlock(3p)
4356 When you preload the shared object, it replaces the functions listed
4357 in the previous tables by wrappers which contain tracepoints and call
4358 the replaced functions.
4361 [[liblttng-ust-cyg-profile]]
4362 ==== Instrument function entry and exit
4364 The path:{liblttng-ust-cyg-profile*.so} helpers can add instrumentation
4365 to the entry and exit points of functions.
4367 man:gcc(1) and man:clang(1) have an option named
4368 https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html[`-finstrument-functions`]
4369 which generates instrumentation calls for entry and exit to functions.
4370 The LTTng-UST function tracing helpers,
4371 path:{liblttng-ust-cyg-profile.so} and
4372 path:{liblttng-ust-cyg-profile-fast.so}, take advantage of this feature
4373 to add tracepoints to the two generated functions (which contain
4374 `cyg_profile` in their names, hence the helper's name).
4376 To use the LTTng-UST function tracing helper, the source files to
4377 instrument must be built using the `-finstrument-functions` compiler
4380 There are two versions of the LTTng-UST function tracing helper:
4382 * **path:{liblttng-ust-cyg-profile-fast.so}** is a lightweight variant
4383 that you should only use when it can be _guaranteed_ that the
4384 complete event stream is recorded without any lost event record.
4385 Any kind of duplicate information is left out.
4387 Assuming no event record is lost, having only the function addresses on
4388 entry is enough to create a call graph, since an event record always
4389 contains the ID of the CPU that generated it.
4391 You can use a tool like man:addr2line(1) to convert function addresses
4392 back to source file names and line numbers.
4394 * **path:{liblttng-ust-cyg-profile.so}** is a more robust variant
4395 which also works in use cases where event records might get discarded or
4396 not recorded from application startup.
4397 In these cases, the trace analyzer needs more information to be
4398 able to reconstruct the program flow.
4400 See man:lttng-ust-cyg-profile(3) to learn more about the instrumentation
4401 points of this helper.
4403 All the tracepoints that this helper provides have the
4404 log level `TRACE_DEBUG_FUNCTION` (see man:lttng-ust(3)).
4406 TIP: It's sometimes a good idea to limit the number of source files that
4407 you compile with the `-finstrument-functions` option to prevent LTTng
4408 from writing an excessive amount of trace data at run time. When using
4409 man:gcc(1), you can use the
4410 `-finstrument-functions-exclude-function-list` option to avoid
4411 instrument entries and exits of specific function names.
4416 ==== Instrument the dynamic linker
4418 The path:{liblttng-ust-dl.so} helper adds instrumentation to the
4419 man:dlopen(3) and man:dlclose(3) function calls.
4421 See man:lttng-ust-dl(3) to learn more about the instrumentation points
4426 [[java-application]]
4427 === User space Java agent
4429 You can instrument any Java application which uses one of the following
4432 * The https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[**`java.util.logging`**]
4433 (JUL) core logging facilities.
4434 * http://logging.apache.org/log4j/1.2/[**Apache log4j 1.2**], since
4435 LTTng 2.6. Note that Apache Log4j{nbsp}2 is not supported.
4438 .LTTng-UST Java agent imported by a Java application.
4439 image::java-app.png[]
4441 Note that the methods described below are new in LTTng{nbsp}{revision}.
4442 Previous LTTng versions use another technique.
4444 NOTE: We use http://openjdk.java.net/[OpenJDK]{nbsp}8 for development
4445 and https://ci.lttng.org/[continuous integration], thus this version is
4446 directly supported. However, the LTTng-UST Java agent is also tested
4447 with OpenJDK{nbsp}7.
4452 ==== Use the LTTng-UST Java agent for `java.util.logging`
4454 To use the LTTng-UST Java agent in a Java application which uses
4455 `java.util.logging` (JUL):
4457 . In the Java application's source code, import the LTTng-UST
4458 log handler package for `java.util.logging`:
4463 import org.lttng.ust.agent.jul.LttngLogHandler;
4467 . Create an LTTng-UST JUL log handler:
4472 Handler lttngUstLogHandler = new LttngLogHandler();
4476 . Add this handler to the JUL loggers which should emit LTTng events:
4481 Logger myLogger = Logger.getLogger("some-logger");
4483 myLogger.addHandler(lttngUstLogHandler);
4487 . Use `java.util.logging` log statements and configuration as usual.
4488 The loggers with an attached LTTng-UST log handler can emit
4491 . Before exiting the application, remove the LTTng-UST log handler from
4492 the loggers attached to it and call its `close()` method:
4497 myLogger.removeHandler(lttngUstLogHandler);
4498 lttngUstLogHandler.close();
4502 This is not strictly necessary, but it is recommended for a clean
4503 disposal of the handler's resources.
4505 . Include the LTTng-UST Java agent's common and JUL-specific JAR files,
4506 path:{lttng-ust-agent-common.jar} and path:{lttng-ust-agent-jul.jar},
4508 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4509 path] when you build the Java application.
4511 The JAR files are typically located in dir:{/usr/share/java}.
4513 IMPORTANT: The LTTng-UST Java agent must be
4514 <<installing-lttng,installed>> for the logging framework your
4517 .Use the LTTng-UST Java agent for `java.util.logging`.
4522 import java.io.IOException;
4523 import java.util.logging.Handler;
4524 import java.util.logging.Logger;
4525 import org.lttng.ust.agent.jul.LttngLogHandler;
4529 private static final int answer = 42;
4531 public static void main(String[] argv) throws Exception
4534 Logger logger = Logger.getLogger("jello");
4536 // Create an LTTng-UST log handler
4537 Handler lttngUstLogHandler = new LttngLogHandler();
4539 // Add the LTTng-UST log handler to our logger
4540 logger.addHandler(lttngUstLogHandler);
4543 logger.info("some info");
4544 logger.warning("some warning");
4546 logger.finer("finer information; the answer is " + answer);
4548 logger.severe("error!");
4550 // Not mandatory, but cleaner
4551 logger.removeHandler(lttngUstLogHandler);
4552 lttngUstLogHandler.close();
4561 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4564 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4565 <<enabling-disabling-events,create an event rule>> matching the
4566 `jello` JUL logger, and <<basic-tracing-session-control,start tracing>>:
4571 $ lttng enable-event --jul jello
4575 Run the compiled class:
4579 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4582 <<basic-tracing-session-control,Stop tracing>> and inspect the
4592 In the resulting trace, an <<event,event record>> generated by a Java
4593 application using `java.util.logging` is named `lttng_jul:event` and
4594 has the following fields:
4597 Log record's message.
4603 Name of the class in which the log statement was executed.
4606 Name of the method in which the log statement was executed.
4609 Logging time (timestamp in milliseconds).
4612 Log level integer value.
4615 ID of the thread in which the log statement was executed.
4617 You can use the opt:lttng-enable-event(1):--loglevel or
4618 opt:lttng-enable-event(1):--loglevel-only option of the
4619 man:lttng-enable-event(1) command to target a range of JUL log levels
4620 or a specific JUL log level.
4625 ==== Use the LTTng-UST Java agent for Apache log4j
4627 To use the LTTng-UST Java agent in a Java application which uses
4630 . In the Java application's source code, import the LTTng-UST
4631 log appender package for Apache log4j:
4636 import org.lttng.ust.agent.log4j.LttngLogAppender;
4640 . Create an LTTng-UST log4j log appender:
4645 Appender lttngUstLogAppender = new LttngLogAppender();
4649 . Add this appender to the log4j loggers which should emit LTTng events:
4654 Logger myLogger = Logger.getLogger("some-logger");
4656 myLogger.addAppender(lttngUstLogAppender);
4660 . Use Apache log4j log statements and configuration as usual. The
4661 loggers with an attached LTTng-UST log appender can emit LTTng events.
4663 . Before exiting the application, remove the LTTng-UST log appender from
4664 the loggers attached to it and call its `close()` method:
4669 myLogger.removeAppender(lttngUstLogAppender);
4670 lttngUstLogAppender.close();
4674 This is not strictly necessary, but it is recommended for a clean
4675 disposal of the appender's resources.
4677 . Include the LTTng-UST Java agent's common and log4j-specific JAR
4678 files, path:{lttng-ust-agent-common.jar} and
4679 path:{lttng-ust-agent-log4j.jar}, in the
4680 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4681 path] when you build the Java application.
4683 The JAR files are typically located in dir:{/usr/share/java}.
4685 IMPORTANT: The LTTng-UST Java agent must be
4686 <<installing-lttng,installed>> for the logging framework your
4689 .Use the LTTng-UST Java agent for Apache log4j.
4694 import org.apache.log4j.Appender;
4695 import org.apache.log4j.Logger;
4696 import org.lttng.ust.agent.log4j.LttngLogAppender;
4700 private static final int answer = 42;
4702 public static void main(String[] argv) throws Exception
4705 Logger logger = Logger.getLogger("jello");
4707 // Create an LTTng-UST log appender
4708 Appender lttngUstLogAppender = new LttngLogAppender();
4710 // Add the LTTng-UST log appender to our logger
4711 logger.addAppender(lttngUstLogAppender);
4714 logger.info("some info");
4715 logger.warn("some warning");
4717 logger.debug("debug information; the answer is " + answer);
4719 logger.fatal("error!");
4721 // Not mandatory, but cleaner
4722 logger.removeAppender(lttngUstLogAppender);
4723 lttngUstLogAppender.close();
4729 Build this example (`$LOG4JPATH` is the path to the Apache log4j JAR
4734 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH Test.java
4737 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4738 <<enabling-disabling-events,create an event rule>> matching the
4739 `jello` log4j logger, and <<basic-tracing-session-control,start tracing>>:
4744 $ lttng enable-event --log4j jello
4748 Run the compiled class:
4752 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH:. Test
4755 <<basic-tracing-session-control,Stop tracing>> and inspect the
4765 In the resulting trace, an <<event,event record>> generated by a Java
4766 application using log4j is named `lttng_log4j:event` and
4767 has the following fields:
4770 Log record's message.
4776 Name of the class in which the log statement was executed.
4779 Name of the method in which the log statement was executed.
4782 Name of the file in which the executed log statement is located.
4785 Line number at which the log statement was executed.
4791 Log level integer value.
4794 Name of the Java thread in which the log statement was executed.
4796 You can use the opt:lttng-enable-event(1):--loglevel or
4797 opt:lttng-enable-event(1):--loglevel-only option of the
4798 man:lttng-enable-event(1) command to target a range of Apache log4j log levels
4799 or a specific log4j log level.
4803 [[java-application-context]]
4804 ==== Provide application-specific context fields in a Java application
4806 A Java application-specific context field is a piece of state provided
4807 by the application which <<adding-context,you can add>>, using the
4808 man:lttng-add-context(1) command, to each <<event,event record>>
4809 produced by the log statements of this application.
4811 For example, a given object might have a current request ID variable.
4812 You can create a context information retriever for this object and
4813 assign a name to this current request ID. You can then, using the
4814 man:lttng-add-context(1) command, add this context field by name to
4815 the JUL or log4j <<channel,channel>>.
4817 To provide application-specific context fields in a Java application:
4819 . In the Java application's source code, import the LTTng-UST
4820 Java agent context classes and interfaces:
4825 import org.lttng.ust.agent.context.ContextInfoManager;
4826 import org.lttng.ust.agent.context.IContextInfoRetriever;
4830 . Create a context information retriever class, that is, a class which
4831 implements the `IContextInfoRetriever` interface:
4836 class MyContextInfoRetriever implements IContextInfoRetriever
4839 public Object retrieveContextInfo(String key)
4841 if (key.equals("intCtx")) {
4843 } else if (key.equals("strContext")) {
4844 return "context value!";
4853 This `retrieveContextInfo()` method is the only member of the
4854 `IContextInfoRetriever` interface. Its role is to return the current
4855 value of a state by name to create a context field. The names of the
4856 context fields and which state variables they return depends on your
4859 All primitive types and objects are supported as context fields.
4860 When `retrieveContextInfo()` returns an object, the context field
4861 serializer calls its `toString()` method to add a string field to
4862 event records. The method can also return `null`, which means that
4863 no context field is available for the required name.
4865 . Register an instance of your context information retriever class to
4866 the context information manager singleton:
4871 IContextInfoRetriever cir = new MyContextInfoRetriever();
4872 ContextInfoManager cim = ContextInfoManager.getInstance();
4873 cim.registerContextInfoRetriever("retrieverName", cir);
4877 . Before exiting the application, remove your context information
4878 retriever from the context information manager singleton:
4883 ContextInfoManager cim = ContextInfoManager.getInstance();
4884 cim.unregisterContextInfoRetriever("retrieverName");
4888 This is not strictly necessary, but it is recommended for a clean
4889 disposal of some manager's resources.
4891 . Build your Java application with LTTng-UST Java agent support as
4892 usual, following the procedure for either the <<jul,JUL>> or
4893 <<log4j,Apache log4j>> framework.
4896 .Provide application-specific context fields in a Java application.
4901 import java.util.logging.Handler;
4902 import java.util.logging.Logger;
4903 import org.lttng.ust.agent.jul.LttngLogHandler;
4904 import org.lttng.ust.agent.context.ContextInfoManager;
4905 import org.lttng.ust.agent.context.IContextInfoRetriever;
4909 // Our context information retriever class
4910 private static class MyContextInfoRetriever
4911 implements IContextInfoRetriever
4914 public Object retrieveContextInfo(String key) {
4915 if (key.equals("intCtx")) {
4917 } else if (key.equals("strContext")) {
4918 return "context value!";
4925 private static final int answer = 42;
4927 public static void main(String args[]) throws Exception
4929 // Get the context information manager instance
4930 ContextInfoManager cim = ContextInfoManager.getInstance();
4932 // Create and register our context information retriever
4933 IContextInfoRetriever cir = new MyContextInfoRetriever();
4934 cim.registerContextInfoRetriever("myRetriever", cir);
4937 Logger logger = Logger.getLogger("jello");
4939 // Create an LTTng-UST log handler
4940 Handler lttngUstLogHandler = new LttngLogHandler();
4942 // Add the LTTng-UST log handler to our logger
4943 logger.addHandler(lttngUstLogHandler);
4946 logger.info("some info");
4947 logger.warning("some warning");
4949 logger.finer("finer information; the answer is " + answer);
4951 logger.severe("error!");
4953 // Not mandatory, but cleaner
4954 logger.removeHandler(lttngUstLogHandler);
4955 lttngUstLogHandler.close();
4956 cim.unregisterContextInfoRetriever("myRetriever");
4965 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4968 <<creating-destroying-tracing-sessions,Create a tracing session>>
4969 and <<enabling-disabling-events,create an event rule>> matching the
4975 $ lttng enable-event --jul jello
4978 <<adding-context,Add the application-specific context fields>> to the
4983 $ lttng add-context --jul --type='$app.myRetriever:intCtx'
4984 $ lttng add-context --jul --type='$app.myRetriever:strContext'
4987 <<basic-tracing-session-control,Start tracing>>:
4994 Run the compiled class:
4998 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
5001 <<basic-tracing-session-control,Stop tracing>> and inspect the
5013 [[python-application]]
5014 === User space Python agent
5016 You can instrument a Python 2 or Python 3 application which uses the
5017 standard https://docs.python.org/3/library/logging.html[`logging`]
5020 Each log statement emits an LTTng event once the
5021 application module imports the
5022 <<lttng-ust-agents,LTTng-UST Python agent>> package.
5025 .A Python application importing the LTTng-UST Python agent.
5026 image::python-app.png[]
5028 To use the LTTng-UST Python agent:
5030 . In the Python application's source code, import the LTTng-UST Python
5040 The LTTng-UST Python agent automatically adds its logging handler to the
5041 root logger at import time.
5043 Any log statement that the application executes before this import does
5044 not emit an LTTng event.
5046 IMPORTANT: The LTTng-UST Python agent must be
5047 <<installing-lttng,installed>>.
5049 . Use log statements and logging configuration as usual.
5050 Since the LTTng-UST Python agent adds a handler to the _root_
5051 logger, you can trace any log statement from any logger.
5053 .Use the LTTng-UST Python agent.
5064 logging.basicConfig()
5065 logger = logging.getLogger('my-logger')
5068 logger.debug('debug message')
5069 logger.info('info message')
5070 logger.warn('warn message')
5071 logger.error('error message')
5072 logger.critical('critical message')
5076 if __name__ == '__main__':
5080 NOTE: `logging.basicConfig()`, which adds to the root logger a basic
5081 logging handler which prints to the standard error stream, is not
5082 strictly required for LTTng-UST tracing to work, but in versions of
5083 Python preceding 3.2, you could see a warning message which indicates
5084 that no handler exists for the logger `my-logger`.
5086 <<creating-destroying-tracing-sessions,Create a tracing session>>,
5087 <<enabling-disabling-events,create an event rule>> matching the
5088 `my-logger` Python logger, and <<basic-tracing-session-control,start
5094 $ lttng enable-event --python my-logger
5098 Run the Python script:
5105 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
5115 In the resulting trace, an <<event,event record>> generated by a Python
5116 application is named `lttng_python:event` and has the following fields:
5119 Logging time (string).
5122 Log record's message.
5128 Name of the function in which the log statement was executed.
5131 Line number at which the log statement was executed.
5134 Log level integer value.
5137 ID of the Python thread in which the log statement was executed.
5140 Name of the Python thread in which the log statement was executed.
5142 You can use the opt:lttng-enable-event(1):--loglevel or
5143 opt:lttng-enable-event(1):--loglevel-only option of the
5144 man:lttng-enable-event(1) command to target a range of Python log levels
5145 or a specific Python log level.
5147 When an application imports the LTTng-UST Python agent, the agent tries
5148 to register to a <<lttng-sessiond,session daemon>>. Note that you must
5149 <<start-sessiond,start the session daemon>> _before_ you run the Python
5150 application. If a session daemon is found, the agent tries to register
5151 to it during 5{nbsp}seconds, after which the application continues
5152 without LTTng tracing support. You can override this timeout value with
5153 the env:LTTNG_UST_PYTHON_REGISTER_TIMEOUT environment variable
5156 If the session daemon stops while a Python application with an imported
5157 LTTng-UST Python agent runs, the agent retries to connect and to
5158 register to a session daemon every 3{nbsp}seconds. You can override this
5159 delay with the env:LTTNG_UST_PYTHON_REGISTER_RETRY_DELAY environment
5164 [[proc-lttng-logger-abi]]
5167 The `lttng-tracer` Linux kernel module, part of
5168 <<lttng-modules,LTTng-modules>>, creates the special LTTng logger file
5169 path:{/proc/lttng-logger} when it's loaded. Any application can write
5170 text data to this file to emit an LTTng event.
5173 .An application writes to the LTTng logger file to emit an LTTng event.
5174 image::lttng-logger.png[]
5176 The LTTng logger is the quickest method--not the most efficient,
5177 however--to add instrumentation to an application. It is designed
5178 mostly to instrument shell scripts:
5182 $ echo "Some message, some $variable" > /proc/lttng-logger
5185 Any event that the LTTng logger emits is named `lttng_logger` and
5186 belongs to the Linux kernel <<domain,tracing domain>>. However, unlike
5187 other instrumentation points in the kernel tracing domain, **any Unix
5188 user** can <<enabling-disabling-events,create an event rule>> which
5189 matches its event name, not only the root user or users in the
5190 <<tracing-group,tracing group>>.
5192 To use the LTTng logger:
5194 * From any application, write text data to the path:{/proc/lttng-logger}
5197 The `msg` field of `lttng_logger` event records contains the
5200 NOTE: The maximum message length of an LTTng logger event is
5201 1024{nbsp}bytes. Writing more than this makes the LTTng logger emit more
5202 than one event to contain the remaining data.
5204 You should not use the LTTng logger to trace a user application which
5205 can be instrumented in a more efficient way, namely:
5207 * <<c-application,C and $$C++$$ applications>>.
5208 * <<java-application,Java applications>>.
5209 * <<python-application,Python applications>>.
5211 .Use the LTTng logger.
5216 echo 'Hello, World!' > /proc/lttng-logger
5218 df --human-readable --print-type / > /proc/lttng-logger
5221 <<creating-destroying-tracing-sessions,Create a tracing session>>,
5222 <<enabling-disabling-events,create an event rule>> matching the
5223 `lttng_logger` Linux kernel tracepoint, and
5224 <<basic-tracing-session-control,start tracing>>:
5229 $ lttng enable-event --kernel lttng_logger
5233 Run the Bash script:
5240 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
5251 [[instrumenting-linux-kernel]]
5252 === LTTng kernel tracepoints
5254 NOTE: This section shows how to _add_ instrumentation points to the
5255 Linux kernel. The kernel's subsystems are already thoroughly
5256 instrumented at strategic places for LTTng when you
5257 <<installing-lttng,install>> the <<lttng-modules,LTTng-modules>>
5261 There are two methods to instrument the Linux kernel:
5263 . <<linux-add-lttng-layer,Add an LTTng layer>> over an existing ftrace
5264 tracepoint which uses the `TRACE_EVENT()` API.
5266 Choose this if you want to instrumentation a Linux kernel tree with an
5267 instrumentation point compatible with ftrace, perf, and SystemTap.
5269 . Use an <<linux-lttng-tracepoint-event,LTTng-only approach>> to
5270 instrument an out-of-tree kernel module.
5272 Choose this if you don't need ftrace, perf, or SystemTap support.
5276 [[linux-add-lttng-layer]]
5277 ==== [[instrumenting-linux-kernel-itself]][[mainline-trace-event]][[lttng-adaptation-layer]]Add an LTTng layer to an existing ftrace tracepoint
5279 This section shows how to add an LTTng layer to existing ftrace
5280 instrumentation using the `TRACE_EVENT()` API.
5282 This section does not document the `TRACE_EVENT()` macro. You can
5283 read the following articles to learn more about this API:
5285 * http://lwn.net/Articles/379903/[Using the TRACE_EVENT() macro (Part 1)]
5286 * http://lwn.net/Articles/381064/[Using the TRACE_EVENT() macro (Part 2)]
5287 * http://lwn.net/Articles/383362/[Using the TRACE_EVENT() macro (Part 3)]
5289 The following procedure assumes that your ftrace tracepoints are
5290 correctly defined in their own header and that they are created in
5291 one source file using the `CREATE_TRACE_POINTS` definition.
5293 To add an LTTng layer over an existing ftrace tracepoint:
5295 . Make sure the following kernel configuration options are
5301 * `CONFIG_HIGH_RES_TIMERS`
5302 * `CONFIG_TRACEPOINTS`
5305 . Build the Linux source tree with your custom ftrace tracepoints.
5306 . Boot the resulting Linux image on your target system.
5308 Confirm that the tracepoints exist by looking for their names in the
5309 dir:{/sys/kernel/debug/tracing/events/subsys} directory, where `subsys`
5310 is your subsystem's name.
5312 . Get a copy of the latest LTTng-modules{nbsp}{revision}:
5317 $ cd $(mktemp -d) &&
5318 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.8.tar.bz2 &&
5319 tar -xf lttng-modules-latest-2.8.tar.bz2 &&
5320 cd lttng-modules-2.8.*
5324 . In dir:{instrumentation/events/lttng-module}, relative to the root
5325 of the LTTng-modules source tree, create a header file named
5326 +__subsys__.h+ for your custom subsystem +__subsys__+ and write your
5327 LTTng-modules tracepoint definitions using the LTTng-modules
5330 Start with this template:
5334 .path:{instrumentation/events/lttng-module/my_subsys.h}
5337 #define TRACE_SYSTEM my_subsys
5339 #if !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ)
5340 #define _LTTNG_MY_SUBSYS_H
5342 #include "../../../probes/lttng-tracepoint-event.h"
5343 #include <linux/tracepoint.h>
5345 LTTNG_TRACEPOINT_EVENT(
5347 * Format is identical to TRACE_EVENT()'s version for the three
5348 * following macro parameters:
5351 TP_PROTO(int my_int, const char *my_string),
5352 TP_ARGS(my_int, my_string),
5354 /* LTTng-modules specific macros */
5356 ctf_integer(int, my_int_field, my_int)
5357 ctf_string(my_bar_field, my_bar)
5361 #endif /* !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ) */
5363 #include "../../../probes/define_trace.h"
5367 The entries in the `TP_FIELDS()` section are the list of fields for the
5368 LTTng tracepoint. This is similar to the `TP_STRUCT__entry()` part of
5369 ftrace's `TRACE_EVENT()` macro.
5371 See <<lttng-modules-tp-fields,Tracepoint fields macros>> for a
5372 complete description of the available `ctf_*()` macros.
5374 . Create the LTTng-modules probe's kernel module C source file,
5375 +probes/lttng-probe-__subsys__.c+, where +__subsys__+ is your
5380 .path:{probes/lttng-probe-my-subsys.c}
5382 #include <linux/module.h>
5383 #include "../lttng-tracer.h"
5386 * Build-time verification of mismatch between mainline
5387 * TRACE_EVENT() arguments and the LTTng-modules adaptation
5388 * layer LTTNG_TRACEPOINT_EVENT() arguments.
5390 #include <trace/events/my_subsys.h>
5392 /* Create LTTng tracepoint probes */
5393 #define LTTNG_PACKAGE_BUILD
5394 #define CREATE_TRACE_POINTS
5395 #define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
5397 #include "../instrumentation/events/lttng-module/my_subsys.h"
5399 MODULE_LICENSE("GPL and additional rights");
5400 MODULE_AUTHOR("Your name <your-email>");
5401 MODULE_DESCRIPTION("LTTng my_subsys probes");
5402 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
5403 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
5404 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
5405 LTTNG_MODULES_EXTRAVERSION);
5409 . Edit path:{probes/Makefile} and add your new kernel module object
5410 next to the existing ones:
5414 .path:{probes/Makefile}
5418 obj-m += lttng-probe-module.o
5419 obj-m += lttng-probe-power.o
5421 obj-m += lttng-probe-my-subsys.o
5427 . Build and install the LTTng kernel modules:
5432 $ make KERNELDIR=/path/to/linux
5433 # make modules_install && depmod -a
5437 Replace `/path/to/linux` with the path to the Linux source tree where
5438 you defined and used tracepoints with ftrace's `TRACE_EVENT()` macro.
5440 Note that you can also use the
5441 <<lttng-tracepoint-event-code,`LTTNG_TRACEPOINT_EVENT_CODE()` macro>>
5442 instead of `LTTNG_TRACEPOINT_EVENT()` to use custom local variables and
5443 C code that need to be executed before the event fields are recorded.
5445 The best way to learn how to use the previous LTTng-modules macros is to
5446 inspect the existing LTTng-modules tracepoint definitions in the
5447 dir:{instrumentation/events/lttng-module} header files. Compare them
5448 with the Linux kernel mainline versions in the
5449 dir:{include/trace/events} directory of the Linux source tree.
5453 [[lttng-tracepoint-event-code]]
5454 ===== Use custom C code to access the data for tracepoint fields
5456 Although we recommended to always use the
5457 <<lttng-adaptation-layer,`LTTNG_TRACEPOINT_EVENT()`>> macro to describe
5458 the arguments and fields of an LTTng-modules tracepoint when possible,
5459 sometimes you need a more complex process to access the data that the
5460 tracer records as event record fields. In other words, you need local
5461 variables and multiple C{nbsp}statements instead of simple
5462 argument-based expressions that you pass to the
5463 <<lttng-modules-tp-fields,`ctf_*()` macros of `TP_FIELDS()`>>.
5465 You can use the `LTTNG_TRACEPOINT_EVENT_CODE()` macro instead of
5466 `LTTNG_TRACEPOINT_EVENT()` to declare custom local variables and define
5467 a block of C{nbsp}code to be executed before LTTng records the fields.
5468 The structure of this macro is:
5471 .`LTTNG_TRACEPOINT_EVENT_CODE()` macro syntax.
5473 LTTNG_TRACEPOINT_EVENT_CODE(
5475 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5476 * version for the following three macro parameters:
5479 TP_PROTO(int my_int, const char *my_string),
5480 TP_ARGS(my_int, my_string),
5482 /* Declarations of custom local variables */
5485 unsigned long b = 0;
5486 const char *name = "(undefined)";
5487 struct my_struct *my_struct;
5491 * Custom code which uses both tracepoint arguments
5492 * (in TP_ARGS()) and local variables (in TP_locvar()).
5494 * Local variables are actually members of a structure pointed
5495 * to by the special variable tp_locvar.
5499 tp_locvar->a = my_int + 17;
5500 tp_locvar->my_struct = get_my_struct_at(tp_locvar->a);
5501 tp_locvar->b = my_struct_compute_b(tp_locvar->my_struct);
5502 tp_locvar->name = my_struct_get_name(tp_locvar->my_struct);
5503 put_my_struct(tp_locvar->my_struct);
5512 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5513 * version for this, except that tp_locvar members can be
5514 * used in the argument expression parameters of
5515 * the ctf_*() macros.
5518 ctf_integer(unsigned long, my_struct_b, tp_locvar->b)
5519 ctf_integer(int, my_struct_a, tp_locvar->a)
5520 ctf_string(my_string_field, my_string)
5521 ctf_string(my_struct_name, tp_locvar->name)
5526 IMPORTANT: The C code defined in `TP_code()` must not have any side
5527 effects when executed. In particular, the code must not allocate
5528 memory or get resources without deallocating this memory or putting
5529 those resources afterwards.
5532 [[instrumenting-linux-kernel-tracing]]
5533 ==== Load and unload a custom probe kernel module
5535 You must load a <<lttng-adaptation-layer,created LTTng-modules probe
5536 kernel module>> in the kernel before it can emit LTTng events.
5538 To load the default probe kernel modules and a custom probe kernel
5541 * Use the opt:lttng-sessiond(8):--extra-kmod-probes option to give extra
5542 probe modules to load when starting a root <<lttng-sessiond,session
5546 .Load the `my_subsys`, `usb`, and the default probe modules.
5550 # lttng-sessiond --extra-kmod-probes=my_subsys,usb
5555 You only need to pass the subsystem name, not the whole kernel module
5558 To load _only_ a given custom probe kernel module:
5560 * Use the opt:lttng-sessiond(8):--kmod-probes option to give the probe
5561 modules to load when starting a root session daemon:
5564 .Load only the `my_subsys` and `usb` probe modules.
5568 # lttng-sessiond --kmod-probes=my_subsys,usb
5573 To confirm that a probe module is loaded:
5580 $ lsmod | grep lttng_probe_usb
5584 To unload the loaded probe modules:
5586 * Kill the session daemon with `SIGTERM`:
5591 # pkill lttng-sessiond
5595 You can also use man:modprobe(8)'s `--remove` option if the session
5596 daemon terminates abnormally.
5599 [[controlling-tracing]]
5602 Once an application or a Linux kernel is
5603 <<instrumenting,instrumented>> for LTTng tracing,
5606 This section is divided in topics on how to use the various
5607 <<plumbing,components of LTTng>>, in particular the <<lttng-cli,cmd:lttng
5608 command-line tool>>, to _control_ the LTTng daemons and tracers.
5610 NOTE: In the following subsections, we refer to an man:lttng(1) command
5611 using its man page name. For example, instead of _Run the `create`
5612 command to..._, we use _Run the man:lttng-create(1) command to..._.
5616 === Start a session daemon
5618 In some situations, you need to run a <<lttng-sessiond,session daemon>>
5619 (man:lttng-sessiond(8)) _before_ you can use the man:lttng(1)
5622 You will see the following error when you run a command while no session
5626 Error: No session daemon is available
5629 The only command that automatically runs a session daemon is
5630 man:lttng-create(1), which you use to
5631 <<creating-destroying-tracing-sessions,create a tracing session>>. While
5632 this is most of the time the first operation that you do, sometimes it's
5633 not. Some examples are:
5635 * <<list-instrumentation-points,List the available instrumentation points>>.
5636 * <<saving-loading-tracing-session,Load a tracing session configuration>>.
5638 [[tracing-group]] Each Unix user must have its own running session
5639 daemon to trace user applications. The session daemon that the root user
5640 starts is the only one allowed to control the LTTng kernel tracer. Users
5641 that are part of the _tracing group_ can control the root session
5642 daemon. The default tracing group name is `tracing`; you can set it to
5643 something else with the opt:lttng-sessiond(8):--group option when you
5644 start the root session daemon.
5646 To start a user session daemon:
5648 * Run man:lttng-sessiond(8):
5653 $ lttng-sessiond --daemonize
5657 To start the root session daemon:
5659 * Run man:lttng-sessiond(8) as the root user:
5664 # lttng-sessiond --daemonize
5668 In both cases, remove the opt:lttng-sessiond(8):--daemonize option to
5669 start the session daemon in foreground.
5671 To stop a session daemon, use man:kill(1) on its process ID (standard
5674 Note that some Linux distributions could manage the LTTng session daemon
5675 as a service. In this case, you should use the service manager to
5676 start, restart, and stop session daemons.
5679 [[creating-destroying-tracing-sessions]]
5680 === Create and destroy a tracing session
5682 Almost all the LTTng control operations happen in the scope of
5683 a <<tracing-session,tracing session>>, which is the dialogue between the
5684 <<lttng-sessiond,session daemon>> and you.
5686 To create a tracing session with a generated name:
5688 * Use the man:lttng-create(1) command:
5697 The created tracing session's name is `auto` followed by the
5700 To create a tracing session with a specific name:
5702 * Use the optional argument of the man:lttng-create(1) command:
5707 $ lttng create my-session
5711 Replace `my-session` with the specific tracing session name.
5713 LTTng appends the creation date to the created tracing session's name.
5715 LTTng writes the traces of a tracing session in
5716 +$LTTNG_HOME/lttng-trace/__name__+ by default, where +__name__+ is the
5717 name of the tracing session. Note that the env:LTTNG_HOME environment
5718 variable defaults to `$HOME` if not set.
5720 To output LTTng traces to a non-default location:
5722 * Use the opt:lttng-create(1):--output option of the man:lttng-create(1) command:
5727 $ lttng create my-session --output=/tmp/some-directory
5731 You may create as many tracing sessions as you wish.
5733 To list all the existing tracing sessions for your Unix user:
5735 * Use the man:lttng-list(1) command:
5744 When you create a tracing session, it is set as the _current tracing
5745 session_. The following man:lttng(1) commands operate on the current
5746 tracing session when you don't specify one:
5748 [role="list-3-cols"]
5764 To change the current tracing session:
5766 * Use the man:lttng-set-session(1) command:
5771 $ lttng set-session new-session
5775 Replace `new-session` by the name of the new current tracing session.
5777 When you are done tracing in a given tracing session, you can destroy
5778 it. This operation frees the resources taken by the tracing session
5779 to destroy; it does not destroy the trace data that LTTng wrote for
5780 this tracing session.
5782 To destroy the current tracing session:
5784 * Use the man:lttng-destroy(1) command:
5794 [[list-instrumentation-points]]
5795 === List the available instrumentation points
5797 The <<lttng-sessiond,session daemon>> can query the running instrumented
5798 user applications and the Linux kernel to get a list of available
5799 instrumentation points. For the Linux kernel <<domain,tracing domain>>,
5800 they are tracepoints and system calls. For the user space tracing
5801 domain, they are tracepoints. For the other tracing domains, they are
5804 To list the available instrumentation points:
5806 * Use the man:lttng-list(1) command with the requested tracing domain's
5810 * opt:lttng-list(1):--kernel: Linux kernel tracepoints (your Unix user
5811 must be a root user, or it must be a member of the
5812 <<tracing-group,tracing group>>).
5813 * opt:lttng-list(1):--kernel with opt:lttng-list(1):--syscall: Linux
5814 kernel system calls (your Unix user must be a root user, or it must be
5815 a member of the tracing group).
5816 * opt:lttng-list(1):--userspace: user space tracepoints.
5817 * opt:lttng-list(1):--jul: `java.util.logging` loggers.
5818 * opt:lttng-list(1):--log4j: Apache log4j loggers.
5819 * opt:lttng-list(1):--python: Python loggers.
5822 .List the available user space tracepoints.
5826 $ lttng list --userspace
5830 .List the available Linux kernel system call tracepoints.
5834 $ lttng list --kernel --syscall
5839 [[enabling-disabling-events]]
5840 === Create and enable an event rule
5842 Once you <<creating-destroying-tracing-sessions,create a tracing
5843 session>>, you can create <<event,event rules>> with the
5844 man:lttng-enable-event(1) command.
5846 You specify each condition with a command-line option. The available
5847 condition options are shown in the following table.
5849 [role="growable",cols="asciidoc,asciidoc,default"]
5850 .Condition command-line options for the man:lttng-enable-event(1) command.
5852 |Option |Description |Applicable tracing domains
5858 . +--probe=__ADDR__+
5859 . +--function=__ADDR__+
5862 Instead of using the default _tracepoint_ instrumentation type, use:
5864 . A Linux system call.
5865 . A Linux https://lwn.net/Articles/132196/[KProbe] (symbol or address).
5866 . The entry and return points of a Linux function (symbol or address).
5870 |First positional argument.
5873 Tracepoint or system call name. In the case of a Linux KProbe or
5874 function, this is a custom name given to the event rule. With the
5875 JUL, log4j, and Python domains, this is a logger name.
5877 With a tracepoint, logger, or system call name, the last character
5878 can be `*` to match anything that remains.
5885 . +--loglevel=__LEVEL__+
5886 . +--loglevel-only=__LEVEL__+
5889 . Match only tracepoints or log statements with a logging level at
5890 least as severe as +__LEVEL__+.
5891 . Match only tracepoints or log statements with a logging level
5892 equal to +__LEVEL__+.
5894 See man:lttng-enable-event(1) for the list of available logging level
5897 |User space, JUL, log4j, and Python.
5899 |+--exclude=__EXCLUSIONS__+
5902 When you use a `*` character at the end of the tracepoint or logger
5903 name (first positional argument), exclude the specific names in the
5904 comma-delimited list +__EXCLUSIONS__+.
5907 User space, JUL, log4j, and Python.
5909 |+--filter=__EXPR__+
5912 Match only events which satisfy the expression +__EXPR__+.
5914 See man:lttng-enable-event(1) to learn more about the syntax of a
5921 You attach an event rule to a <<channel,channel>> on creation. If you do
5922 not specify the channel with the opt:lttng-enable-event(1):--channel
5923 option, and if the event rule to create is the first in its
5924 <<domain,tracing domain>> for a given tracing session, then LTTng
5925 creates a _default channel_ for you. This default channel is reused in
5926 subsequent invocations of the man:lttng-enable-event(1) command for the
5927 same tracing domain.
5929 An event rule is always enabled at creation time.
5931 The following examples show how you can combine the previous
5932 command-line options to create simple to more complex event rules.
5934 .Create an event rule targetting a Linux kernel tracepoint (default channel).
5938 $ lttng enable-event --kernel sched_switch
5942 .Create an event rule matching four Linux kernel system calls (default channel).
5946 $ lttng enable-event --kernel --syscall open,write,read,close
5950 .Create event rules matching tracepoints with filter expressions (default channel).
5954 $ lttng enable-event --kernel sched_switch --filter='prev_comm == "bash"'
5959 $ lttng enable-event --kernel --all \
5960 --filter='$ctx.tid == 1988 || $ctx.tid == 1534'
5965 $ lttng enable-event --jul my_logger \
5966 --filter='$app.retriever:cur_msg_id > 3'
5969 IMPORTANT: Make sure to always quote the filter string when you
5970 use man:lttng(1) from a shell.
5973 .Create an event rule matching any user space tracepoint of a given tracepoint provider with a log level range (default channel).
5977 $ lttng enable-event --userspace my_app:'*' --loglevel=TRACE_INFO
5980 IMPORTANT: Make sure to always quote the wildcard character when you
5981 use man:lttng(1) from a shell.
5984 .Create an event rule matching multiple Python loggers with a wildcard and with exclusions (default channel).
5988 $ lttng enable-event --python my-app.'*' \
5989 --exclude='my-app.module,my-app.hello'
5993 .Create an event rule matching any Apache log4j logger with a specific log level (default channel).
5997 $ lttng enable-event --log4j --all --loglevel-only=LOG4J_WARN
6001 .Create an event rule attached to a specific channel matching a specific user space tracepoint provider and tracepoint.
6005 $ lttng enable-event --userspace my_app:my_tracepoint --channel=my-channel
6009 The event rules of a given channel form a whitelist: as soon as an
6010 emitted event passes one of them, LTTng can record the event. For
6011 example, an event named `my_app:my_tracepoint` emitted from a user space
6012 tracepoint with a `TRACE_ERROR` log level passes both of the following
6017 $ lttng enable-event --userspace my_app:my_tracepoint
6018 $ lttng enable-event --userspace my_app:my_tracepoint \
6019 --loglevel=TRACE_INFO
6022 The second event rule is redundant: the first one includes
6026 [[disable-event-rule]]
6027 === Disable an event rule
6029 To disable an event rule that you <<enabling-disabling-events,created>>
6030 previously, use the man:lttng-disable-event(1) command. This command
6031 disables _all_ the event rules (of a given tracing domain and channel)
6032 which match an instrumentation point. The other conditions are not
6033 supported as of LTTng{nbsp}{revision}.
6035 The LTTng tracer does not record an emitted event which passes
6036 a _disabled_ event rule.
6038 .Disable an event rule matching a Python logger (default channel).
6042 $ lttng disable-event --python my-logger
6046 .Disable an event rule matching all `java.util.logging` loggers (default channel).
6050 $ lttng disable-event --jul '*'
6054 .Disable _all_ the event rules of the default channel.
6056 The opt:lttng-disable-event(1):--all-events option is not, like the
6057 opt:lttng-enable-event(1):--all option of man:lttng-enable-event(1), the
6058 equivalent of the event name `*` (wildcard): it disables _all_ the event
6059 rules of a given channel.
6063 $ lttng disable-event --jul --all-events
6067 NOTE: You cannot delete an event rule once you create it.
6071 === Get the status of a tracing session
6073 To get the status of the current tracing session, that is, its
6074 parameters, its channels, event rules, and their attributes:
6076 * Use the man:lttng-status(1) command:
6086 To get the status of any tracing session:
6088 * Use the man:lttng-list(1) command with the tracing session's name:
6093 $ lttng list my-session
6097 Replace `my-session` with the desired tracing session's name.
6100 [[basic-tracing-session-control]]
6101 === Start and stop a tracing session
6103 Once you <<creating-destroying-tracing-sessions,create a tracing
6105 <<enabling-disabling-events,create one or more event rules>>,
6106 you can start and stop the tracers for this tracing session.
6108 To start tracing in the current tracing session:
6110 * Use the man:lttng-start(1) command:
6119 LTTng is very flexible: you can launch user applications before
6120 or after the you start the tracers. The tracers only record the events
6121 if they pass enabled event rules and if they occur while the tracers are
6124 To stop tracing in the current tracing session:
6126 * Use the man:lttng-stop(1) command:
6135 If there were <<channel-overwrite-mode-vs-discard-mode,lost event
6136 records>> or lost sub-buffers since the last time you ran
6137 man:lttng-start(1), warnings are printed when you run the
6138 man:lttng-stop(1) command.
6141 [[enabling-disabling-channels]]
6142 === Create a channel
6144 Once you create a tracing session, you can create a <<channel,channel>>
6145 with the man:lttng-enable-channel(1) command.
6147 Note that LTTng automatically creates a default channel when, for a
6148 given <<domain,tracing domain>>, no channels exist and you
6149 <<enabling-disabling-events,create>> the first event rule. This default
6150 channel is named `channel0` and its attributes are set to reasonable
6151 values. Therefore, you only need to create a channel when you need
6152 non-default attributes.
6154 You specify each non-default channel attribute with a command-line
6155 option when you use the man:lttng-enable-channel(1) command. The
6156 available command-line options are:
6158 [role="growable",cols="asciidoc,asciidoc"]
6159 .Command-line options for the man:lttng-enable-channel(1) command.
6161 |Option |Description
6167 <<channel-overwrite-mode-vs-discard-mode,event loss mode>> instead of
6168 the default _discard_ mode.
6170 |`--buffers-pid` (user space tracing domain only)
6173 Use the per-process <<channel-buffering-schemes,buffering scheme>>
6174 instead of the default per-user buffering scheme.
6176 |+--subbuf-size=__SIZE__+
6179 Allocate sub-buffers of +__SIZE__+ bytes (power of two), for each CPU,
6180 either for each Unix user (default), or for each instrumented process.
6182 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
6184 |+--num-subbuf=__COUNT__+
6187 Allocate +__COUNT__+ sub-buffers (power of two), for each CPU, either
6188 for each Unix user (default), or for each instrumented process.
6190 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
6192 |+--tracefile-size=__SIZE__+
6195 Set the maximum size of each trace file that this channel writes within
6196 a stream to +__SIZE__+ bytes instead of no maximum.
6198 See <<tracefile-rotation,Trace file count and size>>.
6200 |+--tracefile-count=__COUNT__+
6203 Limit the number of trace files that this channel creates to
6204 +__COUNT__+ channels instead of no limit.
6206 See <<tracefile-rotation,Trace file count and size>>.
6208 |+--switch-timer=__PERIODUS__+
6211 Set the <<channel-switch-timer,switch timer period>>
6212 to +__PERIODUS__+{nbsp}µs.
6214 |+--read-timer=__PERIODUS__+
6217 Set the <<channel-read-timer,read timer period>>
6218 to +__PERIODUS__+{nbsp}µs.
6220 |+--output=__TYPE__+ (Linux kernel tracing domain only)
6223 Set the channel's output type to +__TYPE__+, either `mmap` or `splice`.
6227 You can only create a channel in the Linux kernel and user space
6228 <<domain,tracing domains>>: other tracing domains have their own channel
6229 created on the fly when <<enabling-disabling-events,creating event
6234 Because of a current LTTng limitation, you must create all channels
6235 _before_ you <<basic-tracing-session-control,start tracing>> in a given
6236 tracing session, that is, before the first time you run
6239 Since LTTng automatically creates a default channel when you use the
6240 man:lttng-enable-event(1) command with a specific tracing domain, you
6241 cannot, for example, create a Linux kernel event rule, start tracing,
6242 and then create a user space event rule, because no user space channel
6243 exists yet and it's too late to create one.
6245 For this reason, make sure to configure your channels properly
6246 before starting the tracers for the first time!
6249 The following examples show how you can combine the previous
6250 command-line options to create simple to more complex channels.
6252 .Create a Linux kernel channel with default attributes.
6256 $ lttng enable-channel --kernel my-channel
6260 .Create a user space channel with 4 sub-buffers or 1{nbsp}MiB each, per CPU, per instrumented process.
6264 $ lttng enable-channel --userspace --num-subbuf=4 --subbuf-size=1M \
6265 --buffers-pid my-channel
6269 .Create a Linux kernel channel which rotates 8 trace files of 4{nbsp}MiB each for each stream
6273 $ lttng enable-channel --kernel --tracefile-count=8 \
6274 --tracefile-size=4194304 my-channel
6278 .Create a user space channel in overwrite (or _flight recorder_) mode.
6282 $ lttng enable-channel --userspace --overwrite my-channel
6286 You can <<enabling-disabling-events,create>> the same event rule in
6287 two different channels:
6291 $ lttng enable-event --userspace --channel=my-channel app:tp
6292 $ lttng enable-event --userspace --channel=other-channel app:tp
6295 If both channels are enabled, when a tracepoint named `app:tp` is
6296 reached, LTTng records two events, one for each channel.
6300 === Disable a channel
6302 To disable a specific channel that you <<enabling-disabling-channels,created>>
6303 previously, use the man:lttng-disable-channel(1) command.
6305 .Disable a specific Linux kernel channel.
6309 $ lttng disable-channel --kernel my-channel
6313 The state of a channel precedes the individual states of event rules
6314 attached to it: event rules which belong to a disabled channel, even if
6315 they are enabled, are also considered disabled.
6319 === Add context fields to a channel
6321 Event record fields in trace files provide important information about
6322 events that occured previously, but sometimes some external context may
6323 help you solve a problem faster. Examples of context fields are:
6325 * The **process ID**, **thread ID**, **process name**, and
6326 **process priority** of the thread in which the event occurs.
6327 * The **hostname** of the system on which the event occurs.
6328 * The current values of many possible **performance counters** using
6330 ** CPU cycles, stalled cycles, idle cycles, and the other cycle types.
6332 ** Branch instructions, misses, and loads.
6334 * Any context defined at the application level (supported for the
6335 JUL and log4j <<domain,tracing domains>>).
6337 To get the full list of available context fields, see
6338 `lttng add-context --list`. Some context fields are reserved for a
6339 specific <<domain,tracing domain>> (Linux kernel or user space).
6341 You add context fields to <<channel,channels>>. All the events
6342 that a channel with added context fields records contain those fields.
6344 To add context fields to one or all the channels of a given tracing
6347 * Use the man:lttng-add-context(1) command.
6349 .Add context fields to all the channels of the current tracing session.
6351 The following command line adds the virtual process identifier and
6352 the per-thread CPU cycles count fields to all the user space channels
6353 of the current tracing session.
6357 $ lttng add-context --userspace --type=vpid --type=perf:thread:cpu-cycles
6361 .Add a context field to a specific channel.
6363 The following command line adds the thread identifier context field
6364 to the Linux kernel channel named `my-channel` in the current
6369 $ lttng add-context --kernel --channel=my-channel --type=tid
6373 .Add an application-specific context field to a specific channel.
6375 The following command line adds the `cur_msg_id` context field of the
6376 `retriever` context retriever for all the instrumented
6377 <<java-application,Java applications>> recording <<event,event records>>
6378 in the channel named `my-channel`:
6382 $ lttng add-context --kernel --channel=my-channel \
6383 --type='$app:retriever:cur_msg_id'
6386 IMPORTANT: Make sure to always quote the `$` character when you
6387 use man:lttng-add-context(1) from a shell.
6390 NOTE: You cannot remove context fields from a channel once you add it.
6395 === Track process IDs
6397 It's often useful to allow only specific process IDs (PIDs) to emit
6398 events. For example, you may wish to record all the system calls made by
6399 a given process (à la http://linux.die.net/man/1/strace[strace]).
6401 The man:lttng-track(1) and man:lttng-untrack(1) commands serve this
6402 purpose. Both commands operate on a whitelist of process IDs. You _add_
6403 entries to this whitelist with the man:lttng-track(1) command and remove
6404 entries with the man:lttng-untrack(1) command. Any process which has one
6405 of the PIDs in the whitelist is allowed to emit LTTng events which pass
6406 an enabled <<event,event rule>>.
6408 NOTE: The PID tracker tracks the _numeric process IDs_. Should a
6409 process with a given tracked ID exit and another process be given this
6410 ID, then the latter would also be allowed to emit events.
6412 .Track and untrack process IDs.
6414 For the sake of the following example, assume the target system has 16
6418 <<creating-destroying-tracing-sessions,create a tracing session>>,
6419 the whitelist contains all the possible PIDs:
6422 .All PIDs are tracked.
6423 image::track-all.png[]
6425 When the whitelist is full and you use the man:lttng-track(1) command to
6426 specify some PIDs to track, LTTng first clears the whitelist, then it
6427 tracks the specific PIDs. After:
6431 $ lttng track --pid=3,4,7,10,13
6437 .PIDs 3, 4, 7, 10, and 13 are tracked.
6438 image::track-3-4-7-10-13.png[]
6440 You can add more PIDs to the whitelist afterwards:
6444 $ lttng track --pid=1,15,16
6450 .PIDs 1, 15, and 16 are added to the whitelist.
6451 image::track-1-3-4-7-10-13-15-16.png[]
6453 The man:lttng-untrack(1) command removes entries from the PID tracker's
6454 whitelist. Given the previous example, the following command:
6458 $ lttng untrack --pid=3,7,10,13
6461 leads to this whitelist:
6464 .PIDs 3, 7, 10, and 13 are removed from the whitelist.
6465 image::track-1-4-15-16.png[]
6467 LTTng can track all possible PIDs again using the opt:track(1):--all
6472 $ lttng track --pid --all
6475 The result is, again:
6478 .All PIDs are tracked.
6479 image::track-all.png[]
6482 .Track only specific PIDs
6484 A very typical use case with PID tracking is to start with an empty
6485 whitelist, then <<basic-tracing-session-control,start the tracers>>, and
6486 then add PIDs manually while tracers are active. You can accomplish this
6487 by using the opt:lttng-untrack(1):--all option of the
6488 man:lttng-untrack(1) command to clear the whitelist after you
6489 <<creating-destroying-tracing-sessions,create a tracing session>>:
6493 $ lttng untrack --pid --all
6499 .No PIDs are tracked.
6500 image::untrack-all.png[]
6502 If you trace with this whitelist configuration, the tracer records no
6503 events for this <<domain,tracing domain>> because no processes are
6504 tracked. You can use the man:lttng-track(1) command as usual to track
6505 specific PIDs, for example:
6509 $ lttng track --pid=6,11
6515 .PIDs 6 and 11 are tracked.
6516 image::track-6-11.png[]
6521 [[saving-loading-tracing-session]]
6522 === Save and load tracing session configurations
6524 Configuring a <<tracing-session,tracing session>> can be long. Some of
6525 the tasks involved are:
6527 * <<enabling-disabling-channels,Create channels>> with
6528 specific attributes.
6529 * <<adding-context,Add context fields>> to specific channels.
6530 * <<enabling-disabling-events,Create event rules>> with specific log
6531 level and filter conditions.
6533 If you use LTTng to solve real world problems, chances are you have to
6534 record events using the same tracing session setup over and over,
6535 modifying a few variables each time in your instrumented program
6536 or environment. To avoid constant tracing session reconfiguration,
6537 the man:lttng(1) command-line tool can save and load tracing session
6538 configurations to/from XML files.
6540 To save a given tracing session configuration:
6542 * Use the man:lttng-save(1) command:
6547 $ lttng save my-session
6551 Replace `my-session` with the name of the tracing session to save.
6553 LTTng saves tracing session configurations to
6554 dir:{$LTTNG_HOME/.lttng/sessions} by default. Note that the
6555 env:LTTNG_HOME environment variable defaults to `$HOME` if not set. Use
6556 the opt:lttng-save(1):--output-path option to change this destination
6559 LTTng saves all configuration parameters, for example:
6561 * The tracing session name.
6562 * The trace data output path.
6563 * The channels with their state and all their attributes.
6564 * The context fields you added to channels.
6565 * The event rules with their state, log level and filter conditions.
6567 To load a tracing session:
6569 * Use the man:lttng-load(1) command:
6574 $ lttng load my-session
6578 Replace `my-session` with the name of the tracing session to load.
6580 When LTTng loads a configuration, it restores your saved tracing session
6581 as if you just configured it manually.
6583 See man:lttng(1) for the complete list of command-line options. You
6584 can also save and load all many sessions at a time, and decide in which
6585 directory to output the XML files.
6588 [[sending-trace-data-over-the-network]]
6589 === Send trace data over the network
6591 LTTng can send the recorded trace data to a remote system over the
6592 network instead of writing it to the local file system.
6594 To send the trace data over the network:
6596 . On the _remote_ system (which can also be the target system),
6597 start an LTTng <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)):
6606 . On the _target_ system, create a tracing session configured to
6607 send trace data over the network:
6612 $ lttng create my-session --set-url=net://remote-system
6616 Replace `remote-system` by the host name or IP address of the
6617 remote system. See man:lttng-create(1) for the exact URL format.
6619 . On the target system, use the man:lttng(1) command-line tool as usual.
6620 When tracing is active, the target's consumer daemon sends sub-buffers
6621 to the relay daemon running on the remote system instead of flushing
6622 them to the local file system. The relay daemon writes the received
6623 packets to the local file system.
6625 The relay daemon writes trace files to
6626 +$LTTNG_HOME/lttng-traces/__hostname__/__session__+ by default, where
6627 +__hostname__+ is the host name of the target system and +__session__+
6628 is the tracing session name. Note that the env:LTTNG_HOME environment
6629 variable defaults to `$HOME` if not set. Use the
6630 opt:lttng-relayd(8):--output option of man:lttng-relayd(8) to write
6631 trace files to another base directory.
6636 === View events as LTTng emits them (noch:{LTTng} live)
6638 LTTng live is a network protocol implemented by the <<lttng-relayd,relay
6639 daemon>> (man:lttng-relayd(8)) to allow compatible trace viewers to
6640 display events as LTTng emits them on the target system while tracing is
6643 The relay daemon creates a _tee_: it forwards the trace data to both
6644 the local file system and to connected live viewers:
6647 .The relay daemon creates a _tee_, forwarding the trace data to both trace files and a connected live viewer.
6652 . On the _target system_, create a <<tracing-session,tracing session>>
6658 $ lttng create my-session --live
6662 This spawns a local relay daemon.
6664 . Start the live viewer and configure it to connect to the relay
6665 daemon. For example, with http://diamon.org/babeltrace[Babeltrace]:
6670 $ babeltrace --input-format=lttng-live
6671 net://localhost/host/hostname/my-session
6678 * `hostname` with the host name of the target system.
6679 * `my-session` with the name of the tracing session to view.
6682 . Configure the tracing session as usual with the man:lttng(1)
6683 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6685 You can list the available live tracing sessions with Babeltrace:
6689 $ babeltrace --input-format=lttng-live net://localhost
6692 You can start the relay daemon on another system. In this case, you need
6693 to specify the relay daemon's URL when you create the tracing session
6694 with the opt:lttng-create(1):--set-url option. You also need to replace
6695 `localhost` in the procedure above with the host name of the system on
6696 which the relay daemon is running.
6698 See man:lttng-create(1) and man:lttng-relayd(8) for the complete list of
6699 command-line options.
6703 [[taking-a-snapshot]]
6704 === Take a snapshot of the current sub-buffers of a tracing session
6706 The normal behavior of LTTng is to append full sub-buffers to growing
6707 trace data files. This is ideal to keep a full history of the events
6708 that occurred on the target system, but it can
6709 represent too much data in some situations. For example, you may wish
6710 to trace your application continuously until some critical situation
6711 happens, in which case you only need the latest few recorded
6712 events to perform the desired analysis, not multi-gigabyte trace files.
6714 With the man:lttng-snapshot(1) command, you can take a snapshot of the
6715 current sub-buffers of a given <<tracing-session,tracing session>>.
6716 LTTng can write the snapshot to the local file system or send it over
6721 . Create a tracing session in _snapshot mode_:
6726 $ lttng create my-session --snapshot
6730 The <<channel-overwrite-mode-vs-discard-mode,event loss mode>> of
6731 <<channel,channels>> created in this mode is automatically set to
6732 _overwrite_ (flight recorder mode).
6734 . Configure the tracing session as usual with the man:lttng(1)
6735 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6737 . **Optional**: When you need to take a snapshot,
6738 <<basic-tracing-session-control,stop tracing>>.
6740 You can take a snapshot when the tracers are active, but if you stop
6741 them first, you are sure that the data in the sub-buffers does not
6742 change before you actually take the snapshot.
6749 $ lttng snapshot record --name=my-first-snapshot
6753 LTTng writes the current sub-buffers of all the current tracing
6754 session's channels to trace files on the local file system. Those trace
6755 files have `my-first-snapshot` in their name.
6757 There is no difference between the format of a normal trace file and the
6758 format of a snapshot: viewers of LTTng traces also support LTTng
6761 By default, LTTng writes snapshot files to the path shown by
6762 `lttng snapshot list-output`. You can change this path or decide to send
6763 snapshots over the network using either:
6765 . An output path or URL that you specify when you create the
6767 . An snapshot output path or URL that you add using
6768 `lttng snapshot add-output`
6769 . An output path or URL that you provide directly to the
6770 `lttng snapshot record` command.
6772 Method 3 overrides method 2, which overrides method 1. When you
6773 specify a URL, a relay daemon must listen on a remote system (see
6774 <<sending-trace-data-over-the-network,Send trace data over the network>>).
6779 === Use the machine interface
6781 With any command of the man:lttng(1) command-line tool, you can set the
6782 opt:lttng(1):--mi option to `xml` (before the command name) to get an
6783 XML machine interface output, for example:
6787 $ lttng --mi=xml enable-event --kernel --syscall open
6790 A schema definition (XSD) is
6791 https://github.com/lttng/lttng-tools/blob/stable-2.8/src/common/mi-lttng-3.0.xsd[available]
6792 to ease the integration with external tools as much as possible.
6796 [[metadata-regenerate]]
6797 === Regenerate the metadata of an LTTng trace
6799 An LTTng trace, which is a http://diamon.org/ctf[CTF] trace, has both
6800 data stream files and a metadata file. This metadata file contains,
6801 amongst other things, information about the offset of the clock sources
6802 used to timestamp <<event,event records>> when tracing.
6804 If, once a <<tracing-session,tracing session>> is
6805 <<basic-tracing-session-control,started>>, a major
6806 https://en.wikipedia.org/wiki/Network_Time_Protocol[NTP] correction
6807 happens, the trace's clock offset also needs to be updated. You
6808 can use the man:lttng-metadata(1) command to do so.
6810 The main use case of this command is to allow a system to boot with
6811 an incorrect wall time and trace it with LTTng before its wall time
6812 is corrected. Once the system is known to be in a state where its
6813 wall time is correct, it can run `lttng metadata regenerate`.
6815 To regenerate the metadata of an LTTng trace:
6817 * Use the `regenerate` action of the man:lttng-metadata(1) command:
6822 $ lttng metadata regenerate
6828 `lttng metadata regenerate` has the following limitations:
6830 * Tracing session <<creating-destroying-tracing-sessions,created>>
6832 * User space <<channel,channels>>, if any, using
6833 <<channel-buffering-schemes,per-user buffering>>.
6838 [[persistent-memory-file-systems]]
6839 === Record trace data on persistent memory file systems
6841 https://en.wikipedia.org/wiki/Non-volatile_random-access_memory[Non-volatile random-access memory]
6842 (NVRAM) is random-access memory that retains its information when power
6843 is turned off (non-volatile). Systems with such memory can store data
6844 structures in RAM and retrieve them after a reboot, without flushing
6845 to typical _storage_.
6847 Linux supports NVRAM file systems thanks to either
6848 http://pramfs.sourceforge.net/[PRAMFS] or
6849 https://www.kernel.org/doc/Documentation/filesystems/dax.txt[DAX]{nbsp}+{nbsp}http://lkml.iu.edu/hypermail/linux/kernel/1504.1/03463.html[pmem]
6850 (requires Linux 4.1+).
6852 This section does not describe how to operate such file systems;
6853 we assume that you have a working persistent memory file system.
6855 When you create a <<tracing-session,tracing session>>, you can specify
6856 the path of the shared memory holding the sub-buffers. If you specify a
6857 location on an NVRAM file system, then you can retrieve the latest
6858 recorded trace data when the system reboots after a crash.
6860 To record trace data on a persistent memory file system and retrieve the
6861 trace data after a system crash:
6863 . Create a tracing session with a sub-buffer shared memory path located
6864 on an NVRAM file system:
6869 $ lttng create my-session --shm-path=/path/to/shm
6873 . Configure the tracing session as usual with the man:lttng(1)
6874 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6876 . After a system crash, use the man:lttng-crash(1) command-line tool to
6877 view the trace data recorded on the NVRAM file system:
6882 $ lttng-crash /path/to/shm
6886 The binary layout of the ring buffer files is not exactly the same as
6887 the trace files layout. This is why you need to use man:lttng-crash(1)
6888 instead of your preferred trace viewer directly.
6890 To convert the ring buffer files to LTTng trace files:
6892 * Use the opt:lttng-crash(1):--extract option of man:lttng-crash(1):
6897 $ lttng-crash --extract=/path/to/trace /path/to/shm
6905 [[lttng-modules-ref]]
6906 === noch:{LTTng-modules}
6909 [[lttng-modules-tp-fields]]
6910 ==== Tracepoint fields macros (for `TP_FIELDS()`)
6912 [[tp-fast-assign]][[tp-struct-entry]]The available macros to define
6913 tracepoint fields, which must be listed within `TP_FIELDS()` in
6914 `LTTNG_TRACEPOINT_EVENT()`, are:
6916 [role="func-desc growable",cols="asciidoc,asciidoc"]
6917 .Available macros to define LTTng-modules tracepoint fields
6919 |Macro |Description and parameters
6922 +ctf_integer(__t__, __n__, __e__)+
6924 +ctf_integer_nowrite(__t__, __n__, __e__)+
6926 +ctf_user_integer(__t__, __n__, __e__)+
6928 +ctf_user_integer_nowrite(__t__, __n__, __e__)+
6930 Standard integer, displayed in base 10.
6933 Integer C type (`int`, `long`, `size_t`, ...).
6939 Argument expression.
6942 +ctf_integer_hex(__t__, __n__, __e__)+
6944 +ctf_user_integer_hex(__t__, __n__, __e__)+
6946 Standard integer, displayed in base 16.
6955 Argument expression.
6957 |+ctf_integer_oct(__t__, __n__, __e__)+
6959 Standard integer, displayed in base 8.
6968 Argument expression.
6971 +ctf_integer_network(__t__, __n__, __e__)+
6973 +ctf_user_integer_network(__t__, __n__, __e__)+
6975 Integer in network byte order (big-endian), displayed in base 10.
6984 Argument expression.
6987 +ctf_integer_network_hex(__t__, __n__, __e__)+
6989 +ctf_user_integer_network_hex(__t__, __n__, __e__)+
6991 Integer in network byte order, displayed in base 16.
7000 Argument expression.
7003 +ctf_string(__n__, __e__)+
7005 +ctf_string_nowrite(__n__, __e__)+
7007 +ctf_user_string(__n__, __e__)+
7009 +ctf_user_string_nowrite(__n__, __e__)+
7011 Null-terminated string; undefined behavior if +__e__+ is `NULL`.
7017 Argument expression.
7020 +ctf_array(__t__, __n__, __e__, __s__)+
7022 +ctf_array_nowrite(__t__, __n__, __e__, __s__)+
7024 +ctf_user_array(__t__, __n__, __e__, __s__)+
7026 +ctf_user_array_nowrite(__t__, __n__, __e__, __s__)+
7028 Statically-sized array of integers.
7031 Array element C type.
7037 Argument expression.
7043 +ctf_array_bitfield(__t__, __n__, __e__, __s__)+
7045 +ctf_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7047 +ctf_user_array_bitfield(__t__, __n__, __e__, __s__)+
7049 +ctf_user_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7051 Statically-sized array of bits.
7053 The type of +__e__+ must be an integer type. +__s__+ is the number
7054 of elements of such type in +__e__+, not the number of bits.
7057 Array element C type.
7063 Argument expression.
7069 +ctf_array_text(__t__, __n__, __e__, __s__)+
7071 +ctf_array_text_nowrite(__t__, __n__, __e__, __s__)+
7073 +ctf_user_array_text(__t__, __n__, __e__, __s__)+
7075 +ctf_user_array_text_nowrite(__t__, __n__, __e__, __s__)+
7077 Statically-sized array, printed as text.
7079 The string does not need to be null-terminated.
7082 Array element C type (always `char`).
7088 Argument expression.
7094 +ctf_sequence(__t__, __n__, __e__, __T__, __E__)+
7096 +ctf_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7098 +ctf_user_sequence(__t__, __n__, __e__, __T__, __E__)+
7100 +ctf_user_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7102 Dynamically-sized array of integers.
7104 The type of +__E__+ must be unsigned.
7107 Array element C type.
7113 Argument expression.
7116 Length expression C type.
7122 +ctf_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7124 +ctf_user_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7126 Dynamically-sized array of integers, displayed in base 16.
7128 The type of +__E__+ must be unsigned.
7131 Array element C type.
7137 Argument expression.
7140 Length expression C type.
7145 |+ctf_sequence_network(__t__, __n__, __e__, __T__, __E__)+
7147 Dynamically-sized array of integers in network byte order (big-endian),
7148 displayed in base 10.
7150 The type of +__E__+ must be unsigned.
7153 Array element C type.
7159 Argument expression.
7162 Length expression C type.
7168 +ctf_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7170 +ctf_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7172 +ctf_user_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7174 +ctf_user_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7176 Dynamically-sized array of bits.
7178 The type of +__e__+ must be an integer type. +__s__+ is the number
7179 of elements of such type in +__e__+, not the number of bits.
7181 The type of +__E__+ must be unsigned.
7184 Array element C type.
7190 Argument expression.
7193 Length expression C type.
7199 +ctf_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7201 +ctf_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7203 +ctf_user_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7205 +ctf_user_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7207 Dynamically-sized array, displayed as text.
7209 The string does not need to be null-terminated.
7211 The type of +__E__+ must be unsigned.
7213 The behaviour is undefined if +__e__+ is `NULL`.
7216 Sequence element C type (always `char`).
7222 Argument expression.
7225 Length expression C type.
7231 Use the `_user` versions when the argument expression, `e`, is
7232 a user space address. In the cases of `ctf_user_integer*()` and
7233 `ctf_user_float*()`, `&e` must be a user space address, thus `e` must
7236 The `_nowrite` versions omit themselves from the session trace, but are
7237 otherwise identical. This means the `_nowrite` fields won't be written
7238 in the recorded trace. Their primary purpose is to make some
7239 of the event context available to the
7240 <<enabling-disabling-events,event filters>> without having to
7241 commit the data to sub-buffers.
7247 Terms related to LTTng and to tracing in general:
7250 The http://diamon.org/babeltrace[Babeltrace] project, which includes
7251 the cmd:babeltrace command, some libraries, and Python bindings.
7253 <<channel-buffering-schemes,buffering scheme>>::
7254 A layout of sub-buffers applied to a given channel.
7256 <<channel,channel>>::
7257 An entity which is responsible for a set of ring buffers.
7259 <<event,Event rules>> are always attached to a specific channel.
7262 A reference of time for a tracer.
7264 <<lttng-consumerd,consumer daemon>>::
7265 A process which is responsible for consuming the full sub-buffers
7266 and write them to a file system or send them over the network.
7268 <<channel-overwrite-mode-vs-discard-mode,discard mode>>:: The event loss
7269 mode in which the tracer _discards_ new event records when there's no
7270 sub-buffer space left to store them.
7273 The consequence of the execution of an instrumentation
7274 point, like a tracepoint that you manually place in some source code,
7275 or a Linux kernel KProbe.
7277 An event is said to _occur_ at a specific time. Different actions can
7278 be taken upon the occurance of an event, like record the event's payload
7281 <<channel-overwrite-mode-vs-discard-mode,event loss mode>>::
7282 The mechanism by which event records of a given channel are lost
7283 (not recorded) when there is no sub-buffer space left to store them.
7285 [[def-event-name]]event name::
7286 The name of an event, which is also the name of the event record.
7287 This is also called the _instrumentation point name_.
7290 A record, in a trace, of the payload of an event which occured.
7292 <<event,event rule>>::
7293 Set of conditions which must be satisfied for one or more occuring
7294 events to be recorded.
7296 `java.util.logging`::
7298 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[core logging facilities].
7300 <<instrumenting,instrumentation>>::
7301 The use of LTTng probes to make a piece of software traceable.
7303 instrumentation point::
7304 A point in the execution path of a piece of software that, when
7305 reached by this execution, can emit an event.
7307 instrumentation point name::
7308 See _<<def-event-name,event name>>_.
7311 A http://logging.apache.org/log4j/1.2/[logging library] for Java
7312 developed by the Apache Software Foundation.
7315 Level of severity of a log statement or user space
7316 instrumentation point.
7319 The _Linux Trace Toolkit: next generation_ project.
7321 <<lttng-cli,cmd:lttng>>::
7322 A command-line tool provided by the LTTng-tools project which you
7323 can use to send and receive control messages to and from a
7327 The https://github.com/lttng/lttng-analyses[LTTng analyses] project,
7328 which is a set of analyzing programs that are used to obtain a
7329 higher level view of an LTTng trace.
7331 cmd:lttng-consumerd::
7332 The name of the consumer daemon program.
7335 A utility provided by the LTTng-tools project which can convert
7336 ring buffer files (usually
7337 <<persistent-memory-file-systems,saved on a persistent memory file system>>)
7340 LTTng Documentation::
7343 <<lttng-live,LTTng live>>::
7344 A communication protocol between the relay daemon and live viewers
7345 which makes it possible to see events "live", as they are received by
7348 <<lttng-modules,LTTng-modules>>::
7349 The https://github.com/lttng/lttng-modules[LTTng-modules] project,
7350 which contains the Linux kernel modules to make the Linux kernel
7351 instrumentation points available for LTTng tracing.
7354 The name of the relay daemon program.
7356 cmd:lttng-sessiond::
7357 The name of the session daemon program.
7360 The https://github.com/lttng/lttng-tools[LTTng-tools] project, which
7361 contains the various programs and libraries used to
7362 <<controlling-tracing,control tracing>>.
7364 <<lttng-ust,LTTng-UST>>::
7365 The https://github.com/lttng/lttng-ust[LTTng-UST] project, which
7366 contains libraries to instrument user applications.
7368 <<lttng-ust-agents,LTTng-UST Java agent>>::
7369 A Java package provided by the LTTng-UST project to allow the
7370 LTTng instrumentation of `java.util.logging` and Apache log4j 1.2
7373 <<lttng-ust-agents,LTTng-UST Python agent>>::
7374 A Python package provided by the LTTng-UST project to allow the
7375 LTTng instrumentation of Python logging statements.
7377 <<channel-overwrite-mode-vs-discard-mode,overwrite mode>>::
7378 The event loss mode in which new event records overwrite older
7379 event records when there's no sub-buffer space left to store them.
7381 <<channel-buffering-schemes,per-process buffering>>::
7382 A buffering scheme in which each instrumented process has its own
7383 sub-buffers for a given user space channel.
7385 <<channel-buffering-schemes,per-user buffering>>::
7386 A buffering scheme in which all the processes of a Unix user share the
7387 same sub-buffer for a given user space channel.
7389 <<lttng-relayd,relay daemon>>::
7390 A process which is responsible for receiving the trace data sent by
7391 a distant consumer daemon.
7394 A set of sub-buffers.
7396 <<lttng-sessiond,session daemon>>::
7397 A process which receives control commands from you and orchestrates
7398 the tracers and various LTTng daemons.
7400 <<taking-a-snapshot,snapshot>>::
7401 A copy of the current data of all the sub-buffers of a given tracing
7402 session, saved as trace files.
7405 One part of an LTTng ring buffer which contains event records.
7408 The time information attached to an event when it is emitted.
7411 A set of files which are the concatenations of one or more
7412 flushed sub-buffers.
7415 The action of recording the events emitted by an application
7416 or by a system, or to initiate such recording by controlling
7420 The http://tracecompass.org[Trace Compass] project and application.
7423 An instrumentation point using the tracepoint mechanism of the Linux
7424 kernel or of LTTng-UST.
7426 tracepoint definition::
7427 The definition of a single tracepoint.
7430 The name of a tracepoint.
7432 tracepoint provider::
7433 A set of functions providing tracepoints to an instrumented user
7436 Not to be confused with a _tracepoint provider package_: many tracepoint
7437 providers can exist within a tracepoint provider package.
7439 tracepoint provider package::
7440 One or more tracepoint providers compiled as an object file or as
7444 A software which records emitted events.
7446 <<domain,tracing domain>>::
7447 A namespace for event sources.
7449 <<tracing-group,tracing group>>::
7450 The Unix group in which a Unix user can be to be allowed to trace the
7453 <<tracing-session,tracing session>>::
7454 A stateful dialogue between you and a <<lttng-sessiond,session
7458 An application running in user space, as opposed to a Linux kernel
7459 module, for example.