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