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