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 _KeKriek_. From
78 http://brasseriedunham.com/[Brasserie Dunham], the _**KeKriek**_ is a
79 sour mashed golden wheat ale fermented with local sour cherries from
80 Tougas orchards. Fresh sweet cherry notes with some tartness, lively
81 carbonation with a dry finish.
83 New features and changes in LTTng{nbsp}{revision}:
85 * **Tracing control**:
86 ** You can put more than one wildcard special character (`*`), and not
87 only at the end, when you <<enabling-disabling-events,create an event
88 rule>>, in both the instrumentation point name and the literal
90 link:/man/1/lttng-enable-event/v{revision}/#doc-filter-syntax[filter expressions]:
95 # lttng enable-event --kernel 'x86_*_local_timer_*' \
96 --filter='name == "*a*b*c*d*e" && count >= 23'
103 $ lttng enable-event --userspace '*_my_org:*msg*'
107 ** New trigger and notification API for
108 <<liblttng-ctl-lttng,`liblttng-ctl`>>. This new subsystem allows you
109 to register triggers which emit a notification when a given
110 condition is satisfied. As of LTTng{nbsp}{revision}, only
111 <<channel,channel>> buffer usage conditions are available.
112 Documentation is available in the
113 https://github.com/lttng/lttng-tools/tree/stable-{revision}/include/lttng[`liblttng-ctl`
115 <<notif-trigger-api,Get notified when a channel's buffer usage is too
118 ** You can now embed the whole textual LTTng-tools man pages into the
119 executables at build time with the `--enable-embedded-help`
120 configuration option. Thanks to this option, you don't need the
121 http://www.methods.co.nz/asciidoc/[AsciiDoc] and
122 https://directory.fsf.org/wiki/Xmlto[xmlto] tools at build time, and
123 a manual pager at run time, to get access to this documentation.
125 * **User space tracing**:
126 ** New blocking mode: an LTTng-UST tracepoint can now block until
127 <<channel,sub-buffer>> space is available instead of discarding event
128 records in <<channel-overwrite-mode-vs-discard-mode,discard mode>>.
129 With this feature, you can be sure that no event records are
130 discarded during your application's execution at the expense of
133 For example, the following command lines create a user space tracing
134 channel with an infinite blocking timeout and run an application
135 instrumented with LTTng-UST which is explicitly allowed to block:
141 $ lttng enable-channel --userspace --blocking-timeout=inf blocking-channel
142 $ lttng enable-event --userspace --channel=blocking-channel --all
144 $ LTTNG_UST_ALLOW_BLOCKING=1 my-app
148 See the complete <<blocking-timeout-example,blocking timeout example>>.
150 * **Linux kernel tracing**:
151 ** Linux 4.10, 4.11, and 4.12 support.
152 ** The thread state dump events recorded by LTTng-modules now contain
153 the task's CPU identifier. This improves the precision of the
154 scheduler model for analyses.
155 ** Extended man:socketpair(2) system call tracing data.
161 What is LTTng? As its name suggests, the _Linux Trace Toolkit: next
162 generation_ is a modern toolkit for tracing Linux systems and
163 applications. So your first question might be:
170 As the history of software engineering progressed and led to what
171 we now take for granted--complex, numerous and
172 interdependent software applications running in parallel on
173 sophisticated operating systems like Linux--the authors of such
174 components, software developers, began feeling a natural
175 urge to have tools that would ensure the robustness and good performance
176 of their masterpieces.
178 One major achievement in this field is, inarguably, the
179 https://www.gnu.org/software/gdb/[GNU debugger (GDB)],
180 an essential tool for developers to find and fix bugs. But even the best
181 debugger won't help make your software run faster, and nowadays, faster
182 software means either more work done by the same hardware, or cheaper
183 hardware for the same work.
185 A _profiler_ is often the tool of choice to identify performance
186 bottlenecks. Profiling is suitable to identify _where_ performance is
187 lost in a given software. The profiler outputs a profile, a statistical
188 summary of observed events, which you may use to discover which
189 functions took the most time to execute. However, a profiler won't
190 report _why_ some identified functions are the bottleneck. Bottlenecks
191 might only occur when specific conditions are met, conditions that are
192 sometimes impossible to capture by a statistical profiler, or impossible
193 to reproduce with an application altered by the overhead of an
194 event-based profiler. For a thorough investigation of software
195 performance issues, a history of execution is essential, with the
196 recorded values of variables and context fields you choose, and
197 with as little influence as possible on the instrumented software. This
198 is where tracing comes in handy.
200 _Tracing_ is a technique used to understand what goes on in a running
201 software system. The software used for tracing is called a _tracer_,
202 which is conceptually similar to a tape recorder. When recording,
203 specific instrumentation points placed in the software source code
204 generate events that are saved on a giant tape: a _trace_ file. You
205 can trace user applications and the operating system at the same time,
206 opening the possibility of resolving a wide range of problems that would
207 otherwise be extremely challenging.
209 Tracing is often compared to _logging_. However, tracers and loggers are
210 two different tools, serving two different purposes. Tracers are
211 designed to record much lower-level events that occur much more
212 frequently than log messages, often in the range of thousands per
213 second, with very little execution overhead. Logging is more appropriate
214 for a very high-level analysis of less frequent events: user accesses,
215 exceptional conditions (errors and warnings, for example), database
216 transactions, instant messaging communications, and such. Simply put,
217 logging is one of the many use cases that can be satisfied with tracing.
219 The list of recorded events inside a trace file can be read manually
220 like a log file for the maximum level of detail, but it is generally
221 much more interesting to perform application-specific analyses to
222 produce reduced statistics and graphs that are useful to resolve a
223 given problem. Trace viewers and analyzers are specialized tools
226 In the end, this is what LTTng is: a powerful, open source set of
227 tools to trace the Linux kernel and user applications at the same time.
228 LTTng is composed of several components actively maintained and
229 developed by its link:/community/#where[community].
232 [[lttng-alternatives]]
233 === Alternatives to noch:{LTTng}
235 Excluding proprietary solutions, a few competing software tracers
238 * https://github.com/dtrace4linux/linux[dtrace4linux] is a port of
239 Sun Microsystems's DTrace to Linux. The cmd:dtrace tool interprets
240 user scripts and is responsible for loading code into the
241 Linux kernel for further execution and collecting the outputted data.
242 * https://en.wikipedia.org/wiki/Berkeley_Packet_Filter[eBPF] is a
243 subsystem in the Linux kernel in which a virtual machine can execute
244 programs passed from the user space to the kernel. You can attach
245 such programs to tracepoints and KProbes thanks to a system call, and
246 they can output data to the user space when executed thanks to
247 different mechanisms (pipe, VM register values, and eBPF maps, to name
249 * https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace]
250 is the de facto function tracer of the Linux kernel. Its user
251 interface is a set of special files in sysfs.
252 * https://perf.wiki.kernel.org/[perf] is
253 a performance analyzing tool for Linux which supports hardware
254 performance counters, tracepoints, as well as other counters and
255 types of probes. perf's controlling utility is the cmd:perf command
257 * http://linux.die.net/man/1/strace[strace]
258 is a command-line utility which records system calls made by a
259 user process, as well as signal deliveries and changes of process
260 state. strace makes use of https://en.wikipedia.org/wiki/Ptrace[ptrace]
261 to fulfill its function.
262 * http://www.sysdig.org/[sysdig], like SystemTap, uses scripts to
263 analyze Linux kernel events. You write scripts, or _chisels_ in
264 sysdig's jargon, in Lua and sysdig executes them while the system is
265 being traced or afterwards. sysdig's interface is the cmd:sysdig
266 command-line tool as well as the curses-based cmd:csysdig tool.
267 * https://sourceware.org/systemtap/[SystemTap] is a Linux kernel and
268 user space tracer which uses custom user scripts to produce plain text
269 traces. SystemTap converts the scripts to the C language, and then
270 compiles them as Linux kernel modules which are loaded to produce
271 trace data. SystemTap's primary user interface is the cmd:stap
274 The main distinctive features of LTTng is that it produces correlated
275 kernel and user space traces, as well as doing so with the lowest
276 overhead amongst other solutions. It produces trace files in the
277 http://diamon.org/ctf[CTF] format, a file format optimized
278 for the production and analyses of multi-gigabyte data.
280 LTTng is the result of more than 10 years of active open source
281 development by a community of passionate developers.
282 LTTng{nbsp}{revision} is currently available on major desktop and server
285 The main interface for tracing control is a single command-line tool
286 named cmd:lttng. The latter can create several tracing sessions, enable
287 and disable events on the fly, filter events efficiently with custom
288 user expressions, start and stop tracing, and much more. LTTng can
289 record the traces on the file system or send them over the network, and
290 keep them totally or partially. You can view the traces once tracing
291 becomes inactive or in real-time.
293 <<installing-lttng,Install LTTng now>> and
294 <<getting-started,start tracing>>!
300 **LTTng** is a set of software <<plumbing,components>> which interact to
301 <<instrumenting,instrument>> the Linux kernel and user applications, and
302 to <<controlling-tracing,control tracing>> (start and stop
303 tracing, enable and disable event rules, and the rest). Those
304 components are bundled into the following packages:
306 * **LTTng-tools**: Libraries and command-line interface to
308 * **LTTng-modules**: Linux kernel modules to instrument and
310 * **LTTng-UST**: Libraries and Java/Python packages to instrument and
311 trace user applications.
313 Most distributions mark the LTTng-modules and LTTng-UST packages as
314 optional when installing LTTng-tools (which is always required). In the
315 following sections, we always provide the steps to install all three,
318 * You only need to install LTTng-modules if you intend to trace the
320 * You only need to install LTTng-UST if you intend to trace user
324 .Availability of LTTng{nbsp}{revision} for major Linux distributions as of 18 October 2019.
326 |Distribution |Available in releases
328 |https://www.ubuntu.com/[Ubuntu]
329 |xref:ubuntu[Ubuntu{nbsp}18.04 _Bionic Beaver_,
330 Ubuntu{nbsp}19.04 _Disco Dingo_, and
331 Ubuntu{nbsp}19.10 _Eoan Ermine_].
333 Ubuntu{nbsp}16.04 _Xenial Xerus_:
334 <<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>.
336 |https://getfedora.org/[Fedora]
337 |xref:fedora[Fedora{nbsp}29, Fedora{nbsp}30, Fedora{nbsp}31,
340 |https://www.debian.org/[Debian]
341 |<<debian,Debian "buster" (stable) and Debian "bullseye" (testing)>>.
343 |https://alpinelinux.org/[Alpine Linux]
344 |xref:alpine-linux[Alpine Linux{nbsp}3.7, Alpine Linux{nbsp}3.8,
345 Alpine Linux{nbsp}3.9, and Alpine Linux{nbsp}3.10].
347 |https://www.opensuse.org/[openSUSE]
348 |<<opensuse,openSUSE Leap{nbsp}15.1>>.
350 |https://www.redhat.com/[RHEL] and https://www.suse.com/[SLES]
351 |See http://packages.efficios.com/[EfficiOS Enterprise Packages].
353 |https://buildroot.org/[Buildroot]
354 |xref:buildroot[Buildroot{nbsp}2018.02, Buildroot{nbsp}2018.05,
355 Buildroot{nbsp}2018.08, Buildroot{nbsp}2018.11, Buildroot{nbsp}2019.02,
356 Buildroot{nbsp}2018.05, Buildroot{nbsp}2018.08, and
357 Buildroot{nbsp}2018.11].
359 |http://www.openembedded.org/wiki/Main_Page[OpenEmbedded] and
360 https://www.yoctoproject.org/[Yocto]
361 |<<oe-yocto,Yocto Project{nbsp}2.7 _Warrior_ and
362 Yocto Project{nbsp}3.0 _Zeus_>>.
367 === [[ubuntu-official-repositories]]Ubuntu
369 LTTng{nbsp}{revision} is available on:
371 * Ubuntu{nbsp}18.04 _Bionic Beaver_
372 * Ubuntu{nbsp}19.04 _Disco Dingo_
373 * Ubuntu{nbsp}19.10 _Eoan Ermine_
375 For other releases of Ubuntu, <<ubuntu-ppa,use the LTTng
376 Stable{nbsp}{revision} PPA>>.
378 To install LTTng{nbsp}{revision} on Ubuntu{nbsp}18.04 _Bionic Beaver_,
379 Ubuntu{nbsp}19.04 _Disco Dingo_, or
380 Ubuntu{nbsp}19.10 _Eoan Ermine_:
382 . Install the main LTTng{nbsp}{revision} packages:
387 # apt-get install lttng-tools
388 # apt-get install lttng-modules-dkms
389 # apt-get install liblttng-ust-dev
393 . **If you need to instrument and trace
394 <<java-application,Java applications>>**, install the LTTng-UST
400 # apt-get install liblttng-ust-agent-java
404 . **If you need to instrument and trace
405 <<python-application,Python{nbsp}3 applications>>**, install the
406 LTTng-UST Python agent:
411 # apt-get install python3-lttngust
417 ==== noch:{LTTng} Stable {revision} PPA
419 The https://launchpad.net/~lttng/+archive/ubuntu/stable-{revision}[LTTng
420 Stable{nbsp}{revision} PPA] offers the latest stable
421 LTTng{nbsp}{revision} packages for Ubuntu{nbsp}18.04 _Bionic Beaver_.
423 To install LTTng{nbsp}{revision} from the LTTng Stable{nbsp}{revision} PPA:
425 . Add the LTTng Stable{nbsp}{revision} PPA repository and update the
431 # apt-add-repository ppa:lttng/stable-2.10
436 . Install the main LTTng{nbsp}{revision} packages:
441 # apt-get install lttng-tools
442 # apt-get install lttng-modules-dkms
443 # apt-get install liblttng-ust-dev
447 . **If you need to instrument and trace
448 <<java-application,Java applications>>**, install the LTTng-UST
454 # apt-get install liblttng-ust-agent-java
458 . **If you need to instrument and trace
459 <<python-application,Python{nbsp}3 applications>>**, install the
460 LTTng-UST Python agent:
465 # apt-get install python3-lttngust
473 To install LTTng{nbsp}{revision} on Fedora{nbsp}29, Fedora{nbsp}30,
474 Fedora{nbsp}31, or Fedora{nbsp}32:
476 . Install the LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision}
482 # yum install lttng-tools
483 # yum install lttng-ust
487 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
493 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
494 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
495 cd lttng-modules-2.10.* &&
497 sudo make modules_install &&
503 .Java and Python application instrumentation and tracing
505 If you need to instrument and trace <<java-application,Java
506 applications>> on Fedora, you need to build and install
507 LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass
508 the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or
509 `--enable-java-agent-all` options to the `configure` script, depending
510 on which Java logging framework you use.
512 If you need to instrument and trace <<python-application,Python
513 applications>> on Fedora, you need to build and install
514 LTTng-UST{nbsp}{revision} from source and pass the
515 `--enable-python-agent` option to the `configure` script.
522 To install LTTng{nbsp}{revision} on Debian "buster" (stable) or
523 Debian "bullseye" (testing):
525 . Install the main LTTng{nbsp}{revision} packages:
530 # apt-get install lttng-modules-dkms
531 # apt-get install liblttng-ust-dev
532 # apt-get install lttng-tools
536 . **If you need to instrument and trace <<java-application,Java
537 applications>>**, install the LTTng-UST Java agent:
542 # apt-get install liblttng-ust-agent-java
546 . **If you need to instrument and trace <<python-application,Python
547 applications>>**, install the LTTng-UST Python agent:
552 # apt-get install python3-lttngust
560 To install LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision} on
561 Alpine Linux{nbsp}3.7, Alpine Linux{nbsp}3.8, Alpine Linux{nbsp}3.9, or
562 Alpine Linux{nbsp}3.10:
564 . Add the LTTng packages:
569 # apk add lttng-tools
570 # apk add lttng-ust-dev
574 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
580 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
581 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
582 cd lttng-modules-2.10.* &&
584 sudo make modules_install &&
593 To install LTTng{nbsp}{revision} on openSUSE Leap{nbsp}15.1:
595 * Install the main LTTng{nbsp}{revision} packages:
600 sudo zypper install lttng-tools
601 sudo zypper install lttng-modules
602 sudo zypper install lttng-ust-devel
607 .Java and Python application instrumentation and tracing
609 If you need to instrument and trace <<java-application,Java
610 applications>> on openSUSE, you need to build and install
611 LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass
612 the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or
613 `--enable-java-agent-all` options to the `configure` script, depending
614 on which Java logging framework you use.
616 If you need to instrument and trace <<python-application,Python
617 applications>> on openSUSE, you need to build and install
618 LTTng-UST{nbsp}{revision} from source and pass the
619 `--enable-python-agent` option to the `configure` script.
623 [[enterprise-distributions]]
624 === RHEL, SUSE, and other enterprise distributions
626 To install LTTng on enterprise Linux distributions, such as Red Hat
627 Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SUSE), please
628 see http://packages.efficios.com/[EfficiOS Enterprise Packages].
634 To install LTTng{nbsp}{revision} on Buildroot{nbsp}2018.02,
635 Buildroot{nbsp}2018.05, Buildroot{nbsp}2018.08,
636 Buildroot{nbsp}2018.11, Buildroot{nbsp}2019.02,
637 Buildroot{nbsp}2019.05, Buildroot{nbsp}2019.08, or
638 Buildroot{nbsp}2019.11:
640 . Launch the Buildroot configuration tool:
649 . In **Kernel**, check **Linux kernel**.
650 . In **Toolchain**, check **Enable WCHAR support**.
651 . In **Target packages**{nbsp}→ **Debugging, profiling and benchmark**,
652 check **lttng-modules** and **lttng-tools**.
653 . In **Target packages**{nbsp}→ **Libraries**{nbsp}→
654 **Other**, check **lttng-libust**.
658 === OpenEmbedded and Yocto
660 LTTng{nbsp}{revision} recipes are available in the
661 http://layers.openembedded.org/layerindex/branch/master/layer/openembedded-core/[`openembedded-core`]
662 layer for Yocto Project{nbsp}2.7 _Warrior_ and
663 Yocto Project{nbsp}3.0 _Zeus_ under the following names:
669 With BitBake, the simplest way to include LTTng recipes in your target
670 image is to add them to `IMAGE_INSTALL_append` in path:{conf/local.conf}:
673 IMAGE_INSTALL_append = " lttng-tools lttng-modules lttng-ust"
678 . Select a machine and an image recipe.
679 . Click **Edit image recipe**.
680 . Under the **All recipes** tab, search for **lttng**.
681 . Check the desired LTTng recipes.
684 .Java and Python application instrumentation and tracing
686 If you need to instrument and trace <<java-application,Java
687 applications>> on Yocto/OpenEmbedded, you need to build and install
688 LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass
689 the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or
690 `--enable-java-agent-all` options to the `configure` script, depending
691 on which Java logging framework you use.
693 If you need to instrument and trace <<python-application,Python
694 applications>> on Yocto/OpenEmbedded, you need to build and install
695 LTTng-UST{nbsp}{revision} from source and pass the
696 `--enable-python-agent` option to the `configure` script.
700 [[building-from-source]]
701 === Build from source
703 To build and install LTTng{nbsp}{revision} from source:
705 . Using your distribution's package manager, or from source, install
706 the following dependencies of LTTng-tools and LTTng-UST:
709 * https://sourceforge.net/projects/libuuid/[libuuid]
710 * http://directory.fsf.org/wiki/Popt[popt]
711 * http://liburcu.org/[Userspace RCU]
712 * http://www.xmlsoft.org/[libxml2]
715 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
721 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
722 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
723 cd lttng-modules-2.10.* &&
725 sudo make modules_install &&
730 . Download, build, and install the latest LTTng-UST{nbsp}{revision}:
736 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.10.tar.bz2 &&
737 tar -xf lttng-ust-latest-2.10.tar.bz2 &&
738 cd lttng-ust-2.10.* &&
748 .Java and Python application tracing
750 If you need to instrument and trace <<java-application,Java
751 applications>>, pass the `--enable-java-agent-jul`,
752 `--enable-java-agent-log4j`, or `--enable-java-agent-all` options to the
753 `configure` script, depending on which Java logging framework you use.
755 If you need to instrument and trace <<python-application,Python
756 applications>>, pass the `--enable-python-agent` option to the
757 `configure` script. You can set the `PYTHON` environment variable to the
758 path to the Python interpreter for which to install the LTTng-UST Python
766 By default, LTTng-UST libraries are installed to
767 dir:{/usr/local/lib}, which is the de facto directory in which to
768 keep self-compiled and third-party libraries.
770 When <<building-tracepoint-providers-and-user-application,linking an
771 instrumented user application with `liblttng-ust`>>:
773 * Append `/usr/local/lib` to the env:LD_LIBRARY_PATH environment
775 * Pass the `-L/usr/local/lib` and `-Wl,-rpath,/usr/local/lib` options to
776 man:gcc(1), man:g++(1), or man:clang(1).
780 . Download, build, and install the latest LTTng-tools{nbsp}{revision}:
786 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.10.tar.bz2 &&
787 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
788 cd lttng-tools-2.10.* &&
796 TIP: The https://github.com/eepp/vlttng[vlttng tool] can do all the
797 previous steps automatically for a given version of LTTng and confine
798 the installed files in a specific directory. This can be useful to test
799 LTTng without installing it on your system.
805 This is a short guide to get started quickly with LTTng kernel and user
808 Before you follow this guide, make sure to <<installing-lttng,install>>
811 This tutorial walks you through the steps to:
813 . <<tracing-the-linux-kernel,Trace the Linux kernel>>.
814 . <<tracing-your-own-user-application,Trace a user application>> written
816 . <<viewing-and-analyzing-your-traces,View and analyze the
820 [[tracing-the-linux-kernel]]
821 === Trace the Linux kernel
823 The following command lines start with the `#` prompt because you need
824 root privileges to trace the Linux kernel. You can also trace the kernel
825 as a regular user if your Unix user is a member of the
826 <<tracing-group,tracing group>>.
828 . Create a <<tracing-session,tracing session>> which writes its traces
829 to dir:{/tmp/my-kernel-trace}:
834 # lttng create my-kernel-session --output=/tmp/my-kernel-trace
838 . List the available kernel tracepoints and system calls:
843 # lttng list --kernel
844 # lttng list --kernel --syscall
848 . Create <<event,event rules>> which match the desired instrumentation
849 point names, for example the `sched_switch` and `sched_process_fork`
850 tracepoints, and the man:open(2) and man:close(2) system calls:
855 # lttng enable-event --kernel sched_switch,sched_process_fork
856 # lttng enable-event --kernel --syscall open,close
860 You can also create an event rule which matches _all_ the Linux kernel
861 tracepoints (this will generate a lot of data when tracing):
866 # lttng enable-event --kernel --all
870 . <<basic-tracing-session-control,Start tracing>>:
879 . Do some operation on your system for a few seconds. For example,
880 load a website, or list the files of a directory.
881 . <<creating-destroying-tracing-sessions,Destroy>> the current
891 The man:lttng-destroy(1) command does not destroy the trace data; it
892 only destroys the state of the tracing session.
894 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
895 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
896 session>>). You need to stop tracing to make LTTng flush the remaining
897 trace data and make the trace readable.
899 . For the sake of this example, make the recorded trace accessible to
905 # chown -R $(whoami) /tmp/my-kernel-trace
909 See <<viewing-and-analyzing-your-traces,View and analyze the
910 recorded events>> to view the recorded events.
913 [[tracing-your-own-user-application]]
914 === Trace a user application
916 This section steps you through a simple example to trace a
917 _Hello world_ program written in C.
919 To create the traceable user application:
921 . Create the tracepoint provider header file, which defines the
922 tracepoints and the events they can generate:
928 #undef TRACEPOINT_PROVIDER
929 #define TRACEPOINT_PROVIDER hello_world
931 #undef TRACEPOINT_INCLUDE
932 #define TRACEPOINT_INCLUDE "./hello-tp.h"
934 #if !defined(_HELLO_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
937 #include <lttng/tracepoint.h>
947 ctf_string(my_string_field, my_string_arg)
948 ctf_integer(int, my_integer_field, my_integer_arg)
952 #endif /* _HELLO_TP_H */
954 #include <lttng/tracepoint-event.h>
958 . Create the tracepoint provider package source file:
964 #define TRACEPOINT_CREATE_PROBES
965 #define TRACEPOINT_DEFINE
967 #include "hello-tp.h"
971 . Build the tracepoint provider package:
976 $ gcc -c -I. hello-tp.c
980 . Create the _Hello World_ application source file:
987 #include "hello-tp.h"
989 int main(int argc, char *argv[])
993 puts("Hello, World!\nPress Enter to continue...");
996 * The following getchar() call is only placed here for the purpose
997 * of this demonstration, to pause the application in order for
998 * you to have time to list its tracepoints. It is not
1004 * A tracepoint() call.
1006 * Arguments, as defined in hello-tp.h:
1008 * 1. Tracepoint provider name (required)
1009 * 2. Tracepoint name (required)
1010 * 3. my_integer_arg (first user-defined argument)
1011 * 4. my_string_arg (second user-defined argument)
1013 * Notice the tracepoint provider and tracepoint names are
1014 * NOT strings: they are in fact parts of variables that the
1015 * macros in hello-tp.h create.
1017 tracepoint(hello_world, my_first_tracepoint, 23, "hi there!");
1019 for (x = 0; x < argc; ++x) {
1020 tracepoint(hello_world, my_first_tracepoint, x, argv[x]);
1023 puts("Quitting now!");
1024 tracepoint(hello_world, my_first_tracepoint, x * x, "x^2");
1031 . Build the application:
1040 . Link the application with the tracepoint provider package,
1041 `liblttng-ust`, and `libdl`:
1046 $ gcc -o hello hello.o hello-tp.o -llttng-ust -ldl
1050 Here's the whole build process:
1053 .User space tracing tutorial's build steps.
1054 image::ust-flow.png[]
1056 To trace the user application:
1058 . Run the application with a few arguments:
1063 $ ./hello world and beyond
1072 Press Enter to continue...
1076 . Start an LTTng <<lttng-sessiond,session daemon>>:
1081 $ lttng-sessiond --daemonize
1085 Note that a session daemon might already be running, for example as
1086 a service that the distribution's service manager started.
1088 . List the available user space tracepoints:
1093 $ lttng list --userspace
1097 You see the `hello_world:my_first_tracepoint` tracepoint listed
1098 under the `./hello` process.
1100 . Create a <<tracing-session,tracing session>>:
1105 $ lttng create my-user-space-session
1109 . Create an <<event,event rule>> which matches the
1110 `hello_world:my_first_tracepoint` event name:
1115 $ lttng enable-event --userspace hello_world:my_first_tracepoint
1119 . <<basic-tracing-session-control,Start tracing>>:
1128 . Go back to the running `hello` application and press Enter. The
1129 program executes all `tracepoint()` instrumentation points and exits.
1130 . <<creating-destroying-tracing-sessions,Destroy>> the current
1140 The man:lttng-destroy(1) command does not destroy the trace data; it
1141 only destroys the state of the tracing session.
1143 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
1144 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
1145 session>>). You need to stop tracing to make LTTng flush the remaining
1146 trace data and make the trace readable.
1148 By default, LTTng saves the traces in
1149 +$LTTNG_HOME/lttng-traces/__name__-__date__-__time__+,
1150 where +__name__+ is the tracing session name. The
1151 env:LTTNG_HOME environment variable defaults to `$HOME` if not set.
1153 See <<viewing-and-analyzing-your-traces,View and analyze the
1154 recorded events>> to view the recorded events.
1157 [[viewing-and-analyzing-your-traces]]
1158 === View and analyze the recorded events
1160 Once you have completed the <<tracing-the-linux-kernel,Trace the Linux
1161 kernel>> and <<tracing-your-own-user-application,Trace a user
1162 application>> tutorials, you can inspect the recorded events.
1164 Many tools are available to read LTTng traces:
1166 * **cmd:babeltrace** is a command-line utility which converts trace
1167 formats; it supports the format that LTTng produces, CTF, as well as a
1168 basic text output which can be ++grep++ed. The cmd:babeltrace command
1169 is part of the http://diamon.org/babeltrace[Babeltrace] project.
1170 * Babeltrace also includes
1171 **https://www.python.org/[Python] bindings** so
1172 that you can easily open and read an LTTng trace with your own script,
1173 benefiting from the power of Python.
1174 * http://tracecompass.org/[**Trace Compass**]
1175 is a graphical user interface for viewing and analyzing any type of
1176 logs or traces, including LTTng's.
1177 * https://github.com/lttng/lttng-analyses[**LTTng analyses**] is a
1178 project which includes many high-level analyses of LTTng kernel
1179 traces, like scheduling statistics, interrupt frequency distribution,
1180 top CPU usage, and more.
1182 NOTE: This section assumes that the traces recorded during the previous
1183 tutorials were saved to their default location, in the
1184 dir:{$LTTNG_HOME/lttng-traces} directory. The env:LTTNG_HOME
1185 environment variable defaults to `$HOME` if not set.
1188 [[viewing-and-analyzing-your-traces-bt]]
1189 ==== Use the cmd:babeltrace command-line tool
1191 The simplest way to list all the recorded events of a trace is to pass
1192 its path to cmd:babeltrace with no options:
1196 $ babeltrace ~/lttng-traces/my-user-space-session*
1199 cmd:babeltrace finds all traces recursively within the given path and
1200 prints all their events, merging them in chronological order.
1202 You can pipe the output of cmd:babeltrace into a tool like man:grep(1) for
1207 $ babeltrace /tmp/my-kernel-trace | grep _switch
1210 You can pipe the output of cmd:babeltrace into a tool like man:wc(1) to
1211 count the recorded events:
1215 $ babeltrace /tmp/my-kernel-trace | grep _open | wc --lines
1219 [[viewing-and-analyzing-your-traces-bt-python]]
1220 ==== Use the Babeltrace Python bindings
1222 The <<viewing-and-analyzing-your-traces-bt,text output of cmd:babeltrace>>
1223 is useful to isolate events by simple matching using man:grep(1) and
1224 similar utilities. However, more elaborate filters, such as keeping only
1225 event records with a field value falling within a specific range, are
1226 not trivial to write using a shell. Moreover, reductions and even the
1227 most basic computations involving multiple event records are virtually
1228 impossible to implement.
1230 Fortunately, Babeltrace ships with Python 3 bindings which makes it easy
1231 to read the event records of an LTTng trace sequentially and compute the
1232 desired information.
1234 The following script accepts an LTTng Linux kernel trace path as its
1235 first argument and prints the short names of the top 5 running processes
1236 on CPU 0 during the whole trace:
1241 from collections import Counter
1247 if len(sys.argv) != 2:
1248 msg = 'Usage: python3 {} TRACEPATH'.format(sys.argv[0])
1249 print(msg, file=sys.stderr)
1252 # A trace collection contains one or more traces
1253 col = babeltrace.TraceCollection()
1255 # Add the trace provided by the user (LTTng traces always have
1257 if col.add_trace(sys.argv[1], 'ctf') is None:
1258 raise RuntimeError('Cannot add trace')
1260 # This counter dict contains execution times:
1262 # task command name -> total execution time (ns)
1263 exec_times = Counter()
1265 # This contains the last `sched_switch` timestamp
1269 for event in col.events:
1270 # Keep only `sched_switch` events
1271 if event.name != 'sched_switch':
1274 # Keep only events which happened on CPU 0
1275 if event['cpu_id'] != 0:
1279 cur_ts = event.timestamp
1285 # Previous task command (short) name
1286 prev_comm = event['prev_comm']
1288 # Initialize entry in our dict if not yet done
1289 if prev_comm not in exec_times:
1290 exec_times[prev_comm] = 0
1292 # Compute previous command execution time
1293 diff = cur_ts - last_ts
1295 # Update execution time of this command
1296 exec_times[prev_comm] += diff
1298 # Update last timestamp
1302 for name, ns in exec_times.most_common(5):
1304 print('{:20}{} s'.format(name, s))
1309 if __name__ == '__main__':
1310 sys.exit(0 if top5proc() else 1)
1317 $ python3 top5proc.py /tmp/my-kernel-trace/kernel
1323 swapper/0 48.607245889 s
1324 chromium 7.192738188 s
1325 pavucontrol 0.709894415 s
1326 Compositor 0.660867933 s
1327 Xorg.bin 0.616753786 s
1330 Note that `swapper/0` is the "idle" process of CPU 0 on Linux; since we
1331 weren't using the CPU that much when tracing, its first position in the
1336 == [[understanding-lttng]]Core concepts
1338 From a user's perspective, the LTTng system is built on a few concepts,
1339 or objects, on which the <<lttng-cli,cmd:lttng command-line tool>>
1340 operates by sending commands to the <<lttng-sessiond,session daemon>>.
1341 Understanding how those objects relate to eachother is key in mastering
1344 The core concepts are:
1346 * <<tracing-session,Tracing session>>
1347 * <<domain,Tracing domain>>
1348 * <<channel,Channel and ring buffer>>
1349 * <<"event","Instrumentation point, event rule, event, and event record">>
1355 A _tracing session_ is a stateful dialogue between you and
1356 a <<lttng-sessiond,session daemon>>. You can
1357 <<creating-destroying-tracing-sessions,create a new tracing
1358 session>> with the `lttng create` command.
1360 Anything that you do when you control LTTng tracers happens within a
1361 tracing session. In particular, a tracing session:
1364 * Has its own set of trace files.
1365 * Has its own state of activity (started or stopped).
1366 * Has its own <<tracing-session-mode,mode>> (local, network streaming,
1368 * Has its own <<channel,channels>> which have their own
1369 <<event,event rules>>.
1372 .A _tracing session_ contains <<channel,channels>> that are members of <<domain,tracing domains>> and contain <<event,event rules>>.
1373 image::concepts.png[]
1375 Those attributes and objects are completely isolated between different
1378 A tracing session is analogous to a cash machine session:
1379 the operations you do on the banking system through the cash machine do
1380 not alter the data of other users of the same system. In the case of
1381 the cash machine, a session lasts as long as your bank card is inside.
1382 In the case of LTTng, a tracing session lasts from the `lttng create`
1383 command to the `lttng destroy` command.
1386 .Each Unix user has its own set of tracing sessions.
1387 image::many-sessions.png[]
1390 [[tracing-session-mode]]
1391 ==== Tracing session mode
1393 LTTng can send the generated trace data to different locations. The
1394 _tracing session mode_ dictates where to send it. The following modes
1395 are available in LTTng{nbsp}{revision}:
1398 LTTng writes the traces to the file system of the machine being traced
1401 Network streaming mode::
1402 LTTng sends the traces over the network to a
1403 <<lttng-relayd,relay daemon>> running on a remote system.
1406 LTTng does not write the traces by default. Instead, you can request
1407 LTTng to <<taking-a-snapshot,take a snapshot>>, that is, a copy of the
1408 current tracing buffers, and to write it to the target's file system
1409 or to send it over the network to a <<lttng-relayd,relay daemon>>
1410 running on a remote system.
1413 This mode is similar to the network streaming mode, but a live
1414 trace viewer can connect to the distant relay daemon to
1415 <<lttng-live,view event records as LTTng generates them>> by
1422 A _tracing domain_ is a namespace for event sources. A tracing domain
1423 has its own properties and features.
1425 There are currently five available tracing domains:
1429 * `java.util.logging` (JUL)
1433 You must specify a tracing domain when using some commands to avoid
1434 ambiguity. For example, since all the domains support named tracepoints
1435 as event sources (instrumentation points that you manually insert in the
1436 source code), you need to specify a tracing domain when
1437 <<enabling-disabling-events,creating an event rule>> because all the
1438 tracing domains could have tracepoints with the same names.
1440 Some features are reserved to specific tracing domains. Dynamic function
1441 entry and return instrumentation points, for example, are currently only
1442 supported in the Linux kernel tracing domain, but support for other
1443 tracing domains could be added in the future.
1445 You can create <<channel,channels>> in the Linux kernel and user space
1446 tracing domains. The other tracing domains have a single default
1451 === Channel and ring buffer
1453 A _channel_ is an object which is responsible for a set of ring buffers.
1454 Each ring buffer is divided into multiple sub-buffers. When an LTTng
1455 tracer emits an event, it can record it to one or more
1456 sub-buffers. The attributes of a channel determine what to do when
1457 there's no space left for a new event record because all sub-buffers
1458 are full, where to send a full sub-buffer, and other behaviours.
1460 A channel is always associated to a <<domain,tracing domain>>. The
1461 `java.util.logging` (JUL), log4j, and Python tracing domains each have
1462 a default channel which you cannot configure.
1464 A channel also owns <<event,event rules>>. When an LTTng tracer emits
1465 an event, it records it to the sub-buffers of all
1466 the enabled channels with a satisfied event rule, as long as those
1467 channels are part of active <<tracing-session,tracing sessions>>.
1470 [[channel-buffering-schemes]]
1471 ==== Per-user vs. per-process buffering schemes
1473 A channel has at least one ring buffer _per CPU_. LTTng always
1474 records an event to the ring buffer associated to the CPU on which it
1477 Two _buffering schemes_ are available when you
1478 <<enabling-disabling-channels,create a channel>> in the
1479 user space <<domain,tracing domain>>:
1481 Per-user buffering::
1482 Allocate one set of ring buffers--one per CPU--shared by all the
1483 instrumented processes of each Unix user.
1487 .Per-user buffering scheme.
1488 image::per-user-buffering.png[]
1491 Per-process buffering::
1492 Allocate one set of ring buffers--one per CPU--for each
1493 instrumented process.
1497 .Per-process buffering scheme.
1498 image::per-process-buffering.png[]
1501 The per-process buffering scheme tends to consume more memory than the
1502 per-user option because systems generally have more instrumented
1503 processes than Unix users running instrumented processes. However, the
1504 per-process buffering scheme ensures that one process having a high
1505 event throughput won't fill all the shared sub-buffers of the same
1508 The Linux kernel tracing domain has only one available buffering scheme
1509 which is to allocate a single set of ring buffers for the whole system.
1510 This scheme is similar to the per-user option, but with a single, global
1511 user "running" the kernel.
1514 [[channel-overwrite-mode-vs-discard-mode]]
1515 ==== Overwrite vs. discard event loss modes
1517 When an event occurs, LTTng records it to a specific sub-buffer (yellow
1518 arc in the following animation) of a specific channel's ring buffer.
1519 When there's no space left in a sub-buffer, the tracer marks it as
1520 consumable (red) and another, empty sub-buffer starts receiving the
1521 following event records. A <<lttng-consumerd,consumer daemon>>
1522 eventually consumes the marked sub-buffer (returns to white).
1525 [role="docsvg-channel-subbuf-anim"]
1530 In an ideal world, sub-buffers are consumed faster than they are filled,
1531 as is the case in the previous animation. In the real world,
1532 however, all sub-buffers can be full at some point, leaving no space to
1533 record the following events.
1535 By default, LTTng-modules and LTTng-UST are _non-blocking_ tracers: when
1536 no empty sub-buffer is available, it is acceptable to lose event records
1537 when the alternative would be to cause substantial delays in the
1538 instrumented application's execution. LTTng privileges performance over
1539 integrity; it aims at perturbing the traced system as little as possible
1540 in order to make tracing of subtle race conditions and rare interrupt
1543 Starting from LTTng{nbsp}2.10, the LTTng user space tracer, LTTng-UST,
1544 supports a _blocking mode_. See the <<blocking-timeout-example,blocking
1545 timeout example>> to learn how to use the blocking mode.
1547 When it comes to losing event records because no empty sub-buffer is
1548 available, or because the <<opt-blocking-timeout,blocking timeout>> is
1549 reached, the channel's _event loss mode_ determines what to do. The
1550 available event loss modes are:
1553 Drop the newest event records until a the tracer releases a
1556 This is the only available mode when you specify a
1557 <<opt-blocking-timeout,blocking timeout>>.
1560 Clear the sub-buffer containing the oldest event records and start
1561 writing the newest event records there.
1563 This mode is sometimes called _flight recorder mode_ because it's
1565 https://en.wikipedia.org/wiki/Flight_recorder[flight recorder]:
1566 always keep a fixed amount of the latest data.
1568 Which mechanism you should choose depends on your context: prioritize
1569 the newest or the oldest event records in the ring buffer?
1571 Beware that, in overwrite mode, the tracer abandons a _whole sub-buffer_
1572 as soon as a there's no space left for a new event record, whereas in
1573 discard mode, the tracer only discards the event record that doesn't
1576 In discard mode, LTTng increments a count of lost event records when an
1577 event record is lost and saves this count to the trace. In overwrite
1578 mode, since LTTng 2.8, LTTng increments a count of lost sub-buffers when
1579 a sub-buffer is lost and saves this count to the trace. In this mode,
1580 the exact number of lost event records in those lost sub-buffers is not
1581 saved to the trace. Trace analyses can use the trace's saved discarded
1582 event record and sub-buffer counts to decide whether or not to perform
1583 the analyses even if trace data is known to be missing.
1585 There are a few ways to decrease your probability of losing event
1587 <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>> shows
1588 how you can fine-tune the sub-buffer count and size of a channel to
1589 virtually stop losing event records, though at the cost of greater
1593 [[channel-subbuf-size-vs-subbuf-count]]
1594 ==== Sub-buffer count and size
1596 When you <<enabling-disabling-channels,create a channel>>, you can
1597 set its number of sub-buffers and their size.
1599 Note that there is noticeable CPU overhead introduced when
1600 switching sub-buffers (marking a full one as consumable and switching
1601 to an empty one for the following events to be recorded). Knowing this,
1602 the following list presents a few practical situations along with how
1603 to configure the sub-buffer count and size for them:
1605 * **High event throughput**: In general, prefer bigger sub-buffers to
1606 lower the risk of losing event records.
1608 Having bigger sub-buffers also ensures a lower
1609 <<channel-switch-timer,sub-buffer switching frequency>>.
1611 The number of sub-buffers is only meaningful if you create the channel
1612 in overwrite mode: in this case, if a sub-buffer overwrite happens, the
1613 other sub-buffers are left unaltered.
1615 * **Low event throughput**: In general, prefer smaller sub-buffers
1616 since the risk of losing event records is low.
1618 Because events occur less frequently, the sub-buffer switching frequency
1619 should remain low and thus the tracer's overhead should not be a
1622 * **Low memory system**: If your target system has a low memory
1623 limit, prefer fewer first, then smaller sub-buffers.
1625 Even if the system is limited in memory, you want to keep the
1626 sub-buffers as big as possible to avoid a high sub-buffer switching
1629 Note that LTTng uses http://diamon.org/ctf/[CTF] as its trace format,
1630 which means event data is very compact. For example, the average
1631 LTTng kernel event record weights about 32{nbsp}bytes. Thus, a
1632 sub-buffer size of 1{nbsp}MiB is considered big.
1634 The previous situations highlight the major trade-off between a few big
1635 sub-buffers and more, smaller sub-buffers: sub-buffer switching
1636 frequency vs. how much data is lost in overwrite mode. Assuming a
1637 constant event throughput and using the overwrite mode, the two
1638 following configurations have the same ring buffer total size:
1641 [role="docsvg-channel-subbuf-size-vs-count-anim"]
1646 * **2 sub-buffers of 4{nbsp}MiB each**: Expect a very low sub-buffer
1647 switching frequency, but if a sub-buffer overwrite happens, half of
1648 the event records so far (4{nbsp}MiB) are definitely lost.
1649 * **8 sub-buffers of 1{nbsp}MiB each**: Expect 4{nbsp}times the tracer's
1650 overhead as the previous configuration, but if a sub-buffer
1651 overwrite happens, only the eighth of event records so far are
1654 In discard mode, the sub-buffers count parameter is pointless: use two
1655 sub-buffers and set their size according to the requirements of your
1659 [[channel-switch-timer]]
1660 ==== Switch timer period
1662 The _switch timer period_ is an important configurable attribute of
1663 a channel to ensure periodic sub-buffer flushing.
1665 When the _switch timer_ expires, a sub-buffer switch happens. You can
1666 set the switch timer period attribute when you
1667 <<enabling-disabling-channels,create a channel>> to ensure that event
1668 data is consumed and committed to trace files or to a distant relay
1669 daemon periodically in case of a low event throughput.
1672 [role="docsvg-channel-switch-timer"]
1677 This attribute is also convenient when you use big sub-buffers to cope
1678 with a sporadic high event throughput, even if the throughput is
1682 [[channel-read-timer]]
1683 ==== Read timer period
1685 By default, the LTTng tracers use a notification mechanism to signal a
1686 full sub-buffer so that a consumer daemon can consume it. When such
1687 notifications must be avoided, for example in real-time applications,
1688 you can use the channel's _read timer_ instead. When the read timer
1689 fires, the <<lttng-consumerd,consumer daemon>> checks for full,
1690 consumable sub-buffers.
1693 [[tracefile-rotation]]
1694 ==== Trace file count and size
1696 By default, trace files can grow as large as needed. You can set the
1697 maximum size of each trace file that a channel writes when you
1698 <<enabling-disabling-channels,create a channel>>. When the size of
1699 a trace file reaches the channel's fixed maximum size, LTTng creates
1700 another file to contain the next event records. LTTng appends a file
1701 count to each trace file name in this case.
1703 If you set the trace file size attribute when you create a channel, the
1704 maximum number of trace files that LTTng creates is _unlimited_ by
1705 default. To limit them, you can also set a maximum number of trace
1706 files. When the number of trace files reaches the channel's fixed
1707 maximum count, the oldest trace file is overwritten. This mechanism is
1708 called _trace file rotation_.
1712 === Instrumentation point, event rule, event, and event record
1714 An _event rule_ is a set of conditions which must be **all** satisfied
1715 for LTTng to record an occuring event.
1717 You set the conditions when you <<enabling-disabling-events,create
1720 You always attach an event rule to <<channel,channel>> when you create
1723 When an event passes the conditions of an event rule, LTTng records it
1724 in one of the attached channel's sub-buffers.
1726 The available conditions, as of LTTng{nbsp}{revision}, are:
1728 * The event rule _is enabled_.
1729 * The instrumentation point's type _is{nbsp}T_.
1730 * The instrumentation point's name (sometimes called _event name_)
1731 _matches{nbsp}N_, but _is not{nbsp}E_.
1732 * The instrumentation point's log level _is as severe as{nbsp}L_, or
1733 _is exactly{nbsp}L_.
1734 * The fields of the event's payload _satisfy_ a filter
1735 expression{nbsp}__F__.
1737 As you can see, all the conditions but the dynamic filter are related to
1738 the event rule's status or to the instrumentation point, not to the
1739 occurring events. This is why, without a filter, checking if an event
1740 passes an event rule is not a dynamic task: when you create or modify an
1741 event rule, all the tracers of its tracing domain enable or disable the
1742 instrumentation points themselves once. This is possible because the
1743 attributes of an instrumentation point (type, name, and log level) are
1744 defined statically. In other words, without a dynamic filter, the tracer
1745 _does not evaluate_ the arguments of an instrumentation point unless it
1746 matches an enabled event rule.
1748 Note that, for LTTng to record an event, the <<channel,channel>> to
1749 which a matching event rule is attached must also be enabled, and the
1750 tracing session owning this channel must be active.
1753 .Logical path from an instrumentation point to an event record.
1754 image::event-rule.png[]
1756 .Event, event record, or event rule?
1758 With so many similar terms, it's easy to get confused.
1760 An **event** is the consequence of the execution of an _instrumentation
1761 point_, like a tracepoint that you manually place in some source code,
1762 or a Linux kernel KProbe. An event is said to _occur_ at a specific
1763 time. Different actions can be taken upon the occurrence of an event,
1764 like record the event's payload to a buffer.
1766 An **event record** is the representation of an event in a sub-buffer. A
1767 tracer is responsible for capturing the payload of an event, current
1768 context variables, the event's ID, and the event's timestamp. LTTng
1769 can append this sub-buffer to a trace file.
1771 An **event rule** is a set of conditions which must all be satisfied for
1772 LTTng to record an occuring event. Events still occur without
1773 satisfying event rules, but LTTng does not record them.
1778 == Components of noch:{LTTng}
1780 The second _T_ in _LTTng_ stands for _toolkit_: it would be wrong
1781 to call LTTng a simple _tool_ since it is composed of multiple
1782 interacting components. This section describes those components,
1783 explains their respective roles, and shows how they connect together to
1784 form the LTTng ecosystem.
1786 The following diagram shows how the most important components of LTTng
1787 interact with user applications, the Linux kernel, and you:
1790 .Control and trace data paths between LTTng components.
1791 image::plumbing.png[]
1793 The LTTng project incorporates:
1795 * **LTTng-tools**: Libraries and command-line interface to
1796 control tracing sessions.
1797 ** <<lttng-sessiond,Session daemon>> (man:lttng-sessiond(8)).
1798 ** <<lttng-consumerd,Consumer daemon>> (cmd:lttng-consumerd).
1799 ** <<lttng-relayd,Relay daemon>> (man:lttng-relayd(8)).
1800 ** <<liblttng-ctl-lttng,Tracing control library>> (`liblttng-ctl`).
1801 ** <<lttng-cli,Tracing control command-line tool>> (man:lttng(1)).
1802 * **LTTng-UST**: Libraries and Java/Python packages to trace user
1804 ** <<lttng-ust,User space tracing library>> (`liblttng-ust`) and its
1805 headers to instrument and trace any native user application.
1806 ** <<prebuilt-ust-helpers,Preloadable user space tracing helpers>>:
1807 *** `liblttng-ust-libc-wrapper`
1808 *** `liblttng-ust-pthread-wrapper`
1809 *** `liblttng-ust-cyg-profile`
1810 *** `liblttng-ust-cyg-profile-fast`
1811 *** `liblttng-ust-dl`
1812 ** User space tracepoint provider source files generator command-line
1813 tool (man:lttng-gen-tp(1)).
1814 ** <<lttng-ust-agents,LTTng-UST Java agent>> to instrument and trace
1815 Java applications using `java.util.logging` or
1816 Apache log4j 1.2 logging.
1817 ** <<lttng-ust-agents,LTTng-UST Python agent>> to instrument
1818 Python applications using the standard `logging` package.
1819 * **LTTng-modules**: <<lttng-modules,Linux kernel modules>> to trace
1821 ** LTTng kernel tracer module.
1822 ** Tracing ring buffer kernel modules.
1823 ** Probe kernel modules.
1824 ** LTTng logger kernel module.
1828 === Tracing control command-line interface
1831 .The tracing control command-line interface.
1832 image::plumbing-lttng-cli.png[]
1834 The _man:lttng(1) command-line tool_ is the standard user interface to
1835 control LTTng <<tracing-session,tracing sessions>>. The cmd:lttng tool
1836 is part of LTTng-tools.
1838 The cmd:lttng tool is linked with
1839 <<liblttng-ctl-lttng,`liblttng-ctl`>> to communicate with
1840 one or more <<lttng-sessiond,session daemons>> behind the scenes.
1842 The cmd:lttng tool has a Git-like interface:
1846 $ lttng <GENERAL OPTIONS> <COMMAND> <COMMAND OPTIONS>
1849 The <<controlling-tracing,Tracing control>> section explores the
1850 available features of LTTng using the cmd:lttng tool.
1853 [[liblttng-ctl-lttng]]
1854 === Tracing control library
1857 .The tracing control library.
1858 image::plumbing-liblttng-ctl.png[]
1860 The _LTTng control library_, `liblttng-ctl`, is used to communicate
1861 with a <<lttng-sessiond,session daemon>> using a C API that hides the
1862 underlying protocol's details. `liblttng-ctl` is part of LTTng-tools.
1864 The <<lttng-cli,cmd:lttng command-line tool>>
1865 is linked with `liblttng-ctl`.
1867 You can use `liblttng-ctl` in C or $$C++$$ source code by including its
1872 #include <lttng/lttng.h>
1875 Some objects are referenced by name (C string), such as tracing
1876 sessions, but most of them require to create a handle first using
1877 `lttng_create_handle()`.
1879 The best available developer documentation for `liblttng-ctl` is, as of
1880 LTTng{nbsp}{revision}, its installed header files. Every function and
1881 structure is thoroughly documented.
1885 === User space tracing library
1888 .The user space tracing library.
1889 image::plumbing-liblttng-ust.png[]
1891 The _user space tracing library_, `liblttng-ust` (see man:lttng-ust(3)),
1892 is the LTTng user space tracer. It receives commands from a
1893 <<lttng-sessiond,session daemon>>, for example to
1894 enable and disable specific instrumentation points, and writes event
1895 records to ring buffers shared with a
1896 <<lttng-consumerd,consumer daemon>>.
1897 `liblttng-ust` is part of LTTng-UST.
1899 Public C header files are installed beside `liblttng-ust` to
1900 instrument any <<c-application,C or $$C++$$ application>>.
1902 <<lttng-ust-agents,LTTng-UST agents>>, which are regular Java and Python
1903 packages, use their own library providing tracepoints which is
1904 linked with `liblttng-ust`.
1906 An application or library does not have to initialize `liblttng-ust`
1907 manually: its constructor does the necessary tasks to properly register
1908 to a session daemon. The initialization phase also enables the
1909 instrumentation points matching the <<event,event rules>> that you
1913 [[lttng-ust-agents]]
1914 === User space tracing agents
1917 .The user space tracing agents.
1918 image::plumbing-lttng-ust-agents.png[]
1920 The _LTTng-UST Java and Python agents_ are regular Java and Python
1921 packages which add LTTng tracing capabilities to the
1922 native logging frameworks. The LTTng-UST agents are part of LTTng-UST.
1924 In the case of Java, the
1925 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[`java.util.logging`
1926 core logging facilities] and
1927 https://logging.apache.org/log4j/1.2/[Apache log4j 1.2] are supported.
1928 Note that Apache Log4{nbsp}2 is not supported.
1930 In the case of Python, the standard
1931 https://docs.python.org/3/library/logging.html[`logging`] package
1932 is supported. Both Python 2 and Python 3 modules can import the
1933 LTTng-UST Python agent package.
1935 The applications using the LTTng-UST agents are in the
1936 `java.util.logging` (JUL),
1937 log4j, and Python <<domain,tracing domains>>.
1939 Both agents use the same mechanism to trace the log statements. When an
1940 agent is initialized, it creates a log handler that attaches to the root
1941 logger. The agent also registers to a <<lttng-sessiond,session daemon>>.
1942 When the application executes a log statement, it is passed to the
1943 agent's log handler by the root logger. The agent's log handler calls a
1944 native function in a tracepoint provider package shared library linked
1945 with <<lttng-ust,`liblttng-ust`>>, passing the formatted log message and
1946 other fields, like its logger name and its log level. This native
1947 function contains a user space instrumentation point, hence tracing the
1950 The log level condition of an
1951 <<event,event rule>> is considered when tracing
1952 a Java or a Python application, and it's compatible with the standard
1953 JUL, log4j, and Python log levels.
1957 === LTTng kernel modules
1960 .The LTTng kernel modules.
1961 image::plumbing-lttng-modules.png[]
1963 The _LTTng kernel modules_ are a set of Linux kernel modules
1964 which implement the kernel tracer of the LTTng project. The LTTng
1965 kernel modules are part of LTTng-modules.
1967 The LTTng kernel modules include:
1969 * A set of _probe_ modules.
1971 Each module attaches to a specific subsystem
1972 of the Linux kernel using its tracepoint instrument points. There are
1973 also modules to attach to the entry and return points of the Linux
1974 system call functions.
1976 * _Ring buffer_ modules.
1978 A ring buffer implementation is provided as kernel modules. The LTTng
1979 kernel tracer writes to the ring buffer; a
1980 <<lttng-consumerd,consumer daemon>> reads from the ring buffer.
1982 * The _LTTng kernel tracer_ module.
1983 * The _LTTng logger_ module.
1985 The LTTng logger module implements the special path:{/proc/lttng-logger}
1986 file so that any executable can generate LTTng events by opening and
1987 writing to this file.
1989 See <<proc-lttng-logger-abi,LTTng logger>>.
1991 Generally, you do not have to load the LTTng kernel modules manually
1992 (using man:modprobe(8), for example): a root <<lttng-sessiond,session
1993 daemon>> loads the necessary modules when starting. If you have extra
1994 probe modules, you can specify to load them to the session daemon on
1997 The LTTng kernel modules are installed in
1998 +/usr/lib/modules/__release__/extra+ by default, where +__release__+ is
1999 the kernel release (see `uname --kernel-release`).
2006 .The session daemon.
2007 image::plumbing-sessiond.png[]
2009 The _session daemon_, man:lttng-sessiond(8), is a daemon responsible for
2010 managing tracing sessions and for controlling the various components of
2011 LTTng. The session daemon is part of LTTng-tools.
2013 The session daemon sends control requests to and receives control
2016 * The <<lttng-ust,user space tracing library>>.
2018 Any instance of the user space tracing library first registers to
2019 a session daemon. Then, the session daemon can send requests to
2020 this instance, such as:
2023 ** Get the list of tracepoints.
2024 ** Share an <<event,event rule>> so that the user space tracing library
2025 can enable or disable tracepoints. Amongst the possible conditions
2026 of an event rule is a filter expression which `liblttng-ust` evalutes
2027 when an event occurs.
2028 ** Share <<channel,channel>> attributes and ring buffer locations.
2031 The session daemon and the user space tracing library use a Unix
2032 domain socket for their communication.
2034 * The <<lttng-ust-agents,user space tracing agents>>.
2036 Any instance of a user space tracing agent first registers to
2037 a session daemon. Then, the session daemon can send requests to
2038 this instance, such as:
2041 ** Get the list of loggers.
2042 ** Enable or disable a specific logger.
2045 The session daemon and the user space tracing agent use a TCP connection
2046 for their communication.
2048 * The <<lttng-modules,LTTng kernel tracer>>.
2049 * The <<lttng-consumerd,consumer daemon>>.
2051 The session daemon sends requests to the consumer daemon to instruct
2052 it where to send the trace data streams, amongst other information.
2054 * The <<lttng-relayd,relay daemon>>.
2056 The session daemon receives commands from the
2057 <<liblttng-ctl-lttng,tracing control library>>.
2059 The root session daemon loads the appropriate
2060 <<lttng-modules,LTTng kernel modules>> on startup. It also spawns
2061 a <<lttng-consumerd,consumer daemon>> as soon as you create
2062 an <<event,event rule>>.
2064 The session daemon does not send and receive trace data: this is the
2065 role of the <<lttng-consumerd,consumer daemon>> and
2066 <<lttng-relayd,relay daemon>>. It does, however, generate the
2067 http://diamon.org/ctf/[CTF] metadata stream.
2069 Each Unix user can have its own session daemon instance. The
2070 tracing sessions managed by different session daemons are completely
2073 The root user's session daemon is the only one which is
2074 allowed to control the LTTng kernel tracer, and its spawned consumer
2075 daemon is the only one which is allowed to consume trace data from the
2076 LTTng kernel tracer. Note, however, that any Unix user which is a member
2077 of the <<tracing-group,tracing group>> is allowed
2078 to create <<channel,channels>> in the
2079 Linux kernel <<domain,tracing domain>>, and thus to trace the Linux
2082 The <<lttng-cli,cmd:lttng command-line tool>> automatically starts a
2083 session daemon when using its `create` command if none is currently
2084 running. You can also start the session daemon manually.
2091 .The consumer daemon.
2092 image::plumbing-consumerd.png[]
2094 The _consumer daemon_, cmd:lttng-consumerd, is a daemon which shares
2095 ring buffers with user applications or with the LTTng kernel modules to
2096 collect trace data and send it to some location (on disk or to a
2097 <<lttng-relayd,relay daemon>> over the network). The consumer daemon
2098 is part of LTTng-tools.
2100 You do not start a consumer daemon manually: a consumer daemon is always
2101 spawned by a <<lttng-sessiond,session daemon>> as soon as you create an
2102 <<event,event rule>>, that is, before you start tracing. When you kill
2103 its owner session daemon, the consumer daemon also exits because it is
2104 the session daemon's child process. Command-line options of
2105 man:lttng-sessiond(8) target the consumer daemon process.
2107 There are up to two running consumer daemons per Unix user, whereas only
2108 one session daemon can run per user. This is because each process can be
2109 either 32-bit or 64-bit: if the target system runs a mixture of 32-bit
2110 and 64-bit processes, it is more efficient to have separate
2111 corresponding 32-bit and 64-bit consumer daemons. The root user is an
2112 exception: it can have up to _three_ running consumer daemons: 32-bit
2113 and 64-bit instances for its user applications, and one more
2114 reserved for collecting kernel trace data.
2122 image::plumbing-relayd.png[]
2124 The _relay daemon_, man:lttng-relayd(8), is a daemon acting as a bridge
2125 between remote session and consumer daemons, local trace files, and a
2126 remote live trace viewer. The relay daemon is part of LTTng-tools.
2128 The main purpose of the relay daemon is to implement a receiver of
2129 <<sending-trace-data-over-the-network,trace data over the network>>.
2130 This is useful when the target system does not have much file system
2131 space to record trace files locally.
2133 The relay daemon is also a server to which a
2134 <<lttng-live,live trace viewer>> can
2135 connect. The live trace viewer sends requests to the relay daemon to
2136 receive trace data as the target system emits events. The
2137 communication protocol is named _LTTng live_; it is used over TCP
2140 Note that you can start the relay daemon on the target system directly.
2141 This is the setup of choice when the use case is to view events as
2142 the target system emits them without the need of a remote system.
2146 == [[using-lttng]]Instrumentation
2148 There are many examples of tracing and monitoring in our everyday life:
2150 * You have access to real-time and historical weather reports and
2151 forecasts thanks to weather stations installed around the country.
2152 * You know your heart is safe thanks to an electrocardiogram.
2153 * You make sure not to drive your car too fast and to have enough fuel
2154 to reach your destination thanks to gauges visible on your dashboard.
2156 All the previous examples have something in common: they rely on
2157 **instruments**. Without the electrodes attached to the surface of your
2158 body's skin, cardiac monitoring is futile.
2160 LTTng, as a tracer, is no different from those real life examples. If
2161 you're about to trace a software system or, in other words, record its
2162 history of execution, you better have **instrumentation points** in the
2163 subject you're tracing, that is, the actual software.
2165 Various ways were developed to instrument a piece of software for LTTng
2166 tracing. The most straightforward one is to manually place
2167 instrumentation points, called _tracepoints_, in the software's source
2168 code. It is also possible to add instrumentation points dynamically in
2169 the Linux kernel <<domain,tracing domain>>.
2171 If you're only interested in tracing the Linux kernel, your
2172 instrumentation needs are probably already covered by LTTng's built-in
2173 <<lttng-modules,Linux kernel tracepoints>>. You may also wish to trace a
2174 user application which is already instrumented for LTTng tracing.
2175 In such cases, you can skip this whole section and read the topics of
2176 the <<controlling-tracing,Tracing control>> section.
2178 Many methods are available to instrument a piece of software for LTTng
2181 * <<c-application,User space instrumentation for C and $$C++$$
2183 * <<prebuilt-ust-helpers,Prebuilt user space tracing helpers>>.
2184 * <<java-application,User space Java agent>>.
2185 * <<python-application,User space Python agent>>.
2186 * <<proc-lttng-logger-abi,LTTng logger>>.
2187 * <<instrumenting-linux-kernel,LTTng kernel tracepoints>>.
2191 === [[cxx-application]]User space instrumentation for C and $$C++$$ applications
2193 The procedure to instrument a C or $$C++$$ user application with
2194 the <<lttng-ust,LTTng user space tracing library>>, `liblttng-ust`, is:
2196 . <<tracepoint-provider,Create the source files of a tracepoint provider
2198 . <<probing-the-application-source-code,Add tracepoints to
2199 the application's source code>>.
2200 . <<building-tracepoint-providers-and-user-application,Build and link
2201 a tracepoint provider package and the user application>>.
2203 If you need quick, man:printf(3)-like instrumentation, you can skip
2204 those steps and use <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>>
2207 IMPORTANT: You need to <<installing-lttng,install>> LTTng-UST to
2208 instrument a user application with `liblttng-ust`.
2211 [[tracepoint-provider]]
2212 ==== Create the source files of a tracepoint provider package
2214 A _tracepoint provider_ is a set of compiled functions which provide
2215 **tracepoints** to an application, the type of instrumentation point
2216 supported by LTTng-UST. Those functions can emit events with
2217 user-defined fields and serialize those events as event records to one
2218 or more LTTng-UST <<channel,channel>> sub-buffers. The `tracepoint()`
2219 macro, which you <<probing-the-application-source-code,insert in a user
2220 application's source code>>, calls those functions.
2222 A _tracepoint provider package_ is an object file (`.o`) or a shared
2223 library (`.so`) which contains one or more tracepoint providers.
2224 Its source files are:
2226 * One or more <<tpp-header,tracepoint provider header>> (`.h`).
2227 * A <<tpp-source,tracepoint provider package source>> (`.c`).
2229 A tracepoint provider package is dynamically linked with `liblttng-ust`,
2230 the LTTng user space tracer, at run time.
2233 .User application linked with `liblttng-ust` and containing a tracepoint provider.
2234 image::ust-app.png[]
2236 NOTE: If you need quick, man:printf(3)-like instrumentation, you can
2237 skip creating and using a tracepoint provider and use
2238 <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>> instead.
2242 ===== Create a tracepoint provider header file template
2244 A _tracepoint provider header file_ contains the tracepoint
2245 definitions of a tracepoint provider.
2247 To create a tracepoint provider header file:
2249 . Start from this template:
2253 .Tracepoint provider header file template (`.h` file extension).
2255 #undef TRACEPOINT_PROVIDER
2256 #define TRACEPOINT_PROVIDER provider_name
2258 #undef TRACEPOINT_INCLUDE
2259 #define TRACEPOINT_INCLUDE "./tp.h"
2261 #if !defined(_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
2264 #include <lttng/tracepoint.h>
2267 * Use TRACEPOINT_EVENT(), TRACEPOINT_EVENT_CLASS(),
2268 * TRACEPOINT_EVENT_INSTANCE(), and TRACEPOINT_LOGLEVEL() here.
2273 #include <lttng/tracepoint-event.h>
2279 * `provider_name` with the name of your tracepoint provider.
2280 * `"tp.h"` with the name of your tracepoint provider header file.
2282 . Below the `#include <lttng/tracepoint.h>` line, put your
2283 <<defining-tracepoints,tracepoint definitions>>.
2285 Your tracepoint provider name must be unique amongst all the possible
2286 tracepoint provider names used on the same target system. We
2287 suggest to include the name of your project or company in the name,
2288 for example, `org_lttng_my_project_tpp`.
2290 TIP: [[lttng-gen-tp]]You can use the man:lttng-gen-tp(1) tool to create
2291 this boilerplate for you. When using cmd:lttng-gen-tp, all you need to
2292 write are the <<defining-tracepoints,tracepoint definitions>>.
2295 [[defining-tracepoints]]
2296 ===== Create a tracepoint definition
2298 A _tracepoint definition_ defines, for a given tracepoint:
2300 * Its **input arguments**. They are the macro parameters that the
2301 `tracepoint()` macro accepts for this particular tracepoint
2302 in the user application's source code.
2303 * Its **output event fields**. They are the sources of event fields
2304 that form the payload of any event that the execution of the
2305 `tracepoint()` macro emits for this particular tracepoint.
2307 You can create a tracepoint definition by using the
2308 `TRACEPOINT_EVENT()` macro below the `#include <lttng/tracepoint.h>`
2310 <<tpp-header,tracepoint provider header file template>>.
2312 The syntax of the `TRACEPOINT_EVENT()` macro is:
2315 .`TRACEPOINT_EVENT()` macro syntax.
2318 /* Tracepoint provider name */
2321 /* Tracepoint name */
2324 /* Input arguments */
2329 /* Output event fields */
2338 * `provider_name` with your tracepoint provider name.
2339 * `tracepoint_name` with your tracepoint name.
2340 * `arguments` with the <<tpp-def-input-args,input arguments>>.
2341 * `fields` with the <<tpp-def-output-fields,output event field>>
2344 This tracepoint emits events named `provider_name:tracepoint_name`.
2347 .Event name's length limitation
2349 The concatenation of the tracepoint provider name and the
2350 tracepoint name must not exceed **254 characters**. If it does, the
2351 instrumented application compiles and runs, but LTTng throws multiple
2352 warnings and you could experience serious issues.
2355 [[tpp-def-input-args]]The syntax of the `TP_ARGS()` macro is:
2358 .`TP_ARGS()` macro syntax.
2367 * `type` with the C type of the argument.
2368 * `arg_name` with the argument name.
2370 You can repeat `type` and `arg_name` up to 10 times to have
2371 more than one argument.
2373 .`TP_ARGS()` usage with three arguments.
2385 The `TP_ARGS()` and `TP_ARGS(void)` forms are valid to create a
2386 tracepoint definition with no input arguments.
2388 [[tpp-def-output-fields]]The `TP_FIELDS()` macro contains a list of
2389 `ctf_*()` macros. Each `ctf_*()` macro defines one event field. See
2390 man:lttng-ust(3) for a complete description of the available `ctf_*()`
2391 macros. A `ctf_*()` macro specifies the type, size, and byte order of
2394 Each `ctf_*()` macro takes an _argument expression_ parameter. This is a
2395 C expression that the tracer evalutes at the `tracepoint()` macro site
2396 in the application's source code. This expression provides a field's
2397 source of data. The argument expression can include input argument names
2398 listed in the `TP_ARGS()` macro.
2400 Each `ctf_*()` macro also takes a _field name_ parameter. Field names
2401 must be unique within a given tracepoint definition.
2403 Here's a complete tracepoint definition example:
2405 .Tracepoint definition.
2407 The following tracepoint definition defines a tracepoint which takes
2408 three input arguments and has four output event fields.
2412 #include "my-custom-structure.h"
2418 const struct my_custom_structure*, my_custom_structure,
2423 ctf_string(query_field, query)
2424 ctf_float(double, ratio_field, ratio)
2425 ctf_integer(int, recv_size, my_custom_structure->recv_size)
2426 ctf_integer(int, send_size, my_custom_structure->send_size)
2431 You can refer to this tracepoint definition with the `tracepoint()`
2432 macro in your application's source code like this:
2436 tracepoint(my_provider, my_tracepoint,
2437 my_structure, some_ratio, the_query);
2441 NOTE: The LTTng tracer only evaluates tracepoint arguments at run time
2442 if they satisfy an enabled <<event,event rule>>.
2445 [[using-tracepoint-classes]]
2446 ===== Use a tracepoint class
2448 A _tracepoint class_ is a class of tracepoints which share the same
2449 output event field definitions. A _tracepoint instance_ is one
2450 instance of such a defined tracepoint class, with its own tracepoint
2453 The <<defining-tracepoints,`TRACEPOINT_EVENT()` macro>> is actually a
2454 shorthand which defines both a tracepoint class and a tracepoint
2455 instance at the same time.
2457 When you build a tracepoint provider package, the C or $$C++$$ compiler
2458 creates one serialization function for each **tracepoint class**. A
2459 serialization function is responsible for serializing the event fields
2460 of a tracepoint to a sub-buffer when tracing.
2462 For various performance reasons, when your situation requires multiple
2463 tracepoint definitions with different names, but with the same event
2464 fields, we recommend that you manually create a tracepoint class
2465 and instantiate as many tracepoint instances as needed. One positive
2466 effect of such a design, amongst other advantages, is that all
2467 tracepoint instances of the same tracepoint class reuse the same
2468 serialization function, thus reducing
2469 https://en.wikipedia.org/wiki/Cache_pollution[cache pollution].
2471 .Use a tracepoint class and tracepoint instances.
2473 Consider the following three tracepoint definitions:
2485 ctf_integer(int, userid, userid)
2486 ctf_integer(size_t, len, len)
2498 ctf_integer(int, userid, userid)
2499 ctf_integer(size_t, len, len)
2511 ctf_integer(int, userid, userid)
2512 ctf_integer(size_t, len, len)
2517 In this case, we create three tracepoint classes, with one implicit
2518 tracepoint instance for each of them: `get_account`, `get_settings`, and
2519 `get_transaction`. However, they all share the same event field names
2520 and types. Hence three identical, yet independent serialization
2521 functions are created when you build the tracepoint provider package.
2523 A better design choice is to define a single tracepoint class and three
2524 tracepoint instances:
2528 /* The tracepoint class */
2529 TRACEPOINT_EVENT_CLASS(
2530 /* Tracepoint provider name */
2533 /* Tracepoint class name */
2536 /* Input arguments */
2542 /* Output event fields */
2544 ctf_integer(int, userid, userid)
2545 ctf_integer(size_t, len, len)
2549 /* The tracepoint instances */
2550 TRACEPOINT_EVENT_INSTANCE(
2551 /* Tracepoint provider name */
2554 /* Tracepoint class name */
2557 /* Tracepoint name */
2560 /* Input arguments */
2566 TRACEPOINT_EVENT_INSTANCE(
2575 TRACEPOINT_EVENT_INSTANCE(
2588 [[assigning-log-levels]]
2589 ===== Assign a log level to a tracepoint definition
2591 You can assign an optional _log level_ to a
2592 <<defining-tracepoints,tracepoint definition>>.
2594 Assigning different levels of severity to tracepoint definitions can
2595 be useful: when you <<enabling-disabling-events,create an event rule>>,
2596 you can target tracepoints having a log level as severe as a specific
2599 The concept of LTTng-UST log levels is similar to the levels found
2600 in typical logging frameworks:
2602 * In a logging framework, the log level is given by the function
2603 or method name you use at the log statement site: `debug()`,
2604 `info()`, `warn()`, `error()`, and so on.
2605 * In LTTng-UST, you statically assign the log level to a tracepoint
2606 definition; any `tracepoint()` macro invocation which refers to
2607 this definition has this log level.
2609 You can assign a log level to a tracepoint definition with the
2610 `TRACEPOINT_LOGLEVEL()` macro. You must use this macro _after_ the
2611 <<defining-tracepoints,`TRACEPOINT_EVENT()`>> or
2612 <<using-tracepoint-classes,`TRACEPOINT_INSTANCE()`>> macro for a given
2615 The syntax of the `TRACEPOINT_LOGLEVEL()` macro is:
2618 .`TRACEPOINT_LOGLEVEL()` macro syntax.
2620 TRACEPOINT_LOGLEVEL(provider_name, tracepoint_name, log_level)
2625 * `provider_name` with the tracepoint provider name.
2626 * `tracepoint_name` with the tracepoint name.
2627 * `log_level` with the log level to assign to the tracepoint
2628 definition named `tracepoint_name` in the `provider_name`
2629 tracepoint provider.
2631 See man:lttng-ust(3) for a list of available log level names.
2633 .Assign the `TRACE_DEBUG_UNIT` log level to a tracepoint definition.
2637 /* Tracepoint definition */
2646 ctf_integer(int, userid, userid)
2647 ctf_integer(size_t, len, len)
2651 /* Log level assignment */
2652 TRACEPOINT_LOGLEVEL(my_app, get_transaction, TRACE_DEBUG_UNIT)
2658 ===== Create a tracepoint provider package source file
2660 A _tracepoint provider package source file_ is a C source file which
2661 includes a <<tpp-header,tracepoint provider header file>> to expand its
2662 macros into event serialization and other functions.
2664 You can always use the following tracepoint provider package source
2668 .Tracepoint provider package source file template.
2670 #define TRACEPOINT_CREATE_PROBES
2675 Replace `tp.h` with the name of your <<tpp-header,tracepoint provider
2676 header file>> name. You may also include more than one tracepoint
2677 provider header file here to create a tracepoint provider package
2678 holding more than one tracepoint providers.
2681 [[probing-the-application-source-code]]
2682 ==== Add tracepoints to an application's source code
2684 Once you <<tpp-header,create a tracepoint provider header file>>, you
2685 can use the `tracepoint()` macro in your application's
2686 source code to insert the tracepoints that this header
2687 <<defining-tracepoints,defines>>.
2689 The `tracepoint()` macro takes at least two parameters: the tracepoint
2690 provider name and the tracepoint name. The corresponding tracepoint
2691 definition defines the other parameters.
2693 .`tracepoint()` usage.
2695 The following <<defining-tracepoints,tracepoint definition>> defines a
2696 tracepoint which takes two input arguments and has two output event
2700 .Tracepoint provider header file.
2702 #include "my-custom-structure.h"
2709 const char*, cmd_name
2712 ctf_string(cmd_name, cmd_name)
2713 ctf_integer(int, number_of_args, argc)
2718 You can refer to this tracepoint definition with the `tracepoint()`
2719 macro in your application's source code like this:
2722 .Application's source file.
2726 int main(int argc, char* argv[])
2728 tracepoint(my_provider, my_tracepoint, argc, argv[0]);
2734 Note how the application's source code includes
2735 the tracepoint provider header file containing the tracepoint
2736 definitions to use, path:{tp.h}.
2739 .`tracepoint()` usage with a complex tracepoint definition.
2741 Consider this complex tracepoint definition, where multiple event
2742 fields refer to the same input arguments in their argument expression
2746 .Tracepoint provider header file.
2748 /* For `struct stat` */
2749 #include <sys/types.h>
2750 #include <sys/stat.h>
2762 ctf_integer(int, my_constant_field, 23 + 17)
2763 ctf_integer(int, my_int_arg_field, my_int_arg)
2764 ctf_integer(int, my_int_arg_field2, my_int_arg * my_int_arg)
2765 ctf_integer(int, sum4_field, my_str_arg[0] + my_str_arg[1] +
2766 my_str_arg[2] + my_str_arg[3])
2767 ctf_string(my_str_arg_field, my_str_arg)
2768 ctf_integer_hex(off_t, size_field, st->st_size)
2769 ctf_float(double, size_dbl_field, (double) st->st_size)
2770 ctf_sequence_text(char, half_my_str_arg_field, my_str_arg,
2771 size_t, strlen(my_str_arg) / 2)
2776 You can refer to this tracepoint definition with the `tracepoint()`
2777 macro in your application's source code like this:
2780 .Application's source file.
2782 #define TRACEPOINT_DEFINE
2789 stat("/etc/fstab", &s);
2790 tracepoint(my_provider, my_tracepoint, 23, "Hello, World!", &s);
2796 If you look at the event record that LTTng writes when tracing this
2797 program, assuming the file size of path:{/etc/fstab} is 301{nbsp}bytes,
2798 it should look like this:
2800 .Event record fields
2802 |Field's name |Field's value
2803 |`my_constant_field` |40
2804 |`my_int_arg_field` |23
2805 |`my_int_arg_field2` |529
2807 |`my_str_arg_field` |`Hello, World!`
2808 |`size_field` |0x12d
2809 |`size_dbl_field` |301.0
2810 |`half_my_str_arg_field` |`Hello,`
2814 Sometimes, the arguments you pass to `tracepoint()` are expensive to
2815 compute--they use the call stack, for example. To avoid this
2816 computation when the tracepoint is disabled, you can use the
2817 `tracepoint_enabled()` and `do_tracepoint()` macros.
2819 The syntax of the `tracepoint_enabled()` and `do_tracepoint()` macros
2823 .`tracepoint_enabled()` and `do_tracepoint()` macros syntax.
2825 tracepoint_enabled(provider_name, tracepoint_name)
2826 do_tracepoint(provider_name, tracepoint_name, ...)
2831 * `provider_name` with the tracepoint provider name.
2832 * `tracepoint_name` with the tracepoint name.
2834 `tracepoint_enabled()` returns a non-zero value if the tracepoint named
2835 `tracepoint_name` from the provider named `provider_name` is enabled
2838 `do_tracepoint()` is like `tracepoint()`, except that it doesn't check
2839 if the tracepoint is enabled. Using `tracepoint()` with
2840 `tracepoint_enabled()` is dangerous since `tracepoint()` also contains
2841 the `tracepoint_enabled()` check, thus a race condition is
2842 possible in this situation:
2845 .Possible race condition when using `tracepoint_enabled()` with `tracepoint()`.
2847 if (tracepoint_enabled(my_provider, my_tracepoint)) {
2848 stuff = prepare_stuff();
2851 tracepoint(my_provider, my_tracepoint, stuff);
2854 If the tracepoint is enabled after the condition, then `stuff` is not
2855 prepared: the emitted event will either contain wrong data, or the whole
2856 application could crash (segmentation fault, for example).
2858 NOTE: Neither `tracepoint_enabled()` nor `do_tracepoint()` have an
2859 `STAP_PROBEV()` call. If you need it, you must emit
2863 [[building-tracepoint-providers-and-user-application]]
2864 ==== Build and link a tracepoint provider package and an application
2866 Once you have one or more <<tpp-header,tracepoint provider header
2867 files>> and a <<tpp-source,tracepoint provider package source file>>,
2868 you can create the tracepoint provider package by compiling its source
2869 file. From here, multiple build and run scenarios are possible. The
2870 following table shows common application and library configurations
2871 along with the required command lines to achieve them.
2873 In the following diagrams, we use the following file names:
2876 Executable application.
2879 Application's object file.
2882 Tracepoint provider package object file.
2885 Tracepoint provider package archive file.
2888 Tracepoint provider package shared object file.
2891 User library object file.
2894 User library shared object file.
2896 We use the following symbols in the diagrams of table below:
2899 .Symbols used in the build scenario diagrams.
2900 image::ust-sit-symbols.png[]
2902 We assume that path:{.} is part of the env:LD_LIBRARY_PATH environment
2903 variable in the following instructions.
2905 [role="growable ust-scenarios",cols="asciidoc,asciidoc"]
2906 .Common tracepoint provider package scenarios.
2908 |Scenario |Instructions
2911 The instrumented application is statically linked with
2912 the tracepoint provider package object.
2914 image::ust-sit+app-linked-with-tp-o+app-instrumented.png[]
2917 include::../common/ust-sit-step-tp-o.txt[]
2919 To build the instrumented application:
2921 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2926 #define TRACEPOINT_DEFINE
2930 . Compile the application source file:
2939 . Build the application:
2944 $ gcc -o app app.o tpp.o -llttng-ust -ldl
2948 To run the instrumented application:
2950 * Start the application:
2960 The instrumented application is statically linked with the
2961 tracepoint provider package archive file.
2963 image::ust-sit+app-linked-with-tp-a+app-instrumented.png[]
2966 To create the tracepoint provider package archive file:
2968 . Compile the <<tpp-source,tracepoint provider package source file>>:
2977 . Create the tracepoint provider package archive file:
2982 $ ar rcs tpp.a tpp.o
2986 To build the instrumented application:
2988 . In path:{app.c}, before including path:{tpp.h}, add the following line:
2993 #define TRACEPOINT_DEFINE
2997 . Compile the application source file:
3006 . Build the application:
3011 $ gcc -o app app.o tpp.a -llttng-ust -ldl
3015 To run the instrumented application:
3017 * Start the application:
3027 The instrumented application is linked with the tracepoint provider
3028 package shared object.
3030 image::ust-sit+app-linked-with-tp-so+app-instrumented.png[]
3033 include::../common/ust-sit-step-tp-so.txt[]
3035 To build the instrumented application:
3037 . In path:{app.c}, before including path:{tpp.h}, add the following line:
3042 #define TRACEPOINT_DEFINE
3046 . Compile the application source file:
3055 . Build the application:
3060 $ gcc -o app app.o -ldl -L. -ltpp
3064 To run the instrumented application:
3066 * Start the application:
3076 The tracepoint provider package shared object is preloaded before the
3077 instrumented application starts.
3079 image::ust-sit+tp-so-preloaded+app-instrumented.png[]
3082 include::../common/ust-sit-step-tp-so.txt[]
3084 To build the instrumented application:
3086 . In path:{app.c}, before including path:{tpp.h}, add the
3092 #define TRACEPOINT_DEFINE
3093 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3097 . Compile the application source file:
3106 . Build the application:
3111 $ gcc -o app app.o -ldl
3115 To run the instrumented application with tracing support:
3117 * Preload the tracepoint provider package shared object and
3118 start the application:
3123 $ LD_PRELOAD=./libtpp.so ./app
3127 To run the instrumented application without tracing support:
3129 * Start the application:
3139 The instrumented application dynamically loads the tracepoint provider
3140 package shared object.
3142 See the <<dlclose-warning,warning about `dlclose()`>>.
3144 image::ust-sit+app-dlopens-tp-so+app-instrumented.png[]
3147 include::../common/ust-sit-step-tp-so.txt[]
3149 To build the instrumented application:
3151 . In path:{app.c}, before including path:{tpp.h}, add the
3157 #define TRACEPOINT_DEFINE
3158 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3162 . Compile the application source file:
3171 . Build the application:
3176 $ gcc -o app app.o -ldl
3180 To run the instrumented application:
3182 * Start the application:
3192 The application is linked with the instrumented user library.
3194 The instrumented user library is statically linked with the tracepoint
3195 provider package object file.
3197 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-o+lib-instrumented.png[]
3200 include::../common/ust-sit-step-tp-o-fpic.txt[]
3202 To build the instrumented user library:
3204 . In path:{emon.c}, before including path:{tpp.h}, add the
3210 #define TRACEPOINT_DEFINE
3214 . Compile the user library source file:
3219 $ gcc -I. -fpic -c emon.c
3223 . Build the user library shared object:
3228 $ gcc -shared -o libemon.so emon.o tpp.o -llttng-ust -ldl
3232 To build the application:
3234 . Compile the application source file:
3243 . Build the application:
3248 $ gcc -o app app.o -L. -lemon
3252 To run the application:
3254 * Start the application:
3264 The application is linked with the instrumented user library.
3266 The instrumented user library is linked with the tracepoint provider
3267 package shared object.
3269 image::ust-sit+app-linked-with-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3272 include::../common/ust-sit-step-tp-so.txt[]
3274 To build the instrumented user library:
3276 . In path:{emon.c}, before including path:{tpp.h}, add the
3282 #define TRACEPOINT_DEFINE
3286 . Compile the user library source file:
3291 $ gcc -I. -fpic -c emon.c
3295 . Build the user library shared object:
3300 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3304 To build the application:
3306 . Compile the application source file:
3315 . Build the application:
3320 $ gcc -o app app.o -L. -lemon
3324 To run the application:
3326 * Start the application:
3336 The tracepoint provider package shared object is preloaded before the
3339 The application is linked with the instrumented user library.
3341 image::ust-sit+tp-so-preloaded+app-linked-with-lib+lib-instrumented.png[]
3344 include::../common/ust-sit-step-tp-so.txt[]
3346 To build the instrumented user library:
3348 . In path:{emon.c}, before including path:{tpp.h}, add the
3354 #define TRACEPOINT_DEFINE
3355 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3359 . Compile the user library source file:
3364 $ gcc -I. -fpic -c emon.c
3368 . Build the user library shared object:
3373 $ gcc -shared -o libemon.so emon.o -ldl
3377 To build the application:
3379 . Compile the application source file:
3388 . Build the application:
3393 $ gcc -o app app.o -L. -lemon
3397 To run the application with tracing support:
3399 * Preload the tracepoint provider package shared object and
3400 start the application:
3405 $ LD_PRELOAD=./libtpp.so ./app
3409 To run the application without tracing support:
3411 * Start the application:
3421 The application is linked with the instrumented user library.
3423 The instrumented user library dynamically loads the tracepoint provider
3424 package shared object.
3426 See the <<dlclose-warning,warning about `dlclose()`>>.
3428 image::ust-sit+app-linked-with-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3431 include::../common/ust-sit-step-tp-so.txt[]
3433 To build the instrumented user library:
3435 . In path:{emon.c}, before including path:{tpp.h}, add the
3441 #define TRACEPOINT_DEFINE
3442 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3446 . Compile the user library source file:
3451 $ gcc -I. -fpic -c emon.c
3455 . Build the user library shared object:
3460 $ gcc -shared -o libemon.so emon.o -ldl
3464 To build the application:
3466 . Compile the application source file:
3475 . Build the application:
3480 $ gcc -o app app.o -L. -lemon
3484 To run the application:
3486 * Start the application:
3496 The application dynamically loads the instrumented user library.
3498 The instrumented user library is linked with the tracepoint provider
3499 package shared object.
3501 See the <<dlclose-warning,warning about `dlclose()`>>.
3503 image::ust-sit+app-dlopens-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3506 include::../common/ust-sit-step-tp-so.txt[]
3508 To build the instrumented user library:
3510 . In path:{emon.c}, before including path:{tpp.h}, add the
3516 #define TRACEPOINT_DEFINE
3520 . Compile the user library source file:
3525 $ gcc -I. -fpic -c emon.c
3529 . Build the user library shared object:
3534 $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3538 To build the application:
3540 . Compile the application source file:
3549 . Build the application:
3554 $ gcc -o app app.o -ldl -L. -lemon
3558 To run the application:
3560 * Start the application:
3570 The application dynamically loads the instrumented user library.
3572 The instrumented user library dynamically loads the tracepoint provider
3573 package shared object.
3575 See the <<dlclose-warning,warning about `dlclose()`>>.
3577 image::ust-sit+app-dlopens-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3580 include::../common/ust-sit-step-tp-so.txt[]
3582 To build the instrumented user library:
3584 . In path:{emon.c}, before including path:{tpp.h}, add the
3590 #define TRACEPOINT_DEFINE
3591 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3595 . Compile the user library source file:
3600 $ gcc -I. -fpic -c emon.c
3604 . Build the user library shared object:
3609 $ gcc -shared -o libemon.so emon.o -ldl
3613 To build the application:
3615 . Compile the application source file:
3624 . Build the application:
3629 $ gcc -o app app.o -ldl -L. -lemon
3633 To run the application:
3635 * Start the application:
3645 The tracepoint provider package shared object is preloaded before the
3648 The application dynamically loads the instrumented user library.
3650 image::ust-sit+tp-so-preloaded+app-dlopens-lib+lib-instrumented.png[]
3653 include::../common/ust-sit-step-tp-so.txt[]
3655 To build the instrumented user library:
3657 . In path:{emon.c}, before including path:{tpp.h}, add the
3663 #define TRACEPOINT_DEFINE
3664 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3668 . Compile the user library source file:
3673 $ gcc -I. -fpic -c emon.c
3677 . Build the user library shared object:
3682 $ gcc -shared -o libemon.so emon.o -ldl
3686 To build the application:
3688 . Compile the application source file:
3697 . Build the application:
3702 $ gcc -o app app.o -L. -lemon
3706 To run the application with tracing support:
3708 * Preload the tracepoint provider package shared object and
3709 start the application:
3714 $ LD_PRELOAD=./libtpp.so ./app
3718 To run the application without tracing support:
3720 * Start the application:
3730 The application is statically linked with the tracepoint provider
3731 package object file.
3733 The application is linked with the instrumented user library.
3735 image::ust-sit+app-linked-with-tp-o+app-linked-with-lib+lib-instrumented.png[]
3738 include::../common/ust-sit-step-tp-o.txt[]
3740 To build the instrumented user library:
3742 . In path:{emon.c}, before including path:{tpp.h}, add the
3748 #define TRACEPOINT_DEFINE
3752 . Compile the user library source file:
3757 $ gcc -I. -fpic -c emon.c
3761 . Build the user library shared object:
3766 $ gcc -shared -o libemon.so emon.o
3770 To build the application:
3772 . Compile the application source file:
3781 . Build the application:
3786 $ gcc -o app app.o tpp.o -llttng-ust -ldl -L. -lemon
3790 To run the instrumented application:
3792 * Start the application:
3802 The application is statically linked with the tracepoint provider
3803 package object file.
3805 The application dynamically loads the instrumented user library.
3807 image::ust-sit+app-linked-with-tp-o+app-dlopens-lib+lib-instrumented.png[]
3810 include::../common/ust-sit-step-tp-o.txt[]
3812 To build the application:
3814 . In path:{app.c}, before including path:{tpp.h}, add the following line:
3819 #define TRACEPOINT_DEFINE
3823 . Compile the application source file:
3832 . Build the application:
3837 $ gcc -Wl,--export-dynamic -o app app.o tpp.o \
3842 The `--export-dynamic` option passed to the linker is necessary for the
3843 dynamically loaded library to ``see'' the tracepoint symbols defined in
3846 To build the instrumented user library:
3848 . Compile the user library source file:
3853 $ gcc -I. -fpic -c emon.c
3857 . Build the user library shared object:
3862 $ gcc -shared -o libemon.so emon.o
3866 To run the application:
3868 * Start the application:
3880 .Do not use man:dlclose(3) on a tracepoint provider package
3882 Never use man:dlclose(3) on any shared object which:
3884 * Is linked with, statically or dynamically, a tracepoint provider
3886 * Calls man:dlopen(3) itself to dynamically open a tracepoint provider
3887 package shared object.
3889 This is currently considered **unsafe** due to a lack of reference
3890 counting from LTTng-UST to the shared object.
3892 A known workaround (available since glibc 2.2) is to use the
3893 `RTLD_NODELETE` flag when calling man:dlopen(3) initially. This has the
3894 effect of not unloading the loaded shared object, even if man:dlclose(3)
3897 You can also preload the tracepoint provider package shared object with
3898 the env:LD_PRELOAD environment variable to overcome this limitation.
3902 [[using-lttng-ust-with-daemons]]
3903 ===== Use noch:{LTTng-UST} with daemons
3905 If your instrumented application calls man:fork(2), man:clone(2),
3906 or BSD's man:rfork(2), without a following man:exec(3)-family
3907 system call, you must preload the path:{liblttng-ust-fork.so} shared
3908 object when you start the application.
3912 $ LD_PRELOAD=liblttng-ust-fork.so ./my-app
3915 If your tracepoint provider package is
3916 a shared library which you also preload, you must put both
3917 shared objects in env:LD_PRELOAD:
3921 $ LD_PRELOAD=liblttng-ust-fork.so:/path/to/tp.so ./my-app
3927 ===== Use noch:{LTTng-UST} with applications which close file descriptors that don't belong to them
3929 If your instrumented application closes one or more file descriptors
3930 which it did not open itself, you must preload the
3931 path:{liblttng-ust-fd.so} shared object when you start the application:
3935 $ LD_PRELOAD=liblttng-ust-fd.so ./my-app
3938 Typical use cases include closing all the file descriptors after
3939 man:fork(2) or man:rfork(2) and buggy applications doing
3943 [[lttng-ust-pkg-config]]
3944 ===== Use noch:{pkg-config}
3946 On some distributions, LTTng-UST ships with a
3947 https://www.freedesktop.org/wiki/Software/pkg-config/[pkg-config]
3948 metadata file. If this is your case, then you can use cmd:pkg-config to
3949 build an application on the command line:
3953 $ gcc -o my-app my-app.o tp.o $(pkg-config --cflags --libs lttng-ust)
3957 [[instrumenting-32-bit-app-on-64-bit-system]]
3958 ===== [[advanced-instrumenting-techniques]]Build a 32-bit instrumented application for a 64-bit target system
3960 In order to trace a 32-bit application running on a 64-bit system,
3961 LTTng must use a dedicated 32-bit
3962 <<lttng-consumerd,consumer daemon>>.
3964 The following steps show how to build and install a 32-bit consumer
3965 daemon, which is _not_ part of the default 64-bit LTTng build, how to
3966 build and install the 32-bit LTTng-UST libraries, and how to build and
3967 link an instrumented 32-bit application in that context.
3969 To build a 32-bit instrumented application for a 64-bit target system,
3970 assuming you have a fresh target system with no installed Userspace RCU
3973 . Download, build, and install a 32-bit version of Userspace RCU:
3978 $ cd $(mktemp -d) &&
3979 wget http://lttng.org/files/urcu/userspace-rcu-latest-0.9.tar.bz2 &&
3980 tar -xf userspace-rcu-latest-0.9.tar.bz2 &&
3981 cd userspace-rcu-0.9.* &&
3982 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 &&
3984 sudo make install &&
3989 . Using your distribution's package manager, or from source, install
3990 the following 32-bit versions of the following dependencies of
3991 LTTng-tools and LTTng-UST:
3994 * https://sourceforge.net/projects/libuuid/[libuuid]
3995 * http://directory.fsf.org/wiki/Popt[popt]
3996 * http://www.xmlsoft.org/[libxml2]
3999 . Download, build, and install a 32-bit version of the latest
4000 LTTng-UST{nbsp}{revision}:
4005 $ cd $(mktemp -d) &&
4006 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.10.tar.bz2 &&
4007 tar -xf lttng-ust-latest-2.10.tar.bz2 &&
4008 cd lttng-ust-2.10.* &&
4009 ./configure --libdir=/usr/local/lib32 \
4010 CFLAGS=-m32 CXXFLAGS=-m32 \
4011 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' &&
4013 sudo make install &&
4020 Depending on your distribution,
4021 32-bit libraries could be installed at a different location than
4022 `/usr/lib32`. For example, Debian is known to install
4023 some 32-bit libraries in `/usr/lib/i386-linux-gnu`.
4025 In this case, make sure to set `LDFLAGS` to all the
4026 relevant 32-bit library paths, for example:
4030 $ LDFLAGS='-L/usr/lib/i386-linux-gnu -L/usr/lib32'
4034 . Download the latest LTTng-tools{nbsp}{revision}, build, and install
4035 the 32-bit consumer daemon:
4040 $ cd $(mktemp -d) &&
4041 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.10.tar.bz2 &&
4042 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
4043 cd lttng-tools-2.10.* &&
4044 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 CXXFLAGS=-m32 \
4045 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' \
4046 --disable-bin-lttng --disable-bin-lttng-crash \
4047 --disable-bin-lttng-relayd --disable-bin-lttng-sessiond &&
4049 cd src/bin/lttng-consumerd &&
4050 sudo make install &&
4055 . From your distribution or from source,
4056 <<installing-lttng,install>> the 64-bit versions of
4057 LTTng-UST and Userspace RCU.
4058 . Download, build, and install the 64-bit version of the
4059 latest LTTng-tools{nbsp}{revision}:
4064 $ cd $(mktemp -d) &&
4065 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.10.tar.bz2 &&
4066 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
4067 cd lttng-tools-2.10.* &&
4068 ./configure --with-consumerd32-libdir=/usr/local/lib32 \
4069 --with-consumerd32-bin=/usr/local/lib32/lttng/libexec/lttng-consumerd &&
4071 sudo make install &&
4076 . Pass the following options to man:gcc(1), man:g++(1), or man:clang(1)
4077 when linking your 32-bit application:
4080 -m32 -L/usr/lib32 -L/usr/local/lib32 \
4081 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32
4084 For example, let's rebuild the quick start example in
4085 <<tracing-your-own-user-application,Trace a user application>> as an
4086 instrumented 32-bit application:
4091 $ gcc -m32 -c -I. hello-tp.c
4092 $ gcc -m32 -c hello.c
4093 $ gcc -m32 -o hello hello.o hello-tp.o \
4094 -L/usr/lib32 -L/usr/local/lib32 \
4095 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32 \
4100 No special action is required to execute the 32-bit application and
4101 to trace it: use the command-line man:lttng(1) tool as usual.
4108 man:tracef(3) is a small LTTng-UST API designed for quick,
4109 man:printf(3)-like instrumentation without the burden of
4110 <<tracepoint-provider,creating>> and
4111 <<building-tracepoint-providers-and-user-application,building>>
4112 a tracepoint provider package.
4114 To use `tracef()` in your application:
4116 . In the C or C++ source files where you need to use `tracef()`,
4117 include `<lttng/tracef.h>`:
4122 #include <lttng/tracef.h>
4126 . In the application's source code, use `tracef()` like you would use
4134 tracef("my message: %d (%s)", my_integer, my_string);
4140 . Link your application with `liblttng-ust`:
4145 $ gcc -o app app.c -llttng-ust
4149 To trace the events that `tracef()` calls emit:
4151 * <<enabling-disabling-events,Create an event rule>> which matches the
4152 `lttng_ust_tracef:*` event name:
4157 $ lttng enable-event --userspace 'lttng_ust_tracef:*'
4162 .Limitations of `tracef()`
4164 The `tracef()` utility function was developed to make user space tracing
4165 super simple, albeit with notable disadvantages compared to
4166 <<defining-tracepoints,user-defined tracepoints>>:
4168 * All the emitted events have the same tracepoint provider and
4169 tracepoint names, respectively `lttng_ust_tracef` and `event`.
4170 * There is no static type checking.
4171 * The only event record field you actually get, named `msg`, is a string
4172 potentially containing the values you passed to `tracef()`
4173 using your own format string. This also means that you cannot filter
4174 events with a custom expression at run time because there are no
4176 * Since `tracef()` uses the C standard library's man:vasprintf(3)
4177 function behind the scenes to format the strings at run time, its
4178 expected performance is lower than with user-defined tracepoints,
4179 which do not require a conversion to a string.
4181 Taking this into consideration, `tracef()` is useful for some quick
4182 prototyping and debugging, but you should not consider it for any
4183 permanent and serious applicative instrumentation.
4189 ==== Use `tracelog()`
4191 The man:tracelog(3) API is very similar to <<tracef,`tracef()`>>, with
4192 the difference that it accepts an additional log level parameter.
4194 The goal of `tracelog()` is to ease the migration from logging to
4197 To use `tracelog()` in your application:
4199 . In the C or C++ source files where you need to use `tracelog()`,
4200 include `<lttng/tracelog.h>`:
4205 #include <lttng/tracelog.h>
4209 . In the application's source code, use `tracelog()` like you would use
4210 man:printf(3), except for the first parameter which is the log
4218 tracelog(TRACE_WARNING, "my message: %d (%s)",
4219 my_integer, my_string);
4225 See man:lttng-ust(3) for a list of available log level names.
4227 . Link your application with `liblttng-ust`:
4232 $ gcc -o app app.c -llttng-ust
4236 To trace the events that `tracelog()` calls emit with a log level
4237 _as severe as_ a specific log level:
4239 * <<enabling-disabling-events,Create an event rule>> which matches the
4240 `lttng_ust_tracelog:*` event name and a minimum level
4246 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
4247 --loglevel=TRACE_WARNING
4251 To trace the events that `tracelog()` calls emit with a
4252 _specific log level_:
4254 * Create an event rule which matches the `lttng_ust_tracelog:*`
4255 event name and a specific log level:
4260 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
4261 --loglevel-only=TRACE_INFO
4266 [[prebuilt-ust-helpers]]
4267 === Prebuilt user space tracing helpers
4269 The LTTng-UST package provides a few helpers in the form or preloadable
4270 shared objects which automatically instrument system functions and
4273 The helper shared objects are normally found in dir:{/usr/lib}. If you
4274 built LTTng-UST <<building-from-source,from source>>, they are probably
4275 located in dir:{/usr/local/lib}.
4277 The installed user space tracing helpers in LTTng-UST{nbsp}{revision}
4280 path:{liblttng-ust-libc-wrapper.so}::
4281 path:{liblttng-ust-pthread-wrapper.so}::
4282 <<liblttng-ust-libc-pthread-wrapper,C{nbsp}standard library
4283 memory and POSIX threads function tracing>>.
4285 path:{liblttng-ust-cyg-profile.so}::
4286 path:{liblttng-ust-cyg-profile-fast.so}::
4287 <<liblttng-ust-cyg-profile,Function entry and exit tracing>>.
4289 path:{liblttng-ust-dl.so}::
4290 <<liblttng-ust-dl,Dynamic linker tracing>>.
4292 To use a user space tracing helper with any user application:
4294 * Preload the helper shared object when you start the application:
4299 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so my-app
4303 You can preload more than one helper:
4308 $ LD_PRELOAD=liblttng-ust-libc-wrapper.so:liblttng-ust-dl.so my-app
4314 [[liblttng-ust-libc-pthread-wrapper]]
4315 ==== Instrument C standard library memory and POSIX threads functions
4317 The path:{liblttng-ust-libc-wrapper.so} and
4318 path:{liblttng-ust-pthread-wrapper.so} helpers
4319 add instrumentation to some C standard library and POSIX
4323 .Functions instrumented by preloading path:{liblttng-ust-libc-wrapper.so}.
4325 |TP provider name |TP name |Instrumented function
4327 .6+|`lttng_ust_libc` |`malloc` |man:malloc(3)
4328 |`calloc` |man:calloc(3)
4329 |`realloc` |man:realloc(3)
4330 |`free` |man:free(3)
4331 |`memalign` |man:memalign(3)
4332 |`posix_memalign` |man:posix_memalign(3)
4336 .Functions instrumented by preloading path:{liblttng-ust-pthread-wrapper.so}.
4338 |TP provider name |TP name |Instrumented function
4340 .4+|`lttng_ust_pthread` |`pthread_mutex_lock_req` |man:pthread_mutex_lock(3p) (request time)
4341 |`pthread_mutex_lock_acq` |man:pthread_mutex_lock(3p) (acquire time)
4342 |`pthread_mutex_trylock` |man:pthread_mutex_trylock(3p)
4343 |`pthread_mutex_unlock` |man:pthread_mutex_unlock(3p)
4346 When you preload the shared object, it replaces the functions listed
4347 in the previous tables by wrappers which contain tracepoints and call
4348 the replaced functions.
4351 [[liblttng-ust-cyg-profile]]
4352 ==== Instrument function entry and exit
4354 The path:{liblttng-ust-cyg-profile*.so} helpers can add instrumentation
4355 to the entry and exit points of functions.
4357 man:gcc(1) and man:clang(1) have an option named
4358 https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html[`-finstrument-functions`]
4359 which generates instrumentation calls for entry and exit to functions.
4360 The LTTng-UST function tracing helpers,
4361 path:{liblttng-ust-cyg-profile.so} and
4362 path:{liblttng-ust-cyg-profile-fast.so}, take advantage of this feature
4363 to add tracepoints to the two generated functions (which contain
4364 `cyg_profile` in their names, hence the helper's name).
4366 To use the LTTng-UST function tracing helper, the source files to
4367 instrument must be built using the `-finstrument-functions` compiler
4370 There are two versions of the LTTng-UST function tracing helper:
4372 * **path:{liblttng-ust-cyg-profile-fast.so}** is a lightweight variant
4373 that you should only use when it can be _guaranteed_ that the
4374 complete event stream is recorded without any lost event record.
4375 Any kind of duplicate information is left out.
4377 Assuming no event record is lost, having only the function addresses on
4378 entry is enough to create a call graph, since an event record always
4379 contains the ID of the CPU that generated it.
4381 You can use a tool like man:addr2line(1) to convert function addresses
4382 back to source file names and line numbers.
4384 * **path:{liblttng-ust-cyg-profile.so}** is a more robust variant
4385 which also works in use cases where event records might get discarded or
4386 not recorded from application startup.
4387 In these cases, the trace analyzer needs more information to be
4388 able to reconstruct the program flow.
4390 See man:lttng-ust-cyg-profile(3) to learn more about the instrumentation
4391 points of this helper.
4393 All the tracepoints that this helper provides have the
4394 log level `TRACE_DEBUG_FUNCTION` (see man:lttng-ust(3)).
4396 TIP: It's sometimes a good idea to limit the number of source files that
4397 you compile with the `-finstrument-functions` option to prevent LTTng
4398 from writing an excessive amount of trace data at run time. When using
4399 man:gcc(1), you can use the
4400 `-finstrument-functions-exclude-function-list` option to avoid
4401 instrument entries and exits of specific function names.
4406 ==== Instrument the dynamic linker
4408 The path:{liblttng-ust-dl.so} helper adds instrumentation to the
4409 man:dlopen(3) and man:dlclose(3) function calls.
4411 See man:lttng-ust-dl(3) to learn more about the instrumentation points
4416 [[java-application]]
4417 === User space Java agent
4419 You can instrument any Java application which uses one of the following
4422 * The https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[**`java.util.logging`**]
4423 (JUL) core logging facilities.
4424 * http://logging.apache.org/log4j/1.2/[**Apache log4j 1.2**], since
4425 LTTng 2.6. Note that Apache Log4j{nbsp}2 is not supported.
4428 .LTTng-UST Java agent imported by a Java application.
4429 image::java-app.png[]
4431 Note that the methods described below are new in LTTng{nbsp}{revision}.
4432 Previous LTTng versions use another technique.
4434 NOTE: We use http://openjdk.java.net/[OpenJDK]{nbsp}8 for development
4435 and https://ci.lttng.org/[continuous integration], thus this version is
4436 directly supported. However, the LTTng-UST Java agent is also tested
4437 with OpenJDK{nbsp}7.
4442 ==== Use the LTTng-UST Java agent for `java.util.logging`
4444 To use the LTTng-UST Java agent in a Java application which uses
4445 `java.util.logging` (JUL):
4447 . In the Java application's source code, import the LTTng-UST
4448 log handler package for `java.util.logging`:
4453 import org.lttng.ust.agent.jul.LttngLogHandler;
4457 . Create an LTTng-UST JUL log handler:
4462 Handler lttngUstLogHandler = new LttngLogHandler();
4466 . Add this handler to the JUL loggers which should emit LTTng events:
4471 Logger myLogger = Logger.getLogger("some-logger");
4473 myLogger.addHandler(lttngUstLogHandler);
4477 . Use `java.util.logging` log statements and configuration as usual.
4478 The loggers with an attached LTTng-UST log handler can emit
4481 . Before exiting the application, remove the LTTng-UST log handler from
4482 the loggers attached to it and call its `close()` method:
4487 myLogger.removeHandler(lttngUstLogHandler);
4488 lttngUstLogHandler.close();
4492 This is not strictly necessary, but it is recommended for a clean
4493 disposal of the handler's resources.
4495 . Include the LTTng-UST Java agent's common and JUL-specific JAR files,
4496 path:{lttng-ust-agent-common.jar} and path:{lttng-ust-agent-jul.jar},
4498 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4499 path] when you build the Java application.
4501 The JAR files are typically located in dir:{/usr/share/java}.
4503 IMPORTANT: The LTTng-UST Java agent must be
4504 <<installing-lttng,installed>> for the logging framework your
4507 .Use the LTTng-UST Java agent for `java.util.logging`.
4512 import java.io.IOException;
4513 import java.util.logging.Handler;
4514 import java.util.logging.Logger;
4515 import org.lttng.ust.agent.jul.LttngLogHandler;
4519 private static final int answer = 42;
4521 public static void main(String[] argv) throws Exception
4524 Logger logger = Logger.getLogger("jello");
4526 // Create an LTTng-UST log handler
4527 Handler lttngUstLogHandler = new LttngLogHandler();
4529 // Add the LTTng-UST log handler to our logger
4530 logger.addHandler(lttngUstLogHandler);
4533 logger.info("some info");
4534 logger.warning("some warning");
4536 logger.finer("finer information; the answer is " + answer);
4538 logger.severe("error!");
4540 // Not mandatory, but cleaner
4541 logger.removeHandler(lttngUstLogHandler);
4542 lttngUstLogHandler.close();
4551 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4554 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4555 <<enabling-disabling-events,create an event rule>> matching the
4556 `jello` JUL logger, and <<basic-tracing-session-control,start tracing>>:
4561 $ lttng enable-event --jul jello
4565 Run the compiled class:
4569 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4572 <<basic-tracing-session-control,Stop tracing>> and inspect the
4582 In the resulting trace, an <<event,event record>> generated by a Java
4583 application using `java.util.logging` is named `lttng_jul:event` and
4584 has the following fields:
4587 Log record's message.
4593 Name of the class in which the log statement was executed.
4596 Name of the method in which the log statement was executed.
4599 Logging time (timestamp in milliseconds).
4602 Log level integer value.
4605 ID of the thread in which the log statement was executed.
4607 You can use the opt:lttng-enable-event(1):--loglevel or
4608 opt:lttng-enable-event(1):--loglevel-only option of the
4609 man:lttng-enable-event(1) command to target a range of JUL log levels
4610 or a specific JUL log level.
4615 ==== Use the LTTng-UST Java agent for Apache log4j
4617 To use the LTTng-UST Java agent in a Java application which uses
4620 . In the Java application's source code, import the LTTng-UST
4621 log appender package for Apache log4j:
4626 import org.lttng.ust.agent.log4j.LttngLogAppender;
4630 . Create an LTTng-UST log4j log appender:
4635 Appender lttngUstLogAppender = new LttngLogAppender();
4639 . Add this appender to the log4j loggers which should emit LTTng events:
4644 Logger myLogger = Logger.getLogger("some-logger");
4646 myLogger.addAppender(lttngUstLogAppender);
4650 . Use Apache log4j log statements and configuration as usual. The
4651 loggers with an attached LTTng-UST log appender can emit LTTng events.
4653 . Before exiting the application, remove the LTTng-UST log appender from
4654 the loggers attached to it and call its `close()` method:
4659 myLogger.removeAppender(lttngUstLogAppender);
4660 lttngUstLogAppender.close();
4664 This is not strictly necessary, but it is recommended for a clean
4665 disposal of the appender's resources.
4667 . Include the LTTng-UST Java agent's common and log4j-specific JAR
4668 files, path:{lttng-ust-agent-common.jar} and
4669 path:{lttng-ust-agent-log4j.jar}, in the
4670 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4671 path] when you build the Java application.
4673 The JAR files are typically located in dir:{/usr/share/java}.
4675 IMPORTANT: The LTTng-UST Java agent must be
4676 <<installing-lttng,installed>> for the logging framework your
4679 .Use the LTTng-UST Java agent for Apache log4j.
4684 import org.apache.log4j.Appender;
4685 import org.apache.log4j.Logger;
4686 import org.lttng.ust.agent.log4j.LttngLogAppender;
4690 private static final int answer = 42;
4692 public static void main(String[] argv) throws Exception
4695 Logger logger = Logger.getLogger("jello");
4697 // Create an LTTng-UST log appender
4698 Appender lttngUstLogAppender = new LttngLogAppender();
4700 // Add the LTTng-UST log appender to our logger
4701 logger.addAppender(lttngUstLogAppender);
4704 logger.info("some info");
4705 logger.warn("some warning");
4707 logger.debug("debug information; the answer is " + answer);
4709 logger.fatal("error!");
4711 // Not mandatory, but cleaner
4712 logger.removeAppender(lttngUstLogAppender);
4713 lttngUstLogAppender.close();
4719 Build this example (`$LOG4JPATH` is the path to the Apache log4j JAR
4724 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH Test.java
4727 <<creating-destroying-tracing-sessions,Create a tracing session>>,
4728 <<enabling-disabling-events,create an event rule>> matching the
4729 `jello` log4j logger, and <<basic-tracing-session-control,start tracing>>:
4734 $ lttng enable-event --log4j jello
4738 Run the compiled class:
4742 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH:. Test
4745 <<basic-tracing-session-control,Stop tracing>> and inspect the
4755 In the resulting trace, an <<event,event record>> generated by a Java
4756 application using log4j is named `lttng_log4j:event` and
4757 has the following fields:
4760 Log record's message.
4766 Name of the class in which the log statement was executed.
4769 Name of the method in which the log statement was executed.
4772 Name of the file in which the executed log statement is located.
4775 Line number at which the log statement was executed.
4781 Log level integer value.
4784 Name of the Java thread in which the log statement was executed.
4786 You can use the opt:lttng-enable-event(1):--loglevel or
4787 opt:lttng-enable-event(1):--loglevel-only option of the
4788 man:lttng-enable-event(1) command to target a range of Apache log4j log levels
4789 or a specific log4j log level.
4793 [[java-application-context]]
4794 ==== Provide application-specific context fields in a Java application
4796 A Java application-specific context field is a piece of state provided
4797 by the application which <<adding-context,you can add>>, using the
4798 man:lttng-add-context(1) command, to each <<event,event record>>
4799 produced by the log statements of this application.
4801 For example, a given object might have a current request ID variable.
4802 You can create a context information retriever for this object and
4803 assign a name to this current request ID. You can then, using the
4804 man:lttng-add-context(1) command, add this context field by name to
4805 the JUL or log4j <<channel,channel>>.
4807 To provide application-specific context fields in a Java application:
4809 . In the Java application's source code, import the LTTng-UST
4810 Java agent context classes and interfaces:
4815 import org.lttng.ust.agent.context.ContextInfoManager;
4816 import org.lttng.ust.agent.context.IContextInfoRetriever;
4820 . Create a context information retriever class, that is, a class which
4821 implements the `IContextInfoRetriever` interface:
4826 class MyContextInfoRetriever implements IContextInfoRetriever
4829 public Object retrieveContextInfo(String key)
4831 if (key.equals("intCtx")) {
4833 } else if (key.equals("strContext")) {
4834 return "context value!";
4843 This `retrieveContextInfo()` method is the only member of the
4844 `IContextInfoRetriever` interface. Its role is to return the current
4845 value of a state by name to create a context field. The names of the
4846 context fields and which state variables they return depends on your
4849 All primitive types and objects are supported as context fields.
4850 When `retrieveContextInfo()` returns an object, the context field
4851 serializer calls its `toString()` method to add a string field to
4852 event records. The method can also return `null`, which means that
4853 no context field is available for the required name.
4855 . Register an instance of your context information retriever class to
4856 the context information manager singleton:
4861 IContextInfoRetriever cir = new MyContextInfoRetriever();
4862 ContextInfoManager cim = ContextInfoManager.getInstance();
4863 cim.registerContextInfoRetriever("retrieverName", cir);
4867 . Before exiting the application, remove your context information
4868 retriever from the context information manager singleton:
4873 ContextInfoManager cim = ContextInfoManager.getInstance();
4874 cim.unregisterContextInfoRetriever("retrieverName");
4878 This is not strictly necessary, but it is recommended for a clean
4879 disposal of some manager's resources.
4881 . Build your Java application with LTTng-UST Java agent support as
4882 usual, following the procedure for either the <<jul,JUL>> or
4883 <<log4j,Apache log4j>> framework.
4886 .Provide application-specific context fields in a Java application.
4891 import java.util.logging.Handler;
4892 import java.util.logging.Logger;
4893 import org.lttng.ust.agent.jul.LttngLogHandler;
4894 import org.lttng.ust.agent.context.ContextInfoManager;
4895 import org.lttng.ust.agent.context.IContextInfoRetriever;
4899 // Our context information retriever class
4900 private static class MyContextInfoRetriever
4901 implements IContextInfoRetriever
4904 public Object retrieveContextInfo(String key) {
4905 if (key.equals("intCtx")) {
4907 } else if (key.equals("strContext")) {
4908 return "context value!";
4915 private static final int answer = 42;
4917 public static void main(String args[]) throws Exception
4919 // Get the context information manager instance
4920 ContextInfoManager cim = ContextInfoManager.getInstance();
4922 // Create and register our context information retriever
4923 IContextInfoRetriever cir = new MyContextInfoRetriever();
4924 cim.registerContextInfoRetriever("myRetriever", cir);
4927 Logger logger = Logger.getLogger("jello");
4929 // Create an LTTng-UST log handler
4930 Handler lttngUstLogHandler = new LttngLogHandler();
4932 // Add the LTTng-UST log handler to our logger
4933 logger.addHandler(lttngUstLogHandler);
4936 logger.info("some info");
4937 logger.warning("some warning");
4939 logger.finer("finer information; the answer is " + answer);
4941 logger.severe("error!");
4943 // Not mandatory, but cleaner
4944 logger.removeHandler(lttngUstLogHandler);
4945 lttngUstLogHandler.close();
4946 cim.unregisterContextInfoRetriever("myRetriever");
4955 $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4958 <<creating-destroying-tracing-sessions,Create a tracing session>>
4959 and <<enabling-disabling-events,create an event rule>> matching the
4965 $ lttng enable-event --jul jello
4968 <<adding-context,Add the application-specific context fields>> to the
4973 $ lttng add-context --jul --type='$app.myRetriever:intCtx'
4974 $ lttng add-context --jul --type='$app.myRetriever:strContext'
4977 <<basic-tracing-session-control,Start tracing>>:
4984 Run the compiled class:
4988 $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4991 <<basic-tracing-session-control,Stop tracing>> and inspect the
5003 [[python-application]]
5004 === User space Python agent
5006 You can instrument a Python 2 or Python 3 application which uses the
5007 standard https://docs.python.org/3/library/logging.html[`logging`]
5010 Each log statement emits an LTTng event once the
5011 application module imports the
5012 <<lttng-ust-agents,LTTng-UST Python agent>> package.
5015 .A Python application importing the LTTng-UST Python agent.
5016 image::python-app.png[]
5018 To use the LTTng-UST Python agent:
5020 . In the Python application's source code, import the LTTng-UST Python
5030 The LTTng-UST Python agent automatically adds its logging handler to the
5031 root logger at import time.
5033 Any log statement that the application executes before this import does
5034 not emit an LTTng event.
5036 IMPORTANT: The LTTng-UST Python agent must be
5037 <<installing-lttng,installed>>.
5039 . Use log statements and logging configuration as usual.
5040 Since the LTTng-UST Python agent adds a handler to the _root_
5041 logger, you can trace any log statement from any logger.
5043 .Use the LTTng-UST Python agent.
5054 logging.basicConfig()
5055 logger = logging.getLogger('my-logger')
5058 logger.debug('debug message')
5059 logger.info('info message')
5060 logger.warn('warn message')
5061 logger.error('error message')
5062 logger.critical('critical message')
5066 if __name__ == '__main__':
5070 NOTE: `logging.basicConfig()`, which adds to the root logger a basic
5071 logging handler which prints to the standard error stream, is not
5072 strictly required for LTTng-UST tracing to work, but in versions of
5073 Python preceding 3.2, you could see a warning message which indicates
5074 that no handler exists for the logger `my-logger`.
5076 <<creating-destroying-tracing-sessions,Create a tracing session>>,
5077 <<enabling-disabling-events,create an event rule>> matching the
5078 `my-logger` Python logger, and <<basic-tracing-session-control,start
5084 $ lttng enable-event --python my-logger
5088 Run the Python script:
5095 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
5105 In the resulting trace, an <<event,event record>> generated by a Python
5106 application is named `lttng_python:event` and has the following fields:
5109 Logging time (string).
5112 Log record's message.
5118 Name of the function in which the log statement was executed.
5121 Line number at which the log statement was executed.
5124 Log level integer value.
5127 ID of the Python thread in which the log statement was executed.
5130 Name of the Python thread in which the log statement was executed.
5132 You can use the opt:lttng-enable-event(1):--loglevel or
5133 opt:lttng-enable-event(1):--loglevel-only option of the
5134 man:lttng-enable-event(1) command to target a range of Python log levels
5135 or a specific Python log level.
5137 When an application imports the LTTng-UST Python agent, the agent tries
5138 to register to a <<lttng-sessiond,session daemon>>. Note that you must
5139 <<start-sessiond,start the session daemon>> _before_ you run the Python
5140 application. If a session daemon is found, the agent tries to register
5141 to it during 5{nbsp}seconds, after which the application continues
5142 without LTTng tracing support. You can override this timeout value with
5143 the env:LTTNG_UST_PYTHON_REGISTER_TIMEOUT environment variable
5146 If the session daemon stops while a Python application with an imported
5147 LTTng-UST Python agent runs, the agent retries to connect and to
5148 register to a session daemon every 3{nbsp}seconds. You can override this
5149 delay with the env:LTTNG_UST_PYTHON_REGISTER_RETRY_DELAY environment
5154 [[proc-lttng-logger-abi]]
5157 The `lttng-tracer` Linux kernel module, part of
5158 <<lttng-modules,LTTng-modules>>, creates the special LTTng logger file
5159 path:{/proc/lttng-logger} when it's loaded. Any application can write
5160 text data to this file to emit an LTTng event.
5163 .An application writes to the LTTng logger file to emit an LTTng event.
5164 image::lttng-logger.png[]
5166 The LTTng logger is the quickest method--not the most efficient,
5167 however--to add instrumentation to an application. It is designed
5168 mostly to instrument shell scripts:
5172 $ echo "Some message, some $variable" > /proc/lttng-logger
5175 Any event that the LTTng logger emits is named `lttng_logger` and
5176 belongs to the Linux kernel <<domain,tracing domain>>. However, unlike
5177 other instrumentation points in the kernel tracing domain, **any Unix
5178 user** can <<enabling-disabling-events,create an event rule>> which
5179 matches its event name, not only the root user or users in the
5180 <<tracing-group,tracing group>>.
5182 To use the LTTng logger:
5184 * From any application, write text data to the path:{/proc/lttng-logger}
5187 The `msg` field of `lttng_logger` event records contains the
5190 NOTE: The maximum message length of an LTTng logger event is
5191 1024{nbsp}bytes. Writing more than this makes the LTTng logger emit more
5192 than one event to contain the remaining data.
5194 You should not use the LTTng logger to trace a user application which
5195 can be instrumented in a more efficient way, namely:
5197 * <<c-application,C and $$C++$$ applications>>.
5198 * <<java-application,Java applications>>.
5199 * <<python-application,Python applications>>.
5201 .Use the LTTng logger.
5206 echo 'Hello, World!' > /proc/lttng-logger
5208 df --human-readable --print-type / > /proc/lttng-logger
5211 <<creating-destroying-tracing-sessions,Create a tracing session>>,
5212 <<enabling-disabling-events,create an event rule>> matching the
5213 `lttng_logger` Linux kernel tracepoint, and
5214 <<basic-tracing-session-control,start tracing>>:
5219 $ lttng enable-event --kernel lttng_logger
5223 Run the Bash script:
5230 <<basic-tracing-session-control,Stop tracing>> and inspect the recorded
5241 [[instrumenting-linux-kernel]]
5242 === LTTng kernel tracepoints
5244 NOTE: This section shows how to _add_ instrumentation points to the
5245 Linux kernel. The kernel's subsystems are already thoroughly
5246 instrumented at strategic places for LTTng when you
5247 <<installing-lttng,install>> the <<lttng-modules,LTTng-modules>>
5251 There are two methods to instrument the Linux kernel:
5253 . <<linux-add-lttng-layer,Add an LTTng layer>> over an existing ftrace
5254 tracepoint which uses the `TRACE_EVENT()` API.
5256 Choose this if you want to instrumentation a Linux kernel tree with an
5257 instrumentation point compatible with ftrace, perf, and SystemTap.
5259 . Use an <<linux-lttng-tracepoint-event,LTTng-only approach>> to
5260 instrument an out-of-tree kernel module.
5262 Choose this if you don't need ftrace, perf, or SystemTap support.
5266 [[linux-add-lttng-layer]]
5267 ==== [[instrumenting-linux-kernel-itself]][[mainline-trace-event]][[lttng-adaptation-layer]]Add an LTTng layer to an existing ftrace tracepoint
5269 This section shows how to add an LTTng layer to existing ftrace
5270 instrumentation using the `TRACE_EVENT()` API.
5272 This section does not document the `TRACE_EVENT()` macro. You can
5273 read the following articles to learn more about this API:
5275 * http://lwn.net/Articles/379903/[Using the TRACE_EVENT() macro (Part 1)]
5276 * http://lwn.net/Articles/381064/[Using the TRACE_EVENT() macro (Part 2)]
5277 * http://lwn.net/Articles/383362/[Using the TRACE_EVENT() macro (Part 3)]
5279 The following procedure assumes that your ftrace tracepoints are
5280 correctly defined in their own header and that they are created in
5281 one source file using the `CREATE_TRACE_POINTS` definition.
5283 To add an LTTng layer over an existing ftrace tracepoint:
5285 . Make sure the following kernel configuration options are
5291 * `CONFIG_HIGH_RES_TIMERS`
5292 * `CONFIG_TRACEPOINTS`
5295 . Build the Linux source tree with your custom ftrace tracepoints.
5296 . Boot the resulting Linux image on your target system.
5298 Confirm that the tracepoints exist by looking for their names in the
5299 dir:{/sys/kernel/debug/tracing/events/subsys} directory, where `subsys`
5300 is your subsystem's name.
5302 . Get a copy of the latest LTTng-modules{nbsp}{revision}:
5307 $ cd $(mktemp -d) &&
5308 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
5309 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
5310 cd lttng-modules-2.10.*
5314 . In dir:{instrumentation/events/lttng-module}, relative to the root
5315 of the LTTng-modules source tree, create a header file named
5316 +__subsys__.h+ for your custom subsystem +__subsys__+ and write your
5317 LTTng-modules tracepoint definitions using the LTTng-modules
5320 Start with this template:
5324 .path:{instrumentation/events/lttng-module/my_subsys.h}
5327 #define TRACE_SYSTEM my_subsys
5329 #if !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ)
5330 #define _LTTNG_MY_SUBSYS_H
5332 #include "../../../probes/lttng-tracepoint-event.h"
5333 #include <linux/tracepoint.h>
5335 LTTNG_TRACEPOINT_EVENT(
5337 * Format is identical to TRACE_EVENT()'s version for the three
5338 * following macro parameters:
5341 TP_PROTO(int my_int, const char *my_string),
5342 TP_ARGS(my_int, my_string),
5344 /* LTTng-modules specific macros */
5346 ctf_integer(int, my_int_field, my_int)
5347 ctf_string(my_bar_field, my_bar)
5351 #endif /* !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ) */
5353 #include "../../../probes/define_trace.h"
5357 The entries in the `TP_FIELDS()` section are the list of fields for the
5358 LTTng tracepoint. This is similar to the `TP_STRUCT__entry()` part of
5359 ftrace's `TRACE_EVENT()` macro.
5361 See <<lttng-modules-tp-fields,Tracepoint fields macros>> for a
5362 complete description of the available `ctf_*()` macros.
5364 . Create the LTTng-modules probe's kernel module C source file,
5365 +probes/lttng-probe-__subsys__.c+, where +__subsys__+ is your
5370 .path:{probes/lttng-probe-my-subsys.c}
5372 #include <linux/module.h>
5373 #include "../lttng-tracer.h"
5376 * Build-time verification of mismatch between mainline
5377 * TRACE_EVENT() arguments and the LTTng-modules adaptation
5378 * layer LTTNG_TRACEPOINT_EVENT() arguments.
5380 #include <trace/events/my_subsys.h>
5382 /* Create LTTng tracepoint probes */
5383 #define LTTNG_PACKAGE_BUILD
5384 #define CREATE_TRACE_POINTS
5385 #define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
5387 #include "../instrumentation/events/lttng-module/my_subsys.h"
5389 MODULE_LICENSE("GPL and additional rights");
5390 MODULE_AUTHOR("Your name <your-email>");
5391 MODULE_DESCRIPTION("LTTng my_subsys probes");
5392 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
5393 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
5394 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
5395 LTTNG_MODULES_EXTRAVERSION);
5399 . Edit path:{probes/KBuild} and add your new kernel module object
5400 next to the existing ones:
5404 .path:{probes/KBuild}
5408 obj-m += lttng-probe-module.o
5409 obj-m += lttng-probe-power.o
5411 obj-m += lttng-probe-my-subsys.o
5417 . Build and install the LTTng kernel modules:
5422 $ make KERNELDIR=/path/to/linux
5423 # make modules_install && depmod -a
5427 Replace `/path/to/linux` with the path to the Linux source tree where
5428 you defined and used tracepoints with ftrace's `TRACE_EVENT()` macro.
5430 Note that you can also use the
5431 <<lttng-tracepoint-event-code,`LTTNG_TRACEPOINT_EVENT_CODE()` macro>>
5432 instead of `LTTNG_TRACEPOINT_EVENT()` to use custom local variables and
5433 C code that need to be executed before the event fields are recorded.
5435 The best way to learn how to use the previous LTTng-modules macros is to
5436 inspect the existing LTTng-modules tracepoint definitions in the
5437 dir:{instrumentation/events/lttng-module} header files. Compare them
5438 with the Linux kernel mainline versions in the
5439 dir:{include/trace/events} directory of the Linux source tree.
5443 [[lttng-tracepoint-event-code]]
5444 ===== Use custom C code to access the data for tracepoint fields
5446 Although we recommended to always use the
5447 <<lttng-adaptation-layer,`LTTNG_TRACEPOINT_EVENT()`>> macro to describe
5448 the arguments and fields of an LTTng-modules tracepoint when possible,
5449 sometimes you need a more complex process to access the data that the
5450 tracer records as event record fields. In other words, you need local
5451 variables and multiple C{nbsp}statements instead of simple
5452 argument-based expressions that you pass to the
5453 <<lttng-modules-tp-fields,`ctf_*()` macros of `TP_FIELDS()`>>.
5455 You can use the `LTTNG_TRACEPOINT_EVENT_CODE()` macro instead of
5456 `LTTNG_TRACEPOINT_EVENT()` to declare custom local variables and define
5457 a block of C{nbsp}code to be executed before LTTng records the fields.
5458 The structure of this macro is:
5461 .`LTTNG_TRACEPOINT_EVENT_CODE()` macro syntax.
5463 LTTNG_TRACEPOINT_EVENT_CODE(
5465 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5466 * version for the following three macro parameters:
5469 TP_PROTO(int my_int, const char *my_string),
5470 TP_ARGS(my_int, my_string),
5472 /* Declarations of custom local variables */
5475 unsigned long b = 0;
5476 const char *name = "(undefined)";
5477 struct my_struct *my_struct;
5481 * Custom code which uses both tracepoint arguments
5482 * (in TP_ARGS()) and local variables (in TP_locvar()).
5484 * Local variables are actually members of a structure pointed
5485 * to by the special variable tp_locvar.
5489 tp_locvar->a = my_int + 17;
5490 tp_locvar->my_struct = get_my_struct_at(tp_locvar->a);
5491 tp_locvar->b = my_struct_compute_b(tp_locvar->my_struct);
5492 tp_locvar->name = my_struct_get_name(tp_locvar->my_struct);
5493 put_my_struct(tp_locvar->my_struct);
5502 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5503 * version for this, except that tp_locvar members can be
5504 * used in the argument expression parameters of
5505 * the ctf_*() macros.
5508 ctf_integer(unsigned long, my_struct_b, tp_locvar->b)
5509 ctf_integer(int, my_struct_a, tp_locvar->a)
5510 ctf_string(my_string_field, my_string)
5511 ctf_string(my_struct_name, tp_locvar->name)
5516 IMPORTANT: The C code defined in `TP_code()` must not have any side
5517 effects when executed. In particular, the code must not allocate
5518 memory or get resources without deallocating this memory or putting
5519 those resources afterwards.
5522 [[instrumenting-linux-kernel-tracing]]
5523 ==== Load and unload a custom probe kernel module
5525 You must load a <<lttng-adaptation-layer,created LTTng-modules probe
5526 kernel module>> in the kernel before it can emit LTTng events.
5528 To load the default probe kernel modules and a custom probe kernel
5531 * Use the opt:lttng-sessiond(8):--extra-kmod-probes option to give extra
5532 probe modules to load when starting a root <<lttng-sessiond,session
5536 .Load the `my_subsys`, `usb`, and the default probe modules.
5540 # lttng-sessiond --extra-kmod-probes=my_subsys,usb
5545 You only need to pass the subsystem name, not the whole kernel module
5548 To load _only_ a given custom probe kernel module:
5550 * Use the opt:lttng-sessiond(8):--kmod-probes option to give the probe
5551 modules to load when starting a root session daemon:
5554 .Load only the `my_subsys` and `usb` probe modules.
5558 # lttng-sessiond --kmod-probes=my_subsys,usb
5563 To confirm that a probe module is loaded:
5570 $ lsmod | grep lttng_probe_usb
5574 To unload the loaded probe modules:
5576 * Kill the session daemon with `SIGTERM`:
5581 # pkill lttng-sessiond
5585 You can also use man:modprobe(8)'s `--remove` option if the session
5586 daemon terminates abnormally.
5589 [[controlling-tracing]]
5592 Once an application or a Linux kernel is
5593 <<instrumenting,instrumented>> for LTTng tracing,
5596 This section is divided in topics on how to use the various
5597 <<plumbing,components of LTTng>>, in particular the <<lttng-cli,cmd:lttng
5598 command-line tool>>, to _control_ the LTTng daemons and tracers.
5600 NOTE: In the following subsections, we refer to an man:lttng(1) command
5601 using its man page name. For example, instead of _Run the `create`
5602 command to..._, we use _Run the man:lttng-create(1) command to..._.
5606 === Start a session daemon
5608 In some situations, you need to run a <<lttng-sessiond,session daemon>>
5609 (man:lttng-sessiond(8)) _before_ you can use the man:lttng(1)
5612 You will see the following error when you run a command while no session
5616 Error: No session daemon is available
5619 The only command that automatically runs a session daemon is
5620 man:lttng-create(1), which you use to
5621 <<creating-destroying-tracing-sessions,create a tracing session>>. While
5622 this is most of the time the first operation that you do, sometimes it's
5623 not. Some examples are:
5625 * <<list-instrumentation-points,List the available instrumentation points>>.
5626 * <<saving-loading-tracing-session,Load a tracing session configuration>>.
5628 [[tracing-group]] Each Unix user must have its own running session
5629 daemon to trace user applications. The session daemon that the root user
5630 starts is the only one allowed to control the LTTng kernel tracer. Users
5631 that are part of the _tracing group_ can control the root session
5632 daemon. The default tracing group name is `tracing`; you can set it to
5633 something else with the opt:lttng-sessiond(8):--group option when you
5634 start the root session daemon.
5636 To start a user session daemon:
5638 * Run man:lttng-sessiond(8):
5643 $ lttng-sessiond --daemonize
5647 To start the root session daemon:
5649 * Run man:lttng-sessiond(8) as the root user:
5654 # lttng-sessiond --daemonize
5658 In both cases, remove the opt:lttng-sessiond(8):--daemonize option to
5659 start the session daemon in foreground.
5661 To stop a session daemon, use man:kill(1) on its process ID (standard
5664 Note that some Linux distributions could manage the LTTng session daemon
5665 as a service. In this case, you should use the service manager to
5666 start, restart, and stop session daemons.
5669 [[creating-destroying-tracing-sessions]]
5670 === Create and destroy a tracing session
5672 Almost all the LTTng control operations happen in the scope of
5673 a <<tracing-session,tracing session>>, which is the dialogue between the
5674 <<lttng-sessiond,session daemon>> and you.
5676 To create a tracing session with a generated name:
5678 * Use the man:lttng-create(1) command:
5687 The created tracing session's name is `auto` followed by the
5690 To create a tracing session with a specific name:
5692 * Use the optional argument of the man:lttng-create(1) command:
5697 $ lttng create my-session
5701 Replace `my-session` with the specific tracing session name.
5703 LTTng appends the creation date to the created tracing session's name.
5705 LTTng writes the traces of a tracing session in
5706 +$LTTNG_HOME/lttng-trace/__name__+ by default, where +__name__+ is the
5707 name of the tracing session. Note that the env:LTTNG_HOME environment
5708 variable defaults to `$HOME` if not set.
5710 To output LTTng traces to a non-default location:
5712 * Use the opt:lttng-create(1):--output option of the man:lttng-create(1) command:
5717 $ lttng create my-session --output=/tmp/some-directory
5721 You may create as many tracing sessions as you wish.
5723 To list all the existing tracing sessions for your Unix user:
5725 * Use the man:lttng-list(1) command:
5734 When you create a tracing session, it is set as the _current tracing
5735 session_. The following man:lttng(1) commands operate on the current
5736 tracing session when you don't specify one:
5738 [role="list-3-cols"]
5755 To change the current tracing session:
5757 * Use the man:lttng-set-session(1) command:
5762 $ lttng set-session new-session
5766 Replace `new-session` by the name of the new current tracing session.
5768 When you are done tracing in a given tracing session, you can destroy
5769 it. This operation frees the resources taken by the tracing session
5770 to destroy; it does not destroy the trace data that LTTng wrote for
5771 this tracing session.
5773 To destroy the current tracing session:
5775 * Use the man:lttng-destroy(1) command:
5784 The man:lttng-destroy(1) command also runs the man:lttng-stop(1)
5785 command implicitly (see <<basic-tracing-session-control,Start and stop a
5786 tracing session>>). You need to stop tracing to make LTTng flush the
5787 remaining trace data and make the trace readable.
5790 [[list-instrumentation-points]]
5791 === List the available instrumentation points
5793 The <<lttng-sessiond,session daemon>> can query the running instrumented
5794 user applications and the Linux kernel to get a list of available
5795 instrumentation points. For the Linux kernel <<domain,tracing domain>>,
5796 they are tracepoints and system calls. For the user space tracing
5797 domain, they are tracepoints. For the other tracing domains, they are
5800 To list the available instrumentation points:
5802 * Use the man:lttng-list(1) command with the requested tracing domain's
5806 * opt:lttng-list(1):--kernel: Linux kernel tracepoints (your Unix user
5807 must be a root user, or it must be a member of the
5808 <<tracing-group,tracing group>>).
5809 * opt:lttng-list(1):--kernel with opt:lttng-list(1):--syscall: Linux
5810 kernel system calls (your Unix user must be a root user, or it must be
5811 a member of the tracing group).
5812 * opt:lttng-list(1):--userspace: user space tracepoints.
5813 * opt:lttng-list(1):--jul: `java.util.logging` loggers.
5814 * opt:lttng-list(1):--log4j: Apache log4j loggers.
5815 * opt:lttng-list(1):--python: Python loggers.
5818 .List the available user space tracepoints.
5822 $ lttng list --userspace
5826 .List the available Linux kernel system call tracepoints.
5830 $ lttng list --kernel --syscall
5835 [[enabling-disabling-events]]
5836 === Create and enable an event rule
5838 Once you <<creating-destroying-tracing-sessions,create a tracing
5839 session>>, you can create <<event,event rules>> with the
5840 man:lttng-enable-event(1) command.
5842 You specify each condition with a command-line option. The available
5843 condition options are shown in the following table.
5845 [role="growable",cols="asciidoc,asciidoc,default"]
5846 .Condition command-line options for the man:lttng-enable-event(1) command.
5848 |Option |Description |Applicable tracing domains
5854 . +--probe=__ADDR__+
5855 . +--function=__ADDR__+
5858 Instead of using the default _tracepoint_ instrumentation type, use:
5860 . A Linux system call.
5861 . A Linux https://lwn.net/Articles/132196/[KProbe] (symbol or address).
5862 . The entry and return points of a Linux function (symbol or address).
5866 |First positional argument.
5869 Tracepoint or system call name. In the case of a Linux KProbe or
5870 function, this is a custom name given to the event rule. With the
5871 JUL, log4j, and Python domains, this is a logger name.
5873 With a tracepoint, logger, or system call name, you can use the special
5874 `*` globbing character to match anything (for example, `sched_*`,
5882 . +--loglevel=__LEVEL__+
5883 . +--loglevel-only=__LEVEL__+
5886 . Match only tracepoints or log statements with a logging level at
5887 least as severe as +__LEVEL__+.
5888 . Match only tracepoints or log statements with a logging level
5889 equal to +__LEVEL__+.
5891 See man:lttng-enable-event(1) for the list of available logging level
5894 |User space, JUL, log4j, and Python.
5896 |+--exclude=__EXCLUSIONS__+
5899 When you use a `*` character at the end of the tracepoint or logger
5900 name (first positional argument), exclude the specific names in the
5901 comma-delimited list +__EXCLUSIONS__+.
5904 User space, JUL, log4j, and Python.
5906 |+--filter=__EXPR__+
5909 Match only events which satisfy the expression +__EXPR__+.
5911 See man:lttng-enable-event(1) to learn more about the syntax of a
5918 You attach an event rule to a <<channel,channel>> on creation. If you do
5919 not specify the channel with the opt:lttng-enable-event(1):--channel
5920 option, and if the event rule to create is the first in its
5921 <<domain,tracing domain>> for a given tracing session, then LTTng
5922 creates a _default channel_ for you. This default channel is reused in
5923 subsequent invocations of the man:lttng-enable-event(1) command for the
5924 same tracing domain.
5926 An event rule is always enabled at creation time.
5928 The following examples show how you can combine the previous
5929 command-line options to create simple to more complex event rules.
5931 .Create an event rule targetting a Linux kernel tracepoint (default channel).
5935 $ lttng enable-event --kernel sched_switch
5939 .Create an event rule matching four Linux kernel system calls (default channel).
5943 $ lttng enable-event --kernel --syscall open,write,read,close
5947 .Create event rules matching tracepoints with filter expressions (default channel).
5951 $ lttng enable-event --kernel sched_switch --filter='prev_comm == "bash"'
5956 $ lttng enable-event --kernel --all \
5957 --filter='$ctx.tid == 1988 || $ctx.tid == 1534'
5962 $ lttng enable-event --jul my_logger \
5963 --filter='$app.retriever:cur_msg_id > 3'
5966 IMPORTANT: Make sure to always quote the filter string when you
5967 use man:lttng(1) from a shell.
5970 .Create an event rule matching any user space tracepoint of a given tracepoint provider with a log level range (default channel).
5974 $ lttng enable-event --userspace my_app:'*' --loglevel=TRACE_INFO
5977 IMPORTANT: Make sure to always quote the wildcard character when you
5978 use man:lttng(1) from a shell.
5981 .Create an event rule matching multiple Python loggers with a wildcard and with exclusions (default channel).
5985 $ lttng enable-event --python my-app.'*' \
5986 --exclude='my-app.module,my-app.hello'
5990 .Create an event rule matching any Apache log4j logger with a specific log level (default channel).
5994 $ lttng enable-event --log4j --all --loglevel-only=LOG4J_WARN
5998 .Create an event rule attached to a specific channel matching a specific user space tracepoint provider and tracepoint.
6002 $ lttng enable-event --userspace my_app:my_tracepoint --channel=my-channel
6006 The event rules of a given channel form a whitelist: as soon as an
6007 emitted event passes one of them, LTTng can record the event. For
6008 example, an event named `my_app:my_tracepoint` emitted from a user space
6009 tracepoint with a `TRACE_ERROR` log level passes both of the following
6014 $ lttng enable-event --userspace my_app:my_tracepoint
6015 $ lttng enable-event --userspace my_app:my_tracepoint \
6016 --loglevel=TRACE_INFO
6019 The second event rule is redundant: the first one includes
6023 [[disable-event-rule]]
6024 === Disable an event rule
6026 To disable an event rule that you <<enabling-disabling-events,created>>
6027 previously, use the man:lttng-disable-event(1) command. This command
6028 disables _all_ the event rules (of a given tracing domain and channel)
6029 which match an instrumentation point. The other conditions are not
6030 supported as of LTTng{nbsp}{revision}.
6032 The LTTng tracer does not record an emitted event which passes
6033 a _disabled_ event rule.
6035 .Disable an event rule matching a Python logger (default channel).
6039 $ lttng disable-event --python my-logger
6043 .Disable an event rule matching all `java.util.logging` loggers (default channel).
6047 $ lttng disable-event --jul '*'
6051 .Disable _all_ the event rules of the default channel.
6053 The opt:lttng-disable-event(1):--all-events option is not, like the
6054 opt:lttng-enable-event(1):--all option of man:lttng-enable-event(1), the
6055 equivalent of the event name `*` (wildcard): it disables _all_ the event
6056 rules of a given channel.
6060 $ lttng disable-event --jul --all-events
6064 NOTE: You cannot delete an event rule once you create it.
6068 === Get the status of a tracing session
6070 To get the status of the current tracing session, that is, its
6071 parameters, its channels, event rules, and their attributes:
6073 * Use the man:lttng-status(1) command:
6083 To get the status of any tracing session:
6085 * Use the man:lttng-list(1) command with the tracing session's name:
6090 $ lttng list my-session
6094 Replace `my-session` with the desired tracing session's name.
6097 [[basic-tracing-session-control]]
6098 === Start and stop a tracing session
6100 Once you <<creating-destroying-tracing-sessions,create a tracing
6102 <<enabling-disabling-events,create one or more event rules>>,
6103 you can start and stop the tracers for this tracing session.
6105 To start tracing in the current tracing session:
6107 * Use the man:lttng-start(1) command:
6116 LTTng is very flexible: you can launch user applications before
6117 or after the you start the tracers. The tracers only record the events
6118 if they pass enabled event rules and if they occur while the tracers are
6121 To stop tracing in the current tracing session:
6123 * Use the man:lttng-stop(1) command:
6132 If there were <<channel-overwrite-mode-vs-discard-mode,lost event
6133 records>> or lost sub-buffers since the last time you ran
6134 man:lttng-start(1), warnings are printed when you run the
6135 man:lttng-stop(1) command.
6137 IMPORTANT: You need to stop tracing to make LTTng flush the remaining
6138 trace data and make the trace readable. Note that the
6139 man:lttng-destroy(1) command (see
6140 <<creating-destroying-tracing-sessions,Create and destroy a tracing
6141 session>>) also runs the man:lttng-stop(1) command implicitly.
6144 [[enabling-disabling-channels]]
6145 === Create a channel
6147 Once you create a tracing session, you can create a <<channel,channel>>
6148 with the man:lttng-enable-channel(1) command.
6150 Note that LTTng automatically creates a default channel when, for a
6151 given <<domain,tracing domain>>, no channels exist and you
6152 <<enabling-disabling-events,create>> the first event rule. This default
6153 channel is named `channel0` and its attributes are set to reasonable
6154 values. Therefore, you only need to create a channel when you need
6155 non-default attributes.
6157 You specify each non-default channel attribute with a command-line
6158 option when you use the man:lttng-enable-channel(1) command. The
6159 available command-line options are:
6161 [role="growable",cols="asciidoc,asciidoc"]
6162 .Command-line options for the man:lttng-enable-channel(1) command.
6164 |Option |Description
6170 <<channel-overwrite-mode-vs-discard-mode,event loss mode>> instead of
6171 the default _discard_ mode.
6173 |`--buffers-pid` (user space tracing domain only)
6176 Use the per-process <<channel-buffering-schemes,buffering scheme>>
6177 instead of the default per-user buffering scheme.
6179 |+--subbuf-size=__SIZE__+
6182 Allocate sub-buffers of +__SIZE__+ bytes (power of two), for each CPU,
6183 either for each Unix user (default), or for each instrumented process.
6185 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
6187 |+--num-subbuf=__COUNT__+
6190 Allocate +__COUNT__+ sub-buffers (power of two), for each CPU, either
6191 for each Unix user (default), or for each instrumented process.
6193 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
6195 |+--tracefile-size=__SIZE__+
6198 Set the maximum size of each trace file that this channel writes within
6199 a stream to +__SIZE__+ bytes instead of no maximum.
6201 See <<tracefile-rotation,Trace file count and size>>.
6203 |+--tracefile-count=__COUNT__+
6206 Limit the number of trace files that this channel creates to
6207 +__COUNT__+ channels instead of no limit.
6209 See <<tracefile-rotation,Trace file count and size>>.
6211 |+--switch-timer=__PERIODUS__+
6214 Set the <<channel-switch-timer,switch timer period>>
6215 to +__PERIODUS__+{nbsp}µs.
6217 |+--read-timer=__PERIODUS__+
6220 Set the <<channel-read-timer,read timer period>>
6221 to +__PERIODUS__+{nbsp}µs.
6223 |[[opt-blocking-timeout]]+--blocking-timeout=__TIMEOUTUS__+
6226 Set the timeout of user space applications which load LTTng-UST
6227 in blocking mode to +__TIMEOUTUS__+:
6230 Never block (non-blocking mode).
6233 Block forever until space is available in a sub-buffer to record
6236 __n__, a positive value::
6237 Wait for at most __n__ µs when trying to write into a sub-buffer.
6239 Note that, for this option to have any effect on an instrumented
6240 user space application, you need to run the application with a set
6241 env:LTTNG_UST_ALLOW_BLOCKING environment variable.
6243 |+--output=__TYPE__+ (Linux kernel tracing domain only)
6246 Set the channel's output type to +__TYPE__+, either `mmap` or `splice`.
6250 You can only create a channel in the Linux kernel and user space
6251 <<domain,tracing domains>>: other tracing domains have their own channel
6252 created on the fly when <<enabling-disabling-events,creating event
6257 Because of a current LTTng limitation, you must create all channels
6258 _before_ you <<basic-tracing-session-control,start tracing>> in a given
6259 tracing session, that is, before the first time you run
6262 Since LTTng automatically creates a default channel when you use the
6263 man:lttng-enable-event(1) command with a specific tracing domain, you
6264 cannot, for example, create a Linux kernel event rule, start tracing,
6265 and then create a user space event rule, because no user space channel
6266 exists yet and it's too late to create one.
6268 For this reason, make sure to configure your channels properly
6269 before starting the tracers for the first time!
6272 The following examples show how you can combine the previous
6273 command-line options to create simple to more complex channels.
6275 .Create a Linux kernel channel with default attributes.
6279 $ lttng enable-channel --kernel my-channel
6283 .Create a user space channel with 4 sub-buffers or 1{nbsp}MiB each, per CPU, per instrumented process.
6287 $ lttng enable-channel --userspace --num-subbuf=4 --subbuf-size=1M \
6288 --buffers-pid my-channel
6292 .[[blocking-timeout-example]]Create a default user space channel with an infinite blocking timeout.
6294 <<creating-destroying-tracing-sessions,Create a tracing-session>>,
6295 create the channel, <<enabling-disabling-events,create an event rule>>,
6296 and <<basic-tracing-session-control,start tracing>>:
6301 $ lttng enable-channel --userspace --blocking-timeout=inf blocking-channel
6302 $ lttng enable-event --userspace --channel=blocking-channel --all
6306 Run an application instrumented with LTTng-UST and allow it to block:
6310 $ LTTNG_UST_ALLOW_BLOCKING=1 my-app
6314 .Create a Linux kernel channel which rotates 8 trace files of 4{nbsp}MiB each for each stream
6318 $ lttng enable-channel --kernel --tracefile-count=8 \
6319 --tracefile-size=4194304 my-channel
6323 .Create a user space channel in overwrite (or _flight recorder_) mode.
6327 $ lttng enable-channel --userspace --overwrite my-channel
6331 You can <<enabling-disabling-events,create>> the same event rule in
6332 two different channels:
6336 $ lttng enable-event --userspace --channel=my-channel app:tp
6337 $ lttng enable-event --userspace --channel=other-channel app:tp
6340 If both channels are enabled, when a tracepoint named `app:tp` is
6341 reached, LTTng records two events, one for each channel.
6345 === Disable a channel
6347 To disable a specific channel that you <<enabling-disabling-channels,created>>
6348 previously, use the man:lttng-disable-channel(1) command.
6350 .Disable a specific Linux kernel channel.
6354 $ lttng disable-channel --kernel my-channel
6358 The state of a channel precedes the individual states of event rules
6359 attached to it: event rules which belong to a disabled channel, even if
6360 they are enabled, are also considered disabled.
6364 === Add context fields to a channel
6366 Event record fields in trace files provide important information about
6367 events that occured previously, but sometimes some external context may
6368 help you solve a problem faster. Examples of context fields are:
6370 * The **process ID**, **thread ID**, **process name**, and
6371 **process priority** of the thread in which the event occurs.
6372 * The **hostname** of the system on which the event occurs.
6373 * The current values of many possible **performance counters** using
6375 ** CPU cycles, stalled cycles, idle cycles, and the other cycle types.
6377 ** Branch instructions, misses, and loads.
6379 * Any context defined at the application level (supported for the
6380 JUL and log4j <<domain,tracing domains>>).
6382 To get the full list of available context fields, see
6383 `lttng add-context --list`. Some context fields are reserved for a
6384 specific <<domain,tracing domain>> (Linux kernel or user space).
6386 You add context fields to <<channel,channels>>. All the events
6387 that a channel with added context fields records contain those fields.
6389 To add context fields to one or all the channels of a given tracing
6392 * Use the man:lttng-add-context(1) command.
6394 .Add context fields to all the channels of the current tracing session.
6396 The following command line adds the virtual process identifier and
6397 the per-thread CPU cycles count fields to all the user space channels
6398 of the current tracing session.
6402 $ lttng add-context --userspace --type=vpid --type=perf:thread:cpu-cycles
6406 .Add performance counter context fields by raw ID
6408 See man:lttng-add-context(1) for the exact format of the context field
6409 type, which is partly compatible with the format used in
6414 $ lttng add-context --userspace --type=perf:thread:raw:r0110:test
6415 $ lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted
6419 .Add a context field to a specific channel.
6421 The following command line adds the thread identifier context field
6422 to the Linux kernel channel named `my-channel` in the current
6427 $ lttng add-context --kernel --channel=my-channel --type=tid
6431 .Add an application-specific context field to a specific channel.
6433 The following command line adds the `cur_msg_id` context field of the
6434 `retriever` context retriever for all the instrumented
6435 <<java-application,Java applications>> recording <<event,event records>>
6436 in the channel named `my-channel`:
6440 $ lttng add-context --kernel --channel=my-channel \
6441 --type='$app:retriever:cur_msg_id'
6444 IMPORTANT: Make sure to always quote the `$` character when you
6445 use man:lttng-add-context(1) from a shell.
6448 NOTE: You cannot remove context fields from a channel once you add it.
6453 === Track process IDs
6455 It's often useful to allow only specific process IDs (PIDs) to emit
6456 events. For example, you may wish to record all the system calls made by
6457 a given process (Ă la http://linux.die.net/man/1/strace[strace]).
6459 The man:lttng-track(1) and man:lttng-untrack(1) commands serve this
6460 purpose. Both commands operate on a whitelist of process IDs. You _add_
6461 entries to this whitelist with the man:lttng-track(1) command and remove
6462 entries with the man:lttng-untrack(1) command. Any process which has one
6463 of the PIDs in the whitelist is allowed to emit LTTng events which pass
6464 an enabled <<event,event rule>>.
6466 NOTE: The PID tracker tracks the _numeric process IDs_. Should a
6467 process with a given tracked ID exit and another process be given this
6468 ID, then the latter would also be allowed to emit events.
6470 .Track and untrack process IDs.
6472 For the sake of the following example, assume the target system has 16
6476 <<creating-destroying-tracing-sessions,create a tracing session>>,
6477 the whitelist contains all the possible PIDs:
6480 .All PIDs are tracked.
6481 image::track-all.png[]
6483 When the whitelist is full and you use the man:lttng-track(1) command to
6484 specify some PIDs to track, LTTng first clears the whitelist, then it
6485 tracks the specific PIDs. After:
6489 $ lttng track --pid=3,4,7,10,13
6495 .PIDs 3, 4, 7, 10, and 13 are tracked.
6496 image::track-3-4-7-10-13.png[]
6498 You can add more PIDs to the whitelist afterwards:
6502 $ lttng track --pid=1,15,16
6508 .PIDs 1, 15, and 16 are added to the whitelist.
6509 image::track-1-3-4-7-10-13-15-16.png[]
6511 The man:lttng-untrack(1) command removes entries from the PID tracker's
6512 whitelist. Given the previous example, the following command:
6516 $ lttng untrack --pid=3,7,10,13
6519 leads to this whitelist:
6522 .PIDs 3, 7, 10, and 13 are removed from the whitelist.
6523 image::track-1-4-15-16.png[]
6525 LTTng can track all possible PIDs again using the
6526 opt:lttng-track(1):--all option:
6530 $ lttng track --pid --all
6533 The result is, again:
6536 .All PIDs are tracked.
6537 image::track-all.png[]
6540 .Track only specific PIDs
6542 A very typical use case with PID tracking is to start with an empty
6543 whitelist, then <<basic-tracing-session-control,start the tracers>>, and
6544 then add PIDs manually while tracers are active. You can accomplish this
6545 by using the opt:lttng-untrack(1):--all option of the
6546 man:lttng-untrack(1) command to clear the whitelist after you
6547 <<creating-destroying-tracing-sessions,create a tracing session>>:
6551 $ lttng untrack --pid --all
6557 .No PIDs are tracked.
6558 image::untrack-all.png[]
6560 If you trace with this whitelist configuration, the tracer records no
6561 events for this <<domain,tracing domain>> because no processes are
6562 tracked. You can use the man:lttng-track(1) command as usual to track
6563 specific PIDs, for example:
6567 $ lttng track --pid=6,11
6573 .PIDs 6 and 11 are tracked.
6574 image::track-6-11.png[]
6579 [[saving-loading-tracing-session]]
6580 === Save and load tracing session configurations
6582 Configuring a <<tracing-session,tracing session>> can be long. Some of
6583 the tasks involved are:
6585 * <<enabling-disabling-channels,Create channels>> with
6586 specific attributes.
6587 * <<adding-context,Add context fields>> to specific channels.
6588 * <<enabling-disabling-events,Create event rules>> with specific log
6589 level and filter conditions.
6591 If you use LTTng to solve real world problems, chances are you have to
6592 record events using the same tracing session setup over and over,
6593 modifying a few variables each time in your instrumented program
6594 or environment. To avoid constant tracing session reconfiguration,
6595 the man:lttng(1) command-line tool can save and load tracing session
6596 configurations to/from XML files.
6598 To save a given tracing session configuration:
6600 * Use the man:lttng-save(1) command:
6605 $ lttng save my-session
6609 Replace `my-session` with the name of the tracing session to save.
6611 LTTng saves tracing session configurations to
6612 dir:{$LTTNG_HOME/.lttng/sessions} by default. Note that the
6613 env:LTTNG_HOME environment variable defaults to `$HOME` if not set. Use
6614 the opt:lttng-save(1):--output-path option to change this destination
6617 LTTng saves all configuration parameters, for example:
6619 * The tracing session name.
6620 * The trace data output path.
6621 * The channels with their state and all their attributes.
6622 * The context fields you added to channels.
6623 * The event rules with their state, log level and filter conditions.
6625 To load a tracing session:
6627 * Use the man:lttng-load(1) command:
6632 $ lttng load my-session
6636 Replace `my-session` with the name of the tracing session to load.
6638 When LTTng loads a configuration, it restores your saved tracing session
6639 as if you just configured it manually.
6641 See man:lttng(1) for the complete list of command-line options. You
6642 can also save and load all many sessions at a time, and decide in which
6643 directory to output the XML files.
6646 [[sending-trace-data-over-the-network]]
6647 === Send trace data over the network
6649 LTTng can send the recorded trace data to a remote system over the
6650 network instead of writing it to the local file system.
6652 To send the trace data over the network:
6654 . On the _remote_ system (which can also be the target system),
6655 start an LTTng <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)):
6664 . On the _target_ system, create a tracing session configured to
6665 send trace data over the network:
6670 $ lttng create my-session --set-url=net://remote-system
6674 Replace `remote-system` by the host name or IP address of the
6675 remote system. See man:lttng-create(1) for the exact URL format.
6677 . On the target system, use the man:lttng(1) command-line tool as usual.
6678 When tracing is active, the target's consumer daemon sends sub-buffers
6679 to the relay daemon running on the remote system instead of flushing
6680 them to the local file system. The relay daemon writes the received
6681 packets to the local file system.
6683 The relay daemon writes trace files to
6684 +$LTTNG_HOME/lttng-traces/__hostname__/__session__+ by default, where
6685 +__hostname__+ is the host name of the target system and +__session__+
6686 is the tracing session name. Note that the env:LTTNG_HOME environment
6687 variable defaults to `$HOME` if not set. Use the
6688 opt:lttng-relayd(8):--output option of man:lttng-relayd(8) to write
6689 trace files to another base directory.
6694 === View events as LTTng emits them (noch:{LTTng} live)
6696 LTTng live is a network protocol implemented by the <<lttng-relayd,relay
6697 daemon>> (man:lttng-relayd(8)) to allow compatible trace viewers to
6698 display events as LTTng emits them on the target system while tracing is
6701 The relay daemon creates a _tee_: it forwards the trace data to both
6702 the local file system and to connected live viewers:
6705 .The relay daemon creates a _tee_, forwarding the trace data to both trace files and a connected live viewer.
6710 . On the _target system_, create a <<tracing-session,tracing session>>
6716 $ lttng create my-session --live
6720 This spawns a local relay daemon.
6722 . Start the live viewer and configure it to connect to the relay
6723 daemon. For example, with http://diamon.org/babeltrace[Babeltrace]:
6728 $ babeltrace --input-format=lttng-live \
6729 net://localhost/host/hostname/my-session
6736 * `hostname` with the host name of the target system.
6737 * `my-session` with the name of the tracing session to view.
6740 . Configure the tracing session as usual with the man:lttng(1)
6741 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6743 You can list the available live tracing sessions with Babeltrace:
6747 $ babeltrace --input-format=lttng-live net://localhost
6750 You can start the relay daemon on another system. In this case, you need
6751 to specify the relay daemon's URL when you create the tracing session
6752 with the opt:lttng-create(1):--set-url option. You also need to replace
6753 `localhost` in the procedure above with the host name of the system on
6754 which the relay daemon is running.
6756 See man:lttng-create(1) and man:lttng-relayd(8) for the complete list of
6757 command-line options.
6761 [[taking-a-snapshot]]
6762 === Take a snapshot of the current sub-buffers of a tracing session
6764 The normal behavior of LTTng is to append full sub-buffers to growing
6765 trace data files. This is ideal to keep a full history of the events
6766 that occurred on the target system, but it can
6767 represent too much data in some situations. For example, you may wish
6768 to trace your application continuously until some critical situation
6769 happens, in which case you only need the latest few recorded
6770 events to perform the desired analysis, not multi-gigabyte trace files.
6772 With the man:lttng-snapshot(1) command, you can take a snapshot of the
6773 current sub-buffers of a given <<tracing-session,tracing session>>.
6774 LTTng can write the snapshot to the local file system or send it over
6779 . Create a tracing session in _snapshot mode_:
6784 $ lttng create my-session --snapshot
6788 The <<channel-overwrite-mode-vs-discard-mode,event loss mode>> of
6789 <<channel,channels>> created in this mode is automatically set to
6790 _overwrite_ (flight recorder mode).
6792 . Configure the tracing session as usual with the man:lttng(1)
6793 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6795 . **Optional**: When you need to take a snapshot,
6796 <<basic-tracing-session-control,stop tracing>>.
6798 You can take a snapshot when the tracers are active, but if you stop
6799 them first, you are sure that the data in the sub-buffers does not
6800 change before you actually take the snapshot.
6807 $ lttng snapshot record --name=my-first-snapshot
6811 LTTng writes the current sub-buffers of all the current tracing
6812 session's channels to trace files on the local file system. Those trace
6813 files have `my-first-snapshot` in their name.
6815 There is no difference between the format of a normal trace file and the
6816 format of a snapshot: viewers of LTTng traces also support LTTng
6819 By default, LTTng writes snapshot files to the path shown by
6820 `lttng snapshot list-output`. You can change this path or decide to send
6821 snapshots over the network using either:
6823 . An output path or URL that you specify when you create the
6825 . An snapshot output path or URL that you add using
6826 `lttng snapshot add-output`
6827 . An output path or URL that you provide directly to the
6828 `lttng snapshot record` command.
6830 Method 3 overrides method 2, which overrides method 1. When you
6831 specify a URL, a relay daemon must listen on a remote system (see
6832 <<sending-trace-data-over-the-network,Send trace data over the network>>).
6837 === Use the machine interface
6839 With any command of the man:lttng(1) command-line tool, you can set the
6840 opt:lttng(1):--mi option to `xml` (before the command name) to get an
6841 XML machine interface output, for example:
6845 $ lttng --mi=xml enable-event --kernel --syscall open
6848 A schema definition (XSD) is
6849 https://github.com/lttng/lttng-tools/blob/stable-2.10/src/common/mi-lttng-3.0.xsd[available]
6850 to ease the integration with external tools as much as possible.
6854 [[metadata-regenerate]]
6855 === Regenerate the metadata of an LTTng trace
6857 An LTTng trace, which is a http://diamon.org/ctf[CTF] trace, has both
6858 data stream files and a metadata file. This metadata file contains,
6859 amongst other things, information about the offset of the clock sources
6860 used to timestamp <<event,event records>> when tracing.
6862 If, once a <<tracing-session,tracing session>> is
6863 <<basic-tracing-session-control,started>>, a major
6864 https://en.wikipedia.org/wiki/Network_Time_Protocol[NTP] correction
6865 happens, the trace's clock offset also needs to be updated. You
6866 can use the `metadata` item of the man:lttng-regenerate(1) command
6869 The main use case of this command is to allow a system to boot with
6870 an incorrect wall time and trace it with LTTng before its wall time
6871 is corrected. Once the system is known to be in a state where its
6872 wall time is correct, it can run `lttng regenerate metadata`.
6874 To regenerate the metadata of an LTTng trace:
6876 * Use the `metadata` item of the man:lttng-regenerate(1) command:
6881 $ lttng regenerate metadata
6887 `lttng regenerate metadata` has the following limitations:
6889 * Tracing session <<creating-destroying-tracing-sessions,created>>
6891 * User space <<channel,channels>>, if any, are using
6892 <<channel-buffering-schemes,per-user buffering>>.
6897 [[regenerate-statedump]]
6898 === Regenerate the state dump of a tracing session
6900 The LTTng kernel and user space tracers generate state dump
6901 <<event,event records>> when the application starts or when you
6902 <<basic-tracing-session-control,start a tracing session>>. An analysis
6903 can use the state dump event records to set an initial state before it
6904 builds the rest of the state from the following event records.
6905 http://tracecompass.org/[Trace Compass] is a notable example of an
6906 application which uses the state dump of an LTTng trace.
6908 When you <<taking-a-snapshot,take a snapshot>>, it's possible that the
6909 state dump event records are not included in the snapshot because they
6910 were recorded to a sub-buffer that has been consumed or overwritten
6913 You can use the `lttng regenerate statedump` command to emit the state
6914 dump event records again.
6916 To regenerate the state dump of the current tracing session, provided
6917 create it in snapshot mode, before you take a snapshot:
6919 . Use the `statedump` item of the man:lttng-regenerate(1) command:
6924 $ lttng regenerate statedump
6928 . <<basic-tracing-session-control,Stop the tracing session>>:
6937 . <<taking-a-snapshot,Take a snapshot>>:
6942 $ lttng snapshot record --name=my-snapshot
6946 Depending on the event throughput, you should run steps 1 and 2
6947 as closely as possible.
6949 NOTE: To record the state dump events, you need to
6950 <<enabling-disabling-events,create event rules>> which enable them.
6951 LTTng-UST state dump tracepoints start with `lttng_ust_statedump:`.
6952 LTTng-modules state dump tracepoints start with `lttng_statedump_`.
6956 [[persistent-memory-file-systems]]
6957 === Record trace data on persistent memory file systems
6959 https://en.wikipedia.org/wiki/Non-volatile_random-access_memory[Non-volatile random-access memory]
6960 (NVRAM) is random-access memory that retains its information when power
6961 is turned off (non-volatile). Systems with such memory can store data
6962 structures in RAM and retrieve them after a reboot, without flushing
6963 to typical _storage_.
6965 Linux supports NVRAM file systems thanks to either
6966 http://pramfs.sourceforge.net/[PRAMFS] or
6967 https://www.kernel.org/doc/Documentation/filesystems/dax.txt[DAX]{nbsp}+{nbsp}http://lkml.iu.edu/hypermail/linux/kernel/1504.1/03463.html[pmem]
6968 (requires Linux 4.1+).
6970 This section does not describe how to operate such file systems;
6971 we assume that you have a working persistent memory file system.
6973 When you create a <<tracing-session,tracing session>>, you can specify
6974 the path of the shared memory holding the sub-buffers. If you specify a
6975 location on an NVRAM file system, then you can retrieve the latest
6976 recorded trace data when the system reboots after a crash.
6978 To record trace data on a persistent memory file system and retrieve the
6979 trace data after a system crash:
6981 . Create a tracing session with a sub-buffer shared memory path located
6982 on an NVRAM file system:
6987 $ lttng create my-session --shm-path=/path/to/shm
6991 . Configure the tracing session as usual with the man:lttng(1)
6992 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6994 . After a system crash, use the man:lttng-crash(1) command-line tool to
6995 view the trace data recorded on the NVRAM file system:
7000 $ lttng-crash /path/to/shm
7004 The binary layout of the ring buffer files is not exactly the same as
7005 the trace files layout. This is why you need to use man:lttng-crash(1)
7006 instead of your preferred trace viewer directly.
7008 To convert the ring buffer files to LTTng trace files:
7010 * Use the opt:lttng-crash(1):--extract option of man:lttng-crash(1):
7015 $ lttng-crash --extract=/path/to/trace /path/to/shm
7021 [[notif-trigger-api]]
7022 === Get notified when a channel's buffer usage is too high or too low
7024 With LTTng's $$C/C++$$ notification and trigger API, your user
7025 application can get notified when the buffer usage of one or more
7026 <<channel,channels>> becomes too low or too high. You can use this API
7027 and enable or disable <<event,event rules>> during tracing to avoid
7028 <<channel-overwrite-mode-vs-discard-mode,discarded event records>>.
7030 .Have a user application get notified when an LTTng channel's buffer usage is too high.
7032 In this example, we create and build an application which gets notified
7033 when the buffer usage of a specific LTTng channel is higher than
7034 75{nbsp}%. We only print that it is the case in the example, but we
7035 could as well use the API of <<liblttng-ctl-lttng,`liblttng-ctl`>> to
7036 disable event rules when this happens.
7038 . Create the application's C source file:
7046 #include <lttng/domain.h>
7047 #include <lttng/action/action.h>
7048 #include <lttng/action/notify.h>
7049 #include <lttng/condition/condition.h>
7050 #include <lttng/condition/buffer-usage.h>
7051 #include <lttng/condition/evaluation.h>
7052 #include <lttng/notification/channel.h>
7053 #include <lttng/notification/notification.h>
7054 #include <lttng/trigger/trigger.h>
7055 #include <lttng/endpoint.h>
7057 int main(int argc, char *argv[])
7059 int exit_status = 0;
7060 struct lttng_notification_channel *notification_channel;
7061 struct lttng_condition *condition;
7062 struct lttng_action *action;
7063 struct lttng_trigger *trigger;
7064 const char *tracing_session_name;
7065 const char *channel_name;
7068 tracing_session_name = argv[1];
7069 channel_name = argv[2];
7072 * Create a notification channel. A notification channel
7073 * connects the user application to the LTTng session daemon.
7074 * This notification channel can be used to listen to various
7075 * types of notifications.
7077 notification_channel = lttng_notification_channel_create(
7078 lttng_session_daemon_notification_endpoint);
7081 * Create a "high buffer usage" condition. In this case, the
7082 * condition is reached when the buffer usage is greater than or
7083 * equal to 75 %. We create the condition for a specific tracing
7084 * session name, channel name, and for the user space tracing
7087 * The "low buffer usage" condition type also exists.
7089 condition = lttng_condition_buffer_usage_high_create();
7090 lttng_condition_buffer_usage_set_threshold_ratio(condition, .75);
7091 lttng_condition_buffer_usage_set_session_name(
7092 condition, tracing_session_name);
7093 lttng_condition_buffer_usage_set_channel_name(condition,
7095 lttng_condition_buffer_usage_set_domain_type(condition,
7099 * Create an action (get a notification) to take when the
7100 * condition created above is reached.
7102 action = lttng_action_notify_create();
7105 * Create a trigger. A trigger associates a condition to an
7106 * action: the action is executed when the condition is reached.
7108 trigger = lttng_trigger_create(condition, action);
7110 /* Register the trigger to LTTng. */
7111 lttng_register_trigger(trigger);
7114 * Now that we have registered a trigger, a notification will be
7115 * emitted everytime its condition is met. To receive this
7116 * notification, we must subscribe to notifications that match
7117 * the same condition.
7119 lttng_notification_channel_subscribe(notification_channel,
7123 * Notification loop. You can put this in a dedicated thread to
7124 * avoid blocking the main thread.
7127 struct lttng_notification *notification;
7128 enum lttng_notification_channel_status status;
7129 const struct lttng_evaluation *notification_evaluation;
7130 const struct lttng_condition *notification_condition;
7131 double buffer_usage;
7133 /* Receive the next notification. */
7134 status = lttng_notification_channel_get_next_notification(
7135 notification_channel, ¬ification);
7138 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK:
7140 case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED:
7142 * The session daemon can drop notifications if
7143 * a monitoring application is not consuming the
7144 * notifications fast enough.
7147 case LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED:
7149 * The notification channel has been closed by the
7150 * session daemon. This is typically caused by a session
7151 * daemon shutting down.
7155 /* Unhandled conditions or errors. */
7161 * A notification provides, amongst other things:
7163 * * The condition that caused this notification to be
7165 * * The condition evaluation, which provides more
7166 * specific information on the evaluation of the
7169 * The condition evaluation provides the buffer usage
7170 * value at the moment the condition was reached.
7172 notification_condition = lttng_notification_get_condition(
7174 notification_evaluation = lttng_notification_get_evaluation(
7177 /* We're subscribed to only one condition. */
7178 assert(lttng_condition_get_type(notification_condition) ==
7179 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH);
7182 * Get the exact sampled buffer usage from the
7183 * condition evaluation.
7185 lttng_evaluation_buffer_usage_get_usage_ratio(
7186 notification_evaluation, &buffer_usage);
7189 * At this point, instead of printing a message, we
7190 * could do something to reduce the channel's buffer
7191 * usage, like disable specific events.
7193 printf("Buffer usage is %f %% in tracing session \"%s\", "
7194 "user space channel \"%s\".\n", buffer_usage * 100,
7195 tracing_session_name, channel_name);
7196 lttng_notification_destroy(notification);
7200 lttng_action_destroy(action);
7201 lttng_condition_destroy(condition);
7202 lttng_trigger_destroy(trigger);
7203 lttng_notification_channel_destroy(notification_channel);
7209 . Build the `notif-app` application, linking it to `liblttng-ctl`:
7214 $ gcc -o notif-app notif-app.c -llttng-ctl
7218 . <<creating-destroying-tracing-sessions,Create a tracing session>>,
7219 <<enabling-disabling-events,create an event rule>> matching all the
7220 user space tracepoints, and
7221 <<basic-tracing-session-control,start tracing>>:
7226 $ lttng create my-session
7227 $ lttng enable-event --userspace --all
7232 If you create the channel manually with the man:lttng-enable-channel(1)
7233 command, you can control how frequently are the current values of the
7234 channel's properties sampled to evaluate user conditions with the
7235 opt:lttng-enable-channel(1):--monitor-timer option.
7237 . Run the `notif-app` application. This program accepts the
7238 <<tracing-session,tracing session>> name and the user space channel
7239 name as its two first arguments. The channel which LTTng automatically
7240 creates with the man:lttng-enable-event(1) command above is named
7246 $ ./notif-app my-session channel0
7250 . In another terminal, run an application with a very high event
7251 throughput so that the 75{nbsp}% buffer usage condition is reached.
7253 In the first terminal, the application should print lines like this:
7256 Buffer usage is 81.45197 % in tracing session "my-session", user space
7260 If you don't see anything, try modifying the condition in
7261 path:{notif-app.c} to a lower value (0.1, for example), rebuilding it
7262 (step 2) and running it again (step 4).
7269 [[lttng-modules-ref]]
7270 === noch:{LTTng-modules}
7274 [[lttng-tracepoint-enum]]
7275 ==== `LTTNG_TRACEPOINT_ENUM()` usage
7277 Use the `LTTNG_TRACEPOINT_ENUM()` macro to define an enumeration:
7281 LTTNG_TRACEPOINT_ENUM(name, TP_ENUM_VALUES(entries))
7286 * `name` with the name of the enumeration (C identifier, unique
7287 amongst all the defined enumerations).
7288 * `entries` with a list of enumeration entries.
7290 The available enumeration entry macros are:
7292 +ctf_enum_value(__name__, __value__)+::
7293 Entry named +__name__+ mapped to the integral value +__value__+.
7295 +ctf_enum_range(__name__, __begin__, __end__)+::
7296 Entry named +__name__+ mapped to the range of integral values between
7297 +__begin__+ (included) and +__end__+ (included).
7299 +ctf_enum_auto(__name__)+::
7300 Entry named +__name__+ mapped to the integral value following the
7301 last mapping's value.
7303 The last value of a `ctf_enum_value()` entry is its +__value__+
7306 The last value of a `ctf_enum_range()` entry is its +__end__+ parameter.
7308 If `ctf_enum_auto()` is the first entry in the list, its integral
7311 Use the `ctf_enum()` <<lttng-modules-tp-fields,field definition macro>>
7312 to use a defined enumeration as a tracepoint field.
7314 .Define an enumeration with `LTTNG_TRACEPOINT_ENUM()`.
7318 LTTNG_TRACEPOINT_ENUM(
7321 ctf_enum_auto("AUTO: EXPECT 0")
7322 ctf_enum_value("VALUE: 23", 23)
7323 ctf_enum_value("VALUE: 27", 27)
7324 ctf_enum_auto("AUTO: EXPECT 28")
7325 ctf_enum_range("RANGE: 101 TO 303", 101, 303)
7326 ctf_enum_auto("AUTO: EXPECT 304")
7334 [[lttng-modules-tp-fields]]
7335 ==== Tracepoint fields macros (for `TP_FIELDS()`)
7337 [[tp-fast-assign]][[tp-struct-entry]]The available macros to define
7338 tracepoint fields, which must be listed within `TP_FIELDS()` in
7339 `LTTNG_TRACEPOINT_EVENT()`, are:
7341 [role="func-desc growable",cols="asciidoc,asciidoc"]
7342 .Available macros to define LTTng-modules tracepoint fields
7344 |Macro |Description and parameters
7347 +ctf_integer(__t__, __n__, __e__)+
7349 +ctf_integer_nowrite(__t__, __n__, __e__)+
7351 +ctf_user_integer(__t__, __n__, __e__)+
7353 +ctf_user_integer_nowrite(__t__, __n__, __e__)+
7355 Standard integer, displayed in base 10.
7358 Integer C type (`int`, `long`, `size_t`, ...).
7364 Argument expression.
7367 +ctf_integer_hex(__t__, __n__, __e__)+
7369 +ctf_user_integer_hex(__t__, __n__, __e__)+
7371 Standard integer, displayed in base 16.
7380 Argument expression.
7382 |+ctf_integer_oct(__t__, __n__, __e__)+
7384 Standard integer, displayed in base 8.
7393 Argument expression.
7396 +ctf_integer_network(__t__, __n__, __e__)+
7398 +ctf_user_integer_network(__t__, __n__, __e__)+
7400 Integer in network byte order (big-endian), displayed in base 10.
7409 Argument expression.
7412 +ctf_integer_network_hex(__t__, __n__, __e__)+
7414 +ctf_user_integer_network_hex(__t__, __n__, __e__)+
7416 Integer in network byte order, displayed in base 16.
7425 Argument expression.
7428 +ctf_enum(__N__, __t__, __n__, __e__)+
7430 +ctf_enum_nowrite(__N__, __t__, __n__, __e__)+
7432 +ctf_user_enum(__N__, __t__, __n__, __e__)+
7434 +ctf_user_enum_nowrite(__N__, __t__, __n__, __e__)+
7439 Name of a <<lttng-tracepoint-enum,previously defined enumeration>>.
7442 Integer C type (`int`, `long`, `size_t`, ...).
7448 Argument expression.
7451 +ctf_string(__n__, __e__)+
7453 +ctf_string_nowrite(__n__, __e__)+
7455 +ctf_user_string(__n__, __e__)+
7457 +ctf_user_string_nowrite(__n__, __e__)+
7459 Null-terminated string; undefined behavior if +__e__+ is `NULL`.
7465 Argument expression.
7468 +ctf_array(__t__, __n__, __e__, __s__)+
7470 +ctf_array_nowrite(__t__, __n__, __e__, __s__)+
7472 +ctf_user_array(__t__, __n__, __e__, __s__)+
7474 +ctf_user_array_nowrite(__t__, __n__, __e__, __s__)+
7476 Statically-sized array of integers.
7479 Array element C type.
7485 Argument expression.
7491 +ctf_array_bitfield(__t__, __n__, __e__, __s__)+
7493 +ctf_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7495 +ctf_user_array_bitfield(__t__, __n__, __e__, __s__)+
7497 +ctf_user_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7499 Statically-sized array of bits.
7501 The type of +__e__+ must be an integer type. +__s__+ is the number
7502 of elements of such type in +__e__+, not the number of bits.
7505 Array element C type.
7511 Argument expression.
7517 +ctf_array_text(__t__, __n__, __e__, __s__)+
7519 +ctf_array_text_nowrite(__t__, __n__, __e__, __s__)+
7521 +ctf_user_array_text(__t__, __n__, __e__, __s__)+
7523 +ctf_user_array_text_nowrite(__t__, __n__, __e__, __s__)+
7525 Statically-sized array, printed as text.
7527 The string does not need to be null-terminated.
7530 Array element C type (always `char`).
7536 Argument expression.
7542 +ctf_sequence(__t__, __n__, __e__, __T__, __E__)+
7544 +ctf_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7546 +ctf_user_sequence(__t__, __n__, __e__, __T__, __E__)+
7548 +ctf_user_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7550 Dynamically-sized array of integers.
7552 The type of +__E__+ must be unsigned.
7555 Array element C type.
7561 Argument expression.
7564 Length expression C type.
7570 +ctf_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7572 +ctf_user_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7574 Dynamically-sized array of integers, displayed in base 16.
7576 The type of +__E__+ must be unsigned.
7579 Array element C type.
7585 Argument expression.
7588 Length expression C type.
7593 |+ctf_sequence_network(__t__, __n__, __e__, __T__, __E__)+
7595 Dynamically-sized array of integers in network byte order (big-endian),
7596 displayed in base 10.
7598 The type of +__E__+ must be unsigned.
7601 Array element C type.
7607 Argument expression.
7610 Length expression C type.
7616 +ctf_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7618 +ctf_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7620 +ctf_user_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7622 +ctf_user_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7624 Dynamically-sized array of bits.
7626 The type of +__e__+ must be an integer type. +__s__+ is the number
7627 of elements of such type in +__e__+, not the number of bits.
7629 The type of +__E__+ must be unsigned.
7632 Array element C type.
7638 Argument expression.
7641 Length expression C type.
7647 +ctf_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7649 +ctf_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7651 +ctf_user_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7653 +ctf_user_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7655 Dynamically-sized array, displayed as text.
7657 The string does not need to be null-terminated.
7659 The type of +__E__+ must be unsigned.
7661 The behaviour is undefined if +__e__+ is `NULL`.
7664 Sequence element C type (always `char`).
7670 Argument expression.
7673 Length expression C type.
7679 Use the `_user` versions when the argument expression, `e`, is
7680 a user space address. In the cases of `ctf_user_integer*()` and
7681 `ctf_user_float*()`, `&e` must be a user space address, thus `e` must
7684 The `_nowrite` versions omit themselves from the session trace, but are
7685 otherwise identical. This means the `_nowrite` fields won't be written
7686 in the recorded trace. Their primary purpose is to make some
7687 of the event context available to the
7688 <<enabling-disabling-events,event filters>> without having to
7689 commit the data to sub-buffers.
7695 Terms related to LTTng and to tracing in general:
7698 The http://diamon.org/babeltrace[Babeltrace] project, which includes
7699 the cmd:babeltrace command, some libraries, and Python bindings.
7701 <<channel-buffering-schemes,buffering scheme>>::
7702 A layout of sub-buffers applied to a given channel.
7704 <<channel,channel>>::
7705 An entity which is responsible for a set of ring buffers.
7707 <<event,Event rules>> are always attached to a specific channel.
7710 A reference of time for a tracer.
7712 <<lttng-consumerd,consumer daemon>>::
7713 A process which is responsible for consuming the full sub-buffers
7714 and write them to a file system or send them over the network.
7716 <<channel-overwrite-mode-vs-discard-mode,discard mode>>:: The event loss
7717 mode in which the tracer _discards_ new event records when there's no
7718 sub-buffer space left to store them.
7721 The consequence of the execution of an instrumentation
7722 point, like a tracepoint that you manually place in some source code,
7723 or a Linux kernel KProbe.
7725 An event is said to _occur_ at a specific time. Different actions can
7726 be taken upon the occurrence of an event, like record the event's payload
7729 <<channel-overwrite-mode-vs-discard-mode,event loss mode>>::
7730 The mechanism by which event records of a given channel are lost
7731 (not recorded) when there is no sub-buffer space left to store them.
7733 [[def-event-name]]event name::
7734 The name of an event, which is also the name of the event record.
7735 This is also called the _instrumentation point name_.
7738 A record, in a trace, of the payload of an event which occured.
7740 <<event,event rule>>::
7741 Set of conditions which must be satisfied for one or more occuring
7742 events to be recorded.
7744 `java.util.logging`::
7746 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[core logging facilities].
7748 <<instrumenting,instrumentation>>::
7749 The use of LTTng probes to make a piece of software traceable.
7751 instrumentation point::
7752 A point in the execution path of a piece of software that, when
7753 reached by this execution, can emit an event.
7755 instrumentation point name::
7756 See _<<def-event-name,event name>>_.
7759 A http://logging.apache.org/log4j/1.2/[logging library] for Java
7760 developed by the Apache Software Foundation.
7763 Level of severity of a log statement or user space
7764 instrumentation point.
7767 The _Linux Trace Toolkit: next generation_ project.
7769 <<lttng-cli,cmd:lttng>>::
7770 A command-line tool provided by the LTTng-tools project which you
7771 can use to send and receive control messages to and from a
7775 The https://github.com/lttng/lttng-analyses[LTTng analyses] project,
7776 which is a set of analyzing programs that are used to obtain a
7777 higher level view of an LTTng trace.
7779 cmd:lttng-consumerd::
7780 The name of the consumer daemon program.
7783 A utility provided by the LTTng-tools project which can convert
7784 ring buffer files (usually
7785 <<persistent-memory-file-systems,saved on a persistent memory file system>>)
7788 LTTng Documentation::
7791 <<lttng-live,LTTng live>>::
7792 A communication protocol between the relay daemon and live viewers
7793 which makes it possible to see events "live", as they are received by
7796 <<lttng-modules,LTTng-modules>>::
7797 The https://github.com/lttng/lttng-modules[LTTng-modules] project,
7798 which contains the Linux kernel modules to make the Linux kernel
7799 instrumentation points available for LTTng tracing.
7802 The name of the relay daemon program.
7804 cmd:lttng-sessiond::
7805 The name of the session daemon program.
7808 The https://github.com/lttng/lttng-tools[LTTng-tools] project, which
7809 contains the various programs and libraries used to
7810 <<controlling-tracing,control tracing>>.
7812 <<lttng-ust,LTTng-UST>>::
7813 The https://github.com/lttng/lttng-ust[LTTng-UST] project, which
7814 contains libraries to instrument user applications.
7816 <<lttng-ust-agents,LTTng-UST Java agent>>::
7817 A Java package provided by the LTTng-UST project to allow the
7818 LTTng instrumentation of `java.util.logging` and Apache log4j 1.2
7821 <<lttng-ust-agents,LTTng-UST Python agent>>::
7822 A Python package provided by the LTTng-UST project to allow the
7823 LTTng instrumentation of Python logging statements.
7825 <<channel-overwrite-mode-vs-discard-mode,overwrite mode>>::
7826 The event loss mode in which new event records overwrite older
7827 event records when there's no sub-buffer space left to store them.
7829 <<channel-buffering-schemes,per-process buffering>>::
7830 A buffering scheme in which each instrumented process has its own
7831 sub-buffers for a given user space channel.
7833 <<channel-buffering-schemes,per-user buffering>>::
7834 A buffering scheme in which all the processes of a Unix user share the
7835 same sub-buffer for a given user space channel.
7837 <<lttng-relayd,relay daemon>>::
7838 A process which is responsible for receiving the trace data sent by
7839 a distant consumer daemon.
7842 A set of sub-buffers.
7844 <<lttng-sessiond,session daemon>>::
7845 A process which receives control commands from you and orchestrates
7846 the tracers and various LTTng daemons.
7848 <<taking-a-snapshot,snapshot>>::
7849 A copy of the current data of all the sub-buffers of a given tracing
7850 session, saved as trace files.
7853 One part of an LTTng ring buffer which contains event records.
7856 The time information attached to an event when it is emitted.
7859 A set of files which are the concatenations of one or more
7860 flushed sub-buffers.
7863 The action of recording the events emitted by an application
7864 or by a system, or to initiate such recording by controlling
7868 The http://tracecompass.org[Trace Compass] project and application.
7871 An instrumentation point using the tracepoint mechanism of the Linux
7872 kernel or of LTTng-UST.
7874 tracepoint definition::
7875 The definition of a single tracepoint.
7878 The name of a tracepoint.
7880 tracepoint provider::
7881 A set of functions providing tracepoints to an instrumented user
7884 Not to be confused with a _tracepoint provider package_: many tracepoint
7885 providers can exist within a tracepoint provider package.
7887 tracepoint provider package::
7888 One or more tracepoint providers compiled as an object file or as
7892 A software which records emitted events.
7894 <<domain,tracing domain>>::
7895 A namespace for event sources.
7897 <<tracing-group,tracing group>>::
7898 The Unix group in which a Unix user can be to be allowed to trace the
7901 <<tracing-session,tracing session>>::
7902 A stateful dialogue between you and a <<lttng-sessiond,session
7906 An application running in user space, as opposed to a Linux kernel
7907 module, for example.