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