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