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