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