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