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