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