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