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