2.8, 2.9: LTTng 2.8 available for Buildroot 2016.11
[lttng-docs.git] / 2.9 / lttng-docs-2.9.txt
CommitLineData
7e35c904
PP
1The LTTng Documentation
2=======================
3Philippe Proulx <pproulx@efficios.com>
d522e823 4v2.9, 2 December 2016
7e35c904
PP
5
6
7include::../common/copyright.txt[]
8
9
10include::../common/welcome.txt[]
11
12
13include::../common/audience.txt[]
14
15
16[[chapters]]
17=== What's in this documentation?
18
19The LTTng Documentation is divided into the following sections:
20
21* **<<nuts-and-bolts,Nuts and bolts>>** explains the
22 rudiments of software tracing and the rationale behind the
23 LTTng project.
24+
25You can skip this section if you’re familiar with software tracing and
26with the LTTng project.
27
28* **<<installing-lttng,Installation>>** describes the steps to
29 install the LTTng packages on common Linux distributions and from
30 their sources.
31+
32You can skip this section if you already properly installed LTTng on
33your target system.
34
35* **<<getting-started,Quick start>>** is a concise guide to
36 getting started quickly with LTTng kernel and user space tracing.
37+
38We recommend this section if you're new to LTTng or to software tracing
39in general.
40+
41You can skip this section if you're not new to LTTng.
42
43* **<<core-concepts,Core concepts>>** explains the concepts at
44 the heart of LTTng.
45+
46It's a good idea to become familiar with the core concepts
47before attempting to use the toolkit.
48
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.
54+
55Instrumenting source code is essential to provide a meaningful
56source of events.
57+
58You can skip this section if you do not have a programming background.
59
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.
66
67
68include::../common/convention.txt[]
69
70
71include::../common/acknowledgements.txt[]
72
73
74[[whats-new]]
75== What's new in LTTng {revision}?
76
77* **Tracing control**:
78** You can override the name or the URL of a tracing session
79 configuration when you use man:lttng-load(1) thanks to the new
80 opt:lttng-load(1):--override-name and
81 opt:lttng-load(1):--override-url options.
82** The new `lttng regenerate` command replaces the now deprecated
83 `lttng metadata` command of LTTng 2.8. man:lttng-regenerate(1) can
84 also <<regenerate-statedump,generate the state dump event records>>
85 of a given tracing session on demand, a handy feature when
86 <<taking-a-snapshot,taking a snapshot>>.
87** You can add PMU counters by raw ID with man:lttng-add-context(1):
88+
89--
90[role="term"]
91----
92lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted
93----
94--
95+
96The format of the raw ID is the same as used with man:perf-record(1).
97See <<adding-context,Add context fields to a channel>> for more
98examples.
99
100** The LTTng <<lttng-relayd,relay daemon>> is now supported on
101 OS{nbsp}X and macOS for a smoother integration within a trace
102 analysis workflow, regardless of the platform used.
103
104* **User space tracing**:
105** Improved performance (tested on x86-64 and ARMv7-A
106 (https://en.wikipedia.org/wiki/Cubieboard[Cubieboard])
107 architectures).
108** New helper library (`liblttng-ust-fd`) to help with
109 <<liblttng-ust-fd,applications which close file descriptors that
110 don't belong to them>>, for example, in a loop which closes file
111 descriptors after man:fork(2), or BSD's `closeall()`.
112** More accurate <<liblttng-ust-dl,dynamic linker instrumentation>> and
113 state dump event records, especially when a dynamically loaded
114 library manually loads its own dependencies.
115** New `ctf_*()` field definition macros (see man:lttng-ust(3)):
116*** `ctf_array_hex()`
117*** `ctf_array_network()`
118*** `ctf_array_network_hex()`
119*** `ctf_sequence_hex()`
120*** `ctf_sequence_network()`
121*** `ctf_sequence_network_hex()`
122** New `lttng_ust_loaded` weak symbol defined by `liblttng-ust` for
123 an application to know if the LTTng-UST shared library is loaded
124 or not:
125+
126--
127[source,c]
128----
129#include <stdio.h>
130
131int lttng_ust_loaded __attribute__((weak));
132
133int main(void)
134{
135 if (lttng_ust_loaded) {
136 puts("LTTng-UST is loaded!");
137 } else {
138 puts("LTTng-UST is not loaded!");
139 }
140
141 return 0;
142}
143----
144--
145
146** LTTng-UST thread names have the `-ust` suffix.
147
148* **Linux kernel tracing**:
149** Improved performance (tested on x86-64 and ARMv7-A
150 (https://en.wikipedia.org/wiki/Cubieboard[Cubieboard])
151 architectures).
152** New enumeration <<lttng-modules-tp-fields,field definition macros>>:
153 `ctf_enum()` and `ctf_user_enum()`.
154** IPv4, IPv6, and TCP header data is recorded in the event records
155 produced by tracepoints starting with `net_`.
156** Detailed system call event records: `select`, `pselect6`, `poll`,
157 `ppoll`, `epoll_wait`, `epoll_pwait`, and `epoll_ctl` on all
158 architectures supported by LTTng-modules, and `accept4` on x86-64.
159** New I²C instrumentation: the `extract_sensitive_payload` parameter
160 of the new `lttng-probe-i2c` LTTng module controls whether or not
161 the payloads of I²C messages are recorded in I²C event records, since
162 they may contain sensitive data (for example, keystrokes).
163** When the LTTng kernel modules are built into the Linux kernel image,
164 the `CONFIG_TRACEPOINTS` configuration option is automatically
165 selected.
166
167
168[[nuts-and-bolts]]
169== Nuts and bolts
170
171What is LTTng? As its name suggests, the _Linux Trace Toolkit: next
172generation_ is a modern toolkit for tracing Linux systems and
173applications. So your first question might be:
174**what is tracing?**
175
176
177[[what-is-tracing]]
178=== What is tracing?
179
180As the history of software engineering progressed and led to what
181we now take for granted--complex, numerous and
182interdependent software applications running in parallel on
183sophisticated operating systems like Linux--the authors of such
184components, software developers, began feeling a natural
185urge to have tools that would ensure the robustness and good performance
186of their masterpieces.
187
188One major achievement in this field is, inarguably, the
189https://www.gnu.org/software/gdb/[GNU debugger (GDB)],
190an essential tool for developers to find and fix bugs. But even the best
191debugger won't help make your software run faster, and nowadays, faster
192software means either more work done by the same hardware, or cheaper
193hardware for the same work.
194
195A _profiler_ is often the tool of choice to identify performance
196bottlenecks. Profiling is suitable to identify _where_ performance is
197lost in a given software. The profiler outputs a profile, a statistical
198summary of observed events, which you may use to discover which
199functions took the most time to execute. However, a profiler won't
200report _why_ some identified functions are the bottleneck. Bottlenecks
201might only occur when specific conditions are met, conditions that are
202sometimes impossible to capture by a statistical profiler, or impossible
203to reproduce with an application altered by the overhead of an
204event-based profiler. For a thorough investigation of software
205performance issues, a history of execution is essential, with the
206recorded values of variables and context fields you choose, and
207with as little influence as possible on the instrumented software. This
208is where tracing comes in handy.
209
210_Tracing_ is a technique used to understand what goes on in a running
211software system. The software used for tracing is called a _tracer_,
212which is conceptually similar to a tape recorder. When recording,
213specific instrumentation points placed in the software source code
214generate events that are saved on a giant tape: a _trace_ file. You
215can trace user applications and the operating system at the same time,
216opening the possibility of resolving a wide range of problems that would
217otherwise be extremely challenging.
218
219Tracing is often compared to _logging_. However, tracers and loggers are
220two different tools, serving two different purposes. Tracers are
221designed to record much lower-level events that occur much more
222frequently than log messages, often in the range of thousands per
223second, with very little execution overhead. Logging is more appropriate
224for a very high-level analysis of less frequent events: user accesses,
225exceptional conditions (errors and warnings, for example), database
226transactions, instant messaging communications, and such. Simply put,
227logging is one of the many use cases that can be satisfied with tracing.
228
229The list of recorded events inside a trace file can be read manually
230like a log file for the maximum level of detail, but it is generally
231much more interesting to perform application-specific analyses to
232produce reduced statistics and graphs that are useful to resolve a
233given problem. Trace viewers and analyzers are specialized tools
234designed to do this.
235
236In the end, this is what LTTng is: a powerful, open source set of
237tools to trace the Linux kernel and user applications at the same time.
238LTTng is composed of several components actively maintained and
239developed by its link:/community/#where[community].
240
241
242[[lttng-alternatives]]
243=== Alternatives to noch:{LTTng}
244
245Excluding proprietary solutions, a few competing software tracers
246exist for Linux:
247
248* https://github.com/dtrace4linux/linux[dtrace4linux] is a port of
249 Sun Microsystems's DTrace to Linux. The cmd:dtrace tool interprets
250 user scripts and is responsible for loading code into the
251 Linux kernel for further execution and collecting the outputted data.
252* https://en.wikipedia.org/wiki/Berkeley_Packet_Filter[eBPF] is a
253 subsystem in the Linux kernel in which a virtual machine can execute
254 programs passed from the user space to the kernel. You can attach
255 such programs to tracepoints and KProbes thanks to a system call, and
256 they can output data to the user space when executed thanks to
257 different mechanisms (pipe, VM register values, and eBPF maps, to name
258 a few).
259* https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace]
260 is the de facto function tracer of the Linux kernel. Its user
261 interface is a set of special files in sysfs.
262* https://perf.wiki.kernel.org/[perf] is
263 a performance analyzing tool for Linux which supports hardware
264 performance counters, tracepoints, as well as other counters and
265 types of probes. perf's controlling utility is the cmd:perf command
266 line/curses tool.
267* http://linux.die.net/man/1/strace[strace]
268 is a command-line utility which records system calls made by a
269 user process, as well as signal deliveries and changes of process
270 state. strace makes use of https://en.wikipedia.org/wiki/Ptrace[ptrace]
271 to fulfill its function.
272* http://www.sysdig.org/[sysdig], like SystemTap, uses scripts to
273 analyze Linux kernel events. You write scripts, or _chisels_ in
274 sysdig's jargon, in Lua and sysdig executes them while the system is
275 being traced or afterwards. sysdig's interface is the cmd:sysdig
276 command-line tool as well as the curses-based cmd:csysdig tool.
277* https://sourceware.org/systemtap/[SystemTap] is a Linux kernel and
278 user space tracer which uses custom user scripts to produce plain text
279 traces. SystemTap converts the scripts to the C language, and then
280 compiles them as Linux kernel modules which are loaded to produce
281 trace data. SystemTap's primary user interface is the cmd:stap
282 command-line tool.
283
284The main distinctive features of LTTng is that it produces correlated
285kernel and user space traces, as well as doing so with the lowest
286overhead amongst other solutions. It produces trace files in the
287http://diamon.org/ctf[CTF] format, a file format optimized
288for the production and analyses of multi-gigabyte data.
289
290LTTng is the result of more than 10 years of active open source
291development by a community of passionate developers.
292LTTng{nbsp}{revision} is currently available on major desktop and server
293Linux distributions.
294
295The main interface for tracing control is a single command-line tool
296named cmd:lttng. The latter can create several tracing sessions, enable
297and disable events on the fly, filter events efficiently with custom
298user expressions, start and stop tracing, and much more. LTTng can
299record the traces on the file system or send them over the network, and
300keep them totally or partially. You can view the traces once tracing
301becomes inactive or in real-time.
302
303<<installing-lttng,Install LTTng now>> and
304<<getting-started,start tracing>>!
305
306
307[[installing-lttng]]
308== Installation
309
310**LTTng** is a set of software <<plumbing,components>> which interact to
311<<instrumenting,instrument>> the Linux kernel and user applications, and
312to <<controlling-tracing,control tracing>> (start and stop
313tracing, enable and disable event rules, and the rest). Those
314components are bundled into the following packages:
315
316* **LTTng-tools**: Libraries and command-line interface to
317 control tracing.
318* **LTTng-modules**: Linux kernel modules to instrument and
319 trace the kernel.
320* **LTTng-UST**: Libraries and Java/Python packages to instrument and
321 trace user applications.
322
323Most distributions mark the LTTng-modules and LTTng-UST packages as
324optional when installing LTTng-tools (which is always required). In the
325following sections, we always provide the steps to install all three,
326but note that:
327
328* You only need to install LTTng-modules if you intend to trace the
329 Linux kernel.
330* You only need to install LTTng-UST if you intend to trace user
331 applications.
332
333[role="growable"]
d522e823 334.Availability of LTTng{nbsp}{revision} for major Linux distributions as of 2 December 2016.
7e35c904
PP
335|====
336|Distribution |Available in releases |Alternatives
337
338|Ubuntu
339|Ubuntu{nbsp}14.04 _Trusty Tahr_ and Ubuntu{nbsp}16.04 _Xenial Xerus_:
340<<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>.
341|link:/docs/v2.8#doc-ubuntu[LTTng{nbsp}2.8 for Ubuntu{nbsp}16.10 _Yakkety Yak_].
342
343<<building-from-source,Build LTTng{nbsp}{revision} from source>> for
344other Ubuntu releases.
345
346|Fedora
347|_Not available_
348|<<building-from-source,Build LTTng-modules{nbsp}{revision} from
349source>>.
350
351|Debian
352|_Not available_
353|<<building-from-source,Build LTTng-modules{nbsp}{revision} from
354source>>.
355
356|openSUSE
357|_Not available_
358|<<building-from-source,Build LTTng-modules{nbsp}{revision} from
359source>>.
360
361|Arch Linux
362|<<arch-linux,Latest AUR packages>>.
363|
364
365|Alpine Linux
366|_Not available_
367|link:/docs/v2.8#doc-alpine-linux[LTTng{nbsp}2.8 for Alpine Linux{nbsp}"edge"].
368
369LTTng{nbsp}2.8 for Alpine Linux{nbsp}3.5 (not released yet).
370
371<<building-from-source,Build LTTng{nbsp}{revision} from source>> for
372other Alpine Linux releases.
373
374|RHEL and SLES
375|See http://packages.efficios.com/[EfficiOS Enterprise Packages].
376|
377
378|Buildroot
379|_Not available_
d522e823 380|link:/docs/v2.8#doc-buildroot[LTTng{nbsp}2.8 for Buildroot{nbsp}2016.11].
7e35c904
PP
381
382<<building-from-source,Build LTTng{nbsp}{revision} from source>> for
383other Buildroot releases.
384
385|OpenEmbedded and Yocto
386|_Not available_
387|link:/docs/v2.8#doc-oe-yocto[LTTng{nbsp}2.8 for Yocto Project{nbsp}2.2 _Morty_]
388(`openembedded-core` layer).
389
390<<building-from-source,Build LTTng{nbsp}{revision} from source>> for
391other OpenEmbedded releases.
392|====
393
394
395[[ubuntu]]
396=== [[ubuntu-official-repositories]]Ubuntu
397
398[[ubuntu-ppa]]
399==== noch:{LTTng} Stable {revision} PPA
400
401The https://launchpad.net/~lttng/+archive/ubuntu/stable-{revision}[LTTng
402Stable{nbsp}{revision} PPA] offers the latest stable
403LTTng{nbsp}{revision} packages for:
404
405* Ubuntu{nbsp}14.04 _Trusty Tahr_
406* Ubuntu{nbsp}16.04 _Xenial Xerus_
407
408To install LTTng{nbsp}{revision} from the LTTng Stable{nbsp}{revision} PPA:
409
410. Add the LTTng Stable{nbsp}{revision} PPA repository and update the
411 list of packages:
412+
413--
414[role="term"]
415----
416sudo apt-add-repository ppa:lttng/stable-2.9
417sudo apt-get update
418----
419--
420
421. Install the main LTTng{nbsp}{revision} packages:
422+
423--
424[role="term"]
425----
426sudo apt-get install lttng-tools
427sudo apt-get install lttng-modules-dkms
428sudo apt-get install liblttng-ust-dev
429----
430--
431
432. **If you need to instrument and trace
433 <<java-application,Java applications>>**, install the LTTng-UST
434 Java agent:
435+
436--
437[role="term"]
438----
439sudo apt-get install liblttng-ust-agent-java
440----
441--
442
443. **If you need to instrument and trace
444 <<python-application,Python{nbsp}3 applications>>**, install the
445 LTTng-UST Python agent:
446+
447--
448[role="term"]
449----
450sudo apt-get install python3-lttngust
451----
452--
453
454
455[[arch-linux]]
456=== Arch Linux
457
458To install LTTng{nbsp}{revision} on Arch Linux using
459https://archlinux.fr/yaourt-en[Yaourt]:
460
461. Install the main LTTng{nbsp}{revision} packages:
462+
463--
464[role="term"]
465----
466yaourt -S lttng-tools
467yaourt -S lttng-ust
468yaourt -S lttng-modules
469----
470--
471
472. **If you need to instrument and trace <<python-application,Python
473 applications>>**, install the LTTng-UST Python agent:
474+
475--
476[role="term"]
477----
478yaourt -S python-lttngust
479yaourt -S python2-lttngust
480----
481--
482
483
484[[enterprise-distributions]]
485=== RHEL, SUSE, and other enterprise distributions
486
487To install LTTng on enterprise Linux distributions, such as Red Hat
488Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SUSE), please
489see http://packages.efficios.com/[EfficiOS Enterprise Packages].
490
491
492[[building-from-source]]
493=== Build from source
494
495To build and install LTTng{nbsp}{revision} from source:
496
497. Using your distribution's package manager, or from source, install
498 the following dependencies of LTTng-tools and LTTng-UST:
499+
500--
501* https://sourceforge.net/projects/libuuid/[libuuid]
502* http://directory.fsf.org/wiki/Popt[popt]
503* http://liburcu.org/[Userspace RCU]
504* http://www.xmlsoft.org/[libxml2]
505--
506
507. Download, build, and install the latest LTTng-modules{nbsp}{revision}:
508+
509--
510[role="term"]
511----
512cd $(mktemp -d) &&
513wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.9.tar.bz2 &&
514tar -xf lttng-modules-latest-2.9.tar.bz2 &&
515cd lttng-modules-2.9.* &&
516make &&
517sudo make modules_install &&
518sudo depmod -a
519----
520--
521
522. Download, build, and install the latest LTTng-UST{nbsp}{revision}:
523+
524--
525[role="term"]
526----
527cd $(mktemp -d) &&
528wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.9.tar.bz2 &&
529tar -xf lttng-ust-latest-2.9.tar.bz2 &&
530cd lttng-ust-2.9.* &&
531./configure &&
532make &&
533sudo make install &&
534sudo ldconfig
535----
536--
537+
538--
539[IMPORTANT]
540.Java and Python application tracing
541====
542If you need to instrument and trace <<java-application,Java
543applications>>, pass the `--enable-java-agent-jul`,
544`--enable-java-agent-log4j`, or `--enable-java-agent-all` options to the
545`configure` script, depending on which Java logging framework you use.
546
547If you need to instrument and trace <<python-application,Python
548applications>>, pass the `--enable-python-agent` option to the
549`configure` script. You can set the `PYTHON` environment variable to the
550path to the Python interpreter for which to install the LTTng-UST Python
551agent package.
552====
553--
554+
555--
556[NOTE]
557====
558By default, LTTng-UST libraries are installed to
559dir:{/usr/local/lib}, which is the de facto directory in which to
560keep self-compiled and third-party libraries.
561
562When <<building-tracepoint-providers-and-user-application,linking an
563instrumented user application with `liblttng-ust`>>:
564
565* Append `/usr/local/lib` to the env:LD_LIBRARY_PATH environment
566 variable.
567* Pass the `-L/usr/local/lib` and `-Wl,-rpath,/usr/local/lib` options to
568 man:gcc(1), man:g++(1), or man:clang(1).
569====
570--
571
572. Download, build, and install the latest LTTng-tools{nbsp}{revision}:
573+
574--
575[role="term"]
576----
577cd $(mktemp -d) &&
578wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.9.tar.bz2 &&
579tar -xf lttng-tools-latest-2.9.tar.bz2 &&
580cd lttng-tools-2.9.* &&
581./configure &&
582make &&
583sudo make install &&
584sudo ldconfig
585----
586--
587
588TIP: The https://github.com/eepp/vlttng[vlttng tool] can do all the
589previous steps automatically for a given version of LTTng and confine
590the installed files in a specific directory. This can be useful to test
591LTTng without installing it on your system.
592
593
594[[getting-started]]
595== Quick start
596
597This is a short guide to get started quickly with LTTng kernel and user
598space tracing.
599
600Before you follow this guide, make sure to <<installing-lttng,install>>
601LTTng.
602
603This tutorial walks you through the steps to:
604
605. <<tracing-the-linux-kernel,Trace the Linux kernel>>.
606. <<tracing-your-own-user-application,Trace a user application>> written
607 in C.
608. <<viewing-and-analyzing-your-traces,View and analyze the
609 recorded events>>.
610
611
612[[tracing-the-linux-kernel]]
613=== Trace the Linux kernel
614
615The following command lines start with cmd:sudo because you need root
616privileges to trace the Linux kernel. You can avoid using cmd:sudo if
617your Unix user is a member of the <<lttng-sessiond,tracing group>>.
618
619. Create a <<tracing-session,tracing session>>:
620+
621--
622[role="term"]
623----
624sudo lttng create my-kernel-session
625----
626--
627
628. List the available kernel tracepoints and system calls:
629+
630--
631[role="term"]
632----
633lttng list --kernel
634----
635--
636
637. Create an <<event,event rule>> which matches the desired event names,
638 for example `sched_switch` and `sched_process_fork`:
639+
640--
641[role="term"]
642----
643sudo lttng enable-event --kernel sched_switch,sched_process_fork
644----
645--
646+
647You can also create an event rule which _matches_ all the Linux kernel
648tracepoints (this will generate a lot of data when tracing):
649+
650--
651[role="term"]
652----
653sudo lttng enable-event --kernel --all
654----
655--
656
657. Start tracing:
658+
659--
660[role="term"]
661----
662sudo lttng start
663----
664--
665
666. Do some operation on your system for a few seconds. For example,
667 load a website, or list the files of a directory.
668. Stop tracing and destroy the tracing session:
669+
670--
671[role="term"]
672----
673sudo lttng stop
674sudo lttng destroy
675----
676--
677+
678The man:lttng-destroy(1) command does not destroy the trace data; it
679only destroys the state of the tracing session.
680
681By default, LTTng saves the traces in
682+$LTTNG_HOME/lttng-traces/__name__-__date__-__time__+,
683where +__name__+ is the tracing session name. Note that the
684env:LTTNG_HOME environment variable defaults to `$HOME` if not set.
685
686See <<viewing-and-analyzing-your-traces,View and analyze the
687recorded events>> to view the recorded events.
688
689
690[[tracing-your-own-user-application]]
691=== Trace a user application
692
693This section steps you through a simple example to trace a
694_Hello world_ program written in C.
695
696To create the traceable user application:
697
698. Create the tracepoint provider header file, which defines the
699 tracepoints and the events they can generate:
700+
701--
702[source,c]
703.path:{hello-tp.h}
704----
705#undef TRACEPOINT_PROVIDER
706#define TRACEPOINT_PROVIDER hello_world
707
708#undef TRACEPOINT_INCLUDE
709#define TRACEPOINT_INCLUDE "./hello-tp.h"
710
711#if !defined(_HELLO_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
712#define _HELLO_TP_H
713
714#include <lttng/tracepoint.h>
715
716TRACEPOINT_EVENT(
717 hello_world,
718 my_first_tracepoint,
719 TP_ARGS(
720 int, my_integer_arg,
721 char*, my_string_arg
722 ),
723 TP_FIELDS(
724 ctf_string(my_string_field, my_string_arg)
725 ctf_integer(int, my_integer_field, my_integer_arg)
726 )
727)
728
729#endif /* _HELLO_TP_H */
730
731#include <lttng/tracepoint-event.h>
732----
733--
734
735. Create the tracepoint provider package source file:
736+
737--
738[source,c]
739.path:{hello-tp.c}
740----
741#define TRACEPOINT_CREATE_PROBES
742#define TRACEPOINT_DEFINE
743
744#include "hello-tp.h"
745----
746--
747
748. Build the tracepoint provider package:
749+
750--
751[role="term"]
752----
753gcc -c -I. hello-tp.c
754----
755--
756
757. Create the _Hello World_ application source file:
758+
759--
760[source,c]
761.path:{hello.c}
762----
763#include <stdio.h>
764#include "hello-tp.h"
765
766int main(int argc, char *argv[])
767{
768 int x;
769
770 puts("Hello, World!\nPress Enter to continue...");
771
772 /*
773 * The following getchar() call is only placed here for the purpose
774 * of this demonstration, to pause the application in order for
775 * you to have time to list its tracepoints. It is not
776 * needed otherwise.
777 */
778 getchar();
779
780 /*
781 * A tracepoint() call.
782 *
783 * Arguments, as defined in hello-tp.h:
784 *
785 * 1. Tracepoint provider name (required)
786 * 2. Tracepoint name (required)
787 * 3. my_integer_arg (first user-defined argument)
788 * 4. my_string_arg (second user-defined argument)
789 *
790 * Notice the tracepoint provider and tracepoint names are
791 * NOT strings: they are in fact parts of variables that the
792 * macros in hello-tp.h create.
793 */
794 tracepoint(hello_world, my_first_tracepoint, 23, "hi there!");
795
796 for (x = 0; x < argc; ++x) {
797 tracepoint(hello_world, my_first_tracepoint, x, argv[x]);
798 }
799
800 puts("Quitting now!");
801 tracepoint(hello_world, my_first_tracepoint, x * x, "x^2");
802
803 return 0;
804}
805----
806--
807
808. Build the application:
809+
810--
811[role="term"]
812----
813gcc -c hello.c
814----
815--
816
817. Link the application with the tracepoint provider package,
818 `liblttng-ust`, and `libdl`:
819+
820--
821[role="term"]
822----
823gcc -o hello hello.o hello-tp.o -llttng-ust -ldl
824----
825--
826
827Here's the whole build process:
828
829[role="img-100"]
830.User space tracing tutorial's build steps.
831image::ust-flow.png[]
832
833To trace the user application:
834
835. Run the application with a few arguments:
836+
837--
838[role="term"]
839----
840./hello world and beyond
841----
842--
843+
844You see:
845+
846--
847----
848Hello, World!
849Press Enter to continue...
850----
851--
852
853. Start an LTTng <<lttng-sessiond,session daemon>>:
854+
855--
856[role="term"]
857----
858lttng-sessiond --daemonize
859----
860--
861+
862Note that a session daemon might already be running, for example as
863a service that the distribution's service manager started.
864
865. List the available user space tracepoints:
866+
867--
868[role="term"]
869----
870lttng list --userspace
871----
872--
873+
874You see the `hello_world:my_first_tracepoint` tracepoint listed
875under the `./hello` process.
876
877. Create a <<tracing-session,tracing session>>:
878+
879--
880[role="term"]
881----
882lttng create my-user-space-session
883----
884--
885
886. Create an <<event,event rule>> which matches the
887 `hello_world:my_first_tracepoint` event name:
888+
889--
890[role="term"]
891----
892lttng enable-event --userspace hello_world:my_first_tracepoint
893----
894--
895
896. Start tracing:
897+
898--
899[role="term"]
900----
901lttng start
902----
903--
904
905. Go back to the running `hello` application and press Enter. The
906 program executes all `tracepoint()` instrumentation points and exits.
907. Stop tracing and destroy the tracing session:
908+
909--
910[role="term"]
911----
912sudo lttng stop
913sudo lttng destroy
914----
915--
916+
917The man:lttng-destroy(1) command does not destroy the trace data; it
918only destroys the state of the tracing session.
919
920By default, LTTng saves the traces in
921+$LTTNG_HOME/lttng-traces/__name__-__date__-__time__+,
922where +__name__+ is the tracing session name. Note that the
923env:LTTNG_HOME environment variable defaults to `$HOME` if not set.
924
925See <<viewing-and-analyzing-your-traces,View and analyze the
926recorded events>> to view the recorded events.
927
928
929[[viewing-and-analyzing-your-traces]]
930=== View and analyze the recorded events
931
932Once you have completed the <<tracing-the-linux-kernel,Trace the Linux
933kernel>> and <<tracing-your-own-user-application,Trace a user
934application>> tutorials, you can inspect the recorded events.
935
936Many tools are available to read LTTng traces:
937
938* **cmd:babeltrace** is a command-line utility which converts trace
939 formats; it supports the format that LTTng produces, CTF, as well as a
940 basic text output which can be ++grep++ed. The cmd:babeltrace command
941 is part of the http://diamon.org/babeltrace[Babeltrace] project.
942* Babeltrace also includes
943 **https://www.python.org/[Python] bindings** so
944 that you can easily open and read an LTTng trace with your own script,
945 benefiting from the power of Python.
946* http://tracecompass.org/[**Trace Compass**]
947 is a graphical user interface for viewing and analyzing any type of
948 logs or traces, including LTTng's.
949* https://github.com/lttng/lttng-analyses[**LTTng analyses**] is a
950 project which includes many high-level analyses of LTTng kernel
951 traces, like scheduling statistics, interrupt frequency distribution,
952 top CPU usage, and more.
953
954NOTE: This section assumes that the traces recorded during the previous
955tutorials were saved to their default location, in the
956dir:{$LTTNG_HOME/lttng-traces} directory. Note that the env:LTTNG_HOME
957environment variable defaults to `$HOME` if not set.
958
959
960[[viewing-and-analyzing-your-traces-bt]]
961==== Use the cmd:babeltrace command-line tool
962
963The simplest way to list all the recorded events of a trace is to pass
964its path to cmd:babeltrace with no options:
965
966[role="term"]
967----
968babeltrace ~/lttng-traces/my-user-space-session*
969----
970
971cmd:babeltrace finds all traces recursively within the given path and
972prints all their events, merging them in chronological order.
973
974You can pipe the output of cmd:babeltrace into a tool like man:grep(1) for
975further filtering:
976
977[role="term"]
978----
979babeltrace ~/lttng-traces/my-kernel-session* | grep sys_
980----
981
982You can pipe the output of cmd:babeltrace into a tool like man:wc(1) to
983count the recorded events:
984
985[role="term"]
986----
987babeltrace ~/lttng-traces/my-kernel-session* | grep sys_read | wc --lines
988----
989
990
991[[viewing-and-analyzing-your-traces-bt-python]]
992==== Use the Babeltrace Python bindings
993
994The <<viewing-and-analyzing-your-traces-bt,text output of cmd:babeltrace>>
995is useful to isolate events by simple matching using man:grep(1) and
996similar utilities. However, more elaborate filters, such as keeping only
997event records with a field value falling within a specific range, are
998not trivial to write using a shell. Moreover, reductions and even the
999most basic computations involving multiple event records are virtually
1000impossible to implement.
1001
1002Fortunately, Babeltrace ships with Python 3 bindings which makes it easy
1003to read the event records of an LTTng trace sequentially and compute the
1004desired information.
1005
1006The following script accepts an LTTng Linux kernel trace path as its
1007first argument and prints the short names of the top 5 running processes
1008on CPU 0 during the whole trace:
1009
1010[source,python]
1011.path:{top5proc.py}
1012----
1013from collections import Counter
1014import babeltrace
1015import sys
1016
1017
1018def top5proc():
1019 if len(sys.argv) != 2:
1020 msg = 'Usage: python3 {} TRACEPATH'.format(sys.argv[0])
1021 print(msg, file=sys.stderr)
1022 return False
1023
1024 # A trace collection contains one or more traces
1025 col = babeltrace.TraceCollection()
1026
1027 # Add the trace provided by the user (LTTng traces always have
1028 # the 'ctf' format)
1029 if col.add_trace(sys.argv[1], 'ctf') is None:
1030 raise RuntimeError('Cannot add trace')
1031
1032 # This counter dict contains execution times:
1033 #
1034 # task command name -> total execution time (ns)
1035 exec_times = Counter()
1036
1037 # This contains the last `sched_switch` timestamp
1038 last_ts = None
1039
1040 # Iterate on events
1041 for event in col.events:
1042 # Keep only `sched_switch` events
1043 if event.name != 'sched_switch':
1044 continue
1045
1046 # Keep only events which happened on CPU 0
1047 if event['cpu_id'] != 0:
1048 continue
1049
1050 # Event timestamp
1051 cur_ts = event.timestamp
1052
1053 if last_ts is None:
1054 # We start here
1055 last_ts = cur_ts
1056
1057 # Previous task command (short) name
1058 prev_comm = event['prev_comm']
1059
1060 # Initialize entry in our dict if not yet done
1061 if prev_comm not in exec_times:
1062 exec_times[prev_comm] = 0
1063
1064 # Compute previous command execution time
1065 diff = cur_ts - last_ts
1066
1067 # Update execution time of this command
1068 exec_times[prev_comm] += diff
1069
1070 # Update last timestamp
1071 last_ts = cur_ts
1072
1073 # Display top 5
1074 for name, ns in exec_times.most_common(5):
1075 s = ns / 1000000000
1076 print('{:20}{} s'.format(name, s))
1077
1078 return True
1079
1080
1081if __name__ == '__main__':
1082 sys.exit(0 if top5proc() else 1)
1083----
1084
1085Run this script:
1086
1087[role="term"]
1088----
1089python3 top5proc.py ~/lttng-traces/my-kernel-session*/kernel
1090----
1091
1092Output example:
1093
1094----
1095swapper/0 48.607245889 s
1096chromium 7.192738188 s
1097pavucontrol 0.709894415 s
1098Compositor 0.660867933 s
1099Xorg.bin 0.616753786 s
1100----
1101
1102Note that `swapper/0` is the "idle" process of CPU 0 on Linux; since we
1103weren't using the CPU that much when tracing, its first position in the
1104list makes sense.
1105
1106
1107[[core-concepts]]
1108== [[understanding-lttng]]Core concepts
1109
1110From a user's perspective, the LTTng system is built on a few concepts,
1111or objects, on which the <<lttng-cli,cmd:lttng command-line tool>>
1112operates by sending commands to the <<lttng-sessiond,session daemon>>.
1113Understanding how those objects relate to eachother is key in mastering
1114the toolkit.
1115
1116The core concepts are:
1117
1118* <<tracing-session,Tracing session>>
1119* <<domain,Tracing domain>>
1120* <<channel,Channel and ring buffer>>
1121* <<"event","Instrumentation point, event rule, event, and event record">>
1122
1123
1124[[tracing-session]]
1125=== Tracing session
1126
1127A _tracing session_ is a stateful dialogue between you and
1128a <<lttng-sessiond,session daemon>>. You can
1129<<creating-destroying-tracing-sessions,create a new tracing
1130session>> with the `lttng create` command.
1131
1132Anything that you do when you control LTTng tracers happens within a
1133tracing session. In particular, a tracing session:
1134
1135* Has its own name.
1136* Has its own set of trace files.
1137* Has its own state of activity (started or stopped).
1138* Has its own <<tracing-session-mode,mode>> (local, network streaming,
1139 snapshot, or live).
1140* Has its own <<channel,channels>> which have their own
1141 <<event,event rules>>.
1142
1143[role="img-100"]
1144.A _tracing session_ contains <<channel,channels>> that are members of <<domain,tracing domains>> and contain <<event,event rules>>.
1145image::concepts.png[]
1146
1147Those attributes and objects are completely isolated between different
1148tracing sessions.
1149
1150A tracing session is analogous to a cash machine session:
1151the operations you do on the banking system through the cash machine do
1152not alter the data of other users of the same system. In the case of
1153the cash machine, a session lasts as long as your bank card is inside.
1154In the case of LTTng, a tracing session lasts from the `lttng create`
1155command to the `lttng destroy` command.
1156
1157[role="img-100"]
1158.Each Unix user has its own set of tracing sessions.
1159image::many-sessions.png[]
1160
1161
1162[[tracing-session-mode]]
1163==== Tracing session mode
1164
1165LTTng can send the generated trace data to different locations. The
1166_tracing session mode_ dictates where to send it. The following modes
1167are available in LTTng{nbsp}{revision}:
1168
1169Local mode::
1170 LTTng writes the traces to the file system of the machine being traced
1171 (target system).
1172
1173Network streaming mode::
1174 LTTng sends the traces over the network to a
1175 <<lttng-relayd,relay daemon>> running on a remote system.
1176
1177Snapshot mode::
1178 LTTng does not write the traces by default. Instead, you can request
1179 LTTng to <<taking-a-snapshot,take a snapshot>>, that is, a copy of the
1180 current tracing buffers, and to write it to the target's file system
1181 or to send it over the network to a <<lttng-relayd,relay daemon>>
1182 running on a remote system.
1183
1184Live mode::
1185 This mode is similar to the network streaming mode, but a live
1186 trace viewer can connect to the distant relay daemon to
1187 <<lttng-live,view event records as LTTng generates them>> by
1188 the tracers.
1189
1190
1191[[domain]]
1192=== Tracing domain
1193
1194A _tracing domain_ is a namespace for event sources. A tracing domain
1195has its own properties and features.
1196
1197There are currently five available tracing domains:
1198
1199* Linux kernel
1200* User space
1201* `java.util.logging` (JUL)
1202* log4j
1203* Python
1204
1205You must specify a tracing domain when using some commands to avoid
1206ambiguity. For example, since all the domains support named tracepoints
1207as event sources (instrumentation points that you manually insert in the
1208source code), you need to specify a tracing domain when
1209<<enabling-disabling-events,creating an event rule>> because all the
1210tracing domains could have tracepoints with the same names.
1211
1212Some features are reserved to specific tracing domains. Dynamic function
1213entry and return instrumentation points, for example, are currently only
1214supported in the Linux kernel tracing domain, but support for other
1215tracing domains could be added in the future.
1216
1217You can create <<channel,channels>> in the Linux kernel and user space
1218tracing domains. The other tracing domains have a single default
1219channel.
1220
1221
1222[[channel]]
1223=== Channel and ring buffer
1224
1225A _channel_ is an object which is responsible for a set of ring buffers.
1226Each ring buffer is divided into multiple sub-buffers. When an LTTng
1227tracer emits an event, it can record it to one or more
1228sub-buffers. The attributes of a channel determine what to do when
1229there's no space left for a new event record because all sub-buffers
1230are full, where to send a full sub-buffer, and other behaviours.
1231
1232A channel is always associated to a <<domain,tracing domain>>. The
1233`java.util.logging` (JUL), log4j, and Python tracing domains each have
1234a default channel which you cannot configure.
1235
1236A channel also owns <<event,event rules>>. When an LTTng tracer emits
1237an event, it records it to the sub-buffers of all
1238the enabled channels with a satisfied event rule, as long as those
1239channels are part of active <<tracing-session,tracing sessions>>.
1240
1241
1242[[channel-buffering-schemes]]
1243==== Per-user vs. per-process buffering schemes
1244
1245A channel has at least one ring buffer _per CPU_. LTTng always
1246records an event to the ring buffer associated to the CPU on which it
1247occurred.
1248
1249Two _buffering schemes_ are available when you
1250<<enabling-disabling-channels,create a channel>> in the
1251user space <<domain,tracing domain>>:
1252
1253Per-user buffering::
1254 Allocate one set of ring buffers--one per CPU--shared by all the
1255 instrumented processes of each Unix user.
1256+
1257--
1258[role="img-100"]
1259.Per-user buffering scheme.
1260image::per-user-buffering.png[]
1261--
1262
1263Per-process buffering::
1264 Allocate one set of ring buffers--one per CPU--for each
1265 instrumented process.
1266+
1267--
1268[role="img-100"]
1269.Per-process buffering scheme.
1270image::per-process-buffering.png[]
1271--
1272+
1273The per-process buffering scheme tends to consume more memory than the
1274per-user option because systems generally have more instrumented
1275processes than Unix users running instrumented processes. However, the
1276per-process buffering scheme ensures that one process having a high
1277event throughput won't fill all the shared sub-buffers of the same
1278user, only its own.
1279
1280The Linux kernel tracing domain has only one available buffering scheme
1281which is to allocate a single set of ring buffers for the whole system.
1282This scheme is similar to the per-user option, but with a single, global
1283user "running" the kernel.
1284
1285
1286[[channel-overwrite-mode-vs-discard-mode]]
1287==== Overwrite vs. discard event loss modes
1288
1289When an event occurs, LTTng records it to a specific sub-buffer (yellow
1290arc in the following animation) of a specific channel's ring buffer.
1291When there's no space left in a sub-buffer, the tracer marks it as
1292consumable (red) and another, empty sub-buffer starts receiving the
1293following event records. A <<lttng-consumerd,consumer daemon>>
1294eventually consumes the marked sub-buffer (returns to white).
1295
1296[NOTE]
1297[role="docsvg-channel-subbuf-anim"]
1298====
1299{note-no-anim}
1300====
1301
1302In an ideal world, sub-buffers are consumed faster than they are filled,
1303as is the case in the previous animation. In the real world,
1304however, all sub-buffers can be full at some point, leaving no space to
1305record the following events.
1306
1307By design, LTTng is a _non-blocking_ tracer: when no empty sub-buffer is
1308available, it is acceptable to lose event records when the alternative
1309would be to cause substantial delays in the instrumented application's
1310execution. LTTng privileges performance over integrity; it aims at
1311perturbing the traced system as little as possible in order to make
1312tracing of subtle race conditions and rare interrupt cascades possible.
1313
1314When it comes to losing event records because no empty sub-buffer is
1315available, the channel's _event loss mode_ determines what to do. The
1316available event loss modes are:
1317
1318Discard mode::
1319 Drop the newest event records until a the tracer
1320 releases a sub-buffer.
1321
1322Overwrite mode::
1323 Clear the sub-buffer containing the oldest event records and start
1324 writing the newest event records there.
1325+
1326This mode is sometimes called _flight recorder mode_ because it's
1327similar to a
1328https://en.wikipedia.org/wiki/Flight_recorder[flight recorder]:
1329always keep a fixed amount of the latest data.
1330
1331Which mechanism you should choose depends on your context: prioritize
1332the newest or the oldest event records in the ring buffer?
1333
1334Beware that, in overwrite mode, the tracer abandons a whole sub-buffer
1335as soon as a there's no space left for a new event record, whereas in
1336discard mode, the tracer only discards the event record that doesn't
1337fit.
1338
1339In discard mode, LTTng increments a count of lost event records when
1340an event record is lost and saves this count to the trace. In
1341overwrite mode, LTTng keeps no information when it overwrites a
1342sub-buffer before consuming it.
1343
1344There are a few ways to decrease your probability of losing event
1345records.
1346<<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>> shows
1347how you can fine-une the sub-buffer count and size of a channel to
1348virtually stop losing event records, though at the cost of greater
1349memory usage.
1350
1351
1352[[channel-subbuf-size-vs-subbuf-count]]
1353==== Sub-buffer count and size
1354
1355When you <<enabling-disabling-channels,create a channel>>, you can
1356set its number of sub-buffers and their size.
1357
1358Note that there is noticeable CPU overhead introduced when
1359switching sub-buffers (marking a full one as consumable and switching
1360to an empty one for the following events to be recorded). Knowing this,
1361the following list presents a few practical situations along with how
1362to configure the sub-buffer count and size for them:
1363
1364* **High event throughput**: In general, prefer bigger sub-buffers to
1365 lower the risk of losing event records.
1366+
1367Having bigger sub-buffers also ensures a lower sub-buffer switching
1368frequency.
1369+
1370The number of sub-buffers is only meaningful if you create the channel
1371in overwrite mode: in this case, if a sub-buffer overwrite happens, the
1372other sub-buffers are left unaltered.
1373
1374* **Low event throughput**: In general, prefer smaller sub-buffers
1375 since the risk of losing event records is low.
1376+
1377Because events occur less frequently, the sub-buffer switching frequency
1378should remain low and thus the tracer's overhead should not be a
1379problem.
1380
1381* **Low memory system**: If your target system has a low memory
1382 limit, prefer fewer first, then smaller sub-buffers.
1383+
1384Even if the system is limited in memory, you want to keep the
1385sub-buffers as big as possible to avoid a high sub-buffer switching
1386frequency.
1387
1388Note that LTTng uses http://diamon.org/ctf/[CTF] as its trace format,
1389which means event data is very compact. For example, the average
1390LTTng kernel event record weights about 32{nbsp}bytes. Thus, a
1391sub-buffer size of 1{nbsp}MiB is considered big.
1392
1393The previous situations highlight the major trade-off between a few big
1394sub-buffers and more, smaller sub-buffers: sub-buffer switching
1395frequency vs. how much data is lost in overwrite mode. Assuming a
1396constant event throughput and using the overwrite mode, the two
1397following configurations have the same ring buffer total size:
1398
1399[NOTE]
1400[role="docsvg-channel-subbuf-size-vs-count-anim"]
1401====
1402{note-no-anim}
1403====
1404
1405* **2 sub-buffers of 4{nbsp}MiB each**: Expect a very low sub-buffer
1406 switching frequency, but if a sub-buffer overwrite happens, half of
1407 the event records so far (4{nbsp}MiB) are definitely lost.
1408* **8 sub-buffers of 1{nbsp}MiB each**: Expect 4{nbsp}times the tracer's
1409 overhead as the previous configuration, but if a sub-buffer
1410 overwrite happens, only the eighth of event records so far are
1411 definitely lost.
1412
1413In discard mode, the sub-buffers count parameter is pointless: use two
1414sub-buffers and set their size according to the requirements of your
1415situation.
1416
1417
1418[[channel-switch-timer]]
1419==== Switch timer period
1420
1421The _switch timer period_ is an important configurable attribute of
1422a channel to ensure periodic sub-buffer flushing.
1423
1424When the _switch timer_ expires, a sub-buffer switch happens. You can
1425set the switch timer period attribute when you
1426<<enabling-disabling-channels,create a channel>> to ensure that event
1427data is consumed and committed to trace files or to a distant relay
1428daemon periodically in case of a low event throughput.
1429
1430[NOTE]
1431[role="docsvg-channel-switch-timer"]
1432====
1433{note-no-anim}
1434====
1435
1436This attribute is also convenient when you use big sub-buffers to cope
1437with a sporadic high event throughput, even if the throughput is
1438normally low.
1439
1440
1441[[channel-read-timer]]
1442==== Read timer period
1443
1444By default, the LTTng tracers use a notification mechanism to signal a
1445full sub-buffer so that a consumer daemon can consume it. When such
1446notifications must be avoided, for example in real-time applications,
1447you can use the channel's _read timer_ instead. When the read timer
1448fires, the <<lttng-consumerd,consumer daemon>> checks for full,
1449consumable sub-buffers.
1450
1451
1452[[tracefile-rotation]]
1453==== Trace file count and size
1454
1455By default, trace files can grow as large as needed. You can set the
1456maximum size of each trace file that a channel writes when you
1457<<enabling-disabling-channels,create a channel>>. When the size of
1458a trace file reaches the channel's fixed maximum size, LTTng creates
1459another file to contain the next event records. LTTng appends a file
1460count to each trace file name in this case.
1461
1462If you set the trace file size attribute when you create a channel, the
1463maximum number of trace files that LTTng creates is _unlimited_ by
1464default. To limit them, you can also set a maximum number of trace
1465files. When the number of trace files reaches the channel's fixed
1466maximum count, the oldest trace file is overwritten. This mechanism is
1467called _trace file rotation_.
1468
1469
1470[[event]]
1471=== Instrumentation point, event rule, event, and event record
1472
1473An _event rule_ is a set of conditions which must be **all** satisfied
1474for LTTng to record an occuring event.
1475
1476You set the conditions when you <<enabling-disabling-events,create
1477an event rule>>.
1478
1479You always attach an event rule to <<channel,channel>> when you create
1480it.
1481
1482When an event passes the conditions of an event rule, LTTng records it
1483in one of the attached channel's sub-buffers.
1484
1485The available conditions, as of LTTng{nbsp}{revision}, are:
1486
1487* The event rule _is enabled_.
1488* The instrumentation point's type _is{nbsp}T_.
1489* The instrumentation point's name (sometimes called _event name_)
1490 _matches{nbsp}N_, but _is not{nbsp}E_.
1491* The instrumentation point's log level _is as severe as{nbsp}L_, or
1492 _is exactly{nbsp}L_.
1493* The fields of the event's payload _satisfy_ a filter
1494 expression{nbsp}__F__.
1495
1496As you can see, all the conditions but the dynamic filter are related to
1497the event rule's status or to the instrumentation point, not to the
1498occurring events. This is why, without a filter, checking if an event
1499passes an event rule is not a dynamic task: when you create or modify an
1500event rule, all the tracers of its tracing domain enable or disable the
1501instrumentation points themselves once. This is possible because the
1502attributes of an instrumentation point (type, name, and log level) are
1503defined statically. In other words, without a dynamic filter, the tracer
1504_does not evaluate_ the arguments of an instrumentation point unless it
1505matches an enabled event rule.
1506
1507Note that, for LTTng to record an event, the <<channel,channel>> to
1508which a matching event rule is attached must also be enabled, and the
1509tracing session owning this channel must be active.
1510
1511[role="img-100"]
1512.Logical path from an instrumentation point to an event record.
1513image::event-rule.png[]
1514
1515.Event, event record, or event rule?
1516****
1517With so many similar terms, it's easy to get confused.
1518
1519An **event** is the consequence of the execution of an _instrumentation
1520point_, like a tracepoint that you manually place in some source code,
1521or a Linux kernel KProbe. An event is said to _occur_ at a specific
1522time. Different actions can be taken upon the occurance of an event,
1523like record the event's payload to a buffer.
1524
1525An **event record** is the representation of an event in a sub-buffer. A
1526tracer is responsible for capturing the payload of an event, current
1527context variables, the event's ID, and the event's timestamp. LTTng
1528can append this sub-buffer to a trace file.
1529
1530An **event rule** is a set of conditions which must all be satisfied for
1531LTTng to record an occuring event. Events still occur without
1532satisfying event rules, but LTTng does not record them.
1533****
1534
1535
1536[[plumbing]]
1537== Components of noch:{LTTng}
1538
1539The second _T_ in _LTTng_ stands for _toolkit_: it would be wrong
1540to call LTTng a simple _tool_ since it is composed of multiple
1541interacting components. This section describes those components,
1542explains their respective roles, and shows how they connect together to
1543form the LTTng ecosystem.
1544
1545The following diagram shows how the most important components of LTTng
1546interact with user applications, the Linux kernel, and you:
1547
1548[role="img-100"]
1549.Control and trace data paths between LTTng components.
1550image::plumbing.png[]
1551
1552The LTTng project incorporates:
1553
1554* **LTTng-tools**: Libraries and command-line interface to
1555 control tracing sessions.
1556** <<lttng-sessiond,Session daemon>> (man:lttng-sessiond(8)).
1557** <<lttng-consumerd,Consumer daemon>> (man:lttng-consumerd(8)).
1558** <<lttng-relayd,Relay daemon>> (man:lttng-relayd(8)).
1559** <<liblttng-ctl-lttng,Tracing control library>> (`liblttng-ctl`).
1560** <<lttng-cli,Tracing control command-line tool>> (man:lttng(1)).
1561* **LTTng-UST**: Libraries and Java/Python packages to trace user
1562 applications.
1563** <<lttng-ust,User space tracing library>> (`liblttng-ust`) and its
1564 headers to instrument and trace any native user application.
1565** <<prebuilt-ust-helpers,Preloadable user space tracing helpers>>:
1566*** `liblttng-ust-libc-wrapper`
1567*** `liblttng-ust-pthread-wrapper`
1568*** `liblttng-ust-cyg-profile`
1569*** `liblttng-ust-cyg-profile-fast`
1570*** `liblttng-ust-dl`
1571** User space tracepoint provider source files generator command-line
1572 tool (man:lttng-gen-tp(1)).
1573** <<lttng-ust-agents,LTTng-UST Java agent>> to instrument and trace
1574 Java applications using `java.util.logging` or
1575 Apache log4j 1.2 logging.
1576** <<lttng-ust-agents,LTTng-UST Python agent>> to instrument
1577 Python applications using the standard `logging` package.
1578* **LTTng-modules**: <<lttng-modules,Linux kernel modules>> to trace
1579 the kernel.
1580** LTTng kernel tracer module.
1581** Tracing ring buffer kernel modules.
1582** Probe kernel modules.
1583** LTTng logger kernel module.
1584
1585
1586[[lttng-cli]]
1587=== Tracing control command-line interface
1588
1589[role="img-100"]
1590.The tracing control command-line interface.
1591image::plumbing-lttng-cli.png[]
1592
1593The _man:lttng(1) command-line tool_ is the standard user interface to
1594control LTTng <<tracing-session,tracing sessions>>. The cmd:lttng tool
1595is part of LTTng-tools.
1596
1597The cmd:lttng tool is linked with
1598<<liblttng-ctl-lttng,`liblttng-ctl`>> to communicate with
1599one or more <<lttng-sessiond,session daemons>> behind the scenes.
1600
1601The cmd:lttng tool has a Git-like interface:
1602
1603[role="term"]
1604----
1605lttng <general options> <command> <command options>
1606----
1607
1608The <<controlling-tracing,Tracing control>> section explores the
1609available features of LTTng using the cmd:lttng tool.
1610
1611
1612[[liblttng-ctl-lttng]]
1613=== Tracing control library
1614
1615[role="img-100"]
1616.The tracing control library.
1617image::plumbing-liblttng-ctl.png[]
1618
1619The _LTTng control library_, `liblttng-ctl`, is used to communicate
1620with a <<lttng-sessiond,session daemon>> using a C API that hides the
1621underlying protocol's details. `liblttng-ctl` is part of LTTng-tools.
1622
1623The <<lttng-cli,cmd:lttng command-line tool>>
1624is linked with `liblttng-ctl`.
1625
1626You can use `liblttng-ctl` in C or $$C++$$ source code by including its
1627"master" header:
1628
1629[source,c]
1630----
1631#include <lttng/lttng.h>
1632----
1633
1634Some objects are referenced by name (C string), such as tracing
1635sessions, but most of them require to create a handle first using
1636`lttng_create_handle()`.
1637
1638The best available developer documentation for `liblttng-ctl` is, as of
1639LTTng{nbsp}{revision}, its installed header files. Every function and
1640structure is thoroughly documented.
1641
1642
1643[[lttng-ust]]
1644=== User space tracing library
1645
1646[role="img-100"]
1647.The user space tracing library.
1648image::plumbing-liblttng-ust.png[]
1649
1650The _user space tracing library_, `liblttng-ust` (see man:lttng-ust(3)),
1651is the LTTng user space tracer. It receives commands from a
1652<<lttng-sessiond,session daemon>>, for example to
1653enable and disable specific instrumentation points, and writes event
1654records to ring buffers shared with a
1655<<lttng-consumerd,consumer daemon>>.
1656`liblttng-ust` is part of LTTng-UST.
1657
1658Public C header files are installed beside `liblttng-ust` to
1659instrument any <<c-application,C or $$C++$$ application>>.
1660
1661<<lttng-ust-agents,LTTng-UST agents>>, which are regular Java and Python
1662packages, use their own library providing tracepoints which is
1663linked with `liblttng-ust`.
1664
1665An application or library does not have to initialize `liblttng-ust`
1666manually: its constructor does the necessary tasks to properly register
1667to a session daemon. The initialization phase also enables the
1668instrumentation points matching the <<event,event rules>> that you
1669already created.
1670
1671
1672[[lttng-ust-agents]]
1673=== User space tracing agents
1674
1675[role="img-100"]
1676.The user space tracing agents.
1677image::plumbing-lttng-ust-agents.png[]
1678
1679The _LTTng-UST Java and Python agents_ are regular Java and Python
1680packages which add LTTng tracing capabilities to the
1681native logging frameworks. The LTTng-UST agents are part of LTTng-UST.
1682
1683In the case of Java, the
1684https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[`java.util.logging`
1685core logging facilities] and
1686https://logging.apache.org/log4j/1.2/[Apache log4j 1.2] are supported.
1687Note that Apache Log4{nbsp}2 is not supported.
1688
1689In the case of Python, the standard
1690https://docs.python.org/3/library/logging.html[`logging`] package
1691is supported. Both Python 2 and Python 3 modules can import the
1692LTTng-UST Python agent package.
1693
1694The applications using the LTTng-UST agents are in the
1695`java.util.logging` (JUL),
1696log4j, and Python <<domain,tracing domains>>.
1697
1698Both agents use the same mechanism to trace the log statements. When an
1699agent is initialized, it creates a log handler that attaches to the root
1700logger. The agent also registers to a <<lttng-sessiond,session daemon>>.
1701When the application executes a log statement, it is passed to the
1702agent's log handler by the root logger. The agent's log handler calls a
1703native function in a tracepoint provider package shared library linked
1704with <<lttng-ust,`liblttng-ust`>>, passing the formatted log message and
1705other fields, like its logger name and its log level. This native
1706function contains a user space instrumentation point, hence tracing the
1707log statement.
1708
1709The log level condition of an
1710<<event,event rule>> is considered when tracing
1711a Java or a Python application, and it's compatible with the standard
1712JUL, log4j, and Python log levels.
1713
1714
1715[[lttng-modules]]
1716=== LTTng kernel modules
1717
1718[role="img-100"]
1719.The LTTng kernel modules.
1720image::plumbing-lttng-modules.png[]
1721
1722The _LTTng kernel modules_ are a set of Linux kernel modules
1723which implement the kernel tracer of the LTTng project. The LTTng
1724kernel modules are part of LTTng-modules.
1725
1726The LTTng kernel modules include:
1727
1728* A set of _probe_ modules.
1729+
1730Each module attaches to a specific subsystem
1731of the Linux kernel using its tracepoint instrument points. There are
1732also modules to attach to the entry and return points of the Linux
1733system call functions.
1734
1735* _Ring buffer_ modules.
1736+
1737A ring buffer implementation is provided as kernel modules. The LTTng
1738kernel tracer writes to the ring buffer; a
1739<<lttng-consumerd,consumer daemon>> reads from the ring buffer.
1740
1741* The _LTTng kernel tracer_ module.
1742* The _LTTng logger_ module.
1743+
1744The LTTng logger module implements the special path:{/proc/lttng-logger}
1745file so that any executable can generate LTTng events by opening and
1746writing to this file.
1747+
1748See <<proc-lttng-logger-abi,LTTng logger>>.
1749
1750Generally, you do not have to load the LTTng kernel modules manually
1751(using man:modprobe(8), for example): a root <<lttng-sessiond,session
1752daemon>> loads the necessary modules when starting. If you have extra
1753probe modules, you can specify to load them to the session daemon on
1754the command line.
1755
1756The LTTng kernel modules are installed in
1757+/usr/lib/modules/__release__/extra+ by default, where +__release__+ is
1758the kernel release (see `uname --kernel-release`).
1759
1760
1761[[lttng-sessiond]]
1762=== Session daemon
1763
1764[role="img-100"]
1765.The session daemon.
1766image::plumbing-sessiond.png[]
1767
1768The _session daemon_, man:lttng-sessiond(8), is a daemon responsible for
1769managing tracing sessions and for controlling the various components of
1770LTTng. The session daemon is part of LTTng-tools.
1771
1772The session daemon sends control requests to and receives control
1773responses from:
1774
1775* The <<lttng-ust,user space tracing library>>.
1776+
1777Any instance of the user space tracing library first registers to
1778a session daemon. Then, the session daemon can send requests to
1779this instance, such as:
1780+
1781--
1782** Get the list of tracepoints.
1783** Share an <<event,event rule>> so that the user space tracing library
1784 can enable or disable tracepoints. Amongst the possible conditions
1785 of an event rule is a filter expression which `liblttng-ust` evalutes
1786 when an event occurs.
1787** Share <<channel,channel>> attributes and ring buffer locations.
1788--
1789+
1790The session daemon and the user space tracing library use a Unix
1791domain socket for their communication.
1792
1793* The <<lttng-ust-agents,user space tracing agents>>.
1794+
1795Any instance of a user space tracing agent first registers to
1796a session daemon. Then, the session daemon can send requests to
1797this instance, such as:
1798+
1799--
1800** Get the list of loggers.
1801** Enable or disable a specific logger.
1802--
1803+
1804The session daemon and the user space tracing agent use a TCP connection
1805for their communication.
1806
1807* The <<lttng-modules,LTTng kernel tracer>>.
1808* The <<lttng-consumerd,consumer daemon>>.
1809+
1810The session daemon sends requests to the consumer daemon to instruct
1811it where to send the trace data streams, amongst other information.
1812
1813* The <<lttng-relayd,relay daemon>>.
1814
1815The session daemon receives commands from the
1816<<liblttng-ctl-lttng,tracing control library>>.
1817
1818The root session daemon loads the appropriate
1819<<lttng-modules,LTTng kernel modules>> on startup. It also spawns
1820a <<lttng-consumerd,consumer daemon>> as soon as you create
1821an <<event,event rule>>.
1822
1823The session daemon does not send and receive trace data: this is the
1824role of the <<lttng-consumerd,consumer daemon>> and
1825<<lttng-relayd,relay daemon>>. It does, however, generate the
1826http://diamon.org/ctf/[CTF] metadata stream.
1827
1828Each Unix user can have its own session daemon instance. The
1829tracing sessions managed by different session daemons are completely
1830independent.
1831
1832The root user's session daemon is the only one which is
1833allowed to control the LTTng kernel tracer, and its spawned consumer
1834daemon is the only one which is allowed to consume trace data from the
1835LTTng kernel tracer. Note, however, that any Unix user which is a member
1836of the <<tracing-group,tracing group>> is allowed
1837to create <<channel,channels>> in the
1838Linux kernel <<domain,tracing domain>>, and thus to trace the Linux
1839kernel.
1840
1841The <<lttng-cli,cmd:lttng command-line tool>> automatically starts a
1842session daemon when using its `create` command if none is currently
1843running. You can also start the session daemon manually.
1844
1845
1846[[lttng-consumerd]]
1847=== Consumer daemon
1848
1849[role="img-100"]
1850.The consumer daemon.
1851image::plumbing-consumerd.png[]
1852
1853The _consumer daemon_, man:lttng-consumerd(8), is a daemon which shares
1854ring buffers with user applications or with the LTTng kernel modules to
1855collect trace data and send it to some location (on disk or to a
1856<<lttng-relayd,relay daemon>> over the network). The consumer daemon
1857is part of LTTng-tools.
1858
1859You do not start a consumer daemon manually: a consumer daemon is always
1860spawned by a <<lttng-sessiond,session daemon>> as soon as you create an
1861<<event,event rule>>, that is, before you start tracing. When you kill
1862its owner session daemon, the consumer daemon also exits because it is
1863the session daemon's child process. Command-line options of
1864man:lttng-sessiond(8) target the consumer daemon process.
1865
1866There are up to two running consumer daemons per Unix user, whereas only
1867one session daemon can run per user. This is because each process can be
1868either 32-bit or 64-bit: if the target system runs a mixture of 32-bit
1869and 64-bit processes, it is more efficient to have separate
1870corresponding 32-bit and 64-bit consumer daemons. The root user is an
1871exception: it can have up to _three_ running consumer daemons: 32-bit
1872and 64-bit instances for its user applications, and one more
1873reserved for collecting kernel trace data.
1874
1875
1876[[lttng-relayd]]
1877=== Relay daemon
1878
1879[role="img-100"]
1880.The relay daemon.
1881image::plumbing-relayd.png[]
1882
1883The _relay daemon_, man:lttng-relayd(8), is a daemon acting as a bridge
1884between remote session and consumer daemons, local trace files, and a
1885remote live trace viewer. The relay daemon is part of LTTng-tools.
1886
1887The main purpose of the relay daemon is to implement a receiver of
1888<<sending-trace-data-over-the-network,trace data over the network>>.
1889This is useful when the target system does not have much file system
1890space to record trace files locally.
1891
1892The relay daemon is also a server to which a
1893<<lttng-live,live trace viewer>> can
1894connect. The live trace viewer sends requests to the relay daemon to
1895receive trace data as the target system emits events. The
1896communication protocol is named _LTTng live_; it is used over TCP
1897connections.
1898
1899Note that you can start the relay daemon on the target system directly.
1900This is the setup of choice when the use case is to view events as
1901the target system emits them without the need of a remote system.
1902
1903
1904[[instrumenting]]
1905== [[using-lttng]]Instrumentation
1906
1907There are many examples of tracing and monitoring in our everyday life:
1908
1909* You have access to real-time and historical weather reports and
1910 forecasts thanks to weather stations installed around the country.
1911* You know your heart is safe thanks to an electrocardiogram.
1912* You make sure not to drive your car too fast and to have enough fuel
1913 to reach your destination thanks to gauges visible on your dashboard.
1914
1915All the previous examples have something in common: they rely on
1916**instruments**. Without the electrodes attached to the surface of your
1917body's skin, cardiac monitoring is futile.
1918
1919LTTng, as a tracer, is no different from those real life examples. If
1920you're about to trace a software system or, in other words, record its
1921history of execution, you better have **instrumentation points** in the
1922subject you're tracing, that is, the actual software.
1923
1924Various ways were developed to instrument a piece of software for LTTng
1925tracing. The most straightforward one is to manually place
1926instrumentation points, called _tracepoints_, in the software's source
1927code. It is also possible to add instrumentation points dynamically in
1928the Linux kernel <<domain,tracing domain>>.
1929
1930If you're only interested in tracing the Linux kernel, your
1931instrumentation needs are probably already covered by LTTng's built-in
1932<<lttng-modules,Linux kernel tracepoints>>. You may also wish to trace a
1933user application which is already instrumented for LTTng tracing.
1934In such cases, you can skip this whole section and read the topics of
1935the <<controlling-tracing,Tracing control>> section.
1936
1937Many methods are available to instrument a piece of software for LTTng
1938tracing. They are:
1939
1940* <<c-application,User space instrumentation for C and $$C++$$
1941 applications>>.
1942* <<prebuilt-ust-helpers,Prebuilt user space tracing helpers>>.
1943* <<java-application,User space Java agent>>.
1944* <<python-application,User space Python agent>>.
1945* <<proc-lttng-logger-abi,LTTng logger>>.
1946* <<instrumenting-linux-kernel,LTTng kernel tracepoints>>.
1947
1948
1949[[c-application]]
1950=== [[cxx-application]]User space instrumentation for C and $$C++$$ applications
1951
1952The procedure to instrument a C or $$C++$$ user application with
1953the <<lttng-ust,LTTng user space tracing library>>, `liblttng-ust`, is:
1954
1955. <<tracepoint-provider,Create the source files of a tracepoint provider
1956 package>>.
1957. <<probing-the-application-source-code,Add tracepoints to
1958 the application's source code>>.
1959. <<building-tracepoint-providers-and-user-application,Build and link
1960 a tracepoint provider package and the user application>>.
1961
1962If you need quick, man:printf(3)-like instrumentation, you can skip
1963those steps and use <<tracef,`tracef()`>> or <<tracelog,`tracelog()`>>
1964instead.
1965
1966IMPORTANT: You need to <<installing-lttng,install>> LTTng-UST to
1967instrument a user application with `liblttng-ust`.
1968
1969
1970[[tracepoint-provider]]
1971==== Create the source files of a tracepoint provider package
1972
1973A _tracepoint provider_ is a set of compiled functions which provide
1974**tracepoints** to an application, the type of instrumentation point
1975supported by LTTng-UST. Those functions can emit events with
1976user-defined fields and serialize those events as event records to one
1977or more LTTng-UST <<channel,channel>> sub-buffers. The `tracepoint()`
1978macro, which you <<probing-the-application-source-code,insert in a user
1979application's source code>>, calls those functions.
1980
1981A _tracepoint provider package_ is an object file (`.o`) or a shared
1982library (`.so`) which contains one or more tracepoint providers.
1983Its source files are:
1984
1985* One or more <<tpp-header,tracepoint provider header>> (`.h`).
1986* A <<tpp-source,tracepoint provider package source>> (`.c`).
1987
1988A tracepoint provider package is dynamically linked with `liblttng-ust`,
1989the LTTng user space tracer, at run time.
1990
1991[role="img-100"]
1992.User application linked with `liblttng-ust` and containing a tracepoint provider.
1993image::ust-app.png[]
1994
1995NOTE: If you need quick, man:printf(3)-like instrumentation, you can
1996skip creating and using a tracepoint provider and use
1997<<tracef,`tracef()`>> or <<tracelog,`tracelog()`>> instead.
1998
1999
2000[[tpp-header]]
2001===== Create a tracepoint provider header file template
2002
2003A _tracepoint provider header file_ contains the tracepoint
2004definitions of a tracepoint provider.
2005
2006To create a tracepoint provider header file:
2007
2008. Start from this template:
2009+
2010--
2011[source,c]
2012.Tracepoint provider header file template (`.h` file extension).
2013----
2014#undef TRACEPOINT_PROVIDER
2015#define TRACEPOINT_PROVIDER provider_name
2016
2017#undef TRACEPOINT_INCLUDE
2018#define TRACEPOINT_INCLUDE "./tp.h"
2019
2020#if !defined(_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
2021#define _TP_H
2022
2023#include <lttng/tracepoint.h>
2024
2025/*
2026 * Use TRACEPOINT_EVENT(), TRACEPOINT_EVENT_CLASS(),
2027 * TRACEPOINT_EVENT_INSTANCE(), and TRACEPOINT_LOGLEVEL() here.
2028 */
2029
2030#endif /* _TP_H */
2031
2032#include <lttng/tracepoint-event.h>
2033----
2034--
2035
2036. Replace:
2037+
2038* `provider_name` with the name of your tracepoint provider.
2039* `"tp.h"` with the name of your tracepoint provider header file.
2040
2041. Below the `#include <lttng/tracepoint.h>` line, put your
2042 <<defining-tracepoints,tracepoint definitions>>.
2043
2044Your tracepoint provider name must be unique amongst all the possible
2045tracepoint provider names used on the same target system. We
2046suggest to include the name of your project or company in the name,
2047for example, `org_lttng_my_project_tpp`.
2048
2049TIP: [[lttng-gen-tp]]You can use the man:lttng-gen-tp(1) tool to create
2050this boilerplate for you. When using cmd:lttng-gen-tp, all you need to
2051write are the <<defining-tracepoints,tracepoint definitions>>.
2052
2053
2054[[defining-tracepoints]]
2055===== Create a tracepoint definition
2056
2057A _tracepoint definition_ defines, for a given tracepoint:
2058
2059* Its **input arguments**. They are the macro parameters that the
2060 `tracepoint()` macro accepts for this particular tracepoint
2061 in the user application's source code.
2062* Its **output event fields**. They are the sources of event fields
2063 that form the payload of any event that the execution of the
2064 `tracepoint()` macro emits for this particular tracepoint.
2065
2066You can create a tracepoint definition by using the
2067`TRACEPOINT_EVENT()` macro below the `#include <lttng/tracepoint.h>`
2068line in the
2069<<tpp-header,tracepoint provider header file template>>.
2070
2071The syntax of the `TRACEPOINT_EVENT()` macro is:
2072
2073[source,c]
2074.`TRACEPOINT_EVENT()` macro syntax.
2075----
2076TRACEPOINT_EVENT(
2077 /* Tracepoint provider name */
2078 provider_name,
2079
2080 /* Tracepoint name */
2081 tracepoint_name,
2082
2083 /* Input arguments */
2084 TP_ARGS(
2085 arguments
2086 ),
2087
2088 /* Output event fields */
2089 TP_FIELDS(
2090 fields
2091 )
2092)
2093----
2094
2095Replace:
2096
2097* `provider_name` with your tracepoint provider name.
2098* `tracepoint_name` with your tracepoint name.
2099* `arguments` with the <<tpp-def-input-args,input arguments>>.
2100* `fields` with the <<tpp-def-output-fields,output event field>>
2101 definitions.
2102
2103This tracepoint emits events named `provider_name:tracepoint_name`.
2104
2105[IMPORTANT]
2106.Event name's length limitation
2107====
2108The concatenation of the tracepoint provider name and the
2109tracepoint name must not exceed **254 characters**. If it does, the
2110instrumented application compiles and runs, but LTTng throws multiple
2111warnings and you could experience serious issues.
2112====
2113
2114[[tpp-def-input-args]]The syntax of the `TP_ARGS()` macro is:
2115
2116[source,c]
2117.`TP_ARGS()` macro syntax.
2118----
2119TP_ARGS(
2120 type, arg_name
2121)
2122----
2123
2124Replace:
2125
2126* `type` with the C type of the argument.
2127* `arg_name` with the argument name.
2128
2129You can repeat `type` and `arg_name` up to 10 times to have
2130more than one argument.
2131
2132.`TP_ARGS()` usage with three arguments.
2133====
2134[source,c]
2135----
2136TP_ARGS(
2137 int, count,
2138 float, ratio,
2139 const char*, query
2140)
2141----
2142====
2143
2144The `TP_ARGS()` and `TP_ARGS(void)` forms are valid to create a
2145tracepoint definition with no input arguments.
2146
2147[[tpp-def-output-fields]]The `TP_FIELDS()` macro contains a list of
2148`ctf_*()` macros. Each `ctf_*()` macro defines one event field. See
2149man:lttng-ust(3) for a complete description of the available `ctf_*()`
2150macros. A `ctf_*()` macro specifies the type, size, and byte order of
2151one event field.
2152
2153Each `ctf_*()` macro takes an _argument expression_ parameter. This is a
2154C expression that the tracer evalutes at the `tracepoint()` macro site
2155in the application's source code. This expression provides a field's
2156source of data. The argument expression can include input argument names
2157listed in the `TP_ARGS()` macro.
2158
2159Each `ctf_*()` macro also takes a _field name_ parameter. Field names
2160must be unique within a given tracepoint definition.
2161
2162Here's a complete tracepoint definition example:
2163
2164.Tracepoint definition.
2165====
2166The following tracepoint definition defines a tracepoint which takes
2167three input arguments and has four output event fields.
2168
2169[source,c]
2170----
2171#include "my-custom-structure.h"
2172
2173TRACEPOINT_EVENT(
2174 my_provider,
2175 my_tracepoint,
2176 TP_ARGS(
2177 const struct my_custom_structure*, my_custom_structure,
2178 float, ratio,
2179 const char*, query
2180 ),
2181 TP_FIELDS(
2182 ctf_string(query_field, query)
2183 ctf_float(double, ratio_field, ratio)
2184 ctf_integer(int, recv_size, my_custom_structure->recv_size)
2185 ctf_integer(int, send_size, my_custom_structure->send_size)
2186 )
2187)
2188----
2189
2190You can refer to this tracepoint definition with the `tracepoint()`
2191macro in your application's source code like this:
2192
2193[source,c]
2194----
2195tracepoint(my_provider, my_tracepoint,
2196 my_structure, some_ratio, the_query);
2197----
2198====
2199
2200NOTE: The LTTng tracer only evaluates tracepoint arguments at run time
2201if they satisfy an enabled <<event,event rule>>.
2202
2203
2204[[using-tracepoint-classes]]
2205===== Use a tracepoint class
2206
2207A _tracepoint class_ is a class of tracepoints which share the same
2208output event field definitions. A _tracepoint instance_ is one
2209instance of such a defined tracepoint class, with its own tracepoint
2210name.
2211
2212The <<defining-tracepoints,`TRACEPOINT_EVENT()` macro>> is actually a
2213shorthand which defines both a tracepoint class and a tracepoint
2214instance at the same time.
2215
2216When you build a tracepoint provider package, the C or $$C++$$ compiler
2217creates one serialization function for each **tracepoint class**. A
2218serialization function is responsible for serializing the event fields
2219of a tracepoint to a sub-buffer when tracing.
2220
2221For various performance reasons, when your situation requires multiple
2222tracepoint definitions with different names, but with the same event
2223fields, we recommend that you manually create a tracepoint class
2224and instantiate as many tracepoint instances as needed. One positive
2225effect of such a design, amongst other advantages, is that all
2226tracepoint instances of the same tracepoint class reuse the same
2227serialization function, thus reducing
2228https://en.wikipedia.org/wiki/Cache_pollution[cache pollution].
2229
2230.Use a tracepoint class and tracepoint instances.
2231====
2232Consider the following three tracepoint definitions:
2233
2234[source,c]
2235----
2236TRACEPOINT_EVENT(
2237 my_app,
2238 get_account,
2239 TP_ARGS(
2240 int, userid,
2241 size_t, len
2242 ),
2243 TP_FIELDS(
2244 ctf_integer(int, userid, userid)
2245 ctf_integer(size_t, len, len)
2246 )
2247)
2248
2249TRACEPOINT_EVENT(
2250 my_app,
2251 get_settings,
2252 TP_ARGS(
2253 int, userid,
2254 size_t, len
2255 ),
2256 TP_FIELDS(
2257 ctf_integer(int, userid, userid)
2258 ctf_integer(size_t, len, len)
2259 )
2260)
2261
2262TRACEPOINT_EVENT(
2263 my_app,
2264 get_transaction,
2265 TP_ARGS(
2266 int, userid,
2267 size_t, len
2268 ),
2269 TP_FIELDS(
2270 ctf_integer(int, userid, userid)
2271 ctf_integer(size_t, len, len)
2272 )
2273)
2274----
2275
2276In this case, we create three tracepoint classes, with one implicit
2277tracepoint instance for each of them: `get_account`, `get_settings`, and
2278`get_transaction`. However, they all share the same event field names
2279and types. Hence three identical, yet independent serialization
2280functions are created when you build the tracepoint provider package.
2281
2282A better design choice is to define a single tracepoint class and three
2283tracepoint instances:
2284
2285[source,c]
2286----
2287/* The tracepoint class */
2288TRACEPOINT_EVENT_CLASS(
2289 /* Tracepoint provider name */
2290 my_app,
2291
2292 /* Tracepoint class name */
2293 my_class,
2294
2295 /* Input arguments */
2296 TP_ARGS(
2297 int, userid,
2298 size_t, len
2299 ),
2300
2301 /* Output event fields */
2302 TP_FIELDS(
2303 ctf_integer(int, userid, userid)
2304 ctf_integer(size_t, len, len)
2305 )
2306)
2307
2308/* The tracepoint instances */
2309TRACEPOINT_EVENT_INSTANCE(
2310 /* Tracepoint provider name */
2311 my_app,
2312
2313 /* Tracepoint class name */
2314 my_class,
2315
2316 /* Tracepoint name */
2317 get_account,
2318
2319 /* Input arguments */
2320 TP_ARGS(
2321 int, userid,
2322 size_t, len
2323 )
2324)
2325TRACEPOINT_EVENT_INSTANCE(
2326 my_app,
2327 my_class,
2328 get_settings,
2329 TP_ARGS(
2330 int, userid,
2331 size_t, len
2332 )
2333)
2334TRACEPOINT_EVENT_INSTANCE(
2335 my_app,
2336 my_class,
2337 get_transaction,
2338 TP_ARGS(
2339 int, userid,
2340 size_t, len
2341 )
2342)
2343----
2344====
2345
2346
2347[[assigning-log-levels]]
2348===== Assign a log level to a tracepoint definition
2349
2350You can assign an optional _log level_ to a
2351<<defining-tracepoints,tracepoint definition>>.
2352
2353Assigning different levels of severity to tracepoint definitions can
2354be useful: when you <<enabling-disabling-events,create an event rule>>,
2355you can target tracepoints having a log level as severe as a specific
2356value.
2357
2358The concept of LTTng-UST log levels is similar to the levels found
2359in typical logging frameworks:
2360
2361* In a logging framework, the log level is given by the function
2362 or method name you use at the log statement site: `debug()`,
2363 `info()`, `warn()`, `error()`, and so on.
2364* In LTTng-UST, you statically assign the log level to a tracepoint
2365 definition; any `tracepoint()` macro invocation which refers to
2366 this definition has this log level.
2367
2368You can assign a log level to a tracepoint definition with the
2369`TRACEPOINT_LOGLEVEL()` macro. You must use this macro _after_ the
2370<<defining-tracepoints,`TRACEPOINT_EVENT()`>> or
2371<<using-tracepoint-classes,`TRACEPOINT_INSTANCE()`>> macro for a given
2372tracepoint.
2373
2374The syntax of the `TRACEPOINT_LOGLEVEL()` macro is:
2375
2376[source,c]
2377.`TRACEPOINT_LOGLEVEL()` macro syntax.
2378----
2379TRACEPOINT_LOGLEVEL(provider_name, tracepoint_name, log_level)
2380----
2381
2382Replace:
2383
2384* `provider_name` with the tracepoint provider name.
2385* `tracepoint_name` with the tracepoint name.
2386* `log_level` with the log level to assign to the tracepoint
2387 definition named `tracepoint_name` in the `provider_name`
2388 tracepoint provider.
2389+
2390See man:lttng-ust(3) for a list of available log level names.
2391
2392.Assign the `TRACE_DEBUG_UNIT` log level to a tracepoint definition.
2393====
2394[source,c]
2395----
2396/* Tracepoint definition */
2397TRACEPOINT_EVENT(
2398 my_app,
2399 get_transaction,
2400 TP_ARGS(
2401 int, userid,
2402 size_t, len
2403 ),
2404 TP_FIELDS(
2405 ctf_integer(int, userid, userid)
2406 ctf_integer(size_t, len, len)
2407 )
2408)
2409
2410/* Log level assignment */
2411TRACEPOINT_LOGLEVEL(my_app, get_transaction, TRACE_DEBUG_UNIT)
2412----
2413====
2414
2415
2416[[tpp-source]]
2417===== Create a tracepoint provider package source file
2418
2419A _tracepoint provider package source file_ is a C source file which
2420includes a <<tpp-header,tracepoint provider header file>> to expand its
2421macros into event serialization and other functions.
2422
2423You can always use the following tracepoint provider package source
2424file template:
2425
2426[source,c]
2427.Tracepoint provider package source file template.
2428----
2429#define TRACEPOINT_CREATE_PROBES
2430
2431#include "tp.h"
2432----
2433
2434Replace `tp.h` with the name of your <<tpp-header,tracepoint provider
2435header file>> name. You may also include more than one tracepoint
2436provider header file here to create a tracepoint provider package
2437holding more than one tracepoint providers.
2438
2439
2440[[probing-the-application-source-code]]
2441==== Add tracepoints to an application's source code
2442
2443Once you <<tpp-header,create a tracepoint provider header file>>, you
2444can use the `tracepoint()` macro in your application's
2445source code to insert the tracepoints that this header
2446<<defining-tracepoints,defines>>.
2447
2448The `tracepoint()` macro takes at least two parameters: the tracepoint
2449provider name and the tracepoint name. The corresponding tracepoint
2450definition defines the other parameters.
2451
2452.`tracepoint()` usage.
2453====
2454The following <<defining-tracepoints,tracepoint definition>> defines a
2455tracepoint which takes two input arguments and has two output event
2456fields.
2457
2458[source,c]
2459.Tracepoint provider header file.
2460----
2461#include "my-custom-structure.h"
2462
2463TRACEPOINT_EVENT(
2464 my_provider,
2465 my_tracepoint,
2466 TP_ARGS(
2467 int, argc,
2468 const char*, cmd_name
2469 ),
2470 TP_FIELDS(
2471 ctf_string(cmd_name, cmd_name)
2472 ctf_integer(int, number_of_args, argc)
2473 )
2474)
2475----
2476
2477You can refer to this tracepoint definition with the `tracepoint()`
2478macro in your application's source code like this:
2479
2480[source,c]
2481.Application's source file.
2482----
2483#include "tp.h"
2484
2485int main(int argc, char* argv[])
2486{
2487 tracepoint(my_provider, my_tracepoint, argc, argv[0]);
2488
2489 return 0;
2490}
2491----
2492
2493Note how the application's source code includes
2494the tracepoint provider header file containing the tracepoint
2495definitions to use, path:{tp.h}.
2496====
2497
2498.`tracepoint()` usage with a complex tracepoint definition.
2499====
2500Consider this complex tracepoint definition, where multiple event
2501fields refer to the same input arguments in their argument expression
2502parameter:
2503
2504[source,c]
2505.Tracepoint provider header file.
2506----
2507/* For `struct stat` */
2508#include <sys/types.h>
2509#include <sys/stat.h>
2510#include <unistd.h>
2511
2512TRACEPOINT_EVENT(
2513 my_provider,
2514 my_tracepoint,
2515 TP_ARGS(
2516 int, my_int_arg,
2517 char*, my_str_arg,
2518 struct stat*, st
2519 ),
2520 TP_FIELDS(
2521 ctf_integer(int, my_constant_field, 23 + 17)
2522 ctf_integer(int, my_int_arg_field, my_int_arg)
2523 ctf_integer(int, my_int_arg_field2, my_int_arg * my_int_arg)
2524 ctf_integer(int, sum4_field, my_str_arg[0] + my_str_arg[1] +
2525 my_str_arg[2] + my_str_arg[3])
2526 ctf_string(my_str_arg_field, my_str_arg)
2527 ctf_integer_hex(off_t, size_field, st->st_size)
2528 ctf_float(double, size_dbl_field, (double) st->st_size)
2529 ctf_sequence_text(char, half_my_str_arg_field, my_str_arg,
2530 size_t, strlen(my_str_arg) / 2)
2531 )
2532)
2533----
2534
2535You can refer to this tracepoint definition with the `tracepoint()`
2536macro in your application's source code like this:
2537
2538[source,c]
2539.Application's source file.
2540----
2541#define TRACEPOINT_DEFINE
2542#include "tp.h"
2543
2544int main(void)
2545{
2546 struct stat s;
2547
2548 stat("/etc/fstab", &s);
2549 tracepoint(my_provider, my_tracepoint, 23, "Hello, World!", &s);
2550
2551 return 0;
2552}
2553----
2554
2555If you look at the event record that LTTng writes when tracing this
2556program, assuming the file size of path:{/etc/fstab} is 301{nbsp}bytes,
2557it should look like this:
2558
2559.Event record fields
2560|====
2561|Field's name |Field's value
2562|`my_constant_field` |40
2563|`my_int_arg_field` |23
2564|`my_int_arg_field2` |529
2565|`sum4_field` |389
2566|`my_str_arg_field` |`Hello, World!`
2567|`size_field` |0x12d
2568|`size_dbl_field` |301.0
2569|`half_my_str_arg_field` |`Hello,`
2570|====
2571====
2572
2573Sometimes, the arguments you pass to `tracepoint()` are expensive to
2574compute--they use the call stack, for example. To avoid this
2575computation when the tracepoint is disabled, you can use the
2576`tracepoint_enabled()` and `do_tracepoint()` macros.
2577
2578The syntax of the `tracepoint_enabled()` and `do_tracepoint()` macros
2579is:
2580
2581[source,c]
2582.`tracepoint_enabled()` and `do_tracepoint()` macros syntax.
2583----
2584tracepoint_enabled(provider_name, tracepoint_name)
2585do_tracepoint(provider_name, tracepoint_name, ...)
2586----
2587
2588Replace:
2589
2590* `provider_name` with the tracepoint provider name.
2591* `tracepoint_name` with the tracepoint name.
2592
2593`tracepoint_enabled()` returns a non-zero value if the tracepoint named
2594`tracepoint_name` from the provider named `provider_name` is enabled
2595**at run time**.
2596
2597`do_tracepoint()` is like `tracepoint()`, except that it doesn't check
2598if the tracepoint is enabled. Using `tracepoint()` with
2599`tracepoint_enabled()` is dangerous since `tracepoint()` also contains
2600the `tracepoint_enabled()` check, thus a race condition is
2601possible in this situation:
2602
2603[source,c]
2604.Possible race condition when using `tracepoint_enabled()` with `tracepoint()`.
2605----
2606if (tracepoint_enabled(my_provider, my_tracepoint)) {
2607 stuff = prepare_stuff();
2608}
2609
2610tracepoint(my_provider, my_tracepoint, stuff);
2611----
2612
2613If the tracepoint is enabled after the condition, then `stuff` is not
2614prepared: the emitted event will either contain wrong data, or the whole
2615application could crash (segmentation fault, for example).
2616
2617NOTE: Neither `tracepoint_enabled()` nor `do_tracepoint()` have an
2618`STAP_PROBEV()` call. If you need it, you must emit
2619this call yourself.
2620
2621
2622[[building-tracepoint-providers-and-user-application]]
2623==== Build and link a tracepoint provider package and an application
2624
2625Once you have one or more <<tpp-header,tracepoint provider header
2626files>> and a <<tpp-source,tracepoint provider package source file>>,
2627you can create the tracepoint provider package by compiling its source
2628file. From here, multiple build and run scenarios are possible. The
2629following table shows common application and library configurations
2630along with the required command lines to achieve them.
2631
2632In the following diagrams, we use the following file names:
2633
2634`app`::
2635 Executable application.
2636
2637`app.o`::
2638 Application's object file.
2639
2640`tpp.o`::
2641 Tracepoint provider package object file.
2642
2643`tpp.a`::
2644 Tracepoint provider package archive file.
2645
2646`libtpp.so`::
2647 Tracepoint provider package shared object file.
2648
2649`emon.o`::
2650 User library object file.
2651
2652`libemon.so`::
2653 User library shared object file.
2654
2655We use the following symbols in the diagrams of table below:
2656
2657[role="img-100"]
2658.Symbols used in the build scenario diagrams.
2659image::ust-sit-symbols.png[]
2660
2661We assume that path:{.} is part of the env:LD_LIBRARY_PATH environment
2662variable in the following instructions.
2663
2664[role="growable ust-scenarios",cols="asciidoc,asciidoc"]
2665.Common tracepoint provider package scenarios.
2666|====
2667|Scenario |Instructions
2668
2669|
2670The instrumented application is statically linked with
2671the tracepoint provider package object.
2672
2673image::ust-sit+app-linked-with-tp-o+app-instrumented.png[]
2674
2675|
2676include::../common/ust-sit-step-tp-o.txt[]
2677
2678To build the instrumented application:
2679
2680. In path:{app.c}, before including path:{tpp.h}, add the following line:
2681+
2682--
2683[source,c]
2684----
2685#define TRACEPOINT_DEFINE
2686----
2687--
2688
2689. Compile the application source file:
2690+
2691--
2692[role="term"]
2693----
2694gcc -c app.c
2695----
2696--
2697
2698. Build the application:
2699+
2700--
2701[role="term"]
2702----
2703gcc -o app app.o tpp.o -llttng-ust -ldl
2704----
2705--
2706
2707To run the instrumented application:
2708
2709* Start the application:
2710+
2711--
2712[role="term"]
2713----
2714./app
2715----
2716--
2717
2718|
2719The instrumented application is statically linked with the
2720tracepoint provider package archive file.
2721
2722image::ust-sit+app-linked-with-tp-a+app-instrumented.png[]
2723
2724|
2725To create the tracepoint provider package archive file:
2726
2727. Compile the <<tpp-source,tracepoint provider package source file>>:
2728+
2729--
2730[role="term"]
2731----
2732gcc -I. -c tpp.c
2733----
2734--
2735
2736. Create the tracepoint provider package archive file:
2737+
2738--
2739[role="term"]
2740----
2741ar rcs tpp.a tpp.o
2742----
2743--
2744
2745To build the instrumented application:
2746
2747. In path:{app.c}, before including path:{tpp.h}, add the following line:
2748+
2749--
2750[source,c]
2751----
2752#define TRACEPOINT_DEFINE
2753----
2754--
2755
2756. Compile the application source file:
2757+
2758--
2759[role="term"]
2760----
2761gcc -c app.c
2762----
2763--
2764
2765. Build the application:
2766+
2767--
2768[role="term"]
2769----
2770gcc -o app app.o tpp.a -llttng-ust -ldl
2771----
2772--
2773
2774To run the instrumented application:
2775
2776* Start the application:
2777+
2778--
2779[role="term"]
2780----
2781./app
2782----
2783--
2784
2785|
2786The instrumented application is linked with the tracepoint provider
2787package shared object.
2788
2789image::ust-sit+app-linked-with-tp-so+app-instrumented.png[]
2790
2791|
2792include::../common/ust-sit-step-tp-so.txt[]
2793
2794To build the instrumented application:
2795
2796. In path:{app.c}, before including path:{tpp.h}, add the following line:
2797+
2798--
2799[source,c]
2800----
2801#define TRACEPOINT_DEFINE
2802----
2803--
2804
2805. Compile the application source file:
2806+
2807--
2808[role="term"]
2809----
2810gcc -c app.c
2811----
2812--
2813
2814. Build the application:
2815+
2816--
2817[role="term"]
2818----
2819gcc -o app app.o -ldl -L. -ltpp
2820----
2821--
2822
2823To run the instrumented application:
2824
2825* Start the application:
2826+
2827--
2828[role="term"]
2829----
2830./app
2831----
2832--
2833
2834|
2835The tracepoint provider package shared object is preloaded before the
2836instrumented application starts.
2837
2838image::ust-sit+tp-so-preloaded+app-instrumented.png[]
2839
2840|
2841include::../common/ust-sit-step-tp-so.txt[]
2842
2843To build the instrumented application:
2844
2845. In path:{app.c}, before including path:{tpp.h}, add the
2846 following lines:
2847+
2848--
2849[source,c]
2850----
2851#define TRACEPOINT_DEFINE
2852#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
2853----
2854--
2855
2856. Compile the application source file:
2857+
2858--
2859[role="term"]
2860----
2861gcc -c app.c
2862----
2863--
2864
2865. Build the application:
2866+
2867--
2868[role="term"]
2869----
2870gcc -o app app.o -ldl
2871----
2872--
2873
2874To run the instrumented application with tracing support:
2875
2876* Preload the tracepoint provider package shared object and
2877 start the application:
2878+
2879--
2880[role="term"]
2881----
2882LD_PRELOAD=./libtpp.so ./app
2883----
2884--
2885
2886To run the instrumented application without tracing support:
2887
2888* Start the application:
2889+
2890--
2891[role="term"]
2892----
2893./app
2894----
2895--
2896
2897|
2898The instrumented application dynamically loads the tracepoint provider
2899package shared object.
2900
2901See the <<dlclose-warning,warning about `dlclose()`>>.
2902
2903image::ust-sit+app-dlopens-tp-so+app-instrumented.png[]
2904
2905|
2906include::../common/ust-sit-step-tp-so.txt[]
2907
2908To build the instrumented application:
2909
2910. In path:{app.c}, before including path:{tpp.h}, add the
2911 following lines:
2912+
2913--
2914[source,c]
2915----
2916#define TRACEPOINT_DEFINE
2917#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
2918----
2919--
2920
2921. Compile the application source file:
2922+
2923--
2924[role="term"]
2925----
2926gcc -c app.c
2927----
2928--
2929
2930. Build the application:
2931+
2932--
2933[role="term"]
2934----
2935gcc -o app app.o -ldl
2936----
2937--
2938
2939To run the instrumented application:
2940
2941* Start the application:
2942+
2943--
2944[role="term"]
2945----
2946./app
2947----
2948--
2949
2950|
2951The application is linked with the instrumented user library.
2952
2953The instrumented user library is statically linked with the tracepoint
2954provider package object file.
2955
2956image::ust-sit+app-linked-with-lib+lib-linked-with-tp-o+lib-instrumented.png[]
2957
2958|
2959include::../common/ust-sit-step-tp-o-fpic.txt[]
2960
2961To build the instrumented user library:
2962
2963. In path:{emon.c}, before including path:{tpp.h}, add the
2964 following line:
2965+
2966--
2967[source,c]
2968----
2969#define TRACEPOINT_DEFINE
2970----
2971--
2972
2973. Compile the user library source file:
2974+
2975--
2976[role="term"]
2977----
2978gcc -I. -fpic -c emon.c
2979----
2980--
2981
2982. Build the user library shared object:
2983+
2984--
2985[role="term"]
2986----
2987gcc -shared -o libemon.so emon.o tpp.o -llttng-ust -ldl
2988----
2989--
2990
2991To build the application:
2992
2993. Compile the application source file:
2994+
2995--
2996[role="term"]
2997----
2998gcc -c app.c
2999----
3000--
3001
3002. Build the application:
3003+
3004--
3005[role="term"]
3006----
3007gcc -o app app.o -L. -lemon
3008----
3009--
3010
3011To run the application:
3012
3013* Start the application:
3014+
3015--
3016[role="term"]
3017----
3018./app
3019----
3020--
3021
3022|
3023The application is linked with the instrumented user library.
3024
3025The instrumented user library is linked with the tracepoint provider
3026package shared object.
3027
3028image::ust-sit+app-linked-with-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3029
3030|
3031include::../common/ust-sit-step-tp-so.txt[]
3032
3033To build the instrumented user library:
3034
3035. In path:{emon.c}, before including path:{tpp.h}, add the
3036 following line:
3037+
3038--
3039[source,c]
3040----
3041#define TRACEPOINT_DEFINE
3042----
3043--
3044
3045. Compile the user library source file:
3046+
3047--
3048[role="term"]
3049----
3050gcc -I. -fpic -c emon.c
3051----
3052--
3053
3054. Build the user library shared object:
3055+
3056--
3057[role="term"]
3058----
3059gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3060----
3061--
3062
3063To build the application:
3064
3065. Compile the application source file:
3066+
3067--
3068[role="term"]
3069----
3070gcc -c app.c
3071----
3072--
3073
3074. Build the application:
3075+
3076--
3077[role="term"]
3078----
3079gcc -o app app.o -L. -lemon
3080----
3081--
3082
3083To run the application:
3084
3085* Start the application:
3086+
3087--
3088[role="term"]
3089----
3090./app
3091----
3092--
3093
3094|
3095The tracepoint provider package shared object is preloaded before the
3096application starts.
3097
3098The application is linked with the instrumented user library.
3099
3100image::ust-sit+tp-so-preloaded+app-linked-with-lib+lib-instrumented.png[]
3101
3102|
3103include::../common/ust-sit-step-tp-so.txt[]
3104
3105To build the instrumented user library:
3106
3107. In path:{emon.c}, before including path:{tpp.h}, add the
3108 following lines:
3109+
3110--
3111[source,c]
3112----
3113#define TRACEPOINT_DEFINE
3114#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3115----
3116--
3117
3118. Compile the user library source file:
3119+
3120--
3121[role="term"]
3122----
3123gcc -I. -fpic -c emon.c
3124----
3125--
3126
3127. Build the user library shared object:
3128+
3129--
3130[role="term"]
3131----
3132gcc -shared -o libemon.so emon.o -ldl
3133----
3134--
3135
3136To build the application:
3137
3138. Compile the application source file:
3139+
3140--
3141[role="term"]
3142----
3143gcc -c app.c
3144----
3145--
3146
3147. Build the application:
3148+
3149--
3150[role="term"]
3151----
3152gcc -o app app.o -L. -lemon
3153----
3154--
3155
3156To run the application with tracing support:
3157
3158* Preload the tracepoint provider package shared object and
3159 start the application:
3160+
3161--
3162[role="term"]
3163----
3164LD_PRELOAD=./libtpp.so ./app
3165----
3166--
3167
3168To run the application without tracing support:
3169
3170* Start the application:
3171+
3172--
3173[role="term"]
3174----
3175./app
3176----
3177--
3178
3179|
3180The application is linked with the instrumented user library.
3181
3182The instrumented user library dynamically loads the tracepoint provider
3183package shared object.
3184
3185See the <<dlclose-warning,warning about `dlclose()`>>.
3186
3187image::ust-sit+app-linked-with-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3188
3189|
3190include::../common/ust-sit-step-tp-so.txt[]
3191
3192To build the instrumented user library:
3193
3194. In path:{emon.c}, before including path:{tpp.h}, add the
3195 following lines:
3196+
3197--
3198[source,c]
3199----
3200#define TRACEPOINT_DEFINE
3201#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3202----
3203--
3204
3205. Compile the user library source file:
3206+
3207--
3208[role="term"]
3209----
3210gcc -I. -fpic -c emon.c
3211----
3212--
3213
3214. Build the user library shared object:
3215+
3216--
3217[role="term"]
3218----
3219gcc -shared -o libemon.so emon.o -ldl
3220----
3221--
3222
3223To build the application:
3224
3225. Compile the application source file:
3226+
3227--
3228[role="term"]
3229----
3230gcc -c app.c
3231----
3232--
3233
3234. Build the application:
3235+
3236--
3237[role="term"]
3238----
3239gcc -o app app.o -L. -lemon
3240----
3241--
3242
3243To run the application:
3244
3245* Start the application:
3246+
3247--
3248[role="term"]
3249----
3250./app
3251----
3252--
3253
3254|
3255The application dynamically loads the instrumented user library.
3256
3257The instrumented user library is linked with the tracepoint provider
3258package shared object.
3259
3260See the <<dlclose-warning,warning about `dlclose()`>>.
3261
3262image::ust-sit+app-dlopens-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3263
3264|
3265include::../common/ust-sit-step-tp-so.txt[]
3266
3267To build the instrumented user library:
3268
3269. In path:{emon.c}, before including path:{tpp.h}, add the
3270 following line:
3271+
3272--
3273[source,c]
3274----
3275#define TRACEPOINT_DEFINE
3276----
3277--
3278
3279. Compile the user library source file:
3280+
3281--
3282[role="term"]
3283----
3284gcc -I. -fpic -c emon.c
3285----
3286--
3287
3288. Build the user library shared object:
3289+
3290--
3291[role="term"]
3292----
3293gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3294----
3295--
3296
3297To build the application:
3298
3299. Compile the application source file:
3300+
3301--
3302[role="term"]
3303----
3304gcc -c app.c
3305----
3306--
3307
3308. Build the application:
3309+
3310--
3311[role="term"]
3312----
3313gcc -o app app.o -ldl -L. -lemon
3314----
3315--
3316
3317To run the application:
3318
3319* Start the application:
3320+
3321--
3322[role="term"]
3323----
3324./app
3325----
3326--
3327
3328|
3329The application dynamically loads the instrumented user library.
3330
3331The instrumented user library dynamically loads the tracepoint provider
3332package shared object.
3333
3334See the <<dlclose-warning,warning about `dlclose()`>>.
3335
3336image::ust-sit+app-dlopens-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3337
3338|
3339include::../common/ust-sit-step-tp-so.txt[]
3340
3341To build the instrumented user library:
3342
3343. In path:{emon.c}, before including path:{tpp.h}, add the
3344 following lines:
3345+
3346--
3347[source,c]
3348----
3349#define TRACEPOINT_DEFINE
3350#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3351----
3352--
3353
3354. Compile the user library source file:
3355+
3356--
3357[role="term"]
3358----
3359gcc -I. -fpic -c emon.c
3360----
3361--
3362
3363. Build the user library shared object:
3364+
3365--
3366[role="term"]
3367----
3368gcc -shared -o libemon.so emon.o -ldl
3369----
3370--
3371
3372To build the application:
3373
3374. Compile the application source file:
3375+
3376--
3377[role="term"]
3378----
3379gcc -c app.c
3380----
3381--
3382
3383. Build the application:
3384+
3385--
3386[role="term"]
3387----
3388gcc -o app app.o -ldl -L. -lemon
3389----
3390--
3391
3392To run the application:
3393
3394* Start the application:
3395+
3396--
3397[role="term"]
3398----
3399./app
3400----
3401--
3402
3403|
3404The tracepoint provider package shared object is preloaded before the
3405application starts.
3406
3407The application dynamically loads the instrumented user library.
3408
3409image::ust-sit+tp-so-preloaded+app-dlopens-lib+lib-instrumented.png[]
3410
3411|
3412include::../common/ust-sit-step-tp-so.txt[]
3413
3414To build the instrumented user library:
3415
3416. In path:{emon.c}, before including path:{tpp.h}, add the
3417 following lines:
3418+
3419--
3420[source,c]
3421----
3422#define TRACEPOINT_DEFINE
3423#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3424----
3425--
3426
3427. Compile the user library source file:
3428+
3429--
3430[role="term"]
3431----
3432gcc -I. -fpic -c emon.c
3433----
3434--
3435
3436. Build the user library shared object:
3437+
3438--
3439[role="term"]
3440----
3441gcc -shared -o libemon.so emon.o -ldl
3442----
3443--
3444
3445To build the application:
3446
3447. Compile the application source file:
3448+
3449--
3450[role="term"]
3451----
3452gcc -c app.c
3453----
3454--
3455
3456. Build the application:
3457+
3458--
3459[role="term"]
3460----
3461gcc -o app app.o -L. -lemon
3462----
3463--
3464
3465To run the application with tracing support:
3466
3467* Preload the tracepoint provider package shared object and
3468 start the application:
3469+
3470--
3471[role="term"]
3472----
3473LD_PRELOAD=./libtpp.so ./app
3474----
3475--
3476
3477To run the application without tracing support:
3478
3479* Start the application:
3480+
3481--
3482[role="term"]
3483----
3484./app
3485----
3486--
3487
3488|
3489The application is statically linked with the tracepoint provider
3490package object file.
3491
3492The application is linked with the instrumented user library.
3493
3494image::ust-sit+app-linked-with-tp-o+app-linked-with-lib+lib-instrumented.png[]
3495
3496|
3497include::../common/ust-sit-step-tp-o.txt[]
3498
3499To build the instrumented user library:
3500
3501. In path:{emon.c}, before including path:{tpp.h}, add the
3502 following line:
3503+
3504--
3505[source,c]
3506----
3507#define TRACEPOINT_DEFINE
3508----
3509--
3510
3511. Compile the user library source file:
3512+
3513--
3514[role="term"]
3515----
3516gcc -I. -fpic -c emon.c
3517----
3518--
3519
3520. Build the user library shared object:
3521+
3522--
3523[role="term"]
3524----
3525gcc -shared -o libemon.so emon.o
3526----
3527--
3528
3529To build the application:
3530
3531. Compile the application source file:
3532+
3533--
3534[role="term"]
3535----
3536gcc -c app.c
3537----
3538--
3539
3540. Build the application:
3541+
3542--
3543[role="term"]
3544----
3545gcc -o app app.o tpp.o -llttng-ust -ldl -L. -lemon
3546----
3547--
3548
3549To run the instrumented application:
3550
3551* Start the application:
3552+
3553--
3554[role="term"]
3555----
3556./app
3557----
3558--
3559
3560|
3561The application is statically linked with the tracepoint provider
3562package object file.
3563
3564The application dynamically loads the instrumented user library.
3565
3566image::ust-sit+app-linked-with-tp-o+app-dlopens-lib+lib-instrumented.png[]
3567
3568|
3569include::../common/ust-sit-step-tp-o.txt[]
3570
3571To build the application:
3572
3573. In path:{app.c}, before including path:{tpp.h}, add the following line:
3574+
3575--
3576[source,c]
3577----
3578#define TRACEPOINT_DEFINE
3579----
3580--
3581
3582. Compile the application source file:
3583+
3584--
3585[role="term"]
3586----
3587gcc -c app.c
3588----
3589--
3590
3591. Build the application:
3592+
3593--
3594[role="term"]
3595----
3596gcc -Wl,--export-dynamic -o app app.o tpp.o \
3597 -llttng-ust -ldl
3598----
3599--
3600+
3601The `--export-dynamic` option passed to the linker is necessary for the
3602dynamically loaded library to ``see'' the tracepoint symbols defined in
3603the application.
3604
3605To build the instrumented user library:
3606
3607. Compile the user library source file:
3608+
3609--
3610[role="term"]
3611----
3612gcc -I. -fpic -c emon.c
3613----
3614--
3615
3616. Build the user library shared object:
3617+
3618--
3619[role="term"]
3620----
3621gcc -shared -o libemon.so emon.o
3622----
3623--
3624
3625To run the application:
3626
3627* Start the application:
3628+
3629--
3630[role="term"]
3631----
3632./app
3633----
3634--
3635|====
3636
3637[[dlclose-warning]]
3638[IMPORTANT]
3639.Do not use man:dlclose(3) on a tracepoint provider package
3640====
3641Never use man:dlclose(3) on any shared object which:
3642
3643* Is linked with, statically or dynamically, a tracepoint provider
3644 package.
3645* Calls man:dlopen(3) itself to dynamically open a tracepoint provider
3646 package shared object.
3647
3648This is currently considered **unsafe** due to a lack of reference
3649counting from LTTng-UST to the shared object.
3650
3651A known workaround (available since glibc 2.2) is to use the
3652`RTLD_NODELETE` flag when calling man:dlopen(3) initially. This has the
3653effect of not unloading the loaded shared object, even if man:dlclose(3)
3654is called.
3655
3656You can also preload the tracepoint provider package shared object with
3657the env:LD_PRELOAD environment variable to overcome this limitation.
3658====
3659
3660
3661[[using-lttng-ust-with-daemons]]
3662===== Use noch:{LTTng-UST} with daemons
3663
3664If your instrumented application calls man:fork(2), man:clone(2),
3665or BSD's man:rfork(2), without a following man:exec(3)-family
3666system call, you must preload the path:{liblttng-ust-fork.so} shared
3667object when you start the application.
3668
3669[role="term"]
3670----
3671LD_PRELOAD=liblttng-ust-fork.so ./my-app
3672----
3673
3674If your tracepoint provider package is
3675a shared library which you also preload, you must put both
3676shared objects in env:LD_PRELOAD:
3677
3678[role="term"]
3679----
3680LD_PRELOAD=liblttng-ust-fork.so:/path/to/tp.so ./my-app
3681----
3682
3683
3684[role="since-2.9"]
3685[[liblttng-ust-fd]]
3686===== Use noch:{LTTng-UST} with applications which close file descriptors that don't belong to them
3687
3688If your instrumented application closes one or more file descriptors
3689which it did not open itself, you must preload the
3690path:{liblttng-ust-fd.so} shared object when you start the application:
3691
3692[role="term"]
3693----
3694LD_PRELOAD=liblttng-ust-fd.so ./my-app
3695----
3696
3697Typical use cases include closing all the file descriptors after
3698man:fork(2) or man:rfork(2) and buggy applications doing
3699``double closes''.
3700
3701
3702[[lttng-ust-pkg-config]]
3703===== Use noch:{pkg-config}
3704
3705On some distributions, LTTng-UST ships with a
3706https://www.freedesktop.org/wiki/Software/pkg-config/[pkg-config]
3707metadata file. If this is your case, then you can use cmd:pkg-config to
3708build an application on the command line:
3709
3710[role="term"]
3711----
3712gcc -o my-app my-app.o tp.o $(pkg-config --cflags --libs lttng-ust)
3713----
3714
3715
3716[[instrumenting-32-bit-app-on-64-bit-system]]
3717===== [[advanced-instrumenting-techniques]]Build a 32-bit instrumented application for a 64-bit target system
3718
3719In order to trace a 32-bit application running on a 64-bit system,
3720LTTng must use a dedicated 32-bit
3721<<lttng-consumerd,consumer daemon>>.
3722
3723The following steps show how to build and install a 32-bit consumer
3724daemon, which is _not_ part of the default 64-bit LTTng build, how to
3725build and install the 32-bit LTTng-UST libraries, and how to build and
3726link an instrumented 32-bit application in that context.
3727
3728To build a 32-bit instrumented application for a 64-bit target system,
3729assuming you have a fresh target system with no installed Userspace RCU
3730or LTTng packages:
3731
3732. Download, build, and install a 32-bit version of Userspace RCU:
3733+
3734--
3735[role="term"]
3736----
3737cd $(mktemp -d) &&
3738wget http://lttng.org/files/urcu/userspace-rcu-latest-0.9.tar.bz2 &&
3739tar -xf userspace-rcu-latest-0.9.tar.bz2 &&
3740cd userspace-rcu-0.9.* &&
3741./configure --libdir=/usr/local/lib32 CFLAGS=-m32 &&
3742make &&
3743sudo make install &&
3744sudo ldconfig
3745----
3746--
3747
3748. Using your distribution's package manager, or from source, install
3749 the following 32-bit versions of the following dependencies of
3750 LTTng-tools and LTTng-UST:
3751+
3752--
3753* https://sourceforge.net/projects/libuuid/[libuuid]
3754* http://directory.fsf.org/wiki/Popt[popt]
3755* http://www.xmlsoft.org/[libxml2]
3756--
3757
3758. Download, build, and install a 32-bit version of the latest
3759 LTTng-UST{nbsp}{revision}:
3760+
3761--
3762[role="term"]
3763----
3764cd $(mktemp -d) &&
3765wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.9.tar.bz2 &&
3766tar -xf lttng-ust-latest-2.9.tar.bz2 &&
3767cd lttng-ust-2.9.* &&
3768./configure --libdir=/usr/local/lib32 \
3769 CFLAGS=-m32 CXXFLAGS=-m32 \
3770 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' &&
3771make &&
3772sudo make install &&
3773sudo ldconfig
3774----
3775--
3776+
3777[NOTE]
3778====
3779Depending on your distribution,
378032-bit libraries could be installed at a different location than
3781`/usr/lib32`. For example, Debian is known to install
3782some 32-bit libraries in `/usr/lib/i386-linux-gnu`.
3783
3784In this case, make sure to set `LDFLAGS` to all the
3785relevant 32-bit library paths, for example:
3786
3787[role="term"]
3788----
3789LDFLAGS='-L/usr/lib/i386-linux-gnu -L/usr/lib32'
3790----
3791====
3792
3793. Download the latest LTTng-tools{nbsp}{revision}, build, and install
3794 the 32-bit consumer daemon:
3795+
3796--
3797[role="term"]
3798----
3799cd $(mktemp -d) &&
3800wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.9.tar.bz2 &&
3801tar -xf lttng-tools-latest-2.9.tar.bz2 &&
3802cd lttng-tools-2.9.* &&
3803./configure --libdir=/usr/local/lib32 CFLAGS=-m32 CXXFLAGS=-m32 \
3804 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' &&
3805make &&
3806cd src/bin/lttng-consumerd &&
3807sudo make install &&
3808sudo ldconfig
3809----
3810--
3811
3812. From your distribution or from source,
3813 <<installing-lttng,install>> the 64-bit versions of
3814 LTTng-UST and Userspace RCU.
3815. Download, build, and install the 64-bit version of the
3816 latest LTTng-tools{nbsp}{revision}:
3817+
3818--
3819[role="term"]
3820----
3821cd $(mktemp -d) &&
3822wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.9.tar.bz2 &&
3823tar -xf lttng-tools-latest-2.9.tar.bz2 &&
3824cd lttng-tools-2.9.* &&
3825./configure --with-consumerd32-libdir=/usr/local/lib32 \
3826 --with-consumerd32-bin=/usr/local/lib32/lttng/libexec/lttng-consumerd &&
3827make &&
3828sudo make install &&
3829sudo ldconfig
3830----
3831--
3832
3833. Pass the following options to man:gcc(1), man:g++(1), or man:clang(1)
3834 when linking your 32-bit application:
3835+
3836----
3837-m32 -L/usr/lib32 -L/usr/local/lib32 \
3838-Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32
3839----
3840+
3841For example, let's rebuild the quick start example in
3842<<tracing-your-own-user-application,Trace a user application>> as an
3843instrumented 32-bit application:
3844+
3845--
3846[role="term"]
3847----
3848gcc -m32 -c -I. hello-tp.c
3849gcc -m32 -c hello.c
3850gcc -m32 -o hello hello.o hello-tp.o \
3851 -L/usr/lib32 -L/usr/local/lib32 \
3852 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32 \
3853 -llttng-ust -ldl
3854----
3855--
3856
3857No special action is required to execute the 32-bit application and
3858to trace it: use the command-line man:lttng(1) tool as usual.
3859
3860
3861[role="since-2.5"]
3862[[tracef]]
3863==== Use `tracef()`
3864
3865man:tracef(3) is a small LTTng-UST API designed for quick,
3866man:printf(3)-like instrumentation without the burden of
3867<<tracepoint-provider,creating>> and
3868<<building-tracepoint-providers-and-user-application,building>>
3869a tracepoint provider package.
3870
3871To use `tracef()` in your application:
3872
3873. In the C or C++ source files where you need to use `tracef()`,
3874 include `<lttng/tracef.h>`:
3875+
3876--
3877[source,c]
3878----
3879#include <lttng/tracef.h>
3880----
3881--
3882
3883. In the application's source code, use `tracef()` like you would use
3884 man:printf(3):
3885+
3886--
3887[source,c]
3888----
3889 /* ... */
3890
3891 tracef("my message: %d (%s)", my_integer, my_string);
3892
3893 /* ... */
3894----
3895--
3896
3897. Link your application with `liblttng-ust`:
3898+
3899--
3900[role="term"]
3901----
3902gcc -o app app.c -llttng-ust
3903----
3904--
3905
3906To trace the events that `tracef()` calls emit:
3907
3908* <<enabling-disabling-events,Create an event rule>> which matches the
3909 `lttng_ust_tracef:*` event name:
3910+
3911--
3912[role="term"]
3913----
3914lttng enable-event --userspace 'lttng_ust_tracef:*'
3915----
3916--
3917
3918[IMPORTANT]
3919.Limitations of `tracef()`
3920====
3921The `tracef()` utility function was developed to make user space tracing
3922super simple, albeit with notable disadvantages compared to
3923<<defining-tracepoints,user-defined tracepoints>>:
3924
3925* All the emitted events have the same tracepoint provider and
3926 tracepoint names, respectively `lttng_ust_tracef` and `event`.
3927* There is no static type checking.
3928* The only event record field you actually get, named `msg`, is a string
3929 potentially containing the values you passed to `tracef()`
3930 using your own format string. This also means that you cannot filter
3931 events with a custom expression at run time because there are no
3932 isolated fields.
3933* Since `tracef()` uses the C standard library's man:vasprintf(3)
3934 function behind the scenes to format the strings at run time, its
3935 expected performance is lower than with user-defined tracepoints,
3936 which do not require a conversion to a string.
3937
3938Taking this into consideration, `tracef()` is useful for some quick
3939prototyping and debugging, but you should not consider it for any
3940permanent and serious applicative instrumentation.
3941====
3942
3943
3944[role="since-2.7"]
3945[[tracelog]]
3946==== Use `tracelog()`
3947
3948The man:tracelog(3) API is very similar to <<tracef,`tracef()`>>, with
3949the difference that it accepts an additional log level parameter.
3950
3951The goal of `tracelog()` is to ease the migration from logging to
3952tracing.
3953
3954To use `tracelog()` in your application:
3955
3956. In the C or C++ source files where you need to use `tracelog()`,
3957 include `<lttng/tracelog.h>`:
3958+
3959--
3960[source,c]
3961----
3962#include <lttng/tracelog.h>
3963----
3964--
3965
3966. In the application's source code, use `tracelog()` like you would use
3967 man:printf(3), except for the first parameter which is the log
3968 level:
3969+
3970--
3971[source,c]
3972----
3973 /* ... */
3974
3975 tracelog(TRACE_WARNING, "my message: %d (%s)",
3976 my_integer, my_string);
3977
3978 /* ... */
3979----
3980--
3981+
3982See man:lttng-ust(3) for a list of available log level names.
3983
3984. Link your application with `liblttng-ust`:
3985+
3986--
3987[role="term"]
3988----
3989gcc -o app app.c -llttng-ust
3990----
3991--
3992
3993To trace the events that `tracelog()` calls emit with a log level
3994_as severe as_ a specific log level:
3995
3996* <<enabling-disabling-events,Create an event rule>> which matches the
3997 `lttng_ust_tracelog:*` event name and a minimum level
3998 of severity:
3999+
4000--
4001[role="term"]
4002----
4003lttng enable-event --userspace 'lttng_ust_tracelog:*'
4004 --loglevel=TRACE_WARNING
4005----
4006--
4007
4008To trace the events that `tracelog()` calls emit with a
4009_specific log level_:
4010
4011* Create an event rule which matches the `lttng_ust_tracelog:*`
4012 event name and a specific log level:
4013+
4014--
4015[role="term"]
4016----
4017lttng enable-event --userspace 'lttng_ust_tracelog:*'
4018 --loglevel-only=TRACE_INFO
4019----
4020--
4021
4022
4023[[prebuilt-ust-helpers]]
4024=== Prebuilt user space tracing helpers
4025
4026The LTTng-UST package provides a few helpers in the form or preloadable
4027shared objects which automatically instrument system functions and
4028calls.
4029
4030The helper shared objects are normally found in dir:{/usr/lib}. If you
4031built LTTng-UST <<building-from-source,from source>>, they are probably
4032located in dir:{/usr/local/lib}.
4033
4034The installed user space tracing helpers in LTTng-UST{nbsp}{revision}
4035are:
4036
4037path:{liblttng-ust-libc-wrapper.so}::
4038path:{liblttng-ust-pthread-wrapper.so}::
4039 <<liblttng-ust-libc-pthread-wrapper,C{nbsp}standard library
4040 memory and POSIX threads function tracing>>.
4041
4042path:{liblttng-ust-cyg-profile.so}::
4043path:{liblttng-ust-cyg-profile-fast.so}::
4044 <<liblttng-ust-cyg-profile,Function entry and exit tracing>>.
4045
4046path:{liblttng-ust-dl.so}::
4047 <<liblttng-ust-dl,Dynamic linker tracing>>.
4048
4049To use a user space tracing helper with any user application:
4050
4051* Preload the helper shared object when you start the application:
4052+
4053--
4054[role="term"]
4055----
4056LD_PRELOAD=liblttng-ust-libc-wrapper.so my-app
4057----
4058--
4059+
4060You can preload more than one helper:
4061+
4062--
4063[role="term"]
4064----
4065LD_PRELOAD=liblttng-ust-libc-wrapper.so:liblttng-ust-dl.so my-app
4066----
4067--
4068
4069
4070[role="since-2.3"]
4071[[liblttng-ust-libc-pthread-wrapper]]
4072==== Instrument C standard library memory and POSIX threads functions
4073
4074The path:{liblttng-ust-libc-wrapper.so} and
4075path:{liblttng-ust-pthread-wrapper.so} helpers
4076add instrumentation to some C standard library and POSIX
4077threads functions.
4078
4079[role="growable"]
4080.Functions instrumented by preloading path:{liblttng-ust-libc-wrapper.so}.
4081|====
4082|TP provider name |TP name |Instrumented function
4083
4084.6+|`lttng_ust_libc` |`malloc` |man:malloc(3)
4085 |`calloc` |man:calloc(3)
4086 |`realloc` |man:realloc(3)
4087 |`free` |man:free(3)
4088 |`memalign` |man:memalign(3)
4089 |`posix_memalign` |man:posix_memalign(3)
4090|====
4091
4092[role="growable"]
4093.Functions instrumented by preloading path:{liblttng-ust-pthread-wrapper.so}.
4094|====
4095|TP provider name |TP name |Instrumented function
4096
4097.4+|`lttng_ust_pthread` |`pthread_mutex_lock_req` |man:pthread_mutex_lock(3p) (request time)
4098 |`pthread_mutex_lock_acq` |man:pthread_mutex_lock(3p) (acquire time)
4099 |`pthread_mutex_trylock` |man:pthread_mutex_trylock(3p)
4100 |`pthread_mutex_unlock` |man:pthread_mutex_unlock(3p)
4101|====
4102
4103When you preload the shared object, it replaces the functions listed
4104in the previous tables by wrappers which contain tracepoints and call
4105the replaced functions.
4106
4107
4108[[liblttng-ust-cyg-profile]]
4109==== Instrument function entry and exit
4110
4111The path:{liblttng-ust-cyg-profile*.so} helpers can add instrumentation
4112to the entry and exit points of functions.
4113
4114man:gcc(1) and man:clang(1) have an option named
4115https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html[`-finstrument-functions`]
4116which generates instrumentation calls for entry and exit to functions.
4117The LTTng-UST function tracing helpers,
4118path:{liblttng-ust-cyg-profile.so} and
4119path:{liblttng-ust-cyg-profile-fast.so}, take advantage of this feature
4120to add tracepoints to the two generated functions (which contain
4121`cyg_profile` in their names, hence the helper's name).
4122
4123To use the LTTng-UST function tracing helper, the source files to
4124instrument must be built using the `-finstrument-functions` compiler
4125flag.
4126
4127There are two versions of the LTTng-UST function tracing helper:
4128
4129* **path:{liblttng-ust-cyg-profile-fast.so}** is a lightweight variant
4130 that you should only use when it can be _guaranteed_ that the
4131 complete event stream is recorded without any lost event record.
4132 Any kind of duplicate information is left out.
4133+
4134Assuming no event record is lost, having only the function addresses on
4135entry is enough to create a call graph, since an event record always
4136contains the ID of the CPU that generated it.
4137+
4138You can use a tool like man:addr2line(1) to convert function addresses
4139back to source file names and line numbers.
4140
4141* **path:{liblttng-ust-cyg-profile.so}** is a more robust variant
4142which also works in use cases where event records might get discarded or
4143not recorded from application startup.
4144In these cases, the trace analyzer needs more information to be
4145able to reconstruct the program flow.
4146
4147See man:lttng-ust-cyg-profile(3) to learn more about the instrumentation
4148points of this helper.
4149
4150All the tracepoints that this helper provides have the
4151log level `TRACE_DEBUG_FUNCTION` (see man:lttng-ust(3)).
4152
4153TIP: It's sometimes a good idea to limit the number of source files that
4154you compile with the `-finstrument-functions` option to prevent LTTng
4155from writing an excessive amount of trace data at run time. When using
4156man:gcc(1), you can use the
4157`-finstrument-functions-exclude-function-list` option to avoid
4158instrument entries and exits of specific function names.
4159
4160
4161[role="since-2.4"]
4162[[liblttng-ust-dl]]
4163==== Instrument the dynamic linker
4164
4165The path:{liblttng-ust-dl.so} helper adds instrumentation to the
4166man:dlopen(3) and man:dlclose(3) function calls.
4167
4168See man:lttng-ust-dl(3) to learn more about the instrumentation points
4169of this helper.
4170
4171
4172[role="since-2.4"]
4173[[java-application]]
4174=== User space Java agent
4175
4176You can instrument any Java application which uses one of the following
4177logging frameworks:
4178
4179* The https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[**`java.util.logging`**]
4180 (JUL) core logging facilities.
4181* http://logging.apache.org/log4j/1.2/[**Apache log4j 1.2**], since
4182 LTTng 2.6. Note that Apache Log4j{nbsp}2 is not supported.
4183
4184[role="img-100"]
4185.LTTng-UST Java agent imported by a Java application.
4186image::java-app.png[]
4187
4188Note that the methods described below are new in LTTng{nbsp}{revision}.
4189Previous LTTng versions use another technique.
4190
4191NOTE: We use http://openjdk.java.net/[OpenJDK]{nbsp}8 for development
4192and https://ci.lttng.org/[continuous integration], thus this version is
4193directly supported. However, the LTTng-UST Java agent is also tested
4194with OpenJDK{nbsp}7.
4195
4196
4197[role="since-2.8"]
4198[[jul]]
4199==== Use the LTTng-UST Java agent for `java.util.logging`
4200
4201To use the LTTng-UST Java agent in a Java application which uses
4202`java.util.logging` (JUL):
4203
4204. In the Java application's source code, import the LTTng-UST
4205 log handler package for `java.util.logging`:
4206+
4207--
4208[source,java]
4209----
4210import org.lttng.ust.agent.jul.LttngLogHandler;
4211----
4212--
4213
4214. Create an LTTng-UST JUL log handler:
4215+
4216--
4217[source,java]
4218----
4219Handler lttngUstLogHandler = new LttngLogHandler();
4220----
4221--
4222
4223. Add this handler to the JUL loggers which should emit LTTng events:
4224+
4225--
4226[source,java]
4227----
4228Logger myLogger = Logger.getLogger("some-logger");
4229
4230myLogger.addHandler(lttngUstLogHandler);
4231----
4232--
4233
4234. Use `java.util.logging` log statements and configuration as usual.
4235 The loggers with an attached LTTng-UST log handler can emit
4236 LTTng events.
4237
4238. Before exiting the application, remove the LTTng-UST log handler from
4239 the loggers attached to it and call its `close()` method:
4240+
4241--
4242[source,java]
4243----
4244myLogger.removeHandler(lttngUstLogHandler);
4245lttngUstLogHandler.close();
4246----
4247--
4248+
4249This is not strictly necessary, but it is recommended for a clean
4250disposal of the handler's resources.
4251
4252. Include the LTTng-UST Java agent's common and JUL-specific JAR files,
4253 path:{lttng-ust-agent-common.jar} and path:{lttng-ust-agent-jul.jar},
4254 in the
4255 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4256 path] when you build the Java application.
4257+
4258The JAR files are typically located in dir:{/usr/share/java}.
4259+
4260IMPORTANT: The LTTng-UST Java agent must be
4261<<installing-lttng,installed>> for the logging framework your
4262application uses.
4263
4264.Use the LTTng-UST Java agent for `java.util.logging`.
4265====
4266[source,java]
4267.path:{Test.java}
4268----
4269import java.io.IOException;
4270import java.util.logging.Handler;
4271import java.util.logging.Logger;
4272import org.lttng.ust.agent.jul.LttngLogHandler;
4273
4274public class Test
4275{
4276 private static final int answer = 42;
4277
4278 public static void main(String[] argv) throws Exception
4279 {
4280 // Create a logger
4281 Logger logger = Logger.getLogger("jello");
4282
4283 // Create an LTTng-UST log handler
4284 Handler lttngUstLogHandler = new LttngLogHandler();
4285
4286 // Add the LTTng-UST log handler to our logger
4287 logger.addHandler(lttngUstLogHandler);
4288
4289 // Log at will!
4290 logger.info("some info");
4291 logger.warning("some warning");
4292 Thread.sleep(500);
4293 logger.finer("finer information; the answer is " + answer);
4294 Thread.sleep(123);
4295 logger.severe("error!");
4296
4297 // Not mandatory, but cleaner
4298 logger.removeHandler(lttngUstLogHandler);
4299 lttngUstLogHandler.close();
4300 }
4301}
4302----
4303
4304Build this example:
4305
4306[role="term"]
4307----
4308javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4309----
4310
4311<<creating-destroying-tracing-sessions,Create a tracing session>>,
4312<<enabling-disabling-events,create an event rule>> matching the
4313`jello` JUL logger, and <<basic-tracing-session-control,start tracing>>:
4314
4315[role="term"]
4316----
4317lttng create
4318lttng enable-event --jul jello
4319lttng start
4320----
4321
4322Run the compiled class:
4323
4324[role="term"]
4325----
4326java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4327----
4328
4329<<basic-tracing-session-control,Stop tracing>> and inspect the
4330recorded events:
4331
4332[role="term"]
4333----
4334lttng stop
4335lttng view
4336----
4337====
4338
4339You can use the opt:lttng-enable-event(1):--loglevel or
4340opt:lttng-enable-event(1):--loglevel-only option of the
4341man:lttng-enable-event(1) command to target a range of JUL log levels
4342or a specific JUL log level.
4343
4344
4345[role="since-2.8"]
4346[[log4j]]
4347==== Use the LTTng-UST Java agent for Apache log4j
4348
4349To use the LTTng-UST Java agent in a Java application which uses
4350Apache log4j 1.2:
4351
4352. In the Java application's source code, import the LTTng-UST
4353 log appender package for Apache log4j:
4354+
4355--
4356[source,java]
4357----
4358import org.lttng.ust.agent.log4j.LttngLogAppender;
4359----
4360--
4361
4362. Create an LTTng-UST log4j log appender:
4363+
4364--
4365[source,java]
4366----
4367Appender lttngUstLogAppender = new LttngLogAppender();
4368----
4369--
4370
4371. Add this appender to the log4j loggers which should emit LTTng events:
4372+
4373--
4374[source,java]
4375----
4376Logger myLogger = Logger.getLogger("some-logger");
4377
4378myLogger.addAppender(lttngUstLogAppender);
4379----
4380--
4381
4382. Use Apache log4j log statements and configuration as usual. The
4383 loggers with an attached LTTng-UST log appender can emit LTTng events.
4384
4385. Before exiting the application, remove the LTTng-UST log appender from
4386 the loggers attached to it and call its `close()` method:
4387+
4388--
4389[source,java]
4390----
4391myLogger.removeAppender(lttngUstLogAppender);
4392lttngUstLogAppender.close();
4393----
4394--
4395+
4396This is not strictly necessary, but it is recommended for a clean
4397disposal of the appender's resources.
4398
4399. Include the LTTng-UST Java agent's common and log4j-specific JAR
4400 files, path:{lttng-ust-agent-common.jar} and
4401 path:{lttng-ust-agent-log4j.jar}, in the
4402 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4403 path] when you build the Java application.
4404+
4405The JAR files are typically located in dir:{/usr/share/java}.
4406+
4407IMPORTANT: The LTTng-UST Java agent must be
4408<<installing-lttng,installed>> for the logging framework your
4409application uses.
4410
4411.Use the LTTng-UST Java agent for Apache log4j.
4412====
4413[source,java]
4414.path:{Test.java}
4415----
4416import org.apache.log4j.Appender;
4417import org.apache.log4j.Logger;
4418import org.lttng.ust.agent.log4j.LttngLogAppender;
4419
4420public class Test
4421{
4422 private static final int answer = 42;
4423
4424 public static void main(String[] argv) throws Exception
4425 {
4426 // Create a logger
4427 Logger logger = Logger.getLogger("jello");
4428
4429 // Create an LTTng-UST log appender
4430 Appender lttngUstLogAppender = new LttngLogAppender();
4431
4432 // Add the LTTng-UST log appender to our logger
4433 logger.addAppender(lttngUstLogAppender);
4434
4435 // Log at will!
4436 logger.info("some info");
4437 logger.warn("some warning");
4438 Thread.sleep(500);
4439 logger.debug("debug information; the answer is " + answer);
4440 Thread.sleep(123);
4441 logger.fatal("error!");
4442
4443 // Not mandatory, but cleaner
4444 logger.removeAppender(lttngUstLogAppender);
4445 lttngUstLogAppender.close();
4446 }
4447}
4448
4449----
4450
4451Build this example (`$LOG4JPATH` is the path to the Apache log4j JAR
4452file):
4453
4454[role="term"]
4455----
4456javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH Test.java
4457----
4458
4459<<creating-destroying-tracing-sessions,Create a tracing session>>,
4460<<enabling-disabling-events,create an event rule>> matching the
4461`jello` log4j logger, and <<basic-tracing-session-control,start tracing>>:
4462
4463[role="term"]
4464----
4465lttng create
4466lttng enable-event --log4j jello
4467lttng start
4468----
4469
4470Run the compiled class:
4471
4472[role="term"]
4473----
4474java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH:. Test
4475----
4476
4477<<basic-tracing-session-control,Stop tracing>> and inspect the
4478recorded events:
4479
4480[role="term"]
4481----
4482lttng stop
4483lttng view
4484----
4485====
4486
4487You can use the opt:lttng-enable-event(1):--loglevel or
4488opt:lttng-enable-event(1):--loglevel-only option of the
4489man:lttng-enable-event(1) command to target a range of Apache log4j log levels
4490or a specific log4j log level.
4491
4492
4493[role="since-2.8"]
4494[[java-application-context]]
4495==== Provide application-specific context fields in a Java application
4496
4497A Java application-specific context field is a piece of state provided
4498by the application which <<adding-context,you can add>>, using the
4499man:lttng-add-context(1) command, to each <<event,event record>>
4500produced by the log statements of this application.
4501
4502For example, a given object might have a current request ID variable.
4503You can create a context information retriever for this object and
4504assign a name to this current request ID. You can then, using the
4505man:lttng-add-context(1) command, add this context field by name to
4506the JUL or log4j <<channel,channel>>.
4507
4508To provide application-specific context fields in a Java application:
4509
4510. In the Java application's source code, import the LTTng-UST
4511 Java agent context classes and interfaces:
4512+
4513--
4514[source,java]
4515----
4516import org.lttng.ust.agent.context.ContextInfoManager;
4517import org.lttng.ust.agent.context.IContextInfoRetriever;
4518----
4519--
4520
4521. Create a context information retriever class, that is, a class which
4522 implements the `IContextInfoRetriever` interface:
4523+
4524--
4525[source,java]
4526----
4527class MyContextInfoRetriever implements IContextInfoRetriever
4528{
4529 @Override
4530 public Object retrieveContextInfo(String key)
4531 {
4532 if (key.equals("intCtx")) {
4533 return (short) 17;
4534 } else if (key.equals("strContext")) {
4535 return "context value!";
4536 } else {
4537 return null;
4538 }
4539 }
4540}
4541----
4542--
4543+
4544This `retrieveContextInfo()` method is the only member of the
4545`IContextInfoRetriever` interface. Its role is to return the current
4546value of a state by name to create a context field. The names of the
4547context fields and which state variables they return depends on your
4548specific scenario.
4549+
4550All primitive types and objects are supported as context fields.
4551When `retrieveContextInfo()` returns an object, the context field
4552serializer calls its `toString()` method to add a string field to
4553event records. The method can also return `null`, which means that
4554no context field is available for the required name.
4555
4556. Register an instance of your context information retriever class to
4557 the context information manager singleton:
4558+
4559--
4560[source,java]
4561----
4562IContextInfoRetriever cir = new MyContextInfoRetriever();
4563ContextInfoManager cim = ContextInfoManager.getInstance();
4564cim.registerContextInfoRetriever("retrieverName", cir);
4565----
4566--
4567
4568. Before exiting the application, remove your context information
4569 retriever from the context information manager singleton:
4570+
4571--
4572[source,java]
4573----
4574ContextInfoManager cim = ContextInfoManager.getInstance();
4575cim.unregisterContextInfoRetriever("retrieverName");
4576----
4577--
4578+
4579This is not strictly necessary, but it is recommended for a clean
4580disposal of some manager's resources.
4581
4582. Build your Java application with LTTng-UST Java agent support as
4583 usual, following the procedure for either the <<jul,JUL>> or
4584 <<log4j,Apache log4j>> framework.
4585
4586
4587.Provide application-specific context fields in a Java application.
4588====
4589[source,java]
4590.path:{Test.java}
4591----
4592import java.util.logging.Handler;
4593import java.util.logging.Logger;
4594import org.lttng.ust.agent.jul.LttngLogHandler;
4595import org.lttng.ust.agent.context.ContextInfoManager;
4596import org.lttng.ust.agent.context.IContextInfoRetriever;
4597
4598public class Test
4599{
4600 // Our context information retriever class
4601 private static class MyContextInfoRetriever
4602 implements IContextInfoRetriever
4603 {
4604 @Override
4605 public Object retrieveContextInfo(String key) {
4606 if (key.equals("intCtx")) {
4607 return (short) 17;
4608 } else if (key.equals("strContext")) {
4609 return "context value!";
4610 } else {
4611 return null;
4612 }
4613 }
4614 }
4615
4616 private static final int answer = 42;
4617
4618 public static void main(String args[]) throws Exception
4619 {
4620 // Get the context information manager instance
4621 ContextInfoManager cim = ContextInfoManager.getInstance();
4622
4623 // Create and register our context information retriever
4624 IContextInfoRetriever cir = new MyContextInfoRetriever();
4625 cim.registerContextInfoRetriever("myRetriever", cir);
4626
4627 // Create a logger
4628 Logger logger = Logger.getLogger("jello");
4629
4630 // Create an LTTng-UST log handler
4631 Handler lttngUstLogHandler = new LttngLogHandler();
4632
4633 // Add the LTTng-UST log handler to our logger
4634 logger.addHandler(lttngUstLogHandler);
4635
4636 // Log at will!
4637 logger.info("some info");
4638 logger.warning("some warning");
4639 Thread.sleep(500);
4640 logger.finer("finer information; the answer is " + answer);
4641 Thread.sleep(123);
4642 logger.severe("error!");
4643
4644 // Not mandatory, but cleaner
4645 logger.removeHandler(lttngUstLogHandler);
4646 lttngUstLogHandler.close();
4647 cim.unregisterContextInfoRetriever("myRetriever");
4648 }
4649}
4650----
4651
4652Build this example:
4653
4654[role="term"]
4655----
4656javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4657----
4658
4659<<creating-destroying-tracing-sessions,Create a tracing session>>
4660and <<enabling-disabling-events,create an event rule>> matching the
4661`jello` JUL logger:
4662
4663[role="term"]
4664----
4665lttng create
4666lttng enable-event --jul jello
4667----
4668
4669<<adding-context,Add the application-specific context fields>> to the
4670JUL channel:
4671
4672[role="term"]
4673----
4674lttng add-context --jul --type='$app.myRetriever:intCtx'
4675lttng add-context --jul --type='$app.myRetriever:strContext'
4676----
4677
4678<<basic-tracing-session-control,Start tracing>>:
4679
4680[role="term"]
4681----
4682lttng start
4683----
4684
4685Run the compiled class:
4686
4687[role="term"]
4688----
4689java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4690----
4691
4692<<basic-tracing-session-control,Stop tracing>> and inspect the
4693recorded events:
4694
4695[role="term"]
4696----
4697lttng stop
4698lttng view
4699----
4700====
4701
4702
4703[role="since-2.7"]
4704[[python-application]]
4705=== User space Python agent
4706
4707You can instrument a Python 2 or Python 3 application which uses the
4708standard https://docs.python.org/3/library/logging.html[`logging`]
4709package.
4710
4711Each log statement emits an LTTng event once the
4712application module imports the
4713<<lttng-ust-agents,LTTng-UST Python agent>> package.
4714
4715[role="img-100"]
4716.A Python application importing the LTTng-UST Python agent.
4717image::python-app.png[]
4718
4719To use the LTTng-UST Python agent:
4720
4721. In the Python application's source code, import the LTTng-UST Python
4722 agent:
4723+
4724--
4725[source,python]
4726----
4727import lttngust
4728----
4729--
4730+
4731The LTTng-UST Python agent automatically adds its logging handler to the
4732root logger at import time.
4733+
4734Any log statement that the application executes before this import does
4735not emit an LTTng event.
4736+
4737IMPORTANT: The LTTng-UST Python agent must be
4738<<installing-lttng,installed>>.
4739
4740. Use log statements and logging configuration as usual.
4741 Since the LTTng-UST Python agent adds a handler to the _root_
4742 logger, you can trace any log statement from any logger.
4743
4744.Use the LTTng-UST Python agent.
4745====
4746[source,python]
4747.path:{test.py}
4748----
4749import lttngust
4750import logging
4751import time
4752
4753
4754def example():
4755 logging.basicConfig()
4756 logger = logging.getLogger('my-logger')
4757
4758 while True:
4759 logger.debug('debug message')
4760 logger.info('info message')
4761 logger.warn('warn message')
4762 logger.error('error message')
4763 logger.critical('critical message')
4764 time.sleep(1)
4765
4766
4767if __name__ == '__main__':
4768 example()
4769----
4770
4771NOTE: `logging.basicConfig()`, which adds to the root logger a basic
4772logging handler which prints to the standard error stream, is not
4773strictly required for LTTng-UST tracing to work, but in versions of
4774Python preceding 3.2, you could see a warning message which indicates
4775that no handler exists for the logger `my-logger`.
4776
4777<<creating-destroying-tracing-sessions,Create a tracing session>>,
4778<<enabling-disabling-events,create an event rule>> matching the
4779`my-logger` Python logger, and <<basic-tracing-session-control,start
4780tracing>>:
4781
4782[role="term"]
4783----
4784lttng create
4785lttng enable-event --python my-logger
4786lttng start
4787----
4788
4789Run the Python script:
4790
4791[role="term"]
4792----
4793python test.py
4794----
4795
4796<<basic-tracing-session-control,Stop tracing>> and inspect the recorded
4797events:
4798
4799[role="term"]
4800----
4801lttng stop
4802lttng view
4803----
4804====
4805
4806You can use the opt:lttng-enable-event(1):--loglevel or
4807opt:lttng-enable-event(1):--loglevel-only option of the
4808man:lttng-enable-event(1) command to target a range of Python log levels
4809or a specific Python log level.
4810
4811When an application imports the LTTng-UST Python agent, the agent tries
4812to register to a <<lttng-sessiond,session daemon>>. Note that you must
4813<<start-sessiond,start the session daemon>> _before_ you run the Python
4814application. If a session daemon is found, the agent tries to register
4815to it during 5{nbsp}seconds, after which the application continues
4816without LTTng tracing support. You can override this timeout value with
4817the env:LTTNG_UST_PYTHON_REGISTER_TIMEOUT environment variable
4818(milliseconds).
4819
4820If the session daemon stops while a Python application with an imported
4821LTTng-UST Python agent runs, the agent retries to connect and to
4822register to a session daemon every 3{nbsp}seconds. You can override this
4823delay with the env:LTTNG_UST_PYTHON_REGISTER_RETRY_DELAY environment
4824variable.
4825
4826
4827[role="since-2.5"]
4828[[proc-lttng-logger-abi]]
4829=== LTTng logger
4830
4831The `lttng-tracer` Linux kernel module, part of
4832<<lttng-modules,LTTng-modules>>, creates the special LTTng logger file
4833path:{/proc/lttng-logger} when it's loaded. Any application can write
4834text data to this file to emit an LTTng event.
4835
4836[role="img-100"]
4837.An application writes to the LTTng logger file to emit an LTTng event.
4838image::lttng-logger.png[]
4839
4840The LTTng logger is the quickest method--not the most efficient,
4841however--to add instrumentation to an application. It is designed
4842mostly to instrument shell scripts:
4843
4844[role="term"]
4845----
4846echo "Some message, some $variable" > /proc/lttng-logger
4847----
4848
4849Any event that the LTTng logger emits is named `lttng_logger` and
4850belongs to the Linux kernel <<domain,tracing domain>>. However, unlike
4851other instrumentation points in the kernel tracing domain, **any Unix
4852user** can <<enabling-disabling-events,create an event rule>> which
4853matches its event name, not only the root user or users in the tracing
4854group.
4855
4856To use the LTTng logger:
4857
4858* From any application, write text data to the path:{/proc/lttng-logger}
4859 file.
4860
4861The `msg` field of `lttng_logger` event records contains the
4862recorded message.
4863
4864NOTE: The maximum message length of an LTTng logger event is
48651024{nbsp}bytes. Writing more than this makes the LTTng logger emit more
4866than one event to contain the remaining data.
4867
4868You should not use the LTTng logger to trace a user application which
4869can be instrumented in a more efficient way, namely:
4870
4871* <<c-application,C and $$C++$$ applications>>.
4872* <<java-application,Java applications>>.
4873* <<python-application,Python applications>>.
4874
4875.Use the LTTng logger.
4876====
4877[source,bash]
4878.path:{test.bash}
4879----
4880echo 'Hello, World!' > /proc/lttng-logger
4881sleep 2
4882df --human-readable --print-type / > /proc/lttng-logger
4883----
4884
4885<<creating-destroying-tracing-sessions,Create a tracing session>>,
4886<<enabling-disabling-events,create an event rule>> matching the
4887`lttng_logger` Linux kernel tracepoint, and
4888<<basic-tracing-session-control,start tracing>>:
4889
4890[role="term"]
4891----
4892lttng create
4893lttng enable-event --kernel lttng_logger
4894lttng start
4895----
4896
4897Run the Bash script:
4898
4899[role="term"]
4900----
4901bash test.bash
4902----
4903
4904<<basic-tracing-session-control,Stop tracing>> and inspect the recorded
4905events:
4906
4907[role="term"]
4908----
4909lttng stop
4910lttng view
4911----
4912====
4913
4914
4915[[instrumenting-linux-kernel]]
4916=== LTTng kernel tracepoints
4917
4918NOTE: This section shows how to _add_ instrumentation points to the
4919Linux kernel. The kernel's subsystems are already thoroughly
4920instrumented at strategic places for LTTng when you
4921<<installing-lttng,install>> the <<lttng-modules,LTTng-modules>>
4922package.
4923
4924////
4925There are two methods to instrument the Linux kernel:
4926
4927. <<linux-add-lttng-layer,Add an LTTng layer>> over an existing ftrace
4928 tracepoint which uses the `TRACE_EVENT()` API.
4929+
4930Choose this if you want to instrumentation a Linux kernel tree with an
4931instrumentation point compatible with ftrace, perf, and SystemTap.
4932
4933. Use an <<linux-lttng-tracepoint-event,LTTng-only approach>> to
4934 instrument an out-of-tree kernel module.
4935+
4936Choose this if you don't need ftrace, perf, or SystemTap support.
4937////
4938
4939
4940[[linux-add-lttng-layer]]
4941==== [[instrumenting-linux-kernel-itself]][[mainline-trace-event]][[lttng-adaptation-layer]]Add an LTTng layer to an existing ftrace tracepoint
4942
4943This section shows how to add an LTTng layer to existing ftrace
4944instrumentation using the `TRACE_EVENT()` API.
4945
4946This section does not document the `TRACE_EVENT()` macro. You can
4947read the following articles to learn more about this API:
4948
4949* http://lwn.net/Articles/379903/[Using the TRACE_EVENT() macro (Part 1)]
4950* http://lwn.net/Articles/381064/[Using the TRACE_EVENT() macro (Part 2)]
4951* http://lwn.net/Articles/383362/[Using the TRACE_EVENT() macro (Part 3)]
4952
4953The following procedure assumes that your ftrace tracepoints are
4954correctly defined in their own header and that they are created in
4955one source file using the `CREATE_TRACE_POINTS` definition.
4956
4957To add an LTTng layer over an existing ftrace tracepoint:
4958
4959. Make sure the following kernel configuration options are
4960 enabled:
4961+
4962--
4963* `CONFIG_MODULES`
4964* `CONFIG_KALLSYMS`
4965* `CONFIG_HIGH_RES_TIMERS`
4966* `CONFIG_TRACEPOINTS`
4967--
4968
4969. Build the Linux source tree with your custom ftrace tracepoints.
4970. Boot the resulting Linux image on your target system.
4971+
4972Confirm that the tracepoints exist by looking for their names in the
4973dir:{/sys/kernel/debug/tracing/events/subsys} directory, where `subsys`
4974is your subsystem's name.
4975
4976. Get a copy of the latest LTTng-modules{nbsp}{revision}:
4977+
4978--
4979[role="term"]
4980----
4981cd $(mktemp -d) &&
4982wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.9.tar.bz2 &&
4983tar -xf lttng-modules-latest-2.9.tar.bz2 &&
4984cd lttng-modules-2.9.*
4985----
4986--
4987
4988. In dir:{instrumentation/events/lttng-module}, relative to the root
4989 of the LTTng-modules source tree, create a header file named
4990 +__subsys__.h+ for your custom subsystem +__subsys__+ and write your
4991 LTTng-modules tracepoint definitions using the LTTng-modules
4992 macros in it.
4993+
4994Start with this template:
4995+
4996--
4997[source,c]
4998.path:{instrumentation/events/lttng-module/my_subsys.h}
4999----
5000#undef TRACE_SYSTEM
5001#define TRACE_SYSTEM my_subsys
5002
5003#if !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ)
5004#define _LTTNG_MY_SUBSYS_H
5005
5006#include "../../../probes/lttng-tracepoint-event.h"
5007#include <linux/tracepoint.h>
5008
5009LTTNG_TRACEPOINT_EVENT(
5010 /*
5011 * Format is identical to TRACE_EVENT()'s version for the three
5012 * following macro parameters:
5013 */
5014 my_subsys_my_event,
5015 TP_PROTO(int my_int, const char *my_string),
5016 TP_ARGS(my_int, my_string),
5017
5018 /* LTTng-modules specific macros */
5019 TP_FIELDS(
5020 ctf_integer(int, my_int_field, my_int)
5021 ctf_string(my_bar_field, my_bar)
5022 )
5023)
5024
5025#endif /* !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ) */
5026
5027#include "../../../probes/define_trace.h"
5028----
5029--
5030+
5031The entries in the `TP_FIELDS()` section are the list of fields for the
5032LTTng tracepoint. This is similar to the `TP_STRUCT__entry()` part of
5033ftrace's `TRACE_EVENT()` macro.
5034+
5035See <<lttng-modules-tp-fields,Tracepoint fields macros>> for a
5036complete description of the available `ctf_*()` macros.
5037
5038. Create the LTTng-modules probe's kernel module C source file,
5039 +probes/lttng-probe-__subsys__.c+, where +__subsys__+ is your
5040 subsystem name:
5041+
5042--
5043[source,c]
5044.path:{probes/lttng-probe-my-subsys.c}
5045----
5046#include <linux/module.h>
5047#include "../lttng-tracer.h"
5048
5049/*
5050 * Build-time verification of mismatch between mainline
5051 * TRACE_EVENT() arguments and the LTTng-modules adaptation
5052 * layer LTTNG_TRACEPOINT_EVENT() arguments.
5053 */
5054#include <trace/events/my_subsys.h>
5055
5056/* Create LTTng tracepoint probes */
5057#define LTTNG_PACKAGE_BUILD
5058#define CREATE_TRACE_POINTS
5059#define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
5060
5061#include "../instrumentation/events/lttng-module/my_subsys.h"
5062
5063MODULE_LICENSE("GPL and additional rights");
5064MODULE_AUTHOR("Your name <your-email>");
5065MODULE_DESCRIPTION("LTTng my_subsys probes");
5066MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
5067 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
5068 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
5069 LTTNG_MODULES_EXTRAVERSION);
5070----
5071--
5072
5073. Edit path:{probes/Makefile} and add your new kernel module object
5074 next to the existing ones:
5075+
5076--
5077[source,make]
5078.path:{probes/Makefile}
5079----
5080# ...
5081
5082obj-m += lttng-probe-module.o
5083obj-m += lttng-probe-power.o
5084
5085obj-m += lttng-probe-my-subsys.o
5086
5087# ...
5088----
5089--
5090
5091. Build and install the LTTng kernel modules:
5092+
5093--
5094[role="term"]
5095----
5096make KERNELDIR=/path/to/linux
5097sudo make modules_install
5098----
5099--
5100+
5101Replace `/path/to/linux` with the path to the Linux source tree where
5102you defined and used tracepoints with ftrace's `TRACE_EVENT()` macro.
5103
5104Note that you can also use the
5105<<lttng-tracepoint-event-code,`LTTNG_TRACEPOINT_EVENT_CODE()` macro>>
5106instead of `LTTNG_TRACEPOINT_EVENT()` to use custom local variables and
5107C code that need to be executed before the event fields are recorded.
5108
5109The best way to learn how to use the previous LTTng-modules macros is to
5110inspect the existing LTTng-modules tracepoint definitions in the
5111dir:{instrumentation/events/lttng-module} header files. Compare them
5112with the Linux kernel mainline versions in the
5113dir:{include/trace/events} directory of the Linux source tree.
5114
5115
5116[role="since-2.7"]
5117[[lttng-tracepoint-event-code]]
5118===== Use custom C code to access the data for tracepoint fields
5119
5120Although we recommended to always use the
5121<<lttng-adaptation-layer,`LTTNG_TRACEPOINT_EVENT()`>> macro to describe
5122the arguments and fields of an LTTng-modules tracepoint when possible,
5123sometimes you need a more complex process to access the data that the
5124tracer records as event record fields. In other words, you need local
5125variables and multiple C{nbsp}statements instead of simple
5126argument-based expressions that you pass to the
5127<<lttng-modules-tp-fields,`ctf_*()` macros of `TP_FIELDS()`>>.
5128
5129You can use the `LTTNG_TRACEPOINT_EVENT_CODE()` macro instead of
5130`LTTNG_TRACEPOINT_EVENT()` to declare custom local variables and define
5131a block of C{nbsp}code to be executed before LTTng records the fields.
5132The structure of this macro is:
5133
5134[source,c]
5135.`LTTNG_TRACEPOINT_EVENT_CODE()` macro syntax.
5136----
5137LTTNG_TRACEPOINT_EVENT_CODE(
5138 /*
5139 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5140 * version for the following three macro parameters:
5141 */
5142 my_subsys_my_event,
5143 TP_PROTO(int my_int, const char *my_string),
5144 TP_ARGS(my_int, my_string),
5145
5146 /* Declarations of custom local variables */
5147 TP_locvar(
5148 int a = 0;
5149 unsigned long b = 0;
5150 const char *name = "(undefined)";
5151 struct my_struct *my_struct;
5152 ),
5153
5154 /*
5155 * Custom code which uses both tracepoint arguments
5156 * (in TP_ARGS()) and local variables (in TP_locvar()).
5157 *
5158 * Local variables are actually members of a structure pointed
5159 * to by the special variable tp_locvar.
5160 */
5161 TP_code(
5162 if (my_int) {
5163 tp_locvar->a = my_int + 17;
5164 tp_locvar->my_struct = get_my_struct_at(tp_locvar->a);
5165 tp_locvar->b = my_struct_compute_b(tp_locvar->my_struct);
5166 tp_locvar->name = my_struct_get_name(tp_locvar->my_struct);
5167 put_my_struct(tp_locvar->my_struct);
5168
5169 if (tp_locvar->b) {
5170 tp_locvar->a = 1;
5171 }
5172 }
5173 ),
5174
5175 /*
5176 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5177 * version for this, except that tp_locvar members can be
5178 * used in the argument expression parameters of
5179 * the ctf_*() macros.
5180 */
5181 TP_FIELDS(
5182 ctf_integer(unsigned long, my_struct_b, tp_locvar->b)
5183 ctf_integer(int, my_struct_a, tp_locvar->a)
5184 ctf_string(my_string_field, my_string)
5185 ctf_string(my_struct_name, tp_locvar->name)
5186 )
5187)
5188----
5189
5190IMPORTANT: The C code defined in `TP_code()` must not have any side
5191effects when executed. In particular, the code must not allocate
5192memory or get resources without deallocating this memory or putting
5193those resources afterwards.
5194
5195
5196[[instrumenting-linux-kernel-tracing]]
5197==== Load and unload a custom probe kernel module
5198
5199You must load a <<lttng-adaptation-layer,created LTTng-modules probe
5200kernel module>> in the kernel before it can emit LTTng events.
5201
5202To load the default probe kernel modules and a custom probe kernel
5203module:
5204
5205* Use the opt:lttng-sessiond(8):--extra-kmod-probes option to give extra
5206 probe modules to load when starting a root <<lttng-sessiond,session
5207 daemon>>:
5208+
5209--
5210.Load the `my_subsys`, `usb`, and the default probe modules.
5211====
5212[role="term"]
5213----
5214sudo lttng-sessiond --extra-kmod-probes=my_subsys,usb
5215----
5216====
5217--
5218+
5219You only need to pass the subsystem name, not the whole kernel module
5220name.
5221
5222To load _only_ a given custom probe kernel module:
5223
5224* Use the opt:lttng-sessiond(8):--kmod-probes option to give the probe
5225 modules to load when starting a root session daemon:
5226+
5227--
5228.Load only the `my_subsys` and `usb` probe modules.
5229====
5230[role="term"]
5231----
5232sudo lttng-sessiond --kmod-probes=my_subsys,usb
5233----
5234====
5235--
5236
5237To confirm that a probe module is loaded:
5238
5239* Use man:lsmod(8):
5240+
5241--
5242[role="term"]
5243----
5244lsmod | grep lttng_probe_usb
5245----
5246--
5247
5248To unload the loaded probe modules:
5249
5250* Kill the session daemon with `SIGTERM`:
5251+
5252--
5253[role="term"]
5254----
5255sudo pkill lttng-sessiond
5256----
5257--
5258+
5259You can also use man:modprobe(8)'s `--remove` option if the session
5260daemon terminates abnormally.
5261
5262
5263[[controlling-tracing]]
5264== Tracing control
5265
5266Once an application or a Linux kernel is
5267<<instrumenting,instrumented>> for LTTng tracing,
5268you can _trace_ it.
5269
5270This section is divided in topics on how to use the various
5271<<plumbing,components of LTTng>>, in particular the <<lttng-cli,cmd:lttng
5272command-line tool>>, to _control_ the LTTng daemons and tracers.
5273
5274NOTE: In the following subsections, we refer to an man:lttng(1) command
5275using its man page name. For example, instead of _Run the `create`
5276command to..._, we use _Run the man:lttng-create(1) command to..._.
5277
5278
5279[[start-sessiond]]
5280=== Start a session daemon
5281
5282In some situations, you need to run a <<lttng-sessiond,session daemon>>
5283(man:lttng-sessiond(8)) _before_ you can use the man:lttng(1)
5284command-line tool.
5285
5286You will see the following error when you run a command while no session
5287daemon is running:
5288
5289----
5290Error: No session daemon is available
5291----
5292
5293The only command that automatically runs a session daemon is
5294man:lttng-create(1), which you use to
5295<<creating-destroying-tracing-sessions,create a tracing session>>. While
5296this is most of the time the first operation that you do, sometimes it's
5297not. Some examples are:
5298
5299* <<list-instrumentation-points,List the available instrumentation points>>.
5300* <<saving-loading-tracing-session,Load a tracing session configuration>>.
5301
5302[[tracing-group]] Each Unix user must have its own running session
5303daemon to trace user applications. The session daemon that the root user
5304starts is the only one allowed to control the LTTng kernel tracer. Users
5305that are part of the _tracing group_ can control the root session
5306daemon. The default tracing group name is `tracing`; you can set it to
5307something else with the opt:lttng-sessiond(8):--group option when you
5308start the root session daemon.
5309
5310To start a user session daemon:
5311
5312* Run man:lttng-sessiond(8):
5313+
5314--
5315[role="term"]
5316----
5317lttng-sessiond --daemonize
5318----
5319--
5320
5321To start the root session daemon:
5322
5323* Run man:lttng-sessiond(8) as the root user:
5324+
5325--
5326[role="term"]
5327----
5328sudo lttng-sessiond --daemonize
5329----
5330--
5331
5332In both cases, remove the opt:lttng-sessiond(8):--daemonize option to
5333start the session daemon in foreground.
5334
5335To stop a session daemon, use man:kill(1) on its process ID (standard
5336`TERM` signal).
5337
5338Note that some Linux distributions could manage the LTTng session daemon
5339as a service. In this case, you should use the service manager to
5340start, restart, and stop session daemons.
5341
5342
5343[[creating-destroying-tracing-sessions]]
5344=== Create and destroy a tracing session
5345
5346Almost all the LTTng control operations happen in the scope of
5347a <<tracing-session,tracing session>>, which is the dialogue between the
5348<<lttng-sessiond,session daemon>> and you.
5349
5350To create a tracing session with a generated name:
5351
5352* Use the man:lttng-create(1) command:
5353+
5354--
5355[role="term"]
5356----
5357lttng create
5358----
5359--
5360
5361The created tracing session's name is `auto` followed by the
5362creation date.
5363
5364To create a tracing session with a specific name:
5365
5366* Use the optional argument of the man:lttng-create(1) command:
5367+
5368--
5369[role="term"]
5370----
5371lttng create my-session
5372----
5373--
5374+
5375Replace `my-session` with the specific tracing session name.
5376
5377LTTng appends the creation date to the created tracing session's name.
5378
5379LTTng writes the traces of a tracing session in
5380+$LTTNG_HOME/lttng-trace/__name__+ by default, where +__name__+ is the
5381name of the tracing session. Note that the env:LTTNG_HOME environment
5382variable defaults to `$HOME` if not set.
5383
5384To output LTTng traces to a non-default location:
5385
5386* Use the opt:lttng-create(1):--output option of the man:lttng-create(1) command:
5387+
5388--
5389[role="term"]
5390----
5391lttng create --output=/tmp/some-directory my-session
5392----
5393--
5394
5395You may create as many tracing sessions as you wish.
5396
5397To list all the existing tracing sessions for your Unix user:
5398
5399* Use the man:lttng-list(1) command:
5400+
5401--
5402[role="term"]
5403----
5404lttng list
5405----
5406--
5407
5408When you create a tracing session, it is set as the _current tracing
5409session_. The following man:lttng(1) commands operate on the current
5410tracing session when you don't specify one:
5411
5412[role="list-3-cols"]
5413* `add-context`
5414* `destroy`
5415* `disable-channel`
5416* `disable-event`
5417* `enable-channel`
5418* `enable-event`
5419* `load`
5420* `regenerate`
5421* `save`
5422* `snapshot`
5423* `start`
5424* `stop`
5425* `track`
5426* `untrack`
5427* `view`
5428
5429To change the current tracing session:
5430
5431* Use the man:lttng-set-session(1) command:
5432+
5433--
5434[role="term"]
5435----
5436lttng set-session new-session
5437----
5438--
5439+
5440Replace `new-session` by the name of the new current tracing session.
5441
5442When you are done tracing in a given tracing session, you can destroy
5443it. This operation frees the resources taken by the tracing session
5444to destroy; it does not destroy the trace data that LTTng wrote for
5445this tracing session.
5446
5447To destroy the current tracing session:
5448
5449* Use the man:lttng-destroy(1) command:
5450+
5451--
5452[role="term"]
5453----
5454lttng destroy
5455----
5456--
5457
5458
5459[[list-instrumentation-points]]
5460=== List the available instrumentation points
5461
5462The <<lttng-sessiond,session daemon>> can query the running instrumented
5463user applications and the Linux kernel to get a list of available
5464instrumentation points. For the Linux kernel <<domain,tracing domain>>,
5465they are tracepoints and system calls. For the user space tracing
5466domain, they are tracepoints. For the other tracing domains, they are
5467logger names.
5468
5469To list the available instrumentation points:
5470
5471* Use the man:lttng-list(1) command with the requested tracing domain's
5472 option amongst:
5473+
5474--
5475* opt:lttng-list(1):--kernel: Linux kernel tracepoints (your Unix user
5476 must be a root user, or it must be a member of the
5477 <<tracing-group,tracing group>>).
5478* opt:lttng-list(1):--kernel with opt:lttng-list(1):--syscall: Linux
5479 kernel system calls (your Unix user must be a root user, or it must be
5480 a member of the tracing group).
5481* opt:lttng-list(1):--userspace: user space tracepoints.
5482* opt:lttng-list(1):--jul: `java.util.logging` loggers.
5483* opt:lttng-list(1):--log4j: Apache log4j loggers.
5484* opt:lttng-list(1):--python: Python loggers.
5485--
5486
5487.List the available user space tracepoints.
5488====
5489[role="term"]
5490----
5491lttng list --userspace
5492----
5493====
5494
5495.List the available Linux kernel system call tracepoints.
5496====
5497[role="term"]
5498----
5499lttng list --kernel --syscall
5500----
5501====
5502
5503
5504[[enabling-disabling-events]]
5505=== Create and enable an event rule
5506
5507Once you <<creating-destroying-tracing-sessions,create a tracing
5508session>>, you can create <<event,event rules>> with the
5509man:lttng-enable-event(1) command.
5510
5511You specify each condition with a command-line option. The available
5512condition options are shown in the following table.
5513
5514[role="growable",cols="asciidoc,asciidoc,default"]
5515.Condition command-line options for the man:lttng-enable-event(1) command.
5516|====
5517|Option |Description |Applicable tracing domains
5518
5519|
5520One of:
5521
5522. `--syscall`
5523. +--probe=__ADDR__+
5524. +--function=__ADDR__+
5525
5526|
5527Instead of using the default _tracepoint_ instrumentation type, use:
5528
5529. A Linux system call.
5530. A Linux https://lwn.net/Articles/132196/[KProbe] (symbol or address).
5531. The entry and return points of a Linux function (symbol or address).
5532
5533|Linux kernel.
5534
5535|First positional argument.
5536
5537|
5538Tracepoint or system call name. In the case of a Linux KProbe or
5539function, this is a custom name given to the event rule. With the
5540JUL, log4j, and Python domains, this is a logger name.
5541
5542With a tracepoint, logger, or system call name, the last character
5543can be `*` to match anything that remains.
5544
5545|All.
5546
5547|
5548One of:
5549
5550. +--loglevel=__LEVEL__+
5551. +--loglevel-only=__LEVEL__+
5552
5553|
5554. Match only tracepoints or log statements with a logging level at
5555 least as severe as +__LEVEL__+.
5556. Match only tracepoints or log statements with a logging level
5557 equal to +__LEVEL__+.
5558
5559See man:lttng-enable-event(1) for the list of available logging level
5560names.
5561
5562|User space, JUL, log4j, and Python.
5563
5564|+--exclude=__EXCLUSIONS__+
5565
5566|
5567When you use a `*` character at the end of the tracepoint or logger
5568name (first positional argument), exclude the specific names in the
5569comma-delimited list +__EXCLUSIONS__+.
5570
5571|
5572User space, JUL, log4j, and Python.
5573
5574|+--filter=__EXPR__+
5575
5576|
5577Match only events which satisfy the expression +__EXPR__+.
5578
5579See man:lttng-enable-event(1) to learn more about the syntax of a
5580filter expression.
5581
5582|All.
5583
5584|====
5585
5586You attach an event rule to a <<channel,channel>> on creation. If you do
5587not specify the channel with the opt:lttng-enable-event(1):--channel
5588option, and if the event rule to create is the first in its
5589<<domain,tracing domain>> for a given tracing session, then LTTng
5590creates a _default channel_ for you. This default channel is reused in
5591subsequent invocations of the man:lttng-enable-event(1) command for the
5592same tracing domain.
5593
5594An event rule is always enabled at creation time.
5595
5596The following examples show how you can combine the previous
5597command-line options to create simple to more complex event rules.
5598
5599.Create an event rule targetting a Linux kernel tracepoint (default channel).
5600====
5601[role="term"]
5602----
5603lttng enable-event --kernel sched_switch
5604----
5605====
5606
5607.Create an event rule matching four Linux kernel system calls (default channel).
5608====
5609[role="term"]
5610----
5611lttng enable-event --kernel --syscall open,write,read,close
5612----
5613====
5614
5615.Create event rules matching tracepoints with filter expressions (default channel).
5616====
5617[role="term"]
5618----
5619lttng enable-event --kernel sched_switch --filter='prev_comm == "bash"'
5620----
5621
5622[role="term"]
5623----
5624lttng enable-event --kernel --all \
5625 --filter='$ctx.tid == 1988 || $ctx.tid == 1534'
5626----
5627
5628[role="term"]
5629----
5630lttng enable-event --jul my_logger \
5631 --filter='$app.retriever:cur_msg_id > 3'
5632----
5633
5634IMPORTANT: Make sure to always quote the filter string when you
5635use man:lttng(1) from a shell.
5636====
5637
5638.Create an event rule matching any user space tracepoint of a given tracepoint provider with a log level range (default channel).
5639====
5640[role="term"]
5641----
5642lttng enable-event --userspace my_app:'*' --loglevel=TRACE_INFO
5643----
5644
5645IMPORTANT: Make sure to always quote the wildcard character when you
5646use man:lttng(1) from a shell.
5647====
5648
5649.Create an event rule matching multiple Python loggers with a wildcard and with exclusions (default channel).
5650====
5651[role="term"]
5652----
5653lttng enable-event --python my-app.'*' \
5654 --exclude='my-app.module,my-app.hello'
5655----
5656====
5657
5658.Create an event rule matching any Apache log4j logger with a specific log level (default channel).
5659====
5660[role="term"]
5661----
5662lttng enable-event --log4j --all --loglevel-only=LOG4J_WARN
5663----
5664====
5665
5666.Create an event rule attached to a specific channel matching a specific user space tracepoint provider and tracepoint.
5667====
5668[role="term"]
5669----
5670lttng enable-event --userspace my_app:my_tracepoint --channel=my-channel
5671----
5672====
5673
5674The event rules of a given channel form a whitelist: as soon as an
5675emitted event passes one of them, LTTng can record the event. For
5676example, an event named `my_app:my_tracepoint` emitted from a user space
5677tracepoint with a `TRACE_ERROR` log level passes both of the following
5678rules:
5679
5680[role="term"]
5681----
5682lttng enable-event --userspace my_app:my_tracepoint
5683lttng enable-event --userspace my_app:my_tracepoint \
5684 --loglevel=TRACE_INFO
5685----
5686
5687The second event rule is redundant: the first one includes
5688the second one.
5689
5690
5691[[disable-event-rule]]
5692=== Disable an event rule
5693
5694To disable an event rule that you <<enabling-disabling-events,created>>
5695previously, use the man:lttng-disable-event(1) command. This command
5696disables _all_ the event rules (of a given tracing domain and channel)
5697which match an instrumentation point. The other conditions are not
5698supported as of LTTng{nbsp}{revision}.
5699
5700The LTTng tracer does not record an emitted event which passes
5701a _disabled_ event rule.
5702
5703.Disable an event rule matching a Python logger (default channel).
5704====
5705[role="term"]
5706----
5707lttng disable-event --python my-logger
5708----
5709====
5710
5711.Disable an event rule matching all `java.util.logging` loggers (default channel).
5712====
5713[role="term"]
5714----
5715lttng disable-event --jul '*'
5716----
5717====
5718
5719.Disable _all_ the event rules of the default channel.
5720====
5721The opt:lttng-disable-event(1):--all-events option is not, like the
5722opt:lttng-enable-event(1):--all option of man:lttng-enable-event(1), the
5723equivalent of the event name `*` (wildcard): it disables _all_ the event
5724rules of a given channel.
5725
5726[role="term"]
5727----
5728lttng disable-event --jul --all-events
5729----
5730====
5731
5732NOTE: You cannot delete an event rule once you create it.
5733
5734
5735[[status]]
5736=== Get the status of a tracing session
5737
5738To get the status of the current tracing session, that is, its
5739parameters, its channels, event rules, and their attributes:
5740
5741* Use the man:lttng-status(1) command:
5742+
5743--
5744[role="term"]
5745----
5746lttng status
5747----
5748--
5749+
5750
5751To get the status of any tracing session:
5752
5753* Use the man:lttng-list(1) command with the tracing session's name:
5754+
5755--
5756[role="term"]
5757----
5758lttng list my-session
5759----
5760--
5761+
5762Replace `my-session` with the desired tracing session's name.
5763
5764
5765[[basic-tracing-session-control]]
5766=== Start and stop a tracing session
5767
5768Once you <<creating-destroying-tracing-sessions,create a tracing
5769session>> and
5770<<enabling-disabling-events,create one or more event rules>>,
5771you can start and stop the tracers for this tracing session.
5772
5773To start tracing in the current tracing session:
5774
5775* Use the man:lttng-start(1) command:
5776+
5777--
5778[role="term"]
5779----
5780lttng start
5781----
5782--
5783
5784LTTng is very flexible: you can launch user applications before
5785or after the you start the tracers. The tracers only record the events
5786if they pass enabled event rules and if they occur while the tracers are
5787started.
5788
5789To stop tracing in the current tracing session:
5790
5791* Use the man:lttng-stop(1) command:
5792+
5793--
5794[role="term"]
5795----
5796lttng stop
5797----
5798--
5799+
5800If there were <<channel-overwrite-mode-vs-discard-mode,lost event
5801records>> or lost sub-buffers since the last time you ran
5802man:lttng-start(1), warnings are printed when you run the
5803man:lttng-stop(1) command.
5804
5805
5806[[enabling-disabling-channels]]
5807=== Create a channel
5808
5809Once you create a tracing session, you can create a <<channel,channel>>
5810with the man:lttng-enable-channel(1) command.
5811
5812Note that LTTng automatically creates a default channel when, for a
5813given <<domain,tracing domain>>, no channels exist and you
5814<<enabling-disabling-events,create>> the first event rule. This default
5815channel is named `channel0` and its attributes are set to reasonable
5816values. Therefore, you only need to create a channel when you need
5817non-default attributes.
5818
5819You specify each non-default channel attribute with a command-line
5820option when you use the man:lttng-enable-channel(1) command. The
5821available command-line options are:
5822
5823[role="growable",cols="asciidoc,asciidoc"]
5824.Command-line options for the man:lttng-enable-channel(1) command.
5825|====
5826|Option |Description
5827
5828|`--overwrite`
5829
5830|
5831Use the _overwrite_
5832<<channel-overwrite-mode-vs-discard-mode,event loss mode>> instead of
5833the default _discard_ mode.
5834
5835|`--buffers-pid` (user space tracing domain only)
5836
5837|
5838Use the per-process <<channel-buffering-schemes,buffering scheme>>
5839instead of the default per-user buffering scheme.
5840
5841|+--subbuf-size=__SIZE__+
5842
5843|
5844Allocate sub-buffers of +__SIZE__+ bytes (power of two), for each CPU,
5845either for each Unix user (default), or for each instrumented process.
5846
5847See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
5848
5849|+--num-subbuf=__COUNT__+
5850
5851|
5852Allocate +__COUNT__+ sub-buffers (power of two), for each CPU, either
5853for each Unix user (default), or for each instrumented process.
5854
5855See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
5856
5857|+--tracefile-size=__SIZE__+
5858
5859|
5860Set the maximum size of each trace file that this channel writes within
5861a stream to +__SIZE__+ bytes instead of no maximum.
5862
5863See <<tracefile-rotation,Trace file count and size>>.
5864
5865|+--tracefile-count=__COUNT__+
5866
5867|
5868Limit the number of trace files that this channel creates to
5869+__COUNT__+ channels instead of no limit.
5870
5871See <<tracefile-rotation,Trace file count and size>>.
5872
5873|+--switch-timer=__PERIODUS__+
5874
5875|
5876Set the <<channel-switch-timer,switch timer period>>
5877to +__PERIODUS__+{nbsp}µs.
5878
5879|+--read-timer=__PERIODUS__+
5880
5881|
5882Set the <<channel-read-timer,read timer period>>
5883to +__PERIODUS__+{nbsp}µs.
5884
5885|+--output=__TYPE__+ (Linux kernel tracing domain only)
5886
5887|
5888Set the channel's output type to +__TYPE__+, either `mmap` or `splice`.
5889
5890|====
5891
5892You can only create a channel in the Linux kernel and user space
5893<<domain,tracing domains>>: other tracing domains have their own channel
5894created on the fly when <<enabling-disabling-events,creating event
5895rules>>.
5896
5897[IMPORTANT]
5898====
5899Because of a current LTTng limitation, you must create all channels
5900_before_ you <<basic-tracing-session-control,start tracing>> in a given
5901tracing session, that is, before the first time you run
5902man:lttng-start(1).
5903
5904Since LTTng automatically creates a default channel when you use the
5905man:lttng-enable-event(1) command with a specific tracing domain, you
5906cannot, for example, create a Linux kernel event rule, start tracing,
5907and then create a user space event rule, because no user space channel
5908exists yet and it's too late to create one.
5909
5910For this reason, make sure to configure your channels properly
5911before starting the tracers for the first time!
5912====
5913
5914The following examples show how you can combine the previous
5915command-line options to create simple to more complex channels.
5916
5917.Create a Linux kernel channel with default attributes.
5918====
5919[role="term"]
5920----
5921lttng enable-channel --kernel my-channel
5922----
5923====
5924
5925.Create a user space channel with 4 sub-buffers or 1{nbsp}MiB each, per CPU, per instrumented process.
5926====
5927[role="term"]
5928----
5929lttng enable-channel --userspace --num-subbuf=4 --subbuf-size=1M \
5930 --buffers-pid my-channel
5931----
5932====
5933
5934.Create a Linux kernel channel which rotates 8 trace files of 4{nbsp}MiB each for each stream
5935====
5936[role="term"]
5937----
5938lttng enable-channel --kernel --tracefile-count=8 \
5939 --tracefile-size=4194304 my-channel
5940----
5941====
5942
5943.Create a user space channel in overwrite (or _flight recorder_) mode.
5944====
5945[role="term"]
5946----
5947lttng enable-channel --userspace --overwrite my-channel
5948----
5949====
5950
5951You can <<enabling-disabling-events,create>> the same event rule in
5952two different channels:
5953
5954[role="term"]
5955----
5956lttng enable-event --userspace --channel=my-channel app:tp
5957lttng enable-event --userspace --channel=other-channel app:tp
5958----
5959
5960If both channels are enabled, when a tracepoint named `app:tp` is
5961reached, LTTng records two events, one for each channel.
5962
5963
5964[[disable-channel]]
5965=== Disable a channel
5966
5967To disable a specific channel that you <<enabling-disabling-channels,created>>
5968previously, use the man:lttng-disable-channel(1) command.
5969
5970.Disable a specific Linux kernel channel.
5971====
5972[role="term"]
5973----
5974lttng disable-channel --kernel my-channel
5975----
5976====
5977
5978The state of a channel precedes the individual states of event rules
5979attached to it: event rules which belong to a disabled channel, even if
5980they are enabled, are also considered disabled.
5981
5982
5983[[adding-context]]
5984=== Add context fields to a channel
5985
5986Event record fields in trace files provide important information about
5987events that occured previously, but sometimes some external context may
5988help you solve a problem faster. Examples of context fields are:
5989
5990* The **process ID**, **thread ID**, **process name**, and
5991 **process priority** of the thread in which the event occurs.
5992* The **hostname** of the system on which the event occurs.
5993* The current values of many possible **performance counters** using
5994 perf, for example:
5995** CPU cycles, stalled cycles, idle cycles, and the other cycle types.
5996** Cache misses.
5997** Branch instructions, misses, and loads.
5998** CPU faults.
5999* Any context defined at the application level (supported for the
6000 JUL and log4j <<domain,tracing domains>>).
6001
6002To get the full list of available context fields, see
6003`lttng add-context --list`. Some context fields are reserved for a
6004specific <<domain,tracing domain>> (Linux kernel or user space).
6005
6006You add context fields to <<channel,channels>>. All the events
6007that a channel with added context fields records contain those fields.
6008
6009To add context fields to one or all the channels of a given tracing
6010session:
6011
6012* Use the man:lttng-add-context(1) command.
6013
6014.Add context fields to all the channels of the current tracing session.
6015====
6016The following command line adds the virtual process identifier and
6017the per-thread CPU cycles count fields to all the user space channels
6018of the current tracing session.
6019
6020[role="term"]
6021----
6022lttng add-context --userspace --type=vpid --type=perf:thread:cpu-cycles
6023----
6024====
6025
6026.Add performance counter context fields by raw ID
6027====
6028See man:lttng-add-context(1) for the exact format of the context field
6029type, which is partly compatible with the format used in
6030man:perf-record(1).
6031
6032[role="term"]
6033----
6034lttng add-context --userspace --type=perf:thread:raw:r0110:test
6035lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted
6036----
6037====
6038
6039.Add a context field to a specific channel.
6040====
6041The following command line adds the thread identifier context field
6042to the Linux kernel channel named `my-channel` in the current
6043tracing session.
6044
6045[role="term"]
6046----
6047lttng add-context --kernel --channel=my-channel --type=tid
6048----
6049====
6050
6051.Add an application-specific context field to a specific channel.
6052====
6053The following command line adds the `cur_msg_id` context field of the
6054`retriever` context retriever for all the instrumented
6055<<java-application,Java applications>> recording <<event,event records>>
6056in the channel named `my-channel`:
6057
6058[role="term"]
6059----
6060lttng add-context --kernel --channel=my-channel \
6061 --type='$app:retriever:cur_msg_id'
6062----
6063
6064IMPORTANT: Make sure to always quote the `$` character when you
6065use man:lttng-add-context(1) from a shell.
6066====
6067
6068NOTE: You cannot remove context fields from a channel once you add it.
6069
6070
6071[role="since-2.7"]
6072[[pid-tracking]]
6073=== Track process IDs
6074
6075It's often useful to allow only specific process IDs (PIDs) to emit
6076events. For example, you may wish to record all the system calls made by
6077a given process (à la http://linux.die.net/man/1/strace[strace]).
6078
6079The man:lttng-track(1) and man:lttng-untrack(1) commands serve this
6080purpose. Both commands operate on a whitelist of process IDs. You _add_
6081entries to this whitelist with the man:lttng-track(1) command and remove
6082entries with the man:lttng-untrack(1) command. Any process which has one
6083of the PIDs in the whitelist is allowed to emit LTTng events which pass
6084an enabled <<event,event rule>>.
6085
6086NOTE: The PID tracker tracks the _numeric process IDs_. Should a
6087process with a given tracked ID exit and another process be given this
6088ID, then the latter would also be allowed to emit events.
6089
6090.Track and untrack process IDs.
6091====
6092For the sake of the following example, assume the target system has 16
6093possible PIDs.
6094
6095When you
6096<<creating-destroying-tracing-sessions,create a tracing session>>,
6097the whitelist contains all the possible PIDs:
6098
6099[role="img-100"]
6100.All PIDs are tracked.
6101image::track-all.png[]
6102
6103When the whitelist is full and you use the man:lttng-track(1) command to
6104specify some PIDs to track, LTTng first clears the whitelist, then it
6105tracks the specific PIDs. After:
6106
6107[role="term"]
6108----
6109lttng track --pid=3,4,7,10,13
6110----
6111
6112the whitelist is:
6113
6114[role="img-100"]
6115.PIDs 3, 4, 7, 10, and 13 are tracked.
6116image::track-3-4-7-10-13.png[]
6117
6118You can add more PIDs to the whitelist afterwards:
6119
6120[role="term"]
6121----
6122lttng track --pid=1,15,16
6123----
6124
6125The result is:
6126
6127[role="img-100"]
6128.PIDs 1, 15, and 16 are added to the whitelist.
6129image::track-1-3-4-7-10-13-15-16.png[]
6130
6131The man:lttng-untrack(1) command removes entries from the PID tracker's
6132whitelist. Given the previous example, the following command:
6133
6134[role="term"]
6135----
6136lttng untrack --pid=3,7,10,13
6137----
6138
6139leads to this whitelist:
6140
6141[role="img-100"]
6142.PIDs 3, 7, 10, and 13 are removed from the whitelist.
6143image::track-1-4-15-16.png[]
6144
6145LTTng can track all possible PIDs again using the opt:track(1):--all
6146option:
6147
6148[role="term"]
6149----
6150lttng track --pid --all
6151----
6152
6153The result is, again:
6154
6155[role="img-100"]
6156.All PIDs are tracked.
6157image::track-all.png[]
6158====
6159
6160.Track only specific PIDs
6161====
6162A very typical use case with PID tracking is to start with an empty
6163whitelist, then <<basic-tracing-session-control,start the tracers>>, and
6164then add PIDs manually while tracers are active. You can accomplish this
6165by using the opt:lttng-untrack(1):--all option of the
6166man:lttng-untrack(1) command to clear the whitelist after you
6167<<creating-destroying-tracing-sessions,create a tracing session>>:
6168
6169[role="term"]
6170----
6171lttng untrack --pid --all
6172----
6173
6174gives:
6175
6176[role="img-100"]
6177.No PIDs are tracked.
6178image::untrack-all.png[]
6179
6180If you trace with this whitelist configuration, the tracer records no
6181events for this <<domain,tracing domain>> because no processes are
6182tracked. You can use the man:lttng-track(1) command as usual to track
6183specific PIDs, for example:
6184
6185[role="term"]
6186----
6187lttng track --pid=6,11
6188----
6189
6190Result:
6191
6192[role="img-100"]
6193.PIDs 6 and 11 are tracked.
6194image::track-6-11.png[]
6195====
6196
6197
6198[role="since-2.5"]
6199[[saving-loading-tracing-session]]
6200=== Save and load tracing session configurations
6201
6202Configuring a <<tracing-session,tracing session>> can be long. Some of
6203the tasks involved are:
6204
6205* <<enabling-disabling-channels,Create channels>> with
6206 specific attributes.
6207* <<adding-context,Add context fields>> to specific channels.
6208* <<enabling-disabling-events,Create event rules>> with specific log
6209 level and filter conditions.
6210
6211If you use LTTng to solve real world problems, chances are you have to
6212record events using the same tracing session setup over and over,
6213modifying a few variables each time in your instrumented program
6214or environment. To avoid constant tracing session reconfiguration,
6215the man:lttng(1) command-line tool can save and load tracing session
6216configurations to/from XML files.
6217
6218To save a given tracing session configuration:
6219
6220* Use the man:lttng-save(1) command:
6221+
6222--
6223[role="term"]
6224----
6225lttng save my-session
6226----
6227--
6228+
6229Replace `my-session` with the name of the tracing session to save.
6230
6231LTTng saves tracing session configurations to
6232dir:{$LTTNG_HOME/.lttng/sessions} by default. Note that the
6233env:LTTNG_HOME environment variable defaults to `$HOME` if not set. Use
6234the opt:lttng-save(1):--output-path option to change this destination
6235directory.
6236
6237LTTng saves all configuration parameters, for example:
6238
6239* The tracing session name.
6240* The trace data output path.
6241* The channels with their state and all their attributes.
6242* The context fields you added to channels.
6243* The event rules with their state, log level and filter conditions.
6244
6245To load a tracing session:
6246
6247* Use the man:lttng-load(1) command:
6248+
6249--
6250[role="term"]
6251----
6252lttng load my-session
6253----
6254--
6255+
6256Replace `my-session` with the name of the tracing session to load.
6257
6258When LTTng loads a configuration, it restores your saved tracing session
6259as if you just configured it manually.
6260
6261See man:lttng(1) for the complete list of command-line options. You
6262can also save and load all many sessions at a time, and decide in which
6263directory to output the XML files.
6264
6265
6266[[sending-trace-data-over-the-network]]
6267=== Send trace data over the network
6268
6269LTTng can send the recorded trace data to a remote system over the
6270network instead of writing it to the local file system.
6271
6272To send the trace data over the network:
6273
6274. On the _remote_ system (which can also be the target system),
6275 start an LTTng <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)):
6276+
6277--
6278[role="term"]
6279----
6280lttng-relayd
6281----
6282--
6283
6284. On the _target_ system, create a tracing session configured to
6285 send trace data over the network:
6286+
6287--
6288[role="term"]
6289----
6290lttng create my-session --set-url=net://remote-system
6291----
6292--
6293+
6294Replace `remote-system` by the host name or IP address of the
6295remote system. See man:lttng-create(1) for the exact URL format.
6296
6297. On the target system, use the man:lttng(1) command-line tool as usual.
6298 When tracing is active, the target's consumer daemon sends sub-buffers
6299 to the relay daemon running on the remote system intead of flushing
6300 them to the local file system. The relay daemon writes the received
6301 packets to the local file system.
6302
6303The relay daemon writes trace files to
6304+$LTTNG_HOME/lttng-traces/__hostname__/__session__+ by default, where
6305+__hostname__+ is the host name of the target system and +__session__+
6306is the tracing session name. Note that the env:LTTNG_HOME environment
6307variable defaults to `$HOME` if not set. Use the
6308opt:lttng-relayd(8):--output option of man:lttng-relayd(8) to write
6309trace files to another base directory.
6310
6311
6312[role="since-2.4"]
6313[[lttng-live]]
6314=== View events as LTTng emits them (noch:{LTTng} live)
6315
6316LTTng live is a network protocol implemented by the <<lttng-relayd,relay
6317daemon>> (man:lttng-relayd(8)) to allow compatible trace viewers to
6318display events as LTTng emits them on the target system while tracing is
6319active.
6320
6321The relay daemon creates a _tee_: it forwards the trace data to both
6322the local file system and to connected live viewers:
6323
6324[role="img-90"]
6325.The relay daemon creates a _tee_, forwarding the trace data to both trace files and a connected live viewer.
6326image::live.png[]
6327
6328To use LTTng live:
6329
6330. On the _target system_, create a <<tracing-session,tracing session>>
6331 in _live mode_:
6332+
6333--
6334[role="term"]
6335----
6336lttng create --live my-session
6337----
6338--
6339+
6340This spawns a local relay daemon.
6341
6342. Start the live viewer and configure it to connect to the relay
6343 daemon. For example, with http://diamon.org/babeltrace[Babeltrace]:
6344+
6345--
6346[role="term"]
6347----
6348babeltrace --input-format=lttng-live net://localhost/host/hostname/my-session
6349----
6350--
6351+
6352Replace:
6353+
6354--
6355* `hostname` with the host name of the target system.
6356* `my-session` with the name of the tracing session to view.
6357--
6358
6359. Configure the tracing session as usual with the man:lttng(1)
6360 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6361
6362You can list the available live tracing sessions with Babeltrace:
6363
6364[role="term"]
6365----
6366babeltrace --input-format=lttng-live net://localhost
6367----
6368
6369You can start the relay daemon on another system. In this case, you need
6370to specify the relay daemon's URL when you create the tracing session
6371with the opt:lttng-create(1):--set-url option. You also need to replace
6372`localhost` in the procedure above with the host name of the system on
6373which the relay daemon is running.
6374
6375See man:lttng-create(1) and man:lttng-relayd(8) for the complete list of
6376command-line options.
6377
6378
6379[role="since-2.3"]
6380[[taking-a-snapshot]]
6381=== Take a snapshot of the current sub-buffers of a tracing session
6382
6383The normal behavior of LTTng is to append full sub-buffers to growing
6384trace data files. This is ideal to keep a full history of the events
6385that occurred on the target system, but it can
6386represent too much data in some situations. For example, you may wish
6387to trace your application continuously until some critical situation
6388happens, in which case you only need the latest few recorded
6389events to perform the desired analysis, not multi-gigabyte trace files.
6390
6391With the man:lttng-snapshot(1) command, you can take a snapshot of the
6392current sub-buffers of a given <<tracing-session,tracing session>>.
6393LTTng can write the snapshot to the local file system or send it over
6394the network.
6395
6396To take a snapshot:
6397
6398. Create a tracing session in _snapshot mode_:
6399+
6400--
6401[role="term"]
6402----
6403lttng create --snapshot my-session
6404----
6405--
6406+
6407The <<channel-overwrite-mode-vs-discard-mode,event loss mode>> of
6408<<channel,channels>> created in this mode is automatically set to
6409_overwrite_ (flight recorder mode).
6410
6411. Configure the tracing session as usual with the man:lttng(1)
6412 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6413
6414. **Optional**: When you need to take a snapshot,
6415 <<basic-tracing-session-control,stop tracing>>.
6416+
6417You can take a snapshot when the tracers are active, but if you stop
6418them first, you are sure that the data in the sub-buffers does not
6419change before you actually take the snapshot.
6420
6421. Take a snapshot:
6422+
6423--
6424[role="term"]
6425----
6426lttng snapshot record --name=my-first-snapshot
6427----
6428--
6429+
6430LTTng writes the current sub-buffers of all the current tracing
6431session's channels to trace files on the local file system. Those trace
6432files have `my-first-snapshot` in their name.
6433
6434There is no difference between the format of a normal trace file and the
6435format of a snapshot: viewers of LTTng traces also support LTTng
6436snapshots.
6437
6438By default, LTTng writes snapshot files to the path shown by
6439`lttng snapshot list-output`. You can change this path or decide to send
6440snapshots over the network using either:
6441
6442. An output path or URL that you specify when you create the
6443 tracing session.
6444. An snapshot output path or URL that you add using
6445 `lttng snapshot add-output`
6446. An output path or URL that you provide directly to the
6447 `lttng snapshot record` command.
6448
6449Method 3 overrides method 2, which overrides method 1. When you
6450specify a URL, a relay daemon must listen on a remote system (see
6451<<sending-trace-data-over-the-network,Send trace data over the network>>).
6452
6453
6454[role="since-2.6"]
6455[[mi]]
6456=== Use the machine interface
6457
6458With any command of the man:lttng(1) command-line tool, you can set the
6459opt:lttng(1):--mi option to `xml` (before the command name) to get an
6460XML machine interface output, for example:
6461
6462[role="term"]
6463----
6464lttng --mi=xml enable-event --kernel --syscall open
6465----
6466
6467A schema definition (XSD) is
6468https://github.com/lttng/lttng-tools/blob/stable-2.9/src/common/mi-lttng-3.0.xsd[available]
6469to ease the integration with external tools as much as possible.
6470
6471
6472[role="since-2.8"]
6473[[metadata-regenerate]]
6474=== Regenerate the metadata of an LTTng trace
6475
6476An LTTng trace, which is a http://diamon.org/ctf[CTF] trace, has both
6477data stream files and a metadata file. This metadata file contains,
6478amongst other things, information about the offset of the clock sources
6479used to timestamp <<event,event records>> when tracing.
6480
6481If, once a <<tracing-session,tracing session>> is
6482<<basic-tracing-session-control,started>>, a major
6483https://en.wikipedia.org/wiki/Network_Time_Protocol[NTP] correction
6484happens, the trace's clock offset also needs to be updated. You
6485can use the `metadata` item of the man:lttng-regenerate(1) command
6486to do so.
6487
6488The main use case of this command is to allow a system to boot with
6489an incorrect wall time and trace it with LTTng before its wall time
6490is corrected. Once the system is known to be in a state where its
6491wall time is correct, it can run `lttng regenerate metadata`.
6492
6493To regenerate the metadata of an LTTng trace:
6494
6495* Use the `metadata` item of the man:lttng-regenerate(1) command:
6496+
6497--
6498[role="term"]
6499----
6500lttng regenerate metadata
6501----
6502--
6503
6504[IMPORTANT]
6505====
6506`lttng regenerate metadata` has the following limitations:
6507
6508* Tracing session <<creating-destroying-tracing-sessions,created>>
6509 in non-live mode.
6510* User space <<channel,channels>>, if any, are using
6511 <<channel-buffering-schemes,per-user buffering>>.
6512====
6513
6514
6515[role="since-2.9"]
6516[[regenerate-statedump]]
6517=== Regenerate the state dump of a tracing session
6518
6519The LTTng kernel and user space tracers generate state dump
6520<<event,event records>> when the application starts or when you
6521<<basic-tracing-session-control,start a tracing session>>. An analysis
6522can use the state dump event records to set an initial state before it
6523builds the rest of the state from the following event records.
6524http://tracecompass.org/[Trace Compass] is a notable example of an
6525application which uses the state dump of an LTTng trace.
6526
6527When you <<taking-a-snapshot,take a snapshot>>, it's possible that the
6528state dump event records are not included in the snapshot because they
6529were recorded to a sub-buffer that has been consumed or overwritten
6530already.
6531
6532You can use the `lttng regenerate statedump` command to emit the state
6533dump event records again.
6534
6535To regenerate the state dump of the current tracing session, provided
6536create it in snapshot mode, before you take a snapshot:
6537
6538. Use the `statedump` item of the man:lttng-regenerate(1) command:
6539+
6540--
6541[role="term"]
6542----
6543lttng regenerate statedump
6544----
6545--
6546
6547. <<basic-tracing-session-control,Stop the tracing session>>:
6548+
6549--
6550[role="term"]
6551----
6552lttng stop
6553----
6554--
6555
6556. <<taking-a-snapshot,Take a snapshot>>:
6557+
6558--
6559[role="term"]
6560----
6561lttng snapshot record --name=my-snapshot
6562----
6563--
6564
6565Depending on the event throughput, you should run steps 1 and 2
6566as closely as possible.
6567
6568NOTE: To record the state dump events, you need to
6569<<enabling-disabling-events,create event rules>> which enable them.
6570LTTng-UST state dump tracepoints start with `lttng_ust_statedump:`.
6571LTTng-modules state dump tracepoints start with `lttng_statedump_`.
6572
6573
6574[role="since-2.7"]
6575[[persistent-memory-file-systems]]
6576=== Record trace data on persistent memory file systems
6577
6578https://en.wikipedia.org/wiki/Non-volatile_random-access_memory[Non-volatile random-access memory]
6579(NVRAM) is random-access memory that retains its information when power
6580is turned off (non-volatile). Systems with such memory can store data
6581structures in RAM and retrieve them after a reboot, without flushing
6582to typical _storage_.
6583
6584Linux supports NVRAM file systems thanks to either
6585http://pramfs.sourceforge.net/[PRAMFS] or
6586https://www.kernel.org/doc/Documentation/filesystems/dax.txt[DAX]{nbsp}+{nbsp}http://lkml.iu.edu/hypermail/linux/kernel/1504.1/03463.html[pmem]
6587(requires Linux 4.1+).
6588
6589This section does not describe how to operate such file systems;
6590we assume that you have a working persistent memory file system.
6591
6592When you create a <<tracing-session,tracing session>>, you can specify
6593the path of the shared memory holding the sub-buffers. If you specify a
6594location on an NVRAM file system, then you can retrieve the latest
6595recorded trace data when the system reboots after a crash.
6596
6597To record trace data on a persistent memory file system and retrieve the
6598trace data after a system crash:
6599
6600. Create a tracing session with a sub-buffer shared memory path located
6601 on an NVRAM file system:
6602+
6603--
6604[role="term"]
6605----
6606lttng create --shm-path=/path/to/shm
6607----
6608--
6609
6610. Configure the tracing session as usual with the man:lttng(1)
6611 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6612
6613. After a system crash, use the man:lttng-crash(1) command-line tool to
6614 view the trace data recorded on the NVRAM file system:
6615+
6616--
6617[role="term"]
6618----
6619lttng-crash /path/to/shm
6620----
6621--
6622
6623The binary layout of the ring buffer files is not exactly the same as
6624the trace files layout. This is why you need to use man:lttng-crash(1)
6625instead of your preferred trace viewer directly.
6626
6627To convert the ring buffer files to LTTng trace files:
6628
6629* Use the opt:lttng-crash(1):--extract option of man:lttng-crash(1):
6630+
6631--
6632[role="term"]
6633----
6634lttng-crash --extract=/path/to/trace /path/to/shm
6635----
6636--
6637
6638
6639[[reference]]
6640== Reference
6641
6642[[lttng-modules-ref]]
6643=== noch:{LTTng-modules}
6644
6645
6646[role="since-2.9"]
6647[[lttng-tracepoint-enum]]
6648==== `LTTNG_TRACEPOINT_ENUM()` usage
6649
6650Use the `LTTNG_TRACEPOINT_ENUM()` macro to define an enumeration:
6651
6652[source,c]
6653----
6654LTTNG_TRACEPOINT_ENUM(name, TP_ENUM_VALUES(entries))
6655----
6656
6657Replace:
6658
6659* `name` with the name of the enumeration (C identifier, unique
6660 amongst all the defined enumerations).
6661* `entries` with a list of enumeration entries.
6662
6663The available enumeration entry macros are:
6664
6665+ctf_enum_value(__name__, __value__)+::
6666 Entry named +__name__+ mapped to the integral value +__value__+.
6667
6668+ctf_enum_range(__name__, __begin__, __end__)+::
6669 Entry named +__name__+ mapped to the range of integral values between
6670 +__begin__+ (included) and +__end__+ (included).
6671
6672+ctf_enum_auto(__name__)+::
6673 Entry named +__name__+ mapped to the integral value following the
6674 last mapping's value.
6675+
6676The last value of a `ctf_enum_value()` entry is its +__value__+
6677parameter.
6678+
6679The last value of a `ctf_enum_range()` entry is its +__end__+ parameter.
6680+
6681If `ctf_enum_auto()` is the first entry in the list, its integral
6682value is 0.
6683
6684Use the `ctf_enum()` <<lttng-modules-tp-fields,field definition macro>>
6685to use a defined enumeration as a tracepoint field.
6686
6687.Define an enumeration with `LTTNG_TRACEPOINT_ENUM()`.
6688====
6689[source,c]
6690----
6691LTTNG_TRACEPOINT_ENUM(
6692 my_enum,
6693 TP_ENUM_VALUES(
6694 ctf_enum_auto("AUTO: EXPECT 0")
6695 ctf_enum_value("VALUE: 23", 23)
6696 ctf_enum_value("VALUE: 27", 27)
6697 ctf_enum_auto("AUTO: EXPECT 28")
6698 ctf_enum_range("RANGE: 101 TO 303", 101, 303)
6699 ctf_enum_auto("AUTO: EXPECT 304")
6700 )
6701)
6702----
6703====
6704
6705
6706[role="since-2.7"]
6707[[lttng-modules-tp-fields]]
6708==== Tracepoint fields macros (for `TP_FIELDS()`)
6709
6710[[tp-fast-assign]][[tp-struct-entry]]The available macros to define
6711tracepoint fields, which must be listed within `TP_FIELDS()` in
6712`LTTNG_TRACEPOINT_EVENT()`, are:
6713
6714[role="func-desc growable",cols="asciidoc,asciidoc"]
6715.Available macros to define LTTng-modules tracepoint fields
6716|====
6717|Macro |Description and parameters
6718
6719|
6720+ctf_integer(__t__, __n__, __e__)+
6721
6722+ctf_integer_nowrite(__t__, __n__, __e__)+
6723
6724+ctf_user_integer(__t__, __n__, __e__)+
6725
6726+ctf_user_integer_nowrite(__t__, __n__, __e__)+
6727|
6728Standard integer, displayed in base 10.
6729
6730+__t__+::
6731 Integer C type (`int`, `long`, `size_t`, ...).
6732
6733+__n__+::
6734 Field name.
6735
6736+__e__+::
6737 Argument expression.
6738
6739|
6740+ctf_integer_hex(__t__, __n__, __e__)+
6741
6742+ctf_user_integer_hex(__t__, __n__, __e__)+
6743|
6744Standard integer, displayed in base 16.
6745
6746+__t__+::
6747 Integer C type.
6748
6749+__n__+::
6750 Field name.
6751
6752+__e__+::
6753 Argument expression.
6754
6755|+ctf_integer_oct(__t__, __n__, __e__)+
6756|
6757Standard integer, displayed in base 8.
6758
6759+__t__+::
6760 Integer C type.
6761
6762+__n__+::
6763 Field name.
6764
6765+__e__+::
6766 Argument expression.
6767
6768|
6769+ctf_integer_network(__t__, __n__, __e__)+
6770
6771+ctf_user_integer_network(__t__, __n__, __e__)+
6772|
6773Integer in network byte order (big-endian), displayed in base 10.
6774
6775+__t__+::
6776 Integer C type.
6777
6778+__n__+::
6779 Field name.
6780
6781+__e__+::
6782 Argument expression.
6783
6784|
6785+ctf_integer_network_hex(__t__, __n__, __e__)+
6786
6787+ctf_user_integer_network_hex(__t__, __n__, __e__)+
6788|
6789Integer in network byte order, displayed in base 16.
6790
6791+__t__+::
6792 Integer C type.
6793
6794+__n__+::
6795 Field name.
6796
6797+__e__+::
6798 Argument expression.
6799
6800|
6801+ctf_enum(__N__, __t__, __n__, __e__)+
6802
6803+ctf_enum_nowrite(__N__, __t__, __n__, __e__)+
6804
6805+ctf_user_enum(__N__, __t__, __n__, __e__)+
6806
6807+ctf_user_enum_nowrite(__N__, __t__, __n__, __e__)+
6808|
6809Enumeration.
6810
6811+__N__+::
6812 Name of a <<lttng-tracepoint-enum,previously defined enumeration>>.
6813
6814+__t__+::
6815 Integer C type (`int`, `long`, `size_t`, ...).
6816
6817+__n__+::
6818 Field name.
6819
6820+__e__+::
6821 Argument expression.
6822
6823|
6824+ctf_string(__n__, __e__)+
6825
6826+ctf_string_nowrite(__n__, __e__)+
6827
6828+ctf_user_string(__n__, __e__)+
6829
6830+ctf_user_string_nowrite(__n__, __e__)+
6831|
6832Null-terminated string; undefined behavior if +__e__+ is `NULL`.
6833
6834+__n__+::
6835 Field name.
6836
6837+__e__+::
6838 Argument expression.
6839
6840|
6841+ctf_array(__t__, __n__, __e__, __s__)+
6842
6843+ctf_array_nowrite(__t__, __n__, __e__, __s__)+
6844
6845+ctf_user_array(__t__, __n__, __e__, __s__)+
6846
6847+ctf_user_array_nowrite(__t__, __n__, __e__, __s__)+
6848|
6849Statically-sized array of integers.
6850
6851+__t__+::
6852 Array element C type.
6853
6854+__n__+::
6855 Field name.
6856
6857+__e__+::
6858 Argument expression.
6859
6860+__s__+::
6861 Number of elements.
6862
6863|
6864+ctf_array_bitfield(__t__, __n__, __e__, __s__)+
6865
6866+ctf_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
6867
6868+ctf_user_array_bitfield(__t__, __n__, __e__, __s__)+
6869
6870+ctf_user_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
6871|
6872Statically-sized array of bits.
6873
6874The type of +__e__+ must be an integer type. +__s__+ is the number
6875of elements of such type in +__e__+, not the number of bits.
6876
6877+__t__+::
6878 Array element C type.
6879
6880+__n__+::
6881 Field name.
6882
6883+__e__+::
6884 Argument expression.
6885
6886+__s__+::
6887 Number of elements.
6888
6889|
6890+ctf_array_text(__t__, __n__, __e__, __s__)+
6891
6892+ctf_array_text_nowrite(__t__, __n__, __e__, __s__)+
6893
6894+ctf_user_array_text(__t__, __n__, __e__, __s__)+
6895
6896+ctf_user_array_text_nowrite(__t__, __n__, __e__, __s__)+
6897|
6898Statically-sized array, printed as text.
6899
6900The string does not need to be null-terminated.
6901
6902+__t__+::
6903 Array element C type (always `char`).
6904
6905+__n__+::
6906 Field name.
6907
6908+__e__+::
6909 Argument expression.
6910
6911+__s__+::
6912 Number of elements.
6913
6914|
6915+ctf_sequence(__t__, __n__, __e__, __T__, __E__)+
6916
6917+ctf_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
6918
6919+ctf_user_sequence(__t__, __n__, __e__, __T__, __E__)+
6920
6921+ctf_user_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
6922|
6923Dynamically-sized array of integers.
6924
6925The type of +__E__+ must be unsigned.
6926
6927+__t__+::
6928 Array element C type.
6929
6930+__n__+::
6931 Field name.
6932
6933+__e__+::
6934 Argument expression.
6935
6936+__T__+::
6937 Length expression C type.
6938
6939+__E__+::
6940 Length expression.
6941
6942|
6943+ctf_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
6944
6945+ctf_user_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
6946|
6947Dynamically-sized array of integers, displayed in base 16.
6948
6949The type of +__E__+ must be unsigned.
6950
6951+__t__+::
6952 Array element C type.
6953
6954+__n__+::
6955 Field name.
6956
6957+__e__+::
6958 Argument expression.
6959
6960+__T__+::
6961 Length expression C type.
6962
6963+__E__+::
6964 Length expression.
6965
6966|+ctf_sequence_network(__t__, __n__, __e__, __T__, __E__)+
6967|
6968Dynamically-sized array of integers in network byte order (big-endian),
6969displayed in base 10.
6970
6971The type of +__E__+ must be unsigned.
6972
6973+__t__+::
6974 Array element C type.
6975
6976+__n__+::
6977 Field name.
6978
6979+__e__+::
6980 Argument expression.
6981
6982+__T__+::
6983 Length expression C type.
6984
6985+__E__+::
6986 Length expression.
6987
6988|
6989+ctf_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
6990
6991+ctf_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
6992
6993+ctf_user_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
6994
6995+ctf_user_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
6996|
6997Dynamically-sized array of bits.
6998
6999The type of +__e__+ must be an integer type. +__s__+ is the number
7000of elements of such type in +__e__+, not the number of bits.
7001
7002The type of +__E__+ must be unsigned.
7003
7004+__t__+::
7005 Array element C type.
7006
7007+__n__+::
7008 Field name.
7009
7010+__e__+::
7011 Argument expression.
7012
7013+__T__+::
7014 Length expression C type.
7015
7016+__E__+::
7017 Length expression.
7018
7019|
7020+ctf_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7021
7022+ctf_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7023
7024+ctf_user_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7025
7026+ctf_user_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7027|
7028Dynamically-sized array, displayed as text.
7029
7030The string does not need to be null-terminated.
7031
7032The type of +__E__+ must be unsigned.
7033
7034The behaviour is undefined if +__e__+ is `NULL`.
7035
7036+__t__+::
7037 Sequence element C type (always `char`).
7038
7039+__n__+::
7040 Field name.
7041
7042+__e__+::
7043 Argument expression.
7044
7045+__T__+::
7046 Length expression C type.
7047
7048+__E__+::
7049 Length expression.
7050|====
7051
7052Use the `_user` versions when the argument expression, `e`, is
7053a user space address. In the cases of `ctf_user_integer*()` and
7054`ctf_user_float*()`, `&e` must be a user space address, thus `e` must
7055be addressable.
7056
7057The `_nowrite` versions omit themselves from the session trace, but are
7058otherwise identical. This means the `_nowrite` fields won't be written
7059in the recorded trace. Their primary purpose is to make some
7060of the event context available to the
7061<<enabling-disabling-events,event filters>> without having to
7062commit the data to sub-buffers.
7063
7064
7065[[glossary]]
7066== Glossary
7067
7068Terms related to LTTng and to tracing in general:
7069
7070Babeltrace::
7071 The http://diamon.org/babeltrace[Babeltrace] project, which includes
7072 the cmd:babeltrace command, some libraries, and Python bindings.
7073
7074<<channel-buffering-schemes,buffering scheme>>::
7075 A layout of sub-buffers applied to a given channel.
7076
7077<<channel,channel>>::
7078 An entity which is responsible for a set of ring buffers.
7079+
7080<<event,Event rules>> are always attached to a specific channel.
7081
7082clock::
7083 A reference of time for a tracer.
7084
7085<<lttng-consumerd,consumer daemon>>::
7086 A process which is responsible for consuming the full sub-buffers
7087 and write them to a file system or send them over the network.
7088
7089<<channel-overwrite-mode-vs-discard-mode,discard mode>>:: The event loss
7090 mode in which the tracer _discards_ new event records when there's no
7091 sub-buffer space left to store them.
7092
7093event::
7094 The consequence of the execution of an instrumentation
7095 point, like a tracepoint that you manually place in some source code,
7096 or a Linux kernel KProbe.
7097+
7098An event is said to _occur_ at a specific time. Different actions can
7099be taken upon the occurance of an event, like record the event's payload
7100to a sub-buffer.
7101
7102<<channel-overwrite-mode-vs-discard-mode,event loss mode>>::
7103 The mechanism by which event records of a given channel are lost
7104 (not recorded) when there is no sub-buffer space left to store them.
7105
7106[[def-event-name]]event name::
7107 The name of an event, which is also the name of the event record.
7108 This is also called the _instrumentation point name_.
7109
7110event record::
7111 A record, in a trace, of the payload of an event which occured.
7112
7113<<event,event rule>>::
7114 Set of conditions which must be satisfied for one or more occuring
7115 events to be recorded.
7116
7117`java.util.logging`::
7118 Java platform's
7119 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[core logging facilities].
7120
7121<<instrumenting,instrumentation>>::
7122 The use of LTTng probes to make a piece of software traceable.
7123
7124instrumentation point::
7125 A point in the execution path of a piece of software that, when
7126 reached by this execution, can emit an event.
7127
7128instrumentation point name::
7129 See _<<def-event-name,event name>>_.
7130
7131log4j::
7132 A http://logging.apache.org/log4j/1.2/[logging library] for Java
7133 developed by the Apache Software Foundation.
7134
7135log level::
7136 Level of severity of a log statement or user space
7137 instrumentation point.
7138
7139LTTng::
7140 The _Linux Trace Toolkit: next generation_ project.
7141
7142<<lttng-cli,cmd:lttng>>::
7143 A command-line tool provided by the LTTng-tools project which you
7144 can use to send and receive control messages to and from a
7145 session daemon.
7146
7147LTTng analyses::
7148 The https://github.com/lttng/lttng-analyses[LTTng analyses] project,
7149 which is a set of analyzing programs that are used to obtain a
7150 higher level view of an LTTng trace.
7151
7152cmd:lttng-consumerd::
7153 The name of the consumer daemon program.
7154
7155cmd:lttng-crash::
7156 A utility provided by the LTTng-tools project which can convert
7157 ring buffer files (usually
7158 <<persistent-memory-file-systems,saved on a persistent memory file system>>)
7159 to trace files.
7160
7161LTTng Documentation::
7162 This document.
7163
7164<<lttng-live,LTTng live>>::
7165 A communication protocol between the relay daemon and live viewers
7166 which makes it possible to see events "live", as they are received by
7167 the relay daemon.
7168
7169<<lttng-modules,LTTng-modules>>::
7170 The https://github.com/lttng/lttng-modules[LTTng-modules] project,
7171 which contains the Linux kernel modules to make the Linux kernel
7172 instrumentation points available for LTTng tracing.
7173
7174cmd:lttng-relayd::
7175 The name of the relay daemon program.
7176
7177cmd:lttng-sessiond::
7178 The name of the session daemon program.
7179
7180LTTng-tools::
7181 The https://github.com/lttng/lttng-tools[LTTng-tools] project, which
7182 contains the various programs and libraries used to
7183 <<controlling-tracing,control tracing>>.
7184
7185<<lttng-ust,LTTng-UST>>::
7186 The https://github.com/lttng/lttng-ust[LTTng-UST] project, which
7187 contains libraries to instrument user applications.
7188
7189<<lttng-ust-agents,LTTng-UST Java agent>>::
7190 A Java package provided by the LTTng-UST project to allow the
7191 LTTng instrumentation of `java.util.logging` and Apache log4j 1.2
7192 logging statements.
7193
7194<<lttng-ust-agents,LTTng-UST Python agent>>::
7195 A Python package provided by the LTTng-UST project to allow the
7196 LTTng instrumentation of Python logging statements.
7197
7198<<channel-overwrite-mode-vs-discard-mode,overwrite mode>>::
7199 The event loss mode in which new event records overwrite older
7200 event records when there's no sub-buffer space left to store them.
7201
7202<<channel-buffering-schemes,per-process buffering>>::
7203 A buffering scheme in which each instrumented process has its own
7204 sub-buffers for a given user space channel.
7205
7206<<channel-buffering-schemes,per-user buffering>>::
7207 A buffering scheme in which all the processes of a Unix user share the
7208 same sub-buffer for a given user space channel.
7209
7210<<lttng-relayd,relay daemon>>::
7211 A process which is responsible for receiving the trace data sent by
7212 a distant consumer daemon.
7213
7214ring buffer::
7215 A set of sub-buffers.
7216
7217<<lttng-sessiond,session daemon>>::
7218 A process which receives control commands from you and orchestrates
7219 the tracers and various LTTng daemons.
7220
7221<<taking-a-snapshot,snapshot>>::
7222 A copy of the current data of all the sub-buffers of a given tracing
7223 session, saved as trace files.
7224
7225sub-buffer::
7226 One part of an LTTng ring buffer which contains event records.
7227
7228timestamp::
7229 The time information attached to an event when it is emitted.
7230
7231trace (_noun_)::
7232 A set of files which are the concatenations of one or more
7233 flushed sub-buffers.
7234
7235trace (_verb_)::
7236 The action of recording the events emitted by an application
7237 or by a system, or to initiate such recording by controlling
7238 a tracer.
7239
7240Trace Compass::
7241 The http://tracecompass.org[Trace Compass] project and application.
7242
7243tracepoint::
7244 An instrumentation point using the tracepoint mechanism of the Linux
7245 kernel or of LTTng-UST.
7246
7247tracepoint definition::
7248 The definition of a single tracepoint.
7249
7250tracepoint name::
7251 The name of a tracepoint.
7252
7253tracepoint provider::
7254 A set of functions providing tracepoints to an instrumented user
7255 application.
7256+
7257Not to be confused with a _tracepoint provider package_: many tracepoint
7258providers can exist within a tracepoint provider package.
7259
7260tracepoint provider package::
7261 One or more tracepoint providers compiled as an object file or as
7262 a shared library.
7263
7264tracer::
7265 A software which records emitted events.
7266
7267<<domain,tracing domain>>::
7268 A namespace for event sources.
7269
7270tracing group::
7271 The Unix group in which a Unix user can be to be allowed to trace the
7272 Linux kernel.
7273
7274<<tracing-session,tracing session>>::
7275 A stateful dialogue between you and a <<lttng-sessiond,session
7276 daemon>>.
7277
7278user application::
7279 An application running in user space, as opposed to a Linux kernel
7280 module, for example.
This page took 0.416006 seconds and 4 git commands to generate.