2.10, 2.11: do not use `lttng stop`, then `lttng destroy` (implicit)
[lttng-docs.git] / 2.10 / lttng-docs-2.10.txt
1 The LTTng Documentation
2 =======================
3 Philippe Proulx <pproulx@efficios.com>
4 v2.10, 19 November 2018
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 _KeKriek_. From
78 http://brasseriedunham.com/[Brasserie Dunham], the _**KeKriek**_ is a
79 sour mashed golden wheat ale fermented with local sour cherries from
80 Tougas orchards. Fresh sweet cherry notes with some tartness, lively
81 carbonation with a dry finish.
82
83 New features and changes in LTTng{nbsp}{revision}:
84
85 * **Tracing control**:
86 ** You can put more than one wildcard special character (`*`), and not
87 only at the end, when you <<enabling-disabling-events,create an event
88 rule>>, in both the instrumentation point name and the literal
89 strings of
90 link:/man/1/lttng-enable-event/v{revision}/#doc-filter-syntax[filter expressions]:
91 +
92 --
93 [role="term"]
94 ----
95 # lttng enable-event --kernel 'x86_*_local_timer_*' \
96 --filter='name == "*a*b*c*d*e" && count >= 23'
97 ----
98 --
99 +
100 --
101 [role="term"]
102 ----
103 $ lttng enable-event --userspace '*_my_org:*msg*'
104 ----
105 --
106
107 ** New trigger and notification API for
108 <<liblttng-ctl-lttng,`liblttng-ctl`>>. This new subsystem allows you
109 to register triggers which emit a notification when a given
110 condition is satisfied. As of LTTng{nbsp}{revision}, only
111 <<channel,channel>> buffer usage conditions are available.
112 Documentation is available in the
113 https://github.com/lttng/lttng-tools/tree/stable-{revision}/include/lttng[`liblttng-ctl`
114 header files] and in
115 <<notif-trigger-api,Get notified when a channel's buffer usage is too
116 high or too low>>.
117
118 ** You can now embed the whole textual LTTng-tools man pages into the
119 executables at build time with the `--enable-embedded-help`
120 configuration option. Thanks to this option, you don't need the
121 http://www.methods.co.nz/asciidoc/[AsciiDoc] and
122 https://directory.fsf.org/wiki/Xmlto[xmlto] tools at build time, and
123 a manual pager at run time, to get access to this documentation.
124
125 * **User space tracing**:
126 ** New blocking mode: an LTTng-UST tracepoint can now block until
127 <<channel,sub-buffer>> space is available instead of discarding event
128 records in <<channel-overwrite-mode-vs-discard-mode,discard mode>>.
129 With this feature, you can be sure that no event records are
130 discarded during your application's execution at the expense of
131 performance.
132 +
133 For example, the following command lines create a user space tracing
134 channel with an infinite blocking timeout and run an application
135 instrumented with LTTng-UST which is explicitly allowed to block:
136 +
137 --
138 [role="term"]
139 ----
140 $ lttng create
141 $ lttng enable-channel --userspace --blocking-timeout=inf blocking-channel
142 $ lttng enable-event --userspace --channel=blocking-channel --all
143 $ lttng start
144 $ LTTNG_UST_ALLOW_BLOCKING=1 my-app
145 ----
146 --
147 +
148 See the complete <<blocking-timeout-example,blocking timeout example>>.
149
150 * **Linux kernel tracing**:
151 ** Linux 4.10, 4.11, and 4.12 support.
152 ** The thread state dump events recorded by LTTng-modules now contain
153 the task's CPU identifier. This improves the precision of the
154 scheduler model for analyses.
155 ** Extended man:socketpair(2) system call tracing data.
156
157
158 [[nuts-and-bolts]]
159 == Nuts and bolts
160
161 What is LTTng? As its name suggests, the _Linux Trace Toolkit: next
162 generation_ is a modern toolkit for tracing Linux systems and
163 applications. So your first question might be:
164 **what is tracing?**
165
166
167 [[what-is-tracing]]
168 === What is tracing?
169
170 As the history of software engineering progressed and led to what
171 we now take for granted--complex, numerous and
172 interdependent software applications running in parallel on
173 sophisticated operating systems like Linux--the authors of such
174 components, software developers, began feeling a natural
175 urge to have tools that would ensure the robustness and good performance
176 of their masterpieces.
177
178 One major achievement in this field is, inarguably, the
179 https://www.gnu.org/software/gdb/[GNU debugger (GDB)],
180 an essential tool for developers to find and fix bugs. But even the best
181 debugger won't help make your software run faster, and nowadays, faster
182 software means either more work done by the same hardware, or cheaper
183 hardware for the same work.
184
185 A _profiler_ is often the tool of choice to identify performance
186 bottlenecks. Profiling is suitable to identify _where_ performance is
187 lost in a given software. The profiler outputs a profile, a statistical
188 summary of observed events, which you may use to discover which
189 functions took the most time to execute. However, a profiler won't
190 report _why_ some identified functions are the bottleneck. Bottlenecks
191 might only occur when specific conditions are met, conditions that are
192 sometimes impossible to capture by a statistical profiler, or impossible
193 to reproduce with an application altered by the overhead of an
194 event-based profiler. For a thorough investigation of software
195 performance issues, a history of execution is essential, with the
196 recorded values of variables and context fields you choose, and
197 with as little influence as possible on the instrumented software. This
198 is where tracing comes in handy.
199
200 _Tracing_ is a technique used to understand what goes on in a running
201 software system. The software used for tracing is called a _tracer_,
202 which is conceptually similar to a tape recorder. When recording,
203 specific instrumentation points placed in the software source code
204 generate events that are saved on a giant tape: a _trace_ file. You
205 can trace user applications and the operating system at the same time,
206 opening the possibility of resolving a wide range of problems that would
207 otherwise be extremely challenging.
208
209 Tracing is often compared to _logging_. However, tracers and loggers are
210 two different tools, serving two different purposes. Tracers are
211 designed to record much lower-level events that occur much more
212 frequently than log messages, often in the range of thousands per
213 second, with very little execution overhead. Logging is more appropriate
214 for a very high-level analysis of less frequent events: user accesses,
215 exceptional conditions (errors and warnings, for example), database
216 transactions, instant messaging communications, and such. Simply put,
217 logging is one of the many use cases that can be satisfied with tracing.
218
219 The list of recorded events inside a trace file can be read manually
220 like a log file for the maximum level of detail, but it is generally
221 much more interesting to perform application-specific analyses to
222 produce reduced statistics and graphs that are useful to resolve a
223 given problem. Trace viewers and analyzers are specialized tools
224 designed to do this.
225
226 In the end, this is what LTTng is: a powerful, open source set of
227 tools to trace the Linux kernel and user applications at the same time.
228 LTTng is composed of several components actively maintained and
229 developed by its link:/community/#where[community].
230
231
232 [[lttng-alternatives]]
233 === Alternatives to noch:{LTTng}
234
235 Excluding proprietary solutions, a few competing software tracers
236 exist for Linux:
237
238 * https://github.com/dtrace4linux/linux[dtrace4linux] is a port of
239 Sun Microsystems's DTrace to Linux. The cmd:dtrace tool interprets
240 user scripts and is responsible for loading code into the
241 Linux kernel for further execution and collecting the outputted data.
242 * https://en.wikipedia.org/wiki/Berkeley_Packet_Filter[eBPF] is a
243 subsystem in the Linux kernel in which a virtual machine can execute
244 programs passed from the user space to the kernel. You can attach
245 such programs to tracepoints and KProbes thanks to a system call, and
246 they can output data to the user space when executed thanks to
247 different mechanisms (pipe, VM register values, and eBPF maps, to name
248 a few).
249 * https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace]
250 is the de facto function tracer of the Linux kernel. Its user
251 interface is a set of special files in sysfs.
252 * https://perf.wiki.kernel.org/[perf] is
253 a performance analyzing tool for Linux which supports hardware
254 performance counters, tracepoints, as well as other counters and
255 types of probes. perf's controlling utility is the cmd:perf command
256 line/curses tool.
257 * http://linux.die.net/man/1/strace[strace]
258 is a command-line utility which records system calls made by a
259 user process, as well as signal deliveries and changes of process
260 state. strace makes use of https://en.wikipedia.org/wiki/Ptrace[ptrace]
261 to fulfill its function.
262 * http://www.sysdig.org/[sysdig], like SystemTap, uses scripts to
263 analyze Linux kernel events. You write scripts, or _chisels_ in
264 sysdig's jargon, in Lua and sysdig executes them while the system is
265 being traced or afterwards. sysdig's interface is the cmd:sysdig
266 command-line tool as well as the curses-based cmd:csysdig tool.
267 * https://sourceware.org/systemtap/[SystemTap] is a Linux kernel and
268 user space tracer which uses custom user scripts to produce plain text
269 traces. SystemTap converts the scripts to the C language, and then
270 compiles them as Linux kernel modules which are loaded to produce
271 trace data. SystemTap's primary user interface is the cmd:stap
272 command-line tool.
273
274 The main distinctive features of LTTng is that it produces correlated
275 kernel and user space traces, as well as doing so with the lowest
276 overhead amongst other solutions. It produces trace files in the
277 http://diamon.org/ctf[CTF] format, a file format optimized
278 for the production and analyses of multi-gigabyte data.
279
280 LTTng is the result of more than 10 years of active open source
281 development by a community of passionate developers.
282 LTTng{nbsp}{revision} is currently available on major desktop and server
283 Linux distributions.
284
285 The main interface for tracing control is a single command-line tool
286 named cmd:lttng. The latter can create several tracing sessions, enable
287 and disable events on the fly, filter events efficiently with custom
288 user expressions, start and stop tracing, and much more. LTTng can
289 record the traces on the file system or send them over the network, and
290 keep them totally or partially. You can view the traces once tracing
291 becomes inactive or in real-time.
292
293 <<installing-lttng,Install LTTng now>> and
294 <<getting-started,start tracing>>!
295
296
297 [[installing-lttng]]
298 == Installation
299
300 **LTTng** is a set of software <<plumbing,components>> which interact to
301 <<instrumenting,instrument>> the Linux kernel and user applications, and
302 to <<controlling-tracing,control tracing>> (start and stop
303 tracing, enable and disable event rules, and the rest). Those
304 components are bundled into the following packages:
305
306 * **LTTng-tools**: Libraries and command-line interface to
307 control tracing.
308 * **LTTng-modules**: Linux kernel modules to instrument and
309 trace the kernel.
310 * **LTTng-UST**: Libraries and Java/Python packages to instrument and
311 trace user applications.
312
313 Most distributions mark the LTTng-modules and LTTng-UST packages as
314 optional when installing LTTng-tools (which is always required). In the
315 following sections, we always provide the steps to install all three,
316 but note that:
317
318 * You only need to install LTTng-modules if you intend to trace the
319 Linux kernel.
320 * You only need to install LTTng-UST if you intend to trace user
321 applications.
322
323 [role="growable"]
324 .Availability of LTTng{nbsp}{revision} for major Linux distributions as of 12 November 2018.
325 |====
326 |Distribution |Available in releases |Alternatives
327
328 |https://www.ubuntu.com/[Ubuntu]
329 |<<ubuntu,Ubuntu{nbsp}18.04 _Bionic Beaver_>>.
330
331 Ubuntu{nbsp}14.04 _Trusty Tahr_, Ubuntu{nbsp}16.04 _Xenial Xerus_,
332 and Ubuntu{nbsp}18.04 _Bionic Beaver_:
333 <<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>.
334 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
335
336 |https://getfedora.org/[Fedora]
337 |xref:fedora[Fedora{nbsp}27, Fedora{nbsp}28, and Fedora{nbsp}29].
338 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
339
340 |https://www.debian.org/[Debian]
341 |<<debian,Debian "buster" (testing)>>.
342 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
343
344 |https://www.archlinux.org/[Arch Linux]
345 |<<arch-linux,Current Arch Linux build>>.
346 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
347
348 |https://alpinelinux.org/[Alpine Linux]
349 |<<alpine-linux,Alpine Linux{nbsp}3.7 and Alpine Linux{nbsp}3.8>>.
350 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
351
352 |https://www.opensuse.org/[openSUSE]
353 |<<opensuse,openSUSE Leap{nbsp}15.0>>.
354 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
355
356 |https://www.redhat.com/[RHEL] and https://www.suse.com/[SLES]
357 |See http://packages.efficios.com/[EfficiOS Enterprise Packages].
358 |
359
360 |https://buildroot.org/[Buildroot]
361 |xref:buildroot[Buildroot{nbsp}2018.02, Buildroot{nbsp}2018.05,
362 Buildroot{nbsp}2018.08, and Buildroot{nbsp}2018.11].
363 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
364
365 |http://www.openembedded.org/wiki/Main_Page[OpenEmbedded] and
366 https://www.yoctoproject.org/[Yocto]
367 |_Not available_
368 |<<building-from-source,Build LTTng{nbsp}{revision} from source>>.
369 |====
370
371
372 [[ubuntu]]
373 === [[ubuntu-official-repositories]]Ubuntu
374
375 LTTng{nbsp}{revision} is available on Ubuntu{nbsp}18.04 _Bionic Beaver_.
376 For previous supported releases of Ubuntu,
377 <<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>.
378
379 To install LTTng{nbsp}{revision} on Ubuntu{nbsp}18.04 _Bionic Beaver_:
380
381 . Install the main LTTng{nbsp}{revision} packages:
382 +
383 --
384 [role="term"]
385 ----
386 # apt-get install lttng-tools
387 # apt-get install lttng-modules-dkms
388 # apt-get install liblttng-ust-dev
389 ----
390 --
391
392 . **If you need to instrument and trace
393 <<java-application,Java applications>>**, install the LTTng-UST
394 Java agent:
395 +
396 --
397 [role="term"]
398 ----
399 # apt-get install liblttng-ust-agent-java
400 ----
401 --
402
403 . **If you need to instrument and trace
404 <<python-application,Python{nbsp}3 applications>>**, install the
405 LTTng-UST Python agent:
406 +
407 --
408 [role="term"]
409 ----
410 # apt-get install python3-lttngust
411 ----
412 --
413
414
415 [[ubuntu-ppa]]
416 ==== noch:{LTTng} Stable {revision} PPA
417
418 The https://launchpad.net/~lttng/+archive/ubuntu/stable-{revision}[LTTng
419 Stable{nbsp}{revision} PPA] offers the latest stable
420 LTTng{nbsp}{revision} packages for:
421
422 * Ubuntu{nbsp}14.04 _Trusty Tahr_
423 * Ubuntu{nbsp}16.04 _Xenial Xerus_
424 * Ubuntu{nbsp}18.04 _Bionic Beaver_
425
426 To install LTTng{nbsp}{revision} from the LTTng Stable{nbsp}{revision} PPA:
427
428 . Add the LTTng Stable{nbsp}{revision} PPA repository and update the
429 list of packages:
430 +
431 --
432 [role="term"]
433 ----
434 # apt-add-repository ppa:lttng/stable-2.10
435 # apt-get update
436 ----
437 --
438
439 . Install the main LTTng{nbsp}{revision} packages:
440 +
441 --
442 [role="term"]
443 ----
444 # apt-get install lttng-tools
445 # apt-get install lttng-modules-dkms
446 # apt-get install liblttng-ust-dev
447 ----
448 --
449
450 . **If you need to instrument and trace
451 <<java-application,Java applications>>**, install the LTTng-UST
452 Java agent:
453 +
454 --
455 [role="term"]
456 ----
457 # apt-get install liblttng-ust-agent-java
458 ----
459 --
460
461 . **If you need to instrument and trace
462 <<python-application,Python{nbsp}3 applications>>**, install the
463 LTTng-UST Python agent:
464 +
465 --
466 [role="term"]
467 ----
468 # apt-get install python3-lttngust
469 ----
470 --
471
472
473 [[fedora]]
474 === Fedora
475
476 To install LTTng{nbsp}{revision} on Fedora{nbsp}27, Fedora{nbsp}28,
477 or Fedora{nbsp}29:
478
479 . Install the LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision}
480 packages:
481 +
482 --
483 [role="term"]
484 ----
485 # yum install lttng-tools
486 # yum install lttng-ust
487 ----
488 --
489
490 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
491 +
492 --
493 [role="term"]
494 ----
495 $ cd $(mktemp -d) &&
496 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
497 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
498 cd lttng-modules-2.10.* &&
499 make &&
500 sudo make modules_install &&
501 sudo depmod -a
502 ----
503 --
504
505 [IMPORTANT]
506 .Java and Python application instrumentation and tracing
507 ====
508 If you need to instrument and trace <<java-application,Java
509 applications>> on Fedora, you need to build and install
510 LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass
511 the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or
512 `--enable-java-agent-all` options to the `configure` script, depending
513 on which Java logging framework you use.
514
515 If you need to instrument and trace <<python-application,Python
516 applications>> on Fedora, you need to build and install
517 LTTng-UST{nbsp}{revision} from source and pass the
518 `--enable-python-agent` option to the `configure` script.
519 ====
520
521
522 [[debian]]
523 === Debian
524
525 To install LTTng{nbsp}{revision} on Debian "buster" (testing):
526
527 . Install the main LTTng{nbsp}{revision} packages:
528 +
529 --
530 [role="term"]
531 ----
532 # apt-get install lttng-modules-dkms
533 # apt-get install liblttng-ust-dev
534 # apt-get install lttng-tools
535 ----
536 --
537
538 . **If you need to instrument and trace <<java-application,Java
539 applications>>**, install the LTTng-UST Java agent:
540 +
541 --
542 [role="term"]
543 ----
544 # apt-get install liblttng-ust-agent-java
545 ----
546 --
547
548 . **If you need to instrument and trace <<python-application,Python
549 applications>>**, install the LTTng-UST Python agent:
550 +
551 --
552 [role="term"]
553 ----
554 # apt-get install python3-lttngust
555 ----
556 --
557
558
559 [[arch-linux]]
560 === Arch Linux
561
562 LTTng-UST{nbsp}{revision} is available in Arch Linux's _Community_
563 repository, while LTTng-tools{nbsp}{revision} and
564 LTTng-modules{nbsp}{revision} are available in the
565 https://aur.archlinux.org/[AUR].
566
567 To install LTTng{nbsp}{revision} on Arch Linux, using
568 https://github.com/rmarquis/pacaur[pacaur] for the AUR packages:
569
570 . Install the main LTTng{nbsp}{revision} packages:
571 +
572 --
573 [role="term"]
574 ----
575 # pacman -Sy lttng-ust
576 $ pikaur -Sy lttng-tools
577 $ pikaur -Sy lttng-modules
578 ----
579 --
580
581 . **If you need to instrument and trace <<python-application,Python
582 applications>>**, install the LTTng-UST Python agent:
583 +
584 --
585 [role="term"]
586 ----
587 # pacman -Sy python-lttngust
588 # pacman -Sy python2-lttngust
589 ----
590 --
591
592
593 [[alpine-linux]]
594 === Alpine Linux
595
596 To install LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision} on
597 Alpine Linux{nbsp}3.7 or Alpine Linux{nbsp}3.8:
598
599 . Add the LTTng packages:
600 +
601 --
602 [role="term"]
603 ----
604 # apk add lttng-tools
605 # apk add lttng-ust-dev
606 ----
607 --
608
609 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
610 +
611 --
612 [role="term"]
613 ----
614 $ cd $(mktemp -d) &&
615 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
616 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
617 cd lttng-modules-2.10.* &&
618 make &&
619 sudo make modules_install &&
620 sudo depmod -a
621 ----
622 --
623
624
625 [[opensuse]]
626 === noch:{openSUSE}
627
628 To install LTTng{nbsp}{revision} on openSUSE Leap{nbsp}15.0:
629
630 * Install the main LTTng{nbsp}{revision} packages:
631 +
632 --
633 [role="term"]
634 ----
635 sudo zypper install lttng-tools
636 sudo zypper install lttng-modules
637 sudo zypper install lttng-ust-devel
638 ----
639 --
640
641 [IMPORTANT]
642 .Java and Python application instrumentation and tracing
643 ====
644 If you need to instrument and trace <<java-application,Java
645 applications>> on openSUSE, you need to build and install
646 LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass
647 the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or
648 `--enable-java-agent-all` options to the `configure` script, depending
649 on which Java logging framework you use.
650
651 If you need to instrument and trace <<python-application,Python
652 applications>> on openSUSE, you need to build and install
653 LTTng-UST{nbsp}{revision} from source and pass the
654 `--enable-python-agent` option to the `configure` script.
655 ====
656
657
658 [[enterprise-distributions]]
659 === RHEL, SUSE, and other enterprise distributions
660
661 To install LTTng on enterprise Linux distributions, such as Red Hat
662 Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SUSE), please
663 see http://packages.efficios.com/[EfficiOS Enterprise Packages].
664
665
666 [[buildroot]]
667 === Buildroot
668
669 To install LTTng{nbsp}{revision} on Buildroot{nbsp}2018.02,
670 Buildroot{nbsp}2018.05, Buildroot{nbsp}2018.08, or
671 Buildroot{nbsp}2018.11:
672
673 . Launch the Buildroot configuration tool:
674 +
675 --
676 [role="term"]
677 ----
678 $ make menuconfig
679 ----
680 --
681
682 . In **Kernel**, check **Linux kernel**.
683 . In **Toolchain**, check **Enable WCHAR support**.
684 . In **Target packages**{nbsp}&#8594; **Debugging, profiling and benchmark**,
685 check **lttng-modules** and **lttng-tools**.
686 . In **Target packages**{nbsp}&#8594; **Libraries**{nbsp}&#8594;
687 **Other**, check **lttng-libust**.
688
689
690 [[building-from-source]]
691 === Build from source
692
693 To build and install LTTng{nbsp}{revision} from source:
694
695 . Using your distribution's package manager, or from source, install
696 the following dependencies of LTTng-tools and LTTng-UST:
697 +
698 --
699 * https://sourceforge.net/projects/libuuid/[libuuid]
700 * http://directory.fsf.org/wiki/Popt[popt]
701 * http://liburcu.org/[Userspace RCU]
702 * http://www.xmlsoft.org/[libxml2]
703 --
704
705 . Download, build, and install the latest LTTng-modules{nbsp}{revision}:
706 +
707 --
708 [role="term"]
709 ----
710 $ cd $(mktemp -d) &&
711 wget http://lttng.org/files/lttng-modules/lttng-modules-latest-2.10.tar.bz2 &&
712 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
713 cd lttng-modules-2.10.* &&
714 make &&
715 sudo make modules_install &&
716 sudo depmod -a
717 ----
718 --
719
720 . Download, build, and install the latest LTTng-UST{nbsp}{revision}:
721 +
722 --
723 [role="term"]
724 ----
725 $ cd $(mktemp -d) &&
726 wget http://lttng.org/files/lttng-ust/lttng-ust-latest-2.10.tar.bz2 &&
727 tar -xf lttng-ust-latest-2.10.tar.bz2 &&
728 cd lttng-ust-2.10.* &&
729 ./configure &&
730 make &&
731 sudo make install &&
732 sudo ldconfig
733 ----
734 --
735 +
736 --
737 [IMPORTANT]
738 .Java and Python application tracing
739 ====
740 If you need to instrument and trace <<java-application,Java
741 applications>>, pass the `--enable-java-agent-jul`,
742 `--enable-java-agent-log4j`, or `--enable-java-agent-all` options to the
743 `configure` script, depending on which Java logging framework you use.
744
745 If you need to instrument and trace <<python-application,Python
746 applications>>, pass the `--enable-python-agent` option to the
747 `configure` script. You can set the `PYTHON` environment variable to the
748 path to the Python interpreter for which to install the LTTng-UST Python
749 agent package.
750 ====
751 --
752 +
753 --
754 [NOTE]
755 ====
756 By default, LTTng-UST libraries are installed to
757 dir:{/usr/local/lib}, which is the de facto directory in which to
758 keep self-compiled and third-party libraries.
759
760 When <<building-tracepoint-providers-and-user-application,linking an
761 instrumented user application with `liblttng-ust`>>:
762
763 * Append `/usr/local/lib` to the env:LD_LIBRARY_PATH environment
764 variable.
765 * Pass the `-L/usr/local/lib` and `-Wl,-rpath,/usr/local/lib` options to
766 man:gcc(1), man:g++(1), or man:clang(1).
767 ====
768 --
769
770 . Download, build, and install the latest LTTng-tools{nbsp}{revision}:
771 +
772 --
773 [role="term"]
774 ----
775 $ cd $(mktemp -d) &&
776 wget http://lttng.org/files/lttng-tools/lttng-tools-latest-2.10.tar.bz2 &&
777 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
778 cd lttng-tools-2.10.* &&
779 ./configure &&
780 make &&
781 sudo make install &&
782 sudo ldconfig
783 ----
784 --
785
786 TIP: The https://github.com/eepp/vlttng[vlttng tool] can do all the
787 previous steps automatically for a given version of LTTng and confine
788 the installed files in a specific directory. This can be useful to test
789 LTTng without installing it on your system.
790
791
792 [[getting-started]]
793 == Quick start
794
795 This is a short guide to get started quickly with LTTng kernel and user
796 space tracing.
797
798 Before you follow this guide, make sure to <<installing-lttng,install>>
799 LTTng.
800
801 This tutorial walks you through the steps to:
802
803 . <<tracing-the-linux-kernel,Trace the Linux kernel>>.
804 . <<tracing-your-own-user-application,Trace a user application>> written
805 in C.
806 . <<viewing-and-analyzing-your-traces,View and analyze the
807 recorded events>>.
808
809
810 [[tracing-the-linux-kernel]]
811 === Trace the Linux kernel
812
813 The following command lines start with the `#` prompt because you need
814 root privileges to trace the Linux kernel. You can also trace the kernel
815 as a regular user if your Unix user is a member of the
816 <<tracing-group,tracing group>>.
817
818 . Create a <<tracing-session,tracing session>> which writes its traces
819 to dir:{/tmp/my-kernel-trace}:
820 +
821 --
822 [role="term"]
823 ----
824 # lttng create my-kernel-session --output=/tmp/my-kernel-trace
825 ----
826 --
827
828 . List the available kernel tracepoints and system calls:
829 +
830 --
831 [role="term"]
832 ----
833 # lttng list --kernel
834 # lttng list --kernel --syscall
835 ----
836 --
837
838 . Create <<event,event rules>> which match the desired instrumentation
839 point names, for example the `sched_switch` and `sched_process_fork`
840 tracepoints, and the man:open(2) and man:close(2) system calls:
841 +
842 --
843 [role="term"]
844 ----
845 # lttng enable-event --kernel sched_switch,sched_process_fork
846 # lttng enable-event --kernel --syscall open,close
847 ----
848 --
849 +
850 You can also create an event rule which matches _all_ the Linux kernel
851 tracepoints (this will generate a lot of data when tracing):
852 +
853 --
854 [role="term"]
855 ----
856 # lttng enable-event --kernel --all
857 ----
858 --
859
860 . <<basic-tracing-session-control,Start tracing>>:
861 +
862 --
863 [role="term"]
864 ----
865 # lttng start
866 ----
867 --
868
869 . Do some operation on your system for a few seconds. For example,
870 load a website, or list the files of a directory.
871 . <<creating-destroying-tracing-sessions,Destroy>> the current
872 tracing session:
873 +
874 --
875 [role="term"]
876 ----
877 # lttng destroy
878 ----
879 --
880 +
881 The man:lttng-destroy(1) command does not destroy the trace data; it
882 only destroys the state of the tracing session.
883 +
884 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
885 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
886 session>>). You need to stop tracing to make LTTng flush the remaining
887 trace data and make the trace readable.
888
889 . For the sake of this example, make the recorded trace accessible to
890 the non-root users:
891 +
892 --
893 [role="term"]
894 ----
895 # chown -R $(whoami) /tmp/my-kernel-trace
896 ----
897 --
898
899 See <<viewing-and-analyzing-your-traces,View and analyze the
900 recorded events>> to view the recorded events.
901
902
903 [[tracing-your-own-user-application]]
904 === Trace a user application
905
906 This section steps you through a simple example to trace a
907 _Hello world_ program written in C.
908
909 To create the traceable user application:
910
911 . Create the tracepoint provider header file, which defines the
912 tracepoints and the events they can generate:
913 +
914 --
915 [source,c]
916 .path:{hello-tp.h}
917 ----
918 #undef TRACEPOINT_PROVIDER
919 #define TRACEPOINT_PROVIDER hello_world
920
921 #undef TRACEPOINT_INCLUDE
922 #define TRACEPOINT_INCLUDE "./hello-tp.h"
923
924 #if !defined(_HELLO_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
925 #define _HELLO_TP_H
926
927 #include <lttng/tracepoint.h>
928
929 TRACEPOINT_EVENT(
930 hello_world,
931 my_first_tracepoint,
932 TP_ARGS(
933 int, my_integer_arg,
934 char*, my_string_arg
935 ),
936 TP_FIELDS(
937 ctf_string(my_string_field, my_string_arg)
938 ctf_integer(int, my_integer_field, my_integer_arg)
939 )
940 )
941
942 #endif /* _HELLO_TP_H */
943
944 #include <lttng/tracepoint-event.h>
945 ----
946 --
947
948 . Create the tracepoint provider package source file:
949 +
950 --
951 [source,c]
952 .path:{hello-tp.c}
953 ----
954 #define TRACEPOINT_CREATE_PROBES
955 #define TRACEPOINT_DEFINE
956
957 #include "hello-tp.h"
958 ----
959 --
960
961 . Build the tracepoint provider package:
962 +
963 --
964 [role="term"]
965 ----
966 $ gcc -c -I. hello-tp.c
967 ----
968 --
969
970 . Create the _Hello World_ application source file:
971 +
972 --
973 [source,c]
974 .path:{hello.c}
975 ----
976 #include <stdio.h>
977 #include "hello-tp.h"
978
979 int main(int argc, char *argv[])
980 {
981 int x;
982
983 puts("Hello, World!\nPress Enter to continue...");
984
985 /*
986 * The following getchar() call is only placed here for the purpose
987 * of this demonstration, to pause the application in order for
988 * you to have time to list its tracepoints. It is not
989 * needed otherwise.
990 */
991 getchar();
992
993 /*
994 * A tracepoint() call.
995 *
996 * Arguments, as defined in hello-tp.h:
997 *
998 * 1. Tracepoint provider name (required)
999 * 2. Tracepoint name (required)
1000 * 3. my_integer_arg (first user-defined argument)
1001 * 4. my_string_arg (second user-defined argument)
1002 *
1003 * Notice the tracepoint provider and tracepoint names are
1004 * NOT strings: they are in fact parts of variables that the
1005 * macros in hello-tp.h create.
1006 */
1007 tracepoint(hello_world, my_first_tracepoint, 23, "hi there!");
1008
1009 for (x = 0; x < argc; ++x) {
1010 tracepoint(hello_world, my_first_tracepoint, x, argv[x]);
1011 }
1012
1013 puts("Quitting now!");
1014 tracepoint(hello_world, my_first_tracepoint, x * x, "x^2");
1015
1016 return 0;
1017 }
1018 ----
1019 --
1020
1021 . Build the application:
1022 +
1023 --
1024 [role="term"]
1025 ----
1026 $ gcc -c hello.c
1027 ----
1028 --
1029
1030 . Link the application with the tracepoint provider package,
1031 `liblttng-ust`, and `libdl`:
1032 +
1033 --
1034 [role="term"]
1035 ----
1036 $ gcc -o hello hello.o hello-tp.o -llttng-ust -ldl
1037 ----
1038 --
1039
1040 Here's the whole build process:
1041
1042 [role="img-100"]
1043 .User space tracing tutorial's build steps.
1044 image::ust-flow.png[]
1045
1046 To trace the user application:
1047
1048 . Run the application with a few arguments:
1049 +
1050 --
1051 [role="term"]
1052 ----
1053 $ ./hello world and beyond
1054 ----
1055 --
1056 +
1057 You see:
1058 +
1059 --
1060 ----
1061 Hello, World!
1062 Press Enter to continue...
1063 ----
1064 --
1065
1066 . Start an LTTng <<lttng-sessiond,session daemon>>:
1067 +
1068 --
1069 [role="term"]
1070 ----
1071 $ lttng-sessiond --daemonize
1072 ----
1073 --
1074 +
1075 Note that a session daemon might already be running, for example as
1076 a service that the distribution's service manager started.
1077
1078 . List the available user space tracepoints:
1079 +
1080 --
1081 [role="term"]
1082 ----
1083 $ lttng list --userspace
1084 ----
1085 --
1086 +
1087 You see the `hello_world:my_first_tracepoint` tracepoint listed
1088 under the `./hello` process.
1089
1090 . Create a <<tracing-session,tracing session>>:
1091 +
1092 --
1093 [role="term"]
1094 ----
1095 $ lttng create my-user-space-session
1096 ----
1097 --
1098
1099 . Create an <<event,event rule>> which matches the
1100 `hello_world:my_first_tracepoint` event name:
1101 +
1102 --
1103 [role="term"]
1104 ----
1105 $ lttng enable-event --userspace hello_world:my_first_tracepoint
1106 ----
1107 --
1108
1109 . <<basic-tracing-session-control,Start tracing>>:
1110 +
1111 --
1112 [role="term"]
1113 ----
1114 $ lttng start
1115 ----
1116 --
1117
1118 . Go back to the running `hello` application and press Enter. The
1119 program executes all `tracepoint()` instrumentation points and exits.
1120 . <<creating-destroying-tracing-sessions,Destroy>> the current
1121 tracing session:
1122 +
1123 --
1124 [role="term"]
1125 ----
1126 $ lttng destroy
1127 ----
1128 --
1129 +
1130 The man:lttng-destroy(1) command does not destroy the trace data; it
1131 only destroys the state of the tracing session.
1132 +
1133 The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command
1134 implicitly (see <<basic-tracing-session-control,Start and stop a tracing
1135 session>>). You need to stop tracing to make LTTng flush the remaining
1136 trace data and make the trace readable.
1137
1138 By default, LTTng saves the traces in
1139 +$LTTNG_HOME/lttng-traces/__name__-__date__-__time__+,
1140 where +__name__+ is the tracing session name. The
1141 env:LTTNG_HOME environment variable defaults to `$HOME` if not set.
1142
1143 See <<viewing-and-analyzing-your-traces,View and analyze the
1144 recorded events>> to view the recorded events.
1145
1146
1147 [[viewing-and-analyzing-your-traces]]
1148 === View and analyze the recorded events
1149
1150 Once you have completed the <<tracing-the-linux-kernel,Trace the Linux
1151 kernel>> and <<tracing-your-own-user-application,Trace a user
1152 application>> tutorials, you can inspect the recorded events.
1153
1154 Many tools are available to read LTTng traces:
1155
1156 * **cmd:babeltrace** is a command-line utility which converts trace
1157 formats; it supports the format that LTTng produces, CTF, as well as a
1158 basic text output which can be ++grep++ed. The cmd:babeltrace command
1159 is part of the http://diamon.org/babeltrace[Babeltrace] project.
1160 * Babeltrace also includes
1161 **https://www.python.org/[Python] bindings** so
1162 that you can easily open and read an LTTng trace with your own script,
1163 benefiting from the power of Python.
1164 * http://tracecompass.org/[**Trace Compass**]
1165 is a graphical user interface for viewing and analyzing any type of
1166 logs or traces, including LTTng's.
1167 * https://github.com/lttng/lttng-analyses[**LTTng analyses**] is a
1168 project which includes many high-level analyses of LTTng kernel
1169 traces, like scheduling statistics, interrupt frequency distribution,
1170 top CPU usage, and more.
1171
1172 NOTE: This section assumes that the traces recorded during the previous
1173 tutorials were saved to their default location, in the
1174 dir:{$LTTNG_HOME/lttng-traces} directory. The env:LTTNG_HOME
1175 environment variable defaults to `$HOME` if not set.
1176
1177
1178 [[viewing-and-analyzing-your-traces-bt]]
1179 ==== Use the cmd:babeltrace command-line tool
1180
1181 The simplest way to list all the recorded events of a trace is to pass
1182 its path to cmd:babeltrace with no options:
1183
1184 [role="term"]
1185 ----
1186 $ babeltrace ~/lttng-traces/my-user-space-session*
1187 ----
1188
1189 cmd:babeltrace finds all traces recursively within the given path and
1190 prints all their events, merging them in chronological order.
1191
1192 You can pipe the output of cmd:babeltrace into a tool like man:grep(1) for
1193 further filtering:
1194
1195 [role="term"]
1196 ----
1197 $ babeltrace /tmp/my-kernel-trace | grep _switch
1198 ----
1199
1200 You can pipe the output of cmd:babeltrace into a tool like man:wc(1) to
1201 count the recorded events:
1202
1203 [role="term"]
1204 ----
1205 $ babeltrace /tmp/my-kernel-trace | grep _open | wc --lines
1206 ----
1207
1208
1209 [[viewing-and-analyzing-your-traces-bt-python]]
1210 ==== Use the Babeltrace Python bindings
1211
1212 The <<viewing-and-analyzing-your-traces-bt,text output of cmd:babeltrace>>
1213 is useful to isolate events by simple matching using man:grep(1) and
1214 similar utilities. However, more elaborate filters, such as keeping only
1215 event records with a field value falling within a specific range, are
1216 not trivial to write using a shell. Moreover, reductions and even the
1217 most basic computations involving multiple event records are virtually
1218 impossible to implement.
1219
1220 Fortunately, Babeltrace ships with Python 3 bindings which makes it easy
1221 to read the event records of an LTTng trace sequentially and compute the
1222 desired information.
1223
1224 The following script accepts an LTTng Linux kernel trace path as its
1225 first argument and prints the short names of the top 5 running processes
1226 on CPU 0 during the whole trace:
1227
1228 [source,python]
1229 .path:{top5proc.py}
1230 ----
1231 from collections import Counter
1232 import babeltrace
1233 import sys
1234
1235
1236 def top5proc():
1237 if len(sys.argv) != 2:
1238 msg = 'Usage: python3 {} TRACEPATH'.format(sys.argv[0])
1239 print(msg, file=sys.stderr)
1240 return False
1241
1242 # A trace collection contains one or more traces
1243 col = babeltrace.TraceCollection()
1244
1245 # Add the trace provided by the user (LTTng traces always have
1246 # the 'ctf' format)
1247 if col.add_trace(sys.argv[1], 'ctf') is None:
1248 raise RuntimeError('Cannot add trace')
1249
1250 # This counter dict contains execution times:
1251 #
1252 # task command name -> total execution time (ns)
1253 exec_times = Counter()
1254
1255 # This contains the last `sched_switch` timestamp
1256 last_ts = None
1257
1258 # Iterate on events
1259 for event in col.events:
1260 # Keep only `sched_switch` events
1261 if event.name != 'sched_switch':
1262 continue
1263
1264 # Keep only events which happened on CPU 0
1265 if event['cpu_id'] != 0:
1266 continue
1267
1268 # Event timestamp
1269 cur_ts = event.timestamp
1270
1271 if last_ts is None:
1272 # We start here
1273 last_ts = cur_ts
1274
1275 # Previous task command (short) name
1276 prev_comm = event['prev_comm']
1277
1278 # Initialize entry in our dict if not yet done
1279 if prev_comm not in exec_times:
1280 exec_times[prev_comm] = 0
1281
1282 # Compute previous command execution time
1283 diff = cur_ts - last_ts
1284
1285 # Update execution time of this command
1286 exec_times[prev_comm] += diff
1287
1288 # Update last timestamp
1289 last_ts = cur_ts
1290
1291 # Display top 5
1292 for name, ns in exec_times.most_common(5):
1293 s = ns / 1000000000
1294 print('{:20}{} s'.format(name, s))
1295
1296 return True
1297
1298
1299 if __name__ == '__main__':
1300 sys.exit(0 if top5proc() else 1)
1301 ----
1302
1303 Run this script:
1304
1305 [role="term"]
1306 ----
1307 $ python3 top5proc.py /tmp/my-kernel-trace/kernel
1308 ----
1309
1310 Output example:
1311
1312 ----
1313 swapper/0 48.607245889 s
1314 chromium 7.192738188 s
1315 pavucontrol 0.709894415 s
1316 Compositor 0.660867933 s
1317 Xorg.bin 0.616753786 s
1318 ----
1319
1320 Note that `swapper/0` is the "idle" process of CPU 0 on Linux; since we
1321 weren't using the CPU that much when tracing, its first position in the
1322 list makes sense.
1323
1324
1325 [[core-concepts]]
1326 == [[understanding-lttng]]Core concepts
1327
1328 From a user's perspective, the LTTng system is built on a few concepts,
1329 or objects, on which the <<lttng-cli,cmd:lttng command-line tool>>
1330 operates by sending commands to the <<lttng-sessiond,session daemon>>.
1331 Understanding how those objects relate to eachother is key in mastering
1332 the toolkit.
1333
1334 The core concepts are:
1335
1336 * <<tracing-session,Tracing session>>
1337 * <<domain,Tracing domain>>
1338 * <<channel,Channel and ring buffer>>
1339 * <<"event","Instrumentation point, event rule, event, and event record">>
1340
1341
1342 [[tracing-session]]
1343 === Tracing session
1344
1345 A _tracing session_ is a stateful dialogue between you and
1346 a <<lttng-sessiond,session daemon>>. You can
1347 <<creating-destroying-tracing-sessions,create a new tracing
1348 session>> with the `lttng create` command.
1349
1350 Anything that you do when you control LTTng tracers happens within a
1351 tracing session. In particular, a tracing session:
1352
1353 * Has its own name.
1354 * Has its own set of trace files.
1355 * Has its own state of activity (started or stopped).
1356 * Has its own <<tracing-session-mode,mode>> (local, network streaming,
1357 snapshot, or live).
1358 * Has its own <<channel,channels>> which have their own
1359 <<event,event rules>>.
1360
1361 [role="img-100"]
1362 .A _tracing session_ contains <<channel,channels>> that are members of <<domain,tracing domains>> and contain <<event,event rules>>.
1363 image::concepts.png[]
1364
1365 Those attributes and objects are completely isolated between different
1366 tracing sessions.
1367
1368 A tracing session is analogous to a cash machine session:
1369 the operations you do on the banking system through the cash machine do
1370 not alter the data of other users of the same system. In the case of
1371 the cash machine, a session lasts as long as your bank card is inside.
1372 In the case of LTTng, a tracing session lasts from the `lttng create`
1373 command to the `lttng destroy` command.
1374
1375 [role="img-100"]
1376 .Each Unix user has its own set of tracing sessions.
1377 image::many-sessions.png[]
1378
1379
1380 [[tracing-session-mode]]
1381 ==== Tracing session mode
1382
1383 LTTng can send the generated trace data to different locations. The
1384 _tracing session mode_ dictates where to send it. The following modes
1385 are available in LTTng{nbsp}{revision}:
1386
1387 Local mode::
1388 LTTng writes the traces to the file system of the machine being traced
1389 (target system).
1390
1391 Network streaming mode::
1392 LTTng sends the traces over the network to a
1393 <<lttng-relayd,relay daemon>> running on a remote system.
1394
1395 Snapshot mode::
1396 LTTng does not write the traces by default. Instead, you can request
1397 LTTng to <<taking-a-snapshot,take a snapshot>>, that is, a copy of the
1398 current tracing buffers, and to write it to the target's file system
1399 or to send it over the network to a <<lttng-relayd,relay daemon>>
1400 running on a remote system.
1401
1402 Live mode::
1403 This mode is similar to the network streaming mode, but a live
1404 trace viewer can connect to the distant relay daemon to
1405 <<lttng-live,view event records as LTTng generates them>> by
1406 the tracers.
1407
1408
1409 [[domain]]
1410 === Tracing domain
1411
1412 A _tracing domain_ is a namespace for event sources. A tracing domain
1413 has its own properties and features.
1414
1415 There are currently five available tracing domains:
1416
1417 * Linux kernel
1418 * User space
1419 * `java.util.logging` (JUL)
1420 * log4j
1421 * Python
1422
1423 You must specify a tracing domain when using some commands to avoid
1424 ambiguity. For example, since all the domains support named tracepoints
1425 as event sources (instrumentation points that you manually insert in the
1426 source code), you need to specify a tracing domain when
1427 <<enabling-disabling-events,creating an event rule>> because all the
1428 tracing domains could have tracepoints with the same names.
1429
1430 Some features are reserved to specific tracing domains. Dynamic function
1431 entry and return instrumentation points, for example, are currently only
1432 supported in the Linux kernel tracing domain, but support for other
1433 tracing domains could be added in the future.
1434
1435 You can create <<channel,channels>> in the Linux kernel and user space
1436 tracing domains. The other tracing domains have a single default
1437 channel.
1438
1439
1440 [[channel]]
1441 === Channel and ring buffer
1442
1443 A _channel_ is an object which is responsible for a set of ring buffers.
1444 Each ring buffer is divided into multiple sub-buffers. When an LTTng
1445 tracer emits an event, it can record it to one or more
1446 sub-buffers. The attributes of a channel determine what to do when
1447 there's no space left for a new event record because all sub-buffers
1448 are full, where to send a full sub-buffer, and other behaviours.
1449
1450 A channel is always associated to a <<domain,tracing domain>>. The
1451 `java.util.logging` (JUL), log4j, and Python tracing domains each have
1452 a default channel which you cannot configure.
1453
1454 A channel also owns <<event,event rules>>. When an LTTng tracer emits
1455 an event, it records it to the sub-buffers of all
1456 the enabled channels with a satisfied event rule, as long as those
1457 channels are part of active <<tracing-session,tracing sessions>>.
1458
1459
1460 [[channel-buffering-schemes]]
1461 ==== Per-user vs. per-process buffering schemes
1462
1463 A channel has at least one ring buffer _per CPU_. LTTng always
1464 records an event to the ring buffer associated to the CPU on which it
1465 occurred.
1466
1467 Two _buffering schemes_ are available when you
1468 <<enabling-disabling-channels,create a channel>> in the
1469 user space <<domain,tracing domain>>:
1470
1471 Per-user buffering::
1472 Allocate one set of ring buffers--one per CPU--shared by all the
1473 instrumented processes of each Unix user.
1474 +
1475 --
1476 [role="img-100"]
1477 .Per-user buffering scheme.
1478 image::per-user-buffering.png[]
1479 --
1480
1481 Per-process buffering::
1482 Allocate one set of ring buffers--one per CPU--for each
1483 instrumented process.
1484 +
1485 --
1486 [role="img-100"]
1487 .Per-process buffering scheme.
1488 image::per-process-buffering.png[]
1489 --
1490 +
1491 The per-process buffering scheme tends to consume more memory than the
1492 per-user option because systems generally have more instrumented
1493 processes than Unix users running instrumented processes. However, the
1494 per-process buffering scheme ensures that one process having a high
1495 event throughput won't fill all the shared sub-buffers of the same
1496 user, only its own.
1497
1498 The Linux kernel tracing domain has only one available buffering scheme
1499 which is to allocate a single set of ring buffers for the whole system.
1500 This scheme is similar to the per-user option, but with a single, global
1501 user "running" the kernel.
1502
1503
1504 [[channel-overwrite-mode-vs-discard-mode]]
1505 ==== Overwrite vs. discard event loss modes
1506
1507 When an event occurs, LTTng records it to a specific sub-buffer (yellow
1508 arc in the following animation) of a specific channel's ring buffer.
1509 When there's no space left in a sub-buffer, the tracer marks it as
1510 consumable (red) and another, empty sub-buffer starts receiving the
1511 following event records. A <<lttng-consumerd,consumer daemon>>
1512 eventually consumes the marked sub-buffer (returns to white).
1513
1514 [NOTE]
1515 [role="docsvg-channel-subbuf-anim"]
1516 ====
1517 {note-no-anim}
1518 ====
1519
1520 In an ideal world, sub-buffers are consumed faster than they are filled,
1521 as is the case in the previous animation. In the real world,
1522 however, all sub-buffers can be full at some point, leaving no space to
1523 record the following events.
1524
1525 By default, LTTng-modules and LTTng-UST are _non-blocking_ tracers: when
1526 no empty sub-buffer is available, it is acceptable to lose event records
1527 when the alternative would be to cause substantial delays in the
1528 instrumented application's execution. LTTng privileges performance over
1529 integrity; it aims at perturbing the traced system as little as possible
1530 in order to make tracing of subtle race conditions and rare interrupt
1531 cascades possible.
1532
1533 Starting from LTTng{nbsp}2.10, the LTTng user space tracer, LTTng-UST,
1534 supports a _blocking mode_. See the <<blocking-timeout-example,blocking
1535 timeout example>> to learn how to use the blocking mode.
1536
1537 When it comes to losing event records because no empty sub-buffer is
1538 available, or because the <<opt-blocking-timeout,blocking timeout>> is
1539 reached, the channel's _event loss mode_ determines what to do. The
1540 available event loss modes are:
1541
1542 Discard mode::
1543 Drop the newest event records until a the tracer releases a
1544 sub-buffer.
1545 +
1546 This is the only available mode when you specify a
1547 <<opt-blocking-timeout,blocking timeout>>.
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>> (cmd:lttng-consumerd).
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_, cmd:lttng-consumerd, 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.10.tar.bz2 &&
3997 tar -xf lttng-ust-latest-2.10.tar.bz2 &&
3998 cd lttng-ust-2.10.* &&
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.10.tar.bz2 &&
4032 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
4033 cd lttng-tools-2.10.* &&
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.10.tar.bz2 &&
4056 tar -xf lttng-tools-latest-2.10.tar.bz2 &&
4057 cd lttng-tools-2.10.* &&
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.10.tar.bz2 &&
5299 tar -xf lttng-modules-latest-2.10.tar.bz2 &&
5300 cd lttng-modules-2.10.*
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 The man:lttng-destroy(1) command also runs the man:lttng-stop(1)
5775 command implicitly (see <<basic-tracing-session-control,Start and stop a
5776 tracing session>>). You need to stop tracing to make LTTng flush the
5777 remaining trace data and make the trace readable.
5778
5779
5780 [[list-instrumentation-points]]
5781 === List the available instrumentation points
5782
5783 The <<lttng-sessiond,session daemon>> can query the running instrumented
5784 user applications and the Linux kernel to get a list of available
5785 instrumentation points. For the Linux kernel <<domain,tracing domain>>,
5786 they are tracepoints and system calls. For the user space tracing
5787 domain, they are tracepoints. For the other tracing domains, they are
5788 logger names.
5789
5790 To list the available instrumentation points:
5791
5792 * Use the man:lttng-list(1) command with the requested tracing domain's
5793 option amongst:
5794 +
5795 --
5796 * opt:lttng-list(1):--kernel: Linux kernel tracepoints (your Unix user
5797 must be a root user, or it must be a member of the
5798 <<tracing-group,tracing group>>).
5799 * opt:lttng-list(1):--kernel with opt:lttng-list(1):--syscall: Linux
5800 kernel system calls (your Unix user must be a root user, or it must be
5801 a member of the tracing group).
5802 * opt:lttng-list(1):--userspace: user space tracepoints.
5803 * opt:lttng-list(1):--jul: `java.util.logging` loggers.
5804 * opt:lttng-list(1):--log4j: Apache log4j loggers.
5805 * opt:lttng-list(1):--python: Python loggers.
5806 --
5807
5808 .List the available user space tracepoints.
5809 ====
5810 [role="term"]
5811 ----
5812 $ lttng list --userspace
5813 ----
5814 ====
5815
5816 .List the available Linux kernel system call tracepoints.
5817 ====
5818 [role="term"]
5819 ----
5820 $ lttng list --kernel --syscall
5821 ----
5822 ====
5823
5824
5825 [[enabling-disabling-events]]
5826 === Create and enable an event rule
5827
5828 Once you <<creating-destroying-tracing-sessions,create a tracing
5829 session>>, you can create <<event,event rules>> with the
5830 man:lttng-enable-event(1) command.
5831
5832 You specify each condition with a command-line option. The available
5833 condition options are shown in the following table.
5834
5835 [role="growable",cols="asciidoc,asciidoc,default"]
5836 .Condition command-line options for the man:lttng-enable-event(1) command.
5837 |====
5838 |Option |Description |Applicable tracing domains
5839
5840 |
5841 One of:
5842
5843 . `--syscall`
5844 . +--probe=__ADDR__+
5845 . +--function=__ADDR__+
5846
5847 |
5848 Instead of using the default _tracepoint_ instrumentation type, use:
5849
5850 . A Linux system call.
5851 . A Linux https://lwn.net/Articles/132196/[KProbe] (symbol or address).
5852 . The entry and return points of a Linux function (symbol or address).
5853
5854 |Linux kernel.
5855
5856 |First positional argument.
5857
5858 |
5859 Tracepoint or system call name. In the case of a Linux KProbe or
5860 function, this is a custom name given to the event rule. With the
5861 JUL, log4j, and Python domains, this is a logger name.
5862
5863 With a tracepoint, logger, or system call name, you can use the special
5864 `*` globbing character to match anything (for example, `sched_*`,
5865 `my_comp*:*msg_*`).
5866
5867 |All.
5868
5869 |
5870 One of:
5871
5872 . +--loglevel=__LEVEL__+
5873 . +--loglevel-only=__LEVEL__+
5874
5875 |
5876 . Match only tracepoints or log statements with a logging level at
5877 least as severe as +__LEVEL__+.
5878 . Match only tracepoints or log statements with a logging level
5879 equal to +__LEVEL__+.
5880
5881 See man:lttng-enable-event(1) for the list of available logging level
5882 names.
5883
5884 |User space, JUL, log4j, and Python.
5885
5886 |+--exclude=__EXCLUSIONS__+
5887
5888 |
5889 When you use a `*` character at the end of the tracepoint or logger
5890 name (first positional argument), exclude the specific names in the
5891 comma-delimited list +__EXCLUSIONS__+.
5892
5893 |
5894 User space, JUL, log4j, and Python.
5895
5896 |+--filter=__EXPR__+
5897
5898 |
5899 Match only events which satisfy the expression +__EXPR__+.
5900
5901 See man:lttng-enable-event(1) to learn more about the syntax of a
5902 filter expression.
5903
5904 |All.
5905
5906 |====
5907
5908 You attach an event rule to a <<channel,channel>> on creation. If you do
5909 not specify the channel with the opt:lttng-enable-event(1):--channel
5910 option, and if the event rule to create is the first in its
5911 <<domain,tracing domain>> for a given tracing session, then LTTng
5912 creates a _default channel_ for you. This default channel is reused in
5913 subsequent invocations of the man:lttng-enable-event(1) command for the
5914 same tracing domain.
5915
5916 An event rule is always enabled at creation time.
5917
5918 The following examples show how you can combine the previous
5919 command-line options to create simple to more complex event rules.
5920
5921 .Create an event rule targetting a Linux kernel tracepoint (default channel).
5922 ====
5923 [role="term"]
5924 ----
5925 $ lttng enable-event --kernel sched_switch
5926 ----
5927 ====
5928
5929 .Create an event rule matching four Linux kernel system calls (default channel).
5930 ====
5931 [role="term"]
5932 ----
5933 $ lttng enable-event --kernel --syscall open,write,read,close
5934 ----
5935 ====
5936
5937 .Create event rules matching tracepoints with filter expressions (default channel).
5938 ====
5939 [role="term"]
5940 ----
5941 $ lttng enable-event --kernel sched_switch --filter='prev_comm == "bash"'
5942 ----
5943
5944 [role="term"]
5945 ----
5946 $ lttng enable-event --kernel --all \
5947 --filter='$ctx.tid == 1988 || $ctx.tid == 1534'
5948 ----
5949
5950 [role="term"]
5951 ----
5952 $ lttng enable-event --jul my_logger \
5953 --filter='$app.retriever:cur_msg_id > 3'
5954 ----
5955
5956 IMPORTANT: Make sure to always quote the filter string when you
5957 use man:lttng(1) from a shell.
5958 ====
5959
5960 .Create an event rule matching any user space tracepoint of a given tracepoint provider with a log level range (default channel).
5961 ====
5962 [role="term"]
5963 ----
5964 $ lttng enable-event --userspace my_app:'*' --loglevel=TRACE_INFO
5965 ----
5966
5967 IMPORTANT: Make sure to always quote the wildcard character when you
5968 use man:lttng(1) from a shell.
5969 ====
5970
5971 .Create an event rule matching multiple Python loggers with a wildcard and with exclusions (default channel).
5972 ====
5973 [role="term"]
5974 ----
5975 $ lttng enable-event --python my-app.'*' \
5976 --exclude='my-app.module,my-app.hello'
5977 ----
5978 ====
5979
5980 .Create an event rule matching any Apache log4j logger with a specific log level (default channel).
5981 ====
5982 [role="term"]
5983 ----
5984 $ lttng enable-event --log4j --all --loglevel-only=LOG4J_WARN
5985 ----
5986 ====
5987
5988 .Create an event rule attached to a specific channel matching a specific user space tracepoint provider and tracepoint.
5989 ====
5990 [role="term"]
5991 ----
5992 $ lttng enable-event --userspace my_app:my_tracepoint --channel=my-channel
5993 ----
5994 ====
5995
5996 The event rules of a given channel form a whitelist: as soon as an
5997 emitted event passes one of them, LTTng can record the event. For
5998 example, an event named `my_app:my_tracepoint` emitted from a user space
5999 tracepoint with a `TRACE_ERROR` log level passes both of the following
6000 rules:
6001
6002 [role="term"]
6003 ----
6004 $ lttng enable-event --userspace my_app:my_tracepoint
6005 $ lttng enable-event --userspace my_app:my_tracepoint \
6006 --loglevel=TRACE_INFO
6007 ----
6008
6009 The second event rule is redundant: the first one includes
6010 the second one.
6011
6012
6013 [[disable-event-rule]]
6014 === Disable an event rule
6015
6016 To disable an event rule that you <<enabling-disabling-events,created>>
6017 previously, use the man:lttng-disable-event(1) command. This command
6018 disables _all_ the event rules (of a given tracing domain and channel)
6019 which match an instrumentation point. The other conditions are not
6020 supported as of LTTng{nbsp}{revision}.
6021
6022 The LTTng tracer does not record an emitted event which passes
6023 a _disabled_ event rule.
6024
6025 .Disable an event rule matching a Python logger (default channel).
6026 ====
6027 [role="term"]
6028 ----
6029 $ lttng disable-event --python my-logger
6030 ----
6031 ====
6032
6033 .Disable an event rule matching all `java.util.logging` loggers (default channel).
6034 ====
6035 [role="term"]
6036 ----
6037 $ lttng disable-event --jul '*'
6038 ----
6039 ====
6040
6041 .Disable _all_ the event rules of the default channel.
6042 ====
6043 The opt:lttng-disable-event(1):--all-events option is not, like the
6044 opt:lttng-enable-event(1):--all option of man:lttng-enable-event(1), the
6045 equivalent of the event name `*` (wildcard): it disables _all_ the event
6046 rules of a given channel.
6047
6048 [role="term"]
6049 ----
6050 $ lttng disable-event --jul --all-events
6051 ----
6052 ====
6053
6054 NOTE: You cannot delete an event rule once you create it.
6055
6056
6057 [[status]]
6058 === Get the status of a tracing session
6059
6060 To get the status of the current tracing session, that is, its
6061 parameters, its channels, event rules, and their attributes:
6062
6063 * Use the man:lttng-status(1) command:
6064 +
6065 --
6066 [role="term"]
6067 ----
6068 $ lttng status
6069 ----
6070 --
6071 +
6072
6073 To get the status of any tracing session:
6074
6075 * Use the man:lttng-list(1) command with the tracing session's name:
6076 +
6077 --
6078 [role="term"]
6079 ----
6080 $ lttng list my-session
6081 ----
6082 --
6083 +
6084 Replace `my-session` with the desired tracing session's name.
6085
6086
6087 [[basic-tracing-session-control]]
6088 === Start and stop a tracing session
6089
6090 Once you <<creating-destroying-tracing-sessions,create a tracing
6091 session>> and
6092 <<enabling-disabling-events,create one or more event rules>>,
6093 you can start and stop the tracers for this tracing session.
6094
6095 To start tracing in the current tracing session:
6096
6097 * Use the man:lttng-start(1) command:
6098 +
6099 --
6100 [role="term"]
6101 ----
6102 $ lttng start
6103 ----
6104 --
6105
6106 LTTng is very flexible: you can launch user applications before
6107 or after the you start the tracers. The tracers only record the events
6108 if they pass enabled event rules and if they occur while the tracers are
6109 started.
6110
6111 To stop tracing in the current tracing session:
6112
6113 * Use the man:lttng-stop(1) command:
6114 +
6115 --
6116 [role="term"]
6117 ----
6118 $ lttng stop
6119 ----
6120 --
6121 +
6122 If there were <<channel-overwrite-mode-vs-discard-mode,lost event
6123 records>> or lost sub-buffers since the last time you ran
6124 man:lttng-start(1), warnings are printed when you run the
6125 man:lttng-stop(1) command.
6126
6127 IMPORTANT: You need to stop tracing to make LTTng flush the remaining
6128 trace data and make the trace readable. Note that the
6129 man:lttng-destroy(1) command (see
6130 <<creating-destroying-tracing-sessions,Create and destroy a tracing
6131 session>>) also runs the man:lttng-stop(1) command implicitly.
6132
6133
6134 [[enabling-disabling-channels]]
6135 === Create a channel
6136
6137 Once you create a tracing session, you can create a <<channel,channel>>
6138 with the man:lttng-enable-channel(1) command.
6139
6140 Note that LTTng automatically creates a default channel when, for a
6141 given <<domain,tracing domain>>, no channels exist and you
6142 <<enabling-disabling-events,create>> the first event rule. This default
6143 channel is named `channel0` and its attributes are set to reasonable
6144 values. Therefore, you only need to create a channel when you need
6145 non-default attributes.
6146
6147 You specify each non-default channel attribute with a command-line
6148 option when you use the man:lttng-enable-channel(1) command. The
6149 available command-line options are:
6150
6151 [role="growable",cols="asciidoc,asciidoc"]
6152 .Command-line options for the man:lttng-enable-channel(1) command.
6153 |====
6154 |Option |Description
6155
6156 |`--overwrite`
6157
6158 |
6159 Use the _overwrite_
6160 <<channel-overwrite-mode-vs-discard-mode,event loss mode>> instead of
6161 the default _discard_ mode.
6162
6163 |`--buffers-pid` (user space tracing domain only)
6164
6165 |
6166 Use the per-process <<channel-buffering-schemes,buffering scheme>>
6167 instead of the default per-user buffering scheme.
6168
6169 |+--subbuf-size=__SIZE__+
6170
6171 |
6172 Allocate sub-buffers of +__SIZE__+ bytes (power of two), for each CPU,
6173 either for each Unix user (default), or for each instrumented process.
6174
6175 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
6176
6177 |+--num-subbuf=__COUNT__+
6178
6179 |
6180 Allocate +__COUNT__+ sub-buffers (power of two), for each CPU, either
6181 for each Unix user (default), or for each instrumented process.
6182
6183 See <<channel-subbuf-size-vs-subbuf-count,Sub-buffer count and size>>.
6184
6185 |+--tracefile-size=__SIZE__+
6186
6187 |
6188 Set the maximum size of each trace file that this channel writes within
6189 a stream to +__SIZE__+ bytes instead of no maximum.
6190
6191 See <<tracefile-rotation,Trace file count and size>>.
6192
6193 |+--tracefile-count=__COUNT__+
6194
6195 |
6196 Limit the number of trace files that this channel creates to
6197 +__COUNT__+ channels instead of no limit.
6198
6199 See <<tracefile-rotation,Trace file count and size>>.
6200
6201 |+--switch-timer=__PERIODUS__+
6202
6203 |
6204 Set the <<channel-switch-timer,switch timer period>>
6205 to +__PERIODUS__+{nbsp}µs.
6206
6207 |+--read-timer=__PERIODUS__+
6208
6209 |
6210 Set the <<channel-read-timer,read timer period>>
6211 to +__PERIODUS__+{nbsp}µs.
6212
6213 |[[opt-blocking-timeout]]+--blocking-timeout=__TIMEOUTUS__+
6214
6215 |
6216 Set the timeout of user space applications which load LTTng-UST
6217 in blocking mode to +__TIMEOUTUS__+:
6218
6219 0 (default)::
6220 Never block (non-blocking mode).
6221
6222 `inf`::
6223 Block forever until space is available in a sub-buffer to record
6224 the event.
6225
6226 __n__, a positive value::
6227 Wait for at most __n__ µs when trying to write into a sub-buffer.
6228
6229 Note that, for this option to have any effect on an instrumented
6230 user space application, you need to run the application with a set
6231 env:LTTNG_UST_ALLOW_BLOCKING environment variable.
6232
6233 |+--output=__TYPE__+ (Linux kernel tracing domain only)
6234
6235 |
6236 Set the channel's output type to +__TYPE__+, either `mmap` or `splice`.
6237
6238 |====
6239
6240 You can only create a channel in the Linux kernel and user space
6241 <<domain,tracing domains>>: other tracing domains have their own channel
6242 created on the fly when <<enabling-disabling-events,creating event
6243 rules>>.
6244
6245 [IMPORTANT]
6246 ====
6247 Because of a current LTTng limitation, you must create all channels
6248 _before_ you <<basic-tracing-session-control,start tracing>> in a given
6249 tracing session, that is, before the first time you run
6250 man:lttng-start(1).
6251
6252 Since LTTng automatically creates a default channel when you use the
6253 man:lttng-enable-event(1) command with a specific tracing domain, you
6254 cannot, for example, create a Linux kernel event rule, start tracing,
6255 and then create a user space event rule, because no user space channel
6256 exists yet and it's too late to create one.
6257
6258 For this reason, make sure to configure your channels properly
6259 before starting the tracers for the first time!
6260 ====
6261
6262 The following examples show how you can combine the previous
6263 command-line options to create simple to more complex channels.
6264
6265 .Create a Linux kernel channel with default attributes.
6266 ====
6267 [role="term"]
6268 ----
6269 $ lttng enable-channel --kernel my-channel
6270 ----
6271 ====
6272
6273 .Create a user space channel with 4 sub-buffers or 1{nbsp}MiB each, per CPU, per instrumented process.
6274 ====
6275 [role="term"]
6276 ----
6277 $ lttng enable-channel --userspace --num-subbuf=4 --subbuf-size=1M \
6278 --buffers-pid my-channel
6279 ----
6280 ====
6281
6282 .[[blocking-timeout-example]]Create a default user space channel with an infinite blocking timeout.
6283 ====
6284 <<creating-destroying-tracing-sessions,Create a tracing-session>>,
6285 create the channel, <<enabling-disabling-events,create an event rule>>,
6286 and <<basic-tracing-session-control,start tracing>>:
6287
6288 [role="term"]
6289 ----
6290 $ lttng create
6291 $ lttng enable-channel --userspace --blocking-timeout=inf blocking-channel
6292 $ lttng enable-event --userspace --channel=blocking-channel --all
6293 $ lttng start
6294 ----
6295
6296 Run an application instrumented with LTTng-UST and allow it to block:
6297
6298 [role="term"]
6299 ----
6300 $ LTTNG_UST_ALLOW_BLOCKING=1 my-app
6301 ----
6302 ====
6303
6304 .Create a Linux kernel channel which rotates 8 trace files of 4{nbsp}MiB each for each stream
6305 ====
6306 [role="term"]
6307 ----
6308 $ lttng enable-channel --kernel --tracefile-count=8 \
6309 --tracefile-size=4194304 my-channel
6310 ----
6311 ====
6312
6313 .Create a user space channel in overwrite (or _flight recorder_) mode.
6314 ====
6315 [role="term"]
6316 ----
6317 $ lttng enable-channel --userspace --overwrite my-channel
6318 ----
6319 ====
6320
6321 You can <<enabling-disabling-events,create>> the same event rule in
6322 two different channels:
6323
6324 [role="term"]
6325 ----
6326 $ lttng enable-event --userspace --channel=my-channel app:tp
6327 $ lttng enable-event --userspace --channel=other-channel app:tp
6328 ----
6329
6330 If both channels are enabled, when a tracepoint named `app:tp` is
6331 reached, LTTng records two events, one for each channel.
6332
6333
6334 [[disable-channel]]
6335 === Disable a channel
6336
6337 To disable a specific channel that you <<enabling-disabling-channels,created>>
6338 previously, use the man:lttng-disable-channel(1) command.
6339
6340 .Disable a specific Linux kernel channel.
6341 ====
6342 [role="term"]
6343 ----
6344 $ lttng disable-channel --kernel my-channel
6345 ----
6346 ====
6347
6348 The state of a channel precedes the individual states of event rules
6349 attached to it: event rules which belong to a disabled channel, even if
6350 they are enabled, are also considered disabled.
6351
6352
6353 [[adding-context]]
6354 === Add context fields to a channel
6355
6356 Event record fields in trace files provide important information about
6357 events that occured previously, but sometimes some external context may
6358 help you solve a problem faster. Examples of context fields are:
6359
6360 * The **process ID**, **thread ID**, **process name**, and
6361 **process priority** of the thread in which the event occurs.
6362 * The **hostname** of the system on which the event occurs.
6363 * The current values of many possible **performance counters** using
6364 perf, for example:
6365 ** CPU cycles, stalled cycles, idle cycles, and the other cycle types.
6366 ** Cache misses.
6367 ** Branch instructions, misses, and loads.
6368 ** CPU faults.
6369 * Any context defined at the application level (supported for the
6370 JUL and log4j <<domain,tracing domains>>).
6371
6372 To get the full list of available context fields, see
6373 `lttng add-context --list`. Some context fields are reserved for a
6374 specific <<domain,tracing domain>> (Linux kernel or user space).
6375
6376 You add context fields to <<channel,channels>>. All the events
6377 that a channel with added context fields records contain those fields.
6378
6379 To add context fields to one or all the channels of a given tracing
6380 session:
6381
6382 * Use the man:lttng-add-context(1) command.
6383
6384 .Add context fields to all the channels of the current tracing session.
6385 ====
6386 The following command line adds the virtual process identifier and
6387 the per-thread CPU cycles count fields to all the user space channels
6388 of the current tracing session.
6389
6390 [role="term"]
6391 ----
6392 $ lttng add-context --userspace --type=vpid --type=perf:thread:cpu-cycles
6393 ----
6394 ====
6395
6396 .Add performance counter context fields by raw ID
6397 ====
6398 See man:lttng-add-context(1) for the exact format of the context field
6399 type, which is partly compatible with the format used in
6400 man:perf-record(1).
6401
6402 [role="term"]
6403 ----
6404 $ lttng add-context --userspace --type=perf:thread:raw:r0110:test
6405 $ lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted
6406 ----
6407 ====
6408
6409 .Add a context field to a specific channel.
6410 ====
6411 The following command line adds the thread identifier context field
6412 to the Linux kernel channel named `my-channel` in the current
6413 tracing session.
6414
6415 [role="term"]
6416 ----
6417 $ lttng add-context --kernel --channel=my-channel --type=tid
6418 ----
6419 ====
6420
6421 .Add an application-specific context field to a specific channel.
6422 ====
6423 The following command line adds the `cur_msg_id` context field of the
6424 `retriever` context retriever for all the instrumented
6425 <<java-application,Java applications>> recording <<event,event records>>
6426 in the channel named `my-channel`:
6427
6428 [role="term"]
6429 ----
6430 $ lttng add-context --kernel --channel=my-channel \
6431 --type='$app:retriever:cur_msg_id'
6432 ----
6433
6434 IMPORTANT: Make sure to always quote the `$` character when you
6435 use man:lttng-add-context(1) from a shell.
6436 ====
6437
6438 NOTE: You cannot remove context fields from a channel once you add it.
6439
6440
6441 [role="since-2.7"]
6442 [[pid-tracking]]
6443 === Track process IDs
6444
6445 It's often useful to allow only specific process IDs (PIDs) to emit
6446 events. For example, you may wish to record all the system calls made by
6447 a given process (Ă  la http://linux.die.net/man/1/strace[strace]).
6448
6449 The man:lttng-track(1) and man:lttng-untrack(1) commands serve this
6450 purpose. Both commands operate on a whitelist of process IDs. You _add_
6451 entries to this whitelist with the man:lttng-track(1) command and remove
6452 entries with the man:lttng-untrack(1) command. Any process which has one
6453 of the PIDs in the whitelist is allowed to emit LTTng events which pass
6454 an enabled <<event,event rule>>.
6455
6456 NOTE: The PID tracker tracks the _numeric process IDs_. Should a
6457 process with a given tracked ID exit and another process be given this
6458 ID, then the latter would also be allowed to emit events.
6459
6460 .Track and untrack process IDs.
6461 ====
6462 For the sake of the following example, assume the target system has 16
6463 possible PIDs.
6464
6465 When you
6466 <<creating-destroying-tracing-sessions,create a tracing session>>,
6467 the whitelist contains all the possible PIDs:
6468
6469 [role="img-100"]
6470 .All PIDs are tracked.
6471 image::track-all.png[]
6472
6473 When the whitelist is full and you use the man:lttng-track(1) command to
6474 specify some PIDs to track, LTTng first clears the whitelist, then it
6475 tracks the specific PIDs. After:
6476
6477 [role="term"]
6478 ----
6479 $ lttng track --pid=3,4,7,10,13
6480 ----
6481
6482 the whitelist is:
6483
6484 [role="img-100"]
6485 .PIDs 3, 4, 7, 10, and 13 are tracked.
6486 image::track-3-4-7-10-13.png[]
6487
6488 You can add more PIDs to the whitelist afterwards:
6489
6490 [role="term"]
6491 ----
6492 $ lttng track --pid=1,15,16
6493 ----
6494
6495 The result is:
6496
6497 [role="img-100"]
6498 .PIDs 1, 15, and 16 are added to the whitelist.
6499 image::track-1-3-4-7-10-13-15-16.png[]
6500
6501 The man:lttng-untrack(1) command removes entries from the PID tracker's
6502 whitelist. Given the previous example, the following command:
6503
6504 [role="term"]
6505 ----
6506 $ lttng untrack --pid=3,7,10,13
6507 ----
6508
6509 leads to this whitelist:
6510
6511 [role="img-100"]
6512 .PIDs 3, 7, 10, and 13 are removed from the whitelist.
6513 image::track-1-4-15-16.png[]
6514
6515 LTTng can track all possible PIDs again using the
6516 opt:lttng-track(1):--all option:
6517
6518 [role="term"]
6519 ----
6520 $ lttng track --pid --all
6521 ----
6522
6523 The result is, again:
6524
6525 [role="img-100"]
6526 .All PIDs are tracked.
6527 image::track-all.png[]
6528 ====
6529
6530 .Track only specific PIDs
6531 ====
6532 A very typical use case with PID tracking is to start with an empty
6533 whitelist, then <<basic-tracing-session-control,start the tracers>>, and
6534 then add PIDs manually while tracers are active. You can accomplish this
6535 by using the opt:lttng-untrack(1):--all option of the
6536 man:lttng-untrack(1) command to clear the whitelist after you
6537 <<creating-destroying-tracing-sessions,create a tracing session>>:
6538
6539 [role="term"]
6540 ----
6541 $ lttng untrack --pid --all
6542 ----
6543
6544 gives:
6545
6546 [role="img-100"]
6547 .No PIDs are tracked.
6548 image::untrack-all.png[]
6549
6550 If you trace with this whitelist configuration, the tracer records no
6551 events for this <<domain,tracing domain>> because no processes are
6552 tracked. You can use the man:lttng-track(1) command as usual to track
6553 specific PIDs, for example:
6554
6555 [role="term"]
6556 ----
6557 $ lttng track --pid=6,11
6558 ----
6559
6560 Result:
6561
6562 [role="img-100"]
6563 .PIDs 6 and 11 are tracked.
6564 image::track-6-11.png[]
6565 ====
6566
6567
6568 [role="since-2.5"]
6569 [[saving-loading-tracing-session]]
6570 === Save and load tracing session configurations
6571
6572 Configuring a <<tracing-session,tracing session>> can be long. Some of
6573 the tasks involved are:
6574
6575 * <<enabling-disabling-channels,Create channels>> with
6576 specific attributes.
6577 * <<adding-context,Add context fields>> to specific channels.
6578 * <<enabling-disabling-events,Create event rules>> with specific log
6579 level and filter conditions.
6580
6581 If you use LTTng to solve real world problems, chances are you have to
6582 record events using the same tracing session setup over and over,
6583 modifying a few variables each time in your instrumented program
6584 or environment. To avoid constant tracing session reconfiguration,
6585 the man:lttng(1) command-line tool can save and load tracing session
6586 configurations to/from XML files.
6587
6588 To save a given tracing session configuration:
6589
6590 * Use the man:lttng-save(1) command:
6591 +
6592 --
6593 [role="term"]
6594 ----
6595 $ lttng save my-session
6596 ----
6597 --
6598 +
6599 Replace `my-session` with the name of the tracing session to save.
6600
6601 LTTng saves tracing session configurations to
6602 dir:{$LTTNG_HOME/.lttng/sessions} by default. Note that the
6603 env:LTTNG_HOME environment variable defaults to `$HOME` if not set. Use
6604 the opt:lttng-save(1):--output-path option to change this destination
6605 directory.
6606
6607 LTTng saves all configuration parameters, for example:
6608
6609 * The tracing session name.
6610 * The trace data output path.
6611 * The channels with their state and all their attributes.
6612 * The context fields you added to channels.
6613 * The event rules with their state, log level and filter conditions.
6614
6615 To load a tracing session:
6616
6617 * Use the man:lttng-load(1) command:
6618 +
6619 --
6620 [role="term"]
6621 ----
6622 $ lttng load my-session
6623 ----
6624 --
6625 +
6626 Replace `my-session` with the name of the tracing session to load.
6627
6628 When LTTng loads a configuration, it restores your saved tracing session
6629 as if you just configured it manually.
6630
6631 See man:lttng(1) for the complete list of command-line options. You
6632 can also save and load all many sessions at a time, and decide in which
6633 directory to output the XML files.
6634
6635
6636 [[sending-trace-data-over-the-network]]
6637 === Send trace data over the network
6638
6639 LTTng can send the recorded trace data to a remote system over the
6640 network instead of writing it to the local file system.
6641
6642 To send the trace data over the network:
6643
6644 . On the _remote_ system (which can also be the target system),
6645 start an LTTng <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)):
6646 +
6647 --
6648 [role="term"]
6649 ----
6650 $ lttng-relayd
6651 ----
6652 --
6653
6654 . On the _target_ system, create a tracing session configured to
6655 send trace data over the network:
6656 +
6657 --
6658 [role="term"]
6659 ----
6660 $ lttng create my-session --set-url=net://remote-system
6661 ----
6662 --
6663 +
6664 Replace `remote-system` by the host name or IP address of the
6665 remote system. See man:lttng-create(1) for the exact URL format.
6666
6667 . On the target system, use the man:lttng(1) command-line tool as usual.
6668 When tracing is active, the target's consumer daemon sends sub-buffers
6669 to the relay daemon running on the remote system instead of flushing
6670 them to the local file system. The relay daemon writes the received
6671 packets to the local file system.
6672
6673 The relay daemon writes trace files to
6674 +$LTTNG_HOME/lttng-traces/__hostname__/__session__+ by default, where
6675 +__hostname__+ is the host name of the target system and +__session__+
6676 is the tracing session name. Note that the env:LTTNG_HOME environment
6677 variable defaults to `$HOME` if not set. Use the
6678 opt:lttng-relayd(8):--output option of man:lttng-relayd(8) to write
6679 trace files to another base directory.
6680
6681
6682 [role="since-2.4"]
6683 [[lttng-live]]
6684 === View events as LTTng emits them (noch:{LTTng} live)
6685
6686 LTTng live is a network protocol implemented by the <<lttng-relayd,relay
6687 daemon>> (man:lttng-relayd(8)) to allow compatible trace viewers to
6688 display events as LTTng emits them on the target system while tracing is
6689 active.
6690
6691 The relay daemon creates a _tee_: it forwards the trace data to both
6692 the local file system and to connected live viewers:
6693
6694 [role="img-90"]
6695 .The relay daemon creates a _tee_, forwarding the trace data to both trace files and a connected live viewer.
6696 image::live.png[]
6697
6698 To use LTTng live:
6699
6700 . On the _target system_, create a <<tracing-session,tracing session>>
6701 in _live mode_:
6702 +
6703 --
6704 [role="term"]
6705 ----
6706 $ lttng create my-session --live
6707 ----
6708 --
6709 +
6710 This spawns a local relay daemon.
6711
6712 . Start the live viewer and configure it to connect to the relay
6713 daemon. For example, with http://diamon.org/babeltrace[Babeltrace]:
6714 +
6715 --
6716 [role="term"]
6717 ----
6718 $ babeltrace --input-format=lttng-live \
6719 net://localhost/host/hostname/my-session
6720 ----
6721 --
6722 +
6723 Replace:
6724 +
6725 --
6726 * `hostname` with the host name of the target system.
6727 * `my-session` with the name of the tracing session to view.
6728 --
6729
6730 . Configure the tracing session as usual with the man:lttng(1)
6731 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6732
6733 You can list the available live tracing sessions with Babeltrace:
6734
6735 [role="term"]
6736 ----
6737 $ babeltrace --input-format=lttng-live net://localhost
6738 ----
6739
6740 You can start the relay daemon on another system. In this case, you need
6741 to specify the relay daemon's URL when you create the tracing session
6742 with the opt:lttng-create(1):--set-url option. You also need to replace
6743 `localhost` in the procedure above with the host name of the system on
6744 which the relay daemon is running.
6745
6746 See man:lttng-create(1) and man:lttng-relayd(8) for the complete list of
6747 command-line options.
6748
6749
6750 [role="since-2.3"]
6751 [[taking-a-snapshot]]
6752 === Take a snapshot of the current sub-buffers of a tracing session
6753
6754 The normal behavior of LTTng is to append full sub-buffers to growing
6755 trace data files. This is ideal to keep a full history of the events
6756 that occurred on the target system, but it can
6757 represent too much data in some situations. For example, you may wish
6758 to trace your application continuously until some critical situation
6759 happens, in which case you only need the latest few recorded
6760 events to perform the desired analysis, not multi-gigabyte trace files.
6761
6762 With the man:lttng-snapshot(1) command, you can take a snapshot of the
6763 current sub-buffers of a given <<tracing-session,tracing session>>.
6764 LTTng can write the snapshot to the local file system or send it over
6765 the network.
6766
6767 To take a snapshot:
6768
6769 . Create a tracing session in _snapshot mode_:
6770 +
6771 --
6772 [role="term"]
6773 ----
6774 $ lttng create my-session --snapshot
6775 ----
6776 --
6777 +
6778 The <<channel-overwrite-mode-vs-discard-mode,event loss mode>> of
6779 <<channel,channels>> created in this mode is automatically set to
6780 _overwrite_ (flight recorder mode).
6781
6782 . Configure the tracing session as usual with the man:lttng(1)
6783 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6784
6785 . **Optional**: When you need to take a snapshot,
6786 <<basic-tracing-session-control,stop tracing>>.
6787 +
6788 You can take a snapshot when the tracers are active, but if you stop
6789 them first, you are sure that the data in the sub-buffers does not
6790 change before you actually take the snapshot.
6791
6792 . Take a snapshot:
6793 +
6794 --
6795 [role="term"]
6796 ----
6797 $ lttng snapshot record --name=my-first-snapshot
6798 ----
6799 --
6800 +
6801 LTTng writes the current sub-buffers of all the current tracing
6802 session's channels to trace files on the local file system. Those trace
6803 files have `my-first-snapshot` in their name.
6804
6805 There is no difference between the format of a normal trace file and the
6806 format of a snapshot: viewers of LTTng traces also support LTTng
6807 snapshots.
6808
6809 By default, LTTng writes snapshot files to the path shown by
6810 `lttng snapshot list-output`. You can change this path or decide to send
6811 snapshots over the network using either:
6812
6813 . An output path or URL that you specify when you create the
6814 tracing session.
6815 . An snapshot output path or URL that you add using
6816 `lttng snapshot add-output`
6817 . An output path or URL that you provide directly to the
6818 `lttng snapshot record` command.
6819
6820 Method 3 overrides method 2, which overrides method 1. When you
6821 specify a URL, a relay daemon must listen on a remote system (see
6822 <<sending-trace-data-over-the-network,Send trace data over the network>>).
6823
6824
6825 [role="since-2.6"]
6826 [[mi]]
6827 === Use the machine interface
6828
6829 With any command of the man:lttng(1) command-line tool, you can set the
6830 opt:lttng(1):--mi option to `xml` (before the command name) to get an
6831 XML machine interface output, for example:
6832
6833 [role="term"]
6834 ----
6835 $ lttng --mi=xml enable-event --kernel --syscall open
6836 ----
6837
6838 A schema definition (XSD) is
6839 https://github.com/lttng/lttng-tools/blob/stable-2.10/src/common/mi-lttng-3.0.xsd[available]
6840 to ease the integration with external tools as much as possible.
6841
6842
6843 [role="since-2.8"]
6844 [[metadata-regenerate]]
6845 === Regenerate the metadata of an LTTng trace
6846
6847 An LTTng trace, which is a http://diamon.org/ctf[CTF] trace, has both
6848 data stream files and a metadata file. This metadata file contains,
6849 amongst other things, information about the offset of the clock sources
6850 used to timestamp <<event,event records>> when tracing.
6851
6852 If, once a <<tracing-session,tracing session>> is
6853 <<basic-tracing-session-control,started>>, a major
6854 https://en.wikipedia.org/wiki/Network_Time_Protocol[NTP] correction
6855 happens, the trace's clock offset also needs to be updated. You
6856 can use the `metadata` item of the man:lttng-regenerate(1) command
6857 to do so.
6858
6859 The main use case of this command is to allow a system to boot with
6860 an incorrect wall time and trace it with LTTng before its wall time
6861 is corrected. Once the system is known to be in a state where its
6862 wall time is correct, it can run `lttng regenerate metadata`.
6863
6864 To regenerate the metadata of an LTTng trace:
6865
6866 * Use the `metadata` item of the man:lttng-regenerate(1) command:
6867 +
6868 --
6869 [role="term"]
6870 ----
6871 $ lttng regenerate metadata
6872 ----
6873 --
6874
6875 [IMPORTANT]
6876 ====
6877 `lttng regenerate metadata` has the following limitations:
6878
6879 * Tracing session <<creating-destroying-tracing-sessions,created>>
6880 in non-live mode.
6881 * User space <<channel,channels>>, if any, are using
6882 <<channel-buffering-schemes,per-user buffering>>.
6883 ====
6884
6885
6886 [role="since-2.9"]
6887 [[regenerate-statedump]]
6888 === Regenerate the state dump of a tracing session
6889
6890 The LTTng kernel and user space tracers generate state dump
6891 <<event,event records>> when the application starts or when you
6892 <<basic-tracing-session-control,start a tracing session>>. An analysis
6893 can use the state dump event records to set an initial state before it
6894 builds the rest of the state from the following event records.
6895 http://tracecompass.org/[Trace Compass] is a notable example of an
6896 application which uses the state dump of an LTTng trace.
6897
6898 When you <<taking-a-snapshot,take a snapshot>>, it's possible that the
6899 state dump event records are not included in the snapshot because they
6900 were recorded to a sub-buffer that has been consumed or overwritten
6901 already.
6902
6903 You can use the `lttng regenerate statedump` command to emit the state
6904 dump event records again.
6905
6906 To regenerate the state dump of the current tracing session, provided
6907 create it in snapshot mode, before you take a snapshot:
6908
6909 . Use the `statedump` item of the man:lttng-regenerate(1) command:
6910 +
6911 --
6912 [role="term"]
6913 ----
6914 $ lttng regenerate statedump
6915 ----
6916 --
6917
6918 . <<basic-tracing-session-control,Stop the tracing session>>:
6919 +
6920 --
6921 [role="term"]
6922 ----
6923 $ lttng stop
6924 ----
6925 --
6926
6927 . <<taking-a-snapshot,Take a snapshot>>:
6928 +
6929 --
6930 [role="term"]
6931 ----
6932 $ lttng snapshot record --name=my-snapshot
6933 ----
6934 --
6935
6936 Depending on the event throughput, you should run steps 1 and 2
6937 as closely as possible.
6938
6939 NOTE: To record the state dump events, you need to
6940 <<enabling-disabling-events,create event rules>> which enable them.
6941 LTTng-UST state dump tracepoints start with `lttng_ust_statedump:`.
6942 LTTng-modules state dump tracepoints start with `lttng_statedump_`.
6943
6944
6945 [role="since-2.7"]
6946 [[persistent-memory-file-systems]]
6947 === Record trace data on persistent memory file systems
6948
6949 https://en.wikipedia.org/wiki/Non-volatile_random-access_memory[Non-volatile random-access memory]
6950 (NVRAM) is random-access memory that retains its information when power
6951 is turned off (non-volatile). Systems with such memory can store data
6952 structures in RAM and retrieve them after a reboot, without flushing
6953 to typical _storage_.
6954
6955 Linux supports NVRAM file systems thanks to either
6956 http://pramfs.sourceforge.net/[PRAMFS] or
6957 https://www.kernel.org/doc/Documentation/filesystems/dax.txt[DAX]{nbsp}+{nbsp}http://lkml.iu.edu/hypermail/linux/kernel/1504.1/03463.html[pmem]
6958 (requires Linux 4.1+).
6959
6960 This section does not describe how to operate such file systems;
6961 we assume that you have a working persistent memory file system.
6962
6963 When you create a <<tracing-session,tracing session>>, you can specify
6964 the path of the shared memory holding the sub-buffers. If you specify a
6965 location on an NVRAM file system, then you can retrieve the latest
6966 recorded trace data when the system reboots after a crash.
6967
6968 To record trace data on a persistent memory file system and retrieve the
6969 trace data after a system crash:
6970
6971 . Create a tracing session with a sub-buffer shared memory path located
6972 on an NVRAM file system:
6973 +
6974 --
6975 [role="term"]
6976 ----
6977 $ lttng create my-session --shm-path=/path/to/shm
6978 ----
6979 --
6980
6981 . Configure the tracing session as usual with the man:lttng(1)
6982 command-line tool, and <<basic-tracing-session-control,start tracing>>.
6983
6984 . After a system crash, use the man:lttng-crash(1) command-line tool to
6985 view the trace data recorded on the NVRAM file system:
6986 +
6987 --
6988 [role="term"]
6989 ----
6990 $ lttng-crash /path/to/shm
6991 ----
6992 --
6993
6994 The binary layout of the ring buffer files is not exactly the same as
6995 the trace files layout. This is why you need to use man:lttng-crash(1)
6996 instead of your preferred trace viewer directly.
6997
6998 To convert the ring buffer files to LTTng trace files:
6999
7000 * Use the opt:lttng-crash(1):--extract option of man:lttng-crash(1):
7001 +
7002 --
7003 [role="term"]
7004 ----
7005 $ lttng-crash --extract=/path/to/trace /path/to/shm
7006 ----
7007 --
7008
7009
7010 [role="since-2.10"]
7011 [[notif-trigger-api]]
7012 === Get notified when a channel's buffer usage is too high or too low
7013
7014 With LTTng's $$C/C++$$ notification and trigger API, your user
7015 application can get notified when the buffer usage of one or more
7016 <<channel,channels>> becomes too low or too high. You can use this API
7017 and enable or disable <<event,event rules>> during tracing to avoid
7018 <<channel-overwrite-mode-vs-discard-mode,discarded event records>>.
7019
7020 .Have a user application get notified when an LTTng channel's buffer usage is too high.
7021 ====
7022 In this example, we create and build an application which gets notified
7023 when the buffer usage of a specific LTTng channel is higher than
7024 75{nbsp}%. We only print that it is the case in the example, but we
7025 could as well use the API of <<liblttng-ctl-lttng,`liblttng-ctl`>> to
7026 disable event rules when this happens.
7027
7028 . Create the application's C source file:
7029 +
7030 --
7031 [source,c]
7032 .path:{notif-app.c}
7033 ----
7034 #include <stdio.h>
7035 #include <assert.h>
7036 #include <lttng/domain.h>
7037 #include <lttng/action/action.h>
7038 #include <lttng/action/notify.h>
7039 #include <lttng/condition/condition.h>
7040 #include <lttng/condition/buffer-usage.h>
7041 #include <lttng/condition/evaluation.h>
7042 #include <lttng/notification/channel.h>
7043 #include <lttng/notification/notification.h>
7044 #include <lttng/trigger/trigger.h>
7045 #include <lttng/endpoint.h>
7046
7047 int main(int argc, char *argv[])
7048 {
7049 int exit_status = 0;
7050 struct lttng_notification_channel *notification_channel;
7051 struct lttng_condition *condition;
7052 struct lttng_action *action;
7053 struct lttng_trigger *trigger;
7054 const char *tracing_session_name;
7055 const char *channel_name;
7056
7057 assert(argc >= 3);
7058 tracing_session_name = argv[1];
7059 channel_name = argv[2];
7060
7061 /*
7062 * Create a notification channel. A notification channel
7063 * connects the user application to the LTTng session daemon.
7064 * This notification channel can be used to listen to various
7065 * types of notifications.
7066 */
7067 notification_channel = lttng_notification_channel_create(
7068 lttng_session_daemon_notification_endpoint);
7069
7070 /*
7071 * Create a "high buffer usage" condition. In this case, the
7072 * condition is reached when the buffer usage is greater than or
7073 * equal to 75 %. We create the condition for a specific tracing
7074 * session name, channel name, and for the user space tracing
7075 * domain.
7076 *
7077 * The "low buffer usage" condition type also exists.
7078 */
7079 condition = lttng_condition_buffer_usage_high_create();
7080 lttng_condition_buffer_usage_set_threshold_ratio(condition, .75);
7081 lttng_condition_buffer_usage_set_session_name(
7082 condition, tracing_session_name);
7083 lttng_condition_buffer_usage_set_channel_name(condition,
7084 channel_name);
7085 lttng_condition_buffer_usage_set_domain_type(condition,
7086 LTTNG_DOMAIN_UST);
7087
7088 /*
7089 * Create an action (get a notification) to take when the
7090 * condition created above is reached.
7091 */
7092 action = lttng_action_notify_create();
7093
7094 /*
7095 * Create a trigger. A trigger associates a condition to an
7096 * action: the action is executed when the condition is reached.
7097 */
7098 trigger = lttng_trigger_create(condition, action);
7099
7100 /* Register the trigger to LTTng. */
7101 lttng_register_trigger(trigger);
7102
7103 /*
7104 * Now that we have registered a trigger, a notification will be
7105 * emitted everytime its condition is met. To receive this
7106 * notification, we must subscribe to notifications that match
7107 * the same condition.
7108 */
7109 lttng_notification_channel_subscribe(notification_channel,
7110 condition);
7111
7112 /*
7113 * Notification loop. You can put this in a dedicated thread to
7114 * avoid blocking the main thread.
7115 */
7116 for (;;) {
7117 struct lttng_notification *notification;
7118 enum lttng_notification_channel_status status;
7119 const struct lttng_evaluation *notification_evaluation;
7120 const struct lttng_condition *notification_condition;
7121 double buffer_usage;
7122
7123 /* Receive the next notification. */
7124 status = lttng_notification_channel_get_next_notification(
7125 notification_channel, &notification);
7126
7127 switch (status) {
7128 case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK:
7129 break;
7130 case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED:
7131 /*
7132 * The session daemon can drop notifications if
7133 * a monitoring application is not consuming the
7134 * notifications fast enough.
7135 */
7136 continue;
7137 case LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED:
7138 /*
7139 * The notification channel has been closed by the
7140 * session daemon. This is typically caused by a session
7141 * daemon shutting down.
7142 */
7143 goto end;
7144 default:
7145 /* Unhandled conditions or errors. */
7146 exit_status = 1;
7147 goto end;
7148 }
7149
7150 /*
7151 * A notification provides, amongst other things:
7152 *
7153 * * The condition that caused this notification to be
7154 * emitted.
7155 * * The condition evaluation, which provides more
7156 * specific information on the evaluation of the
7157 * condition.
7158 *
7159 * The condition evaluation provides the buffer usage
7160 * value at the moment the condition was reached.
7161 */
7162 notification_condition = lttng_notification_get_condition(
7163 notification);
7164 notification_evaluation = lttng_notification_get_evaluation(
7165 notification);
7166
7167 /* We're subscribed to only one condition. */
7168 assert(lttng_condition_get_type(notification_condition) ==
7169 LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH);
7170
7171 /*
7172 * Get the exact sampled buffer usage from the
7173 * condition evaluation.
7174 */
7175 lttng_evaluation_buffer_usage_get_usage_ratio(
7176 notification_evaluation, &buffer_usage);
7177
7178 /*
7179 * At this point, instead of printing a message, we
7180 * could do something to reduce the channel's buffer
7181 * usage, like disable specific events.
7182 */
7183 printf("Buffer usage is %f %% in tracing session \"%s\", "
7184 "user space channel \"%s\".\n", buffer_usage * 100,
7185 tracing_session_name, channel_name);
7186 lttng_notification_destroy(notification);
7187 }
7188
7189 end:
7190 lttng_action_destroy(action);
7191 lttng_condition_destroy(condition);
7192 lttng_trigger_destroy(trigger);
7193 lttng_notification_channel_destroy(notification_channel);
7194 return exit_status;
7195 }
7196 ----
7197 --
7198
7199 . Build the `notif-app` application, linking it to `liblttng-ctl`:
7200 +
7201 --
7202 [role="term"]
7203 ----
7204 $ gcc -o notif-app notif-app.c -llttng-ctl
7205 ----
7206 --
7207
7208 . <<creating-destroying-tracing-sessions,Create a tracing session>>,
7209 <<enabling-disabling-events,create an event rule>> matching all the
7210 user space tracepoints, and
7211 <<basic-tracing-session-control,start tracing>>:
7212 +
7213 --
7214 [role="term"]
7215 ----
7216 $ lttng create my-session
7217 $ lttng enable-event --userspace --all
7218 $ lttng start
7219 ----
7220 --
7221 +
7222 If you create the channel manually with the man:lttng-enable-channel(1)
7223 command, you can control how frequently are the current values of the
7224 channel's properties sampled to evaluate user conditions with the
7225 opt:lttng-enable-channel(1):--monitor-timer option.
7226
7227 . Run the `notif-app` application. This program accepts the
7228 <<tracing-session,tracing session>> name and the user space channel
7229 name as its two first arguments. The channel which LTTng automatically
7230 creates with the man:lttng-enable-event(1) command above is named
7231 `channel0`:
7232 +
7233 --
7234 [role="term"]
7235 ----
7236 $ ./notif-app my-session channel0
7237 ----
7238 --
7239
7240 . In another terminal, run an application with a very high event
7241 throughput so that the 75{nbsp}% buffer usage condition is reached.
7242 +
7243 In the first terminal, the application should print lines like this:
7244 +
7245 ----
7246 Buffer usage is 81.45197 % in tracing session "my-session", user space
7247 channel "channel0".
7248 ----
7249 +
7250 If you don't see anything, try modifying the condition in
7251 path:{notif-app.c} to a lower value (0.1, for example), rebuilding it
7252 (step 2) and running it again (step 4).
7253 ====
7254
7255
7256 [[reference]]
7257 == Reference
7258
7259 [[lttng-modules-ref]]
7260 === noch:{LTTng-modules}
7261
7262
7263 [role="since-2.9"]
7264 [[lttng-tracepoint-enum]]
7265 ==== `LTTNG_TRACEPOINT_ENUM()` usage
7266
7267 Use the `LTTNG_TRACEPOINT_ENUM()` macro to define an enumeration:
7268
7269 [source,c]
7270 ----
7271 LTTNG_TRACEPOINT_ENUM(name, TP_ENUM_VALUES(entries))
7272 ----
7273
7274 Replace:
7275
7276 * `name` with the name of the enumeration (C identifier, unique
7277 amongst all the defined enumerations).
7278 * `entries` with a list of enumeration entries.
7279
7280 The available enumeration entry macros are:
7281
7282 +ctf_enum_value(__name__, __value__)+::
7283 Entry named +__name__+ mapped to the integral value +__value__+.
7284
7285 +ctf_enum_range(__name__, __begin__, __end__)+::
7286 Entry named +__name__+ mapped to the range of integral values between
7287 +__begin__+ (included) and +__end__+ (included).
7288
7289 +ctf_enum_auto(__name__)+::
7290 Entry named +__name__+ mapped to the integral value following the
7291 last mapping's value.
7292 +
7293 The last value of a `ctf_enum_value()` entry is its +__value__+
7294 parameter.
7295 +
7296 The last value of a `ctf_enum_range()` entry is its +__end__+ parameter.
7297 +
7298 If `ctf_enum_auto()` is the first entry in the list, its integral
7299 value is 0.
7300
7301 Use the `ctf_enum()` <<lttng-modules-tp-fields,field definition macro>>
7302 to use a defined enumeration as a tracepoint field.
7303
7304 .Define an enumeration with `LTTNG_TRACEPOINT_ENUM()`.
7305 ====
7306 [source,c]
7307 ----
7308 LTTNG_TRACEPOINT_ENUM(
7309 my_enum,
7310 TP_ENUM_VALUES(
7311 ctf_enum_auto("AUTO: EXPECT 0")
7312 ctf_enum_value("VALUE: 23", 23)
7313 ctf_enum_value("VALUE: 27", 27)
7314 ctf_enum_auto("AUTO: EXPECT 28")
7315 ctf_enum_range("RANGE: 101 TO 303", 101, 303)
7316 ctf_enum_auto("AUTO: EXPECT 304")
7317 )
7318 )
7319 ----
7320 ====
7321
7322
7323 [role="since-2.7"]
7324 [[lttng-modules-tp-fields]]
7325 ==== Tracepoint fields macros (for `TP_FIELDS()`)
7326
7327 [[tp-fast-assign]][[tp-struct-entry]]The available macros to define
7328 tracepoint fields, which must be listed within `TP_FIELDS()` in
7329 `LTTNG_TRACEPOINT_EVENT()`, are:
7330
7331 [role="func-desc growable",cols="asciidoc,asciidoc"]
7332 .Available macros to define LTTng-modules tracepoint fields
7333 |====
7334 |Macro |Description and parameters
7335
7336 |
7337 +ctf_integer(__t__, __n__, __e__)+
7338
7339 +ctf_integer_nowrite(__t__, __n__, __e__)+
7340
7341 +ctf_user_integer(__t__, __n__, __e__)+
7342
7343 +ctf_user_integer_nowrite(__t__, __n__, __e__)+
7344 |
7345 Standard integer, displayed in base 10.
7346
7347 +__t__+::
7348 Integer C type (`int`, `long`, `size_t`, ...).
7349
7350 +__n__+::
7351 Field name.
7352
7353 +__e__+::
7354 Argument expression.
7355
7356 |
7357 +ctf_integer_hex(__t__, __n__, __e__)+
7358
7359 +ctf_user_integer_hex(__t__, __n__, __e__)+
7360 |
7361 Standard integer, displayed in base 16.
7362
7363 +__t__+::
7364 Integer C type.
7365
7366 +__n__+::
7367 Field name.
7368
7369 +__e__+::
7370 Argument expression.
7371
7372 |+ctf_integer_oct(__t__, __n__, __e__)+
7373 |
7374 Standard integer, displayed in base 8.
7375
7376 +__t__+::
7377 Integer C type.
7378
7379 +__n__+::
7380 Field name.
7381
7382 +__e__+::
7383 Argument expression.
7384
7385 |
7386 +ctf_integer_network(__t__, __n__, __e__)+
7387
7388 +ctf_user_integer_network(__t__, __n__, __e__)+
7389 |
7390 Integer in network byte order (big-endian), displayed in base 10.
7391
7392 +__t__+::
7393 Integer C type.
7394
7395 +__n__+::
7396 Field name.
7397
7398 +__e__+::
7399 Argument expression.
7400
7401 |
7402 +ctf_integer_network_hex(__t__, __n__, __e__)+
7403
7404 +ctf_user_integer_network_hex(__t__, __n__, __e__)+
7405 |
7406 Integer in network byte order, displayed in base 16.
7407
7408 +__t__+::
7409 Integer C type.
7410
7411 +__n__+::
7412 Field name.
7413
7414 +__e__+::
7415 Argument expression.
7416
7417 |
7418 +ctf_enum(__N__, __t__, __n__, __e__)+
7419
7420 +ctf_enum_nowrite(__N__, __t__, __n__, __e__)+
7421
7422 +ctf_user_enum(__N__, __t__, __n__, __e__)+
7423
7424 +ctf_user_enum_nowrite(__N__, __t__, __n__, __e__)+
7425 |
7426 Enumeration.
7427
7428 +__N__+::
7429 Name of a <<lttng-tracepoint-enum,previously defined enumeration>>.
7430
7431 +__t__+::
7432 Integer C type (`int`, `long`, `size_t`, ...).
7433
7434 +__n__+::
7435 Field name.
7436
7437 +__e__+::
7438 Argument expression.
7439
7440 |
7441 +ctf_string(__n__, __e__)+
7442
7443 +ctf_string_nowrite(__n__, __e__)+
7444
7445 +ctf_user_string(__n__, __e__)+
7446
7447 +ctf_user_string_nowrite(__n__, __e__)+
7448 |
7449 Null-terminated string; undefined behavior if +__e__+ is `NULL`.
7450
7451 +__n__+::
7452 Field name.
7453
7454 +__e__+::
7455 Argument expression.
7456
7457 |
7458 +ctf_array(__t__, __n__, __e__, __s__)+
7459
7460 +ctf_array_nowrite(__t__, __n__, __e__, __s__)+
7461
7462 +ctf_user_array(__t__, __n__, __e__, __s__)+
7463
7464 +ctf_user_array_nowrite(__t__, __n__, __e__, __s__)+
7465 |
7466 Statically-sized array of integers.
7467
7468 +__t__+::
7469 Array element C type.
7470
7471 +__n__+::
7472 Field name.
7473
7474 +__e__+::
7475 Argument expression.
7476
7477 +__s__+::
7478 Number of elements.
7479
7480 |
7481 +ctf_array_bitfield(__t__, __n__, __e__, __s__)+
7482
7483 +ctf_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7484
7485 +ctf_user_array_bitfield(__t__, __n__, __e__, __s__)+
7486
7487 +ctf_user_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+
7488 |
7489 Statically-sized array of bits.
7490
7491 The type of +__e__+ must be an integer type. +__s__+ is the number
7492 of elements of such type in +__e__+, not the number of bits.
7493
7494 +__t__+::
7495 Array element C type.
7496
7497 +__n__+::
7498 Field name.
7499
7500 +__e__+::
7501 Argument expression.
7502
7503 +__s__+::
7504 Number of elements.
7505
7506 |
7507 +ctf_array_text(__t__, __n__, __e__, __s__)+
7508
7509 +ctf_array_text_nowrite(__t__, __n__, __e__, __s__)+
7510
7511 +ctf_user_array_text(__t__, __n__, __e__, __s__)+
7512
7513 +ctf_user_array_text_nowrite(__t__, __n__, __e__, __s__)+
7514 |
7515 Statically-sized array, printed as text.
7516
7517 The string does not need to be null-terminated.
7518
7519 +__t__+::
7520 Array element C type (always `char`).
7521
7522 +__n__+::
7523 Field name.
7524
7525 +__e__+::
7526 Argument expression.
7527
7528 +__s__+::
7529 Number of elements.
7530
7531 |
7532 +ctf_sequence(__t__, __n__, __e__, __T__, __E__)+
7533
7534 +ctf_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7535
7536 +ctf_user_sequence(__t__, __n__, __e__, __T__, __E__)+
7537
7538 +ctf_user_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
7539 |
7540 Dynamically-sized array of integers.
7541
7542 The type of +__E__+ must be unsigned.
7543
7544 +__t__+::
7545 Array element C type.
7546
7547 +__n__+::
7548 Field name.
7549
7550 +__e__+::
7551 Argument expression.
7552
7553 +__T__+::
7554 Length expression C type.
7555
7556 +__E__+::
7557 Length expression.
7558
7559 |
7560 +ctf_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7561
7562 +ctf_user_sequence_hex(__t__, __n__, __e__, __T__, __E__)+
7563 |
7564 Dynamically-sized array of integers, displayed in base 16.
7565
7566 The type of +__E__+ must be unsigned.
7567
7568 +__t__+::
7569 Array element C type.
7570
7571 +__n__+::
7572 Field name.
7573
7574 +__e__+::
7575 Argument expression.
7576
7577 +__T__+::
7578 Length expression C type.
7579
7580 +__E__+::
7581 Length expression.
7582
7583 |+ctf_sequence_network(__t__, __n__, __e__, __T__, __E__)+
7584 |
7585 Dynamically-sized array of integers in network byte order (big-endian),
7586 displayed in base 10.
7587
7588 The type of +__E__+ must be unsigned.
7589
7590 +__t__+::
7591 Array element C type.
7592
7593 +__n__+::
7594 Field name.
7595
7596 +__e__+::
7597 Argument expression.
7598
7599 +__T__+::
7600 Length expression C type.
7601
7602 +__E__+::
7603 Length expression.
7604
7605 |
7606 +ctf_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7607
7608 +ctf_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7609
7610 +ctf_user_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+
7611
7612 +ctf_user_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+
7613 |
7614 Dynamically-sized array of bits.
7615
7616 The type of +__e__+ must be an integer type. +__s__+ is the number
7617 of elements of such type in +__e__+, not the number of bits.
7618
7619 The type of +__E__+ must be unsigned.
7620
7621 +__t__+::
7622 Array element C type.
7623
7624 +__n__+::
7625 Field name.
7626
7627 +__e__+::
7628 Argument expression.
7629
7630 +__T__+::
7631 Length expression C type.
7632
7633 +__E__+::
7634 Length expression.
7635
7636 |
7637 +ctf_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7638
7639 +ctf_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7640
7641 +ctf_user_sequence_text(__t__, __n__, __e__, __T__, __E__)+
7642
7643 +ctf_user_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
7644 |
7645 Dynamically-sized array, displayed as text.
7646
7647 The string does not need to be null-terminated.
7648
7649 The type of +__E__+ must be unsigned.
7650
7651 The behaviour is undefined if +__e__+ is `NULL`.
7652
7653 +__t__+::
7654 Sequence element C type (always `char`).
7655
7656 +__n__+::
7657 Field name.
7658
7659 +__e__+::
7660 Argument expression.
7661
7662 +__T__+::
7663 Length expression C type.
7664
7665 +__E__+::
7666 Length expression.
7667 |====
7668
7669 Use the `_user` versions when the argument expression, `e`, is
7670 a user space address. In the cases of `ctf_user_integer*()` and
7671 `ctf_user_float*()`, `&e` must be a user space address, thus `e` must
7672 be addressable.
7673
7674 The `_nowrite` versions omit themselves from the session trace, but are
7675 otherwise identical. This means the `_nowrite` fields won't be written
7676 in the recorded trace. Their primary purpose is to make some
7677 of the event context available to the
7678 <<enabling-disabling-events,event filters>> without having to
7679 commit the data to sub-buffers.
7680
7681
7682 [[glossary]]
7683 == Glossary
7684
7685 Terms related to LTTng and to tracing in general:
7686
7687 Babeltrace::
7688 The http://diamon.org/babeltrace[Babeltrace] project, which includes
7689 the cmd:babeltrace command, some libraries, and Python bindings.
7690
7691 <<channel-buffering-schemes,buffering scheme>>::
7692 A layout of sub-buffers applied to a given channel.
7693
7694 <<channel,channel>>::
7695 An entity which is responsible for a set of ring buffers.
7696 +
7697 <<event,Event rules>> are always attached to a specific channel.
7698
7699 clock::
7700 A reference of time for a tracer.
7701
7702 <<lttng-consumerd,consumer daemon>>::
7703 A process which is responsible for consuming the full sub-buffers
7704 and write them to a file system or send them over the network.
7705
7706 <<channel-overwrite-mode-vs-discard-mode,discard mode>>:: The event loss
7707 mode in which the tracer _discards_ new event records when there's no
7708 sub-buffer space left to store them.
7709
7710 event::
7711 The consequence of the execution of an instrumentation
7712 point, like a tracepoint that you manually place in some source code,
7713 or a Linux kernel KProbe.
7714 +
7715 An event is said to _occur_ at a specific time. Different actions can
7716 be taken upon the occurrence of an event, like record the event's payload
7717 to a sub-buffer.
7718
7719 <<channel-overwrite-mode-vs-discard-mode,event loss mode>>::
7720 The mechanism by which event records of a given channel are lost
7721 (not recorded) when there is no sub-buffer space left to store them.
7722
7723 [[def-event-name]]event name::
7724 The name of an event, which is also the name of the event record.
7725 This is also called the _instrumentation point name_.
7726
7727 event record::
7728 A record, in a trace, of the payload of an event which occured.
7729
7730 <<event,event rule>>::
7731 Set of conditions which must be satisfied for one or more occuring
7732 events to be recorded.
7733
7734 `java.util.logging`::
7735 Java platform's
7736 https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[core logging facilities].
7737
7738 <<instrumenting,instrumentation>>::
7739 The use of LTTng probes to make a piece of software traceable.
7740
7741 instrumentation point::
7742 A point in the execution path of a piece of software that, when
7743 reached by this execution, can emit an event.
7744
7745 instrumentation point name::
7746 See _<<def-event-name,event name>>_.
7747
7748 log4j::
7749 A http://logging.apache.org/log4j/1.2/[logging library] for Java
7750 developed by the Apache Software Foundation.
7751
7752 log level::
7753 Level of severity of a log statement or user space
7754 instrumentation point.
7755
7756 LTTng::
7757 The _Linux Trace Toolkit: next generation_ project.
7758
7759 <<lttng-cli,cmd:lttng>>::
7760 A command-line tool provided by the LTTng-tools project which you
7761 can use to send and receive control messages to and from a
7762 session daemon.
7763
7764 LTTng analyses::
7765 The https://github.com/lttng/lttng-analyses[LTTng analyses] project,
7766 which is a set of analyzing programs that are used to obtain a
7767 higher level view of an LTTng trace.
7768
7769 cmd:lttng-consumerd::
7770 The name of the consumer daemon program.
7771
7772 cmd:lttng-crash::
7773 A utility provided by the LTTng-tools project which can convert
7774 ring buffer files (usually
7775 <<persistent-memory-file-systems,saved on a persistent memory file system>>)
7776 to trace files.
7777
7778 LTTng Documentation::
7779 This document.
7780
7781 <<lttng-live,LTTng live>>::
7782 A communication protocol between the relay daemon and live viewers
7783 which makes it possible to see events "live", as they are received by
7784 the relay daemon.
7785
7786 <<lttng-modules,LTTng-modules>>::
7787 The https://github.com/lttng/lttng-modules[LTTng-modules] project,
7788 which contains the Linux kernel modules to make the Linux kernel
7789 instrumentation points available for LTTng tracing.
7790
7791 cmd:lttng-relayd::
7792 The name of the relay daemon program.
7793
7794 cmd:lttng-sessiond::
7795 The name of the session daemon program.
7796
7797 LTTng-tools::
7798 The https://github.com/lttng/lttng-tools[LTTng-tools] project, which
7799 contains the various programs and libraries used to
7800 <<controlling-tracing,control tracing>>.
7801
7802 <<lttng-ust,LTTng-UST>>::
7803 The https://github.com/lttng/lttng-ust[LTTng-UST] project, which
7804 contains libraries to instrument user applications.
7805
7806 <<lttng-ust-agents,LTTng-UST Java agent>>::
7807 A Java package provided by the LTTng-UST project to allow the
7808 LTTng instrumentation of `java.util.logging` and Apache log4j 1.2
7809 logging statements.
7810
7811 <<lttng-ust-agents,LTTng-UST Python agent>>::
7812 A Python package provided by the LTTng-UST project to allow the
7813 LTTng instrumentation of Python logging statements.
7814
7815 <<channel-overwrite-mode-vs-discard-mode,overwrite mode>>::
7816 The event loss mode in which new event records overwrite older
7817 event records when there's no sub-buffer space left to store them.
7818
7819 <<channel-buffering-schemes,per-process buffering>>::
7820 A buffering scheme in which each instrumented process has its own
7821 sub-buffers for a given user space channel.
7822
7823 <<channel-buffering-schemes,per-user buffering>>::
7824 A buffering scheme in which all the processes of a Unix user share the
7825 same sub-buffer for a given user space channel.
7826
7827 <<lttng-relayd,relay daemon>>::
7828 A process which is responsible for receiving the trace data sent by
7829 a distant consumer daemon.
7830
7831 ring buffer::
7832 A set of sub-buffers.
7833
7834 <<lttng-sessiond,session daemon>>::
7835 A process which receives control commands from you and orchestrates
7836 the tracers and various LTTng daemons.
7837
7838 <<taking-a-snapshot,snapshot>>::
7839 A copy of the current data of all the sub-buffers of a given tracing
7840 session, saved as trace files.
7841
7842 sub-buffer::
7843 One part of an LTTng ring buffer which contains event records.
7844
7845 timestamp::
7846 The time information attached to an event when it is emitted.
7847
7848 trace (_noun_)::
7849 A set of files which are the concatenations of one or more
7850 flushed sub-buffers.
7851
7852 trace (_verb_)::
7853 The action of recording the events emitted by an application
7854 or by a system, or to initiate such recording by controlling
7855 a tracer.
7856
7857 Trace Compass::
7858 The http://tracecompass.org[Trace Compass] project and application.
7859
7860 tracepoint::
7861 An instrumentation point using the tracepoint mechanism of the Linux
7862 kernel or of LTTng-UST.
7863
7864 tracepoint definition::
7865 The definition of a single tracepoint.
7866
7867 tracepoint name::
7868 The name of a tracepoint.
7869
7870 tracepoint provider::
7871 A set of functions providing tracepoints to an instrumented user
7872 application.
7873 +
7874 Not to be confused with a _tracepoint provider package_: many tracepoint
7875 providers can exist within a tracepoint provider package.
7876
7877 tracepoint provider package::
7878 One or more tracepoint providers compiled as an object file or as
7879 a shared library.
7880
7881 tracer::
7882 A software which records emitted events.
7883
7884 <<domain,tracing domain>>::
7885 A namespace for event sources.
7886
7887 <<tracing-group,tracing group>>::
7888 The Unix group in which a Unix user can be to be allowed to trace the
7889 Linux kernel.
7890
7891 <<tracing-session,tracing session>>::
7892 A stateful dialogue between you and a <<lttng-sessiond,session
7893 daemon>>.
7894
7895 user application::
7896 An application running in user space, as opposed to a Linux kernel
7897 module, for example.
This page took 0.195969 seconds and 4 git commands to generate.