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