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