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