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