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