2.13: fix two-line example title
[lttng-docs.git] / 2.13 / lttng-docs-2.13.txt
CommitLineData
50e95807
PP
1The LTTng Documentation
2=======================
3Philippe Proulx <pproulx@efficios.com>
4v2.13, 15 June 2021
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+
25Skip this section if you’re familiar with software tracing and with the
26LTTng 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+
32Skip this section if you already properly installed LTTng on your target
33system.
34
35* ``**<<getting-started,Quick start>>**'' is a concise guide to
36 get 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+
41Skip 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
50 components of the LTTng machinery, like the daemons, the libraries,
51 and the command-line interface.
52
53* ``**<<instrumenting,Instrumentation>>**'' shows different ways to
54 instrument user applications and the Linux kernel for LTTng tracing.
55+
56Instrumenting source code is essential to provide a meaningful
57source of events.
58+
59Skip this section if you don't have a programming background.
60
61* ``**<<controlling-tracing,Tracing control>>**'' is divided into topics
62 which demonstrate how to use the vast array of features that
63 LTTng{nbsp}{revision} offers.
64
65* ``**<<reference,Reference>>**'' contains API reference tables.
66
67* ``**<<glossary,Glossary>>**'' is a specialized dictionary of terms
68 related to LTTng or to the field of software tracing.
69
70
71include::../common/convention.txt[]
72
73
74include::../common/acknowledgements.txt[]
75
76
77[[whats-new]]
78== What's new in LTTng{nbsp}{revision}?
79
80LTTng{nbsp}{revision} bears the name _Nordicité_, the product of a
81collaboration between https://champlibre.co/[Champ Libre] and
075bb206 82https://www.boreale.com/[Boréale]. This farmhouse IPA is brewed with
50e95807
PP
83https://en.wikipedia.org/wiki/Kveik[Kveik] yeast and Québec-grown
84barley, oats, and juniper branches. The result is a remarkable, fruity,
85hazy golden IPA that offers a balanced touch of resinous and woodsy
86bitterness.
87
88New features and changes in LTTng{nbsp}{revision}:
89
90General::
91+
92* The LTTng trigger API of <<liblttng-ctl-lttng,`liblttng-ctl`>> now
93 offers the ``__event rule matches__'' condition (an <<event-rule,event
94 rule>> matches an event) as well as the following new actions:
95+
96--
97* <<basic-tracing-session-control,Start or stop>> a recording session.
98* <<session-rotation,Archive the current trace chunk>> of a
99 recording session (rotate).
100* <<taking-a-snapshot,Take a snapshot>> of a recording session.
101--
102+
103As a reminder, a <<trigger,trigger>> is a condition-actions pair. When
104the condition of a trigger is satisfied, LTTng attempts to execute its
105actions.
106+
107This feature is also available with the new man:lttng-add-trigger(1),
108man:lttng-remove-trigger(1), and man:lttng-list-triggers(1)
109<<lttng-cli,cmd:lttng>> commands.
110+
111Starting from LTTng{nbsp}{revision}, a trigger may have more than one
112action.
113+
114See “<<add-event-rule-matches-trigger,Add an ``event rule matches''
115trigger to a session daemon>>” to learn more.
116
117* The LTTng <<lttng-ust,user space>> and <<lttng-modules,kernel>>
118 tracers offer the new namespace context field `time_ns`, which is the
119 inode number, in the proc file system, of the current clock namespace.
120+
121See man:lttng-add-context(1), man:lttng-ust(3), and
122man:time_namespaces(7).
123
124* The link:/man[manual pages] of LTTng-tools now have a terminology and
125 style which match the LTTng Documentation, many fixes, more internal
126 and manual page links, clearer lists and procedures, superior
127 consistency, and usage examples.
128+
129The new man:lttng-event-rule(7) manual page explains the new, common
130way to specify an event rule on the command line.
131+
132The new man:lttng-concepts(7) manual page explains the core concepts of
133LTTng. Its contents is essentially the ``<<core-concepts,Core
134concepts>>'' section of this documentation, but more adapted to the
135manual page style.
136
137User space tracing::
138+
139[IMPORTANT]
140====
141The major version part of the `liblttng-ust`
142https://en.wikipedia.org/wiki/Soname[soname] is bumped, which means you
143**must recompile** your instrumented applications/libraries and
144<<tracepoint-provider,tracepoint provider packages>> to use
145LTTng-UST{nbsp}{revision}.
146
147This change became a necessity to clean up the library and for
148`liblttng-ust` to stop exporting private symbols.
149
150Also, LTTng{nbsp}{revision} prepends the `lttng_ust_` and `LTTNG_UST_`
151prefix to all public macro/definition/function names to offer a
152consistent API namespace. The LTTng{nbsp}2.12 API is still available;
153see the ``Compatibility with previous APIs'' section of
154man:lttng-ust(3).
155====
156+
157Other notable changes:
158+
159* The `liblttng-ust` C{nbsp}API offers the new man:lttng_ust_vtracef(3)
160 and man:lttng_ust_vtracelog(3) macros which are to
161 man:lttng_ust_tracef(3) and man:lttng_ust_tracelog(3) what
162 man:vprintf(3) is to man:printf(3).
163
164* LTTng-UST now only depends on https://liburcu.org/[`liburcu`] at build
165 time, not at run time.
166
167Kernel tracing::
168+
169* The preferred display base of event record integer fields which
170 contain memory addresses is now hexadecimal instead of decimal.
171
172* The `pid` field is removed from `lttng_statedump_file_descriptor`
173 event records and the `file_table_address` field is added.
174+
175This new field is the address of the `files_struct` structure which
176contains the file descriptor.
177+
178See the
179``https://github.com/lttng/lttng-modules/commit/e7a0ca7205fd4be7c829d171baa8823fe4784c90[statedump: introduce `file_table_address`]''
180patch to learn more.
181
182* The `flags` field of `syscall_entry_clone` event records is now a
183 structure containing two enumerations (exit signal and options).
184+
185This change makes the flag values more readable and meaningful.
186+
187See the
188``https://github.com/lttng/lttng-modules/commit/d775625e2ba4825b73b5897e7701ad6e2bdba115[syscalls: Make `clone()`'s `flags` field a 2 enum struct]''
189patch to learn more.
190
191* The memory footprint of the kernel tracer is improved: the latter only
192 generates metadata for the specific system call recording event rules
193 that you <<enabling-disabling-events,create>>.
194
195
196[[nuts-and-bolts]]
197== Nuts and bolts
198
199What is LTTng? As its name suggests, the _Linux Trace Toolkit: next
200generation_ is a modern toolkit for tracing Linux systems and
201applications. So your first question might be:
202**what is tracing?**
203
204
205[[what-is-tracing]]
206=== What is tracing?
207
208As the history of software engineering progressed and led to what
209we now take for granted--complex, numerous and
210interdependent software applications running in parallel on
211sophisticated operating systems like Linux--the authors of such
212components, software developers, began feeling a natural
213urge to have tools that would ensure the robustness and good performance
214of their masterpieces.
215
216One major achievement in this field is, inarguably, the
217https://www.gnu.org/software/gdb/[GNU debugger (GDB)],
218an essential tool for developers to find and fix bugs. But even the best
219debugger won't help make your software run faster, and nowadays, faster
220software means either more work done by the same hardware, or cheaper
221hardware for the same work.
222
223A _profiler_ is often the tool of choice to identify performance
224bottlenecks. Profiling is suitable to identify _where_ performance is
225lost in a given piece of software. The profiler outputs a profile, a
226statistical summary of observed events, which you may use to discover
227which functions took the most time to execute. However, a profiler won't
228report _why_ some identified functions are the bottleneck. Bottlenecks
229might only occur when specific conditions are met, conditions that are
230sometimes impossible to capture by a statistical profiler, or impossible
231to reproduce with an application altered by the overhead of an
232event-based profiler. For a thorough investigation of software
233performance issues, a history of execution is essential, with the
234recorded values of variables and context fields you choose, and with as
235little influence as possible on the instrumented application. This is
236where tracing comes in handy.
237
238_Tracing_ is a technique used to understand what goes on in a running
239software system. The piece of software used for tracing is called a
240_tracer_, which is conceptually similar to a tape recorder. When
241recording, specific instrumentation points placed in the software source
242code generate events that are saved on a giant tape: a _trace_ file. You
243can record user application and operating system events at the same
244time, opening the possibility of resolving a wide range of problems that
245would otherwise be extremely challenging.
246
247Tracing is often compared to _logging_. However, tracers and loggers are
248two different tools, serving two different purposes. Tracers are
249designed to record much lower-level events that occur much more
250frequently than log messages, often in the range of thousands per
251second, with very little execution overhead. Logging is more appropriate
252for a very high-level analysis of less frequent events: user accesses,
253exceptional conditions (errors and warnings, for example), database
254transactions, instant messaging communications, and such. Simply put,
255logging is one of the many use cases that can be satisfied with tracing.
256
257The list of recorded events inside a trace file can be read manually
258like a log file for the maximum level of detail, but it's generally
259much more interesting to perform application-specific analyses to
260produce reduced statistics and graphs that are useful to resolve a
261given problem. Trace viewers and analyzers are specialized tools
262designed to do this.
263
264In the end, this is what LTTng is: a powerful, open source set of
265tools to trace the Linux kernel and user applications at the same time.
266LTTng is composed of several components actively maintained and
267developed by its link:/community/#where[community].
268
269
270[[lttng-alternatives]]
271=== Alternatives to noch:{LTTng}
272
273Excluding proprietary solutions, a few competing software tracers
274exist for Linux:
275
276https://github.com/dtrace4linux/linux[dtrace4linux]::
277 A port of Sun Microsystems' DTrace to Linux.
278+
279The cmd:dtrace tool interprets user scripts and is responsible for
280loading code into the Linux kernel for further execution and collecting
281the outputted data.
282
283https://en.wikipedia.org/wiki/Berkeley_Packet_Filter[eBPF]::
284 A subsystem in the Linux kernel in which a virtual machine can
285 execute programs passed from the user space to the kernel.
286+
287You can attach such programs to tracepoints and kprobes thanks to a
288system call, and they can output data to the user space when executed
289thanks to different mechanisms (pipe, VM register values, and eBPF maps,
290to name a few).
291
292https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace]::
293 The de facto function tracer of the Linux kernel.
294+
295Its user interface is a set of special files in sysfs.
296
297https://perf.wiki.kernel.org/[perf]::
298 A performance analysis tool for Linux which supports hardware
299 performance counters, tracepoints, as well as other counters and
300 types of probes.
301+
302The controlling utility of perf is the cmd:perf command line/text UI
303tool.
304
305https://linux.die.net/man/1/strace[strace]::
306 A command-line utility which records system calls made by a
307 user process, as well as signal deliveries and changes of process
308 state.
309+
310strace makes use of https://en.wikipedia.org/wiki/Ptrace[ptrace] to
311fulfill its function.
312
313https://www.sysdig.org/[sysdig]::
314 Like SystemTap, uses scripts to analyze Linux kernel events.
315+
316You write scripts, or _chisels_ in the jargon of sysdig, in Lua and
317sysdig executes them while it traces the system or afterwards. The
318interface of sysdig is the cmd:sysdig command-line tool as well as the
319text UI-based cmd:csysdig tool.
320
321https://sourceware.org/systemtap/[SystemTap]::
322 A Linux kernel and user space tracer which uses custom user scripts
323 to produce plain text traces.
324+
325SystemTap converts the scripts to the C language, and then compiles them
326as Linux kernel modules which are loaded to produce trace data. The
327primary user interface of SystemTap is the cmd:stap command-line tool.
328
329The main distinctive features of LTTng is that it produces correlated
330kernel and user space traces, as well as doing so with the lowest
331overhead amongst other solutions. It produces trace files in the
332https://diamon.org/ctf[CTF] format, a file format optimized
333for the production and analyses of multi-gigabyte data.
334
335LTTng is the result of more than 10{nbsp}years of active open source
336development by a community of passionate developers. LTTng is currently
337available on major desktop and server Linux distributions.
338
339The main interface for tracing control is a single command-line tool
340named cmd:lttng. The latter can create several recording sessions, enable
341and disable recording event rules on the fly, filter events efficiently
342with custom user expressions, start and stop tracing, and much more.
343LTTng can write the traces on the file system or send them over the
344network, and keep them totally or partially. You can make LTTng execute
345user-defined actions when LTTng emits an event. You can view the traces
346once tracing becomes inactive or as LTTng records events.
347
348<<installing-lttng,Install LTTng now>> and
349<<getting-started,start tracing>>!
350
351
352[[installing-lttng]]
353== Installation
354
355**LTTng** is a set of software <<plumbing,components>> which interact to
356<<instrumenting,instrument>> the Linux kernel and user applications, and
357to <<controlling-tracing,control tracing>> (start and stop
358recording, create recording event rules, and the rest). Those
359components are bundled into the following packages:
360
361LTTng-tools::
362 Libraries and command-line interface to control tracing.
363
364LTTng-modules::
365 Linux kernel modules to instrument and trace the kernel.
366
367LTTng-UST::
368 Libraries and Java/Python packages to instrument and trace user
369 applications.
370
371Most distributions mark the LTTng-modules and LTTng-UST packages as
372optional when installing LTTng-tools (which is always required). In the
373following sections, we always provide the steps to install all three,
374but note that:
375
376* You only need to install LTTng-modules if you intend to use
377 the Linux kernel LTTng tracer.
378
379* You only need to install LTTng-UST if you intend to use the user
380 space LTTng tracer.
381
382[NOTE]
383====
384As of 10{nbsp}June{nbsp}2021, LTTng{nbsp}{revision} is not yet available
385in any major non-enterprise Linux distribution.
386
387For https://www.redhat.com/[RHEL] and https://www.suse.com/[SLES]
388packages, see https://packages.efficios.com/[EfficiOS Enterprise
389Packages].
390
391For other distributions, <<building-from-source,build LTTng from
392source>>.
393====
394
395
396[[building-from-source]]
397=== Build from source
398
399To build and install LTTng{nbsp}{revision} from source:
400
401. Using the package manager of your distribution, or from source,
402 install the following dependencies of LTTng-tools and LTTng-UST:
403+
404--
405* https://sourceforge.net/projects/libuuid/[libuuid]
406* https://directory.fsf.org/wiki/Popt[popt]
407* https://liburcu.org/[Userspace RCU]
408* http://www.xmlsoft.org/[libxml2]
409* **Optional**: https://github.com/numactl/numactl[numactl]
410--
411
412. Download, build, and install the latest LTTng-modules{nbsp}{revision}:
413+
414--
415[role="term"]
416----
417$ cd $(mktemp -d) &&
418 wget https://lttng.org/files/lttng-modules/lttng-modules-latest-2.13.tar.bz2 &&
419 tar -xf lttng-modules-latest-2.13.tar.bz2 &&
420 cd lttng-modules-2.13.* &&
421 make &&
422 sudo make modules_install &&
423 sudo depmod -a
424----
425--
426
427. Download, build, and install the latest LTTng-UST{nbsp}{revision}:
428+
429--
430[role="term"]
431----
432$ cd $(mktemp -d) &&
433 wget https://lttng.org/files/lttng-ust/lttng-ust-latest-2.13.tar.bz2 &&
434 tar -xf lttng-ust-latest-2.13.tar.bz2 &&
435 cd lttng-ust-2.13.* &&
436 ./configure &&
437 make &&
438 sudo make install &&
439 sudo ldconfig
440----
441--
442+
443Add `--disable-numa` to `./configure` if you don't have
444https://github.com/numactl/numactl[numactl].
445+
446--
447[IMPORTANT]
448.Java and Python application tracing
449====
450If you need to instrument and have LTTng trace <<java-application,Java
451applications>>, pass the `--enable-java-agent-jul`,
452`--enable-java-agent-log4j`, or `--enable-java-agent-all` options to the
453`configure` script, depending on which Java logging framework you use.
454
455If you need to instrument and have LTTng trace
456<<python-application,Python applications>>, pass the
457`--enable-python-agent` option to the `configure` script. You can set
458the env:PYTHON environment variable to the path to the Python interpreter
459for which to install the LTTng-UST Python agent package.
460====
461--
462+
463--
464[NOTE]
465====
466By default, LTTng-UST libraries are installed to
467dir:{/usr/local/lib}, which is the de facto directory in which to
468keep self-compiled and third-party libraries.
469
470When <<building-tracepoint-providers-and-user-application,linking an
471instrumented user application with `liblttng-ust`>>:
472
473* Append `/usr/local/lib` to the env:LD_LIBRARY_PATH environment
474 variable.
475
476* Pass the `-L/usr/local/lib` and `-Wl,-rpath,/usr/local/lib` options to
477 man:gcc(1), man:g++(1), or man:clang(1).
478====
479--
480
481. Download, build, and install the latest LTTng-tools{nbsp}{revision}:
482+
483--
484[role="term"]
485----
486$ cd $(mktemp -d) &&
487 wget https://lttng.org/files/lttng-tools/lttng-tools-latest-2.13.tar.bz2 &&
488 tar -xf lttng-tools-latest-2.13.tar.bz2 &&
489 cd lttng-tools-2.13.* &&
490 ./configure &&
491 make &&
492 sudo make install &&
493 sudo ldconfig
494----
495--
496
497TIP: The https://github.com/eepp/vlttng[vlttng tool] can do all the
498previous steps automatically for a given version of LTTng and confine
499the installed files to a specific directory. This can be useful to try
500LTTng without installing it on your system.
501
502
503[[getting-started]]
504== Quick start
505
506This is a short guide to get started quickly with LTTng kernel and user
507space tracing.
508
509Before you follow this guide, make sure to <<installing-lttng,install>>
510LTTng.
511
512This tutorial walks you through the steps to:
513
514. <<tracing-the-linux-kernel,Record Linux kernel events>>.
515
516. <<tracing-your-own-user-application,Record the events of a user
517 application>> written in C.
518
519. <<viewing-and-analyzing-your-traces,View and analyze the
520 recorded events>>.
521
522
523[[tracing-the-linux-kernel]]
524=== Record Linux kernel events
525
526NOTE: The following command lines start with the `#` prompt because you
527need root privileges to control the Linux kernel LTTng tracer. You can
528also control the kernel tracer as a regular user if your Unix user is a
529member of the <<tracing-group,tracing group>>.
530
531. Create a <<tracing-session,recording session>> to write LTTng traces
532 to dir:{/tmp/my-kernel-trace}:
533+
534--
535[role="term"]
536----
537# lttng create my-kernel-session --output=/tmp/my-kernel-trace
538----
539--
540
541. List the available kernel tracepoints and system calls:
542+
543--
544[role="term"]
545----
546# lttng list --kernel
547# lttng list --kernel --syscall
548----
549--
550
551. Create <<event,recording event rules>> which match events having
552 the desired names, for example the `sched_switch` and
553 `sched_process_fork` tracepoints, and the man:open(2) and man:close(2)
554 system calls:
555+
556--
557[role="term"]
558----
559# lttng enable-event --kernel sched_switch,sched_process_fork
560# lttng enable-event --kernel --syscall open,close
561----
562--
563+
564Create a recording event rule which matches _all_ the Linux kernel
565tracepoint events with the opt:lttng-enable-event(1):--all option
566(recording with such a recording event rule generates a lot of data):
567+
568--
569[role="term"]
570----
571# lttng enable-event --kernel --all
572----
573--
574
575. <<basic-tracing-session-control,Start recording>>:
576+
577--
578[role="term"]
579----
580# lttng start
581----
582--
583
584. Do some operation on your system for a few seconds. For example,
585 load a website, or list the files of a directory.
586
587. <<creating-destroying-tracing-sessions,Destroy>> the current
588 recording session:
589+
590--
591[role="term"]
592----
593# lttng destroy
594----
595--
596+
597The man:lttng-destroy(1) command doesn't destroy the trace data; it
598only destroys the state of the recording session.
599+
600The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
601implicitly (see ``<<basic-tracing-session-control,Start and stop a
602recording session>>''). You need to stop recording to make LTTng flush
603the remaining trace data and make the trace readable.
604
605. For the sake of this example, make the recorded trace accessible to
606 the non-root users:
607+
608--
609[role="term"]
610----
611# chown -R $(whoami) /tmp/my-kernel-trace
612----
613--
614
615See ``<<viewing-and-analyzing-your-traces,View and analyze the
616recorded events>>'' to view the recorded events.
617
618
619[[tracing-your-own-user-application]]
620=== Record user application events
621
622This section walks you through a simple example to record the events of
623a _Hello world_ program written in{nbsp}C.
624
625To create the traceable user application:
626
627. Create the tracepoint provider header file, which defines the
628 tracepoints and the events they can generate:
629+
630--
631[source,c]
632.path:{hello-tp.h}
633----
634#undef LTTNG_UST_TRACEPOINT_PROVIDER
635#define LTTNG_UST_TRACEPOINT_PROVIDER hello_world
636
637#undef LTTNG_UST_TRACEPOINT_INCLUDE
638#define LTTNG_UST_TRACEPOINT_INCLUDE "./hello-tp.h"
639
640#if !defined(_HELLO_TP_H) || defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ)
641#define _HELLO_TP_H
642
643#include <lttng/tracepoint.h>
644
645LTTNG_UST_TRACEPOINT_EVENT(
646 hello_world,
647 my_first_tracepoint,
648 LTTNG_UST_TP_ARGS(
649 int, my_integer_arg,
650 char *, my_string_arg
651 ),
652 LTTNG_UST_TP_FIELDS(
653 lttng_ust_field_string(my_string_field, my_string_arg)
654 lttng_ust_field_integer(int, my_integer_field, my_integer_arg)
655 )
656)
657
658#endif /* _HELLO_TP_H */
659
660#include <lttng/tracepoint-event.h>
661----
662--
663
664. Create the tracepoint provider package source file:
665+
666--
667[source,c]
668.path:{hello-tp.c}
669----
670#define LTTNG_UST_TRACEPOINT_CREATE_PROBES
671#define LTTNG_UST_TRACEPOINT_DEFINE
672
673#include "hello-tp.h"
674----
675--
676
677. Build the tracepoint provider package:
678+
679--
680[role="term"]
681----
682$ gcc -c -I. hello-tp.c
683----
684--
685
686. Create the _Hello World_ application source file:
687+
688--
689[source,c]
690.path:{hello.c}
691----
692#include <stdio.h>
693#include "hello-tp.h"
694
695int main(int argc, char *argv[])
696{
697 unsigned int i;
698
699 puts("Hello, World!\nPress Enter to continue...");
700
701 /*
702 * The following getchar() call only exists for the purpose of this
703 * demonstration, to pause the application in order for you to have
704 * time to list its tracepoints. You don't need it otherwise.
705 */
706 getchar();
707
708 /*
709 * An lttng_ust_tracepoint() call.
710 *
711 * Arguments, as defined in `hello-tp.h`:
712 *
713 * 1. Tracepoint provider name (required)
714 * 2. Tracepoint name (required)
715 * 3. `my_integer_arg` (first user-defined argument)
716 * 4. `my_string_arg` (second user-defined argument)
717 *
718 * Notice the tracepoint provider and tracepoint names are
719 * C identifiers, NOT strings: they're in fact parts of variables
720 * that the macros in `hello-tp.h` create.
721 */
722 lttng_ust_tracepoint(hello_world, my_first_tracepoint, 23,
723 "hi there!");
724
725 for (i = 0; i < argc; i++) {
726 lttng_ust_tracepoint(hello_world, my_first_tracepoint,
727 i, argv[i]);
728 }
729
730 puts("Quitting now!");
731 lttng_ust_tracepoint(hello_world, my_first_tracepoint,
732 i * i, "i^2");
733 return 0;
734}
735----
736--
737
738. Build the application:
739+
740--
741[role="term"]
742----
743$ gcc -c hello.c
744----
745--
746
747. Link the application with the tracepoint provider package,
748 `liblttng-ust` and `libdl`:
749+
750--
751[role="term"]
752----
753$ gcc -o hello hello.o hello-tp.o -llttng-ust -ldl
754----
755--
756
757Here's the whole build process:
758
759[role="img-100"]
760.Build steps of the user space tracing tutorial.
761image::ust-flow.png[]
762
763To record the events of the user application:
764
765. Run the application with a few arguments:
766+
767--
768[role="term"]
769----
770$ ./hello world and beyond
771----
772--
773+
774You see:
775+
776--
777----
778Hello, World!
779Press Enter to continue...
780----
781--
782
783. Start an LTTng <<lttng-sessiond,session daemon>>:
784+
785--
786[role="term"]
787----
788$ lttng-sessiond --daemonize
789----
790--
791+
792NOTE: A session daemon might already be running, for example as a
793service that the service manager of your distribution started.
794
795. List the available user space tracepoints:
796+
797--
798[role="term"]
799----
800$ lttng list --userspace
801----
802--
803+
804You see the `hello_world:my_first_tracepoint` tracepoint listed
805under the `./hello` process.
806
807. Create a <<tracing-session,recording session>>:
808+
809--
810[role="term"]
811----
812$ lttng create my-user-space-session
813----
814--
815
816. Create a <<event,recording event rule>> which matches user space
817 tracepoint events named `hello_world:my_first_tracepoint`:
818+
819--
820[role="term"]
821----
822$ lttng enable-event --userspace hello_world:my_first_tracepoint
823----
824--
825
826. <<basic-tracing-session-control,Start recording>>:
827+
828--
829[role="term"]
830----
831$ lttng start
832----
833--
834
835. Go back to the running `hello` application and press **Enter**.
836+
837The program executes all `lttng_ust_tracepoint()` instrumentation
838points, emitting events as the event rule you created in step{nbsp}5
839matches them, and
840exits.
841
842. <<creating-destroying-tracing-sessions,Destroy>> the current
843 recording session:
844+
845--
846[role="term"]
847----
848$ lttng destroy
849----
850--
851+
852The man:lttng-destroy(1) command doesn't destroy the trace data; it
853only destroys the state of the recording session.
854+
855The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
856implicitly (see ``<<basic-tracing-session-control,Start and stop a
857recording session>>''). You need to stop recording to make LTTng flush
858the remaining trace data and make the trace readable.
859
860By default, LTTng saves the traces to the
861+$LTTNG_HOME/lttng-traces/__NAME__-__DATE__-__TIME__+ directory, where
862+__NAME__+ is the recording session name. The env:LTTNG_HOME environment
863variable defaults to `$HOME` if not set.
864
865
866[[viewing-and-analyzing-your-traces]]
867=== View and analyze the recorded events
868
869Once you have completed the <<tracing-the-linux-kernel,Record Linux
870kernel events>> and <<tracing-your-own-user-application,Record user
871application events>> tutorials, you can inspect the recorded events.
872
873There are many tools you can use to read LTTng traces:
874
875https://babeltrace.org/[Babeltrace{nbsp}2]::
876 A rich, flexible trace manipulation toolkit which includes
877 a versatile command-line interface
878 (man:babeltrace2(1)),
879 a https://babeltrace.org/docs/v2.0/libbabeltrace2/[C{nbsp}library],
880 and https://babeltrace.org/docs/v2.0/python/bt2/[Python{nbsp}3 bindings]
881 so that you can easily process or convert an LTTng trace with
882 your own script.
883+
884The Babeltrace{nbsp}2 project ships with a plugin
885(man:babeltrace2-plugin-ctf(7)) which supports the format of the traces
886which LTTng produces, https://diamon.org/ctf/[CTF].
887
888http://tracecompass.org/[Trace Compass]::
889 A graphical user interface for viewing and analyzing any type of
890 logs or traces, including those of LTTng.
891
892https://github.com/lttng/lttng-analyses[LTTng analyses]::
893 An experimental project which includes many high-level analyses of
894 LTTng kernel traces, like scheduling statistics, interrupt
895 frequency distribution, top CPU usage, and more.
896
897NOTE: This section assumes that LTTng wrote the traces it recorded
898during the previous tutorials to their default location, in the
899dir:{$LTTNG_HOME/lttng-traces} directory. The env:LTTNG_HOME
900environment variable defaults to `$HOME` if not set.
901
902
903[[viewing-and-analyzing-your-traces-bt]]
904==== Use the cmd:babeltrace2 command-line tool
905
906The simplest way to list all the recorded events of an LTTng trace is to
907pass its path to man:babeltrace2(1), without options:
908
909[role="term"]
910----
911$ babeltrace2 ~/lttng-traces/my-user-space-session*
912----
913
914The cmd:babeltrace2 command finds all traces recursively within the
915given path and prints all their events, sorting them chronologically.
916
917Pipe the output of cmd:babeltrace2 into a tool like man:grep(1) for
918further filtering:
919
920[role="term"]
921----
922$ babeltrace2 /tmp/my-kernel-trace | grep _switch
923----
924
925Pipe the output of cmd:babeltrace2 into a tool like man:wc(1) to count
926the recorded events:
927
928[role="term"]
929----
930$ babeltrace2 /tmp/my-kernel-trace | grep _open | wc --lines
931----
932
933
934[[viewing-and-analyzing-your-traces-bt-python]]
935==== Use the Babeltrace{nbsp}2 Python bindings
936
937The <<viewing-and-analyzing-your-traces-bt,text output of
938cmd:babeltrace2>> is useful to isolate event records by simple matching
939using man:grep(1) and similar utilities. However, more elaborate
940filters, such as keeping only event records with a field value falling
941within a specific range, are not trivial to write using a shell.
942Moreover, reductions and even the most basic computations involving
943multiple event records are virtually impossible to implement.
944
945Fortunately, Babeltrace{nbsp}2 ships with
946https://babeltrace.org/docs/v2.0/python/bt2/[Python{nbsp}3 bindings]
947which make it easy to read the event records of an LTTng trace
948sequentially and compute the desired information.
949
950The following script accepts an LTTng Linux kernel trace path as its
951first argument and prints the short names of the top five running
952processes on CPU{nbsp}0 during the whole trace:
953
954[source,python]
955.path:{top5proc.py}
956----
957import bt2
958import sys
959import collections
960
961
962def top5proc():
963 # Get the trace path from the first command-line argument
964 it = bt2.TraceCollectionMessageIterator(sys.argv[1])
965
966 # This counter dictionary will hold execution times:
967 #
968 # Task command name -> Total execution time (ns)
969 exec_times = collections.Counter()
970
971 # This holds the last `sched_switch` timestamp
972 last_ts = None
973
974 for msg in it:
975 # We only care about event messages
976 if type(msg) is not bt2._EventMessageConst:
977 continue
978
979 # Event of the event message
980 event = msg.event
981
982 # Keep only `sched_switch` events
983 if event.cls.name != 'sched_switch':
984 continue
985
986 # Keep only records of events which LTTng emitted from CPU 0
987 if event.packet.context_field['cpu_id'] != 0:
988 continue
989
990 # Event timestamp (ns)
991 cur_ts = msg.default_clock_snapshot.ns_from_origin
992
993 if last_ts is None:
994 # Start here
995 last_ts = cur_ts
996
997 # (Short) name of the previous task command
998 prev_comm = str(event.payload_field['prev_comm'])
999
1000 # Initialize an entry in our dictionary if not done yet
1001 if prev_comm not in exec_times:
1002 exec_times[prev_comm] = 0
1003
1004 # Compute previous command execution time
1005 diff = cur_ts - last_ts
1006
1007 # Update execution time of this command
1008 exec_times[prev_comm] += diff
1009
1010 # Update last timestamp
1011 last_ts = cur_ts
1012
1013 # Print top 5
1014 for name, ns in exec_times.most_common(5):
1015 print('{:20}{} s'.format(name, ns / 1e9))
1016
1017
1018if __name__ == '__main__':
1019 top5proc()
1020----
1021
1022Run this script:
1023
1024[role="term"]
1025----
1026$ python3 top5proc.py /tmp/my-kernel-trace/kernel
1027----
1028
1029Output example:
1030
1031----
1032swapper/0 48.607245889 s
1033chromium 7.192738188 s
1034pavucontrol 0.709894415 s
1035Compositor 0.660867933 s
1036Xorg.bin 0.616753786 s
1037----
1038
1039Note that `swapper/0` is the ``idle'' process of CPU{nbsp}0 on Linux;
1040since we weren't using the CPU that much when recording, its first
1041position in the list makes sense.
1042
1043
1044[[core-concepts]]
1045== [[understanding-lttng]]Core concepts
1046
1047From a user's perspective, the LTTng system is built on a few concepts,
1048or objects, on which the <<lttng-cli,cmd:lttng command-line tool>>
1049operates by sending commands to the <<lttng-sessiond,session daemon>>
1050(through <<liblttng-ctl-lttng,`liblttng-ctl`>>).
1051
1052Understanding how those objects relate to each other is key to master
1053the toolkit.
1054
1055The core concepts of LTTng are:
1056
1057* <<"event-rule","Instrumentation point, event rule, and event">>
1058* <<trigger,Trigger>>
1059* <<tracing-session,Recording session>>
1060* <<domain,Tracing domain>>
1061* <<channel,Channel and ring buffer>>
1062* <<event,Recording event rule and event record>>
1063
1064NOTE: The man:lttng-concepts(7) manual page also documents the core
1065concepts of LTTng, with more links to other LTTng-tools manual pages.
1066
1067
1068[[event-rule]]
1069=== Instrumentation point, event rule, and event
1070
1071An _instrumentation point_ is a point, within a piece of software,
1072which, when executed, creates an LTTng _event_.
1073
1074LTTng offers various <<instrumentation-point-types,types of
1075instrumentation>>.
1076
1077An _event rule_ is a set of conditions to match a set of events.
1078
1079When LTTng creates an event{nbsp}__E__, an event rule{nbsp}__ER__ is
1080said to __match__{nbsp}__E__ when{nbsp}__E__ satisfies _all_ the
1081conditions of{nbsp}__ER__. This concept is similar to a
1082https://en.wikipedia.org/wiki/Regular_expression[regular expression]
1083which matches a set of strings.
1084
1085When an event rule matches an event, LTTng _emits_ the event, therefore
1086attempting to execute one or more actions.
1087
1088[IMPORTANT]
1089====
1090[[event-creation-emission-opti]]The event creation and emission
1091processes are documentation concepts to help understand the journey from
1092an instrumentation point to the execution of actions.
1093
1094The actual creation of an event can be costly because LTTng needs to
1095evaluate the arguments of the instrumentation point.
1096
1097In practice, LTTng implements various optimizations for the Linux kernel
1098and user space <<domain,tracing domains>> to avoid actually creating an
1099event when the tracer knows, thanks to properties which are independent
1100from the event payload and current context, that it would never emit
1101such an event. Those properties are:
1102
1103* The <<instrumentation-point-types,instrumentation point type>>.
1104
1105* The instrumentation point name.
1106
1107* The instrumentation point log level.
1108
1109* For a <<event,recording event rule>>:
1110** The status of the rule itself.
1111** The status of the <<channel,channel>>.
1112** The activity of the <<tracing-session,recording session>>.
1113** Whether or not the process for which LTTng would create the event is
1114 <<pid-tracking,allowed to record events>>.
1115
1116In other words: if, for a given instrumentation point{nbsp}__IP__, the
1117LTTng tracer knows that it would never emit an event,
1118executing{nbsp}__IP__ represents a simple boolean variable check and,
1119for a Linux kernel recording event rule, a few process attribute checks.
1120====
1121
1122As of LTTng{nbsp}{revision}, there are two places where you can find an
1123event rule:
1124
1125<<event,Recording event rule>>::
1126 A specific type of event rule of which the action is to record the
1127 matched event as an event record.
1128+
1129See ``<<enabling-disabling-events,Create and enable a recording event
1130rule>>'' to learn more.
1131
1132``Event rule matches'' <<trigger,trigger>> condition (since LTTng{nbsp}2.13)::
1133 When the event rule of the trigger condition matches an event, LTTng
1134 can execute user-defined actions such as sending an LTTng
1135 notification,
1136 <<basic-tracing-session-control,starting a recording session>>,
1137 and more.
1138+
1139See “<<add-event-rule-matches-trigger,Add an ``event rule matches''
1140trigger to a session daemon>>” to learn more.
1141
1142For LTTng to emit an event{nbsp}__E__,{nbsp}__E__ must satisfy _all_ the
1143basic conditions of an event rule{nbsp}__ER__, that is:
1144
1145* The instrumentation point from which LTTng
1146 creates{nbsp}__E__ has a specific
1147 <<instrumentation-point-types,type>>.
1148
1149* A pattern matches the name of{nbsp}__E__ while another pattern
1150 doesn't.
1151
1152* The log level of the instrumentation point from which LTTng
1153 creates{nbsp}__E__ is at least as severe as some value, or is exactly
1154 some value.
1155
1156* The fields of the payload of{nbsp}__E__ and the current context fields
1157 satisfy a filter expression.
1158
1159A <<event,recording event rule>> has additional, implicit conditions to
1160satisfy.
1161
1162
1163[[instrumentation-point-types]]
1164==== Instrumentation point types
1165
1166As of LTTng{nbsp}{revision}, the available instrumentation point
1167types are, depending on the <<domain,tracing domain>>:
1168
1169Linux kernel::
1170 LTTng tracepoint:::
1171 A statically defined point in the source code of the kernel
1172 image or of a kernel module using the
1173 <<lttng-modules,LTTng-modules>> macros.
1174
1175 Linux kernel system call:::
1176 Entry, exit, or both of a Linux kernel system call.
1177
1178 Linux https://www.kernel.org/doc/html/latest/trace/kprobes.html[kprobe]:::
1179 A single probe dynamically placed in the compiled kernel code.
1180+
1181When you create such an instrumentation point, you set its memory
1182address or symbol name.
1183
1184 Linux user space probe:::
1185 A single probe dynamically placed at the entry of a compiled
1186 user space application/library function through the kernel.
1187+
1188When you create such an instrumentation point, you set:
1189+
1190--
1191With the ELF method::
1192 Its application/library path and its symbol name.
1193
1194With the USDT method::
1195 Its application/library path, its provider name, and its probe name.
1196+
1197``USDT'' stands for _SystemTap User-level Statically Defined Tracing_,
1198a http://dtrace.org/blogs/about/[DTrace]-style marker.
1199--
1200+
1201As of LTTng{nbsp}{revision}, LTTng only supports USDT probes which
1202are _not_ reference-counted.
1203
1204 Linux https://www.kernel.org/doc/html/latest/trace/kprobes.html[kretprobe]:::
1205 Entry, exit, or both of a Linux kernel function.
1206+
1207When you create such an instrumentation point, you set the memory
1208address or symbol name of its function.
1209
1210User space::
1211 LTTng tracepoint:::
1212 A statically defined point in the source code of a C/$$C++$$
1213 application/library using the
1214 <<lttng-ust,LTTng-UST>> macros.
1215
1216`java.util.logging`, Apache log4j, and Python::
1217 Java or Python logging statement:::
1218 A method call on a Java or Python logger attached to an
1219 LTTng-UST handler.
1220
1221See ``<<list-instrumentation-points,List the available instrumentation
1222points>>'' to learn how to list available Linux kernel, user space, and
1223logging instrumentation points.
1224
1225
1226[[trigger]]
1227=== Trigger
1228
1229A _trigger_ associates a condition to one or more actions.
1230
1231When the condition of a trigger is satisfied, LTTng attempts to execute
1232its actions.
1233
1234As of LTTng{nbsp}{revision}, the available trigger conditions and
1235actions are:
1236
1237Conditions::
1238+
1239* The consumed buffer size of a given <<tracing-session,recording
1240 session>> becomes greater than some value.
1241
1242* The buffer usage of a given <<channel,channel>> becomes greater than
1243 some value.
1244
1245* The buffer usage of a given channel becomes less than some value.
1246
1247* There's an ongoing <<session-rotation,recording session rotation>>.
1248
1249* A recording session rotation becomes completed.
1250
1251* An <<add-event-rule-matches-trigger,event rule matches>> an event.
1252
1253Actions::
1254+
1255* <<trigger-event-notif,Send a notification>> to a user application.
1256* <<basic-tracing-session-control,Start>> a given recording session.
1257* <<basic-tracing-session-control,Stop>> a given recording session.
1258* <<session-rotation,Archive the current trace chunk>> of a given
1259 recording session (rotate).
1260* <<taking-a-snapshot,Take a snapshot>> of a given recording session.
1261
1262A trigger belongs to a <<lttng-sessiond,session daemon>>, not to a
1263specific recording session. For a given session daemon, each Unix user has
1264its own, private triggers. Note, however, that the `root` Unix user may,
1265for the root session daemon:
1266
1267* Add a trigger as another Unix user.
1268
1269* List all the triggers, regardless of their owner.
1270
1271* Remove a trigger which belongs to another Unix user.
1272
1273For a given session daemon and Unix user, a trigger has a unique name.
1274
1275
1276[[tracing-session]]
1277=== Recording session
1278
1279A _recording session_ (named ``tracing session'' prior to
1280LTTng{nbsp}2.13) is a stateful dialogue between you and a
1281<<lttng-sessiond,session daemon>> for everything related to
1282<<event,event recording>>.
1283
1284Everything that you do when you control LTTng tracers to record events
1285happens within a recording session. In particular, a recording session:
1286
1287* Has its own name, unique for a given session daemon.
1288
1289* Has its own set of trace files, if any.
1290
1291* Has its own state of activity (started or stopped).
1292+
1293An active recording session is an implicit <<event,recording event rule>>
1294condition.
1295
1296* Has its own <<tracing-session-mode,mode>> (local, network streaming,
1297 snapshot, or live).
1298
1299* Has its own <<channel,channels>> to which are attached their own
1300 recording event rules.
1301
1302* Has its own <<pid-tracking,process attribute inclusion sets>>.
1303
1304[role="img-100"]
1305.A _recording session_ contains <<channel,channels>> that are members of <<domain,tracing domains>> and contain <<event,recording event rules>>.
1306image::concepts.png[]
1307
1308Those attributes and objects are completely isolated between different
1309recording sessions.
1310
1311A recording session is like an
1312https://en.wikipedia.org/wiki/Automated_teller_machine[ATM] session: the
1313operations you do on the banking system through the ATM don't alter the
1314data of other users of the same system. In the case of the ATM, a
1315session lasts as long as your bank card is inside. In the case of LTTng,
1316a recording session lasts from the man:lttng-create(1) command to the
1317man:lttng-destroy(1) command.
1318
1319[role="img-100"]
1320.Each Unix user has its own set of recording sessions.
1321image::many-sessions.png[]
1322
1323A recording session belongs to a <<lttng-sessiond,session daemon>>. For a
1324given session daemon, each Unix user has its own, private recording
1325sessions. Note, however, that the `root` Unix user may operate on or
1326destroy another user's recording session.
1327
1328
1329[[tracing-session-mode]]
1330==== Recording session mode
1331
1332LTTng offers four recording session modes:
1333
1334[[local-mode]]Local mode::
1335 Write the trace data to the local file system.
1336
1337[[net-streaming-mode]]Network streaming mode::
1338 Send the trace data over the network to a listening
1339 <<lttng-relayd,relay daemon>>.
1340
1341[[snapshot-mode]]Snapshot mode::
1342 Only write the trace data to the local file system or send it to a
1343 listening relay daemon when LTTng <<taking-a-snapshot,takes a
1344 snapshot>>.
1345+
1346LTTng forces all the <<channel,channels>>
1347to be created to be configured to be snapshot-ready.
1348+
1349LTTng takes a snapshot of such a recording session when:
1350+
1351--
1352* You run the man:lttng-snapshot(1) command.
1353
1354* LTTng executes a `snapshot-session` <<trigger,trigger>> action.
1355--
1356
1357[[live-mode]]Live mode::
1358 Send the trace data over the network to a listening relay daemon
1359 for <<lttng-live,live reading>>.
1360+
1361An LTTng live reader (for example, man:babeltrace2(1)) can connect to
1362the same relay daemon to receive trace data while the recording session is
1363active.
1364
1365
1366[[domain]]
1367=== Tracing domain
1368
1369A _tracing domain_ identifies a type of LTTng tracer.
1370
1371A tracing domain has its own properties and features.
1372
1373There are currently five available tracing domains:
1374
1375* Linux kernel
1376* User space
1377* `java.util.logging` (JUL)
1378* log4j
1379* Python
1380
1381You must specify a tracing domain to target a type of LTTng tracer when
1382using some <<lttng-cli,cmd:lttng>> commands to avoid ambiguity. For
1383example, because the Linux kernel and user space tracing domains support
1384named tracepoints as <<event-rule,instrumentation points>>, you need to
1385specify a tracing domain when you <<enabling-disabling-events,create
1386an event rule>> because both tracing domains could have tracepoints
1387sharing the same name.
1388
1389You can create <<channel,channels>> in the Linux kernel and user space
1390tracing domains. The other tracing domains have a single, default
1391channel.
1392
1393
1394[[channel]]
1395=== Channel and ring buffer
1396
1397A _channel_ is an object which is responsible for a set of
1398_ring buffers_.
1399
1400Each ring buffer is divided into multiple _sub-buffers_. When a
1401<<event,recording event rule>>
1402matches an event, LTTng can record it to one or more sub-buffers of one
1403or more channels.
1404
1405When you <<enabling-disabling-channels,create a channel>>, you set its
1406final attributes, that is:
1407
1408* Its <<channel-buffering-schemes,buffering scheme>>.
1409
1410* What to do <<channel-overwrite-mode-vs-discard-mode,when there's no
1411 space left>> for a new event record because all sub-buffers are full.
1412
1413* The <<channel-subbuf-size-vs-subbuf-count,size of each ring buffer and
1414 how many sub-buffers>> a ring buffer has.
1415
1416* The <<tracefile-rotation,size of each trace file LTTng writes for this
1417 channel and the maximum count>> of trace files.
1418
1419* The periods of its <<channel-read-timer,read>>,
1420 <<channel-switch-timer,switch>>, and <<channel-monitor-timer,monitor>>
1421 timers.
1422
1423* For a Linux kernel channel: its output type.
1424+
1425See the opt:lttng-enable-channel(1):--output option of the
1426man:lttng-enable-channel(1) command.
1427
1428* For a user space channel: the value of its
1429 <<blocking-timeout-example,blocking timeout>>.
1430
1431A channel is always associated to a <<domain,tracing domain>>. The
1432`java.util.logging` (JUL), log4j, and Python tracing domains each have a
1433default channel which you can't configure.
1434
1435A channel owns <<event,recording event rules>>.
1436
1437
1438[[channel-buffering-schemes]]
1439==== Buffering scheme
1440
1441A channel has at least one ring buffer _per CPU_. LTTng always records
1442an event to the ring buffer dedicated to the CPU which emits it.
1443
1444The buffering scheme of a user space channel determines what has its own
1445set of per-CPU ring buffers:
1446
1447Per-user buffering::
1448 Allocate one set of ring buffers--one per CPU--shared by all the
1449 instrumented processes of:
1450 If your Unix user is `root`:::
1451 Each Unix user.
1452+
1453--
1454[role="img-100"]
1455.Per-user buffering scheme (recording session belongs to the `root` Unix user).
1456image::per-user-buffering-root.png[]
1457--
1458
1459 Otherwise:::
1460 Your Unix user.
1461+
1462--
1463[role="img-100"]
1464.Per-user buffering scheme (recording session belongs to the `Bob` Unix user).
1465image::per-user-buffering.png[]
1466--
1467
1468Per-process buffering::
1469 Allocate one set of ring buffers--one per CPU--for each
1470 instrumented process of:
1471 If your Unix user is `root`:::
1472 All Unix users.
1473+
1474--
1475[role="img-100"]
1476.Per-process buffering scheme (recording session belongs to the `root` Unix user).
1477image::per-process-buffering-root.png[]
1478--
1479
1480 Otherwise:::
1481 Your Unix user.
1482+
1483--
1484[role="img-100"]
1485.Per-process buffering scheme (recording session belongs to the `Bob` Unix user).
1486image::per-process-buffering.png[]
1487--
1488
1489The per-process buffering scheme tends to consume more memory than the
1490per-user option because systems generally have more instrumented
1491processes than Unix users running instrumented processes. However, the
1492per-process buffering scheme ensures that one process having a high
1493event throughput won't fill all the shared sub-buffers of the same Unix
1494user, only its own.
1495
1496The buffering scheme of a Linux kernel channel is always to allocate a
1497single set of ring buffers for the whole system. This scheme is similar
1498to the per-user option, but with a single, global user ``running'' the
1499kernel.
1500
1501
1502[[channel-overwrite-mode-vs-discard-mode]]
1503==== Event record loss mode
1504
1505When LTTng emits an event, LTTng can record it to a specific, available
1506sub-buffer within the ring buffers of specific channels. When there's no
1507space left in a sub-buffer, the tracer marks it as consumable and
1508another, available sub-buffer starts receiving the following event
1509records. An LTTng <<lttng-consumerd,consumer daemon>> eventually
1510consumes the marked sub-buffer, which returns to the available state.
1511
1512[NOTE]
1513[role="docsvg-channel-subbuf-anim"]
1514====
1515{note-no-anim}
1516====
1517
1518In an ideal world, sub-buffers are consumed faster than they're filled.
1519In the real world, however, all sub-buffers can be full at some point,
1520leaving no space to record the following events.
1521
1522In an ideal world, sub-buffers are consumed faster than they're filled,
1523as it's the case in the previous animation. In the real world,
1524however, all sub-buffers can be full at some point, leaving no space to
1525record the following events.
1526
1527By default, <<lttng-modules,LTTng-modules>> and <<lttng-ust,LTTng-UST>>
1528are _non-blocking_ tracers: when there's no available sub-buffer to
1529record an event, it's acceptable to lose event records when the
1530alternative would be to cause substantial delays in the execution of the
1531instrumented application. LTTng privileges performance over integrity;
1532it aims at perturbing the instrumented application as little as possible
1533in order to make the detection of subtle race conditions and rare
1534interrupt cascades possible.
1535
1536Since LTTng{nbsp}2.10, the LTTng user space tracer, LTTng-UST, supports
1537a _blocking mode_. See the <<blocking-timeout-example,blocking timeout
1538example>> to learn how to use the blocking mode.
1539
1540When it comes to losing event records because there's no available
1541sub-buffer, or because the blocking timeout of
1542the channel is reached, the _event record loss mode_ of the channel
1543determines what to do. The available event record loss modes are:
1544
1545[[discard-mode]]Discard mode::
1546 Drop the newest event records until a sub-buffer becomes available.
1547+
1548This is the only available mode when you specify a blocking timeout.
1549+
1550With this mode, LTTng increments a count of lost event records when an
1551event record is lost and saves this count to the trace. A trace reader
1552can use the saved discarded event record count of the trace to decide
1553whether or not to perform some analysis even if trace data is known to
1554be missing.
1555
1556[[overwrite-mode]]Overwrite mode::
1557 Clear the sub-buffer containing the oldest event records and start
1558 writing the newest event records there.
1559+
1560This mode is sometimes called _flight recorder mode_ because it's
1561similar to a https://en.wikipedia.org/wiki/Flight_recorder[flight
1562recorder]: always keep a fixed amount of the latest data. It's also
1563similar to the roll mode of an oscilloscope.
1564+
1565Since LTTng{nbsp}2.8, with this mode, LTTng writes to a given sub-buffer
1566its sequence number within its data stream. With a <<local-mode,local>>,
1567<<net-streaming-mode,network streaming>>, or <<live-mode,live>> recording
1568session, a trace reader can use such sequence numbers to report lost
1569packets. A trace reader can use the saved discarded sub-buffer (packet)
1570count of the trace to decide whether or not to perform some analysis
1571even if trace data is known to be missing.
1572+
1573With this mode, LTTng doesn't write to the trace the exact number of
1574lost event records in the lost sub-buffers.
1575
1576Which mechanism you should choose depends on your context: prioritize
1577the newest or the oldest event records in the ring buffer?
1578
1579Beware that, in overwrite mode, the tracer abandons a _whole sub-buffer_
1580as soon as a there's no space left for a new event record, whereas in
1581discard mode, the tracer only discards the event record that doesn't
1582fit.
1583
1584There are a few ways to decrease your probability of losing event
1585records. The ``<<channel-subbuf-size-vs-subbuf-count,Sub-buffer size and
1586count>>'' section shows how to fine-tune the sub-buffer size and count
1587of a channel to virtually stop losing event records, though at the cost
1588of greater memory usage.
1589
1590
1591[[channel-subbuf-size-vs-subbuf-count]]
1592==== Sub-buffer size and count
1593
1594A channel has one or more ring buffer for each CPU of the target system.
1595
1596See the ``<<channel-buffering-schemes,Buffering scheme>>'' section to
1597learn how many ring buffers of a given channel are dedicated to each CPU
1598depending on its buffering scheme.
1599
1600Set the size of each sub-buffer the ring buffers of a channel contain
1601and how many there are
1602when you <<enabling-disabling-channels,create it>>.
1603
1604Note that LTTng switching the current sub-buffer of a ring buffer
1605(marking a full one as consumable and switching to an available one for
1606LTTng to record the next events) introduces noticeable CPU overhead.
1607Knowing this, the following list presents a few practical situations
1608along with how to configure the sub-buffer size and count for them:
1609
1610High event throughput::
1611 In general, prefer large sub-buffers to lower the risk of losing
1612 event records.
1613+
1614Having larger sub-buffers also ensures a lower sub-buffer switching
1615frequency.
1616+
1617The sub-buffer count is only meaningful if you create the channel in
1618<<overwrite-mode,overwrite mode>>: in this case, if LTTng overwrites a
1619sub-buffer, then the other sub-buffers are left unaltered.
1620
1621Low event throughput::
1622 In general, prefer smaller sub-buffers since the risk of losing
1623 event records is low.
1624+
1625Because LTTng emits events less frequently, the sub-buffer switching
1626frequency should remain low and therefore the overhead of the tracer
1627shouldn't be a problem.
1628
1629Low memory system::
1630 If your target system has a low memory limit, prefer fewer first,
1631 then smaller sub-buffers.
1632+
1633Even if the system is limited in memory, you want to keep the
1634sub-buffers as large as possible to avoid a high sub-buffer switching
1635frequency.
1636
1637Note that LTTng uses https://diamon.org/ctf/[CTF] as its trace format,
1638which means event record data is very compact. For example, the average
1639LTTng kernel event record weights about 32{nbsp}bytes. Therefore, a
1640sub-buffer size of 1{nbsp}MiB is considered large.
1641
1642The previous scenarios highlight the major trade-off between a few large
1643sub-buffers and more, smaller sub-buffers: sub-buffer switching
1644frequency vs. how many event records are lost in overwrite mode.
1645Assuming a constant event throughput and using the overwrite mode, the
1646two following configurations have the same ring buffer total size:
1647
1648[NOTE]
1649[role="docsvg-channel-subbuf-size-vs-count-anim"]
1650====
1651{note-no-anim}
1652====
1653
1654Two sub-buffers of 4{nbsp}MiB each::
1655 Expect a very low sub-buffer switching frequency, but if LTTng
1656 ever needs to overwrite a sub-buffer, half of the event records so
1657 far (4{nbsp}MiB) are definitely lost.
1658
1659Eight sub-buffers of 1{nbsp}MiB each::
1660 Expect four times the tracer overhead of the configuration above,
1661 but if LTTng needs to overwrite a sub-buffer, only the eighth of
1662 event records so far (1{nbsp}MiB) are definitely lost.
1663
1664In <<discard-mode,discard mode>>, the sub-buffer count parameter is
1665pointless: use two sub-buffers and set their size according to your
1666requirements.
1667
1668
1669[[tracefile-rotation]]
1670==== Maximum trace file size and count (trace file rotation)
1671
1672By default, trace files can grow as large as needed.
1673
1674Set the maximum size of each trace file that LTTng writes of a given
1675channel when you <<enabling-disabling-channels,create it>>.
1676
1677When the size of a trace file reaches the fixed maximum size of the
1678channel, LTTng creates another file to contain the next event records.
1679LTTng appends a file count to each trace file name in this case.
1680
1681If you set the trace file size attribute when you create a channel, the
1682maximum number of trace files that LTTng creates is _unlimited_ by
1683default. To limit them, set a maximum number of trace files. When the
1684number of trace files reaches the fixed maximum count of the channel,
1685LTTng overwrites the oldest trace file. This mechanism is called _trace
1686file rotation_.
1687
1688[IMPORTANT]
1689====
1690Even if you don't limit the trace file count, always assume that LTTng
1691manages all the trace files of the recording session.
1692
1693In other words, there's no safe way to know if LTTng still holds a given
1694trace file open with the trace file rotation feature.
1695
1696The only way to obtain an unmanaged, self-contained LTTng trace before
1697you <<creating-destroying-tracing-sessions,destroy the recording session>>
1698is with the <<session-rotation,recording session rotation>> feature, which
1699is available since LTTng{nbsp}2.11.
1700====
1701
1702
1703[[channel-timers]]
1704==== Timers
1705
1706Each channel can have up to three optional timers:
1707
1708[[channel-switch-timer]]Switch timer::
1709 When this timer expires, a sub-buffer switch happens: for each ring
1710 buffer of the channel, LTTng marks the current sub-buffer as
1711 consumable and _switches_ to an available one to record the next
1712 events.
1713+
1714[NOTE]
1715[role="docsvg-channel-switch-timer"]
1716====
1717{note-no-anim}
1718====
1719+
1720A switch timer is useful to ensure that LTTng consumes and commits trace
1721data to trace files or to a distant <<lttng-relayd,relay daemon>>
1722periodically in case of a low event throughput.
1723+
1724Such a timer is also convenient when you use large
1725<<channel-subbuf-size-vs-subbuf-count,sub-buffers>> to cope with a
1726sporadic high event throughput, even if the throughput is otherwise low.
1727+
1728Set the period of the switch timer of a channel when you
1729<<enabling-disabling-channels,create it>> with
1730the opt:lttng-enable-channel(1):--switch-timer option.
1731
1732[[channel-read-timer]]Read timer::
1733 When this timer expires, LTTng checks for full, consumable
1734 sub-buffers.
1735+
1736By default, the LTTng tracers use an asynchronous message mechanism to
1737signal a full sub-buffer so that a <<lttng-consumerd,consumer daemon>>
1738can consume it.
1739+
1740When such messages must be avoided, for example in real-time
1741applications, use this timer instead.
1742+
1743Set the period of the read timer of a channel when you
1744<<enabling-disabling-channels,create it>> with the
1745opt:lttng-enable-channel(1):--read-timer option.
1746
1747[[channel-monitor-timer]]Monitor timer::
1748 When this timer expires, the consumer daemon samples some channel
1749 statistics to evaluate the following <<trigger,trigger>>
1750 conditions:
1751+
1752--
1753. The consumed buffer size of a given <<tracing-session,recording
1754 session>> becomes greater than some value.
1755. The buffer usage of a given channel becomes greater than some value.
1756. The buffer usage of a given channel becomes less than some value.
1757--
1758+
1759If you disable the monitor timer of a channel{nbsp}__C__:
1760+
1761--
1762* The consumed buffer size value of the recording session of{nbsp}__C__
1763 could be wrong for trigger condition type{nbsp}1: the consumed buffer
1764 size of{nbsp}__C__ won't be part of the grand total.
1765
1766* The buffer usage trigger conditions (types{nbsp}2 and{nbsp}3)
1767 for{nbsp}__C__ will never be satisfied.
1768--
1769+
1770Set the period of the monitor timer of a channel when you
1771<<enabling-disabling-channels,create it>> with the
1772opt:lttng-enable-channel(1):--monitor-timer option.
1773
1774
1775[[event]]
1776=== Recording event rule and event record
1777
1778A _recording event rule_ is a specific type of <<event-rule,event rule>>
1779of which the action is to serialize and record the matched event as an
1780_event record_.
1781
1782Set the explicit conditions of a recording event rule when you
1783<<enabling-disabling-events,create it>>. A recording event rule also has
1784the following implicit conditions:
1785
1786* The recording event rule itself is enabled.
1787+
1788A recording event rule is enabled on creation.
1789
1790* The <<channel,channel>> to which the recording event rule is attached
1791 is enabled.
1792+
1793A channel is enabled on creation.
1794
1795* The <<tracing-session,recording session>> of the recording event rule is
1796 <<basic-tracing-session-control,active>> (started).
1797+
1798A recording session is inactive (stopped) on creation.
1799
1800* The process for which LTTng creates an event to match is
1801 <<pid-tracking,allowed to record events>>.
1802+
1803All processes are allowed to record events on recording session
1804creation.
1805
1806You always attach a recording event rule to a channel, which belongs to
1807a recording session, when you create it.
1808
1809When a recording event rule{nbsp}__ER__ matches an event{nbsp}__E__,
1810LTTng attempts to serialize and record{nbsp}__E__ to one of the
1811available sub-buffers of the channel to which{nbsp}__E__ is attached.
1812
1813When multiple matching recording event rules are attached to the same
1814channel, LTTng attempts to serialize and record the matched event
1815_once_. In the following example, the second recording event rule is
1816redundant when both are enabled:
1817
1818[role="term"]
1819----
1820$ lttng enable-event --userspace hello:world
1821$ lttng enable-event --userspace hello:world --loglevel=INFO
1822----
1823
1824[role="img-100"]
1825.Logical path from an instrumentation point to an event record.
1826image::event-rule.png[]
1827
1828As of LTTng{nbsp}{revision}, you cannot remove a recording event
1829rule: it exists as long as its recording session exists.
1830
1831
1832[[plumbing]]
1833== Components of noch:{LTTng}
1834
1835The second _T_ in _LTTng_ stands for _toolkit_: it would be wrong
1836to call LTTng a simple _tool_ since it's composed of multiple
1837interacting components.
1838
1839This section describes those components, explains their respective
1840roles, and shows how they connect together to form the LTTng ecosystem.
1841
1842The following diagram shows how the most important components of LTTng
1843interact with user applications, the Linux kernel, and you:
1844
1845[role="img-100"]
1846.Control and trace data paths between LTTng components.
1847image::plumbing.png[]
1848
1849The LTTng project integrates:
1850
1851LTTng-tools::
1852 Libraries and command-line interface to control recording sessions:
1853+
1854* <<lttng-sessiond,Session daemon>> (man:lttng-sessiond(8)).
1855* <<lttng-consumerd,Consumer daemon>> (cmd:lttng-consumerd).
1856* <<lttng-relayd,Relay daemon>> (man:lttng-relayd(8)).
1857* <<liblttng-ctl-lttng,Tracing control library>> (`liblttng-ctl`).
1858* <<lttng-cli,Tracing control command-line tool>> (man:lttng(1)).
1859* <<persistent-memory-file-systems,`lttng-crash` command-line tool>>
1860 (man:lttng-crash(1)).
1861
1862LTTng-UST::
1863 Libraries and Java/Python packages to instrument and trace user
1864 applications:
1865+
1866* <<lttng-ust,User space tracing library>> (`liblttng-ust`) and its
1867 headers to instrument and trace any native user application.
1868* <<prebuilt-ust-helpers,Preloadable user space tracing helpers>>:
1869** `liblttng-ust-libc-wrapper`
1870** `liblttng-ust-pthread-wrapper`
1871** `liblttng-ust-cyg-profile`
1872** `liblttng-ust-cyg-profile-fast`
1873** `liblttng-ust-dl`
1874* <<lttng-ust-agents,LTTng-UST Java agent>> to instrument and trace
1875 Java applications using `java.util.logging` or
1876 Apache log4j{nbsp}1.2 logging.
1877* <<lttng-ust-agents,LTTng-UST Python agent>> to instrument
1878 Python applications using the standard `logging` package.
1879
1880LTTng-modules::
1881 <<lttng-modules,Linux kernel modules>> to instrument and trace the
1882 kernel:
1883+
1884* LTTng kernel tracer module.
1885* Recording ring buffer kernel modules.
1886* Probe kernel modules.
1887* LTTng logger kernel module.
1888
1889
1890[[lttng-cli]]
1891=== Tracing control command-line interface
1892
1893The _man:lttng(1) command-line tool_ is the standard user interface to
1894control LTTng <<tracing-session,recording sessions>>.
1895
1896The cmd:lttng tool is part of LTTng-tools.
1897
1898The cmd:lttng tool is linked with
1899<<liblttng-ctl-lttng,`liblttng-ctl`>> to communicate with
1900one or more <<lttng-sessiond,session daemons>> behind the scenes.
1901
1902The cmd:lttng tool has a Git-like interface:
1903
1904[role="term"]
1905----
1906$ lttng [GENERAL OPTIONS] <COMMAND> [COMMAND OPTIONS]
1907----
1908
1909The ``<<controlling-tracing,Tracing control>>'' section explores the
1910available features of LTTng through its cmd:lttng tool.
1911
1912
1913[[liblttng-ctl-lttng]]
1914=== Tracing control library
1915
1916[role="img-100"]
1917.The tracing control library.
1918image::plumbing-liblttng-ctl.png[]
1919
1920The _LTTng control library_, `liblttng-ctl`, is used to communicate with
1921a <<lttng-sessiond,session daemon>> using a C{nbsp}API that hides the
1922underlying details of the protocol.
1923
1924`liblttng-ctl` is part of LTTng-tools.
1925
1926The <<lttng-cli,cmd:lttng command-line tool>> is linked with
1927`liblttng-ctl`.
1928
1929Use `liblttng-ctl` in C or $$C++$$ source code by including its
1930``master'' header:
1931
1932[source,c]
1933----
1934#include <lttng/lttng.h>
1935----
1936
1937As of LTTng{nbsp}{revision}, the best available developer documentation
1938for `liblttng-ctl` is its installed header files. Functions and
1939structures are documented with header comments.
1940
1941
1942[[lttng-ust]]
1943=== User space tracing library
1944
1945[role="img-100"]
1946.The user space tracing library.
1947image::plumbing-liblttng-ust.png[]
1948
1949The _user space tracing library_, `liblttng-ust` (see man:lttng-ust(3)),
1950is the LTTng user space tracer.
1951
1952`liblttng-ust` receives commands from a <<lttng-sessiond,session
1953daemon>>, for example to allow specific instrumentation points to emit
1954LTTng <<event-rule,events>>, and writes event records to <<channel,ring
1955buffers>> shared with a <<lttng-consumerd,consumer daemon>>.
1956
1957`liblttng-ust` is part of LTTng-UST.
1958
1959`liblttng-ust` can also send asynchronous messages to the session daemon
1960when it emits an event. This supports the ``event rule matches''
1961<<trigger,trigger>> condition feature (see
1962“<<add-event-rule-matches-trigger,Add an ``event rule matches'' trigger
1963to a session daemon>>”).
1964
1965Public C{nbsp}header files are installed beside `liblttng-ust` to
1966instrument any <<c-application,C or $$C++$$ application>>.
1967
1968<<lttng-ust-agents,LTTng-UST agents>>, which are regular Java and Python
1969packages, use their own <<tracepoint-provider,tracepoint provider
1970package>> which is linked with `liblttng-ust`.
1971
1972An application or library doesn't have to initialize `liblttng-ust`
1973manually: its constructor does the necessary tasks to register the
1974application to a session daemon. The initialization phase also
1975configures instrumentation points depending on the <<event-rule,event
1976rules>> that you already created.
1977
1978
1979[[lttng-ust-agents]]
1980=== User space tracing agents
1981
1982[role="img-100"]
1983.The user space tracing agents.
1984image::plumbing-lttng-ust-agents.png[]
1985
1986The _LTTng-UST Java and Python agents_ are regular Java and Python
1987packages which add LTTng tracing capabilities to the
1988native logging frameworks.
1989
1990The LTTng-UST agents are part of LTTng-UST.
1991
1992In the case of Java, the
1993https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[`java.util.logging`
1994core logging facilities] and
1995https://logging.apache.org/log4j/1.2/[Apache log4j{nbsp}1.2] are supported.
1996Note that Apache Log4j{nbsp}2 isn't supported.
1997
1998In the case of Python, the standard
1999https://docs.python.org/3/library/logging.html[`logging`] package
2000is supported. Both Python{nbsp}2 and Python{nbsp}3 modules can import the
2001LTTng-UST Python agent package.
2002
2003The applications using the LTTng-UST agents are in the
2004`java.util.logging` (JUL), log4j, and Python <<domain,tracing domains>>.
2005
2006Both agents use the same mechanism to convert log statements to LTTng
2007events. When an agent initializes, it creates a log handler that
2008attaches to the root logger. The agent also registers to a
2009<<lttng-sessiond,session daemon>>. When the user application executes a
2010log statement, the root logger passes it to the log handler of the
2011agent. The custom log handler of the agent calls a native function in a
2012tracepoint provider package shared library linked with
2013<<lttng-ust,`liblttng-ust`>>, passing the formatted log message and
2014other fields, like its logger name and its log level. This native
2015function contains a user space instrumentation point, therefore tracing
2016the log statement.
2017
2018The log level condition of a <<event,recording event rule>> is
2019considered when tracing a Java or a Python application, and it's
2020compatible with the standard `java.util.logging`, log4j, and Python log
2021levels.
2022
2023
2024[[lttng-modules]]
2025=== LTTng kernel modules
2026
2027[role="img-100"]
2028.The LTTng kernel modules.
2029image::plumbing-lttng-modules.png[]
2030
2031The _LTTng kernel modules_ are a set of Linux kernel modules
2032which implement the kernel tracer of the LTTng project.
2033
2034The LTTng kernel modules are part of LTTng-modules.
2035
2036The LTTng kernel modules include:
2037
2038* A set of _probe_ modules.
2039+
2040Each module attaches to a specific subsystem
2041of the Linux kernel using its tracepoint instrument points.
2042+
2043There are also modules to attach to the entry and return points of the
2044Linux system call functions.
2045
2046* _Ring buffer_ modules.
2047+
2048A ring buffer implementation is provided as kernel modules. The LTTng
2049kernel tracer writes to ring buffers; a
2050<<lttng-consumerd,consumer daemon>> reads from ring buffers.
2051
2052* The _LTTng kernel tracer_ module.
2053* The <<proc-lttng-logger-abi,_LTTng logger_>> module.
2054+
2055The LTTng logger module implements the special path:{/proc/lttng-logger}
2056(and path:{/dev/lttng-logger}, since LTTng{nbsp}2.11) files so that any
2057executable can generate LTTng events by opening those files and
2058writing to them.
2059
2060The LTTng kernel tracer can also send asynchronous messages to the
2061<<lttng-sessiond,session daemon>> when it emits an event.
2062This supports the ``event rule matches''
2063<<trigger,trigger>> condition feature (see
2064“<<add-event-rule-matches-trigger,Add an ``event rule matches'' trigger
2065to a session daemon>>”).
2066
2067Generally, you don't have to load the LTTng kernel modules manually
2068(using man:modprobe(8), for example): a root session daemon loads the
2069necessary modules when starting. If you have extra probe modules, you
2070can specify to load them to the session daemon on the command line
2071(see the opt:lttng-sessiond(8):--extra-kmod-probes option).
2072
2073The LTTng kernel modules are installed in
2074+/usr/lib/modules/__release__/extra+ by default, where +__release__+ is
2075the kernel release (output of `uname --kernel-release`).
2076
2077
2078[[lttng-sessiond]]
2079=== Session daemon
2080
2081[role="img-100"]
2082.The session daemon.
2083image::plumbing-sessiond.png[]
2084
2085The _session daemon_, man:lttng-sessiond(8), is a
2086https://en.wikipedia.org/wiki/Daemon_(computing)[daemon] which:
2087
2088* Manages <<tracing-session,recording sessions>>.
2089
2090* Controls the various components (like tracers and
2091 <<lttng-consumerd,consumer daemons>>) of LTTng.
2092
2093* Sends <<notif-trigger-api,asynchronous notifications>> to user
2094 applications.
2095
2096The session daemon is part of LTTng-tools.
2097
2098The session daemon sends control requests to and receives control
2099responses from:
2100
2101* The <<lttng-ust,user space tracing library>>.
2102+
2103Any instance of the user space tracing library first registers to
2104a session daemon. Then, the session daemon can send requests to
2105this instance, such as:
2106+
2107--
2108** Get the list of tracepoints.
2109** Share a <<event,recording event rule>> so that the user space tracing
2110 library can decide whether or not a given tracepoint can emit events.
2111 Amongst the possible conditions of a recording event rule is a filter
2112 expression which `liblttng-ust` evaluates before it emits an event.
2113** Share <<channel,channel>> attributes and ring buffer locations.
2114--
2115+
2116The session daemon and the user space tracing library use a Unix
2117domain socket to communicate.
2118
2119* The <<lttng-ust-agents,user space tracing agents>>.
2120+
2121Any instance of a user space tracing agent first registers to
2122a session daemon. Then, the session daemon can send requests to
2123this instance, such as:
2124+
2125--
2126** Get the list of loggers.
2127** Enable or disable a specific logger.
2128--
2129+
2130The session daemon and the user space tracing agent use a TCP connection
2131to communicate.
2132
2133* The <<lttng-modules,LTTng kernel tracer>>.
2134* The <<lttng-consumerd,consumer daemon>>.
2135+
2136The session daemon sends requests to the consumer daemon to instruct
2137it where to send the trace data streams, amongst other information.
2138
2139* The <<lttng-relayd,relay daemon>>.
2140
2141The session daemon receives commands from the
2142<<liblttng-ctl-lttng,tracing control library>>.
2143
2144The session daemon can receive asynchronous messages from the
2145<<lttng-ust,user space>> and <<lttng-modules,kernel>> tracers
2146when they emit events. This supports the ``event rule matches''
2147<<trigger,trigger>> condition feature (see
2148“<<add-event-rule-matches-trigger,Add an ``event rule matches'' trigger
2149to a session daemon>>”).
2150
2151The root session daemon loads the appropriate
2152<<lttng-modules,LTTng kernel modules>> on startup. It also spawns
2153one or more <<lttng-consumerd,consumer daemons>> as soon as you create
2154a <<event,recording event rule>>.
2155
2156The session daemon doesn't send and receive trace data: this is the
2157role of the <<lttng-consumerd,consumer daemon>> and
2158<<lttng-relayd,relay daemon>>. It does, however, generate the
2159https://diamon.org/ctf/[CTF] metadata stream.
2160
2161Each Unix user can have its own session daemon instance. The
2162recording sessions which different session daemons manage are completely
2163independent.
2164
2165The root user's session daemon is the only one which is
2166allowed to control the LTTng kernel tracer, and its spawned consumer
2167daemon is the only one which is allowed to consume trace data from the
2168LTTng kernel tracer. Note, however, that any Unix user which is a member
2169of the <<tracing-group,tracing group>> is allowed
2170to create <<channel,channels>> in the
2171Linux kernel <<domain,tracing domain>>, and therefore to use the Linux
2172kernel LTTng tracer.
2173
2174The <<lttng-cli,cmd:lttng command-line tool>> automatically starts a
2175session daemon when using its `create` command if none is currently
2176running. You can also start the session daemon manually.
2177
2178
2179[[lttng-consumerd]]
2180=== Consumer daemon
2181
2182[role="img-100"]
2183.The consumer daemon.
2184image::plumbing-consumerd.png[]
2185
2186The _consumer daemon_, cmd:lttng-consumerd, is a
2187https://en.wikipedia.org/wiki/Daemon_(computing)[daemon] which shares
2188ring buffers with user applications or with the LTTng kernel modules to
2189collect trace data and send it to some location (file system or to a
2190<<lttng-relayd,relay daemon>> over the network).
2191
2192The consumer daemon is part of LTTng-tools.
2193
2194You don't start a consumer daemon manually: a consumer daemon is always
2195spawned by a <<lttng-sessiond,session daemon>> as soon as you create a
2196<<event,recording event rule>>, that is, before you start recording. When
2197you kill its owner session daemon, the consumer daemon also exits
2198because it's the child process of the session daemon. Command-line
2199options of man:lttng-sessiond(8) target the consumer daemon process.
2200
2201There are up to two running consumer daemons per Unix user, whereas only
2202one session daemon can run per user. This is because each process can be
2203either 32-bit or 64-bit: if the target system runs a mixture of 32-bit
2204and 64-bit processes, it's more efficient to have separate
2205corresponding 32-bit and 64-bit consumer daemons. The root user is an
2206exception: it can have up to _three_ running consumer daemons: 32-bit
2207and 64-bit instances for its user applications, and one more
2208reserved for collecting kernel trace data.
2209
2210
2211[[lttng-relayd]]
2212=== Relay daemon
2213
2214[role="img-100"]
2215.The relay daemon.
2216image::plumbing-relayd.png[]
2217
2218The _relay daemon_, man:lttng-relayd(8), is a
2219https://en.wikipedia.org/wiki/Daemon_(computing)[daemon] acting as a bridge
2220between remote session and consumer daemons, local trace files, and a
2221remote live trace reader.
2222
2223The relay daemon is part of LTTng-tools.
2224
2225The main purpose of the relay daemon is to implement a receiver of
2226<<sending-trace-data-over-the-network,trace data over the network>>.
2227This is useful when the target system doesn't have much file system
2228space to write trace files locally.
2229
2230The relay daemon is also a server to which a
2231<<lttng-live,live trace reader>> can
2232connect. The live trace reader sends requests to the relay daemon to
2233receive trace data as the target system records events. The
2234communication protocol is named _LTTng live_; it's used over TCP
2235connections.
2236
2237Note that you can start the relay daemon on the target system directly.
2238This is the setup of choice when the use case is to view/analyze events
2239as the target system records them without the need of a remote system.
2240
2241
2242[[instrumenting]]
2243== [[using-lttng]]Instrumentation
2244
2245There are many examples of tracing and monitoring in our everyday life:
2246
2247* You have access to real-time and historical weather reports and
2248 forecasts thanks to weather stations installed around the country.
2249* You know your heart is safe thanks to an electrocardiogram.
2250* You make sure not to drive your car too fast and to have enough fuel
2251 to reach your destination thanks to gauges visible on your dashboard.
2252
2253All the previous examples have something in common: they rely on
2254**instruments**. Without the electrodes attached to the surface of your
2255body skin, cardiac monitoring is futile.
2256
2257LTTng, as a tracer, is no different from those real life examples. If
2258you're about to trace a software system or, in other words, record its
2259history of execution, you better have **instrumentation points** in the
2260subject you're tracing, that is, the actual software system.
2261
2262<<instrumentation-point-types,Various ways>> were developed to
2263instrument a piece of software for LTTng tracing. The most
2264straightforward one is to manually place static instrumentation points,
2265called _tracepoints_, in the source code of the application. The Linux
2266kernel <<domain,tracing domain>> also makes it possible to dynamically
2267add instrumentation points.
2268
2269If you're only interested in tracing the Linux kernel, your
2270instrumentation needs are probably already covered by the built-in
2271<<lttng-modules,Linux kernel instrumentation points>> of LTTng. You may
2272also wish to have LTTng trace a user application which is already
2273instrumented for LTTng tracing. In such cases, skip this whole section
2274and read the topics of the ``<<controlling-tracing,Tracing control>>''
2275section.
2276
2277Many methods are available to instrument a piece of software for LTTng
2278tracing:
2279
2280* <<c-application,Instrument a C/$$C++$$ user application>>.
2281* <<prebuilt-ust-helpers,Load a prebuilt user space tracing helper>>.
2282* <<java-application,Instrument a Java application>>.
2283* <<python-application,Instrument a Python application>>.
2284* <<proc-lttng-logger-abi,Use the LTTng logger>>.
2285* <<instrumenting-linux-kernel,Instrument a Linux kernel image or module>>.
2286
2287
2288[[c-application]]
2289=== [[cxx-application]]Instrument a C/$$C++$$ user application
2290
2291The high level procedure to instrument a C or $$C++$$ user application
2292with the <<lttng-ust,LTTng user space tracing library>>, `liblttng-ust`,
2293is:
2294
2295. <<tracepoint-provider,Create the source files of a tracepoint provider
2296 package>>.
2297
2298. <<probing-the-application-source-code,Add tracepoints to
2299 the source code of the application>>.
2300
2301. <<building-tracepoint-providers-and-user-application,Build and link
2302 a tracepoint provider package and the user application>>.
2303
2304If you need quick, man:printf(3)-like instrumentation, skip those steps
2305and use <<tracef,`lttng_ust_tracef()`>> or
2306<<tracelog,`lttng_ust_tracelog()`>> instead.
2307
2308IMPORTANT: You need to <<installing-lttng,install>> LTTng-UST to
2309instrument a user application with `liblttng-ust`.
2310
2311
2312[[tracepoint-provider]]
2313==== Create the source files of a tracepoint provider package
2314
2315A _tracepoint provider_ is a set of compiled functions which provide
2316**tracepoints** to an application, the type of instrumentation point
2317which LTTng-UST provides.
2318
2319Those functions can make LTTng emit events with user-defined fields and
2320serialize those events as event records to one or more LTTng-UST
2321<<channel,channel>> sub-buffers. The `lttng_ust_tracepoint()` macro,
2322which you <<probing-the-application-source-code,insert in the source
2323code of a user application>>, calls those functions.
2324
2325A _tracepoint provider package_ is an object file (`.o`) or a shared
2326library (`.so`) which contains one or more tracepoint providers. Its
2327source files are:
2328
2329* One or more <<tpp-header,tracepoint provider header>> (`.h`).
2330* A <<tpp-source,tracepoint provider package source>> (`.c`).
2331
2332A tracepoint provider package is dynamically linked with `liblttng-ust`,
2333the LTTng user space tracer, at run time.
2334
2335[role="img-100"]
2336.User application linked with `liblttng-ust` and containing a tracepoint provider.
2337image::ust-app.png[]
2338
2339NOTE: If you need quick, man:printf(3)-like instrumentation, skip
2340creating and using a tracepoint provider and use
2341<<tracef,`lttng_ust_tracef()`>> or <<tracelog,`lttng_ust_tracelog()`>>
2342instead.
2343
2344
2345[[tpp-header]]
2346===== Create a tracepoint provider header file template
2347
2348A _tracepoint provider header file_ contains the tracepoint definitions
2349of a tracepoint provider.
2350
2351To create a tracepoint provider header file:
2352
2353. Start from this template:
2354+
2355--
2356[source,c]
2357.Tracepoint provider header file template (`.h` file extension).
2358----
2359#undef LTTNG_UST_TRACEPOINT_PROVIDER
2360#define LTTNG_UST_TRACEPOINT_PROVIDER provider_name
2361
2362#undef LTTNG_UST_TRACEPOINT_INCLUDE
2363#define LTTNG_UST_TRACEPOINT_INCLUDE "./tp.h"
2364
2365#if !defined(_TP_H) || defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ)
2366#define _TP_H
2367
2368#include <lttng/tracepoint.h>
2369
2370/*
2371 * Use LTTNG_UST_TRACEPOINT_EVENT(), LTTNG_UST_TRACEPOINT_EVENT_CLASS(),
2372 * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(), and
2373 * LTTNG_UST_TRACEPOINT_LOGLEVEL() here.
2374 */
2375
2376#endif /* _TP_H */
2377
2378#include <lttng/tracepoint-event.h>
2379----
2380--
2381+
2382Replace:
2383+
2384* +__provider_name__+ with the name of your tracepoint provider.
2385* `"tp.h"` with the name of your tracepoint provider header file.
2386
2387. Below the `#include <lttng/tracepoint.h>` line, put your
2388 <<defining-tracepoints,tracepoint definitions>>.
2389
2390Your tracepoint provider name must be unique amongst all the possible
2391tracepoint provider names used on the same target system. We suggest to
2392include the name of your project or company in the name, for example,
2393`org_lttng_my_project_tpp`.
2394
2395
2396[[defining-tracepoints]]
2397===== Create a tracepoint definition
2398
2399A _tracepoint definition_ defines, for a given tracepoint:
2400
2401* Its **input arguments**.
2402+
2403They're the macro parameters that the `lttng_ust_tracepoint()` macro
2404accepts for this particular tracepoint in the source code of the user
2405application.
2406
2407* Its **output event fields**.
2408+
2409They're the sources of event fields that form the payload of any event
2410that the execution of the `lttng_ust_tracepoint()` macro emits for this
2411particular tracepoint.
2412
2413Create a tracepoint definition with the
2414`LTTNG_UST_TRACEPOINT_EVENT()` macro below the `#include <lttng/tracepoint.h>`
2415line in the
2416<<tpp-header,tracepoint provider header file template>>.
2417
2418The syntax of the `LTTNG_UST_TRACEPOINT_EVENT()` macro is:
2419
2420[source,c]
2421.`LTTNG_UST_TRACEPOINT_EVENT()` macro syntax.
2422----
2423LTTNG_UST_TRACEPOINT_EVENT(
2424 /* Tracepoint provider name */
2425 provider_name,
2426
2427 /* Tracepoint name */
2428 tracepoint_name,
2429
2430 /* Input arguments */
2431 LTTNG_UST_TP_ARGS(
2432 arguments
2433 ),
2434
2435 /* Output event fields */
2436 LTTNG_UST_TP_FIELDS(
2437 fields
2438 )
2439)
2440----
2441
2442Replace:
2443
2444* +__provider_name__+ with your tracepoint provider name.
2445* +__tracepoint_name__+ with your tracepoint name.
2446* +__arguments__+ with the <<tpp-def-input-args,input arguments>>.
2447* +__fields__+ with the <<tpp-def-output-fields,output event field>>
2448 definitions.
2449
2450The full name of this tracepoint is `provider_name:tracepoint_name`.
2451
2452[IMPORTANT]
2453.Event name length limitation
2454====
2455The concatenation of the tracepoint provider name and the tracepoint
2456name must not exceed **254{nbsp}characters**. If it does, the
2457instrumented application compiles and runs, but LTTng throws multiple
2458warnings and you could experience serious issues.
2459====
2460
2461[[tpp-def-input-args]]The syntax of the `LTTNG_UST_TP_ARGS()` macro is:
2462
2463[source,c]
2464.`LTTNG_UST_TP_ARGS()` macro syntax.
2465----
2466LTTNG_UST_TP_ARGS(
2467 type, arg_name
2468)
2469----
2470
2471Replace:
2472
2473* +__type__+ with the C{nbsp}type of the argument.
2474* +__arg_name__+ with the argument name.
2475
2476You can repeat +__type__+ and +__arg_name__+ up to 10{nbsp}times to have
2477more than one argument.
2478
2479.`LTTNG_UST_TP_ARGS()` usage with three arguments.
2480====
2481[source,c]
2482----
2483LTTNG_UST_TP_ARGS(
2484 int, count,
2485 float, ratio,
2486 const char*, query
2487)
2488----
2489====
2490
2491The `LTTNG_UST_TP_ARGS()` and `LTTNG_UST_TP_ARGS(void)` forms are valid
2492to create a tracepoint definition with no input arguments.
2493
2494[[tpp-def-output-fields]]The `LTTNG_UST_TP_FIELDS()` macro contains a
2495list of `lttng_ust_field_*()` macros. Each `lttng_ust_field_*()` macro
2496defines one event field. See man:lttng-ust(3) for a complete description
2497of the available `lttng_ust_field_*()` macros. A `lttng_ust_field_*()`
2498macro specifies the type, size, and byte order of one event field.
2499
2500Each `lttng_ust_field_*()` macro takes an _argument expression_
2501parameter. This is a C{nbsp}expression that the tracer evaluates at the
2502`lttng_ust_tracepoint()` macro site in the source code of the
2503application. This expression provides the source of data of a field. The
2504argument expression can include input argument names listed in the
2505`LTTNG_UST_TP_ARGS()` macro.
2506
2507Each `lttng_ust_field_*()` macro also takes a _field name_ parameter.
2508Field names must be unique within a given tracepoint definition.
2509
2510Here's a complete tracepoint definition example:
2511
2512.Tracepoint definition.
2513====
2514The following tracepoint definition defines a tracepoint which takes
2515three input arguments and has four output event fields.
2516
2517[source,c]
2518----
2519#include "my-custom-structure.h"
2520
2521LTTNG_UST_TRACEPOINT_EVENT(
2522 my_provider,
2523 my_tracepoint,
2524 LTTNG_UST_TP_ARGS(
2525 const struct my_custom_structure *, my_custom_structure,
2526 float, ratio,
2527 const char *, query
2528 ),
2529 LTTNG_UST_TP_FIELDS(
2530 lttng_ust_field_string(query_field, query)
2531 lttng_ust_field_float(double, ratio_field, ratio)
2532 lttng_ust_field_integer(int, recv_size,
2533 my_custom_structure->recv_size)
2534 lttng_ust_field_integer(int, send_size,
2535 my_custom_structure->send_size)
2536 )
2537)
2538----
2539
2540Refer to this tracepoint definition with the `lttng_ust_tracepoint()`
2541macro in the source code of your application like this:
2542
2543[source,c]
2544----
2545lttng_ust_tracepoint(my_provider, my_tracepoint,
2546 my_structure, some_ratio, the_query);
2547----
2548====
2549
2550NOTE: The LTTng-UST tracer only evaluates the arguments of a tracepoint
2551at run time when such a tracepoint _could_ emit an event. See
2552<<event-creation-emission-opti,this note>> to learn more.
2553
2554
2555[[using-tracepoint-classes]]
2556===== Use a tracepoint class
2557
2558A _tracepoint class_ is a class of tracepoints which share the same
2559output event field definitions. A _tracepoint instance_ is one
2560instance of such a defined tracepoint class, with its own tracepoint
2561name.
2562
2563The <<defining-tracepoints,`LTTNG_UST_TRACEPOINT_EVENT()` macro>> is
2564actually a shorthand which defines both a tracepoint class and a
2565tracepoint instance at the same time.
2566
2567When you build a tracepoint provider package, the C or $$C++$$ compiler
2568creates one serialization function for each **tracepoint class**. A
2569serialization function is responsible for serializing the event fields
2570of a tracepoint to a sub-buffer when recording.
2571
2572For various performance reasons, when your situation requires multiple
2573tracepoint definitions with different names, but with the same event
2574fields, we recommend that you manually create a tracepoint class and
2575instantiate as many tracepoint instances as needed. One positive effect
2576of such a design, amongst other advantages, is that all tracepoint
2577instances of the same tracepoint class reuse the same serialization
2578function, thus reducing
2579https://en.wikipedia.org/wiki/Cache_pollution[cache pollution].
2580
2581.Use a tracepoint class and tracepoint instances.
2582====
2583Consider the following three tracepoint definitions:
2584
2585[source,c]
2586----
2587LTTNG_UST_TRACEPOINT_EVENT(
2588 my_app,
2589 get_account,
2590 LTTNG_UST_TP_ARGS(
2591 int, userid,
2592 size_t, len
2593 ),
2594 LTTNG_UST_TP_FIELDS(
2595 lttng_ust_field_integer(int, userid, userid)
2596 lttng_ust_field_integer(size_t, len, len)
2597 )
2598)
2599
2600LTTNG_UST_TRACEPOINT_EVENT(
2601 my_app,
2602 get_settings,
2603 LTTNG_UST_TP_ARGS(
2604 int, userid,
2605 size_t, len
2606 ),
2607 LTTNG_UST_TP_FIELDS(
2608 lttng_ust_field_integer(int, userid, userid)
2609 lttng_ust_field_integer(size_t, len, len)
2610 )
2611)
2612
2613LTTNG_UST_TRACEPOINT_EVENT(
2614 my_app,
2615 get_transaction,
2616 LTTNG_UST_TP_ARGS(
2617 int, userid,
2618 size_t, len
2619 ),
2620 LTTNG_UST_TP_FIELDS(
2621 lttng_ust_field_integer(int, userid, userid)
2622 lttng_ust_field_integer(size_t, len, len)
2623 )
2624)
2625----
2626
2627In this case, we create three tracepoint classes, with one implicit
2628tracepoint instance for each of them: `get_account`, `get_settings`, and
2629`get_transaction`. However, they all share the same event field names
2630and types. Hence three identical, yet independent serialization
2631functions are created when you build the tracepoint provider package.
2632
2633A better design choice is to define a single tracepoint class and three
2634tracepoint instances:
2635
2636[source,c]
2637----
2638/* The tracepoint class */
2639LTTNG_UST_TRACEPOINT_EVENT_CLASS(
2640 /* Tracepoint class provider name */
2641 my_app,
2642
2643 /* Tracepoint class name */
2644 my_class,
2645
2646 /* Input arguments */
2647 LTTNG_UST_TP_ARGS(
2648 int, userid,
2649 size_t, len
2650 ),
2651
2652 /* Output event fields */
2653 LTTNG_UST_TP_FIELDS(
2654 lttng_ust_field_integer(int, userid, userid)
2655 lttng_ust_field_integer(size_t, len, len)
2656 )
2657)
2658
2659/* The tracepoint instances */
2660LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(
2661 /* Tracepoint class provider name */
2662 my_app,
2663
2664 /* Tracepoint class name */
2665 my_class,
2666
2667 /* Instance provider name */
2668 my_app,
2669
2670 /* Tracepoint name */
2671 get_account,
2672
2673 /* Input arguments */
2674 LTTNG_UST_TP_ARGS(
2675 int, userid,
2676 size_t, len
2677 )
2678)
2679LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(
2680 my_app,
2681 my_class,
2682 get_settings,
2683 LTTNG_UST_TP_ARGS(
2684 int, userid,
2685 size_t, len
2686 )
2687)
2688LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(
2689 my_app,
2690 my_class,
2691 get_transaction,
2692 LTTNG_UST_TP_ARGS(
2693 int, userid,
2694 size_t, len
2695 )
2696)
2697----
2698====
2699
2700The tracepoint class and instance provider names must be the same if the
2701`LTTNG_UST_TRACEPOINT_EVENT_CLASS()` and
2702`LTTNG_UST_TRACEPOINT_EVENT_INSTANCE()` expansions are part of the same
2703translation unit. See man:lttng-ust(3) to learn more.
2704
2705
2706[[assigning-log-levels]]
2707===== Assign a log level to a tracepoint definition
2708
2709Assign a _log level_ to a <<defining-tracepoints,tracepoint definition>>
2710with the `LTTNG_UST_TRACEPOINT_LOGLEVEL()` macro.
2711
2712Assigning different levels of severity to tracepoint definitions can be
2713useful: when you <<enabling-disabling-events,create a recording event
2714rule>>, you can target tracepoints having a log level at least as severe
2715as a specific value.
2716
2717The concept of LTTng-UST log levels is similar to the levels found
2718in typical logging frameworks:
2719
2720* In a logging framework, the log level is given by the function
2721 or method name you use at the log statement site: `debug()`,
2722 `info()`, `warn()`, `error()`, and so on.
2723
2724* In LTTng-UST, you statically assign the log level to a tracepoint
2725 definition; any `lttng_ust_tracepoint()` macro invocation which refers
2726 to this definition has this log level.
2727
2728You must use `LTTNG_UST_TRACEPOINT_LOGLEVEL()` _after_ the
2729<<defining-tracepoints,`LTTNG_UST_TRACEPOINT_EVENT()`>> or
2730<<using-tracepoint-classes,`LTTNG_UST_TRACEPOINT_INSTANCE()`>> macro for
2731a given tracepoint.
2732
2733The syntax of the `LTTNG_UST_TRACEPOINT_LOGLEVEL()` macro is:
2734
2735[source,c]
2736.`LTTNG_UST_TRACEPOINT_LOGLEVEL()` macro syntax.
2737----
2738LTTNG_UST_TRACEPOINT_LOGLEVEL(provider_name, tracepoint_name, log_level)
2739----
2740
2741Replace:
2742
2743* +__provider_name__+ with the tracepoint provider name.
2744* +__tracepoint_name__+ with the tracepoint name.
2745* +__log_level__+ with the log level to assign to the tracepoint
2746 definition named +__tracepoint_name__+ in the +__provider_name__+
2747 tracepoint provider.
2748+
2749See man:lttng-ust(3) for a list of available log level names.
2750
fc360555 2751.Assign the `LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_UNIT` log level to a tracepoint definition.
50e95807
PP
2752====
2753[source,c]
2754----
2755/* Tracepoint definition */
2756LTTNG_UST_TRACEPOINT_EVENT(
2757 my_app,
2758 get_transaction,
2759 LTTNG_UST_TP_ARGS(
2760 int, userid,
2761 size_t, len
2762 ),
2763 LTTNG_UST_TP_FIELDS(
2764 lttng_ust_field_integer(int, userid, userid)
2765 lttng_ust_field_integer(size_t, len, len)
2766 )
2767)
2768
2769/* Log level assignment */
2770LTTNG_UST_TRACEPOINT_LOGLEVEL(my_app, get_transaction,
2771 LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_UNIT)
2772----
2773====
2774
2775
2776[[tpp-source]]
2777===== Create a tracepoint provider package source file
2778
2779A _tracepoint provider package source file_ is a C source file which
2780includes a <<tpp-header,tracepoint provider header file>> to expand its
2781macros into event serialization and other functions.
2782
2783Use the following tracepoint provider package source file template:
2784
2785[source,c]
2786.Tracepoint provider package source file template.
2787----
2788#define LTTNG_UST_TRACEPOINT_CREATE_PROBES
2789
2790#include "tp.h"
2791----
2792
2793Replace `tp.h` with the name of your <<tpp-header,tracepoint provider
2794header file>> name. You may also include more than one tracepoint
2795provider header file here to create a tracepoint provider package
2796holding more than one tracepoint providers.
2797
2798
2799[[probing-the-application-source-code]]
2800==== Add tracepoints to the source code of an application
2801
2802Once you <<tpp-header,create a tracepoint provider header file>>, use
2803the `lttng_ust_tracepoint()` macro in the source code of your
2804application to insert the tracepoints that this header
2805<<defining-tracepoints,defines>>.
2806
2807The `lttng_ust_tracepoint()` macro takes at least two parameters: the
2808tracepoint provider name and the tracepoint name. The corresponding
2809tracepoint definition defines the other parameters.
2810
2811.`lttng_ust_tracepoint()` usage.
2812====
2813The following <<defining-tracepoints,tracepoint definition>> defines a
2814tracepoint which takes two input arguments and has two output event
2815fields.
2816
2817[source,c]
2818.Tracepoint provider header file.
2819----
2820#include "my-custom-structure.h"
2821
2822LTTNG_UST_TRACEPOINT_EVENT(
2823 my_provider,
2824 my_tracepoint,
2825 LTTNG_UST_TP_ARGS(
2826 int, argc,
2827 const char *, cmd_name
2828 ),
2829 LTTNG_UST_TP_FIELDS(
2830 lttng_ust_field_string(cmd_name, cmd_name)
2831 lttng_ust_field_integer(int, number_of_args, argc)
2832 )
2833)
2834----
2835
2836Refer to this tracepoint definition with the `lttng_ust_tracepoint()`
2837macro in the source code of your application like this:
2838
2839[source,c]
2840.Application source file.
2841----
2842#include "tp.h"
2843
2844int main(int argc, char* argv[])
2845{
2846 lttng_ust_tracepoint(my_provider, my_tracepoint, argc, argv[0]);
2847 return 0;
2848}
2849----
2850
2851Note how the source code of the application includes
2852the tracepoint provider header file containing the tracepoint
2853definitions to use, path:{tp.h}.
2854====
2855
2856.`lttng_ust_tracepoint()` usage with a complex tracepoint definition.
2857====
2858Consider this complex tracepoint definition, where multiple event
2859fields refer to the same input arguments in their argument expression
2860parameter:
2861
2862[source,c]
2863.Tracepoint provider header file.
2864----
2865/* For `struct stat` */
2866#include <sys/types.h>
2867#include <sys/stat.h>
2868#include <unistd.h>
2869
2870LTTNG_UST_TRACEPOINT_EVENT(
2871 my_provider,
2872 my_tracepoint,
2873 LTTNG_UST_TP_ARGS(
2874 int, my_int_arg,
2875 char *, my_str_arg,
2876 struct stat *, st
2877 ),
2878 LTTNG_UST_TP_FIELDS(
2879 lttng_ust_field_integer(int, my_constant_field, 23 + 17)
2880 lttng_ust_field_integer(int, my_int_arg_field, my_int_arg)
2881 lttng_ust_field_integer(int, my_int_arg_field2,
2882 my_int_arg * my_int_arg)
2883 lttng_ust_field_integer(int, sum4_field,
2884 my_str_arg[0] + my_str_arg[1] +
2885 my_str_arg[2] + my_str_arg[3])
2886 lttng_ust_field_string(my_str_arg_field, my_str_arg)
2887 lttng_ust_field_integer_hex(off_t, size_field, st->st_size)
2888 lttng_ust_field_float(double, size_dbl_field, (double) st->st_size)
2889 lttng_ust_field_sequence_text(char, half_my_str_arg_field,
2890 my_str_arg, size_t,
2891 strlen(my_str_arg) / 2)
2892 )
2893)
2894----
2895
2896Refer to this tracepoint definition with the `lttng_ust_tracepoint()`
2897macro in the source code of your application like this:
2898
2899[source,c]
2900.Application source file.
2901----
2902#define LTTNG_UST_TRACEPOINT_DEFINE
2903#include "tp.h"
2904
2905int main(void)
2906{
2907 struct stat s;
2908
2909 stat("/etc/fstab", &s);
2910 lttng_ust_tracepoint(my_provider, my_tracepoint, 23,
2911 "Hello, World!", &s);
2912
2913 return 0;
2914}
2915----
2916
2917If you look at the event record that LTTng writes when recording this
2918program, assuming the file size of path:{/etc/fstab} is 301{nbsp}bytes,
2919it should look like this:
2920
2921.Event record fields
2922|====
2923|Field name |Field value
2924|`my_constant_field` |40
2925|`my_int_arg_field` |23
2926|`my_int_arg_field2` |529
2927|`sum4_field` |389
2928|`my_str_arg_field` |`Hello, World!`
2929|`size_field` |0x12d
2930|`size_dbl_field` |301.0
2931|`half_my_str_arg_field` |`Hello,`
2932|====
2933====
2934
2935Sometimes, the arguments you pass to `lttng_ust_tracepoint()` are
2936expensive to evaluate--they use the call stack, for example. To avoid
2937this computation when LTTng wouldn't emit any event anyway, use the
2938`lttng_ust_tracepoint_enabled()` and `lttng_ust_do_tracepoint()` macros.
2939
2940The syntax of the `lttng_ust_tracepoint_enabled()` and
2941`lttng_ust_do_tracepoint()` macros is:
2942
2943[source,c]
2944.`lttng_ust_tracepoint_enabled()` and `lttng_ust_do_tracepoint()` macros syntax.
2945----
2946lttng_ust_tracepoint_enabled(provider_name, tracepoint_name)
2947
2948lttng_ust_do_tracepoint(provider_name, tracepoint_name, ...)
2949----
2950
2951Replace:
2952
2953* +__provider_name__+ with the tracepoint provider name.
2954* +__tracepoint_name__+ with the tracepoint name.
2955
2956`lttng_ust_tracepoint_enabled()` returns a non-zero value if executing
2957the tracepoint named `tracepoint_name` from the provider named
2958`provider_name` _could_ make LTTng emit an event, depending on the
2959payload of said event.
2960
2961`lttng_ust_do_tracepoint()` is like `lttng_ust_tracepoint()`, except
2962that it doesn't check what `lttng_ust_tracepoint_enabled()` checks.
2963Using `lttng_ust_tracepoint()` with `lttng_ust_tracepoint_enabled()` is
2964dangerous because `lttng_ust_tracepoint()` also contains the
2965`lttng_ust_tracepoint_enabled()` check; therefore, a race condition is
2966possible in this situation:
2967
2968[source,c]
2969.Possible race condition when using `lttng_ust_tracepoint_enabled()` with `lttng_ust_tracepoint()`.
2970----
2971if (lttng_ust_tracepoint_enabled(my_provider, my_tracepoint)) {
2972 stuff = prepare_stuff();
2973}
2974
2975lttng_ust_tracepoint(my_provider, my_tracepoint, stuff);
2976----
2977
2978If `lttng_ust_tracepoint_enabled()` is false, but would be true after
2979the conditional block, then `stuff` isn't prepared: the emitted event
2980will either contain wrong data, or the whole application could crash
2981(with a segmentation fault, for example).
2982
2983NOTE: Neither `lttng_ust_tracepoint_enabled()` nor
2984`lttng_ust_do_tracepoint()` have an `STAP_PROBEV()` call. If you need
2985it, you must emit this call yourself.
2986
2987
2988[[building-tracepoint-providers-and-user-application]]
2989==== Build and link a tracepoint provider package and an application
2990
2991Once you have one or more <<tpp-header,tracepoint provider header
2992files>> and a <<tpp-source,tracepoint provider package source file>>,
2993create the tracepoint provider package by compiling its source
2994file. From here, multiple build and run scenarios are possible. The
2995following table shows common application and library configurations
2996along with the required command lines to achieve them.
2997
2998In the following diagrams, we use the following file names:
2999
3000`app`::
3001 Executable application.
3002
3003`app.o`::
3004 Application object file.
3005
3006`tpp.o`::
3007 Tracepoint provider package object file.
3008
3009`tpp.a`::
3010 Tracepoint provider package archive file.
3011
3012`libtpp.so`::
3013 Tracepoint provider package shared object file.
3014
3015`emon.o`::
3016 User library object file.
3017
3018`libemon.so`::
3019 User library shared object file.
3020
3021We use the following symbols in the diagrams of table below:
3022
3023[role="img-100"]
3024.Symbols used in the build scenario diagrams.
3025image::ust-sit-symbols.png[]
3026
3027We assume that path:{.} is part of the env:LD_LIBRARY_PATH environment
3028variable in the following instructions.
3029
3030[role="growable ust-scenarios",cols="asciidoc,asciidoc"]
3031.Common tracepoint provider package scenarios.
3032|====
3033|Scenario |Instructions
3034
3035|
3036The instrumented application is statically linked with
3037the tracepoint provider package object.
3038
3039image::ust-sit+app-linked-with-tp-o+app-instrumented.png[]
3040
3041|
3042include::../common/ust-sit-step-tp-o.txt[]
3043
3044To build the instrumented application:
3045
3046. In path:{app.c}, before including path:{tpp.h}, add the following line:
3047+
3048--
3049[source,c]
3050----
3051#define LTTNG_UST_TRACEPOINT_DEFINE
3052----
3053--
3054
3055. Compile the application source file:
3056+
3057--
3058[role="term"]
3059----
3060$ gcc -c app.c
3061----
3062--
3063
3064. Build the application:
3065+
3066--
3067[role="term"]
3068----
3069$ gcc -o app app.o tpp.o -llttng-ust -ldl
3070----
3071--
3072
3073To run the instrumented application:
3074
3075* Start the application:
3076+
3077--
3078[role="term"]
3079----
3080$ ./app
3081----
3082--
3083
3084|
3085The instrumented application is statically linked with the
3086tracepoint provider package archive file.
3087
3088image::ust-sit+app-linked-with-tp-a+app-instrumented.png[]
3089
3090|
3091To create the tracepoint provider package archive file:
3092
3093. Compile the <<tpp-source,tracepoint provider package source file>>:
3094+
3095--
3096[role="term"]
3097----
3098$ gcc -I. -c tpp.c
3099----
3100--
3101
3102. Create the tracepoint provider package archive file:
3103+
3104--
3105[role="term"]
3106----
3107$ ar rcs tpp.a tpp.o
3108----
3109--
3110
3111To build the instrumented application:
3112
3113. In path:{app.c}, before including path:{tpp.h}, add the following line:
3114+
3115--
3116[source,c]
3117----
3118#define LTTNG_UST_TRACEPOINT_DEFINE
3119----
3120--
3121
3122. Compile the application source file:
3123+
3124--
3125[role="term"]
3126----
3127$ gcc -c app.c
3128----
3129--
3130
3131. Build the application:
3132+
3133--
3134[role="term"]
3135----
3136$ gcc -o app app.o tpp.a -llttng-ust -ldl
3137----
3138--
3139
3140To run the instrumented application:
3141
3142* Start the application:
3143+
3144--
3145[role="term"]
3146----
3147$ ./app
3148----
3149--
3150
3151|
3152The instrumented application is linked with the tracepoint provider
3153package shared object.
3154
3155image::ust-sit+app-linked-with-tp-so+app-instrumented.png[]
3156
3157|
3158include::../common/ust-sit-step-tp-so.txt[]
3159
3160To build the instrumented application:
3161
3162. In path:{app.c}, before including path:{tpp.h}, add the following line:
3163+
3164--
3165[source,c]
3166----
3167#define LTTNG_UST_TRACEPOINT_DEFINE
3168----
3169--
3170
3171. Compile the application source file:
3172+
3173--
3174[role="term"]
3175----
3176$ gcc -c app.c
3177----
3178--
3179
3180. Build the application:
3181+
3182--
3183[role="term"]
3184----
3185$ gcc -o app app.o -ldl -L. -ltpp
3186----
3187--
3188
3189To run the instrumented application:
3190
3191* Start the application:
3192+
3193--
3194[role="term"]
3195----
3196$ ./app
3197----
3198--
3199
3200|
3201The tracepoint provider package shared object is preloaded before the
3202instrumented application starts.
3203
3204image::ust-sit+tp-so-preloaded+app-instrumented.png[]
3205
3206|
3207include::../common/ust-sit-step-tp-so.txt[]
3208
3209To build the instrumented application:
3210
3211. In path:{app.c}, before including path:{tpp.h}, add the
3212 following lines:
3213+
3214--
3215[source,c]
3216----
3217#define LTTNG_UST_TRACEPOINT_DEFINE
3218#define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3219----
3220--
3221
3222. Compile the application source file:
3223+
3224--
3225[role="term"]
3226----
3227$ gcc -c app.c
3228----
3229--
3230
3231. Build the application:
3232+
3233--
3234[role="term"]
3235----
3236$ gcc -o app app.o -ldl
3237----
3238--
3239
3240To run the instrumented application with tracing support:
3241
3242* Preload the tracepoint provider package shared object and
3243 start the application:
3244+
3245--
3246[role="term"]
3247----
3248$ LD_PRELOAD=./libtpp.so ./app
3249----
3250--
3251
3252To run the instrumented application without tracing support:
3253
3254* Start the application:
3255+
3256--
3257[role="term"]
3258----
3259$ ./app
3260----
3261--
3262
3263|
3264The instrumented application dynamically loads the tracepoint provider
3265package shared object.
3266
3267image::ust-sit+app-dlopens-tp-so+app-instrumented.png[]
3268
3269|
3270include::../common/ust-sit-step-tp-so.txt[]
3271
3272To build the instrumented application:
3273
3274. In path:{app.c}, before including path:{tpp.h}, add the
3275 following lines:
3276+
3277--
3278[source,c]
3279----
3280#define LTTNG_UST_TRACEPOINT_DEFINE
3281#define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3282----
3283--
3284
3285. Compile the application source file:
3286+
3287--
3288[role="term"]
3289----
3290$ gcc -c app.c
3291----
3292--
3293
3294. Build the application:
3295+
3296--
3297[role="term"]
3298----
3299$ gcc -o app app.o -ldl
3300----
3301--
3302
3303To run the instrumented application:
3304
3305* Start the application:
3306+
3307--
3308[role="term"]
3309----
3310$ ./app
3311----
3312--
3313
3314|
3315The application is linked with the instrumented user library.
3316
3317The instrumented user library is statically linked with the tracepoint
3318provider package object file.
3319
3320image::ust-sit+app-linked-with-lib+lib-linked-with-tp-o+lib-instrumented.png[]
3321
3322|
3323include::../common/ust-sit-step-tp-o-fpic.txt[]
3324
3325To build the instrumented user library:
3326
3327. In path:{emon.c}, before including path:{tpp.h}, add the
3328 following line:
3329+
3330--
3331[source,c]
3332----
3333#define LTTNG_UST_TRACEPOINT_DEFINE
3334----
3335--
3336
3337. Compile the user library source file:
3338+
3339--
3340[role="term"]
3341----
3342$ gcc -I. -fpic -c emon.c
3343----
3344--
3345
3346. Build the user library shared object:
3347+
3348--
3349[role="term"]
3350----
3351$ gcc -shared -o libemon.so emon.o tpp.o -llttng-ust -ldl
3352----
3353--
3354
3355To build the application:
3356
3357. Compile the application source file:
3358+
3359--
3360[role="term"]
3361----
3362$ gcc -c app.c
3363----
3364--
3365
3366. Build the application:
3367+
3368--
3369[role="term"]
3370----
3371$ gcc -o app app.o -L. -lemon
3372----
3373--
3374
3375To run the application:
3376
3377* Start the application:
3378+
3379--
3380[role="term"]
3381----
3382$ ./app
3383----
3384--
3385
3386|
3387The application is linked with the instrumented user library.
3388
3389The instrumented user library is linked with the tracepoint provider
3390package shared object.
3391
3392image::ust-sit+app-linked-with-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3393
3394|
3395include::../common/ust-sit-step-tp-so.txt[]
3396
3397To build the instrumented user library:
3398
3399. In path:{emon.c}, before including path:{tpp.h}, add the
3400 following line:
3401+
3402--
3403[source,c]
3404----
3405#define LTTNG_UST_TRACEPOINT_DEFINE
3406----
3407--
3408
3409. Compile the user library source file:
3410+
3411--
3412[role="term"]
3413----
3414$ gcc -I. -fpic -c emon.c
3415----
3416--
3417
3418. Build the user library shared object:
3419+
3420--
3421[role="term"]
3422----
3423$ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3424----
3425--
3426
3427To build the application:
3428
3429. Compile the application source file:
3430+
3431--
3432[role="term"]
3433----
3434$ gcc -c app.c
3435----
3436--
3437
3438. Build the application:
3439+
3440--
3441[role="term"]
3442----
3443$ gcc -o app app.o -L. -lemon
3444----
3445--
3446
3447To run the application:
3448
3449* Start the application:
3450+
3451--
3452[role="term"]
3453----
3454$ ./app
3455----
3456--
3457
3458|
3459The tracepoint provider package shared object is preloaded before the
3460application starts.
3461
3462The application is linked with the instrumented user library.
3463
3464image::ust-sit+tp-so-preloaded+app-linked-with-lib+lib-instrumented.png[]
3465
3466|
3467include::../common/ust-sit-step-tp-so.txt[]
3468
3469To build the instrumented user library:
3470
3471. In path:{emon.c}, before including path:{tpp.h}, add the
3472 following lines:
3473+
3474--
3475[source,c]
3476----
3477#define LTTNG_UST_TRACEPOINT_DEFINE
3478#define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3479----
3480--
3481
3482. Compile the user library source file:
3483+
3484--
3485[role="term"]
3486----
3487$ gcc -I. -fpic -c emon.c
3488----
3489--
3490
3491. Build the user library shared object:
3492+
3493--
3494[role="term"]
3495----
3496$ gcc -shared -o libemon.so emon.o -ldl
3497----
3498--
3499
3500To build the application:
3501
3502. Compile the application source file:
3503+
3504--
3505[role="term"]
3506----
3507$ gcc -c app.c
3508----
3509--
3510
3511. Build the application:
3512+
3513--
3514[role="term"]
3515----
3516$ gcc -o app app.o -L. -lemon
3517----
3518--
3519
3520To run the application with tracing support:
3521
3522* Preload the tracepoint provider package shared object and
3523 start the application:
3524+
3525--
3526[role="term"]
3527----
3528$ LD_PRELOAD=./libtpp.so ./app
3529----
3530--
3531
3532To run the application without tracing support:
3533
3534* Start the application:
3535+
3536--
3537[role="term"]
3538----
3539$ ./app
3540----
3541--
3542
3543|
3544The application is linked with the instrumented user library.
3545
3546The instrumented user library dynamically loads the tracepoint provider
3547package shared object.
3548
3549image::ust-sit+app-linked-with-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3550
3551|
3552include::../common/ust-sit-step-tp-so.txt[]
3553
3554To build the instrumented user library:
3555
3556. In path:{emon.c}, before including path:{tpp.h}, add the
3557 following lines:
3558+
3559--
3560[source,c]
3561----
3562#define LTTNG_UST_TRACEPOINT_DEFINE
3563#define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3564----
3565--
3566
3567. Compile the user library source file:
3568+
3569--
3570[role="term"]
3571----
3572$ gcc -I. -fpic -c emon.c
3573----
3574--
3575
3576. Build the user library shared object:
3577+
3578--
3579[role="term"]
3580----
3581$ gcc -shared -o libemon.so emon.o -ldl
3582----
3583--
3584
3585To build the application:
3586
3587. Compile the application source file:
3588+
3589--
3590[role="term"]
3591----
3592$ gcc -c app.c
3593----
3594--
3595
3596. Build the application:
3597+
3598--
3599[role="term"]
3600----
3601$ gcc -o app app.o -L. -lemon
3602----
3603--
3604
3605To run the application:
3606
3607* Start the application:
3608+
3609--
3610[role="term"]
3611----
3612$ ./app
3613----
3614--
3615
3616|
3617The application dynamically loads the instrumented user library.
3618
3619The instrumented user library is linked with the tracepoint provider
3620package shared object.
3621
3622image::ust-sit+app-dlopens-lib+lib-linked-with-tp-so+lib-instrumented.png[]
3623
3624|
3625include::../common/ust-sit-step-tp-so.txt[]
3626
3627To build the instrumented user library:
3628
3629. In path:{emon.c}, before including path:{tpp.h}, add the
3630 following line:
3631+
3632--
3633[source,c]
3634----
3635#define LTTNG_UST_TRACEPOINT_DEFINE
3636----
3637--
3638
3639. Compile the user library source file:
3640+
3641--
3642[role="term"]
3643----
3644$ gcc -I. -fpic -c emon.c
3645----
3646--
3647
3648. Build the user library shared object:
3649+
3650--
3651[role="term"]
3652----
3653$ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp
3654----
3655--
3656
3657To build the application:
3658
3659. Compile the application source file:
3660+
3661--
3662[role="term"]
3663----
3664$ gcc -c app.c
3665----
3666--
3667
3668. Build the application:
3669+
3670--
3671[role="term"]
3672----
3673$ gcc -o app app.o -ldl -L. -lemon
3674----
3675--
3676
3677To run the application:
3678
3679* Start the application:
3680+
3681--
3682[role="term"]
3683----
3684$ ./app
3685----
3686--
3687
3688|
3689The application dynamically loads the instrumented user library.
3690
3691The instrumented user library dynamically loads the tracepoint provider
3692package shared object.
3693
3694image::ust-sit+app-dlopens-lib+lib-dlopens-tp-so+lib-instrumented.png[]
3695
3696|
3697include::../common/ust-sit-step-tp-so.txt[]
3698
3699To build the instrumented user library:
3700
3701. In path:{emon.c}, before including path:{tpp.h}, add the
3702 following lines:
3703+
3704--
3705[source,c]
3706----
3707#define LTTNG_UST_TRACEPOINT_DEFINE
3708#define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3709----
3710--
3711
3712. Compile the user library source file:
3713+
3714--
3715[role="term"]
3716----
3717$ gcc -I. -fpic -c emon.c
3718----
3719--
3720
3721. Build the user library shared object:
3722+
3723--
3724[role="term"]
3725----
3726$ gcc -shared -o libemon.so emon.o -ldl
3727----
3728--
3729
3730To build the application:
3731
3732. Compile the application source file:
3733+
3734--
3735[role="term"]
3736----
3737$ gcc -c app.c
3738----
3739--
3740
3741. Build the application:
3742+
3743--
3744[role="term"]
3745----
3746$ gcc -o app app.o -ldl -L. -lemon
3747----
3748--
3749
3750To run the application:
3751
3752* Start the application:
3753+
3754--
3755[role="term"]
3756----
3757$ ./app
3758----
3759--
3760
3761|
3762The tracepoint provider package shared object is preloaded before the
3763application starts.
3764
3765The application dynamically loads the instrumented user library.
3766
3767image::ust-sit+tp-so-preloaded+app-dlopens-lib+lib-instrumented.png[]
3768
3769|
3770include::../common/ust-sit-step-tp-so.txt[]
3771
3772To build the instrumented user library:
3773
3774. In path:{emon.c}, before including path:{tpp.h}, add the
3775 following lines:
3776+
3777--
3778[source,c]
3779----
3780#define LTTNG_UST_TRACEPOINT_DEFINE
3781#define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE
3782----
3783--
3784
3785. Compile the user library source file:
3786+
3787--
3788[role="term"]
3789----
3790$ gcc -I. -fpic -c emon.c
3791----
3792--
3793
3794. Build the user library shared object:
3795+
3796--
3797[role="term"]
3798----
3799$ gcc -shared -o libemon.so emon.o -ldl
3800----
3801--
3802
3803To build the application:
3804
3805. Compile the application source file:
3806+
3807--
3808[role="term"]
3809----
3810$ gcc -c app.c
3811----
3812--
3813
3814. Build the application:
3815+
3816--
3817[role="term"]
3818----
3819$ gcc -o app app.o -L. -lemon
3820----
3821--
3822
3823To run the application with tracing support:
3824
3825* Preload the tracepoint provider package shared object and
3826 start the application:
3827+
3828--
3829[role="term"]
3830----
3831$ LD_PRELOAD=./libtpp.so ./app
3832----
3833--
3834
3835To run the application without tracing support:
3836
3837* Start the application:
3838+
3839--
3840[role="term"]
3841----
3842$ ./app
3843----
3844--
3845
3846|
3847The application is statically linked with the tracepoint provider
3848package object file.
3849
3850The application is linked with the instrumented user library.
3851
3852image::ust-sit+app-linked-with-tp-o+app-linked-with-lib+lib-instrumented.png[]
3853
3854|
3855include::../common/ust-sit-step-tp-o.txt[]
3856
3857To build the instrumented user library:
3858
3859. In path:{emon.c}, before including path:{tpp.h}, add the
3860 following line:
3861+
3862--
3863[source,c]
3864----
3865#define LTTNG_UST_TRACEPOINT_DEFINE
3866----
3867--
3868
3869. Compile the user library source file:
3870+
3871--
3872[role="term"]
3873----
3874$ gcc -I. -fpic -c emon.c
3875----
3876--
3877
3878. Build the user library shared object:
3879+
3880--
3881[role="term"]
3882----
3883$ gcc -shared -o libemon.so emon.o
3884----
3885--
3886
3887To build the application:
3888
3889. Compile the application source file:
3890+
3891--
3892[role="term"]
3893----
3894$ gcc -c app.c
3895----
3896--
3897
3898. Build the application:
3899+
3900--
3901[role="term"]
3902----
3903$ gcc -o app app.o tpp.o -llttng-ust -ldl -L. -lemon
3904----
3905--
3906
3907To run the instrumented application:
3908
3909* Start the application:
3910+
3911--
3912[role="term"]
3913----
3914$ ./app
3915----
3916--
3917
3918|
3919The application is statically linked with the tracepoint provider
3920package object file.
3921
3922The application dynamically loads the instrumented user library.
3923
3924image::ust-sit+app-linked-with-tp-o+app-dlopens-lib+lib-instrumented.png[]
3925
3926|
3927include::../common/ust-sit-step-tp-o.txt[]
3928
3929To build the application:
3930
3931. In path:{app.c}, before including path:{tpp.h}, add the following line:
3932+
3933--
3934[source,c]
3935----
3936#define LTTNG_UST_TRACEPOINT_DEFINE
3937----
3938--
3939
3940. Compile the application source file:
3941+
3942--
3943[role="term"]
3944----
3945$ gcc -c app.c
3946----
3947--
3948
3949. Build the application:
3950+
3951--
3952[role="term"]
3953----
3954$ gcc -Wl,--export-dynamic -o app app.o tpp.o \
3955 -llttng-ust -ldl
3956----
3957--
3958+
3959The `--export-dynamic` option passed to the linker is necessary for the
3960dynamically loaded library to ``see'' the tracepoint symbols defined in
3961the application.
3962
3963To build the instrumented user library:
3964
3965. Compile the user library source file:
3966+
3967--
3968[role="term"]
3969----
3970$ gcc -I. -fpic -c emon.c
3971----
3972--
3973
3974. Build the user library shared object:
3975+
3976--
3977[role="term"]
3978----
3979$ gcc -shared -o libemon.so emon.o
3980----
3981--
3982
3983To run the application:
3984
3985* Start the application:
3986+
3987--
3988[role="term"]
3989----
3990$ ./app
3991----
3992--
3993|====
3994
3995
3996[[using-lttng-ust-with-daemons]]
3997===== Use noch:{LTTng-UST} with daemons
3998
3999If your instrumented application calls man:fork(2), man:clone(2),
4000or BSD's man:rfork(2), without a following man:exec(3)-family
4001system call, you must preload the path:{liblttng-ust-fork.so} shared
4002object when you start the application.
4003
4004[role="term"]
4005----
4006$ LD_PRELOAD=liblttng-ust-fork.so ./my-app
4007----
4008
4009If your tracepoint provider package is
4010a shared library which you also preload, you must put both
4011shared objects in env:LD_PRELOAD:
4012
4013[role="term"]
4014----
4015$ LD_PRELOAD=liblttng-ust-fork.so:/path/to/tp.so ./my-app
4016----
4017
4018
4019[role="since-2.9"]
4020[[liblttng-ust-fd]]
4021===== Use noch:{LTTng-UST} with applications which close file descriptors that don't belong to them
4022
4023If your instrumented application closes one or more file descriptors
4024which it did not open itself, you must preload the
4025path:{liblttng-ust-fd.so} shared object when you start the application:
4026
4027[role="term"]
4028----
4029$ LD_PRELOAD=liblttng-ust-fd.so ./my-app
4030----
4031
4032Typical use cases include closing all the file descriptors after
4033man:fork(2) or man:rfork(2) and buggy applications doing
4034``double closes''.
4035
4036
4037[[lttng-ust-pkg-config]]
4038===== Use noch:{pkg-config}
4039
4040On some distributions, LTTng-UST ships with a
4041https://www.freedesktop.org/wiki/Software/pkg-config/[pkg-config]
4042metadata file. If this is your case, then use cmd:pkg-config to
4043build an application on the command line:
4044
4045[role="term"]
4046----
4047$ gcc -o my-app my-app.o tp.o $(pkg-config --cflags --libs lttng-ust)
4048----
4049
4050
4051[[instrumenting-32-bit-app-on-64-bit-system]]
4052===== [[advanced-instrumenting-techniques]]Build a 32-bit instrumented application for a 64-bit target system
4053
4054In order to trace a 32-bit application running on a 64-bit system,
4055LTTng must use a dedicated 32-bit
4056<<lttng-consumerd,consumer daemon>>.
4057
4058The following steps show how to build and install a 32-bit consumer
4059daemon, which is _not_ part of the default 64-bit LTTng build, how to
4060build and install the 32-bit LTTng-UST libraries, and how to build and
4061link an instrumented 32-bit application in that context.
4062
4063To build a 32-bit instrumented application for a 64-bit target system,
4064assuming you have a fresh target system with no installed Userspace RCU
4065or LTTng packages:
4066
4067. Download, build, and install a 32-bit version of Userspace RCU:
4068+
4069--
4070[role="term"]
4071----
4072$ cd $(mktemp -d) &&
4073 wget https://lttng.org/files/urcu/userspace-rcu-latest-0.13.tar.bz2 &&
4074 tar -xf userspace-rcu-latest-0.13.tar.bz2 &&
4075 cd userspace-rcu-0.13.* &&
4076 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 &&
4077 make &&
4078 sudo make install &&
4079 sudo ldconfig
4080----
4081--
4082
4083. Using the package manager of your distribution, or from source,
4084 install the 32-bit versions of the following dependencies of
4085 LTTng-tools and LTTng-UST:
4086+
4087--
4088* https://sourceforge.net/projects/libuuid/[libuuid]
4089* https://directory.fsf.org/wiki/Popt[popt]
4090* https://www.xmlsoft.org/[libxml2]
4091* **Optional**: https://github.com/numactl/numactl[numactl]
4092--
4093
4094. Download, build, and install a 32-bit version of the latest
4095 LTTng-UST{nbsp}{revision}:
4096+
4097--
4098[role="term"]
4099----
4100$ cd $(mktemp -d) &&
4101 wget https://lttng.org/files/lttng-ust/lttng-ust-latest-2.13.tar.bz2 &&
4102 tar -xf lttng-ust-latest-2.13.tar.bz2 &&
4103 cd lttng-ust-2.13.* &&
4104 ./configure --libdir=/usr/local/lib32 \
4105 CFLAGS=-m32 CXXFLAGS=-m32 \
4106 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' &&
4107 make &&
4108 sudo make install &&
4109 sudo ldconfig
4110----
4111--
4112+
4113Add `--disable-numa` to `./configure` if you don't have
4114https://github.com/numactl/numactl[numactl].
4115+
4116[NOTE]
4117====
4118Depending on your distribution, 32-bit libraries could be installed at a
4119different location than `/usr/lib32`. For example, Debian is known to
4120install some 32-bit libraries in `/usr/lib/i386-linux-gnu`.
4121
4122In this case, make sure to set `LDFLAGS` to all the
4123relevant 32-bit library paths, for example:
4124
4125[role="term"]
4126----
4127$ LDFLAGS='-L/usr/lib/i386-linux-gnu -L/usr/lib32'
4128----
4129====
4130
4131. Download the latest LTTng-tools{nbsp}{revision}, build, and install
4132 the 32-bit consumer daemon:
4133+
4134--
4135[role="term"]
4136----
4137$ cd $(mktemp -d) &&
4138 wget https://lttng.org/files/lttng-tools/lttng-tools-latest-2.13.tar.bz2 &&
4139 tar -xf lttng-tools-latest-2.13.tar.bz2 &&
4140 cd lttng-tools-2.13.* &&
4141 ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 CXXFLAGS=-m32 \
4142 LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' \
4143 --disable-bin-lttng --disable-bin-lttng-crash \
4144 --disable-bin-lttng-relayd --disable-bin-lttng-sessiond &&
4145 make &&
4146 cd src/bin/lttng-consumerd &&
4147 sudo make install &&
4148 sudo ldconfig
4149----
4150--
4151
4152. From your distribution or from source, <<installing-lttng,install>>
4153 the 64-bit versions of LTTng-UST and Userspace RCU.
4154
4155. Download, build, and install the 64-bit version of the
4156 latest LTTng-tools{nbsp}{revision}:
4157+
4158--
4159[role="term"]
4160----
4161$ cd $(mktemp -d) &&
4162 wget https://lttng.org/files/lttng-tools/lttng-tools-latest-2.13.tar.bz2 &&
4163 tar -xf lttng-tools-latest-2.13.tar.bz2 &&
4164 cd lttng-tools-2.13.* &&
4165 ./configure --with-consumerd32-libdir=/usr/local/lib32 \
4166 --with-consumerd32-bin=/usr/local/lib32/lttng/libexec/lttng-consumerd &&
4167 make &&
4168 sudo make install &&
4169 sudo ldconfig
4170----
4171--
4172
4173. Pass the following options to man:gcc(1), man:g++(1), or man:clang(1)
4174 when linking your 32-bit application:
4175+
4176----
4177-m32 -L/usr/lib32 -L/usr/local/lib32 \
4178-Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32
4179----
4180+
4181For example, let's rebuild the quick start example in
4182``<<tracing-your-own-user-application,Record user application events>>''
4183as an instrumented 32-bit application:
4184+
4185--
4186[role="term"]
4187----
4188$ gcc -m32 -c -I. hello-tp.c
4189$ gcc -m32 -c hello.c
4190$ gcc -m32 -o hello hello.o hello-tp.o \
4191 -L/usr/lib32 -L/usr/local/lib32 \
4192 -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32 \
4193 -llttng-ust -ldl
4194----
4195--
4196
4197No special action is required to execute the 32-bit application and
4198for LTTng to trace it: use the command-line man:lttng(1) tool as usual.
4199
4200
4201[role="since-2.5"]
4202[[tracef]]
4203==== Use `lttng_ust_tracef()`
4204
4205man:lttng_ust_tracef(3) is a small LTTng-UST API designed for quick,
4206man:printf(3)-like instrumentation without the burden of
4207<<tracepoint-provider,creating>> and
4208<<building-tracepoint-providers-and-user-application,building>>
4209a tracepoint provider package.
4210
4211To use `lttng_ust_tracef()` in your application:
4212
4213. In the C or $$C++$$ source files where you need to use
4214 `lttng_ust_tracef()`, include `<lttng/tracef.h>`:
4215+
4216--
4217[source,c]
4218----
4219#include <lttng/tracef.h>
4220----
4221--
4222
4223. In the source code of the application, use `lttng_ust_tracef()` like
4224 you would use man:printf(3):
4225+
4226--
4227[source,c]
4228----
4229 /* ... */
4230
4231 lttng_ust_tracef("my message: %d (%s)", my_integer, my_string);
4232
4233 /* ... */
4234----
4235--
4236
4237. Link your application with `liblttng-ust`:
4238+
4239--
4240[role="term"]
4241----
4242$ gcc -o app app.c -llttng-ust
4243----
4244--
4245
4246To record the events that `lttng_ust_tracef()` calls emit:
4247
4248* <<enabling-disabling-events,Create a recording event rule>> which
4249 matches user space events named `lttng_ust_tracef:*`:
4250+
4251--
4252[role="term"]
4253----
4254$ lttng enable-event --userspace 'lttng_ust_tracef:*'
4255----
4256--
4257
4258[IMPORTANT]
4259.Limitations of `lttng_ust_tracef()`
4260====
4261The `lttng_ust_tracef()` utility function was developed to make user
4262space tracing super simple, albeit with notable disadvantages compared
4263to <<defining-tracepoints,user-defined tracepoints>>:
4264
4265* All the created events have the same tracepoint provider and
4266 tracepoint names, respectively `lttng_ust_tracef` and `event`.
4267* There's no static type checking.
4268* The only event record field you actually get, named `msg`, is a string
4269 potentially containing the values you passed to `lttng_ust_tracef()`
4270 using your own format string. This also means that you can't filter
4271 events with a custom expression at run time because there are no
4272 isolated fields.
4273* Since `lttng_ust_tracef()` uses the man:vasprintf(3) function of the
4274 C{nbsp}standard library behind the scenes to format the strings at run
4275 time, its expected performance is lower than with user-defined
4276 tracepoints, which don't require a conversion to a string.
4277
4278Taking this into consideration, `lttng_ust_tracef()` is useful for some
4279quick prototyping and debugging, but you shouldn't consider it for any
4280permanent and serious applicative instrumentation.
4281====
4282
4283
4284[role="since-2.7"]
4285[[tracelog]]
4286==== Use `lttng_ust_tracelog()`
4287
4288The man:tracelog(3) API is very similar to
4289<<tracef,`lttng_ust_tracef()`>>, with the difference that it accepts an
4290additional log level parameter.
4291
4292The goal of `lttng_ust_tracelog()` is to ease the migration from logging
4293to tracing.
4294
4295To use `lttng_ust_tracelog()` in your application:
4296
4297. In the C or $$C++$$ source files where you need to use `tracelog()`,
4298 include `<lttng/tracelog.h>`:
4299+
4300--
4301[source,c]
4302----
4303#include <lttng/tracelog.h>
4304----
4305--
4306
4307. In the source code of the application, use `lttng_ust_tracelog()` like
4308 you would use man:printf(3), except for the first parameter which is
4309 the log level:
4310+
4311--
4312[source,c]
4313----
4314 /* ... */
4315
4316 tracelog(LTTNG_UST_TRACEPOINT_LOGLEVEL_WARNING,
4317 "my message: %d (%s)", my_integer, my_string);
4318
4319 /* ... */
4320----
4321--
4322+
4323See man:lttng-ust(3) for a list of available log level names.
4324
4325. Link your application with `liblttng-ust`:
4326+
4327--
4328[role="term"]
4329----
4330$ gcc -o app app.c -llttng-ust
4331----
4332--
4333
4334To record the events that `lttng_ust_tracelog()` calls emit with a log
4335level _at least as severe as_ a specific log level:
4336
4337* <<enabling-disabling-events,Create a recording event rule>> which
4338 matches user space tracepoint events named `lttng_ust_tracelog:*` and
4339 with some minimum level of severity:
4340+
4341--
4342[role="term"]
4343----
4344$ lttng enable-event --userspace 'lttng_ust_tracelog:*' \
4345 --loglevel=WARNING
4346----
4347--
4348
4349To record the events that `lttng_ust_tracelog()` calls emit with a
4350_specific log level_:
4351
4352* Create a recording event rule which matches tracepoint events named
4353 `lttng_ust_tracelog:*` and with a specific log level:
4354+
4355--
4356[role="term"]
4357----
4358$ lttng enable-event --userspace 'lttng_ust_tracelog:*' \
4359 --loglevel-only=INFO
4360----
4361--
4362
4363
4364[[prebuilt-ust-helpers]]
4365=== Load a prebuilt user space tracing helper
4366
4367The LTTng-UST package provides a few helpers in the form of preloadable
4368shared objects which automatically instrument system functions and
4369calls.
4370
4371The helper shared objects are normally found in dir:{/usr/lib}. If you
4372built LTTng-UST <<building-from-source,from source>>, they're probably
4373located in dir:{/usr/local/lib}.
4374
4375The installed user space tracing helpers in LTTng-UST{nbsp}{revision}
4376are:
4377
4378path:{liblttng-ust-libc-wrapper.so}::
4379path:{liblttng-ust-pthread-wrapper.so}::
4380 <<liblttng-ust-libc-pthread-wrapper,C{nbsp}standard library
4381 memory and POSIX threads function tracing>>.
4382
4383path:{liblttng-ust-cyg-profile.so}::
4384path:{liblttng-ust-cyg-profile-fast.so}::
4385 <<liblttng-ust-cyg-profile,Function entry and exit tracing>>.
4386
4387path:{liblttng-ust-dl.so}::
4388 <<liblttng-ust-dl,Dynamic linker tracing>>.
4389
4390To use a user space tracing helper with any user application:
4391
4392* Preload the helper shared object when you start the application:
4393+
4394--
4395[role="term"]
4396----
4397$ LD_PRELOAD=liblttng-ust-libc-wrapper.so my-app
4398----
4399--
4400+
4401You can preload more than one helper:
4402+
4403--
4404[role="term"]
4405----
4406$ LD_PRELOAD=liblttng-ust-libc-wrapper.so:liblttng-ust-dl.so my-app
4407----
4408--
4409
4410
4411[role="since-2.3"]
4412[[liblttng-ust-libc-pthread-wrapper]]
4413==== Instrument C standard library memory and POSIX threads functions
4414
4415The path:{liblttng-ust-libc-wrapper.so} and
4416path:{liblttng-ust-pthread-wrapper.so} helpers
4417add instrumentation to some C standard library and POSIX
4418threads functions.
4419
4420[role="growable"]
4421.Functions instrumented by preloading path:{liblttng-ust-libc-wrapper.so}.
4422|====
4423|TP provider name |TP name |Instrumented function
4424
4425.6+|`lttng_ust_libc` |`malloc` |man:malloc(3)
4426 |`calloc` |man:calloc(3)
4427 |`realloc` |man:realloc(3)
4428 |`free` |man:free(3)
4429 |`memalign` |man:memalign(3)
4430 |`posix_memalign` |man:posix_memalign(3)
4431|====
4432
4433[role="growable"]
4434.Functions instrumented by preloading path:{liblttng-ust-pthread-wrapper.so}.
4435|====
4436|TP provider name |TP name |Instrumented function
4437
4438.4+|`lttng_ust_pthread` |`pthread_mutex_lock_req` |man:pthread_mutex_lock(3p) (request time)
4439 |`pthread_mutex_lock_acq` |man:pthread_mutex_lock(3p) (acquire time)
4440 |`pthread_mutex_trylock` |man:pthread_mutex_trylock(3p)
4441 |`pthread_mutex_unlock` |man:pthread_mutex_unlock(3p)
4442|====
4443
4444When you preload the shared object, it replaces the functions listed
4445in the previous tables by wrappers which contain tracepoints and call
4446the replaced functions.
4447
4448
4449[[liblttng-ust-cyg-profile]]
4450==== Instrument function entry and exit
4451
4452The path:{liblttng-ust-cyg-profile*.so} helpers can add instrumentation
4453to the entry and exit points of functions.
4454
4455man:gcc(1) and man:clang(1) have an option named
4456https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html[`-finstrument-functions`]
4457which generates instrumentation calls for entry and exit to functions.
4458The LTTng-UST function tracing helpers,
4459path:{liblttng-ust-cyg-profile.so} and
4460path:{liblttng-ust-cyg-profile-fast.so}, take advantage of this feature
4461to add tracepoints to the two generated functions (which contain
4462`cyg_profile` in their names, hence the name of the helper).
4463
4464To use the LTTng-UST function tracing helper, the source files to
4465instrument must be built using the `-finstrument-functions` compiler
4466flag.
4467
4468There are two versions of the LTTng-UST function tracing helper:
4469
4470* **path:{liblttng-ust-cyg-profile-fast.so}** is a lightweight variant
4471 that you should only use when it can be _guaranteed_ that the
4472 complete event stream is recorded without any lost event record.
4473 Any kind of duplicate information is left out.
4474+
4475Assuming no event record is lost, having only the function addresses on
4476entry is enough to create a call graph, since an event record always
4477contains the ID of the CPU that generated it.
4478+
4479Use a tool like man:addr2line(1) to convert function addresses back to
4480source file names and line numbers.
4481
4482* **path:{liblttng-ust-cyg-profile.so}** is a more robust variant
4483which also works in use cases where event records might get discarded or
4484not recorded from application startup.
4485In these cases, the trace analyzer needs more information to be
4486able to reconstruct the program flow.
4487
4488See man:lttng-ust-cyg-profile(3) to learn more about the instrumentation
4489points of this helper.
4490
4491All the tracepoints that this helper provides have the log level
4492`LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_FUNCTION` (see man:lttng-ust(3)).
4493
4494TIP: It's sometimes a good idea to limit the number of source files that
4495you compile with the `-finstrument-functions` option to prevent LTTng
4496from writing an excessive amount of trace data at run time. When using
4497man:gcc(1), use the
4498`-finstrument-functions-exclude-function-list` option to avoid
4499instrument entries and exits of specific function names.
4500
4501
4502[role="since-2.4"]
4503[[liblttng-ust-dl]]
4504==== Instrument the dynamic linker
4505
4506The path:{liblttng-ust-dl.so} helper adds instrumentation to the
4507man:dlopen(3) and man:dlclose(3) function calls.
4508
4509See man:lttng-ust-dl(3) to learn more about the instrumentation points
4510of this helper.
4511
4512
4513[role="since-2.4"]
4514[[java-application]]
4515=== Instrument a Java application
4516
4517You can instrument any Java application which uses one of the following
4518logging frameworks:
4519
4520* The https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[**`java.util.logging`**]
4521 (JUL) core logging facilities.
4522
4523* https://logging.apache.org/log4j/1.2/[**Apache log4j{nbsp}1.2**], since
4524 LTTng{nbsp}2.6. Note that Apache Log4j{nbsp}2 isn't supported.
4525
4526[role="img-100"]
4527.LTTng-UST Java agent imported by a Java application.
4528image::java-app.png[]
4529
4530Note that the methods described below are new in LTTng{nbsp}2.8.
4531Previous LTTng versions use another technique.
4532
4533NOTE: We use https://openjdk.java.net/[OpenJDK]{nbsp}8 for development
4534and https://ci.lttng.org/[continuous integration], thus this version is
4535directly supported. However, the LTTng-UST Java agent is also tested
4536with OpenJDK{nbsp}7.
4537
4538
4539[role="since-2.8"]
4540[[jul]]
4541==== Use the LTTng-UST Java agent for `java.util.logging`
4542
4543To use the LTTng-UST Java agent in a Java application which uses
4544`java.util.logging` (JUL):
4545
4546. In the source code of the Java application, import the LTTng-UST log
4547 handler package for `java.util.logging`:
4548+
4549--
4550[source,java]
4551----
4552import org.lttng.ust.agent.jul.LttngLogHandler;
4553----
4554--
4555
4556. Create an LTTng-UST `java.util.logging` log handler:
4557+
4558--
4559[source,java]
4560----
4561Handler lttngUstLogHandler = new LttngLogHandler();
4562----
4563--
4564
4565. Add this handler to the `java.util.logging` loggers which should emit
4566 LTTng events:
4567+
4568--
4569[source,java]
4570----
4571Logger myLogger = Logger.getLogger("some-logger");
4572
4573myLogger.addHandler(lttngUstLogHandler);
4574----
4575--
4576
4577. Use `java.util.logging` log statements and configuration as usual.
4578 The loggers with an attached LTTng-UST log handler can emit
4579 LTTng events.
4580
4581. Before exiting the application, remove the LTTng-UST log handler from
4582 the loggers attached to it and call its `close()` method:
4583+
4584--
4585[source,java]
4586----
4587myLogger.removeHandler(lttngUstLogHandler);
4588lttngUstLogHandler.close();
4589----
4590--
4591+
4592This isn't strictly necessary, but it's recommended for a clean
4593disposal of the resources of the handler.
4594
4595. Include the common and JUL-specific JAR files of the LTTng-UST Java agent,
4596 path:{lttng-ust-agent-common.jar} and path:{lttng-ust-agent-jul.jar},
4597 in the
4598 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4599 path] when you build the Java application.
4600+
4601The JAR files are typically located in dir:{/usr/share/java}.
4602+
4603IMPORTANT: The LTTng-UST Java agent must be
4604<<installing-lttng,installed>> for the logging framework your
4605application uses.
4606
4607.Use the LTTng-UST Java agent for `java.util.logging`.
4608====
4609[source,java]
4610.path:{Test.java}
4611----
4612import java.io.IOException;
4613import java.util.logging.Handler;
4614import java.util.logging.Logger;
4615import org.lttng.ust.agent.jul.LttngLogHandler;
4616
4617public class Test
4618{
4619 private static final int answer = 42;
4620
4621 public static void main(String[] argv) throws Exception
4622 {
4623 // Create a logger
4624 Logger logger = Logger.getLogger("jello");
4625
4626 // Create an LTTng-UST log handler
4627 Handler lttngUstLogHandler = new LttngLogHandler();
4628
4629 // Add the LTTng-UST log handler to our logger
4630 logger.addHandler(lttngUstLogHandler);
4631
4632 // Log at will!
4633 logger.info("some info");
4634 logger.warning("some warning");
4635 Thread.sleep(500);
4636 logger.finer("finer information; the answer is " + answer);
4637 Thread.sleep(123);
4638 logger.severe("error!");
4639
4640 // Not mandatory, but cleaner
4641 logger.removeHandler(lttngUstLogHandler);
4642 lttngUstLogHandler.close();
4643 }
4644}
4645----
4646
4647Build this example:
4648
4649[role="term"]
4650----
4651$ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
4652----
4653
4654<<creating-destroying-tracing-sessions,Create a recording session>>,
4655<<enabling-disabling-events,create a recording event rule>> matching JUL
4656events named `jello`, and <<basic-tracing-session-control,start
4657recording>>:
4658
4659[role="term"]
4660----
4661$ lttng create
4662$ lttng enable-event --jul jello
4663$ lttng start
4664----
4665
4666Run the compiled class:
4667
4668[role="term"]
4669----
4670$ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
4671----
4672
4673<<basic-tracing-session-control,Stop recording>> and inspect the
4674recorded events:
4675
4676[role="term"]
4677----
4678$ lttng stop
4679$ lttng view
4680----
4681====
4682
4683In the resulting trace, an <<event,event record>> which a Java
4684application using `java.util.logging` generated is named
4685`lttng_jul:event` and has the following fields:
4686
4687`msg`::
4688 Log record message.
4689
4690`logger_name`::
4691 Logger name.
4692
4693`class_name`::
4694 Name of the class in which the log statement was executed.
4695
4696`method_name`::
4697 Name of the method in which the log statement was executed.
4698
4699`long_millis`::
4700 Logging time (timestamp in milliseconds).
4701
4702`int_loglevel`::
4703 Log level integer value.
4704
4705`int_threadid`::
4706 ID of the thread in which the log statement was executed.
4707
4708Use the opt:lttng-enable-event(1):--loglevel or
4709opt:lttng-enable-event(1):--loglevel-only option of the
4710man:lttng-enable-event(1) command to target a range of
4711`java.util.logging` log levels or a specific `java.util.logging` log
4712level.
4713
4714
4715[role="since-2.8"]
4716[[log4j]]
4717==== Use the LTTng-UST Java agent for Apache log4j
4718
4719To use the LTTng-UST Java agent in a Java application which uses
4720Apache log4j{nbsp}1.2:
4721
4722. In the source code of the Java application, import the LTTng-UST log
4723 appender package for Apache log4j:
4724+
4725--
4726[source,java]
4727----
4728import org.lttng.ust.agent.log4j.LttngLogAppender;
4729----
4730--
4731
4732. Create an LTTng-UST log4j log appender:
4733+
4734--
4735[source,java]
4736----
4737Appender lttngUstLogAppender = new LttngLogAppender();
4738----
4739--
4740
4741. Add this appender to the log4j loggers which should emit LTTng events:
4742+
4743--
4744[source,java]
4745----
4746Logger myLogger = Logger.getLogger("some-logger");
4747
4748myLogger.addAppender(lttngUstLogAppender);
4749----
4750--
4751
4752. Use Apache log4j log statements and configuration as usual. The
4753 loggers with an attached LTTng-UST log appender can emit LTTng events.
4754
4755. Before exiting the application, remove the LTTng-UST log appender from
4756 the loggers attached to it and call its `close()` method:
4757+
4758--
4759[source,java]
4760----
4761myLogger.removeAppender(lttngUstLogAppender);
4762lttngUstLogAppender.close();
4763----
4764--
4765+
4766This isn't strictly necessary, but it's recommended for a clean
4767disposal of the resources of the appender.
4768
4769. Include the common and log4j-specific JAR
4770 files of the LTTng-UST Java agent, path:{lttng-ust-agent-common.jar} and
4771 path:{lttng-ust-agent-log4j.jar}, in the
4772 https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class
4773 path] when you build the Java application.
4774+
4775The JAR files are typically located in dir:{/usr/share/java}.
4776+
4777IMPORTANT: The LTTng-UST Java agent must be
4778<<installing-lttng,installed>> for the logging framework your
4779application uses.
4780
4781.Use the LTTng-UST Java agent for Apache log4j.
4782====
4783[source,java]
4784.path:{Test.java}
4785----
4786import org.apache.log4j.Appender;
4787import org.apache.log4j.Logger;
4788import org.lttng.ust.agent.log4j.LttngLogAppender;
4789
4790public class Test
4791{
4792 private static final int answer = 42;
4793
4794 public static void main(String[] argv) throws Exception
4795 {
4796 // Create a logger
4797 Logger logger = Logger.getLogger("jello");
4798
4799 // Create an LTTng-UST log appender
4800 Appender lttngUstLogAppender = new LttngLogAppender();
4801
4802 // Add the LTTng-UST log appender to our logger
4803 logger.addAppender(lttngUstLogAppender);
4804
4805 // Log at will!
4806 logger.info("some info");
4807 logger.warn("some warning");
4808 Thread.sleep(500);
4809 logger.debug("debug information; the answer is " + answer);
4810 Thread.sleep(123);
4811 logger.fatal("error!");
4812
4813 // Not mandatory, but cleaner
4814 logger.removeAppender(lttngUstLogAppender);
4815 lttngUstLogAppender.close();
4816 }
4817}
4818
4819----
4820
4821Build this example (`$LOG4JPATH` is the path to the Apache log4j JAR
4822file):
4823
4824[role="term"]
4825----
4826$ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH Test.java
4827----
4828
4829<<creating-destroying-tracing-sessions,Create a recording session>>,
4830<<enabling-disabling-events,create a recording event rule>> matching
4831log4j events named `jello`, and <<basic-tracing-session-control,start
4832recording>>:
4833
4834[role="term"]
4835----
4836$ lttng create
4837$ lttng enable-event --log4j jello
4838$ lttng start
4839----
4840
4841Run the compiled class:
4842
4843[role="term"]
4844----
4845$ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH:. Test
4846----
4847
4848<<basic-tracing-session-control,Stop recording>> and inspect the
4849recorded events:
4850
4851[role="term"]
4852----
4853$ lttng stop
4854$ lttng view
4855----
4856====
4857
4858In the resulting trace, an <<event,event record>> which a Java
4859application using log4j generated is named `lttng_log4j:event` and
4860has the following fields:
4861
4862`msg`::
4863 Log record message.
4864
4865`logger_name`::
4866 Logger name.
4867
4868`class_name`::
4869 Name of the class in which the log statement was executed.
4870
4871`method_name`::
4872 Name of the method in which the log statement was executed.
4873
4874`filename`::
4875 Name of the file in which the executed log statement is located.
4876
4877`line_number`::
4878 Line number at which the log statement was executed.
4879
4880`timestamp`::
4881 Logging timestamp.
4882
4883`int_loglevel`::
4884 Log level integer value.
4885
4886`thread_name`::
4887 Name of the Java thread in which the log statement was executed.
4888
4889Use the opt:lttng-enable-event(1):--loglevel or
4890opt:lttng-enable-event(1):--loglevel-only option of the
4891man:lttng-enable-event(1) command to target a range of Apache log4j
4892log levels or a specific log4j log level.
4893
4894
4895[role="since-2.8"]
4896[[java-application-context]]
4897==== Provide application-specific context fields in a Java application
4898
4899A Java application-specific context field is a piece of state which
4900the Java application provides. You can <<adding-context,add>> such
4901a context field to be recorded, using the
4902man:lttng-add-context(1) command, to each <<event,event record>>
4903which the log statements of this application produce.
4904
4905For example, a given object might have a current request ID variable.
4906You can create a context information retriever for this object and
4907assign a name to this current request ID. You can then, using the
4908man:lttng-add-context(1) command, add this context field by name so that
4909LTTng writes it to the event records of a given `java.util.logging` or
4910log4j <<channel,channel>>.
4911
4912To provide application-specific context fields in a Java application:
4913
4914. In the source code of the Java application, import the LTTng-UST
4915 Java agent context classes and interfaces:
4916+
4917--
4918[source,java]
4919----
4920import org.lttng.ust.agent.context.ContextInfoManager;
4921import org.lttng.ust.agent.context.IContextInfoRetriever;
4922----
4923--
4924
4925. Create a context information retriever class, that is, a class which
4926 implements the `IContextInfoRetriever` interface:
4927+
4928--
4929[source,java]
4930----
4931class MyContextInfoRetriever implements IContextInfoRetriever
4932{
4933 @Override
4934 public Object retrieveContextInfo(String key)
4935 {
4936 if (key.equals("intCtx")) {
4937 return (short) 17;
4938 } else if (key.equals("strContext")) {
4939 return "context value!";
4940 } else {
4941 return null;
4942 }
4943 }
4944}
4945----
4946--
4947+
4948This `retrieveContextInfo()` method is the only member of the
4949`IContextInfoRetriever` interface. Its role is to return the current
4950value of a state by name to create a context field. The names of the
4951context fields and which state variables they return depends on your
4952specific scenario.
4953+
4954All primitive types and objects are supported as context fields.
4955When `retrieveContextInfo()` returns an object, the context field
4956serializer calls its `toString()` method to add a string field to
4957event records. The method can also return `null`, which means that
4958no context field is available for the required name.
4959
4960. Register an instance of your context information retriever class to
4961 the context information manager singleton:
4962+
4963--
4964[source,java]
4965----
4966IContextInfoRetriever cir = new MyContextInfoRetriever();
4967ContextInfoManager cim = ContextInfoManager.getInstance();
4968cim.registerContextInfoRetriever("retrieverName", cir);
4969----
4970--
4971
4972. Before exiting the application, remove your context information
4973 retriever from the context information manager singleton:
4974+
4975--
4976[source,java]
4977----
4978ContextInfoManager cim = ContextInfoManager.getInstance();
4979cim.unregisterContextInfoRetriever("retrieverName");
4980----
4981--
4982+
4983This isn't strictly necessary, but it's recommended for a clean
4984disposal of some resources of the manager.
4985
4986. Build your Java application with LTTng-UST Java agent support as
4987 usual, following the procedure for either the
4988 <<jul,`java.util.logging`>> or <<log4j,Apache log4j>> framework.
4989
4990.Provide application-specific context fields in a Java application.
4991====
4992[source,java]
4993.path:{Test.java}
4994----
4995import java.util.logging.Handler;
4996import java.util.logging.Logger;
4997import org.lttng.ust.agent.jul.LttngLogHandler;
4998import org.lttng.ust.agent.context.ContextInfoManager;
4999import org.lttng.ust.agent.context.IContextInfoRetriever;
5000
5001public class Test
5002{
5003 // Our context information retriever class
5004 private static class MyContextInfoRetriever
5005 implements IContextInfoRetriever
5006 {
5007 @Override
5008 public Object retrieveContextInfo(String key) {
5009 if (key.equals("intCtx")) {
5010 return (short) 17;
5011 } else if (key.equals("strContext")) {
5012 return "context value!";
5013 } else {
5014 return null;
5015 }
5016 }
5017 }
5018
5019 private static final int answer = 42;
5020
5021 public static void main(String args[]) throws Exception
5022 {
5023 // Get the context information manager instance
5024 ContextInfoManager cim = ContextInfoManager.getInstance();
5025
5026 // Create and register our context information retriever
5027 IContextInfoRetriever cir = new MyContextInfoRetriever();
5028 cim.registerContextInfoRetriever("myRetriever", cir);
5029
5030 // Create a logger
5031 Logger logger = Logger.getLogger("jello");
5032
5033 // Create an LTTng-UST log handler
5034 Handler lttngUstLogHandler = new LttngLogHandler();
5035
5036 // Add the LTTng-UST log handler to our logger
5037 logger.addHandler(lttngUstLogHandler);
5038
5039 // Log at will!
5040 logger.info("some info");
5041 logger.warning("some warning");
5042 Thread.sleep(500);
5043 logger.finer("finer information; the answer is " + answer);
5044 Thread.sleep(123);
5045 logger.severe("error!");
5046
5047 // Not mandatory, but cleaner
5048 logger.removeHandler(lttngUstLogHandler);
5049 lttngUstLogHandler.close();
5050 cim.unregisterContextInfoRetriever("myRetriever");
5051 }
5052}
5053----
5054
5055Build this example:
5056
5057[role="term"]
5058----
5059$ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java
5060----
5061
5062<<creating-destroying-tracing-sessions,Create a recording session>> and
5063<<enabling-disabling-events,create a recording event rule>> matching
5064`java.util.logging` events named `jello`:
5065
5066[role="term"]
5067----
5068$ lttng create
5069$ lttng enable-event --jul jello
5070----
5071
5072<<adding-context,Add the application-specific context fields>> to be
5073recorded to the event records of the `java.util.logging` channel:
5074
5075[role="term"]
5076----
5077$ lttng add-context --jul --type='$app.myRetriever:intCtx'
5078$ lttng add-context --jul --type='$app.myRetriever:strContext'
5079----
5080
5081<<basic-tracing-session-control,Start recording>>:
5082
5083[role="term"]
5084----
5085$ lttng start
5086----
5087
5088Run the compiled class:
5089
5090[role="term"]
5091----
5092$ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test
5093----
5094
5095<<basic-tracing-session-control,Stop recording>> and inspect the
5096recorded events:
5097
5098[role="term"]
5099----
5100$ lttng stop
5101$ lttng view
5102----
5103====
5104
5105
5106[role="since-2.7"]
5107[[python-application]]
5108=== Instrument a Python application
5109
5110You can instrument a Python{nbsp}2 or Python{nbsp}3 application which
5111uses the standard
5112https://docs.python.org/3/library/logging.html[`logging`] package.
5113
5114Each log statement creates an LTTng event once the application module
5115imports the <<lttng-ust-agents,LTTng-UST Python agent>> package.
5116
5117[role="img-100"]
5118.A Python application importing the LTTng-UST Python agent.
5119image::python-app.png[]
5120
5121To use the LTTng-UST Python agent:
5122
5123. In the source code of the Python application, import the LTTng-UST
5124 Python agent:
5125+
5126--
5127[source,python]
5128----
5129import lttngust
5130----
5131--
5132+
5133The LTTng-UST Python agent automatically adds its logging handler to the
5134root logger at import time.
5135+
5136A log statement that the application executes before this import doesn't
5137create an LTTng event.
5138+
5139IMPORTANT: The LTTng-UST Python agent must be
5140<<installing-lttng,installed>>.
5141
5142. Use log statements and logging configuration as usual.
5143 Since the LTTng-UST Python agent adds a handler to the _root_
5144 logger, any log statement from any logger can emit an LTTng event.
5145
5146.Use the LTTng-UST Python agent.
5147====
5148[source,python]
5149.path:{test.py}
5150----
5151import lttngust
5152import logging
5153import time
5154
5155
5156def example():
5157 logging.basicConfig()
5158 logger = logging.getLogger('my-logger')
5159
5160 while True:
5161 logger.debug('debug message')
5162 logger.info('info message')
5163 logger.warn('warn message')
5164 logger.error('error message')
5165 logger.critical('critical message')
5166 time.sleep(1)
5167
5168
5169if __name__ == '__main__':
5170 example()
5171----
5172
5173NOTE: `logging.basicConfig()`, which adds to the root logger a basic
5174logging handler which prints to the standard error stream, isn't
5175strictly required for LTTng-UST tracing to work, but in versions of
5176Python preceding{nbsp}3.2, you could see a warning message which
5177indicates that no handler exists for the logger `my-logger`.
5178
5179<<creating-destroying-tracing-sessions,Create a recording session>>,
5180<<enabling-disabling-events,create a recording event rule>> matching
5181Python logging events named `my-logger`, and
5182<<basic-tracing-session-control,start recording>>:
5183
5184[role="term"]
5185----
5186$ lttng create
5187$ lttng enable-event --python my-logger
5188$ lttng start
5189----
5190
5191Run the Python script:
5192
5193[role="term"]
5194----
5195$ python test.py
5196----
5197
5198<<basic-tracing-session-control,Stop recording>> and inspect the
5199recorded events:
5200
5201[role="term"]
5202----
5203$ lttng stop
5204$ lttng view
5205----
5206====
5207
5208In the resulting trace, an <<event,event record>> which a Python
5209application generated is named `lttng_python:event` and has the
5210following fields:
5211
5212`asctime`::
5213 Logging time (string).
5214
5215`msg`::
5216 Log record message.
5217
5218`logger_name`::
5219 Logger name.
5220
5221`funcName`::
5222 Name of the function in which the log statement was executed.
5223
5224`lineno`::
5225 Line number at which the log statement was executed.
5226
5227`int_loglevel`::
5228 Log level integer value.
5229
5230`thread`::
5231 ID of the Python thread in which the log statement was executed.
5232
5233`threadName`::
5234 Name of the Python thread in which the log statement was executed.
5235
5236Use the opt:lttng-enable-event(1):--loglevel or
5237opt:lttng-enable-event(1):--loglevel-only option of the
5238man:lttng-enable-event(1) command to target a range of Python log levels
5239or a specific Python log level.
5240
5241When an application imports the LTTng-UST Python agent, the agent tries
5242to register to a <<lttng-sessiond,session daemon>>. Note that you must
5243<<start-sessiond,start the session daemon>> _before_ you run the Python
5244application. If a session daemon is found, the agent tries to register
5245to it during five seconds, after which the application continues
5246without LTTng tracing support. Override this timeout value with
5247the env:LTTNG_UST_PYTHON_REGISTER_TIMEOUT environment variable
5248(milliseconds).
5249
5250If the session daemon stops while a Python application with an imported
5251LTTng-UST Python agent runs, the agent retries to connect and to
5252register to a session daemon every three seconds. Override this
5253delay with the env:LTTNG_UST_PYTHON_REGISTER_RETRY_DELAY environment
5254variable.
5255
5256
5257[role="since-2.5"]
5258[[proc-lttng-logger-abi]]
5259=== Use the LTTng logger
5260
5261The `lttng-tracer` Linux kernel module, part of
5262<<lttng-modules,LTTng-modules>>, creates the special LTTng logger files
5263path:{/proc/lttng-logger} and path:{/dev/lttng-logger} (since
5264LTTng{nbsp}2.11) when it's loaded. Any application can write text data
5265to any of those files to create one or more LTTng events.
5266
5267[role="img-100"]
5268.An application writes to the LTTng logger file to create one or more LTTng events.
5269image::lttng-logger.png[]
5270
5271The LTTng logger is the quickest method--not the most efficient,
5272however--to add instrumentation to an application. It's designed
5273mostly to instrument shell scripts:
5274
5275[role="term"]
5276----
5277$ echo "Some message, some $variable" > /dev/lttng-logger
5278----
5279
5280Any event that the LTTng logger creates is named `lttng_logger` and
5281belongs to the Linux kernel <<domain,tracing domain>>. However, unlike
5282other instrumentation points in the kernel tracing domain, **any Unix
5283user** can <<enabling-disabling-events,create a recording event rule>>
5284which matches events named `lttng_logger`, not only the root user or
5285users in the <<tracing-group,tracing group>>.
5286
5287To use the LTTng logger:
5288
5289* From any application, write text data to the path:{/dev/lttng-logger}
5290 file.
5291
5292The `msg` field of `lttng_logger` event records contains the
5293recorded message.
5294
5295NOTE: The maximum message length of an LTTng logger event is
52961024{nbsp}bytes. Writing more than this makes the LTTng logger emit more
5297than one event to contain the remaining data.
5298
5299You shouldn't use the LTTng logger to trace a user application which you
5300can instrument in a more efficient way, namely:
5301
5302* <<c-application,C and $$C++$$ applications>>.
5303* <<java-application,Java applications>>.
5304* <<python-application,Python applications>>.
5305
5306.Use the LTTng logger.
5307====
5308[source,bash]
5309.path:{test.bash}
5310----
5311echo 'Hello, World!' > /dev/lttng-logger
5312sleep 2
5313df --human-readable --print-type / > /dev/lttng-logger
5314----
5315
5316<<creating-destroying-tracing-sessions,Create a recording session>>,
5317<<enabling-disabling-events,create a recording event rule>> matching
5318Linux kernel tracepoint events named `lttng_logger`, and
5319<<basic-tracing-session-control,start recording>>:
5320
5321[role="term"]
5322----
5323$ lttng create
5324$ lttng enable-event --kernel lttng_logger
5325$ lttng start
5326----
5327
5328Run the Bash script:
5329
5330[role="term"]
5331----
5332$ bash test.bash
5333----
5334
5335<<basic-tracing-session-control,Stop recording>> and inspect the recorded
5336events:
5337
5338[role="term"]
5339----
5340$ lttng stop
5341$ lttng view
5342----
5343====
5344
5345
5346[[instrumenting-linux-kernel]]
5347=== Instrument a Linux kernel image or module
5348
5349NOTE: This section shows how to _add_ instrumentation points to the
5350Linux kernel. The subsystems of the kernel are already thoroughly
5351instrumented at strategic points for LTTng when you
5352<<installing-lttng,install>> the <<lttng-modules,LTTng-modules>>
5353package.
5354
5355
5356[[linux-add-lttng-layer]]
5357==== [[instrumenting-linux-kernel-itself]][[mainline-trace-event]][[lttng-adaptation-layer]]Add an LTTng layer to an existing ftrace tracepoint
5358
5359This section shows how to add an LTTng layer to existing ftrace
5360instrumentation using the `TRACE_EVENT()` API.
5361
5362This section doesn't document the `TRACE_EVENT()` macro. Read the
5363following articles to learn more about this API:
5364
5365* https://lwn.net/Articles/379903/[Using the TRACE_EVENT() macro (Part{nbsp}1)]
5366* https://lwn.net/Articles/381064/[Using the TRACE_EVENT() macro (Part{nbsp}2)]
5367* https://lwn.net/Articles/383362/[Using the TRACE_EVENT() macro (Part{nbsp}3)]
5368
5369The following procedure assumes that your ftrace tracepoints are
5370correctly defined in their own header and that they're created in
5371one source file using the `CREATE_TRACE_POINTS` definition.
5372
5373To add an LTTng layer over an existing ftrace tracepoint:
5374
5375. Make sure the following kernel configuration options are
5376 enabled:
5377+
5378--
5379* `CONFIG_MODULES`
5380* `CONFIG_KALLSYMS`
5381* `CONFIG_HIGH_RES_TIMERS`
5382* `CONFIG_TRACEPOINTS`
5383--
5384
5385. Build the Linux source tree with your custom ftrace tracepoints.
5386. Boot the resulting Linux image on your target system.
5387+
5388Confirm that the tracepoints exist by looking for their names in the
5389dir:{/sys/kernel/debug/tracing/events/subsys} directory, where `subsys`
5390is your subsystem name.
5391
5392. Get a copy of the latest LTTng-modules{nbsp}{revision}:
5393+
5394--
5395[role="term"]
5396----
5397$ cd $(mktemp -d) &&
5398 wget https://lttng.org/files/lttng-modules/lttng-modules-latest-2.13.tar.bz2 &&
5399 tar -xf lttng-modules-latest-2.13.tar.bz2 &&
5400 cd lttng-modules-2.13.*
5401----
5402--
5403
5404. In dir:{instrumentation/events/lttng-module}, relative to the root
5405 of the LTTng-modules source tree, create a header file named
5406 +__subsys__.h+ for your custom subsystem +__subsys__+ and write your
5407 LTTng-modules tracepoint definitions using the LTTng-modules
5408 macros in it.
5409+
5410Start with this template:
5411+
5412--
5413[source,c]
5414.path:{instrumentation/events/lttng-module/my_subsys.h}
5415----
5416#undef TRACE_SYSTEM
5417#define TRACE_SYSTEM my_subsys
5418
5419#if !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ)
5420#define _LTTNG_MY_SUBSYS_H
5421
5422#include "../../../probes/lttng-tracepoint-event.h"
5423#include <linux/tracepoint.h>
5424
5425LTTNG_TRACEPOINT_EVENT(
5426 /*
5427 * Format is identical to the TRACE_EVENT() version for the three
5428 * following macro parameters:
5429 */
5430 my_subsys_my_event,
5431 TP_PROTO(int my_int, const char *my_string),
5432 TP_ARGS(my_int, my_string),
5433
5434 /* LTTng-modules specific macros */
5435 TP_FIELDS(
5436 ctf_integer(int, my_int_field, my_int)
5437 ctf_string(my_bar_field, my_bar)
5438 )
5439)
5440
5441#endif /* !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ) */
5442
5443#include "../../../probes/define_trace.h"
5444----
5445--
5446+
5447The entries in the `TP_FIELDS()` section are the list of fields for the
5448LTTng tracepoint. This is similar to the `TP_STRUCT__entry()` part of
5449the `TRACE_EVENT()` ftrace macro.
5450+
5451See ``<<lttng-modules-tp-fields,Tracepoint fields macros>>'' for a
5452complete description of the available `ctf_*()` macros.
5453
5454. Create the kernel module C{nbsp}source file of the LTTng-modules
5455 probe, +probes/lttng-probe-__subsys__.c+, where +__subsys__+ is your
5456 subsystem name:
5457+
5458--
5459[source,c]
5460.path:{probes/lttng-probe-my-subsys.c}
5461----
5462#include <linux/module.h>
5463#include "../lttng-tracer.h"
5464
5465/*
5466 * Build-time verification of mismatch between mainline
5467 * TRACE_EVENT() arguments and the LTTng-modules adaptation
5468 * layer LTTNG_TRACEPOINT_EVENT() arguments.
5469 */
5470#include <trace/events/my_subsys.h>
5471
5472/* Create LTTng tracepoint probes */
5473#define LTTNG_PACKAGE_BUILD
5474#define CREATE_TRACE_POINTS
5475#define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
5476
5477#include "../instrumentation/events/lttng-module/my_subsys.h"
5478
5479MODULE_LICENSE("GPL and additional rights");
5480MODULE_AUTHOR("Your name <your-email>");
5481MODULE_DESCRIPTION("LTTng my_subsys probes");
5482MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
5483 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
5484 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
5485 LTTNG_MODULES_EXTRAVERSION);
5486----
5487--
5488
5489. Edit path:{probes/KBuild} and add your new kernel module object
5490 next to the existing ones:
5491+
5492--
5493[source,make]
5494.path:{probes/KBuild}
5495----
5496# ...
5497
5498obj-m += lttng-probe-module.o
5499obj-m += lttng-probe-power.o
5500
5501obj-m += lttng-probe-my-subsys.o
5502
5503# ...
5504----
5505--
5506
5507. Build and install the LTTng kernel modules:
5508+
5509--
5510[role="term"]
5511----
5512$ make KERNELDIR=/path/to/linux
5513# make modules_install && depmod -a
5514----
5515--
5516+
5517Replace `/path/to/linux` with the path to the Linux source tree where
5518you defined and used tracepoints with the `TRACE_EVENT()` ftrace macro.
5519
5520Note that you can also use the
5521<<lttng-tracepoint-event-code,`LTTNG_TRACEPOINT_EVENT_CODE()` macro>>
5522instead of `LTTNG_TRACEPOINT_EVENT()` to use custom local variables and
5523C{nbsp}code that need to be executed before LTTng records the event
5524fields.
5525
5526The best way to learn how to use the previous LTTng-modules macros is to
5527inspect the existing LTTng-modules tracepoint definitions in the
5528dir:{instrumentation/events/lttng-module} header files. Compare them
5529with the Linux kernel mainline versions in the
5530dir:{include/trace/events} directory of the Linux source tree.
5531
5532
5533[role="since-2.7"]
5534[[lttng-tracepoint-event-code]]
5535===== Use custom C code to access the data for tracepoint fields
5536
5537Although we recommended to always use the
5538<<lttng-adaptation-layer,`LTTNG_TRACEPOINT_EVENT()`>> macro to describe
5539the arguments and fields of an LTTng-modules tracepoint when possible,
5540sometimes you need a more complex process to access the data that the
5541tracer records as event record fields. In other words, you need local
5542variables and multiple C{nbsp}statements instead of simple
5543argument-based expressions that you pass to the
5544<<lttng-modules-tp-fields,`ctf_*()` macros of `TP_FIELDS()`>>.
5545
5546Use the `LTTNG_TRACEPOINT_EVENT_CODE()` macro instead of
5547`LTTNG_TRACEPOINT_EVENT()` to declare custom local variables and define
5548a block of C{nbsp}code to be executed before LTTng records the fields.
5549The structure of this macro is:
5550
5551[source,c]
5552.`LTTNG_TRACEPOINT_EVENT_CODE()` macro syntax.
5553----
5554LTTNG_TRACEPOINT_EVENT_CODE(
5555 /*
5556 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5557 * version for the following three macro parameters:
5558 */
5559 my_subsys_my_event,
5560 TP_PROTO(int my_int, const char *my_string),
5561 TP_ARGS(my_int, my_string),
5562
5563 /* Declarations of custom local variables */
5564 TP_locvar(
5565 int a = 0;
5566 unsigned long b = 0;
5567 const char *name = "(undefined)";
5568 struct my_struct *my_struct;
5569 ),
5570
5571 /*
5572 * Custom code which uses both tracepoint arguments
5573 * (in TP_ARGS()) and local variables (in TP_locvar()).
5574 *
5575 * Local variables are actually members of a structure pointed
5576 * to by the special variable tp_locvar.
5577 */
5578 TP_code(
5579 if (my_int) {
5580 tp_locvar->a = my_int + 17;
5581 tp_locvar->my_struct = get_my_struct_at(tp_locvar->a);
5582 tp_locvar->b = my_struct_compute_b(tp_locvar->my_struct);
5583 tp_locvar->name = my_struct_get_name(tp_locvar->my_struct);
5584 put_my_struct(tp_locvar->my_struct);
5585
5586 if (tp_locvar->b) {
5587 tp_locvar->a = 1;
5588 }
5589 }
5590 ),
5591
5592 /*
5593 * Format identical to the LTTNG_TRACEPOINT_EVENT()
5594 * version for this, except that tp_locvar members can be
5595 * used in the argument expression parameters of
5596 * the ctf_*() macros.
5597 */
5598 TP_FIELDS(
5599 ctf_integer(unsigned long, my_struct_b, tp_locvar->b)
5600 ctf_integer(int, my_struct_a, tp_locvar->a)
5601 ctf_string(my_string_field, my_string)
5602 ctf_string(my_struct_name, tp_locvar->name)
5603 )
5604)
5605----
5606
5607IMPORTANT: The C code defined in `TP_code()` must not have any side
5608effects when executed. In particular, the code must not allocate
5609memory or get resources without deallocating this memory or putting
5610those resources afterwards.
5611
5612
5613[[instrumenting-linux-kernel-tracing]]
5614==== Load and unload a custom probe kernel module
5615
5616You must load a <<lttng-adaptation-layer,created LTTng-modules probe
5617kernel module>> in the kernel before it can emit LTTng events.
5618
5619To load the default probe kernel modules and a custom probe kernel
5620module:
5621
5622* Use the opt:lttng-sessiond(8):--extra-kmod-probes option to give extra
5623 probe modules to load when starting a root <<lttng-sessiond,session
5624 daemon>>:
5625+
5626--
5627.Load the `my_subsys`, `usb`, and the default probe modules.
5628====
5629[role="term"]
5630----
5631# lttng-sessiond --extra-kmod-probes=my_subsys,usb
5632----
5633====
5634--
5635+
5636You only need to pass the subsystem name, not the whole kernel module
5637name.
5638
5639To load _only_ a given custom probe kernel module:
5640
5641* Use the opt:lttng-sessiond(8):--kmod-probes option to give the probe
5642 modules to load when starting a root session daemon:
5643+
5644--
5645.Load only the `my_subsys` and `usb` probe modules.
5646====
5647[role="term"]
5648----
5649# lttng-sessiond --kmod-probes=my_subsys,usb
5650----
5651====
5652--
5653
5654To confirm that a probe module is loaded:
5655
5656* Use man:lsmod(8):
5657+
5658--
5659[role="term"]
5660----
5661$ lsmod | grep lttng_probe_usb
5662----
5663--
5664
5665To unload the loaded probe modules:
5666
5667* Kill the session daemon with `SIGTERM`:
5668+
5669--
5670[role="term"]
5671----
5672# pkill lttng-sessiond
5673----
5674--
5675+
5676You can also use the `--remove` option of man:modprobe(8) if the session
5677daemon terminates abnormally.
5678
5679
5680[[controlling-tracing]]
5681== Tracing control
5682
5683Once an application or a Linux kernel is <<instrumenting,instrumented>>
5684for LTTng tracing, you can _trace_ it.
5685
5686In the LTTng context, _tracing_ means making sure that LTTng attempts to
5687execute some action(s) when a CPU executes an instrumentation point.
5688
5689This section is divided in topics on how to use the various
5690<<plumbing,components of LTTng>>, in particular the
5691<<lttng-cli,cmd:lttng command-line tool>>, to _control_ the LTTng
5692daemons and tracers.
5693
5694NOTE: In the following subsections, we refer to an man:lttng(1) command
5695using its man page name. For example, instead of ``Run the `create`
5696command to'', we write ``Run the man:lttng-create(1) command to''.
5697
5698
5699[[start-sessiond]]
5700=== Start a session daemon
5701
5702In some situations, you need to run a <<lttng-sessiond,session daemon>>
5703(man:lttng-sessiond(8)) _before_ you can use the man:lttng(1)
5704command-line tool.
5705
5706You will see the following error when you run a command while no session
5707daemon is running:
5708
5709----
5710Error: No session daemon is available
5711----
5712
5713The only command that automatically runs a session daemon is
5714man:lttng-create(1), which you use to
5715<<creating-destroying-tracing-sessions,create a recording session>>. While
5716this could be your most used first operation, sometimes it's not. Some
5717examples are:
5718
5719* <<list-instrumentation-points,List the available instrumentation points>>.
5720* <<saving-loading-tracing-session,Load a recording session configuration>>.
5721* <<add-event-rule-matches-trigger,Add a trigger>>.
5722
5723All the examples above don't require a recording session to operate on.
5724
5725[[tracing-group]] Each Unix user can have its own running session daemon
5726to use the user space LTTng tracer. The session daemon that the `root`
5727user starts is the only one allowed to control the LTTng kernel tracer.
5728Members of the Unix _tracing group_ may connect to and control the root
5729session daemon, even for user space tracing. See the ``Session daemon
5730connection'' section of man:lttng(1) to learn more about the Unix
5731tracing group.
5732
5733To start a user session daemon:
5734
5735* Run man:lttng-sessiond(8):
5736+
5737--
5738[role="term"]
5739----
5740$ lttng-sessiond --daemonize
5741----
5742--
5743
5744To start the root session daemon:
5745
5746* Run man:lttng-sessiond(8) as the `root` user:
5747+
5748--
5749[role="term"]
5750----
5751# lttng-sessiond --daemonize
5752----
5753--
5754
5755In both cases, remove the opt:lttng-sessiond(8):--daemonize option to
5756start the session daemon in foreground.
5757
5758To stop a session daemon, kill its process (see man:kill(1)) with the
5759standard `TERM` signal.
5760
5761Note that some Linux distributions could manage the LTTng session daemon
5762as a service. In this case, we suggest that you use the service manager
5763to start, restart, and stop session daemons.
5764
5765
5766[[creating-destroying-tracing-sessions]]
5767=== Create and destroy a recording session
5768
5769Many LTTng control operations happen in the scope of a
5770<<tracing-session,recording session>>, which is the dialogue between the
5771<<lttng-sessiond,session daemon>> and you for everything related to
5772<<event,event recording>>.
5773
5774To create a recording session with a generated name:
5775
5776* Use the man:lttng-create(1) command:
5777+
5778--
5779[role="term"]
5780----
5781$ lttng create
5782----
5783--
5784
5785The name of the created recording session is `auto` followed by the
5786creation date.
5787
5788To create a recording session with a specific name:
5789
5790* Use the optional argument of the man:lttng-create(1) command:
5791+
5792--
5793[role="term"]
5794----
5795$ lttng create SESSION
5796----
5797--
5798+
5799Replace +__SESSION__+ with your specific recording session name.
5800
5801In <<local-mode,local mode>>, LTTng writes the traces of a recording
5802session to the +$LTTNG_HOME/lttng-traces/__NAME__-__DATE__-__TIME__+
5803directory by default, where +__NAME__+ is the name of the recording
5804session. Note that the env:LTTNG_HOME environment variable defaults to
5805`$HOME` if not set.
5806
5807To output LTTng traces to a non-default location:
5808
5809* Use the opt:lttng-create(1):--output option of the man:lttng-create(1)
5810 command:
5811+
5812--
5813[role="term"]
5814----
5815$ lttng create my-session --output=/tmp/some-directory
5816----
5817--
5818
5819You may create as many recording sessions as you wish.
5820
5821To list all the existing recording sessions for your Unix user, or for
5822all users if your Unix user is `root`:
5823
5824* Use the man:lttng-list(1) command:
5825+
5826--
5827[role="term"]
5828----
5829$ lttng list
5830----
5831--
5832
5833[[cur-tracing-session]]When you create a recording session, the
5834man:lttng-create(1) command sets it as the _current recording session_.
5835The following man:lttng(1) commands operate on the current recording
5836session when you don't specify one:
5837
5838[role="list-3-cols"]
5839* man:lttng-add-context(1)
5840* man:lttng-clear(1)
5841* man:lttng-destroy(1)
5842* man:lttng-disable-channel(1)
5843* man:lttng-disable-event(1)
5844* man:lttng-disable-rotation(1)
5845* man:lttng-enable-channel(1)
5846* man:lttng-enable-event(1)
5847* man:lttng-enable-rotation(1)
5848* man:lttng-load(1)
5849* man:lttng-regenerate(1)
5850* man:lttng-rotate(1)
5851* man:lttng-save(1)
5852* man:lttng-snapshot(1)
5853* man:lttng-start(1)
5854* man:lttng-status(1)
5855* man:lttng-stop(1)
5856* man:lttng-track(1)
5857* man:lttng-untrack(1)
5858* man:lttng-view(1)
5859
5860To change the current recording session:
5861
5862* Use the man:lttng-set-session(1) command:
5863+
5864--
5865[role="term"]
5866----
5867$ lttng set-session SESSION
5868----
5869--
5870+
5871Replace +__SESSION__+ with the name of the new current recording session.
5872
5873When you're done recording in a given recording session, destroy it.
5874This operation frees the resources taken by the recording session to
5875destroy; it doesn't destroy the trace data that LTTng wrote for this
5876recording session (see ``<<clear,Clear a recording session>>'' for one
5877way to do this).
5878
5879To destroy the current recording session:
5880
5881* Use the man:lttng-destroy(1) command:
5882+
5883--
5884[role="term"]
5885----
5886$ lttng destroy
5887----
5888--
5889
5890The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
5891implicitly (see ``<<basic-tracing-session-control,Start and stop a
5892recording session>>''). You need to stop recording to make LTTng flush the
5893remaining trace data and make the trace readable.
5894
5895
5896[[list-instrumentation-points]]
5897=== List the available instrumentation points
5898
5899The <<lttng-sessiond,session daemon>> can query the running instrumented
5900user applications and the Linux kernel to get a list of available
5901instrumentation points:
5902
5903* LTTng tracepoints and system calls for the Linux kernel
5904 <<domain,tracing domain>>.
5905
5906* LTTng tracepoints for the user space tracing domain.
5907
5908To list the available instrumentation points:
5909
5910. <<start-sessiond,Make sure>> there's a running
5911 <<lttng-sessiond,session daemon>> to which your Unix user can
5912 connect.
5913
5914. Use the man:lttng-list(1) command with the option of the requested
5915 tracing domain amongst:
5916+
5917--
5918opt:lttng-list(1):--kernel::
5919 Linux kernel tracepoints.
5920+
5921Your Unix user must be `root`, or it must be a member of the Unix
5922<<tracing-group,tracing group>>.
5923
5924opt:lttng-list(1):--kernel with opt:lttng-list(1):--syscall::
5925 Linux kernel system calls.
5926+
5927Your Unix user must be `root`, or it must be a member of the Unix
5928<<tracing-group,tracing group>>.
5929
5930opt:lttng-list(1):--userspace::
5931 User space tracepoints.
5932
5933opt:lttng-list(1):--jul::
5934 `java.util.logging` loggers.
5935
5936opt:lttng-list(1):--log4j::
5937 Apache log4j loggers.
5938
5939opt:lttng-list(1):--python::
5940 Python loggers.
5941--
5942
5943.List the available user space tracepoints.
5944====
5945[role="term"]
5946----
5947$ lttng list --userspace
5948----
5949====
5950
5951.List the available Linux kernel system calls.
5952====
5953[role="term"]
5954----
5955$ lttng list --kernel --syscall
5956----
5957====
5958
5959
5960[[enabling-disabling-events]]
5961=== Create and enable a recording event rule
5962
5963Once you <<creating-destroying-tracing-sessions,create a recording
5964session>>, you can create <<event,recording event rules>> with the
5965man:lttng-enable-event(1) command.
5966
5967The man:lttng-enable-event(1) command always attaches an event rule to a
5968<<channel,channel>> on creation. The command can create a _default
5969channel_, named `channel0`, for you. The man:lttng-enable-event(1)
5970command reuses the default channel each time you run it for the same
5971tracing domain and session.
5972
5973A recording event rule is always enabled at creation time.
5974
5975The following examples show how to combine the command-line arguments of
5976the man:lttng-enable-event(1) command to create simple to more complex
5977recording event rules within the <<cur-tracing-session,current recording
5978session>>.
5979
5980.Create a recording event rule matching specific Linux kernel tracepoint events (default channel).
5981====
5982[role="term"]
5983----
5984# lttng enable-event --kernel sched_switch
5985----
5986====
5987
5988.Create a recording event rule matching Linux kernel system call events with four specific names (default channel).
5989====
5990[role="term"]
5991----
5992# lttng enable-event --kernel --syscall open,write,read,close
5993----
5994====
5995
5996.Create recording event rules matching tracepoint events which satisfy a filter expressions (default channel).
5997====
5998[role="term"]
5999----
6000# lttng enable-event --kernel sched_switch --filter='prev_comm == "bash"'
6001----
6002
6003[role="term"]
6004----
6005# lttng enable-event --kernel --all \
6006 --filter='$ctx.tid == 1988 || $ctx.tid == 1534'
6007----
6008
6009[role="term"]
6010----
6011$ lttng enable-event --jul my_logger \
6012 --filter='$app.retriever:cur_msg_id > 3'
6013----
6014
6015IMPORTANT: Make sure to always single-quote the filter string when you
6016run man:lttng(1) from a shell.
6017
6018See also ``<<pid-tracking,Allow specific processes to record events>>''
6019which offers another, more efficient filtering mechanism for process ID,
6020user ID, and group ID attributes.
6021====
6022
6023.Create a recording event rule matching any user space event from the `my_app` tracepoint provider and with a log level range (default channel).
6024====
6025[role="term"]
6026----
6027$ lttng enable-event --userspace my_app:'*' --loglevel=INFO
6028----
6029
6030IMPORTANT: Make sure to always single-quote the wildcard character when
6031you run man:lttng(1) from a shell.
6032====
6033
6034.Create a recording event rule matching user space events named specifically, but with name exclusions (default channel).
6035====
6036[role="term"]
6037----
6038$ lttng enable-event --userspace my_app:'*' \
6039 --exclude=my_app:set_user,my_app:handle_sig
6040----
6041====
6042
6043.Create a recording event rule matching any Apache log4j event with a specific log level (default channel).
6044====
6045[role="term"]
6046----
6047$ lttng enable-event --log4j --all --loglevel-only=WARN
6048----
6049====
6050
6051.Create a recording event rule, attached to a specific channel, and matching user space tracepoint events named `my_app:my_tracepoint`.
6052====
6053[role="term"]
6054----
6055$ lttng enable-event --userspace my_app:my_tracepoint \
6056 --channel=my-channel
6057----
6058====
6059
6060.Create a recording event rule matching user space probe events for the `malloc` function entry in path:{/usr/lib/libc.so.6}:
6061====
6062[role="term"]
6063----
6064# lttng enable-event --kernel \
6065 --userspace-probe=/usr/lib/libc.so.6:malloc \
6066 libc_malloc
6067----
6068====
6069
6070.Create a recording event rule matching user space probe events for the `server`/`accept_request` https://www.sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps[USDT probe] in path:{/usr/bin/serv}:
6071====
6072[role="term"]
6073----
6074# lttng enable-event --kernel \
6075 --userspace-probe=sdt:serv:server:accept_request \
6076 server_accept_request
6077----
6078====
6079
6080The recording event rules of a given channel form a whitelist: as soon
6081as an event rule matches an event, LTTng emits it _once_ and therefore
6082<<channel-overwrite-mode-vs-discard-mode,can>> record it. For example,
6083the following rules both match user space tracepoint events named
6084`my_app:my_tracepoint` with an `INFO` log level:
6085
6086[role="term"]
6087----
6088$ lttng enable-event --userspace my_app:my_tracepoint
6089$ lttng enable-event --userspace my_app:my_tracepoint \
6090 --loglevel=INFO
6091----
6092
6093The second recording event rule is redundant: the first one includes the
6094second one.
6095
6096
6097[[disable-event-rule]]
6098=== Disable a recording event rule
6099
6100To disable a <<event,recording event rule>> that you
6101<<enabling-disabling-events,created>> previously, use the
6102man:lttng-disable-event(1) command.
6103
6104man:lttng-disable-event(1) can only find recording event rules to
6105disable by their <<instrumentation-point-types,instrumentation point
6106type>> and event name conditions. Therefore, you cannot disable
6107recording event rules having a specific instrumentation point log level
6108condition, for example.
6109
6110LTTng doesn't emit (and, therefore, won't record) an event which only
6111_disabled_ recording event rules match.
6112
6113.Disable event rules matching Python logging events from the `my-logger` logger (default <<channel,channel>>, <<cur-tracing-session,current recording session>>).
6114====
6115[role="term"]
6116----
6117$ lttng disable-event --python my-logger
6118----
6119====
6120
6121.Disable event rules matching all `java.util.logging` events (default channel, recording session `my-session`).
6122====
6123[role="term"]
6124----
6125$ lttng disable-event --jul --session=my-session '*'
6126----
6127====
6128
6129.Disable _all_ the Linux kernel recording event rules (channel `my-chan`, current recording session).
6130====
6131The opt:lttng-disable-event(1):--all-events option isn't, like the
6132opt:lttng-enable-event(1):--all option of the man:lttng-enable-event(1)
6133command, an alias for the event name globbing pattern `*`: it disables
6134_all_ the recording event rules of a given channel.
6135
6136[role="term"]
6137----
6138# lttng disable-event --kernel --channel=my-chan --all-events
6139----
6140====
6141
6142NOTE: You can't _remove_ a recording event rule once you create it.
6143
6144
6145[[status]]
6146=== Get the status of a recording session
6147
6148To get the status of the <<cur-tracing-session,current recording
6149session>>, that is, its parameters, its channels, recording event rules,
6150and their attributes:
6151
6152* Use the man:lttng-status(1) command:
6153+
6154--
6155[role="term"]
6156----
6157$ lttng status
6158----
6159--
6160
6161To get the status of any recording session:
6162
6163* Use the man:lttng-list(1) command with the name of the recording
6164 session:
6165+
6166--
6167[role="term"]
6168----
6169$ lttng list SESSION
6170----
6171--
6172+
6173Replace +__SESSION__+ with the recording session name.
6174
6175
6176[[basic-tracing-session-control]]
6177=== Start and stop a recording session
6178
6179Once you <<creating-destroying-tracing-sessions,create a recording
6180session>> and <<enabling-disabling-events,create one or more recording
6181event rules>>, you can start and stop the tracers for this recording
6182session.
6183
6184To start the <<cur-tracing-session,current recording session>>:
6185
6186* Use the man:lttng-start(1) command:
6187+
6188--
6189[role="term"]
6190----
6191$ lttng start
6192----
6193--
6194
6195LTTng is flexible: you can launch user applications before or after you
6196start the tracers. An LTTng tracer only <<event,records an event>> if a
6197recording event rule matches it, which means the tracer is active.
6198
6199The `start-session` <<trigger,trigger>> action can also start a recording
6200session.
6201
6202To stop the current recording session:
6203
6204* Use the man:lttng-stop(1) command:
6205+
6206--
6207[role="term"]
6208----
6209$ lttng stop
6210----
6211--
6212+
6213If there were <<channel-overwrite-mode-vs-discard-mode,lost event
6214records>> or lost sub-buffers since the last time you ran
6215man:lttng-start(1), the man:lttng-stop(1) command prints corresponding
6216warnings.
6217
6218IMPORTANT: You need to stop recording to make LTTng flush the remaining
6219trace data and make the trace readable. Note that the
6220man:lttng-destroy(1) command (see
6221``<<creating-destroying-tracing-sessions,Create and destroy a recording
6222session>>'') also runs the man:lttng-stop(1) command implicitly.
6223
6224The `stop-session` <<trigger,trigger>> action can also stop a recording
6225session.
6226
6227[role="since-2.12"]
6228[[clear]]
6229=== Clear a recording session
6230
6231You might need to remove all the current tracing data of one or more
6232<<tracing-session,recording sessions>> between multiple attempts to
6233reproduce a problem without interrupting the LTTng recording activity.
6234
6235To clear the tracing data of the
6236<<cur-tracing-session,current recording session>>:
6237
6238* Use the man:lttng-clear(1) command:
6239+
6240--
6241[role="term"]
6242----
6243$ lttng clear
6244----
6245--
6246
6247To clear the tracing data of all the recording sessions:
6248
6249* Use the `lttng clear` command with its opt:lttng-clear(1):--all
6250 option:
6251+
6252--
6253[role="term"]
6254----
6255$ lttng clear --all
6256----
6257--
6258
6259
6260[[enabling-disabling-channels]]
6261=== Create a channel
6262
6263Once you <<creating-destroying-tracing-sessions,create a recording
6264session>>, you can create a <<channel,channel>> with the
6265man:lttng-enable-channel(1) command.
6266
6267Note that LTTng can automatically create a default channel when you
6268<<enabling-disabling-events,create a recording event rule>>.
6269Therefore, you only need to create a channel when you need non-default
6270attributes.
6271
6272Specify each non-default channel attribute with a command-line
6273option when you run the man:lttng-enable-channel(1) command.
6274
6275You can only create a custom channel in the Linux kernel and user space
6276<<domain,tracing domains>>: the Java/Python logging tracing domains have
6277their own default channel which LTTng automatically creates when you
6278<<enabling-disabling-events,create a recording event rule>>.
6279
6280[IMPORTANT]
6281====
6282As of LTTng{nbsp}{revision}, you may _not_ perform the
6283following operations with the man:lttng-enable-channel(1) command:
6284
6285* Change an attribute of an existing channel.
6286
6287* Enable a disabled channel once its recording session has been
6288 <<basic-tracing-session-control,active>> at least once.
6289
6290* Create a channel once its recording session has been active at
6291 least once.
6292
6293* Create a user space channel with a given
6294 <<channel-buffering-schemes,buffering scheme>> and create a second
6295 user space channel with a different buffering scheme in the same
6296 recording session.
6297====
6298
6299The following examples show how to combine the command-line options of
6300the man:lttng-enable-channel(1) command to create simple to more complex
6301channels within the <<cur-tracing-session,current recording session>>.
6302
6303.Create a Linux kernel channel with default attributes.
6304====
6305[role="term"]
6306----
6307# lttng enable-channel --kernel my-channel
6308----
6309====
6310
6311.Create a user space channel with four sub-buffers or 1{nbsp}MiB each, per CPU, per instrumented process.
6312====
6313[role="term"]
6314----
6315$ lttng enable-channel --userspace --num-subbuf=4 --subbuf-size=1M \
6316 --buffers-pid my-channel
6317----
6318====
6319
6320.[[blocking-timeout-example]]Create a default user space channel with an infinite blocking timeout.
6321====
6322<<creating-destroying-tracing-sessions,Create a recording session>>,
6323create the channel, <<enabling-disabling-events,create a recording event
6324rule>>, and <<basic-tracing-session-control,start recording>>:
6325
6326[role="term"]
6327----
6328$ lttng create
6329$ lttng enable-channel --userspace --blocking-timeout=inf blocking-chan
6330$ lttng enable-event --userspace --channel=blocking-chan --all
6331$ lttng start
6332----
6333
6334Run an application instrumented with LTTng-UST tracepoints and allow it
6335to block:
6336
6337[role="term"]
6338----
6339$ LTTNG_UST_ALLOW_BLOCKING=1 my-app
6340----
6341====
6342
6343.Create a Linux kernel channel which rotates eight trace files of 4{nbsp}MiB each for each stream.
6344====
6345[role="term"]
6346----
6347# lttng enable-channel --kernel --tracefile-count=8 \
6348 --tracefile-size=4194304 my-channel
6349----
6350====
6351
6352.Create a user space channel in <<overwrite-mode,overwrite>> (or ``flight recorder'') mode.
6353====
6354[role="term"]
6355----
6356$ lttng enable-channel --userspace --overwrite my-channel
6357----
6358====
6359
6360.<<enabling-disabling-events,Create>> the same <<event,recording event rule>> attached to two different channels.
6361====
6362[role="term"]
6363----
6364$ lttng enable-event --userspace --channel=my-channel app:tp
6365$ lttng enable-event --userspace --channel=other-channel app:tp
6366----
6367
6368When a CPU executes the `app:tp` <<c-application,user space
6369tracepoint>>, the two recording event rules above match the created
6370event, making LTTng emit the event. Because the recording event rules
6371are not attached to the same channel, LTTng records the event twice.
6372====
6373
6374
6375[[disable-channel]]
6376=== Disable a channel
6377
6378To disable a specific channel that you
6379<<enabling-disabling-channels,created>> previously, use the
6380man:lttng-disable-channel(1) command.
6381
6382.Disable a specific Linux kernel channel (<<cur-tracing-session,current recording session>>).
6383====
6384[role="term"]
6385----
6386# lttng disable-channel --kernel my-channel
6387----
6388====
6389
6390An enabled channel is an implicit <<event,recording event rule>>
6391condition.
6392
6393NOTE: As of LTTng{nbsp}{revision}, you may _not_ enable a disabled
6394channel once its recording session has been
6395<<basic-tracing-session-control,started>> at least once.
6396
6397
6398[[adding-context]]
6399=== Add context fields to be recorded to the event records of a channel
6400
6401<<event,Event record>> fields in trace files provide important
6402information about previously emitted events, but sometimes some external
6403context may help you solve a problem faster.
6404
6405Examples of context fields are:
6406
6407* The **process ID**, **thread ID**, **process name**, and
6408 **process priority** of the thread from which LTTng emits the event.
6409
6410* The **hostname** of the system on which LTTng emits the event.
6411
6412* The Linux kernel and user call stacks (since LTTng{nbsp}2.11).
6413
6414* The current values of many possible **performance counters** using
6415 perf, for example:
6416
6417** CPU cycles, stalled cycles, idle cycles, and the other cycle types.
6418** Cache misses.
6419** Branch instructions, misses, and loads.
6420** CPU faults.
6421
6422* Any state defined at the application level (supported for the
6423 `java.util.logging` and Apache log4j <<domain,tracing domains>>).
6424
6425To get the full list of available context fields:
6426
6427* Use the opt:lttng-add-context(1):--list option of the
6428 man:lttng-add-context(1) command:
6429+
6430[role="term"]
6431----
6432$ lttng add-context --list
6433----
6434
6435.Add context fields to be recorded to the event records of all the <<channel,channels>> of the <<cur-tracing-session,current recording session>>.
6436====
6437The following command line adds the virtual process identifier and the
6438per-thread CPU cycles count fields to all the user space channels of the
6439current recording session.
6440
6441[role="term"]
6442----
6443$ lttng add-context --userspace --type=vpid --type=perf:thread:cpu-cycles
6444----
6445====
6446
6447.Add performance counter context fields by raw ID
6448====
6449See man:lttng-add-context(1) for the exact format of the context field
6450type, which is partly compatible with the format used in
6451man:perf-record(1).
6452
6453[role="term"]
6454----
6455# lttng add-context --userspace --type=perf:thread:raw:r0110:test
6456# lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted
6457----
6458====
6459
6460.Add context fields to be recorded to the event records of a specific channel.
6461====
6462The following command line adds the thread identifier and user call
6463stack context fields to the Linux kernel channel named `my-channel` of
6464the <<cur-tracing-session,current recording session>>.
6465
6466[role="term"]
6467----
6468# lttng add-context --kernel --channel=my-channel \
6469 --type=tid --type=callstack-user
6470----
6471====
6472
6473.Add an <<java-application-context,application-specific context field>> to be recorded to the event records of a specific channel.
6474====
6475The following command line makes sure LTTng writes the `cur_msg_id`
6476context field of the `retriever` context retriever to all the Java
6477logging <<event,event records>> of the channel named `my-channel`:
6478
6479[role="term"]
6480----
6481# lttng add-context --kernel --channel=my-channel \
6482 --type='$app:retriever:cur_msg_id'
6483----
6484
6485IMPORTANT: Make sure to always single-quote the `$` character when you
6486run man:lttng-add-context(1) from a shell.
6487====
6488
6489NOTE: You can't undo what the man:lttng-add-context(1) command does.
6490
6491
6492[role="since-2.7"]
6493[[pid-tracking]]
6494=== Allow specific processes to record events
6495
6496It's often useful to only allow processes with specific attributes to
6497record events. For example, you may wish to record all the system calls
6498which a given process makes (à la man:strace(1)).
6499
6500The man:lttng-track(1) and man:lttng-untrack(1) commands serve this
6501purpose. Both commands operate on _inclusion sets_ of process
6502attributes. The available process attribute types are:
6503
6504Linux kernel <<domain,tracing domain>>::
6505+
6506* Process ID (PID).
6507
6508* Virtual process ID (VPID).
6509+
6510This is the PID as seen by the application.
6511
6512* Unix user ID (UID).
6513
6514* Virtual Unix user ID (VUID).
6515+
6516This is the UID as seen by the application.
6517
6518* Unix group ID (GID).
6519
6520* Virtual Unix group ID (VGID).
6521+
6522This is the GID as seen by the application.
6523
6524User space tracing domain::
6525+
6526* VPID
6527* VUID
6528* VGID
6529
6530A <<tracing-session,recording session>> has nine process
6531attribute inclusion sets: six for the Linux kernel <<domain,tracing domain>>
6532and three for the user space tracing domain.
6533
6534For a given recording session, a process{nbsp}__P__ is allowed to record
6535LTTng events for a given <<domain,tracing domain>>{nbsp}__D__ if _all_
6536the attributes of{nbsp}__P__ are part of the inclusion sets
6537of{nbsp}__D__.
6538
6539Whether a process is allowed or not to record LTTng events is an
6540implicit condition of all <<event,recording event rules>>. Therefore, if
6541LTTng creates an event{nbsp}__E__ for a given process, but this process
6542may not record events, then no recording event rule matches{nbsp}__E__,
6543which means LTTng won't emit and record{nbsp}__E__.
6544
6545When you <<creating-destroying-tracing-sessions,create a recording
6546session>>, all its process attribute inclusion sets contain all the
6547possible values. In other words, all processes are allowed to record
6548events.
6549
6550Add values to an inclusion set with the man:lttng-track(1) command and
6551remove values with the man:lttng-untrack(1) command.
6552
6553[NOTE]
6554====
6555The process attribute values are _numeric_.
6556
6557Should a process with a given ID (part of an inclusion set), for
6558example, exit, and then a new process be given this same ID, then the
6559latter would also be allowed to record events.
6560
6561With the man:lttng-track(1) command, you can add Unix user and group
6562_names_ to the user and group inclusion sets: the
6563<<lttng-sessiond,session daemon>> finds the corresponding UID, VUID,
6564GID, or VGID once on _addition_ to the inclusion set. This means that if
6565you rename the user or group after you run the man:lttng-track(1)
6566command, its user/group ID remains part of the inclusion sets.
6567====
6568
6569.Allow processes to record events based on their virtual process ID (VPID).
6570====
6571For the sake of the following example, assume the target system has
657216{nbsp}possible VPIDs.
6573
6574When you
6575<<creating-destroying-tracing-sessions,create a recording session>>,
6576the user space VPID inclusion set contains _all_ the possible VPIDs:
6577
6578[role="img-100"]
6579.The VPID inclusion set is full.
6580image::track-all.png[]
6581
6582When the inclusion set is full and you run the man:lttng-track(1)
6583command to specify some VPIDs, LTTng:
6584
6585. Clears the inclusion set.
6586. Adds the specific VPIDs to the inclusion set.
6587
6588After:
6589
6590[role="term"]
6591----
6592$ lttng track --userspace --vpid=3,4,7,10,13
6593----
6594
6595the VPID inclusion set is:
6596
6597[role="img-100"]
6598.The VPID inclusion set contains the VPIDs 3, 4, 7, 10, and 13.
6599image::track-3-4-7-10-13.png[]
6600
6601Add more VPIDs to the inclusion set afterwards:
6602
6603[role="term"]
6604----
6605$ lttng track --userspace --vpid=1,15,16
6606----
6607
6608The result is:
6609
6610[role="img-100"]
6611.VPIDs 1, 15, and 16 are added to the inclusion set.
6612image::track-1-3-4-7-10-13-15-16.png[]
6613
6614The man:lttng-untrack(1) command removes entries from process attribute
6615inclusion sets. Given the previous example, the following command:
6616
6617[role="term"]
6618----
6619$ lttng untrack --userspace --vpid=3,7,10,13
6620----
6621
6622leads to this VPID inclusion set:
6623
6624[role="img-100"]
6625.VPIDs 3, 7, 10, and 13 are removed from the inclusion set.
6626image::track-1-4-15-16.png[]
6627
6628You can make the VPID inclusion set full again with the
6629opt:lttng-track(1):--all option:
6630
6631[role="term"]
6632----
6633$ lttng track --userspace --vpid --all
6634----
6635
6636The result is, again:
6637
6638[role="img-100"]
6639.The VPID inclusion set is full.
6640image::track-all.png[]
6641====
6642
6643.Allow specific processes to record events based on their user ID (UID).
6644====
6645A typical use case with process attribute inclusion sets is to start
6646with an empty inclusion set, then <<basic-tracing-session-control,start
6647the tracers>>, and finally add values manually while the tracers are
6648active.
6649
6650Use the opt:lttng-untrack(1):--all option of the
6651man:lttng-untrack(1) command to clear the inclusion set after you
6652<<creating-destroying-tracing-sessions,create a recording session>>, for
6653example (with UIDs):
6654
6655[role="term"]
6656----
6657# lttng untrack --kernel --uid --all
6658----
6659
6660gives:
6661
6662[role="img-100"]
6663.The UID inclusion set is empty.
6664image::untrack-all.png[]
6665
6666If the LTTng tracer runs with this inclusion set configuration, it
6667records no events within the <<cur-tracing-session,current recording
6668session>> because no processes is allowed to do so. Use the
6669man:lttng-track(1) command as usual to add specific values to the UID
6670inclusion set when you need to, for example:
6671
6672[role="term"]
6673----
6674# lttng track --kernel --uid=http,11
6675----
6676
6677Result:
6678
6679[role="img-100"]
6680.UIDs 6 (`http`) and 11 are part of the UID inclusion set.
6681image::track-6-11.png[]
6682====
6683
6684
6685[role="since-2.5"]
6686[[saving-loading-tracing-session]]
6687=== Save and load recording session configurations
6688
6689Configuring a <<tracing-session,recording session>> can be long. Some of
6690the tasks involved are:
6691
6692* <<enabling-disabling-channels,Create channels>> with
6693 specific attributes.
6694
6695* <<adding-context,Add context fields>> to be recorded to the
6696 <<event,event records>> of specific channels.
6697
6698* <<enabling-disabling-events,Create recording event rules>> with
6699 specific log level, filter, and other conditions.
6700
6701If you use LTTng to solve real world problems, chances are you have to
6702record events using the same recording session setup over and over,
6703modifying a few variables each time in your instrumented program or
6704environment.
6705
6706To avoid constant recording session reconfiguration, the man:lttng(1)
6707command-line tool can save and load recording session configurations
6708to/from XML files.
6709
6710To save a given recording session configuration:
6711
6712* Use the man:lttng-save(1) command:
6713+
6714--
6715[role="term"]
6716----
6717$ lttng save SESSION
6718----
6719--
6720+
6721Replace +__SESSION__+ with the name of the recording session to save.
6722
6723LTTng saves recording session configurations to
6724dir:{$LTTNG_HOME/.lttng/sessions} by default. Note that the
6725env:LTTNG_HOME environment variable defaults to `$HOME` if not set. See
6726man:lttng-save(1) to learn more about the recording session configuration
6727output path.
6728
6729LTTng saves all configuration parameters, for example:
6730
6731* The recording session name.
6732* The trace data output path.
6733* The <<channel,channels>>, with their state and all their attributes.
6734* The context fields you added to channels.
6735* The <<event,recording event rules>> with their state and conditions.
6736
6737To load a recording session:
6738
6739* Use the man:lttng-load(1) command:
6740+
6741--
6742[role="term"]
6743----
6744$ lttng load SESSION
6745----
6746--
6747+
6748Replace +__SESSION__+ with the name of the recording session to load.
6749
6750When LTTng loads a configuration, it restores your saved recording session
6751as if you just configured it manually.
6752
6753You can also save and load many sessions at a time; see
6754man:lttng-save(1) and man:lttng-load(1) to learn more.
6755
6756
6757[[sending-trace-data-over-the-network]]
6758=== Send trace data over the network
6759
6760LTTng can send the recorded trace data of a <<tracing-session,recording
6761session>> to a remote system over the network instead of writing it to
6762the local file system.
6763
6764To send the trace data over the network:
6765
6766. On the _remote_ system (which can also be the target system),
6767 start an LTTng <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)):
6768+
6769--
6770[role="term"]
6771----
6772$ lttng-relayd
6773----
6774--
6775
6776. On the _target_ system, create a recording session
6777 <<net-streaming-mode,configured>> to send trace data over the network:
6778+
6779--
6780[role="term"]
6781----
6782$ lttng create my-session --set-url=net://remote-system
6783----
6784--
6785+
6786Replace +__remote-system__+ with the host name or IP address of the
6787remote system. See man:lttng-create(1) for the exact URL format.
6788
6789. On the target system, use the man:lttng(1) command-line tool as usual.
6790+
6791When recording is <<basic-tracing-session-control,active>>, the
6792<<lttng-consumerd,consumer daemon>> of the target sends the contents of
6793<<channel,sub-buffers>> to the remote relay daemon instead of flushing
6794them to the local file system. The relay daemon writes the received
6795packets to its local file system.
6796
6797See the ``Output directory'' section of man:lttng-relayd(8) to learn
6798where a relay daemon writes its received trace data.
6799
6800
6801[role="since-2.4"]
6802[[lttng-live]]
6803=== View events as LTTng records them (noch:{LTTng} live)
6804
6805_LTTng live_ is a network protocol implemented by the
6806<<lttng-relayd,relay daemon>> (man:lttng-relayd(8)) to allow compatible
6807trace readers to display or analyze <<event,event records>> as LTTng
6808records events on the target system while recording is
6809<<basic-tracing-session-control,active>>.
6810
6811The relay daemon creates a _tee_: it forwards the trace data to both the
6812local file system and to connected live readers:
6813
6814[role="img-90"]
6815.The relay daemon creates a _tee_, forwarding the trace data to both trace files and a connected live reader.
6816image::live.png[]
6817
6818To use LTTng live:
6819
6820. On the _target system_, create a <<tracing-session,recording session>>
6821 in _live mode_:
6822+
6823--
6824[role="term"]
6825----
6826$ lttng create my-session --live
6827----
6828--
6829+
6830This operation spawns a local relay daemon.
6831
6832. Start the live reader and configure it to connect to the relay daemon.
6833+
6834For example, with man:babeltrace2(1):
6835+
6836--
6837[role="term"]
6838----
6839$ babeltrace2 net://localhost/host/HOSTNAME/my-session
6840----
6841--
6842+
6843Replace +__HOSTNAME__+ with the host name of the target system.
6844
6845. Configure the recording session as usual with the man:lttng(1)
6846 command-line tool, and <<basic-tracing-session-control,start recording>>.
6847
6848List the available live recording sessions with man:babeltrace2(1):
6849
6850[role="term"]
6851----
6852$ babeltrace2 net://localhost
6853----
6854
6855You can start the relay daemon on another system. In this case, you need
6856to specify the URL of the relay daemon when you
6857<<creating-destroying-tracing-sessions,create the recording session>> with
6858the opt:lttng-create(1):--set-url option of the man:lttng-create(1)
6859command. You also need to replace +__localhost__+ in the procedure above
6860with the host name of the system on which the relay daemon runs.
6861
6862
6863[role="since-2.3"]
6864[[taking-a-snapshot]]
6865=== Take a snapshot of the current sub-buffers of a recording session
6866
6867The normal behavior of LTTng is to append full sub-buffers to growing
6868trace data files. This is ideal to keep a full history of the events
6869which the target system emitted, but it can represent too much data in
6870some situations.
6871
6872For example, you may wish to have LTTng record your application
6873continuously until some critical situation happens, in which case you
6874only need the latest few recorded events to perform the desired
6875analysis, not multi-gigabyte trace files.
6876
6877With the man:lttng-snapshot(1) command, you can take a _snapshot_ of the
6878current <<channel,sub-buffers>> of a given <<tracing-session,recording
6879session>>. LTTng can write the snapshot to the local file system or send
6880it over the network.
6881
6882[role="img-100"]
6883.A snapshot is a copy of the current sub-buffers, which LTTng does _not_ clear after the operation.
6884image::snapshot.png[]
6885
6886The snapshot feature of LTTng is similar to how a
6887https://en.wikipedia.org/wiki/Flight_recorder[flight recorder] or the
6888``roll'' mode of an oscilloscope work.
6889
6890TIP: If you wish to create unmanaged, self-contained, non-overlapping
6891trace chunk archives instead of a simple copy of the current
6892sub-buffers, see the <<session-rotation,recording session rotation>>
6893feature (available since LTTng{nbsp}2.11).
6894
6895To take a snapshot of the <<cur-tracing-session,current recording
6896session>>:
6897
6898. Create a recording session in <<snapshot-mode,snapshot mode>>:
6899+
6900--
6901[role="term"]
6902----
6903$ lttng create my-session --snapshot
6904----
6905--
6906+
6907The <<channel-overwrite-mode-vs-discard-mode,event record loss mode>> of
6908<<channel,channels>> created in this mode is automatically set to
6909<<overwrite-mode,_overwrite_>>.
6910
6911. Configure the recording session as usual with the man:lttng(1)
6912 command-line tool, and <<basic-tracing-session-control,start
6913 recording>>.
6914
6915. **Optional**: When you need to take a snapshot,
6916 <<basic-tracing-session-control,stop recording>>.
6917+
6918You can take a snapshot when the tracers are active, but if you stop
6919them first, you're guaranteed that the trace data in the sub-buffers
6920doesn't change before you actually take the snapshot.
6921
6922. Take a snapshot:
6923+
6924--
6925[role="term"]
6926----
6927$ lttng snapshot record --name=my-first-snapshot
6928----
6929--
6930+
6931LTTng writes the current sub-buffers of all the channels of the
6932<<cur-tracing-session,current recording session>> to
6933trace files on the local file system. Those trace files have
6934`my-first-snapshot` in their name.
6935
6936There's no difference between the format of a normal trace file and the
6937format of a snapshot: LTTng trace readers also support LTTng snapshots.
6938
6939By default, LTTng writes snapshot files to the path shown by
6940
6941[role="term"]
6942----
6943$ lttng snapshot list-output
6944----
6945
6946You can change this path or decide to send snapshots over the network
6947using either:
6948
6949. An output path or URL that you specify when you
6950 <<creating-destroying-tracing-sessions,create the recording session>>.
6951
6952. A snapshot output path or URL that you add using the
6953 `add-output` action of the man:lttng-snapshot(1) command.
6954
6955. An output path or URL that you provide directly to the
6956 `record` action of the man:lttng-snapshot(1) command.
6957
6958Method{nbsp}3 overrides method{nbsp}2, which overrides method 1. When
6959you specify a URL, a <<lttng-relayd,relay daemon>> must listen on a
6960remote system (see ``<<sending-trace-data-over-the-network,Send trace
6961data over the network>>'').
6962
6963The `snapshot-session` <<trigger,trigger>> action can also take
6964a recording session snapshot.
6965
6966
6967[role="since-2.11"]
6968[[session-rotation]]
6969=== Archive the current trace chunk (rotate a recording session)
6970
6971The <<taking-a-snapshot,snapshot user guide>> shows how to dump the
6972current sub-buffers of a recording session to the file system or send them
6973over the network. When you take a snapshot, LTTng doesn't clear the ring
6974buffers of the recording session: if you take another snapshot immediately
6975after, both snapshots could contain overlapping trace data.
6976
6977Inspired by https://en.wikipedia.org/wiki/Log_rotation[log rotation],
6978_recording session rotation_ is a feature which appends the content of the
6979ring buffers to what's already on the file system or sent over the
6980network since the creation of the recording session or since the last
6981rotation, and then clears those ring buffers to avoid trace data
6982overlaps.
6983
6984What LTTng is about to write when performing a recording session rotation
6985is called the _current trace chunk_. When LTTng writes or sends over the
6986network this current trace chunk, it becomes a _trace chunk archive_.
6987Therefore, a recording session rotation operation _archives_ the current
6988trace chunk.
6989
6990[role="img-100"]
6991.A recording session rotation operation _archives_ the current trace chunk.
6992image::rotation.png[]
6993
6994A trace chunk archive is a self-contained LTTng trace which LTTng
6995doesn't manage anymore: you can read it, modify it, move it, or remove
6996it.
6997
6998As of LTTng{nbsp}{revision}, there are three methods to perform a
6999recording session rotation:
7000
7001* <<immediate-rotation,Immediately>>.
7002
7003* With a <<rotation-schedule,rotation schedule>>.
7004
7005* Through the execution of a `rotate-session` <<trigger,trigger>>
7006 action.
7007
7008[[immediate-rotation]]To perform an immediate rotation of the
7009<<cur-tracing-session,current recording session>>:
7010
7011. <<creating-destroying-tracing-sessions,Create a recording session>> in
7012 <<local-mode,local mode>> or <<net-streaming-mode,network streaming
7013 mode>> (only those two recording session modes support recording session
7014 rotation):
7015+
7016--
7017[role="term"]
7018----
7019# lttng create my-session
7020----
7021--
7022
7023. <<enabling-disabling-events,Create one or more recording event rules>>
7024 and <<basic-tracing-session-control,start recording>>:
7025+
7026--
7027[role="term"]
7028----
7029# lttng enable-event --kernel sched_'*'
7030# lttng start
7031----
7032--
7033
7034. When needed, immediately rotate the current recording session:
7035+
7036--
7037[role="term"]
7038----
7039# lttng rotate
7040----
7041--
7042+
7043The man:lttng-rotate(1) command prints the path to the created trace
7044chunk archive. See its manual page to learn about the format of trace
7045chunk archive directory names.
7046+
7047Perform other immediate rotations while the recording session is active.
7048It's guaranteed that all the trace chunk archives don't contain
7049overlapping trace data. You can also perform an immediate rotation once
7050you have <<basic-tracing-session-control,stopped>> the recording session.
7051
7052. When you're done recording,
7053 <<creating-destroying-tracing-sessions,destroy the current recording
7054 session>>:
7055+
7056--
7057[role="term"]
7058----
7059# lttng destroy
7060----
7061--
7062+
7063The recording session destruction operation creates one last trace chunk
7064archive from the current trace chunk.
7065
7066[[rotation-schedule]]A recording session rotation schedule is a planned
7067rotation which LTTng performs automatically based on one of the
7068following conditions:
7069
7070* A timer with a configured period expires.
7071
7072* The total size of the _flushed_ part of the current trace chunk
7073 becomes greater than or equal to a configured value.
7074
7075To schedule a rotation of the <<cur-tracing-session,current recording
7076session>>, set a _rotation schedule_:
7077
7078. <<creating-destroying-tracing-sessions,Create a recording session>> in
7079 <<local-mode,local mode>> or <<net-streaming-mode,network streaming
7080 mode>> (only those two creation modes support recording session
7081 rotation):
7082+
7083--
7084[role="term"]
7085----
7086# lttng create my-session
7087----
7088--
7089
7090. <<enabling-disabling-events,Create one or more recording event rules>>:
7091+
7092--
7093[role="term"]
7094----
7095# lttng enable-event --kernel sched_'*'
7096----
7097--
7098
7099. Set a recording session rotation schedule:
7100+
7101--
7102[role="term"]
7103----
7104# lttng enable-rotation --timer=10s
7105----
7106--
7107+
7108In this example, we set a rotation schedule so that LTTng performs a
7109recording session rotation every ten seconds.
7110+
7111See man:lttng-enable-rotation(1) to learn more about other ways to set a
7112rotation schedule.
7113
7114. <<basic-tracing-session-control,Start recording>>:
7115+
7116--
7117[role="term"]
7118----
7119# lttng start
7120----
7121--
7122+
7123LTTng performs recording session rotations automatically while the
7124recording session is active thanks to the rotation schedule.
7125
7126. When you're done recording,
7127 <<creating-destroying-tracing-sessions,destroy the current recording
7128 session>>:
7129+
7130--
7131[role="term"]
7132----
7133# lttng destroy
7134----
7135--
7136+
7137The recording session destruction operation creates one last trace chunk
7138archive from the current trace chunk.
7139
7140Unset a recording session rotation schedule with the
7141man:lttng-disable-rotation(1) command.
7142
7143
7144[role="since-2.13"]
7145[[add-event-rule-matches-trigger]]
7146=== Add an ``event rule matches'' trigger to a session daemon
7147
7148With the man:lttng-add-trigger(1) command, you can add a
7149<<trigger,trigger>> to a <<lttng-sessiond,session daemon>>.
7150
7151A trigger associates an LTTng tracing condition to one or more actions:
7152when the condition is satisfied, LTTng attempts to execute the actions.
7153
7154A trigger doesn't need any <<tracing-session,recording session>> to exist:
7155it belongs to a session daemon.
7156
7157As of LTTng{nbsp}{revision}, many condition types are available through
7158the <<liblttng-ctl-lttng,`liblttng-ctl`>> C{nbsp}API, but the
7159man:lttng-add-trigger(1) command only accepts the ``event rule matches''
7160condition.
7161
7162An ``event rule matches'' condition is satisfied when its event rule
7163matches an event.
7164
7165Unlike a <<event,recording event rule>>, the event rule of an
7166``event rule matches'' trigger condition has no implicit conditions,
7167that is:
7168
7169* It has no enabled/disabled state.
7170* It has no attached <<channel,channel>>.
7171* It doesn't belong to a <<tracing-session,recording session>>.
7172
7173Both the man:lttng-add-trigger(1) and man:lttng-enable-event(1) commands
7174accept command-line arguments to specify an <<event-rule,event rule>>.
7175That being said, the former is a more recent command and therefore
7176follows the common event rule specification format (see
7177man:lttng-event-rule(7)).
7178
7179.Start a <<tracing-session,recording session>> when an event rule matches.
7180====
7181This example shows how to add the following trigger to the root
7182<<lttng-sessiond,session daemon>>:
7183
7184Condition::
7185 An event rule matches a Linux kernel system call event of which the
7186 name starts with `exec` and `*/ls` matches the `filename` payload
7187 field.
7188+
7189With such an event rule, LTTng emits an event when the cmd:ls program
7190starts.
7191
7192Action::
7193 <<basic-tracing-session-control,Start the recording session>>
7194 named `pitou`.
7195
7196To add such a trigger to the root session daemon:
7197
7198. **If there's no currently running LTTng root session daemon**, start
7199 one:
7200+
7201[role="term"]
7202----
7203# lttng-sessiond --daemonize
7204----
7205
7206. <<creating-destroying-tracing-sessions,Create a recording session>>
7207 named `pitou` and
7208 <<enabling-disabling-events,create a recording event rule>> matching
7209 all the system call events:
7210+
7211[role="term"]
7212----
7213# lttng create pitou
7214# lttng enable-event --kernel --syscall --all
7215----
7216
7217. Add the trigger to the root session daemon:
7218+
7219[role="term"]
7220----
7221# lttng add-trigger --condition=event-rule-matches \
7222 --type=syscall --name='exec*' \
7223 --filter='filename == "*/ls"' \
7224 --action=start-session pitou
7225----
7226+
7227Confirm that the trigger exists with the man:lttng-list-triggers(1)
7228command:
7229+
7230[role="term"]
7231----
7232# lttng list-triggers
7233----
7234
7235. Make sure the `pitou` recording session is still inactive (stopped):
7236+
7237[role="term"]
7238----
7239# lttng list pitou
7240----
7241+
7242The first line should be something like:
7243+
7244----
7245Recording session pitou: [inactive]
7246----
7247
7248Run the cmd:ls program to fire the LTTng trigger above:
7249
7250[role="term"]
7251----
7252$ ls ~
7253----
7254
7255At this point, the `pitou` recording session should be active
7256(started). Confirm this with the man:lttng-list(1) command again:
7257
7258[role="term"]
7259----
7260# lttng list pitou
7261----
7262
7263The first line should now look like:
7264
7265----
7266Recording session pitou: [active]
7267----
7268
7269This line confirms that the LTTng trigger you added fired, therefore
7270starting the `pitou` recording session.
7271====
7272
7273.[[trigger-event-notif]]Send a notification to a user application when an event rule matches.
7274====
7275This example shows how to add the following trigger to the root
7276<<lttng-sessiond,session daemon>>:
7277
7278Condition::
7279 An event rule matches a Linux kernel tracepoint event named
7280 `sched_switch` and of which the value of the `next_comm` payload
7281 field is `bash`.
7282+
7283With such an event rule, LTTng emits an event when Linux gives access to
7284the processor to a process named `bash`.
7285
7286Action::
7287 Send an LTTng notification to a user application.
7288
7289Moreover, we'll specify a _capture descriptor_ with the
7290`event-rule-matches` trigger condition so that the user application can
7291get the value of a specific `sched_switch` event payload field.
7292
7293First, write and build the user application:
7294
7295. Create the C{nbsp}source file of the application:
7296+
7297--
7298[source,c]
7299.path:{notif-app.c}
7300----
7301#include <stdlib.h>
7302#include <stdio.h>
7303#include <stdbool.h>
7304#include <assert.h>
7305#include <string.h>
7306#include <lttng/lttng.h>
7307
7308/*
7309 * Subscribes to notifications, through the notification channel
7310 * `notification_channel`, which match the condition of the trigger
7311 * named `trigger_name`.
7312 *
7313 * Returns `true` on success.
7314 */
7315static bool subscribe(struct lttng_notification_channel *notification_channel,
7316 const char *trigger_name)
7317{
7318 const struct lttng_condition *condition = NULL;
7319 struct lttng_triggers *triggers = NULL;
7320 unsigned int trigger_count;
7321 unsigned int i;
7322 enum lttng_error_code error_code;
7323 enum lttng_trigger_status trigger_status;
7324 bool ret = false;
7325
7326 /* Get all LTTng triggers */
7327 error_code = lttng_list_triggers(&triggers);
7328 assert(error_code == LTTNG_OK);
7329
7330 /* Get the number of triggers */
7331 trigger_status = lttng_triggers_get_count(triggers, &trigger_count);
7332 assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
7333
7334 /* Find the trigger named `trigger_name` */
7335 for (i = 0; i < trigger_count; i++) {
7336 const struct lttng_trigger *trigger;
7337 const char *this_trigger_name;
7338
7339 trigger = lttng_triggers_get_at_index(triggers, i);
7340 trigger_status = lttng_trigger_get_name(trigger, &this_trigger_name);
7341 assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
7342
7343 if (strcmp(this_trigger_name, trigger_name) == 0) {
7344 /* Trigger found: subscribe with its condition */
7345 enum lttng_notification_channel_status notification_channel_status;
7346
7347 notification_channel_status = lttng_notification_channel_subscribe(
7348 notification_channel,
7349 lttng_trigger_get_const_condition(trigger));
7350 assert(notification_channel_status ==
7351 LTTNG_NOTIFICATION_CHANNEL_STATUS_OK);
7352 ret = true;
7353 break;
7354 }
7355 }
7356
7357 lttng_triggers_destroy(triggers);
7358 return ret;
7359}
7360
7361/*
7362 * Handles the evaluation `evaluation` of a single notification.
7363 */
7364static void handle_evaluation(const struct lttng_evaluation *evaluation)
7365{
7366 enum lttng_evaluation_status evaluation_status;
7367 const struct lttng_event_field_value *array_field_value;
7368 const struct lttng_event_field_value *string_field_value;
7369 enum lttng_event_field_value_status event_field_value_status;
7370 const char *string_field_string_value;
7371
7372 /* Get the value of the first captured (string) field */
7373 evaluation_status = lttng_evaluation_event_rule_matches_get_captured_values(
7374 evaluation, &array_field_value);
7375 assert(evaluation_status == LTTNG_EVALUATION_STATUS_OK);
7376 event_field_value_status =
7377 lttng_event_field_value_array_get_element_at_index(
7378 array_field_value, 0, &string_field_value);
7379 assert(event_field_value_status == LTTNG_EVENT_FIELD_VALUE_STATUS_OK);
7380 assert(lttng_event_field_value_get_type(string_field_value) ==
7381 LTTNG_EVENT_FIELD_VALUE_TYPE_STRING);
7382 event_field_value_status = lttng_event_field_value_string_get_value(
7383 string_field_value, &string_field_string_value);
7384 assert(event_field_value_status == LTTNG_EVENT_FIELD_VALUE_STATUS_OK);
7385
7386 /* Print the string value of the field */
7387 puts(string_field_string_value);
7388}
7389
7390int main(int argc, char *argv[])
7391{
7392 int exit_status = EXIT_SUCCESS;
7393 struct lttng_notification_channel *notification_channel;
7394 enum lttng_notification_channel_status notification_channel_status;
7395 const struct lttng_condition *condition;
7396 const char *trigger_name;
7397 bool subscribe_res;
7398
7399 assert(argc >= 2);
7400 trigger_name = argv[1];
7401
7402 /*
7403 * Create a notification channel.
7404 *
7405 * A notification channel connects the user application to the LTTng
7406 * session daemon.
7407 *
7408 * You can use this notification channel to listen to various types
7409 * of notifications.
7410 */
7411 notification_channel = lttng_notification_channel_create(
7412 lttng_session_daemon_notification_endpoint);
7413 assert(notification_channel);
7414
7415 /*
7416 * Subscribe to notifications which match the condition of the
7417 * trigger named `trigger_name`.
7418 */
7419 if (!subscribe(notification_channel, trigger_name)) {
7420 fprintf(stderr,
7421 "Error: Failed to subscribe to notifications (trigger `%s`).\n",
7422 trigger_name);
7423 exit_status = EXIT_FAILURE;
7424 goto end;
7425 }
7426
7427 /*
7428 * Notification loop.
7429 *
7430 * Put this in a dedicated thread to avoid blocking the main thread.
7431 */
7432 while (true) {
7433 struct lttng_notification *notification;
7434 enum lttng_notification_channel_status status;
7435 const struct lttng_evaluation *notification_evaluation;
7436
7437 /* Receive the next notification */
7438 status = lttng_notification_channel_get_next_notification(
7439 notification_channel, &notification);
7440
7441 switch (status) {
7442 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK:
7443 break;
7444 case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED:
7445 /*
7446 * The session daemon can drop notifications if a receiving
7447 * application doesn't consume the notifications fast
7448 * enough.
7449 */
7450 continue;
7451 case LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED:
7452 /*
7453 * The session daemon closed the notification channel.
7454 *
7455 * This is typically caused by a session daemon shutting
7456 * down.
7457 */
7458 goto end;
7459 default:
7460 /* Unhandled conditions or errors */
7461 exit_status = EXIT_FAILURE;
7462 goto end;
7463 }
7464
7465 /*
7466 * Handle the condition evaluation.
7467 *
7468 * A notification provides, amongst other things:
7469 *
7470 * * The condition that caused LTTng to send this notification.
7471 *
7472 * * The condition evaluation, which provides more specific
7473 * information on the evaluation of the condition.
7474 */
7475 handle_evaluation(lttng_notification_get_evaluation(notification));
7476
7477 /* Destroy the notification object */
7478 lttng_notification_destroy(notification);
7479 }
7480
7481end:
7482 lttng_notification_channel_destroy(notification_channel);
7483 return exit_status;
7484}
7485----
7486--
7487+
7488This application prints the first captured string field value of the
7489condition evaluation of each LTTng notification it receives.
7490
7491. Build the `notif-app` application,
7492 using https://www.freedesktop.org/wiki/Software/pkg-config/[pkg-config]
7493 to provide the right compiler and linker flags:
7494+
7495--
7496[role="term"]
7497----
7498$ gcc -o notif-app notif-app.c $(pkg-config --cflags --libs lttng-ctl)
7499----
7500--
7501
7502Now, to add the trigger to the root session daemon:
7503
7504[start=3]
7505. **If there's no currently running LTTng root session daemon**, start
7506 one:
7507+
7508[role="term"]
7509----
7510# lttng-sessiond --daemonize
7511----
7512
7513. Add the trigger, naming it `sched-switch-notif`, to the root
7514 session daemon:
7515+
7516[role="term"]
7517----
7518# lttng add-trigger --name=sched-switch-notif \
7519 --condition=event-rule-matches \
7520 --type=kernel --name=sched_switch \
7521 --filter='next_comm == "bash"' --capture=prev_comm \
7522 --action=notify
7523----
7524+
7525Confirm that the `sched-switch-notif` trigger exists with the
7526man:lttng-list-triggers(1) command:
7527+
7528[role="term"]
7529----
7530# lttng list-triggers
7531----
7532
7533Run the cmd:notif-app application, passing the name of the trigger
7534of which to watch the notifications:
7535
7536[role="term"]
7537----
7538# ./notif-app sched-switch-notif
7539----
7540
7541Now, in an interactive Bash, type a few keys to fire the
7542`sched-switch-notif` trigger. Watch the `notif-app` application print
7543the previous process names.
7544====
7545
7546[role="since-2.6"]
7547[[mi]]
7548=== Use the machine interface
7549
7550With any command of the man:lttng(1) command-line tool, set the
7551opt:lttng(1):--mi option to `xml` (before the command name) to get an
7552XML machine interface output, for example:
7553
7554[role="term"]
7555----
7556$ lttng --mi=xml list my-session
7557----
7558
7559A schema definition (XSD) is
7560https://github.com/lttng/lttng-tools/blob/stable-{revision}/src/common/mi-lttng-4.0.xsd[available]
7561to ease the integration with external tools as much as possible.
7562
7563
7564[role="since-2.8"]
7565[[metadata-regenerate]]
7566=== Regenerate the metadata of an LTTng trace
7567
7568An LTTng trace, which is a https://diamon.org/ctf[CTF] trace, has both
7569data stream files and a metadata stream file. This metadata file
7570contains, amongst other things, information about the offset of the
7571clock sources which LTTng uses to assign timestamps to <<event,event
7572records>> when recording.
7573
7574If, once a <<tracing-session,recording session>> is
7575<<basic-tracing-session-control,started>>, a major
7576https://en.wikipedia.org/wiki/Network_Time_Protocol[NTP] correction
7577happens, the clock offset of the trace also needs to be updated. Use
7578the `metadata` item of the man:lttng-regenerate(1) command to do so.
7579
7580The main use case of this command is to allow a system to boot with
7581an incorrect wall time and have LTTng trace it before its wall time
7582is corrected. Once the system is known to be in a state where its
7583wall time is correct, you can run `lttng regenerate metadata`.
7584
7585To regenerate the metadata stream files of the
7586<<cur-tracing-session,current recording session>>:
7587
7588* Use the `metadata` item of the man:lttng-regenerate(1) command:
7589+
7590--
7591[role="term"]
7592----
7593$ lttng regenerate metadata
7594----
7595--
7596
7597
7598[role="since-2.9"]
7599[[regenerate-statedump]]
7600=== Regenerate the state dump event records of a recording session
7601
7602The LTTng kernel and user space tracers generate state dump
7603<<event,event records>> when the application starts or when you
7604<<basic-tracing-session-control,start a recording session>>.
7605
7606An analysis can use the state dump event records to set an initial state
7607before it builds the rest of the state from the subsequent event
7608records. http://tracecompass.org/[Trace Compass] and
7609https://github.com/lttng/lttng-analyses[LTTng analyses] are notable
7610examples of applications which use the state dump of an LTTng trace.
7611
7612When you <<taking-a-snapshot,take a snapshot>>, it's possible that the
7613state dump event records aren't included in the snapshot trace files
7614because they were recorded to a <<channel,sub-buffer>> that has been
7615consumed or <<overwrite-mode,overwritten>> already.
7616
7617Use the `statedump` item of the man:lttng-regenerate(1) command to emit
7618and record the state dump events again.
7619
7620To regenerate the state dump of the <<cur-tracing-session,current
7621recording session>>, provided you created it in <<snapshot-mode,snapshot
7622mode>>, before you take a snapshot:
7623
7624. Use the `statedump` item of the man:lttng-regenerate(1) command:
7625+
7626--
7627[role="term"]
7628----
7629$ lttng regenerate statedump
7630----
7631--
7632
7633. <<basic-tracing-session-control,Stop the recording session>>:
7634+
7635--
7636[role="term"]
7637----
7638$ lttng stop
7639----
7640--
7641
7642. <<taking-a-snapshot,Take a snapshot>>:
7643+
7644--
7645[role="term"]
7646----
7647$ lttng snapshot record --name=my-snapshot
7648----
7649--
7650
7651Depending on the event throughput, you should run steps{nbsp}1
7652and{nbsp}2 as closely as possible.
7653
7654[NOTE]
7655====
7656To record the state dump events, you need to
7657<<enabling-disabling-events,create recording event rules>> which enable
7658them:
7659
7660* The names of LTTng-UST state dump tracepoints start with
7661 `lttng_ust_statedump:`.
7662
7663* The names of LTTng-modules state dump tracepoints start with
7664 `lttng_statedump_`.
7665====
7666
7667
7668[role="since-2.7"]
7669[[persistent-memory-file-systems]]
7670=== Record trace data on persistent memory file systems
7671
7672https://en.wikipedia.org/wiki/Non-volatile_random-access_memory[Non-volatile
7673random-access memory] (NVRAM) is random-access memory that retains its
7674information when power is turned off (non-volatile). Systems with such
7675memory can store data structures in RAM and retrieve them after a
7676reboot, without flushing to typical _storage_.
7677
7678Linux supports NVRAM file systems thanks to either
7679http://pramfs.sourceforge.net/[PRAMFS] or
7680https://www.kernel.org/doc/Documentation/filesystems/dax.txt[DAX]{nbsp}+{nbsp}http://lkml.iu.edu/hypermail/linux/kernel/1504.1/03463.html[pmem]
7681(requires Linux{nbsp}4.1+).
7682
7683This section doesn't describe how to operate such file systems; we
7684assume that you have a working persistent memory file system.
7685
7686When you <<creating-destroying-tracing-sessions,create a recording
7687session>>, you can specify the path of the shared memory holding the
7688sub-buffers. If you specify a location on an NVRAM file system, then you
7689can retrieve the latest recorded trace data when the system reboots
7690after a crash.
7691
7692To record trace data on a persistent memory file system and retrieve the
7693trace data after a system crash:
7694
7695. Create a recording session with a <<channel,sub-buffer>> shared memory
7696 path located on an NVRAM file system:
7697+
7698--
7699[role="term"]
7700----
7701$ lttng create my-session --shm-path=/path/to/shm/on/nvram
7702----
7703--
7704
7705. Configure the recording session as usual with the man:lttng(1)
7706 command-line tool, and <<basic-tracing-session-control,start
7707 recording>>.
7708
7709. After a system crash, use the man:lttng-crash(1) command-line tool to
7710 read the trace data recorded on the NVRAM file system:
7711+
7712--
7713[role="term"]
7714----
7715$ lttng-crash /path/to/shm/on/nvram
7716----
7717--
7718
7719The binary layout of the ring buffer files isn't exactly the same as the
7720trace files layout. This is why you need to use man:lttng-crash(1)
7721instead of some standard LTTng trace reader.
7722
7723To convert the ring buffer files to LTTng trace files:
7724
7725* Use the opt:lttng-crash(1):--extract option of man:lttng-crash(1):
7726+
7727--
7728[role="term"]
7729----
7730$ lttng-crash --extract=/path/to/trace /path/to/shm/on/nvram
7731----
7732--
7733
7734
7735[role="since-2.10"]
7736[[notif-trigger-api]]
7737=== Get notified when the buffer usage of a channel is too high or too low
7738
7739With the notification and <<trigger,trigger>> C{nbsp}API of
7740<<liblttng-ctl-lttng,`liblttng-ctl`>>, LTTng can notify your user
7741application when the buffer usage of one or more <<channel,channels>>
7742becomes too low or too high.
7743
7744Use this API and enable or disable <<event,recording event rules>> while
7745a recording session <<basic-tracing-session-control,is active>> to avoid
7746<<channel-overwrite-mode-vs-discard-mode,discarded event records>>, for
7747example.
7748
7749.Send a notification to a user application when the buffer usage of an LTTng channel is too high.
7750====
7751In this example, we create and build an application which gets notified
7752when the buffer usage of a specific LTTng channel is higher than
775375{nbsp}%.
7754
7755We only print that it's the case in this example, but we could as well
7756use the `liblttng-ctl` C{nbsp}API to <<enabling-disabling-events,disable
7757recording event rules>> when this happens, for example.
7758
7759. Create the C{nbsp}source file of the application:
7760+
7761--
7762[source,c]
7763.path:{notif-app.c}
7764----
7765#include <stdlib.h>
7766#include <stdio.h>
7767#include <assert.h>
7768#include <lttng/lttng.h>
7769
7770int main(int argc, char *argv[])
7771{
7772 int exit_status = EXIT_SUCCESS;
7773 struct lttng_notification_channel *notification_channel;
7774 struct lttng_condition *condition;
7775 struct lttng_action *action;
7776 struct lttng_trigger *trigger;
7777 const char *recording_session_name;
7778 const char *channel_name;
7779
7780 assert(argc >= 3);
7781 recording_session_name = argv[1];
7782 channel_name = argv[2];
7783
7784 /*
7785 * Create a notification channel.
7786 *
7787 * A notification channel connects the user application to the LTTng
7788 * session daemon.
7789 *
7790 * You can use this notification channel to listen to various types
7791 * of notifications.
7792 */
7793 notification_channel = lttng_notification_channel_create(
7794 lttng_session_daemon_notification_endpoint);
7795
7796 /*
7797 * Create a "buffer usage becomes greater than" condition.
7798 *
7799 * In this case, the condition is satisfied when the buffer usage
7800 * becomes greater than or equal to 75 %.
7801 *
7802 * We create the condition for a specific recording session name,
7803 * channel name, and for the user space tracing domain.
7804 *
7805 * The following condition types also exist:
7806 *
7807 * * The buffer usage of a channel becomes less than a given value.
7808 *
7809 * * The consumed data size of a recording session becomes greater
7810 * than a given value.
7811 *
7812 * * A recording session rotation becomes ongoing.
7813 *
7814 * * A recording session rotation becomes completed.
7815 *
7816 * * A given event rule matches an event.
7817 */
7818 condition = lttng_condition_buffer_usage_high_create();
7819 lttng_condition_buffer_usage_set_threshold_ratio(condition, .75);
7820 lttng_condition_buffer_usage_set_session_name(condition,
7821 recording_session_name);
7822 lttng_condition_buffer_usage_set_channel_name(condition,
7823 channel_name);
7824 lttng_condition_buffer_usage_set_domain_type(condition,
7825 LTTNG_DOMAIN_UST);
7826
7827 /*
7828 * Create an action (receive a notification) to execute when the
7829 * condition created above is satisfied.
7830 */
7831 action = lttng_action_notify_create();
7832
7833 /*
7834 * Create a trigger.
7835 *
7836 * A trigger associates a condition to an action: LTTng executes
7837 * the action when the condition is satisfied.
7838 */
7839 trigger = lttng_trigger_create(condition, action);
7840
7841 /* Register the trigger to the LTTng session daemon. */
7842 lttng_register_trigger(trigger);
7843
7844 /*
7845 * Now that we have registered a trigger, LTTng will send a
7846 * notification every time its condition is met through a
7847 * notification channel.
7848 *
7849 * To receive this notification, we must subscribe to notifications
7850 * which match the same condition.
7851 */
7852 lttng_notification_channel_subscribe(notification_channel,
7853 condition);
7854
7855 /*
7856 * Notification loop.
7857 *
7858 * Put this in a dedicated thread to avoid blocking the main thread.
7859 */
7860 for (;;) {
7861 struct lttng_notification *notification;
7862 enum lttng_notification_channel_status status;
7863 const struct lttng_evaluation *notification_evaluation;
7864 const struct lttng_condition *notification_condition;
7865 double buffer_usage;
7866
7867 /* Receive the next notification. */
7868 status = lttng_notification_channel_get_next_notification(
7869 notification_channel, &notification);
7870
7871 switch (status) {
7872 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK:
7873 break;
7874 case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED:
7875 /*
7876 * The session daemon can drop notifications if a monitoring
7877 * application isn't consuming the notifications fast
7878 * enough.
7879 */
7880 continue;
7881 case LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED:
7882 /*
7883 * The session daemon closed the notification channel.
7884 *
7885 * This is typically caused by a session daemon shutting
7886 * down.
7887 */
7888 goto end;
7889 default:
7890 /* Unhandled conditions or errors. */
7891 exit_status = EXIT_FAILURE;
7892 goto end;
7893 }
7894
7895 /*
7896 * A notification provides, amongst other things:
7897 *
7898 * * The condition that caused LTTng to send this notification.
7899 *
7900 * * The condition evaluation, which provides more specific
7901 * information on the evaluation of the condition.
7902 *
7903 * The condition evaluation provides the buffer usage
7904 * value at the moment the condition was satisfied.
7905 */
7906 notification_condition = lttng_notification_get_condition(
7907 notification);
7908 notification_evaluation = lttng_notification_get_evaluation(
7909 notification);
7910
7911 /* We're subscribed to only one condition. */
7912 assert(lttng_condition_get_type(notification_condition) ==
7913 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH);
7914
7915 /*
7916 * Get the exact sampled buffer usage from the condition
7917 * evaluation.
7918 */
7919 lttng_evaluation_buffer_usage_get_usage_ratio(
7920 notification_evaluation, &buffer_usage);
7921
7922 /*
7923 * At this point, instead of printing a message, we could do
7924 * something to reduce the buffer usage of the channel, like
7925 * disable specific events, for example.
7926 */
7927 printf("Buffer usage is %f %% in recording session \"%s\", "
7928 "user space channel \"%s\".\n", buffer_usage * 100,
7929 recording_session_name, channel_name);
7930
7931 /* Destroy the notification object. */
7932 lttng_notification_destroy(notification);
7933 }
7934
7935end:
7936 lttng_action_destroy(action);
7937 lttng_condition_destroy(condition);
7938 lttng_trigger_destroy(trigger);
7939 lttng_notification_channel_destroy(notification_channel);
7940 return exit_status;
7941}
7942----
7943--
7944
7945. Build the `notif-app` application, linking it with `liblttng-ctl`:
7946+
7947--
7948[role="term"]
7949----
7950$ gcc -o notif-app notif-app.c $(pkg-config --cflags --libs lttng-ctl)
7951----
7952--
7953
7954. <<creating-destroying-tracing-sessions,Create a recording session>>,
7955 <<enabling-disabling-events,create a recording event rule>> matching
7956 all the user space tracepoint events, and
7957 <<basic-tracing-session-control,start recording>>:
7958+
7959--
7960[role="term"]
7961----
7962$ lttng create my-session
7963$ lttng enable-event --userspace --all
7964$ lttng start
7965----
7966--
7967+
7968If you create the channel manually with the man:lttng-enable-channel(1)
7969command, you can set its <<channel-monitor-timer,monitor timer>> to
7970control how frequently LTTng samples the current values of the channel
7971properties to evaluate user conditions.
7972
7973. Run the `notif-app` application.
7974+
7975This program accepts the <<tracing-session,recording session>> and
7976user space channel names as its two first arguments. The channel
7977which LTTng automatically creates with the man:lttng-enable-event(1)
7978command above is named `channel0`:
7979+
7980--
7981[role="term"]
7982----
7983$ ./notif-app my-session channel0
7984----
7985--
7986
7987. In another terminal, run an application with a very high event
7988 throughput so that the 75{nbsp}% buffer usage condition is reached.
7989+
7990In the first terminal, the application should print lines like this:
7991+
7992----
7993Buffer usage is 81.45197 % in recording session "my-session", user space
7994channel "channel0".
7995----
7996+
7997If you don't see anything, try to make the threshold of the condition in
7998path:{notif-app.c} lower (0.1{nbsp}%, for example), and then rebuild the
7999`notif-app` application (step{nbsp}2) and run it again (step{nbsp}4).
8000====
8001
8002
8003[[reference]]
8004== Reference
8005
8006[[lttng-modules-ref]]
8007=== noch:{LTTng-modules}
8008
8009
8010[role="since-2.9"]
8011[[lttng-tracepoint-enum]]
8012==== `LTTNG_TRACEPOINT_ENUM()` usage
8013
8014Use the `LTTNG_TRACEPOINT_ENUM()` macro to define an enumeration:
8015
8016[source,c]
8017----
8018LTTNG_TRACEPOINT_ENUM(name, TP_ENUM_VALUES(entries))
8019----
8020
8021Replace:
8022
8023* `name` with the name of the enumeration (C identifier, unique
8024 amongst all the defined enumerations).
8025* `entries` with a list of enumeration entries.
8026
8027The available enumeration entry macros are:
8028
8029+ctf_enum_value(__name__, __value__)+::
8030 Entry named +__name__+ mapped to the integral value +__value__+.
8031
8032+ctf_enum_range(__name__, __begin__, __end__)+::
8033 Entry named +__name__+ mapped to the range of integral values between
8034 +__begin__+ (included) and +__end__+ (included).
8035
8036+ctf_enum_auto(__name__)+::
8037 Entry named +__name__+ mapped to the integral value following the
8038 last mapping value.
8039+
8040The last value of a `ctf_enum_value()` entry is its +__value__+
8041parameter.
8042+
8043The last value of a `ctf_enum_range()` entry is its +__end__+ parameter.
8044+
8045If `ctf_enum_auto()` is the first entry in the list, its integral
8046value is 0.
8047
8048Use the `ctf_enum()` <<lttng-modules-tp-fields,field definition macro>>
8049to use a defined enumeration as a tracepoint field.
8050
8051.Define an enumeration with `LTTNG_TRACEPOINT_ENUM()`.
8052====
8053[source,c]
8054----
8055LTTNG_TRACEPOINT_ENUM(
8056 my_enum,
8057 TP_ENUM_VALUES(
8058 ctf_enum_auto("AUTO: EXPECT 0")
8059 ctf_enum_value("VALUE: 23", 23)
8060 ctf_enum_value("VALUE: 27", 27)
8061 ctf_enum_auto("AUTO: EXPECT 28")
8062 ctf_enum_range("RANGE: 101 TO 303", 101, 303)
8063 ctf_enum_auto("AUTO: EXPECT 304")
8064 )
8065)
8066----
8067====
8068
8069
8070[role="since-2.7"]
8071[[lttng-modules-tp-fields]]
8072==== Tracepoint fields macros (for `TP_FIELDS()`)
8073
8074[[tp-fast-assign]][[tp-struct-entry]]The available macros to define
8075tracepoint fields, which must be listed within `TP_FIELDS()` in
8076`LTTNG_TRACEPOINT_EVENT()`, are:
8077
8078[role="func-desc growable",cols="asciidoc,asciidoc"]
8079.Available macros to define LTTng-modules tracepoint fields
8080|====
8081|Macro |Description and parameters
8082
8083|
8084+ctf_integer(__t__, __n__, __e__)+
8085
8086+ctf_integer_nowrite(__t__, __n__, __e__)+
8087
8088+ctf_user_integer(__t__, __n__, __e__)+
8089
8090+ctf_user_integer_nowrite(__t__, __n__, __e__)+
8091|
8092Standard integer, displayed in base{nbsp}10.
8093
8094+__t__+::
8095 Integer C type (`int`, `long`, `size_t`, ...).
8096
8097+__n__+::
8098 Field name.
8099
8100+__e__+::
8101 Argument expression.
8102
8103|
8104+ctf_integer_hex(__t__, __n__, __e__)+
8105
8106+ctf_user_integer_hex(__t__, __n__, __e__)+
8107|
8108Standard integer, displayed in base{nbsp}16.
8109
8110+__t__+::
8111 Integer C type.
8112
8113+__n__+::
8114 Field name.
8115
8116+__e__+::
8117 Argument expression.
8118
8119|+ctf_integer_oct(__t__, __n__, __e__)+
8120|
8121Standard integer, displayed in base{nbsp}8.
8122
8123+__t__+::
8124 Integer C type.
8125
8126+__n__+::
8127 Field name.
8128
8129+__e__+::
8130 Argument expression.
8131
8132|
8133+ctf_integer_network(__t__, __n__, __e__)+
8134
8135+ctf_user_integer_network(__t__, __n__, __e__)+
8136|
8137Integer in network byte order (big-endian), displayed in base{nbsp}10.
8138
8139+__t__+::
8140 Integer C type.
8141
8142+__n__+::
8143 Field name.
8144
8145+__e__+::
8146 Argument expression.
8147
8148|
8149+ctf_integer_network_hex(__t__, __n__, __e__)+
8150
8151+ctf_user_integer_network_hex(__t__, __n__, __e__)+
8152|
8153Integer in network byte order, displayed in base{nbsp}16.
8154
8155+__t__+::
8156 Integer C type.
8157
8158+__n__+::
8159 Field name.
8160
8161+__e__+::
8162 Argument expression.
8163
8164|
8165+ctf_enum(__N__, __t__, __n__, __e__)+
8166
8167+ctf_enum_nowrite(__N__, __t__, __n__, __e__)+
8168
8169+ctf_user_enum(__N__, __t__, __n__, __e__)+
8170
8171+ctf_user_enum_nowrite(__N__, __t__, __n__, __e__)+
8172|
8173Enumeration.
8174
8175+__N__+::
8176 Name of a <<lttng-tracepoint-enum,previously defined enumeration>>.
8177
8178+__t__+::
8179 Integer C type (`int`, `long`, `size_t`, ...).
8180
8181+__n__+::
8182 Field name.
8183
8184+__e__+::
8185 Argument expression.
8186
8187|
8188+ctf_string(__n__, __e__)+
8189
8190+ctf_string_nowrite(__n__, __e__)+
8191
8192+ctf_user_string(__n__, __e__)+
8193
8194+ctf_user_string_nowrite(__n__, __e__)+
8195|
8196Null-terminated string; undefined behavior if +__e__+ is `NULL`.
8197
8198+__n__+::
8199 Field name.
8200
8201+__e__+::
8202 Argument expression.
8203
8204|
8205+ctf_array(__t__, __n__, __e__, __s__)+
8206
8207+ctf_array_nowrite(__t__, __n__, __e__, __s__)+
8208
8209+ctf_user_array(__t__, __n__, __e__, __s__)+
8210
8211+ctf_user_array_nowrite(__t__, __n__, __e__, __s__)+
8212|
8213Statically-sized array of integers.
8214
8215+__t__+::
8216 Array element C type.
8217
8218+__n__+::
8219 Field name.
8220
8221+__e__+::
8222 Argument expression.
8223
8224+__s__+::
8225 Number of elements.
8226
8227|
8228+ctf_array_bitfield(__t__, __n__, __e__, __s__)+
8229
8230+ctf_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
8231
8232+ctf_user_array_bitfield(__t__, __n__, __e__, __s__)+
8233
8234+ctf_user_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
8235|
8236Statically-sized array of bits.
8237
8238The type of +__e__+ must be an integer type. +__s__+ is the number
8239of elements of such type in +__e__+, not the number of bits.
8240
8241+__t__+::
8242 Array element C type.
8243
8244+__n__+::
8245 Field name.
8246
8247+__e__+::
8248 Argument expression.
8249
8250+__s__+::
8251 Number of elements.
8252
8253|
8254+ctf_array_text(__t__, __n__, __e__, __s__)+
8255
8256+ctf_array_text_nowrite(__t__, __n__, __e__, __s__)+
8257
8258+ctf_user_array_text(__t__, __n__, __e__, __s__)+
8259
8260+ctf_user_array_text_nowrite(__t__, __n__, __e__, __s__)+
8261|
8262Statically-sized array, printed as text.
8263
8264The string doesn't need to be null-terminated.
8265
8266+__t__+::
8267 Array element C type (always `char`).
8268
8269+__n__+::
8270 Field name.
8271
8272+__e__+::
8273 Argument expression.
8274
8275+__s__+::
8276 Number of elements.
8277
8278|
8279+ctf_sequence(__t__, __n__, __e__, __T__, __E__)+
8280
8281+ctf_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
8282
8283+ctf_user_sequence(__t__, __n__, __e__, __T__, __E__)+
8284
8285+ctf_user_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
8286|
8287Dynamically-sized array of integers.
8288
8289The type of +__E__+ must be unsigned.
8290
8291+__t__+::
8292 Array element C type.
8293
8294+__n__+::
8295 Field name.
8296
8297+__e__+::
8298 Argument expression.
8299
8300+__T__+::
8301 Length expression C type.
8302
8303+__E__+::
8304 Length expression.
8305
8306|
8307+ctf_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
8308
8309+ctf_user_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
8310|
8311Dynamically-sized array of integers, displayed in base{nbsp}16.
8312
8313The type of +__E__+ must be unsigned.
8314
8315+__t__+::
8316 Array element C type.
8317
8318+__n__+::
8319 Field name.
8320
8321+__e__+::
8322 Argument expression.
8323
8324+__T__+::
8325 Length expression C type.
8326
8327+__E__+::
8328 Length expression.
8329
8330|+ctf_sequence_network(__t__, __n__, __e__, __T__, __E__)+
8331|
8332Dynamically-sized array of integers in network byte order (big-endian),
8333displayed in base{nbsp}10.
8334
8335The type of +__E__+ must be unsigned.
8336
8337+__t__+::
8338 Array element C type.
8339
8340+__n__+::
8341 Field name.
8342
8343+__e__+::
8344 Argument expression.
8345
8346+__T__+::
8347 Length expression C type.
8348
8349+__E__+::
8350 Length expression.
8351
8352|
8353+ctf_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
8354
8355+ctf_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
8356
8357+ctf_user_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
8358
8359+ctf_user_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
8360|
8361Dynamically-sized array of bits.
8362
8363The type of +__e__+ must be an integer type. +__s__+ is the number
8364of elements of such type in +__e__+, not the number of bits.
8365
8366The type of +__E__+ must be unsigned.
8367
8368+__t__+::
8369 Array element C type.
8370
8371+__n__+::
8372 Field name.
8373
8374+__e__+::
8375 Argument expression.
8376
8377+__T__+::
8378 Length expression C type.
8379
8380+__E__+::
8381 Length expression.
8382
8383|
8384+ctf_sequence_text(__t__, __n__, __e__, __T__, __E__)+
8385
8386+ctf_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
8387
8388+ctf_user_sequence_text(__t__, __n__, __e__, __T__, __E__)+
8389
8390+ctf_user_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
8391|
8392Dynamically-sized array, displayed as text.
8393
8394The string doesn't need to be null-terminated.
8395
8396The type of +__E__+ must be unsigned.
8397
8398The behaviour is undefined if +__e__+ is `NULL`.
8399
8400+__t__+::
8401 Sequence element C type (always `char`).
8402
8403+__n__+::
8404 Field name.
8405
8406+__e__+::
8407 Argument expression.
8408
8409+__T__+::
8410 Length expression C type.
8411
8412+__E__+::
8413 Length expression.
8414|====
8415
8416Use the `_user` versions when the argument expression, `e`, is
8417a user space address. In the cases of `ctf_user_integer*()` and
8418`ctf_user_float*()`, `&e` must be a user space address, thus `e` must
8419be addressable.
8420
8421The `_nowrite` versions omit themselves from the trace data, but are
8422otherwise identical. This means LTTng won't write the `_nowrite` fields
8423to the recorded trace. Their primary purpose is to make some of the
8424event context available to the <<enabling-disabling-events,recording
8425event rule filters>> without having to commit the data to
8426<<channel,sub-buffers>>.
8427
8428
8429[[glossary]]
8430== Glossary
8431
8432Terms related to LTTng and to tracing in general:
8433
8434[[def-action]]action::
8435 The part of a <<def-trigger,trigger>> which LTTng executes when the
8436 trigger <<def-condition,condition>> is satisfied.
8437
8438Babeltrace::
8439 The https://diamon.org/babeltrace[Babeltrace] project, which includes:
8440+
8441* The
8442 https://babeltrace.org/docs/v2.0/man1/babeltrace2.1/[cmd:babeltrace2]
8443 command-line interface.
8444* The libbabeltrace2 library which offers a
8445 https://babeltrace.org/docs/v2.0/libbabeltrace2/[C API].
8446* https://babeltrace.org/docs/v2.0/python/bt2/[Python{nbsp}3 bindings].
8447* Plugins.
8448
8449[[def-buffering-scheme]]<<channel-buffering-schemes,buffering scheme>>::
8450 A layout of <<def-sub-buffer,sub-buffers>> applied to a given channel.
8451
8452[[def-channel]]<<channel,channel>>::
8453 An entity which is responsible for a set of
8454 <<def-ring-buffer,ring buffers>>.
8455+
8456<<def-recording-event-rule,Recording event rules>> are always attached
8457to a specific channel.
8458
8459clock::
8460 A source of time for a <<def-tracer,tracer>>.
8461
8462[[def-condition]]condition::
8463 The part of a <<def-trigger,trigger>> which must be satisfied for
8464 LTTng to attempt to execute the trigger <<def-action,actions>>.
8465
8466[[def-consumer-daemon]]<<lttng-consumerd,consumer daemon>>::
8467 A program which is responsible for consuming the full
8468 <<def-sub-buffer,sub-buffers>> and write them to a file system or
8469 send them over the network.
8470
8471[[def-current-trace-chunk]]current trace chunk::
8472 A <<def-trace-chunk,trace chunk>> which includes the current content
8473 of all the <<def-sub-buffer,sub-buffers>> of the
8474 <<def-tracing-session,recording session>> and the stream files
8475 produced since the latest event amongst:
8476+
8477* The creation of the recording session.
8478* The last <<def-tracing-session-rotation,recording session rotation>>, if
8479 any.
8480
8481<<channel-overwrite-mode-vs-discard-mode,discard mode>>::
8482 The <<def-event-record-loss-mode,event record loss mode>> in which
8483 the <<def-tracer,tracer>> _discards_ new <<def-event-record,event
8484 records>> when there's no <<def-sub-buffer,sub-buffer>> space left to
8485 store them.
8486
8487[[def-event]]event::
8488 The execution of an <<def-instrumentation-point,instrumentation
8489 point>>, like a <<def-tracepoint,tracepoint>> that you manually place
8490 in some source code, or a Linux kprobe.
8491+
8492When an instrumentation point is executed, LTTng creates an event.
8493+
8494When an <<def-event-rule,event rule>> matches the event,
8495<<def-lttng,LTTng>> executes some action, for example:
8496+
8497* Record its payload to a <<def-sub-buffer,sub-buffer>> as an
8498 <<def-event-record,event record>>.
8499* Attempt to execute the user-defined actions of a
8500 <<def-trigger,trigger>> with an
8501 <<add-event-rule-matches-trigger,``event rule matches''>> condition.
8502
8503[[def-event-name]]event name::
8504 The name of an <<def-event,event>>, which is also the name of the
8505 <<def-event-record,event record>>.
8506+
8507This is also called the _instrumentation point name_.
8508
8509[[def-event-record]]event record::
8510 A record (binary serialization), in a <<def-trace,trace>>, of the
8511 payload of an <<def-event,event>>.
8512+
8513The payload of an event record has zero or more _fields_.
8514
8515[[def-event-record-loss-mode]]<<channel-overwrite-mode-vs-discard-mode,event record loss mode>>::
8516 The mechanism by which event records of a given
8517 <<def-channel,channel>> are lost (not recorded) when there's no
8518 <<def-sub-buffer,sub-buffer>> space left to store them.
8519
8520[[def-event-rule]]<<event-rule,event rule>>::
8521 Set of conditions which an <<def-event,event>> must satisfy
8522 for LTTng to execute some action.
8523+
8524An event rule is said to _match_ events, like a
8525https://en.wikipedia.org/wiki/Regular_expression[regular expression]
8526matches strings.
8527+
8528A <<def-recording-event-rule,recording event rule>> is a specific type
8529of event rule of which the action is to <<def-record,record>> the event
8530to a <<def-sub-buffer,sub-buffer>>.
8531
8532[[def-incl-set]]inclusion set::
8533 In the <<pid-tracking,process attribute inclusion set>> context: a
8534 set of <<def-proc-attr,process attributes>> of a given type.
8535
8536<<instrumenting,instrumentation>>::
8537 The use of <<def-lttng,LTTng>> probes to make a kernel or
8538 <<def-user-application,user application>> traceable.
8539
8540[[def-instrumentation-point]]instrumentation point::
8541 A point in the execution path of a kernel or
8542 <<def-user-application,user application>> which, when executed,
8543 create an <<def-event,event>>.
8544
8545instrumentation point name::
8546 See _<<def-event-name,event name>>_.
8547
8548`java.util.logging`::
8549 The
8550 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[core logging facilities]
8551 of the Java platform.
8552
8553log4j::
8554 A https://logging.apache.org/log4j/1.2/[logging library] for Java
8555 developed by the Apache Software Foundation.
8556
8557log level::
8558 Level of severity of a log statement or user space
8559 <<def-instrumentation-point,instrumentation point>>.
8560
8561[[def-lttng]]LTTng::
8562 The _Linux Trace Toolkit: next generation_ project.
8563
8564<<lttng-cli,cmd:lttng>>::
8565 A command-line tool provided by the <<def-lttng-tools,LTTng-tools>>
8566 project which you can use to send and receive control messages to and
8567 from a <<def-session-daemon,session daemon>>.
8568
8569LTTng analyses::
8570 The https://github.com/lttng/lttng-analyses[LTTng analyses] project,
8571 which is a set of analyzing programs that you can use to obtain a
8572 higher level view of an <<def-lttng,LTTng>> <<def-trace,trace>>.
8573
8574cmd:lttng-consumerd::
8575 The name of the <<def-consumer-daemon,consumer daemon>> program.
8576
8577cmd:lttng-crash::
8578 A utility provided by the <<def-lttng-tools,LTTng-tools>> project
8579 which can convert <<def-ring-buffer,ring buffer>> files (usually
8580 <<persistent-memory-file-systems,saved on a persistent memory file
8581 system>>) to <<def-trace,trace>> files.
8582+
8583See man:lttng-crash(1).
8584
8585LTTng Documentation::
8586 This document.
8587
8588<<lttng-live,LTTng live>>::
8589 A communication protocol between the <<lttng-relayd,relay daemon>> and
8590 live readers which makes it possible to show or analyze
8591 <<def-event-record,event records>> ``live'', as they're received by
8592 the <<def-relay-daemon,relay daemon>>.
8593
8594<<lttng-modules,LTTng-modules>>::
8595 The https://github.com/lttng/lttng-modules[LTTng-modules] project,
8596 which contains the Linux kernel modules to make the Linux kernel
8597 <<def-instrumentation-point,instrumentation points>> available for
8598 <<def-lttng,LTTng>> tracing.
8599
8600cmd:lttng-relayd::
8601 The name of the <<def-relay-daemon,relay daemon>> program.
8602
8603cmd:lttng-sessiond::
8604 The name of the <<def-session-daemon,session daemon>> program.
8605
8606[[def-lttng-tools]]LTTng-tools::
8607 The https://github.com/lttng/lttng-tools[LTTng-tools] project, which
8608 contains the various programs and libraries used to
8609 <<controlling-tracing,control tracing>>.
8610
8611[[def-lttng-ust]]<<lttng-ust,LTTng-UST>>::
8612 The https://github.com/lttng/lttng-ust[LTTng-UST] project, which
8613 contains libraries to instrument
8614 <<def-user-application,user applications>>.
8615
8616<<lttng-ust-agents,LTTng-UST Java agent>>::
8617 A Java package provided by the <<def-lttng-ust,LTTng-UST>> project to
8618 allow the LTTng instrumentation of `java.util.logging` and Apache
8619 log4j{nbsp}1.2 logging statements.
8620
8621<<lttng-ust-agents,LTTng-UST Python agent>>::
8622 A Python package provided by the <<def-lttng-ust,LTTng-UST>> project
8623 to allow the <<def-lttng,LTTng>> instrumentation of Python logging
8624 statements.
8625
8626<<channel-overwrite-mode-vs-discard-mode,overwrite mode>>::
8627 The <<def-event-record-loss-mode,event record loss mode>> in which new
8628 <<def-event-record,event records>> _overwrite_ older event records
8629 when there's no <<def-sub-buffer,sub-buffer>> space left to store
8630 them.
8631
8632<<channel-buffering-schemes,per-process buffering>>::
8633 A <<def-buffering-scheme,buffering scheme>> in which each instrumented
8634 process has its own <<def-sub-buffer,sub-buffers>> for a given user
8635 space <<def-channel,channel>>.
8636
8637<<channel-buffering-schemes,per-user buffering>>::
8638 A <<def-buffering-scheme,buffering scheme>> in which all the processes
8639 of a Unix user share the same <<def-sub-buffer,sub-buffers>> for a
8640 given user space <<def-channel,channel>>.
8641
8642[[def-proc-attr]]process attribute::
8643 In the <<pid-tracking,process attribute inclusion set>> context:
8644+
8645* A process ID.
8646* A virtual process ID.
8647* A Unix user ID.
8648* A virtual Unix user ID.
8649* A Unix group ID.
8650* A virtual Unix group ID.
8651
8652record (_noun_)::
8653 See <<def-event-record,_event record_>>.
8654
8655[[def-record]]record (_verb_)::
8656 Serialize the binary payload of an <<def-event,event>> to a
8657 <<def-sub-buffer,sub-buffer>>.
8658
8659[[def-recording-event-rule]]<<event,recording event rule>>::
8660 Specific type of <<def-event-rule,event rule>> of which the action is
8661 to <<def-record,record>> the matched event to a
8662 <<def-sub-buffer,sub-buffer>>.
8663
8664[[def-tracing-session]][[def-recording-session]]<<tracing-session,recording session>>::
8665 A stateful dialogue between you and a <<lttng-sessiond,session daemon>>.
8666
8667[[def-tracing-session-rotation]]<<session-rotation,recording session rotation>>::
8668 The action of archiving the
8669 <<def-current-trace-chunk,current trace chunk>> of a
8670 <<def-tracing-session,recording session>>.
8671
8672[[def-relay-daemon]]<<lttng-relayd,relay daemon>>::
8673 A process which is responsible for receiving the <<def-trace,trace>>
8674 data which a distant <<def-consumer-daemon,consumer daemon>> sends.
8675
8676[[def-ring-buffer]]ring buffer::
8677 A set of <<def-sub-buffer,sub-buffers>>.
8678
8679rotation::
8680 See _<<def-tracing-session-rotation,recording session rotation>>_.
8681
8682[[def-session-daemon]]<<lttng-sessiond,session daemon>>::
8683 A process which receives control commands from you and orchestrates
8684 the <<def-tracer,tracers>> and various <<def-lttng,LTTng>> daemons.
8685
8686<<taking-a-snapshot,snapshot>>::
8687 A copy of the current data of all the <<def-sub-buffer,sub-buffers>>
8688 of a given <<def-tracing-session,recording session>>, saved as
8689 <<def-trace,trace>> files.
8690
8691[[def-sub-buffer]]sub-buffer::
8692 One part of an <<def-lttng,LTTng>> <<def-ring-buffer,ring buffer>>
8693 which contains <<def-event-record,event records>>.
8694
8695timestamp::
8696 The time information attached to an <<def-event,event>> when LTTng
8697 creates it.
8698
8699[[def-trace]]trace (_noun_)::
8700 A set of:
8701+
8702* One https://diamon.org/ctf/[CTF] metadata stream file.
8703* One or more CTF data stream files which are the concatenations of one
8704 or more flushed <<def-sub-buffer,sub-buffers>>.
8705
8706[[def-trace-verb]]trace (_verb_)::
8707 From the perspective of a <<def-tracer,tracer>>: attempt to execute
8708 one or more actions when emitting an <<def-event,event>> in an
8709 application or in a system.
8710
8711[[def-trace-chunk]]trace chunk::
8712 A self-contained <<def-trace,trace>> which is part of a
8713 <<def-tracing-session,recording session>>. Each
8714 <<def-tracing-session-rotation, recording session rotation>> produces a
8715 <<def-trace-chunk-archive,trace chunk archive>>.
8716
8717[[def-trace-chunk-archive]]trace chunk archive::
8718 The result of a <<def-tracing-session-rotation, recording session
8719 rotation>>.
8720+
8721<<def-lttng,LTTng>> doesn't manage any trace chunk archive, even if its
8722containing <<def-tracing-session,recording session>> is still active: you
8723are free to read it, modify it, move it, or remove it.
8724
8725Trace Compass::
8726 The http://tracecompass.org[Trace Compass] project and application.
8727
8728[[def-tracepoint]]tracepoint::
8729 An instrumentation point using the tracepoint mechanism of the Linux
8730 kernel or of <<def-lttng-ust,LTTng-UST>>.
8731
8732tracepoint definition::
8733 The definition of a single <<def-tracepoint,tracepoint>>.
8734
8735tracepoint name::
8736 The name of a <<def-tracepoint,tracepoint>>.
8737
8738[[def-tracepoint-provider]]tracepoint provider::
8739 A set of functions providing <<def-tracepoint,tracepoints>> to an
8740 instrumented <<def-user-application,user application>>.
8741+
8742Not to be confused with a <<def-tracepoint-provider-package,tracepoint
8743provider package>>: many tracepoint providers can exist within a
8744tracepoint provider package.
8745
8746[[def-tracepoint-provider-package]]tracepoint provider package::
8747 One or more <<def-tracepoint-provider,tracepoint providers>> compiled
8748 as an https://en.wikipedia.org/wiki/Object_file[object file] or as a
8749 link:https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries[shared
8750 library].
8751
8752[[def-tracer]]tracer::
8753 A piece of software which executes some action when it emits
8754 an <<def-event,event>>, like <<def-record,record>> it to some
8755 buffer.
8756
8757<<domain,tracing domain>>::
8758 A type of LTTng <<def-tracer,tracer>>.
8759
8760<<tracing-group,tracing group>>::
8761 The Unix group which a Unix user can be part of to be allowed to
8762 control the Linux kernel LTTng <<def-tracer,tracer>>.
8763
8764[[def-trigger]]<<trigger,trigger>>::
8765 A <<def-condition,condition>>-<<def-action,actions>> pair; when the
8766 condition of a trigger is satisfied, LTTng attempts to execute its
8767 actions.
8768
8769[[def-user-application]]user application::
8770 An application (program or library) running in user space, as opposed
8771 to a Linux kernel module, for example.
This page took 0.323767 seconds and 4 git commands to generate.