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