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