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