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