2.5, 2.6: installation steps are outdated
[lttng-docs.git] / 2.5 / lttng-docs-2.5.txt
CommitLineData
f0287ae1
PP
1The LTTng Documentation
2=======================
3Philippe Proulx <pproulx@efficios.com>
4v2.5, 21 October 2016
5
6
7include::../common/copyright.txt[]
8
9
10include::../common/warning-not-maintained.txt[]
11
12
13include::../common/welcome.txt[]
14
15
16include::../common/audience.txt[]
17
18
19[[chapters]]
20=== Chapter descriptions
21
22What follows is a list of brief descriptions of this documentation's
23chapters. The latter are ordered in such a way as to make the reading
24as linear as possible.
25
26. <<nuts-and-bolts,Nuts and bolts>> explains the
27 rudiments of software tracing and the rationale behind the
28 LTTng project.
29. <<installing-lttng,Installing LTTng>> is divided into
30 sections describing the steps needed to get a working installation
31 of LTTng packages for common Linux distributions and from its
32 source.
33. <<getting-started,Getting started>> is a very concise guide to
34 get started quickly with LTTng kernel and user space tracing. This
35 chapter is recommended if you're new to LTTng or software tracing
36 in general.
37. <<understanding-lttng,Understanding LTTng>> deals with some
38 core concepts and components of the LTTng suite. Understanding
39 those is important since the next chapter assumes you're familiar
40 with them.
41. <<using-lttng,Using LTTng>> is a complete user guide of the
42 LTTng project. It shows in great details how to instrument user
43 applications and the Linux kernel, how to control tracing sessions
44 using the `lttng` command line tool and miscellaneous practical use
45 cases.
46. <<reference,Reference>> contains references of LTTng components,
47 like links to online manpages and various APIs.
48
49We recommend that you read the above chapters in this order, although
50some of them may be skipped depending on your situation. You may skip
51<<nuts-and-bolts,Nuts and bolts>> if you're familiar with tracing
52and LTTng. Also, you may jump over <<installing-lttng,Installing LTTng>>
53if LTTng is already properly installed on your target system.
54
55
56include::../common/convention.txt[]
57
58
59include::../common/acknowledgements.txt[]
60
61
62[[whats-new]]
63== What's new in LTTng {revision}?
64
65The **LTTng {revision}** toolchain introduces many interesting features,
66some of them which have been requested by users many times.
67
68It is now possible to
69<<saving-loading-tracing-session,save and restore tracing sessions>>.
70Sessions are saved to and loaded from XML files located by default in a
71subdirectory of the user's home directory. LTTng daemons are also
72configurable by configuration files as of LTTng-tools {revision}. This version
73also makes it possible to load user-defined kernel probes with the new
74session daemon's `--kmod-probes` option (or using the
75`LTTNG_KMOD_PROBES` environment variable).
76
77<<tracef,`tracef()`>> is a new instrumentation facility in LTTng-UST {revision}
78which makes it possible to insert `printf()`-like tracepoints in C/$$C++$$
79code for quick debugging. LTTng-UST {revision} also adds support for perf PMU
80counters in user space on the x86 architecture
81(see <<adding-context,Adding some context to channels>>).
82
83As of LTTng-modules {revision}, a new
84<<proc-lttng-logger-abi,LTTng logger ABI>>
85is made available, making tracing Bash scripts, for example, much more
86easier (just `echo` whatever you need to record to path:{/proc/lttng-logger}
87while tracing is active). On the kernel side, some tracepoints are
88added: state dumps of block devices, file descriptors, and file modes,
89as well as http://en.wikipedia.org/wiki/Video4Linux[V4L2] events. Linux
903.15 is now officially supported, and system call tracing is now
91possible on the MIPS32 architecture.
92
93To learn more about the new features of LTTng {revision}, see
94http://lttng.org/blog/2014/08/04/lttng-toolchain-2-5-0-is-out/[this
95release announcement].
96
97
98[[nuts-and-bolts]]
99== Nuts and bolts
100
101What is LTTng? As its name suggests, the _Linux Trace Toolkit: next
102generation_ is a modern toolkit for tracing Linux systems and
103applications. So your first question might rather be: **what is
104tracing?**
105
106As the history of software engineering progressed and led to what
107we now take for granted--complex, numerous and
108interdependent software applications running in parallel on
109sophisticated operating systems like Linux--the authors of such
110components, or software developers, began feeling a natural
111urge of having tools to ensure the robustness and good performance
112of their masterpieces.
113
114One major achievement in this field is, inarguably, the
115https://www.gnu.org/software/gdb/[GNU debugger (GDB)], which is an
116essential tool for developers to find and fix bugs. But even the best
117debugger won't help make your software run faster, and nowadays, faster
118software means either more work done by the same hardware, or cheaper
119hardware for the same work.
120
121A _profiler_ is often the tool of choice to identify performance
122bottlenecks. Profiling is suitable to identify _where_ performance is
123lost in a given software; the profiler outputs a profile, a statistical
124summary of observed events, which you may use to know which functions
125took the most time to execute. However, a profiler won't report _why_
126some identified functions are the bottleneck. Also, bottlenecks might
127only occur when specific conditions are met. For a thorough
128investigation of software performance issues, a history of execution,
129with historical values of chosen variables, is essential. This is where
130tracing comes in handy.
131
132_Tracing_ is a technique used to understand what goes on in a running
133software system. The software used for tracing is called a _tracer_,
134which is conceptually similar to a tape recorder. When recording,
135specific points placed in the software source code generate events that
136are saved on a giant tape: a _trace_ file. Both user applications and
137the operating system may be traced at the same time, opening the
138possibility of resolving a wide range of problems that are otherwise
139extremely challenging.
140
141Tracing is often compared to _logging_. However, tracers and loggers are
142two different types of tools, serving two different purposes. Tracers
143are designed to record much lower-level events that occur much more
144frequently than log messages, often in the thousands per second range,
145with very little execution overhead. Logging is more appropriate for
146very high-level analysis of less frequent events: user accesses,
147exceptional conditions (e.g., errors, warnings), database transactions,
148instant messaging communications, etc. More formally, logging is one of
149several use cases that can be accomplished with tracing.
150
151The list of recorded events inside a trace file may be read manually
152like a log file for the maximum level of detail, but it is generally
153much more interesting to perform application-specific analyses to
154produce reduced statistics and graphs that are useful to resolve a given
155problem. Trace viewers and analysers are specialized tools which achieve
156this.
157
158So, in the end, this is what LTTng is: a powerful, open source set of
159tools to trace the Linux kernel and user applications. LTTng is composed
160of several components actively maintained and developed by its
161http://lttng.org/community/#where[community].
162
163Excluding proprietary solutions, a few competing software tracers exist
164for Linux.
165https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace] is the
166de facto function tracer of the Linux kernel.
167http://linux.die.net/man/1/strace[strace] is able to record all system
168calls made by a user process.
169https://sourceware.org/systemtap/[SystemTap] is a Linux kernel and user
170space tracer which uses custom user scripts to produce plain text
171traces. http://www.sysdig.org/[sysdig] also uses scripts, written in
172Lua, to trace and analyze the Linux kernel.
173
174The main distinctive features of LTTng is that it produces correlated
175kernel and user space traces, as well as doing so with the lowest
176overhead amongst other solutions. It produces trace files in the
177http://www.efficios.com/ctf[CTF] format, an optimized file format for
178production and analyses of multi-gigabyte data. LTTng is the result of
179close to 10 years of active development by a community of passionate
180developers. It is currently available on some major desktop, server, and
181embedded Linux distributions.
182
183The main interface for tracing control is a single command line tool
184named `lttng`. The latter can create several tracing sessions,
185enable/disable events on the fly, filter them efficiently with custom
186user expressions, start/stop tracing and do much more. Traces can be
187recorded on disk or sent over the network, kept totally or partially,
188and viewed once tracing is inactive or in real-time.
189
190<<installing-lttng,Install LTTng now>> and start tracing!
191
192
193[[installing-lttng]]
194== Installing LTTng
195
47748f83
PP
196include::../common/warning-installation-outdated.txt[]
197
f0287ae1
PP
198**LTTng** is a set of software components which interact to allow
199instrumenting the Linux kernel and user applications and controlling
200tracing sessions (starting/stopping tracing, enabling/disabling events,
201etc.). Those components are bundled into the following packages:
202
203LTTng-tools::
204 Libraries and command line interface to control tracing sessions.
205
206LTTng-modules::
207 Linux kernel modules allowing Linux to be traced using LTTng.
208
209LTTng-UST::
210 User space tracing library.
211
212Most distributions mark the LTTng-modules and LTTng-UST packages as
213optional. In the following sections, we always provide the steps to
214install all three, but be aware that LTTng-modules is only required if
215you intend to trace the Linux kernel and LTTng-UST is only required if
216you intend to trace user space applications.
217
218This chapter shows how to install the above packages on a Linux system.
219The easiest way is to use the package manager of the system's
220distribution (<<desktop-distributions,desktop>> or
221<<embedded-distributions,embedded>>). Support is also available for
222<<enterprise-distributions,enterprise distributions>>, such as Red Hat
223Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SLES).
224Otherwise, you can
225<<building-from-source,build the LTTng packages from source>>.
226
227
228[[desktop-distributions]]
229=== Desktop distributions
230
231Official LTTng {revision} packages are available for <<ubuntu,Ubuntu>> and
232<<debian,Debian>>.
233
234More recent versions of LTTng are available for Fedora, openSUSE,
235as well as Arch Linux.
236
237Should any issue arise when following the procedures below, please
238inform the http://lttng.org/community[community] about it.
239
240
241[[ubuntu]]
242==== Ubuntu
243
244LTTng {revision} is packaged in Ubuntu 15.04 _Vivid Vervet_. For other
245releases of Ubuntu, you need to build and install LTTng
246<<building-from-source,from source>>. Ubuntu 15.10 _Wily Werewolf_
247ships with link:/docs/v2.6/[LTTng 2.6].
248
249To install LTTng {revision} from the official Ubuntu repositories,
250simply use `apt-get`:
251
252[role="term"]
253----
254sudo apt-get install lttng-tools
255sudo apt-get install lttng-modules-dkms
256sudo apt-get install liblttng-ust-dev
257----
258
259
260[[debian]]
261==== Debian
262
263Debian "jessie" has official packages of LTTng {revision}:
264
265[role="term"]
266----
267sudo apt-get install lttng-tools
268sudo apt-get install lttng-modules-dkms
269sudo apt-get install liblttng-ust-dev
270----
271
272
273[[embedded-distributions]]
274=== Embedded distributions
275
276Some developers may be interested in tracing the Linux kernel and user space
277applications running on embedded systems. LTTng is packaged by two popular
278embedded Linux distributions: <<buildroot,Buildroot>> and
279<<oe-yocto,OpenEmbedded/Yocto>>.
280
281
282[[buildroot]]
283==== Buildroot
284
285LTTng {revision} packages in Buildroot 2014.11 and 2015.02 are named
286`lttng-tools`, `lttng-modules`, and `lttng-libust`.
287
288To enable them, start the Buildroot configuration menu as usual:
289
290[role="term"]
291----
292make menuconfig
293----
294
295In:
296
297* _Kernel_: make sure _Linux kernel_ is enabled
298* _Toolchain_: make sure the following options are enabled:
299** _Enable large file (files > 2GB) support_
300** _Enable WCHAR support_
301
302In _Target packages_/_Debugging, profiling and benchmark_, enable
303_lttng-modules_ and _lttng-tools_. In
304_Target packages_/_Libraries_/_Other_, enable _lttng-libust_.
305
306
307[[oe-yocto]]
308==== OpenEmbedded/Yocto
309
310LTTng {revision} recipes are available in the `openembedded-core` layer of
311OpenEmbedded from August 15th, 2014 to February 8th, 2015 under the
312following names:
313
314* `lttng-tools`
315* `lttng-modules`
316* `lttng-ust`
317
318Using BitBake, the simplest way to include LTTng recipes in your
319target image is to add them to `IMAGE_INSTALL_append` in
320path:{conf/local.conf}:
321
322----
323IMAGE_INSTALL_append = " lttng-tools lttng-modules lttng-ust"
324----
325
326If you're using Hob, click _Edit image recipe_ once you have selected
327a machine and an image recipe. Then, in the _All recipes_ tab, search
328for `lttng` and you should find and be able to include the three LTTng
329recipes.
330
331
332[[enterprise-distributions]]
333=== Enterprise distributions (RHEL, SLES)
334
335To install LTTng on enterprise Linux distributions
336(such as RHEL and SLES), please see
337http://packages.efficios.com/[EfficiOS Enterprise Packages].
338
339
340[[building-from-source]]
341=== Building from source
342
343As <<installing-lttng,previously stated>>, LTTng is shipped as three
344packages: LTTng-tools, LTTng-modules and LTTng-UST. LTTng-tools contains
345everything needed to control tracing sessions, while LTTng-modules is
346only needed for Linux kernel tracing and LTTng-UST is only needed for
347user space tracing.
348
349The tarballs are available in the
350http://lttng.org/download#build-from-source[Download section]
351of the LTTng website.
352
353Please refer to the path:{README.md} files provided by each package to
354properly build and install them.
355
356TIP: The aforementioned path:{README.md} files are rendered as
357rich text when https://github.com/lttng[viewed on GitHub].
358
359
360[[getting-started]]
361== Getting started with LTTng
362
363This is a small guide to get started quickly with LTTng kernel and user
364space tracing. For intermediate to advanced use cases and a more
365thorough understanding of LTTng, see <<using-lttng,Using LTTng>> and
366<<understanding-lttng,Understanding LTTng>>.
367
368Before reading this guide, make sure LTTng
369<<installing-lttng,is installed>>. You will at least need LTTng-tools.
370Also install LTTng-modules for
371<<tracing-the-linux-kernel,tracing the Linux kernel>>
372and LTTng-UST for <<tracing-your-own-user-application,tracing your own
373user space applications>>. When your traces are finally written and
374complete, the
375<<viewing-and-analyzing-your-traces,Viewing and analyzing your traces>>
376section of this chapter will help you analyze your tracepoint
377events to investigate.
378
379
380[[tracing-the-linux-kernel]]
381=== Tracing the Linux kernel
382
383Make sure LTTng-tools and LTTng-modules packages
384<<installing-lttng,are installed>>.
385
386Since you're about to trace the Linux kernel itself, let's look at the
387available kernel events using the `lttng` tool, which has a
388Git-like command line structure:
389
390[role="term"]
391----
392lttng list --kernel
393----
394
395Before tracing, you need to create a session:
396
397[role="term"]
398----
399sudo lttng create my-session
400----
401
402TIP: You can avoid using `sudo` in the previous and following commands
403if your user is a member of the <<lttng-sessiond,tracing group>>.
404
405`my-session` is the tracing session name and could be anything you
406like. `auto` will be used if omitted.
407
408Let's now enable some events for this session:
409
410[role="term"]
411----
412sudo lttng enable-event --kernel sched_switch,sched_process_fork
413----
414
415or you might want to simply enable all available kernel events (beware
416that trace files will grow rapidly when doing this):
417
418[role="term"]
419----
420sudo lttng enable-event --kernel --all
421----
422
423Start tracing:
424
425[role="term"]
426----
427sudo lttng start
428----
429
430By default, traces are saved in
431+\~/lttng-traces/__name__-__date__-__time__+,
432where +__name__+ is the session name.
433
434When you're done tracing:
435
436[role="term"]
437----
438sudo lttng stop
439sudo lttng destroy
440----
441
442Although `destroy` looks scary here, it doesn't actually destroy the
443outputted trace files: it only destroys the tracing session.
444
445What's next? Have a look at
446<<viewing-and-analyzing-your-traces,Viewing and analyzing your traces>>
447to view and analyze the trace you just recorded.
448
449
450[[tracing-your-own-user-application]]
451=== Tracing your own user application
452
453The previous section helped you create a trace out of Linux kernel
454events. This section steps you through a simple example showing you how
455to trace a _Hello world_ program written in C.
456
457Make sure LTTng-tools and LTTng-UST packages
458<<installing-lttng,are installed>>.
459
460Tracing is just like having `printf()` calls at specific locations of
461your source code, albeit LTTng is much faster and more flexible than
462`printf()`. In the LTTng realm, **`tracepoint()`** is analogous to
463`printf()`.
464
465Unlike `printf()`, though, `tracepoint()` does not use a format string to
466know the types of its arguments: the formats of all tracepoints must be
467defined before using them. So before even writing our _Hello world_ program,
468we need to define the format of our tracepoint. This is done by writing a
469**template file**, with a name usually ending
470with the `.tp` extension (for **t**race**p**oint),
471which the `lttng-gen-tp` tool (shipped with LTTng-UST) will use to generate
472an object file (along with a `.c` file) and a header to be
473included in our application source code.
474
475Here's the whole flow:
476
477[role="img-80"]
478.Build workflow for LTTng application tracing.
479image::lttng-lttng-gen-tp.png[]
480
481The template file format is a list of tracepoint definitions
482and other optional definition entries which we will skip for
483this quickstart. Each tracepoint is defined using the
484`TRACEPOINT_EVENT()` macro. For each tracepoint, you must provide:
485
486* a **provider name**, which is the "scope" of this tracepoint (this usually
487 includes the company and project names)
488* a **tracepoint name**
489* a **list of arguments** for the eventual `tracepoint()` call,
490 each item being:
491** the argument C type
492** the argument name
493* a **list of fields**, which will be the actual fields of the recorded events
494 for this tracepoint
495
496Here's a simple tracepoint definition example with two arguments: an integer
497and a string:
498
499[source,c]
500----
501TRACEPOINT_EVENT(
502 hello_world,
503 my_first_tracepoint,
504 TP_ARGS(
505 int, my_integer_arg,
506 char*, my_string_arg
507 ),
508 TP_FIELDS(
509 ctf_string(my_string_field, my_string_arg)
510 ctf_integer(int, my_integer_field, my_integer_arg)
511 )
512)
513----
514
515The exact syntax is well explained in the
516<<c-application,C application>> instrumenting guide of the
517<<using-lttng,Using LTTng>> chapter, as well as in man:lttng-ust(3).
518
519Save the above snippet as path:{hello-tp.tp} and run:
520
521[role="term"]
522----
523lttng-gen-tp hello-tp.tp
524----
525
526The following files will be created next to path:{hello-tp.tp}:
527
528* path:{hello-tp.c}
529* path:{hello-tp.o}
530* path:{hello-tp.h}
531
532path:{hello-tp.o} is the compiled object file of path:{hello-tp.c}.
533
534Now, by including path:{hello-tp.h} in your own application, you may use the
535tracepoint defined above by properly refering to it when calling
536`tracepoint()`:
537
538[source,c]
539----
540#include <stdio.h>
541#include "hello-tp.h"
542
543int main(int argc, char* argv[])
544{
545 int x;
546
547 puts("Hello, World!\nPress Enter to continue...");
548
549 /* The following getchar() call is only placed here for the purpose
550 * of this demonstration, for pausing the application in order for
551 * you to have time to list its events. It's not needed otherwise.
552 */
553 getchar();
554
555 /* A tracepoint() call. Arguments, as defined in hello-tp.tp:
556 *
557 * 1st: provider name (always)
558 * 2nd: tracepoint name (always)
559 * 3rd: my_integer_arg (first user-defined argument)
560 * 4th: my_string_arg (second user-defined argument)
561 *
562 * Notice the provider and tracepoint names are NOT strings;
563 * they are in fact parts of variables created by macros in
564 * hello-tp.h.
565 */
566 tracepoint(hello_world, my_first_tracepoint, 23, "hi there!");
567
568 for (x = 0; x < argc; ++x) {
569 tracepoint(hello_world, my_first_tracepoint, x, argv[x]);
570 }
571
572 puts("Quitting now!");
573
574 tracepoint(hello_world, my_first_tracepoint, x * x, "x^2");
575
576 return 0;
577}
578----
579
580Save this as path:{hello.c}, next to path:{hello-tp.tp}.
581
582Notice path:{hello-tp.h}, the header file generated by path:{lttng-gen-tp} from
583our template file path:{hello-tp.tp}, is included by path:{hello.c}.
584
585You are now ready to compile the application with LTTng-UST support:
586
587[role="term"]
588----
589gcc -o hello hello.c hello-tp.o -llttng-ust -ldl
590----
591
592If you followed the
593<<tracing-the-linux-kernel,Tracing the Linux kernel>> section, the
594following steps will look familiar.
595
596First, run the application with a few arguments:
597
598[role="term"]
599----
600./hello world and beyond
601----
602
603You should see
604
605----
606Hello, World!
607Press Enter to continue...
608----
609
610Use the `lttng` tool to list all available user space events:
611
612[role="term"]
613----
614lttng list --userspace
615----
616
617You should see the `hello_world:my_first_tracepoint` tracepoint listed
618under the `./hello` process.
619
620Create a tracing session:
621
622[role="term"]
623----
624lttng create my-userspace-session
625----
626
627Enable the `hello_world:my_first_tracepoint` tracepoint:
628
629[role="term"]
630----
631lttng enable-event --userspace hello_world:my_first_tracepoint
632----
633
634Start tracing:
635
636[role="term"]
637----
638lttng start
639----
640
641Go back to the running path:{hello} application and press Enter. All
642`tracepoint()` calls will be executed and the program will finally exit.
643
644Stop tracing:
645
646[role="term"]
647----
648lttng stop
649----
650
651Done! You may use `lttng view` to list the recorded events. This command
652starts
653http://www.efficios.com/babeltrace[`babeltrace`]
654in the background, if it is installed:
655
656[role="term"]
657----
658lttng view
659----
660
661should output something like:
662
663----
664[18:10:27.684304496] (+?.?????????) hostname hello_world:my_first_tracepoint: { cpu_id = 0 }, { my_string_field = "hi there!", my_integer_field = 23 }
665[18:10:27.684338440] (+0.000033944) hostname hello_world:my_first_tracepoint: { cpu_id = 0 }, { my_string_field = "./hello", my_integer_field = 0 }
666[18:10:27.684340692] (+0.000002252) hostname hello_world:my_first_tracepoint: { cpu_id = 0 }, { my_string_field = "world", my_integer_field = 1 }
667[18:10:27.684342616] (+0.000001924) hostname hello_world:my_first_tracepoint: { cpu_id = 0 }, { my_string_field = "and", my_integer_field = 2 }
668[18:10:27.684343518] (+0.000000902) hostname hello_world:my_first_tracepoint: { cpu_id = 0 }, { my_string_field = "beyond", my_integer_field = 3 }
669[18:10:27.684357978] (+0.000014460) hostname hello_world:my_first_tracepoint: { cpu_id = 0 }, { my_string_field = "x^2", my_integer_field = 16 }
670----
671
672When you're done, you may destroy the tracing session, which does _not_
673destroy the generated trace files, leaving them available for further
674analysis:
675
676[role="term"]
677----
678lttng destroy my-userspace-session
679----
680
681The next section presents other alternatives to view and analyze your
682LTTng traces.
683
684
685[[viewing-and-analyzing-your-traces]]
686=== Viewing and analyzing your traces
687
688This section describes how to visualize the data gathered after tracing
689the Linux kernel or a user space application.
690
691Many ways exist to read your LTTng traces:
692
693* **`babeltrace`** is a command line utility which converts trace formats;
694 it supports the format used by LTTng,
695 CTF, as well as a basic
696 text output which may be ++grep++ed. The `babeltrace` command is
697 part of the http://www.efficios.com/babeltrace[Babeltrace] project.
698* Babeltrace also includes a **Python binding** so that you may
699 easily open and read an LTTng trace with your own script, benefiting
700 from the power of Python.
701* **http://projects.eclipse.org/projects/tools.tracecompass[Trace Compass]**
702 is an Eclipse plugin used to visualize and analyze various types of
703 traces, including LTTng's. It also comes as a standalone application
704 and can be downloaded from
705 http://projects.eclipse.org/projects/tools.tracecompass/downloads[here].
706
707LTTng trace files are usually recorded in the path:{~/lttng-traces} directory.
708Let's now view the trace and perform a basic analysis using
709`babeltrace`.
710
711The simplest way to list all the recorded events of a trace is to pass its
712path to `babeltrace` with no options:
713
714[role="term"]
715----
716babeltrace ~/lttng-traces/my-session
717----
718
719`babeltrace` will find all traces within the given path recursively and
720output all their events, merging them intelligently.
721
722Listing all the system calls of a Linux kernel trace with their arguments is
723easy with `babeltrace` and `grep`:
724
725[role="term"]
726----
727babeltrace ~/lttng-traces/my-kernel-session | grep sys_
728----
729
730Counting events is also straightforward:
731
732[role="term"]
733----
734babeltrace ~/lttng-traces/my-kernel-session | grep sys_read | wc --lines
735----
736
737The text output of `babeltrace` is useful for isolating events by simple
738matching using `grep` and similar utilities. However, more elaborate filters
739such as keeping only events with a field value falling within a specific range
740are not trivial to write using a shell. Moreover, reductions and even the
741most basic computations involving multiple events are virtually impossible
742to implement.
743
744Fortunately, Babeltrace ships with a Python 3 binding which makes it
745really easy to read the events of an LTTng trace sequentially and compute
746the desired information.
747
748Here's a simple example using the Babeltrace Python binding. The following
749script accepts an LTTng Linux kernel trace path as its first argument and
750outputs the short names of the top 5 running processes on CPU 0 during the
751whole trace:
752
753[source,python]
754----
755import sys
756from collections import Counter
757import babeltrace
758
759
760def top5proc():
761 if len(sys.argv) != 2:
762 msg = 'Usage: python {} TRACEPATH'.format(sys.argv[0])
763 raise ValueError(msg)
764
765 # a trace collection holds one to many traces
766 col = babeltrace.TraceCollection()
767
768 # add the trace provided by the user
769 # (LTTng traces always have the 'ctf' format)
770 if col.add_trace(sys.argv[1], 'ctf') is None:
771 raise RuntimeError('Cannot add trace')
772
773 # this counter dict will hold execution times:
774 #
775 # task command name -> total execution time (ns)
776 exec_times = Counter()
777
778 # this holds the last `sched_switch` timestamp
779 last_ts = None
780
781 # iterate events
782 for event in col.events:
783 # keep only `sched_switch` events
784 if event.name != 'sched_switch':
785 continue
786
787 # keep only events which happened on CPU 0
788 if event['cpu_id'] != 0:
789 continue
790
791 # event timestamp
792 cur_ts = event.timestamp
793
794 if last_ts is None:
795 # we start here
796 last_ts = cur_ts
797
798 # previous task command (short) name
799 prev_comm = event['prev_comm']
800
801 # initialize entry in our dict if not yet done
802 if prev_comm not in exec_times:
803 exec_times[prev_comm] = 0
804
805 # compute previous command execution time
806 diff = cur_ts - last_ts
807
808 # update execution time of this command
809 exec_times[prev_comm] += diff
810
811 # update last timestamp
812 last_ts = cur_ts
813
814 # display top 10
815 for name, ns in exec_times.most_common(5):
816 s = ns / 1000000000
817 print('{:20}{} s'.format(name, s))
818
819
820if __name__ == '__main__':
821 top5proc()
822----
823
824Save this script as path:{top5proc.py} and run it with Python 3, providing the
825path to an LTTng Linux kernel trace as the first argument:
826
827[role="term"]
828----
829python3 top5proc.py ~/lttng-sessions/my-session-.../kernel
830----
831
832Make sure the path you provide is the directory containing actual trace
833files (path:{channel0_0}, path:{metadata}, etc.): the `babeltrace` utility
834recurses directories, but the Python binding does not.
835
836Here's an example of output:
837
838----
839swapper/0 48.607245889 s
840chromium 7.192738188 s
841pavucontrol 0.709894415 s
842Compositor 0.660867933 s
843Xorg.bin 0.616753786 s
844----
845
846Note that `swapper/0` is the "idle" process of CPU 0 on Linux; since we
847weren't using the CPU that much when tracing, its first position in the list
848makes sense.
849
850
851[[understanding-lttng]]
852== Understanding LTTng
853
854If you're going to use LTTng in any serious way, it is fundamental that
855you become familiar with its core concepts. Technical terms like
856_tracing sessions_, _domains_, _channels_ and _events_ are used over
857and over in the <<using-lttng,Using LTTng>> chapter,
858and it is assumed that you understand what they mean when reading it.
859
860LTTng, as you already know, is a _toolkit_. It would be wrong
861to call it a simple _tool_ since it is composed of multiple interacting
862components. This chapter also describes the latter, providing details
863about their respective roles and how they connect together to form
864the current LTTng ecosystem.
865
866
867[[core-concepts]]
868=== Core concepts
869
870This section explains the various elementary concepts a user has to deal
871with when using LTTng. They are:
872
873* <<tracing-session,tracing session>>
874* <<domain,domain>>
875* <<channel,channel>>
876* <<event,event>>
877
878
879[[tracing-session]]
880==== Tracing session
881
882A _tracing session_ is--like any session--a container of
883state. Anything that is done when tracing using LTTng happens in the
884scope of a tracing session. In this regard, it is analogous to a bank
885website's session: you can't interact online with your bank account
886unless you are logged in a session, except for reading a few static
887webpages (LTTng, too, can report some static information that does not
888need a created tracing session).
889
890A tracing session holds the following attributes and objects (some of
891which are described in the following sections):
892
893* a name
894* the tracing state (tracing started or stopped)
895* the trace data output path/URL (local path or sent over the network)
896* a mode (normal, snapshot or live)
897* the snapshot output paths/URLs (if applicable)
898* for each <<domain,domain>>, a list of <<channel,channels>>
899* for each channel:
900** a name
901** the channel state (enabled or disabled)
902** its parameters (event loss mode, sub-buffers size and count,
903 timer periods, output type, trace files size and count, etc.)
904** a list of added context information
905** a list of <<event,events>>
906* for each event:
907** its state (enabled or disabled)
908** a list of instrumentation points (tracepoints, system calls,
909 dynamic probes, etc.)
910** associated log levels
911** a filter expression
912
913All this information is completely isolated between tracing sessions.
914
915Conceptually, a tracing session is a per-user object; the
916<<plumbing,Plumbing>> section shows how this is actually
917implemented. Any user may create as many concurrent tracing sessions
918as desired. As you can see in the list above, even the tracing state
919is a per-tracing session attribute, so that you may trace your target
920system/application in a given tracing session with a specific
921configuration while another one stays inactive.
922
923The trace data generated in a tracing session may be either saved
924to disk, sent over the network or not saved at all (in which case
925snapshots may still be saved to disk or sent to a remote machine).
926
927
928[[domain]]
929==== Domain
930
931A tracing _domain_ is the official term the LTTng project uses to
932designate a tracer category.
933
934There are currently three known domains:
935
936* Linux kernel
937* user space
938* `java.util.logging` (JUL)
939
940Different tracers expose common features in their own interfaces, but,
941from a user's perspective, you still need to target a specific type of
942tracer to perform some actions. For example, since both kernel and user
943space tracers support named tracepoints (probes manually inserted in
944source code), you need to specify which one is concerned when enabling
945an event because both domains could have existing events with the same
946name.
947
948Some features are not available in all domains. Filtering enabled
949events using custom expressions, for example, is currently not
950supported in the kernel domain, but support could be added in the
951future.
952
953
954[[channel]]
955==== Channel
956
957A _channel_ is a set of events with specific parameters and potential
958added context information. Channels have unique names per domain within
959a tracing session. A given event is always registered to at least one
960channel; having an enabled event in two channels will produce a trace
961with this event recorded twice everytime it occurs.
962
963Channels may be individually enabled or disabled. Occurring events of
964a disabled channel will never make it to recorded events.
965
966The fundamental role of a channel is to keep a shared ring buffer, where
967events are eventually recorded by the tracer and consumed by a consumer
968daemon. This internal ring buffer is divided into many sub-buffers of
969equal size.
970
971Channels, when created, may be fine-tuned thanks to a few parameters,
972many of them related to sub-buffers. The following subsections explain
973what those parameters are and in which situations you should manually
974adjust them.
975
976
977[[channel-overwrite-mode-vs-discard-mode]]
978===== Overwrite and discard event loss modes
979
980As previously mentioned, a channel's ring buffer is divided into many
981equally sized sub-buffers.
982
983As events occur, they are serialized as trace data into a specific
984sub-buffer (yellow arc in the following animation) until it is full:
985when this happens, the sub-buffer is marked as consumable (red) and
986another, _empty_ (white) sub-buffer starts receiving the following
987events. The marked sub-buffer will be consumed eventually by a consumer
988daemon (returns to white).
989
990[NOTE]
991[role="docsvg-channel-subbuf-anim"]
992====
993{note-no-anim}
994====
995
996In an ideal world, sub-buffers are consumed faster than filled, like it
997is the case above. In the real world, however, all sub-buffers could be
998full at some point, leaving no space to record the following events. By
999design, LTTng is a _non-blocking_ tracer: when no empty sub-buffer
1000exists, losing events is acceptable when the alternative would be to
1001cause substantial delays in the instrumented application's execution.
1002LTTng privileges performance over integrity, aiming at perturbing the
1003traced system as little as possible in order to make tracing of subtle
1004race conditions and rare interrupt cascades possible.
1005
1006When it comes to losing events because no empty sub-buffer is available,
1007the channel's _event loss mode_ determines what to do amongst:
1008
1009Discard::
1010 Drop the newest events until a sub-buffer is released.
1011
1012Overwrite::
1013 Clear the sub-buffer containing the oldest recorded
1014 events and start recording the newest events there. This mode is
1015 sometimes called _flight recorder mode_ because it behaves like a
1016 flight recorder: always keep a fixed amount of the latest data.
1017
1018Which mechanism you should choose depends on your context: prioritize
1019the newest or the oldest events in the ring buffer?
1020
1021Beware that, in overwrite mode, a whole sub-buffer is abandoned as soon
1022as a new event doesn't find an empty sub-buffer, whereas in discard
1023mode, only the event that doesn't fit is discarded.
1024
1025Also note that a count of lost events will be incremented and saved in
1026the trace itself when an event is lost in discard mode, whereas no
1027information is kept when a sub-buffer gets overwritten before being
1028committed.
1029
1030There are known ways to decrease your probability of losing events. The
1031next section shows how tuning the sub-buffers count and size can be
1032used to virtually stop losing events.
1033
1034
1035[[channel-subbuf-size-vs-subbuf-count]]
1036===== Sub-buffers count and size
1037
1038For each channel, an LTTng user may set its number of sub-buffers and
1039their size.
1040
1041Note that there is a noticeable tracer's CPU overhead introduced when
1042switching sub-buffers (marking a full one as consumable and switching
1043to an empty one for the following events to be recorded). Knowing this,
1044the following list presents a few practical situations along with how
1045to configure sub-buffers for them:
1046
1047High event throughput::
1048 In general, prefer bigger sub-buffers to
1049 lower the risk of losing events. Having bigger sub-buffers will
1050 also ensure a lower sub-buffer switching frequency. The number of
1051 sub-buffers is only meaningful if the channel is in overwrite mode:
1052 in this case, if a sub-buffer overwrite happens, you will still have
1053 the other sub-buffers left unaltered.
1054
1055Low event throughput::
1056 In general, prefer smaller sub-buffers
1057 since the risk of losing events is already low. Since events
1058 happen less frequently, the sub-buffer switching frequency should
1059 remain low and thus the tracer's overhead should not be a problem.
1060
1061Low memory system::
1062 If your target system has a low memory
1063 limit, prefer fewer first, then smaller sub-buffers. Even if the
1064 system is limited in memory, you want to keep the sub-buffers as
1065 big as possible to avoid a high sub-buffer switching frequency.
1066
1067You should know that LTTng uses CTF as its trace format, which means
1068event data is very compact. For example, the average LTTng Linux kernel
1069event weights about 32{nbsp}bytes. A sub-buffer size of 1{nbsp}MiB is
1070thus considered big.
1071
1072The previous situations highlight the major trade-off between a few big
1073sub-buffers and more, smaller sub-buffers: sub-buffer switching
1074frequency vs. how much data is lost in overwrite mode. Assuming a
1075constant event throughput and using the overwrite mode, the two
1076following configurations have the same ring buffer total size:
1077
1078[NOTE]
1079[role="docsvg-channel-subbuf-size-vs-count-anim"]
1080====
1081{note-no-anim}
1082====
1083
1084* **2 sub-buffers of 4 MiB each** lead to a very low sub-buffer
1085 switching frequency, but if a sub-buffer overwrite happens, half of
1086 the recorded events so far (4{nbsp}MiB) are definitely lost.
1087* **8 sub-buffers of 1 MiB each** lead to 4{nbsp}times the tracer's
1088 overhead as the previous configuration, but if a sub-buffer
1089 overwrite happens, only the eighth of events recorded so far are
1090 definitely lost.
1091
1092In discard mode, the sub-buffers count parameter is pointless: use two
1093sub-buffers and set their size according to the requirements of your
1094situation.
1095
1096
1097[[channel-switch-timer]]
1098===== Switch timer
1099
1100The _switch timer_ period is another important configurable feature of
1101channels to ensure periodic sub-buffer flushing.
1102
1103When the _switch timer_ fires, a sub-buffer switch happens. This timer
1104may be used to ensure that event data is consumed and committed to
1105trace files periodically in case of a low event throughput:
1106
1107[NOTE]
1108[role="docsvg-channel-switch-timer"]
1109====
1110{note-no-anim}
1111====
1112
1113It's also convenient when big sub-buffers are used to cope with
1114sporadic high event throughput, even if the throughput is normally
1115lower.
1116
1117
1118[[channel-buffering-schemes]]
1119===== Buffering schemes
1120
1121In the user space tracing domain, two **buffering schemes** are
1122available when creating a channel:
1123
1124Per-PID buffering::
1125 Keep one ring buffer per process.
1126
1127Per-UID buffering::
1128 Keep one ring buffer for all processes of a single user.
1129
1130The per-PID buffering scheme will consume more memory than the per-UID
1131option if more than one process is instrumented for LTTng-UST. However,
1132per-PID buffering ensures that one process having a high event
1133throughput won't fill all the shared sub-buffers, only its own.
1134
1135The Linux kernel tracing domain only has one available buffering scheme
1136which is to use a single ring buffer for the whole system.
1137
1138
1139[[event]]
1140==== Event
1141
1142An _event_, in LTTng's realm, is a term often used metonymically,
1143having multiple definitions depending on the context:
1144
1145. When tracing, an event is a _point in space-time_. Space, in a
1146 tracing context, is the set of all executable positions of a
1147 compiled application by a logical processor. When a program is
1148 executed by a processor and some instrumentation point, or
1149 _probe_, is encountered, an event occurs. This event is accompanied
1150 by some contextual payload (values of specific variables at this
1151 point of execution) which may or may not be recorded.
1152. In the context of a recorded trace file, the term _event_ implies
1153 a _recorded event_.
1154. When configuring a tracing session, _enabled events_ refer to
1155 specific rules which could lead to the transfer of actual
1156 occurring events (1) to recorded events (2).
1157
1158The whole <<core-concepts,Core concepts>> section focuses on the
1159third definition. An event is always registered to _one or more_
1160channels and may be enabled or disabled at will per channel. A disabled
1161event will never lead to a recorded event, even if its channel
1162is enabled.
1163
1164An event (3) is enabled with a few conditions that must _all_ be met
1165when an event (1) happens in order to generate a recorded event (2):
1166
1167. A _probe_ or group of probes in the traced application must be
1168 executed.
1169. **Optionally**, the probe must have a log level matching a
1170 log level range specified when enabling the event.
1171. **Optionally**, the occurring event must satisfy a custom
1172 expression, or _filter_, specified when enabling the event.
1173
1174The following illustration summarizes how tracing sessions, domains,
1175channels and events are related:
1176
1177[role="img-90"]
1178.Core concepts.
1179image::core-concepts.png[]
1180
1181This diagram also shows how events may be individually enabled/disabled
1182(green/grey) and how a given event may be registered to more than one
1183channel.
1184
1185
1186[[plumbing]]
1187=== Plumbing
1188
1189The previous section described the concepts at the heart of LTTng.
1190This section summarizes LTTng's implementation: how those objects are
1191managed by different applications and libraries working together to
1192form the toolkit.
1193
1194
1195[[plumbing-overview]]
1196==== Overview
1197
1198As <<installing-lttng,mentioned previously>>, the whole LTTng suite
1199is made of the following packages: LTTng-tools, LTTng-UST, and
1200LTTng-modules. Together, they provide different daemons, libraries,
1201kernel modules and command line interfaces. The following tree shows
1202which usable component belongs to which package:
1203
1204* **LTTng-tools**:
1205** session daemon (`lttng-sessiond`)
1206** consumer daemon (`lttng-consumerd`)
1207** relay daemon (`lttng-relayd`)
1208** tracing control library (`liblttng-ctl`)
1209** tracing control command line tool (`lttng`)
1210* **LTTng-UST**:
1211** user space tracing library (`liblttng-ust`) and its headers
1212** preloadable user space tracing helpers
1213 (`liblttng-ust-libc-wrapper`, `liblttng-ust-pthread-wrapper`,
1214 `liblttng-ust-cyg-profile`, `liblttng-ust-cyg-profile-fast`
1215 and `liblttng-ust-dl`)
1216** user space tracepoint code generator command line tool
1217 (`lttng-gen-tp`)
1218** `java.util.logging` tracepoint provider (`liblttng-ust-jul-jni`)
1219 and JAR file (path:{liblttng-ust-jul.jar})
1220* **LTTng-modules**:
1221** LTTng Linux kernel tracer module
1222** tracing ring buffer kernel modules
1223** many LTTng probe kernel modules
1224
1225The following diagram shows how the most important LTTng components
1226interact. Plain black arrows represent trace data paths while dashed
1227red arrows indicate control communications. The LTTng relay daemon is
1228shown running on a remote system, although it could as well run on the
1229target (monitored) system.
1230
1231[role="img-90"]
1232.LTTng plumbing.
1233image::plumbing.png[]
1234
1235Each component is described in the following subsections.
1236
1237
1238[[lttng-sessiond]]
1239==== Session daemon
1240
1241At the heart of LTTng's plumbing is the _session daemon_, often called
1242by its command name, `lttng-sessiond`.
1243
1244The session daemon is responsible for managing tracing sessions and
1245what they logically contain (channel properties, enabled/disabled
1246events, etc.). By communicating locally with instrumented applications
1247(using LTTng-UST) and with the LTTng Linux kernel modules
1248(LTTng-modules), it oversees all tracing activities.
1249
1250One of the many things that `lttng-sessiond` does is to keep
1251track of the available event types. User space applications and
1252libraries actively connect and register to the session daemon when they
1253start. By contrast, `lttng-sessiond` seeks out and loads the appropriate
1254LTTng kernel modules as part of its own initialization. Kernel event
1255types are _pulled_ by `lttng-sessiond`, whereas user space event types
1256are _pushed_ to it by the various user space tracepoint providers.
1257
1258Using a specific inter-process communication protocol with Linux kernel
1259and user space tracers, the session daemon can send channel information
1260so that they are initialized, enable/disable specific probes based on
1261enabled/disabled events by the user, send event filters information to
1262LTTng tracers so that filtering actually happens at the tracer site,
1263start/stop tracing a specific application or the Linux kernel, etc.
1264
1265The session daemon is not useful without some user controlling it,
1266because it's only a sophisticated control interchange and thus
1267doesn't make any decision on its own. `lttng-sessiond` opens a local
1268socket for controlling it, albeit the preferred way to control it is
1269using `liblttng-ctl`, an installed C library hiding the communication
1270protocol behind an easy-to-use API. The `lttng` tool makes use of
1271`liblttng-ctl` to implement a user-friendly command line interface.
1272
1273`lttng-sessiond` does not receive any trace data from instrumented
1274applications; the _consumer daemons_ are the programs responsible for
1275collecting trace data using shared ring buffers. However, the session
1276daemon is the one that must spawn a consumer daemon and establish
1277a control communication with it.
1278
1279Session daemons run on a per-user basis. Knowing this, multiple
1280instances of `lttng-sessiond` may run simultaneously, each belonging
1281to a different user and each operating independently of the others.
1282Only `root`'s session daemon, however, may control LTTng kernel modules
1283(i.e. the kernel tracer). With that in mind, if a user has no root
1284access on the target system, he cannot trace the system's kernel, but
1285should still be able to trace its own instrumented applications.
1286
1287It has to be noted that, although only `root`'s session daemon may
1288control the kernel tracer, the `lttng-sessiond` command has a `--group`
1289option which may be used to specify the name of a special user group
1290allowed to communicate with `root`'s session daemon and thus record
1291kernel traces. By default, this group is named `tracing`.
1292
1293If not done yet, the `lttng` tool, by default, automatically starts a
1294session daemon. `lttng-sessiond` may also be started manually:
1295
1296[role="term"]
1297----
1298lttng-sessiond
1299----
1300
1301This will start the session daemon in foreground. Use
1302
1303[role="term"]
1304----
1305lttng-sessiond --daemonize
1306----
1307
1308to start it as a true daemon.
1309
1310To kill the current user's session daemon, `pkill` may be used:
1311
1312[role="term"]
1313----
1314pkill lttng-sessiond
1315----
1316
1317The default `SIGTERM` signal will terminate it cleanly.
1318
1319Several other options are available and described in
1320man:lttng-sessiond(8) or by running `lttng-sessiond --help`.
1321
1322
1323[[lttng-consumerd]]
1324==== Consumer daemon
1325
1326The _consumer daemon_, or `lttng-consumerd`, is a program sharing some
1327ring buffers with user applications or the LTTng kernel modules to
1328collect trace data and output it at some place (on disk or sent over
1329the network to an LTTng relay daemon).
1330
1331Consumer daemons are created by a session daemon as soon as events are
1332enabled within a tracing session, well before tracing is activated
1333for the latter. Entirely managed by session daemons,
1334consumer daemons survive session destruction to be reused later,
1335should a new tracing session be created. Consumer daemons are always
1336owned by the same user as their session daemon. When its owner session
1337daemon is killed, the consumer daemon also exits. This is because
1338the consumer daemon is always the child process of a session daemon.
1339Consumer daemons should never be started manually. For this reason,
1340they are not installed in one of the usual locations listed in the
1341`PATH` environment variable. `lttng-sessiond` has, however, a
1342bunch of options (see man:lttng-sessiond(8)) to
1343specify custom consumer daemon paths if, for some reason, a consumer
1344daemon other than the default installed one is needed.
1345
1346There are up to two running consumer daemons per user, whereas only one
1347session daemon may run per user. This is because each process has
1348independent bitness: if the target system runs a mixture of 32-bit and
134964-bit processes, it is more efficient to have separate corresponding
135032-bit and 64-bit consumer daemons. The `root` user is an exception: it
1351may have up to _three_ running consumer daemons: 32-bit and 64-bit
1352instances for its user space applications and one more reserved for
1353collecting kernel trace data.
1354
1355As new tracing domains are added to LTTng, the development community's
1356intent is to minimize the need for additionnal consumer daemon instances
1357dedicated to them. For instance, the `java.util.logging` (JUL) domain
1358events are in fact mapped to the user space domain, thus tracing this
1359particular domain is handled by existing user space domain consumer
1360daemons.
1361
1362
1363[[lttng-relayd]]
1364==== Relay daemon
1365
1366When a tracing session is configured to send its trace data over the
1367network, an LTTng _relay daemon_ must be used at the other end to
1368receive trace packets and serialize them to trace files. This setup
1369makes it possible to trace a target system without ever committing trace
1370data to its local storage, a feature which is useful for embedded
1371systems, amongst others. The command implementing the relay daemon
1372is `lttng-relayd`.
1373
1374The basic use case of `lttng-relayd` is to transfer trace data received
1375over the network to trace files on the local file system. The relay
1376daemon must listen on two TCP ports to achieve this: one control port,
1377used by the target session daemon, and one data port, used by the
1378target consumer daemon. The relay and session daemons agree on common
1379default ports when custom ones are not specified.
1380
1381Since the communication transport protocol for both ports is standard
1382TCP, the relay daemon may be started either remotely or locally (on the
1383target system).
1384
1385While two instances of consumer daemons (32-bit and 64-bit) may run
1386concurrently for a given user, `lttng-relayd` needs only be of its
1387host operating system's bitness.
1388
1389The other important feature of LTTng's relay daemon is the support of
1390_LTTng live_. LTTng live is an application protocol to view events as
1391they arrive. The relay daemon will still record events in trace files,
1392but a _tee_ may be created to inspect incoming events. Using LTTng live
1393locally thus requires to run a local relay daemon.
1394
1395
1396[[liblttng-ctl-lttng]]
1397==== [[lttng-cli]]Control library and command line interface
1398
1399The LTTng control library, `liblttng-ctl`, can be used to communicate
1400with the session daemon using a C API that hides the underlying
1401protocol's details. `liblttng-ctl` is part of LTTng-tools.
1402
1403`liblttng-ctl` may be used by including its "master" header:
1404
1405[source,c]
1406----
1407#include <lttng/lttng.h>
1408----
1409
1410Some objects are referred by name (C string), such as tracing sessions,
1411but most of them require creating a handle first using
1412`lttng_create_handle()`. The best available developer documentation for
1413`liblttng-ctl` is, for the moment, its installed header files as such.
1414Every function/structure is thoroughly documented.
1415
1416The `lttng` program is the _de facto_ standard user interface to
1417control LTTng tracing sessions. `lttng` uses `liblttng-ctl` to
1418communicate with session daemons behind the scenes.
1419Its man page, man:lttng(1), is exhaustive, as well as its command
1420line help (+lttng _cmd_ --help+, where +_cmd_+ is the command name).
1421
1422The <<controlling-tracing,Controlling tracing>> section is a feature
1423tour of the `lttng` tool.
1424
1425
1426[[lttng-ust]]
1427==== User space tracing library
1428
1429The user space tracing part of LTTng is possible thanks to the user
1430space tracing library, `liblttng-ust`, which is part of the LTTng-UST
1431package.
1432
1433`liblttng-ust` provides header files containing macros used to define
1434tracepoints and create tracepoint providers, as well as a shared object
1435that must be linked to individual applications to connect to and
1436communicate with a session daemon and a consumer daemon as soon as the
1437application starts.
1438
1439The exact mechanism by which an application is registered to the
1440session daemon is beyond the scope of this documentation. The only thing
1441you need to know is that, since the library constructor does this job
1442automatically, tracepoints may be safely inserted anywhere in the source
1443code without prior manual initialization of `liblttng-ust`.
1444
1445The `liblttng-ust`-session daemon collaboration also provides an
1446interesting feature: user space events may be enabled _before_
1447applications actually start. By doing this and starting tracing before
1448launching the instrumented application, you make sure that even the
1449earliest occurring events can be recorded.
1450
1451The <<c-application,C application>> instrumenting guide of the
1452<<using-lttng,Using LTTng>> chapter focuses on using `liblttng-ust`:
1453instrumenting, building/linking and running a user application.
1454
1455
1456[[lttng-modules]]
1457==== LTTng kernel modules
1458
1459The LTTng Linux kernel modules provide everything needed to trace the
1460Linux kernel: various probes, a ring buffer implementation for a
1461consumer daemon to read trace data and the tracer itself.
1462
1463Only in exceptional circumstances should you ever need to load the
1464LTTng kernel modules manually: it is normally the responsability of
1465`root`'s session daemon to do so. If you were to develop your own LTTng
1466probe module, however--for tracing a custom kernel or some kernel
1467module (this topic is covered in the
1468<<instrumenting-linux-kernel,Linux kernel>> instrumenting guide of
1469the <<using-lttng,Using LTTng>> chapter)--you should either
1470load it manually, or use the `--kmod-probes` option of the session
1471daemon to load a specific list of kernel probes (beware, however,
1472that the `--kmod-probes` option specifies an _absolute_ list, which
1473means you also have to specify the default probes you need). The
1474session and consumer daemons of regular users do not interact with the
1475LTTng kernel modules at all.
1476
1477LTTng kernel modules are installed, by default, in
1478+/usr/lib/modules/_release_/extra+, where +_release_+ is the
1479kernel release (see `uname --kernel-release`).
1480
1481
1482[[using-lttng]]
1483== Using LTTng
1484
1485Using LTTng involves two main activities: **instrumenting** and
1486**controlling tracing**.
1487
1488_<<instrumenting,Instrumenting>>_ is the process of inserting probes
1489into some source code. It can be done manually, by writing tracepoint
1490calls at specific locations in the source code of the program to trace,
1491or more automatically using dynamic probes (address in assembled code,
1492symbol name, function entry/return, etc.).
1493
1494It has to be noted that, as an LTTng user, you may not have to worry
1495about the instrumentation process. Indeed, you may want to trace a
1496program already instrumented. As an example, the Linux kernel is
1497thoroughly instrumented, which is why you can trace it without caring
1498about adding probes.
1499
1500_<<controlling-tracing,Controlling tracing>>_ is everything
1501that can be done by the LTTng session daemon, which is controlled using
1502`liblttng-ctl` or its command line utility, `lttng`: creating tracing
1503sessions, listing tracing sessions and events, enabling/disabling
1504events, starting/stopping the tracers, taking snapshots, etc.
1505
1506This chapter is a complete user guide of both activities,
1507with common use cases of LTTng exposed throughout the text. It is
1508assumed that you are familiar with LTTng's concepts (events, channels,
1509domains, tracing sessions) and that you understand the roles of its
1510components (daemons, libraries, command line tools); if not, we invite
1511you to read the <<understanding-lttng,Understanding LTTng>> chapter
1512before you begin reading this one.
1513
1514If you're new to LTTng, we suggest that you rather start with the
1515<<getting-started,Getting started>> small guide first, then come
1516back here to broaden your knowledge.
1517
1518If you're only interested in tracing the Linux kernel with its current
1519instrumentation, you may skip the
1520<<instrumenting,Instrumenting>> section.
1521
1522
1523[[instrumenting]]
1524=== Instrumenting
1525
1526There are many examples of tracing and monitoring in our everyday life.
1527You have access to real-time and historical weather reports and forecasts
1528thanks to weather stations installed around the country. You know your
1529possibly hospitalized friends' and family's hearts are safe thanks to
1530electrocardiography. You make sure not to drive your car too fast
1531and have enough fuel to reach your destination thanks to gauges visible
1532on your dashboard.
1533
1534All the previous examples have something in common: they rely on
1535**probes**. Without electrodes attached to the surface of a body's
1536skin, cardiac monitoring would be futile.
1537
1538LTTng, as a tracer, is no different from the real life examples above.
1539If you're about to trace a software system, i.e. record its history of
1540execution, you better have probes in the subject you're
1541tracing: the actual software. Various ways were developed to do this.
1542The most straightforward one is to manually place probes, called
1543_tracepoints_, in the software's source code. The Linux kernel tracing
1544domain also allows probes added dynamically.
1545
1546If you're only interested in tracing the Linux kernel, it may very well
1547be that your tracing needs are already appropriately covered by LTTng's
1548built-in Linux kernel tracepoints and other probes. Or you may be in
1549possession of a user space application which has already been
1550instrumented. In such cases, the work will reside entirely in the design
1551and execution of tracing sessions, allowing you to jump to
1552<<controlling-tracing,Controlling tracing>> right now.
1553
1554This chapter focuses on the following use cases of instrumentation:
1555
1556* <<c-application,C>> and <<cxx-application,$$C++$$>> applications
1557* <<prebuilt-ust-helpers,prebuilt user space tracing helpers>>
1558* <<java-application,Java application>>
1559* <<instrumenting-linux-kernel,Linux kernel>> module or the
1560 kernel itself
1561* the <<proc-lttng-logger-abi,path:{/proc/lttng-logger} ABI>>
1562
1563Some advanced techniques are also presented at the very end of this
1564chapter.
1565
1566
1567[[c-application]]
1568==== C application
1569
1570Instrumenting a C (or $$C++$$) application, be it an executable program or
1571a library, implies using LTTng-UST, the
1572user space tracing component of LTTng. For C/$$C++$$ applications, the
1573LTTng-UST package includes a dynamically loaded library
1574(`liblttng-ust`), C headers and the `lttng-gen-tp` command line utility.
1575
1576Since C and $$C++$$ are the base languages of virtually all other
1577programming languages
1578(Java virtual machine, Python, Perl, PHP and Node.js interpreters, etc.),
1579implementing user space tracing for an unsupported language is just a
1580matter of using the LTTng-UST C API at the right places.
1581
1582The usual work flow to instrument a user space C application with
1583LTTng-UST is:
1584
1585. Define tracepoints (actual probes)
1586. Write tracepoint providers
1587. Insert tracepoints into target source code
1588. Package (build) tracepoint providers
1589. Build user application and link it with tracepoint providers
1590
1591The steps above are discussed in greater detail in the following
1592subsections.
1593
1594
1595[[tracepoint-provider]]
1596===== Tracepoint provider
1597
1598Before jumping into defining tracepoints and inserting
1599them into the application source code, you must understand what a
1600_tracepoint provider_ is.
1601
1602For the sake of this guide, consider the following two files:
1603
1604[source,c]
1605.path:{tp.h}
1606----
1607#undef TRACEPOINT_PROVIDER
1608#define TRACEPOINT_PROVIDER my_provider
1609
1610#undef TRACEPOINT_INCLUDE
1611#define TRACEPOINT_INCLUDE "./tp.h"
1612
1613#if !defined(_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
1614#define _TP_H
1615
1616#include <lttng/tracepoint.h>
1617
1618TRACEPOINT_EVENT(
1619 my_provider,
1620 my_first_tracepoint,
1621 TP_ARGS(
1622 int, my_integer_arg,
1623 char*, my_string_arg
1624 ),
1625 TP_FIELDS(
1626 ctf_string(my_string_field, my_string_arg)
1627 ctf_integer(int, my_integer_field, my_integer_arg)
1628 )
1629)
1630
1631TRACEPOINT_EVENT(
1632 my_provider,
1633 my_other_tracepoint,
1634 TP_ARGS(
1635 int, my_int
1636 ),
1637 TP_FIELDS(
1638 ctf_integer(int, some_field, my_int)
1639 )
1640)
1641
1642#endif /* _TP_H */
1643
1644#include <lttng/tracepoint-event.h>
1645----
1646
1647[source,c]
1648.path:{tp.c}
1649----
1650#define TRACEPOINT_CREATE_PROBES
1651
1652#include "tp.h"
1653----
1654
1655The two files above are defining a _tracepoint provider_. A tracepoint
1656provider is some sort of namespace for _tracepoint definitions_. Tracepoint
1657definitions are written above with the `TRACEPOINT_EVENT()` macro, and allow
1658eventual `tracepoint()` calls respecting their definitions to be inserted
1659into the user application's C source code (we explore this in a
1660later section).
1661
1662Many tracepoint definitions may be part of the same tracepoint provider
1663and many tracepoint providers may coexist in a user space application. A
1664tracepoint provider is packaged either:
1665
1666* directly into an existing user application's C source file
1667* as an object file
1668* as a static library
1669* as a shared library
1670
1671The two files above, path:{tp.h} and path:{tp.c}, show a typical template for
1672writing a tracepoint provider. LTTng-UST was designed so that two
1673tracepoint providers should not be defined in the same header file.
1674
1675We will now go through the various parts of the above files and
1676give them a meaning. As you may have noticed, the LTTng-UST API for
1677C/$$C++$$ applications is some preprocessor sorcery. The LTTng-UST macros
1678used in your application and those in the LTTng-UST headers are
1679combined to produce actual source code needed to make tracing possible
1680using LTTng.
1681
1682Let's start with the header file, path:{tp.h}. It begins with
1683
1684[source,c]
1685----
1686#undef TRACEPOINT_PROVIDER
1687#define TRACEPOINT_PROVIDER my_provider
1688----
1689
1690`TRACEPOINT_PROVIDER` defines the name of the provider to which the
1691following tracepoint definitions will belong. It is used internally by
1692LTTng-UST headers and _must_ be defined. Since `TRACEPOINT_PROVIDER`
1693could have been defined by another header file also included by the same
1694C source file, the best practice is to undefine it first.
1695
1696NOTE: Names in LTTng-UST follow the C
1697_identifier_ syntax (starting with a letter and containing either
1698letters, numbers or underscores); they are _not_ C strings
1699(not surrounded by double quotes). This is because LTTng-UST macros
1700use those identifier-like strings to create symbols (named types and
1701variables).
1702
1703The tracepoint provider is a group of tracepoint definitions; its chosen
1704name should reflect this. A hierarchy like Java packages is recommended,
1705using underscores instead of dots, e.g., `org_company_project_component`.
1706
1707Next is `TRACEPOINT_INCLUDE`:
1708
1709[source,c]
1710----
1711#undef TRACEPOINT_INCLUDE
1712#define TRACEPOINT_INCLUDE "./tp.h"
1713----
1714
1715This little bit of instrospection is needed by LTTng-UST to include
1716your header at various predefined places.
1717
1718Include guard follows:
1719
1720[source,c]
1721----
1722#if !defined(_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
1723#define _TP_H
1724----
1725
1726Add these precompiler conditionals to ensure the tracepoint event
1727generation can include this file more than once.
1728
1729The `TRACEPOINT_EVENT()` macro is defined in a LTTng-UST header file which
1730must be included:
1731
1732[source,c]
1733----
1734#include <lttng/tracepoint.h>
1735----
1736
1737This will also allow the application to use the `tracepoint()` macro.
1738
1739Next is a list of `TRACEPOINT_EVENT()` macro calls which create the
1740actual tracepoint definitions. We will skip this for the moment and
1741come back to how to use `TRACEPOINT_EVENT()`
1742<<defining-tracepoints,in a later section>>. Just pay attention to
1743the first argument: it's always the name of the tracepoint provider
1744being defined in this header file.
1745
1746End of include guard:
1747
1748[source,c]
1749----
1750#endif /* _TP_H */
1751----
1752
1753Finally, include `<lttng/tracepoint-event.h>` to expand the macros:
1754
1755[source,c]
1756----
1757#include <lttng/tracepoint-event.h>
1758----
1759
1760That's it for path:{tp.h}. Of course, this is only a header file; it must be
1761included in some C source file to actually use it. This is the job of
1762path:{tp.c}:
1763
1764[source,c]
1765----
1766#define TRACEPOINT_CREATE_PROBES
1767
1768#include "tp.h"
1769----
1770
1771When `TRACEPOINT_CREATE_PROBES` is defined, the macros used in path:{tp.h},
1772which is included just after, will actually create the source code for
1773LTTng-UST probes (global data structures and functions) out of your
1774tracepoint definitions. How exactly this is done is out of this text's scope.
1775`TRACEPOINT_CREATE_PROBES` is discussed further
1776in
1777<<building-tracepoint-providers-and-user-application,Building/linking
1778tracepoint providers and the user application>>.
1779
1780You could include other header files like path:{tp.h} here to create the probes
1781of different tracepoint providers, e.g.:
1782
1783[source,c]
1784----
1785#define TRACEPOINT_CREATE_PROBES
1786
1787#include "tp1.h"
1788#include "tp2.h"
1789----
1790
1791The rule is: probes of a given tracepoint provider
1792must be created in exactly one source file. This source file could be one
1793of your project's; it doesn't have to be on its own like
1794path:{tp.c}, although
1795<<building-tracepoint-providers-and-user-application,a later section>>
1796shows that doing so allows packaging the tracepoint providers
1797independently and keep them out of your application, also making it
1798possible to reuse them between projects.
1799
1800The following sections explain how to define tracepoints, how to use the
1801`tracepoint()` macro to instrument your user space C application and how
1802to build/link tracepoint providers and your application with LTTng-UST
1803support.
1804
1805
1806[[lttng-gen-tp]]
1807===== Using `lttng-gen-tp`
1808
1809LTTng-UST ships with `lttng-gen-tp`, a handy command line utility for
1810generating most of the stuff discussed above. It takes a _template file_,
1811with a name usually ending with the `.tp` extension, containing only
1812tracepoint definitions, and outputs a tracepoint provider (either a C
1813source file or a precompiled object file) with its header file.
1814
1815`lttng-gen-tp` should suffice in <<static-linking,static linking>>
1816situations. When using it, write a template file containing a list of
1817`TRACEPOINT_EVENT()` macro calls. The tool will find the provider names
1818used and generate the appropriate files which are going to look a lot
1819like path:{tp.h} and path:{tp.c} above.
1820
1821Just call `lttng-gen-tp` like this:
1822
1823[role="term"]
1824----
1825lttng-gen-tp my-template.tp
1826----
1827
1828path:{my-template.c}, path:{my-template.o} and path:{my-template.h}
1829will be created in the same directory.
1830
1831You may specify custom C flags passed to the compiler invoked by
1832`lttng-gen-tp` using the `CFLAGS` environment variable:
1833
1834[role="term"]
1835----
1836CFLAGS=-I/custom/include/path lttng-gen-tp my-template.tp
1837----
1838
1839For more information on `lttng-gen-tp`, see man:lttng-gen-tp(1).
1840
1841
1842[[defining-tracepoints]]
1843===== Defining tracepoints
1844
1845As written in <<tracepoint-provider,Tracepoint provider>>,
1846tracepoints are defined using the
1847`TRACEPOINT_EVENT()` macro. Each tracepoint, when called using the
1848`tracepoint()` macro in the actual application's source code, generates
1849a specific event type with its own fields.
1850
1851Let's have another look at the example above, with a few added comments:
1852
1853[source,c]
1854----
1855TRACEPOINT_EVENT(
1856 /* tracepoint provider name */
1857 my_provider,
1858
1859 /* tracepoint/event name */
1860 my_first_tracepoint,
1861
1862 /* list of tracepoint arguments */
1863 TP_ARGS(
1864 int, my_integer_arg,
1865 char*, my_string_arg
1866 ),
1867
1868 /* list of fields of eventual event */
1869 TP_FIELDS(
1870 ctf_string(my_string_field, my_string_arg)
1871 ctf_integer(int, my_integer_field, my_integer_arg)
1872 )
1873)
1874----
1875
1876The tracepoint provider name must match the name of the tracepoint
1877provider in which this tracepoint is defined
1878(see <<tracepoint-provider,Tracepoint provider>>). In other words,
1879always use the same string as the value of `TRACEPOINT_PROVIDER` above.
1880
1881The tracepoint name will become the event name once events are recorded
1882by the LTTng-UST tracer. It must follow the tracepoint provider name
1883syntax: start with a letter and contain either letters, numbers or
1884underscores. Two tracepoints under the same provider cannot have the
1885same name, i.e. you cannot overload a tracepoint like you would
1886overload functions and methods in $$C++$$/Java.
1887
1888NOTE: The concatenation of the tracepoint
1889provider name and the tracepoint name cannot exceed 254 characters. If
1890it does, the instrumented application will compile and run, but LTTng
1891will issue multiple warnings and you could experience serious problems.
1892
1893The list of tracepoint arguments gives this tracepoint its signature:
1894see it like the declaration of a C function. The format of `TP_ARGS()`
1895arguments is: C type, then argument name; repeat as needed, up to ten
1896times. For example, if we were to replicate the signature of C standard
1897library's `fseek()`, the `TP_ARGS()` part would look like:
1898
1899[source,c]
1900----
1901 TP_ARGS(
1902 FILE*, stream,
1903 long int, offset,
1904 int, origin
1905 ),
1906----
1907
1908Of course, you will need to include appropriate header files before
1909the `TRACEPOINT_EVENT()` macro calls if any argument has a complex type.
1910
1911`TP_ARGS()` may not be omitted, but may be empty. `TP_ARGS(void)` is
1912also accepted.
1913
1914The list of fields is where the fun really begins. The fields defined
1915in this list will be the fields of the events generated by the execution
1916of this tracepoint. Each tracepoint field definition has a C
1917_argument expression_ which will be evaluated when the execution reaches
1918the tracepoint. Tracepoint arguments _may be_ used freely in those
1919argument expressions, but they _don't_ have to.
1920
1921There are several types of tracepoint fields available. The macros to
1922define them are given and explained in the
1923<<liblttng-ust-tp-fields,LTTng-UST library reference>> section.
1924
1925Field names must follow the standard C identifier syntax: letter, then
1926optional sequence of letters, numbers or underscores. Each field must have
1927a different name.
1928
1929Those `ctf_*()` macros are added to the `TP_FIELDS()` part of
1930`TRACEPOINT_EVENT()`. Note that they are not delimited by commas.
1931`TP_FIELDS()` may be empty, but the `TP_FIELDS(void)` form is _not_
1932accepted.
1933
1934The following snippet shows how argument expressions may be used in
1935tracepoint fields and how they may refer freely to tracepoint arguments.
1936
1937[source,c]
1938----
1939/* for struct stat */
1940#include <sys/types.h>
1941#include <sys/stat.h>
1942#include <unistd.h>
1943
1944TRACEPOINT_EVENT(
1945 my_provider,
1946 my_tracepoint,
1947 TP_ARGS(
1948 int, my_int_arg,
1949 char*, my_str_arg,
1950 struct stat*, st
1951 ),
1952 TP_FIELDS(
1953 /* simple integer field with constant value */
1954 ctf_integer(
1955 int, /* field C type */
1956 my_constant_field, /* field name */
1957 23 + 17 /* argument expression */
1958 )
1959
1960 /* my_int_arg tracepoint argument */
1961 ctf_integer(
1962 int,
1963 my_int_arg_field,
1964 my_int_arg
1965 )
1966
1967 /* my_int_arg squared */
1968 ctf_integer(
1969 int,
1970 my_int_arg_field2,
1971 my_int_arg * my_int_arg
1972 )
1973
1974 /* sum of first 4 characters of my_str_arg */
1975 ctf_integer(
1976 int,
1977 sum4,
1978 my_str_arg[0] + my_str_arg[1] +
1979 my_str_arg[2] + my_str_arg[3]
1980 )
1981
1982 /* my_str_arg as string field */
1983 ctf_string(
1984 my_str_arg_field, /* field name */
1985 my_str_arg /* argument expression */
1986 )
1987
1988 /* st_size member of st tracepoint argument, hexadecimal */
1989 ctf_integer_hex(
1990 off_t, /* field C type */
1991 size_field, /* field name */
1992 st->st_size /* argument expression */
1993 )
1994
1995 /* st_size member of st tracepoint argument, as double */
1996 ctf_float(
1997 double, /* field C type */
1998 size_dbl_field, /* field name */
1999 (double) st->st_size /* argument expression */
2000 )
2001
2002 /* half of my_str_arg string as text sequence */
2003 ctf_sequence_text(
2004 char, /* element C type */
2005 half_my_str_arg_field, /* field name */
2006 my_str_arg, /* argument expression */
2007 size_t, /* length expression C type */
2008 strlen(my_str_arg) / 2 /* length expression */
2009 )
2010 )
2011)
2012----
2013
2014As you can see, having a custom argument expression for each field
2015makes tracepoints very flexible for tracing a user space C application.
2016This tracepoint definition is reused later in this guide, when
2017actually using tracepoints in a user space application.
2018
2019
2020[[using-tracepoint-classes]]
2021===== Using tracepoint classes
2022
2023In LTTng-UST, a _tracepoint class_ is a class of tracepoints sharing the
2024same field types and names. A _tracepoint instance_ is one instance of
2025such a declared tracepoint class, with its own event name and tracepoint
2026provider name.
2027
2028What is documented in <<defining-tracepoints,Defining tracepoints>>
2029is actually how to declare a _tracepoint class_ and define a
2030_tracepoint instance_ at the same time. Without revealing the internals
2031of LTTng-UST too much, it has to be noted that one serialization
2032function is created for each tracepoint class. A serialization
2033function is responsible for serializing the fields of a tracepoint
2034into a sub-buffer when tracing. For various performance reasons, when
2035your situation requires multiple tracepoints with different names, but
2036with the same fields layout, the best practice is to manually create
2037a tracepoint class and instantiate as many tracepoint instances as
2038needed. One positive effect of such a design, amongst other advantages,
2039is that all tracepoint instances of the same tracepoint class will
2040reuse the same serialization function, thus reducing cache pollution.
2041
2042As an example, here are three tracepoint definitions as we know them:
2043
2044[source,c]
2045----
2046TRACEPOINT_EVENT(
2047 my_app,
2048 get_account,
2049 TP_ARGS(
2050 int, userid,
2051 size_t, len
2052 ),
2053 TP_FIELDS(
2054 ctf_integer(int, userid, userid)
2055 ctf_integer(size_t, len, len)
2056 )
2057)
2058
2059TRACEPOINT_EVENT(
2060 my_app,
2061 get_settings,
2062 TP_ARGS(
2063 int, userid,
2064 size_t, len
2065 ),
2066 TP_FIELDS(
2067 ctf_integer(int, userid, userid)
2068 ctf_integer(size_t, len, len)
2069 )
2070)
2071
2072TRACEPOINT_EVENT(
2073 my_app,
2074 get_transaction,
2075 TP_ARGS(
2076 int, userid,
2077 size_t, len
2078 ),
2079 TP_FIELDS(
2080 ctf_integer(int, userid, userid)
2081 ctf_integer(size_t, len, len)
2082 )
2083)
2084----
2085
2086In this case, three tracepoint classes are created, with one tracepoint
2087instance for each of them: `get_account`, `get_settings` and
2088`get_transaction`. However, they all share the same field names and
2089types. Declaring one tracepoint class and three tracepoint instances of
2090the latter is a better design choice:
2091
2092[source,c]
2093----
2094/* the tracepoint class */
2095TRACEPOINT_EVENT_CLASS(
2096 /* tracepoint provider name */
2097 my_app,
2098
2099 /* tracepoint class name */
2100 my_class,
2101
2102 /* arguments */
2103 TP_ARGS(
2104 int, userid,
2105 size_t, len
2106 ),
2107
2108 /* fields */
2109 TP_FIELDS(
2110 ctf_integer(int, userid, userid)
2111 ctf_integer(size_t, len, len)
2112 )
2113)
2114
2115/* the tracepoint instances */
2116TRACEPOINT_EVENT_INSTANCE(
2117 /* tracepoint provider name */
2118 my_app,
2119
2120 /* tracepoint class name */
2121 my_class,
2122
2123 /* tracepoint/event name */
2124 get_account,
2125
2126 /* arguments */
2127 TP_ARGS(
2128 int, userid,
2129 size_t, len
2130 )
2131)
2132TRACEPOINT_EVENT_INSTANCE(
2133 my_app,
2134 my_class,
2135 get_settings,
2136 TP_ARGS(
2137 int, userid,
2138 size_t, len
2139 )
2140)
2141TRACEPOINT_EVENT_INSTANCE(
2142 my_app,
2143 my_class,
2144 get_transaction,
2145 TP_ARGS(
2146 int, userid,
2147 size_t, len
2148 )
2149)
2150----
2151
2152Of course, all those names and `TP_ARGS()` invocations are redundant,
2153but some C preprocessor magic can solve this:
2154
2155[source,c]
2156----
2157#define MY_TRACEPOINT_ARGS \
2158 TP_ARGS( \
2159 int, userid, \
2160 size_t, len \
2161 )
2162
2163TRACEPOINT_EVENT_CLASS(
2164 my_app,
2165 my_class,
2166 MY_TRACEPOINT_ARGS,
2167 TP_FIELDS(
2168 ctf_integer(int, userid, userid)
2169 ctf_integer(size_t, len, len)
2170 )
2171)
2172
2173#define MY_APP_TRACEPOINT_INSTANCE(name) \
2174 TRACEPOINT_EVENT_INSTANCE( \
2175 my_app, \
2176 my_class, \
2177 name, \
2178 MY_TRACEPOINT_ARGS \
2179 )
2180
2181MY_APP_TRACEPOINT_INSTANCE(get_account)
2182MY_APP_TRACEPOINT_INSTANCE(get_settings)
2183MY_APP_TRACEPOINT_INSTANCE(get_transaction)
2184----
2185
2186
2187[[assigning-log-levels]]
2188===== Assigning log levels to tracepoints
2189
2190Optionally, a log level can be assigned to a defined tracepoint.
2191Assigning different levels of importance to tracepoints can be useful;
2192when controlling tracing sessions,
2193<<controlling-tracing,you can choose>> to only enable tracepoints
2194falling into a specific log level range.
2195
2196Log levels are assigned to defined tracepoints using the
2197`TRACEPOINT_LOGLEVEL()` macro. The latter must be used _after_ having
2198used `TRACEPOINT_EVENT()` for a given tracepoint. The
2199`TRACEPOINT_LOGLEVEL()` macro has the following construct:
2200
2201[source,c]
2202----
2203TRACEPOINT_LOGLEVEL(PROVIDER_NAME, TRACEPOINT_NAME, LOG_LEVEL)
2204----
2205
2206where the first two arguments are the same as the first two arguments
2207of `TRACEPOINT_EVENT()` and `LOG_LEVEL` is one
2208of the values given in the
2209<<liblttng-ust-tracepoint-loglevel,LTTng-UST library reference>>
2210section.
2211
2212As an example, let's assign a `TRACE_DEBUG_UNIT` log level to our
2213previous tracepoint definition:
2214
2215[source,c]
2216----
2217TRACEPOINT_LOGLEVEL(my_provider, my_tracepoint, TRACE_DEBUG_UNIT)
2218----
2219
2220
2221[[probing-the-application-source-code]]
2222===== Probing the application's source code
2223
2224Once tracepoints are properly defined within a tracepoint provider,
2225they may be inserted into the user application to be instrumented
2226using the `tracepoint()` macro. Its first argument is the tracepoint
2227provider name and its second is the tracepoint name. The next, optional
2228arguments are defined by the `TP_ARGS()` part of the definition of
2229the tracepoint to use.
2230
2231As an example, let us again take the following tracepoint definition:
2232
2233[source,c]
2234----
2235TRACEPOINT_EVENT(
2236 /* tracepoint provider name */
2237 my_provider,
2238
2239 /* tracepoint/event name */
2240 my_first_tracepoint,
2241
2242 /* list of tracepoint arguments */
2243 TP_ARGS(
2244 int, my_integer_arg,
2245 char*, my_string_arg
2246 ),
2247
2248 /* list of fields of eventual event */
2249 TP_FIELDS(
2250 ctf_string(my_string_field, my_string_arg)
2251 ctf_integer(int, my_integer_field, my_integer_arg)
2252 )
2253)
2254----
2255
2256Assuming this is part of a file named path:{tp.h} which defines the tracepoint
2257provider and which is included by path:{tp.c}, here's a complete C application
2258calling this tracepoint (multiple times):
2259
2260[source,c]
2261----
2262#define TRACEPOINT_DEFINE
2263#include "tp.h"
2264
2265int main(int argc, char* argv[])
2266{
2267 int i;
2268
2269 tracepoint(my_provider, my_first_tracepoint, 23, "Hello, World!");
2270
2271 for (i = 0; i < argc; ++i) {
2272 tracepoint(my_provider, my_first_tracepoint, i, argv[i]);
2273 }
2274
2275 return 0;
2276}
2277----
2278
2279For each tracepoint provider, `TRACEPOINT_DEFINE` must be defined into
2280exactly one translation unit (C source file) of the user application,
2281before including the tracepoint provider header file. In other words,
2282for a given tracepoint provider, you cannot define `TRACEPOINT_DEFINE`,
2283and then include its header file in two separate C source files of
2284the same application. `TRACEPOINT_DEFINE` is discussed further in
2285<<building-tracepoint-providers-and-user-application,Building/linking
2286tracepoint providers and the user application>>.
2287
2288As another example, remember this definition we wrote in a previous
2289section (comments are stripped):
2290
2291[source,c]
2292----
2293/* for struct stat */
2294#include <sys/types.h>
2295#include <sys/stat.h>
2296#include <unistd.h>
2297
2298TRACEPOINT_EVENT(
2299 my_provider,
2300 my_tracepoint,
2301 TP_ARGS(
2302 int, my_int_arg,
2303 char*, my_str_arg,
2304 struct stat*, st
2305 ),
2306 TP_FIELDS(
2307 ctf_integer(int, my_constant_field, 23 + 17)
2308 ctf_integer(int, my_int_arg_field, my_int_arg)
2309 ctf_integer(int, my_int_arg_field2, my_int_arg * my_int_arg)
2310 ctf_integer(int, sum4_field, my_str_arg[0] + my_str_arg[1] +
2311 my_str_arg[2] + my_str_arg[3])
2312 ctf_string(my_str_arg_field, my_str_arg)
2313 ctf_integer_hex(off_t, size_field, st->st_size)
2314 ctf_float(double, size_dbl_field, (double) st->st_size)
2315 ctf_sequence_text(char, half_my_str_arg_field, my_str_arg,
2316 size_t, strlen(my_str_arg) / 2)
2317 )
2318)
2319----
2320
2321Here's an example of calling it:
2322
2323[source,c]
2324----
2325#define TRACEPOINT_DEFINE
2326#include "tp.h"
2327
2328int main(void)
2329{
2330 struct stat s;
2331
2332 stat("/etc/fstab", &s);
2333
2334 tracepoint(my_provider, my_tracepoint, 23, "Hello, World!", &s);
2335
2336 return 0;
2337}
2338----
2339
2340When viewing the trace, assuming the file size of path:{/etc/fstab} is
2341301{nbsp}bytes, the event generated by the execution of this tracepoint
2342should have the following fields, in this order:
2343
2344----
2345my_constant_field 40
2346my_int_arg_field 23
2347my_int_arg_field2 529
2348sum4_field 389
2349my_str_arg_field "Hello, World!"
2350size_field 0x12d
2351size_dbl_field 301.0
2352half_my_str_arg_field "Hello,"
2353----
2354
2355
2356[[building-tracepoint-providers-and-user-application]]
2357===== Building/linking tracepoint providers and the user application
2358
2359The final step of using LTTng-UST for tracing a user space C application
2360(beside running the application) is building and linking tracepoint
2361providers and the application itself.
2362
2363As discussed above, the macros used by the user-written tracepoint provider
2364header file are useless until actually used to create probes code
2365(global data structures and functions) in a translation unit (C source file).
2366This is accomplished by defining `TRACEPOINT_CREATE_PROBES` in a translation
2367unit and then including the tracepoint provider header file.
2368When `TRACEPOINT_CREATE_PROBES` is defined, macros used and included by
2369the tracepoint provider header will output actual source code needed by any
2370application using the defined tracepoints. Defining
2371`TRACEPOINT_CREATE_PROBES` produces code used when registering
2372tracepoint providers when the tracepoint provider package loads.
2373
2374The other important definition is `TRACEPOINT_DEFINE`. This one creates
2375global, per-tracepoint structures referencing the tracepoint providers
2376data. Those structures are required by the actual functions inserted
2377where `tracepoint()` macros are placed and need to be defined by the
2378instrumented application.
2379
2380Both `TRACEPOINT_CREATE_PROBES` and `TRACEPOINT_DEFINE` need to be defined
2381at some places in order to trace a user space C application using LTTng.
2382Although explaining their exact mechanism is beyond the scope of this
2383document, the reason they both exist separately is to allow the trace
2384providers to be packaged as a shared object (dynamically loaded library).
2385
2386There are two ways to compile and link the tracepoint providers
2387with the application: _<<static-linking,statically>>_ or
2388_<<dynamic-linking,dynamically>>_. Both methods are covered in the
2389following subsections.
2390
2391
2392[[static-linking]]
2393===== Static linking the tracepoint providers to the application
2394
2395With the static linking method, compiled tracepoint providers are copied
2396into the target application. There are three ways to do this:
2397
2398. Use one of your **existing C source files** to create probes.
2399. Create probes in a separate C source file and build it as an
2400 **object file** to be linked with the application (more decoupled).
2401. Create probes in a separate C source file, build it as an
2402 object file and archive it to create a **static library**
2403 (more decoupled, more portable).
2404
2405The first approach is to define `TRACEPOINT_CREATE_PROBES` and include
2406your tracepoint provider(s) header file(s) directly into an existing C
2407source file. Here's an example:
2408
2409[source,c]
2410----
2411#include <stdlib.h>
2412#include <stdio.h>
2413/* ... */
2414
2415#define TRACEPOINT_CREATE_PROBES
2416#define TRACEPOINT_DEFINE
2417#include "tp.h"
2418
2419/* ... */
2420
2421int my_func(int a, const char* b)
2422{
2423 /* ... */
2424
2425 tracepoint(my_provider, my_tracepoint, buf, sz, limit, &tt)
2426
2427 /* ... */
2428}
2429
2430/* ... */
2431----
2432
2433Again, before including a given tracepoint provider header file,
2434`TRACEPOINT_CREATE_PROBES` and `TRACEPOINT_DEFINE` must be defined in
2435one, **and only one**, translation unit. Other C source files of the
2436same application may include path:{tp.h} to use tracepoints with
2437the `tracepoint()` macro, but must not define
2438`TRACEPOINT_CREATE_PROBES`/`TRACEPOINT_DEFINE` again.
2439
2440This translation unit may be built as an object file by making sure to
2441add `.` to the include path:
2442
2443[role="term"]
2444----
2445gcc -c -I. file.c
2446----
2447
2448The second approach is to isolate the tracepoint provider code into a
2449separate object file by using a dedicated C source file to create probes:
2450
2451[source,c]
2452----
2453#define TRACEPOINT_CREATE_PROBES
2454
2455#include "tp.h"
2456----
2457
2458`TRACEPOINT_DEFINE` must be defined by a translation unit of the
2459application. Since we're talking about static linking here, it could as
2460well be defined directly in the file above, before `#include "tp.h"`:
2461
2462[source,c]
2463----
2464#define TRACEPOINT_CREATE_PROBES
2465#define TRACEPOINT_DEFINE
2466
2467#include "tp.h"
2468----
2469
2470This is actually what <<lttng-gen-tp,`lttng-gen-tp`>> does, and is
2471the recommended practice.
2472
2473Build the tracepoint provider:
2474
2475[role="term"]
2476----
2477gcc -c -I. tp.c
2478----
2479
2480Finally, the resulting object file may be archived to create a
2481more portable tracepoint provider static library:
2482
2483[role="term"]
2484----
2485ar rc tp.a tp.o
2486----
2487
2488Using a static library does have the advantage of centralising the
2489tracepoint providers objects so they can be shared between multiple
2490applications. This way, when the tracepoint provider is modified, the
2491source code changes don't have to be patched into each application's source
2492code tree. The applications need to be relinked after each change, but need
2493not to be otherwise recompiled (unless the tracepoint provider's API
2494changes).
2495
2496Regardless of which method you choose, you end up with an object file
2497(potentially archived) containing the trace providers assembled code.
2498To link this code with the rest of your application, you must also link
2499with `liblttng-ust` and `libdl`:
2500
2501[role="term"]
2502----
2503gcc -o app tp.o other.o files.o of.o your.o app.o -llttng-ust -ldl
2504----
2505
2506or
2507
2508[role="term"]
2509----
2510gcc -o app tp.a other.o files.o of.o your.o app.o -llttng-ust -ldl
2511----
2512
2513If you're using a BSD
2514system, replace `-ldl` with `-lc`:
2515
2516[role="term"]
2517----
2518gcc -o app tp.a other.o files.o of.o your.o app.o -llttng-ust -lc
2519----
2520
2521The application can be started as usual, e.g.:
2522
2523[role="term"]
2524----
2525./app
2526----
2527
2528The `lttng` command line tool can be used to
2529<<controlling-tracing,control tracing>>.
2530
2531
2532[[dynamic-linking]]
2533===== Dynamic linking the tracepoint providers to the application
2534
2535The second approach to package the tracepoint providers is to use
2536dynamic linking: the library and its member functions are explicitly
2537sought, loaded and unloaded at runtime using `libdl`.
2538
2539It has to be noted that, for a variety of reasons, the created shared
2540library will be dynamically _loaded_, as opposed to dynamically
2541_linked_. The tracepoint provider shared object is, however, linked
2542with `liblttng-ust`, so that `liblttng-ust` is guaranteed to be loaded
2543as soon as the tracepoint provider is. If the tracepoint provider is
2544not loaded, since the application itself is not linked with
2545`liblttng-ust`, the latter is not loaded at all and the tracepoint calls
2546become inert.
2547
2548The process to create the tracepoint provider shared object is pretty
2549much the same as the static library method, except that:
2550
2551* since the tracepoint provider is not part of the application
2552 anymore, `TRACEPOINT_DEFINE` _must_ be defined, for each tracepoint
2553 provider, in exactly one translation unit (C source file) of the
2554 _application_;
2555* `TRACEPOINT_PROBE_DYNAMIC_LINKAGE` must be defined next to
2556 `TRACEPOINT_DEFINE`.
2557
2558Regarding `TRACEPOINT_DEFINE` and `TRACEPOINT_PROBE_DYNAMIC_LINKAGE`,
2559the recommended practice is to use a separate C source file in your
2560application to define them, and then include the tracepoint provider
2561header files afterwards, e.g.:
2562
2563[source,c]
2564----
2565#define TRACEPOINT_DEFINE
2566#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
2567
2568/* include the header files of one or more tracepoint providers below */
2569#include "tp1.h"
2570#include "tp2.h"
2571#include "tp3.h"
2572----
2573
2574`TRACEPOINT_PROBE_DYNAMIC_LINKAGE` makes the macros included afterwards
2575(by including the tracepoint provider header, which itself includes
2576LTTng-UST headers) aware that the tracepoint provider is to be loaded
2577dynamically and not part of the application's executable.
2578
2579The tracepoint provider object file used to create the shared library
2580is built like it is using the static library method, only with the
2581`-fpic` option added:
2582
2583[role="term"]
2584----
2585gcc -c -fpic -I. tp.c
2586----
2587
2588It is then linked as a shared library like this:
2589
2590[role="term"]
2591----
2592gcc -shared -Wl,--no-as-needed -o tp.so -llttng-ust tp.o
2593----
2594
2595As previously stated, this tracepoint provider shared object isn't
2596linked with the user application: it will be loaded manually. This is
2597why the application is built with no mention of this tracepoint
2598provider, but still needs `libdl`:
2599
2600[role="term"]
2601----
2602gcc -o app other.o files.o of.o your.o app.o -ldl
2603----
2604
2605Now, to make LTTng-UST tracing available to the application, the
2606`LD_PRELOAD` environment variable is used to preload the tracepoint
2607provider shared library _before_ the application actually starts:
2608
2609[role="term"]
2610----
2611LD_PRELOAD=/path/to/tp.so ./app
2612----
2613
2614[NOTE]
2615====
2616It is not safe to use
2617`dlclose()` on a tracepoint provider shared object that
2618is being actively used for tracing, due to a lack of reference
2619counting from LTTng-UST to the shared object.
2620
2621For example, statically linking a tracepoint provider to a
2622shared object which is to be dynamically loaded by an application
2623(e.g., a plugin) is not safe: the shared object, which contains the
2624tracepoint provider, could be dynamically closed
2625(`dlclose()`) at any time by the application.
2626
2627To instrument a shared object, either:
2628
2629* Statically link the tracepoint provider to the _application_, or
2630* Build the tracepoint provider as a shared object (following
2631 the procedure shown in this section), and preload it when
2632 tracing is needed using the `LD_PRELOAD`
2633 environment variable.
2634====
2635
2636Your application will still work without this preloading, albeit without
2637LTTng-UST tracing support:
2638
2639[role="term"]
2640----
2641./app
2642----
2643
2644
2645[[using-lttng-ust-with-daemons]]
2646===== Using LTTng-UST with daemons
2647
2648Some extra care is needed when using `liblttng-ust` with daemon
2649applications that call `fork()`, `clone()` or BSD's `rfork()` without
2650a following `exec()` family system call. The `liblttng-ust-fork`
2651library must be preloaded for the application.
2652
2653Example:
2654
2655[role="term"]
2656----
2657LD_PRELOAD=liblttng-ust-fork.so ./app
2658----
2659
2660Or, if you're using a tracepoint provider shared library:
2661
2662[role="term"]
2663----
2664LD_PRELOAD="liblttng-ust-fork.so /path/to/tp.so" ./app
2665----
2666
2667
2668[[lttng-ust-pkg-config]]
2669===== Using pkg-config
2670
2671On some distributions, LTTng-UST is shipped with a pkg-config metadata
2672file, so that you may use the `pkg-config` tool:
2673
2674[role="term"]
2675----
2676pkg-config --libs lttng-ust
2677----
2678
2679This will return `-llttng-ust -ldl` on Linux systems.
2680
2681You may also check the LTTng-UST version using `pkg-config`:
2682
2683[role="term"]
2684----
2685pkg-config --modversion lttng-ust
2686----
2687
2688For more information about pkg-config, see
2689http://linux.die.net/man/1/pkg-config[its manpage].
2690
2691
2692[[tracef]]
2693===== Using `tracef()`
2694
2695`tracef()` is a small LTTng-UST API to avoid defining your own
2696tracepoints and tracepoint providers. The signature of `tracef()` is
2697the same as `printf()`'s.
2698
2699The `tracef()` utility function was developed to make user space tracing
2700super simple, albeit with notable disadvantages compared to custom,
2701full-fledged tracepoint providers:
2702
2703* All generated events have the same provider/event names, respectively
2704 `lttng_ust_tracef` and `event`.
2705* There's no static type checking.
2706* The only event field you actually get, named `msg`, is a string
2707 potentially containing the values you passed to the function
2708 using your own format. This also means that you cannot use filtering
2709 using a custom expression at runtime because there are no isolated
2710 fields.
2711* Since `tracef()` uses C standard library's `vasprintf()` function
2712 in the background to format the strings at runtime, its
2713 expected performance is lower than using custom tracepoint providers
2714 with typed fields, which do not require a conversion to a string.
2715
2716Thus, `tracef()` is useful for quick prototyping and debugging, but
2717should not be considered for any permanent/serious application
2718instrumentation.
2719
2720To use `tracef()`, first include `<lttng/tracef.h>` in the C source file
2721where you need to insert probes:
2722
2723[source,c]
2724----
2725#include <lttng/tracef.h>
2726----
2727
2728Use `tracef()` like you would use `printf()` in your source code, e.g.:
2729
2730[source,c]
2731----
2732 /* ... */
2733
2734 tracef("my message, my integer: %d", my_integer);
2735
2736 /* ... */
2737----
2738
2739Link your application with `liblttng-ust`:
2740
2741[role="term"]
2742----
2743gcc -o app app.c -llttng-ust
2744----
2745
2746Execute the application as usual:
2747
2748[role="term"]
2749----
2750./app
2751----
2752
2753Voilà! Use the `lttng` command line tool to
2754<<controlling-tracing,control tracing>>. You can enable `tracef()`
2755events like this:
2756
2757[role="term"]
2758----
2759lttng enable-event --userspace 'lttng_ust_tracef:*'
2760----
2761
2762
2763[[lttng-ust-environment-variables-compiler-flags]]
2764===== LTTng-UST environment variables and special compilation flags
2765
2766A few special environment variables and compile flags may affect the
2767behavior of LTTng-UST.
2768
2769LTTng-UST's debugging can be activated by setting the environment
2770variable `LTTNG_UST_DEBUG` to `1` when launching the application. It
2771can also be enabled at compile time by defining `LTTNG_UST_DEBUG` when
2772compiling LTTng-UST (using the `-DLTTNG_UST_DEBUG` compiler option).
2773
2774The environment variable `LTTNG_UST_REGISTER_TIMEOUT` can be used to
2775specify how long the application should wait for the
2776<<lttng-sessiond,session daemon>>'s _registration done_ command
2777before proceeding to execute the main program. The timeout value is
2778specified in milliseconds. 0 means _don't wait_. -1 means
2779_wait forever_. Setting this environment variable to 0 is recommended
2780for applications with time contraints on the process startup time.
2781
2782The default value of `LTTNG_UST_REGISTER_TIMEOUT` (when not defined)
2783is **3000{nbsp}ms**.
2784
2785The compilation definition `LTTNG_UST_DEBUG_VALGRIND` should be enabled
2786at build time (`-DLTTNG_UST_DEBUG_VALGRIND`) to allow `liblttng-ust`
2787to be used with http://valgrind.org/[Valgrind].
2788The side effect of defining `LTTNG_UST_DEBUG_VALGRIND` is that per-CPU
2789buffering is disabled.
2790
2791
2792[[cxx-application]]
2793==== $$C++$$ application
2794
2795Because of $$C++$$'s cross-compatibility with the C language, $$C++$$
2796applications can be readily instrumented with the LTTng-UST C API.
2797
2798Follow the <<c-application,C application>> user guide above. It
2799should be noted that, in this case, tracepoint providers should have
2800the typical `.cpp`, `.cxx` or `.cc` extension and be built with `g++`
2801instead of `gcc`. This is the easiest way of avoiding linking errors
2802due to symbol name mangling incompatibilities between both languages.
2803
2804
2805[[prebuilt-ust-helpers]]
2806==== Prebuilt user space tracing helpers
2807
2808The LTTng-UST package provides a few helpers that one may find
2809useful in some situations. They all work the same way: you must
2810preload the appropriate shared object before running the user
2811application (using the `LD_PRELOAD` environment variable).
2812
2813The shared objects are normally found in dir:{/usr/lib}.
2814
2815The current installed helpers are:
2816
2817path:{liblttng-ust-libc-wrapper.so} and path:{liblttng-ust-pthread-wrapper.so}::
2818 <<liblttng-ust-libc-pthread-wrapper,C{nbsp}standard library
2819 and POSIX threads tracing>>.
2820
2821path:{liblttng-ust-cyg-profile.so} and path:{liblttng-ust-cyg-profile-fast.so}::
2822 <<liblttng-ust-cyg-profile,Function tracing>>.
2823
2824path:{liblttng-ust-dl.so}::
2825 <<liblttng-ust-dl,Dynamic linker tracing>>.
2826
2827The following subsections document what helpers instrument exactly
2828and how to use them.
2829
2830
2831[[liblttng-ust-libc-pthread-wrapper]]
2832===== C standard library and POSIX threads tracing
2833
2834path:{liblttng-ust-libc-wrapper.so} and path:{liblttng-ust-pthread-wrapper.so}
2835can add instrumentation to respectively some C standard library and
2836POSIX threads functions.
2837
2838The following functions are traceable by path:{liblttng-ust-libc-wrapper.so}:
2839
2840[role="growable"]
2841.Functions instrumented by path:{liblttng-ust-libc-wrapper.so}
2842|====
2843|TP provider name |TP name |Instrumented function
2844
2845.6+|`ust_libc` |`malloc` |`malloc()`
2846 |`calloc` |`calloc()`
2847 |`realloc` |`realloc()`
2848 |`free` |`free()`
2849 |`memalign` |`memalign()`
2850 |`posix_memalign` |`posix_memalign()`
2851|====
2852
2853The following functions are traceable by
2854path:{liblttng-ust-pthread-wrapper.so}:
2855
2856[role="growable"]
2857.Functions instrumented by path:{liblttng-ust-pthread-wrapper.so}
2858|====
2859|TP provider name |TP name |Instrumented function
2860
2861.4+|`ust_pthread` |`pthread_mutex_lock_req` |`pthread_mutex_lock()` (request time)
2862 |`pthread_mutex_lock_acq` |`pthread_mutex_lock()` (acquire time)
2863 |`pthread_mutex_trylock` |`pthread_mutex_trylock()`
2864 |`pthread_mutex_unlock` |`pthread_mutex_unlock()`
2865|====
2866
2867All tracepoints have fields corresponding to the arguments of the
2868function they instrument.
2869
2870To use one or the other with any user application, independently of
2871how the latter is built, do:
2872
2873[role="term"]
2874----
2875LD_PRELOAD=liblttng-ust-libc-wrapper.so my-app
2876----
2877
2878or
2879
2880[role="term"]
2881----
2882LD_PRELOAD=liblttng-ust-pthread-wrapper.so my-app
2883----
2884
2885To use both, do:
2886
2887[role="term"]
2888----
2889LD_PRELOAD="liblttng-ust-libc-wrapper.so liblttng-ust-pthread-wrapper.so" my-app
2890----
2891
2892When the shared object is preloaded, it effectively replaces the
2893functions listed in the above tables by wrappers which add tracepoints
2894and call the replaced functions.
2895
2896Of course, like any other tracepoint, the ones above need to be enabled
2897in order for LTTng-UST to generate events. This is done using the
2898`lttng` command line tool
2899(see <<controlling-tracing,Controlling tracing>>).
2900
2901
2902[[liblttng-ust-cyg-profile]]
2903===== Function tracing
2904
2905Function tracing is the recording of which functions are entered and
2906left during the execution of an application. Like with any LTTng event,
2907the precise time at which this happens is also kept.
2908
2909GCC and clang have an option named
2910https://gcc.gnu.org/onlinedocs/gcc-4.9.1/gcc/Code-Gen-Options.html[`-finstrument-functions`]
2911which generates instrumentation calls for entry and exit to functions.
2912The LTTng-UST function tracing helpers, path:{liblttng-ust-cyg-profile.so}
2913and path:{liblttng-ust-cyg-profile-fast.so}, take advantage of this feature
2914to add instrumentation to the two generated functions (which contain
2915`cyg_profile` in their names, hence the shared object's name).
2916
2917In order to use LTTng-UST function tracing, the translation units to
2918instrument must be built using the `-finstrument-functions` compiler
2919flag.
2920
2921LTTng-UST function tracing comes in two flavors, each providing
2922different trade-offs: path:{liblttng-ust-cyg-profile-fast.so} and
2923path:{liblttng-ust-cyg-profile.so}.
2924
2925**path:{liblttng-ust-cyg-profile-fast.so}** is a lightweight variant that
2926should only be used where it can be _guaranteed_ that the complete event
2927stream is recorded without any missing events. Any kind of duplicate
2928information is left out. This version registers the following
2929tracepoints:
2930
2931[role="growable",options="header,autowidth"]
2932.Functions instrumented by path:{liblttng-ust-cyg-profile-fast.so}
2933|====
2934|TP provider name |TP name |Instrumented function
2935
2936.2+|`lttng_ust_cyg_profile_fast`
2937
2938|`func_entry`
2939a|Function entry
2940
2941`addr`::
2942 Address of called function.
2943
2944|`func_exit`
2945|Function exit
2946|====
2947
2948Assuming no event is lost, having only the function addresses on entry
2949is enough for creating a call graph (remember that a recorded event
2950always contains the ID of the CPU that generated it). A tool like
2951https://sourceware.org/binutils/docs/binutils/addr2line.html[`addr2line`]
2952may be used to convert function addresses back to source files names
2953and line numbers.
2954
2955The other helper,
2956**path:{liblttng-ust-cyg-profile.so}**,
2957is a more robust variant which also works for use cases where
2958events might get discarded or not recorded from application startup.
2959In these cases, the trace analyzer needs extra information to be
2960able to reconstruct the program flow. This version registers the
2961following tracepoints:
2962
2963[role="growable",options="header,autowidth"]
2964.Functions instrumented by path:{liblttng-ust-cyg-profile.so}
2965|====
2966|TP provider name |TP name |Instrumented function
2967
2968.2+|`lttng_ust_cyg_profile`
2969
2970|`func_entry`
2971a|Function entry
2972
2973`addr`::
2974 Address of called function.
2975
2976`call_site`::
2977 Call site address.
2978
2979|`func_exit`
2980a|Function exit
2981
2982`addr`::
2983 Address of called function.
2984
2985`call_site`::
2986 Call site address.
2987|====
2988
2989To use one or the other variant with any user application, assuming at
2990least one translation unit of the latter is compiled with the
2991`-finstrument-functions` option, do:
2992
2993[role="term"]
2994----
2995LD_PRELOAD=liblttng-ust-cyg-profile-fast.so my-app
2996----
2997
2998or
2999
3000[role="term"]
3001----
3002LD_PRELOAD=liblttng-ust-cyg-profile.so my-app
3003----
3004
3005It might be necessary to limit the number of source files where
3006`-finstrument-functions` is used to prevent excessive amount of trace
3007data to be generated at runtime.
3008
3009TIP: When using GCC, at least, you can use
3010 the `-finstrument-functions-exclude-function-list`
3011 option to avoid instrumenting entries and exits of specific
3012 symbol names.
3013
3014All events generated from LTTng-UST function tracing are provided on
3015log level `TRACE_DEBUG_FUNCTION`, which is useful to easily enable
3016function tracing events in your tracing session using the
3017`--loglevel-only` option of `lttng enable-event`
3018(see <<controlling-tracing,Controlling tracing>>).
3019
3020
3021[[liblttng-ust-dl]]
3022===== Dynamic linker tracing
3023
3024This LTTng-UST helper causes all calls to `dlopen()` and `dlclose()`
3025in the target application to be traced with LTTng.
3026
3027The helper's shared object, path:{liblttng-ust-dl.so}, registers the
3028following tracepoints when preloaded:
3029
3030[role="growable",options="header,autowidth"]
3031.Functions instrumented by path:{liblttng-ust-dl.so}
3032|====
3033|TP provider name |TP name |Instrumented function
3034
3035.2+|`ust_baddr`
3036
3037|`push`
3038a|`dlopen()` call
3039
3040`baddr`::
3041 Memory base address (where the dynamic linker placed the shared
3042 object).
3043
3044`sopath`::
3045 File system path to the loaded shared object.
3046
3047`size`::
3048 File size of the the loaded shared object.
3049
3050`mtime`::
3051 Last modification time (seconds since Epoch time) of the loaded shared
3052 object.
3053
3054|`pop`
3055a|Function exit
3056
3057`baddr`::
3058 Memory base address (where the dynamic linker placed the shared
3059 object).
3060|====
3061
3062To use this LTTng-UST helper with any user application, independently of
3063how the latter is built, do:
3064
3065[role="term"]
3066----
3067LD_PRELOAD=liblttng-ust-dl.so my-app
3068----
3069
3070Of course, like any other tracepoint, the ones above need to be enabled
3071in order for LTTng-UST to generate events. This is done using the
3072`lttng` command line tool
3073(see <<controlling-tracing,Controlling tracing>>).
3074
3075
3076[[java-application]]
3077==== Java application
3078
3079LTTng-UST provides a _logging_ back-end for Java applications using
3080http://docs.oracle.com/javase/7/docs/api/java/util/logging/Logger.html[`java.util.logging`]
3081(JUL). This back-end is called the _LTTng-UST JUL agent_ and is
3082responsible for communications with an LTTng session daemon.
3083
3084From the user's point of view, once the LTTng-UST JUL agent has been
3085initialized, JUL loggers may be created and used as usual. The agent
3086adds its own handler to the _root logger_, so that all loggers may
3087generate LTTng events with no effort.
3088
3089Common JUL features are supported using the `lttng` tool
3090(see <<controlling-tracing,Controlling tracing>>):
3091
3092* listing all logger names
3093* enabling/disabling events per logger name
3094* JUL log levels
3095
3096Here's an example:
3097
3098[source,java]
3099----
3100import java.util.logging.Logger;
3101import org.lttng.ust.jul.LTTngAgent;
3102
3103public class Test
3104{
3105 public static void main(String[] argv) throws Exception
3106 {
3107 // create a logger
3108 Logger logger = Logger.getLogger("jello");
3109
3110 // call this as soon as possible (before logging)
3111 LTTngAgent lttngAgent = LTTngAgent.getLTTngAgent();
3112
3113 // log at will!
3114 logger.info("some info");
3115 logger.warning("some warning");
3116 Thread.sleep(500);
3117 logger.finer("finer information...");
3118 Thread.sleep(123);
3119 logger.severe("error!");
3120
3121 // not mandatory, but cleaner
3122 lttngAgent.dispose();
3123 }
3124}
3125----
3126
3127The LTTng-UST JUL agent Java classes are packaged in a JAR file named
3128path:{liblttng-ust-jul.jar}. It is typically located in
3129dir:{/usr/lib/lttng/java}. To compile the snippet above
3130(saved as path:{Test.java}), do:
3131
3132[role="term"]
3133----
3134javac -cp /usr/lib/lttng/java/liblttng-ust-jul.jar Test.java
3135----
3136
3137You can run the resulting compiled class:
3138
3139[role="term"]
3140----
3141java -cp /usr/lib/lttng/java/liblttng-ust-jul.jar:. Test
3142----
3143
3144NOTE: http://openjdk.java.net/[OpenJDK] 7 is used for development and
3145continuous integration, thus this version is directly supported.
3146However, the LTTng-UST JUL agent has also been tested with OpenJDK 6.
3147
3148
3149[[instrumenting-linux-kernel]]
3150==== Linux kernel
3151
3152The Linux kernel can be instrumented for LTTng tracing, either its core
3153source code or a kernel module. It has to be noted that Linux is
3154readily traceable using LTTng since many parts of its source code are
3155already instrumented: this is the job of the upstream
3156http://git.lttng.org/?p=lttng-modules.git[LTTng-modules]
3157package. This section presents how to add LTTng instrumentation where it
3158does not currently exist and how to instrument custom kernel modules.
3159
3160All LTTng instrumentation in the Linux kernel is based on an existing
3161infrastructure which bears the name of its main macro, `TRACE_EVENT()`.
3162This macro is used to define tracepoints,
3163each tracepoint having a name, usually with the
3164+__subsys__&#95;__name__+ format,
3165+_subsys_+ being the subsystem name and
3166+_name_+ the specific event name.
3167
3168Tracepoints defined with `TRACE_EVENT()` may be inserted anywhere in
3169the Linux kernel source code, after what callbacks, called _probes_,
3170may be registered to execute some action when a tracepoint is
3171executed. This mechanism is directly used by ftrace and perf,
3172but cannot be used as is by LTTng: an adaptation layer is added to
3173satisfy LTTng's specific needs.
3174
3175With that in mind, this documentation does not cover the `TRACE_EVENT()`
3176format and how to use it, but it is mandatory to understand it and use
3177it to instrument Linux for LTTng. A series of
3178LWN articles explain
3179`TRACE_EVENT()` in details:
3180http://lwn.net/Articles/379903/[part 1],
3181http://lwn.net/Articles/381064/[part 2], and
3182http://lwn.net/Articles/383362/[part 3].
3183Once you master `TRACE_EVENT()` enough for your use case, continue
3184reading this section so that you can add the LTTng adaptation layer of
3185instrumentation.
3186
3187This section first discusses the general method of instrumenting the
3188Linux kernel for LTTng. This method is then reused for the specific
3189case of instrumenting a kernel module.
3190
3191
3192[[instrumenting-linux-kernel-itself]]
3193===== Instrumenting the Linux kernel for LTTng
3194
3195The following subsections explain strictly how to add custom LTTng
3196instrumentation to the Linux kernel. They do not explain how the
3197macros actually work and the internal mechanics of the tracer.
3198
3199You should have a Linux kernel source code tree to work with.
3200Throughout this section, all file paths are relative to the root of
3201this tree unless otherwise stated.
3202
3203You will need a copy of the LTTng-modules Git repository:
3204
3205[role="term"]
3206----
3207git clone git://git.lttng.org/lttng-modules.git
3208----
3209
3210The steps to add custom LTTng instrumentation to a Linux kernel
3211involves defining and using the mainline `TRACE_EVENT()` tracepoints
3212first, then writing and using the LTTng adaptation layer.
3213
3214
3215[[mainline-trace-event]]
3216===== Defining/using tracepoints with mainline `TRACE_EVENT()` infrastructure
3217
3218The first step is to define tracepoints using the mainline Linux
3219`TRACE_EVENT()` macro and insert tracepoints where you want them.
3220Your tracepoint definitions reside in a header file in
3221dir:{include/trace/events}. If you're adding tracepoints to an existing
3222subsystem, edit its appropriate header file.
3223
3224As an example, the following header file (let's call it
3225path:{include/trace/events/hello.h}) defines one tracepoint using
3226`TRACE_EVENT()`:
3227
3228[source,c]
3229----
3230/* subsystem name is "hello" */
3231#undef TRACE_SYSTEM
3232#define TRACE_SYSTEM hello
3233
3234#if !defined(_TRACE_HELLO_H) || defined(TRACE_HEADER_MULTI_READ)
3235#define _TRACE_HELLO_H
3236
3237#include <linux/tracepoint.h>
3238
3239TRACE_EVENT(
3240 /* "hello" is the subsystem name, "world" is the event name */
3241 hello_world,
3242
3243 /* tracepoint function prototype */
3244 TP_PROTO(int foo, const char* bar),
3245
3246 /* arguments for this tracepoint */
3247 TP_ARGS(foo, bar),
3248
3249 /* LTTng doesn't need those */
3250 TP_STRUCT__entry(),
3251 TP_fast_assign(),
3252 TP_printk("", 0)
3253);
3254
3255#endif
3256
3257/* this part must be outside protection */
3258#include <trace/define_trace.h>
3259----
3260
3261Notice that we don't use any of the last three arguments: they
3262are left empty here because LTTng doesn't need them. You would only fill
3263`TP_STRUCT__entry()`, `TP_fast_assign()` and `TP_printk()` if you were
3264to also use this tracepoint for ftrace/perf.
3265
3266Once this is done, you may place calls to `trace_hello_world()`
3267wherever you want in the Linux source code. As an example, let us place
3268such a tracepoint in the `usb_probe_device()` static function
3269(path:{drivers/usb/core/driver.c}):
3270
3271[source,c]
3272----
3273/* called from driver core with dev locked */
3274static int usb_probe_device(struct device *dev)
3275{
3276 struct usb_device_driver *udriver = to_usb_device_driver(dev->driver);
3277 struct usb_device *udev = to_usb_device(dev);
3278 int error = 0;
3279
3280 trace_hello_world(udev->devnum, udev->product);
3281
3282 /* ... */
3283}
3284----
3285
3286This tracepoint should fire every time a USB device is plugged in.
3287
3288At the top of path:{driver.c}, we need to include our actual tracepoint
3289definition and, in this case (one place per subsystem), define
3290`CREATE_TRACE_POINTS`, which will create our tracepoint:
3291
3292[source,c]
3293----
3294/* ... */
3295
3296#include "usb.h"
3297
3298#define CREATE_TRACE_POINTS
3299#include <trace/events/hello.h>
3300
3301/* ... */
3302----
3303
3304Build your custom Linux kernel. In order to use LTTng, make sure the
3305following kernel configuration options are enabled:
3306
3307* `CONFIG_MODULES` (loadable module support)
3308* `CONFIG_KALLSYMS` (load all symbols for debugging/kksymoops)
3309* `CONFIG_HIGH_RES_TIMERS` (high resolution timer support)
3310* `CONFIG_TRACEPOINTS` (kernel tracepoint instrumentation)
3311
3312Boot the custom kernel. The directory
3313dir:{/sys/kernel/debug/tracing/events/hello} should exist if everything
3314went right, with a dir:{hello_world} subdirectory.
3315
3316
3317[[lttng-adaptation-layer]]
3318===== Adding the LTTng adaptation layer
3319
3320The steps to write the LTTng adaptation layer are, in your
3321LTTng-modules copy's source code tree:
3322
3323. In dir:{instrumentation/events/lttng-module},
3324 add a header +__subsys__.h+ for your custom
3325 subsystem +__subsys__+ and write your
3326 tracepoint definitions using LTTng-modules macros in it.
3327 Those macros look like the mainline kernel equivalents,
3328 but they present subtle, yet important differences.
3329. In dir:{probes}, create the C source file of the LTTng probe kernel
3330 module for your subsystem. It should be named
3331 +lttng-probe-__subsys__.c+.
3332. Edit path:{probes/Makefile} so that the LTTng-modules project
3333 builds your custom LTTng probe kernel module.
3334. Build and install LTTng kernel modules.
3335
3336Following our `hello_world` event example, here's the content of
3337path:{instrumentation/events/lttng-module/hello.h}:
3338
3339[source,c]
3340----
3341#undef TRACE_SYSTEM
3342#define TRACE_SYSTEM hello
3343
3344#if !defined(_TRACE_HELLO_H) || defined(TRACE_HEADER_MULTI_READ)
3345#define _TRACE_HELLO_H
3346
3347#include <linux/tracepoint.h>
3348
3349LTTNG_TRACEPOINT_EVENT(
3350 /* format identical to mainline version for those */
3351 hello_world,
3352 TP_PROTO(int foo, const char* bar),
3353 TP_ARGS(foo, bar),
3354
3355 /* possible differences */
3356 TP_STRUCT__entry(
3357 __field(int, my_int)
3358 __field(char, char0)
3359 __field(char, char1)
3360 __string(product, bar)
3361 ),
3362
3363 /* notice the use of tp_assign()/tp_strcpy() and no semicolons */
3364 TP_fast_assign(
3365 tp_assign(my_int, foo)
3366 tp_assign(char0, bar[0])
3367 tp_assign(char1, bar[1])
3368 tp_strcpy(product, bar)
3369 ),
3370
3371 /* This one is actually not used by LTTng either, but must be
3372 * present for the moment.
3373 */
3374 TP_printk("", 0)
3375
3376/* no semicolon after this either */
3377)
3378
3379#endif
3380
3381/* other difference: do NOT include <trace/define_trace.h> */
3382#include "../../../probes/define_trace.h"
3383----
3384
3385Some possible entries for `TP_STRUCT__entry()` and `TP_fast_assign()`,
3386in the case of LTTng-modules, are shown in the
3387<<lttng-modules-ref,LTTng-modules reference>> section.
3388
3389The best way to learn how to use the above macros is to inspect
3390existing LTTng tracepoint definitions in
3391dir:{instrumentation/events/lttng-module} header files. Compare
3392them with the Linux kernel mainline versions in
3393dir:{include/trace/events}.
3394
3395The next step is writing the LTTng probe kernel module C source file.
3396This one is named +lttng-probe-__subsys__.c+
3397in dir:{probes}. You may always use the following template:
3398
3399[source,c]
3400----
3401#include <linux/module.h>
3402#include "../lttng-tracer.h"
3403
3404/* Build time verification of mismatch between mainline TRACE_EVENT()
3405 * arguments and LTTng adaptation layer LTTNG_TRACEPOINT_EVENT() arguments.
3406 */
3407#include <trace/events/hello.h>
3408
3409/* create LTTng tracepoint probes */
3410#define LTTNG_PACKAGE_BUILD
3411#define CREATE_TRACE_POINTS
3412#define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
3413
3414#include "../instrumentation/events/lttng-module/hello.h"
3415
3416MODULE_LICENSE("GPL and additional rights");
3417MODULE_AUTHOR("Your name <your-email>");
3418MODULE_DESCRIPTION("LTTng hello probes");
3419MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
3420 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
3421 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
3422 LTTNG_MODULES_EXTRAVERSION);
3423----
3424
3425Just replace `hello` with your subsystem name. In this example,
3426`<trace/events/hello.h>`, which is the original mainline tracepoint
3427definition header, is included for verification purposes: the
3428LTTng-modules build system is able to emit an error at build time when
3429the arguments of the mainline `TRACE_EVENT()` definitions do not match
3430the ones of the LTTng-modules adaptation layer
3431(`LTTNG_TRACEPOINT_EVENT()`).
3432
3433Edit path:{probes/Makefile} and add your new kernel module object
3434next to existing ones:
3435
3436[source,make]
3437----
3438# ...
3439
3440obj-m += lttng-probe-module.o
3441obj-m += lttng-probe-power.o
3442
3443obj-m += lttng-probe-hello.o
3444
3445# ...
3446----
3447
3448Time to build! Point to your custom Linux kernel source tree using
3449the `KERNELDIR` variable:
3450
3451[role="term"]
3452----
3453make KERNELDIR=/path/to/custom/linux
3454----
3455
3456Finally, install modules:
3457
3458[role="term"]
3459----
3460sudo make modules_install
3461----
3462
3463
3464[[instrumenting-linux-kernel-tracing]]
3465===== Tracing
3466
3467The <<controlling-tracing,Controlling tracing>> section explains
3468how to use the `lttng` tool to create and control tracing sessions.
3469Although the `lttng` tool will load the appropriate _known_ LTTng kernel
3470modules when needed (by launching `root`'s session daemon), it won't
3471load your custom `lttng-probe-hello` module by default. You need to
3472manually load the `lttng-probe-hello` module, and start an LTTng session
3473daemon as `root`:
3474
3475[role="term"]
3476----
3477sudo pkill -u root lttng-sessiond
3478sudo modprobe lttng_probe_hello
3479sudo lttng-sessiond
3480----
3481
3482The first command makes sure any existing instance is killed. If
3483you're not interested in using the default probes, or if you only
3484want to use a few of them, you can use the `--kmod-probes` option
3485of `lttng-sessiond` instead, which specifies an absolute list of
3486probes to load (without the `lttng-probe-` prefix):
3487
3488[role="term"]
3489----
3490sudo lttng-sessiond --kmod-probes=hello,ext4,net,block,signal,sched
3491----
3492
3493Confirm the custom probe module is loaded:
3494
3495[role="term"]
3496----
3497lsmod | grep lttng_probe_hello
3498----
3499
3500The `hello_world` event should appear in the list when doing
3501
3502[role="term"]
3503----
3504lttng list --kernel | grep hello
3505----
3506
3507You may now create an LTTng tracing session, enable the `hello_world`
3508kernel event (and others if you wish) and start tracing:
3509
3510[role="term"]
3511----
3512sudo lttng create my-session
3513sudo lttng enable-event --kernel hello_world
3514sudo lttng start
3515----
3516
3517Plug a few USB devices, then stop tracing and inspect the trace (if
3518http://diamon.org/babeltrace[Babeltrace]
3519is installed):
3520
3521[role="term"]
3522----
3523sudo lttng stop
3524sudo lttng view
3525----
3526
3527Here's a sample output:
3528
3529----
3530[15:30:34.835895035] (+?.?????????) hostname hello_world: { cpu_id = 1 }, { my_int = 8, char0 = 68, char1 = 97, product = "DataTraveler 2.0" }
3531[15:30:42.262781421] (+7.426886386) hostname hello_world: { cpu_id = 1 }, { my_int = 9, char0 = 80, char1 = 97, product = "Patriot Memory" }
3532[15:30:48.175621778] (+5.912840357) hostname hello_world: { cpu_id = 1 }, { my_int = 10, char0 = 68, char1 = 97, product = "DataTraveler 2.0" }
3533----
3534
3535Two USB flash drives were used for this test.
3536
3537You may change your LTTng custom probe, rebuild it and reload it at
3538any time when not tracing. Make sure you remove the old module
3539(either by killing the root LTTng session daemon which loaded the
3540module in the first place (if you used `--kmod-probes`), or by
3541using `modprobe --remove` directly) before loading the updated one.
3542
3543
3544[[instrumenting-out-of-tree-linux-kernel]]
3545===== Advanced: Instrumenting an out-of-tree Linux kernel module for LTTng
3546
3547Instrumenting a custom Linux kernel module for LTTng follows the exact
3548same steps as
3549<<instrumenting-linux-kernel-itself,adding instrumentation
3550to the Linux kernel itself>>,
3551the only difference being that your mainline tracepoint definition
3552header doesn't reside in the mainline source tree, but in your
3553kernel module source tree.
3554
3555The only reference to this mainline header is in the LTTng custom
3556probe's source code (path:{probes/lttng-probe-hello.c} in our example),
3557for build time verification:
3558
3559[source,c]
3560----
3561/* ... */
3562
3563/* Build time verification of mismatch between mainline TRACE_EVENT()
3564 * arguments and LTTng adaptation layer LTTNG_TRACEPOINT_EVENT() arguments.
3565 */
3566#include <trace/events/hello.h>
3567
3568/* ... */
3569----
3570
3571The preferred, flexible way to include your module's mainline
3572tracepoint definition header is to put it in a specific directory
3573relative to your module's root, e.g., dir:{tracepoints}, and include it
3574relative to your module's root directory in the LTTng custom probe's
3575source:
3576
3577[source,c]
3578----
3579#include <tracepoints/hello.h>
3580----
3581
3582You may then build LTTng-modules by adding your module's root
3583directory as an include path to the extra C flags:
3584
3585[role="term"]
3586----
3587make ccflags-y=-I/path/to/kernel/module KERNELDIR=/path/to/custom/linux
3588----
3589
3590Using `ccflags-y` allows you to move your kernel module to another
3591directory and rebuild the LTTng-modules project with no change to
3592source files.
3593
3594
3595[[proc-lttng-logger-abi]]
3596==== LTTng logger ABI
3597
3598The `lttng-tracer` Linux kernel module, installed by the LTTng-modules
3599package, creates a special LTTng logger ABI file path:{/proc/lttng-logger}
3600when loaded. Writing text data to this file generates an LTTng kernel
3601domain event named `lttng_logger`.
3602
3603Unlike other kernel domain events, `lttng_logger` may be enabled by
3604any user, not only root users or members of the tracing group.
3605
3606To use the LTTng logger ABI, simply write a string to
3607path:{/proc/lttng-logger}:
3608
3609[role="term"]
3610----
3611echo -n 'Hello, World!' > /proc/lttng-logger
3612----
3613
3614The `msg` field of the `lttng_logger` event contains the recorded
3615message.
3616
3617NOTE: Messages are split in chunks of 1024{nbsp}bytes.
3618
3619The LTTng logger ABI is a quick and easy way to trace some events from
3620user space through the kernel tracer. However, it is much more basic
3621than LTTng-UST: it's slower (involves system call round-trip to the
3622kernel and only supports logging strings). The LTTng logger ABI is
3623particularly useful for recording logs as LTTng traces from shell
3624scripts, potentially combining them with other Linux kernel/user space
3625events.
3626
3627
3628[[instrumenting-32-bit-app-on-64-bit-system]]
3629==== Advanced: Instrumenting a 32-bit application on a 64-bit system
3630
3631[[advanced-instrumenting-techniques]]In order to trace a 32-bit
3632application running on a 64-bit system,
3633LTTng must use a dedicated 32-bit
3634<<lttng-consumerd,consumer daemon>>. This section discusses how to
3635build that daemon (which is _not_ part of the default 64-bit LTTng
3636build) and the LTTng 32-bit tracing libraries, and how to instrument
3637a 32-bit application in that context.
3638
3639Make sure you install all 32-bit versions of LTTng dependencies.
3640Their names can be found in the path:{README.md} files of each LTTng package
3641source. How to find and install them will vary depending on your target
3642Linux distribution. `gcc-multilib` is a common package name for the
3643multilib version of GCC, which you will also need.
3644
3645The following packages will be built for 32-bit support on a 64-bit
3646system: http://urcu.so/[Userspace RCU],
3647LTTng-UST and LTTng-tools.
3648
3649
3650[[building-32-bit-userspace-rcu]]
3651===== Building 32-bit Userspace RCU
3652
3653Follow this:
3654
3655[role="term"]
3656----
3657git clone git://git.urcu.so/urcu.git
3658cd urcu
3659./bootstrap
3660./configure --libdir=/usr/lib32 CFLAGS=-m32
3661make
3662sudo make install
3663sudo ldconfig
3664----
3665
3666The `-m32` C compiler flag creates 32-bit object files and `--libdir`
3667indicates where to install the resulting libraries.
3668
3669
3670[[building-32-bit-lttng-ust]]
3671===== Building 32-bit LTTng-UST
3672
3673Follow this:
3674
3675[role="term"]
3676----
3677git clone http://git.lttng.org/lttng-ust.git
3678cd lttng-ust
3679./bootstrap
3680./configure --prefix=/usr \
3681 --libdir=/usr/lib32 \
3682 CFLAGS=-m32 CXXFLAGS=-m32 \
3683 LDFLAGS=-L/usr/lib32
3684make
3685sudo make install
3686sudo ldconfig
3687----
3688
3689`-L/usr/lib32` is required for the build to find the 32-bit versions
3690of Userspace RCU and other dependencies.
3691
3692[NOTE]
3693====
3694Depending on your Linux distribution,
369532-bit libraries could be installed at a different location than
3696dir:{/usr/lib32}. For example, Debian is known to install
3697some 32-bit libraries in dir:{/usr/lib/i386-linux-gnu}.
3698
3699In this case, make sure to set `LDFLAGS` to all the
3700relevant 32-bit library paths, e.g.,
3701`LDFLAGS="-L/usr/lib32 -L/usr/lib/i386-linux-gnu"`.
3702====
3703
3704NOTE: You may add options to path:{./configure} if you need them, e.g., for
3705Java and SystemTap support. Look at `./configure --help` for more
3706information.
3707
3708
3709[[building-32-bit-lttng-tools]]
3710===== Building 32-bit LTTng-tools
3711
3712Since the host is a 64-bit system, most 32-bit binaries and libraries of
3713LTTng-tools are not needed; the host will use their 64-bit counterparts.
3714The required step here is building and installing a 32-bit consumer
3715daemon.
3716
3717Follow this:
3718
3719[role="term"]
3720----
3721git clone http://git.lttng.org/lttng-tools.git
3722cd lttng-ust
3723./bootstrap
3724./configure --prefix=/usr \
3725 --libdir=/usr/lib32 CFLAGS=-m32 CXXFLAGS=-m32 \
3726 LDFLAGS=-L/usr/lib32
3727make
3728cd src/bin/lttng-consumerd
3729sudo make install
3730sudo ldconfig
3731----
3732
3733The above commands build all the LTTng-tools project as 32-bit
3734applications, but only installs the 32-bit consumer daemon.
3735
3736
3737[[building-64-bit-lttng-tools]]
3738===== Building 64-bit LTTng-tools
3739
3740Finally, you need to build a 64-bit version of LTTng-tools which is
3741aware of the 32-bit consumer daemon previously built and installed:
3742
3743[role="term"]
3744----
3745make clean
3746./bootstrap
3747./configure --prefix=/usr \
3748 --with-consumerd32-libdir=/usr/lib32 \
3749 --with-consumerd32-bin=/usr/lib32/lttng/libexec/lttng-consumerd
3750make
3751sudo make install
3752sudo ldconfig
3753----
3754
3755Henceforth, the 64-bit session daemon will automatically find the
375632-bit consumer daemon if required.
3757
3758
3759[[building-instrumented-32-bit-c-application]]
3760===== Building an instrumented 32-bit C application
3761
3762Let us reuse the _Hello world_ example of
3763<<tracing-your-own-user-application,Tracing your own user application>>
3764(<<getting-started,Getting started>> chapter).
3765
3766The instrumentation process is unaltered.
3767
3768First, a typical 64-bit build (assuming you're running a 64-bit system):
3769
3770[role="term"]
3771----
3772gcc -o hello64 -I. hello.c hello-tp.c -ldl -llttng-ust
3773----
3774
3775Now, a 32-bit build:
3776
3777[role="term"]
3778----
3779gcc -o hello32 -I. -m32 hello.c hello-tp.c -L/usr/lib32 \
3780 -ldl -llttng-ust -Wl,-rpath,/usr/lib32
3781----
3782
3783The `-rpath` option, passed to the linker, will make the dynamic loader
3784check for libraries in dir:{/usr/lib32} before looking in its default paths,
3785where it should find the 32-bit version of `liblttng-ust`.
3786
3787
3788[[running-32-bit-and-64-bit-c-applications]]
3789===== Running 32-bit and 64-bit versions of an instrumented C application
3790
3791Now, both 32-bit and 64-bit versions of the _Hello world_ example above
3792can be traced in the same tracing session. Use the `lttng` tool as usual
3793to create a tracing session and start tracing:
3794
3795[role="term"]
3796----
3797lttng create session-3264
3798lttng enable-event -u -a
3799./hello32
3800./hello64
3801lttng stop
3802----
3803
3804Use `lttng view` to verify both processes were
3805successfully traced.
3806
3807
3808[[controlling-tracing]]
3809=== Controlling tracing
3810
3811Once you're in possession of a software that is properly
3812<<instrumenting,instrumented>> for LTTng tracing, be it thanks to
3813the built-in LTTng probes for the Linux kernel, a custom user
3814application or a custom Linux kernel, all that is left is actually
3815tracing it. As a user, you control LTTng tracing using a single command
3816line interface: the `lttng` tool. This tool uses `liblttng-ctl` behind
3817the scene to connect to and communicate with session daemons. LTTng
3818session daemons may either be started manually (`lttng-sessiond`) or
3819automatically by the `lttng` command when needed. Trace data may
3820be forwarded to the network and used elsewhere using an LTTng relay
3821daemon (`lttng-relayd`).
3822
3823The manpages of `lttng`, `lttng-sessiond` and `lttng-relayd` are pretty
3824complete, thus this section is not an online copy of the latter (we
3825leave this contents for the
3826<<online-lttng-manpages,Online LTTng manpages>> section).
3827This section is rather a tour of LTTng
3828features through practical examples and tips.
3829
3830If not already done, make sure you understand the core concepts
3831and how LTTng components connect together by reading the
3832<<understanding-lttng,Understanding LTTng>> chapter; this section
3833assumes you are familiar with them.
3834
3835
3836[[creating-destroying-tracing-sessions]]
3837==== Creating and destroying tracing sessions
3838
3839Whatever you want to do with `lttng`, it has to happen inside a
3840**tracing session**, created beforehand. A session, in general, is a
3841per-user container of state. A tracing session is no different; it
3842keeps a specific state of stuff like:
3843
3844* session name
3845* enabled/disabled channels with associated parameters
3846* enabled/disabled events with associated log levels and filters
3847* context information added to channels
3848* tracing activity (started or stopped)
3849
3850and more.
3851
3852A single user may have many active tracing sessions. LTTng session
3853daemons are the ultimate owners and managers of tracing sessions. For
3854user space tracing, each user has its own session daemon. Since Linux
3855kernel tracing requires root privileges, only `root`'s session daemon
3856may enable and trace kernel events. However, `lttng` has a `--group`
3857option (which is passed to `lttng-sessiond` when starting it) to
3858specify the name of a _tracing group_ which selected users may be part
3859of to be allowed to communicate with `root`'s session daemon. By
3860default, the tracing group name is `tracing`.
3861
3862To create a tracing session, do:
3863
3864[role="term"]
3865----
3866lttng create my-session
3867----
3868
3869This will create a new tracing session named `my-session` and make it
3870the current one. If you don't specify any name (calling only
3871`lttng create`), your tracing session will be named `auto`. Traces
3872are written in +\~/lttng-traces/__session__-+ followed
3873by the tracing session's creation date/time by default, where
3874+__session__+ is the tracing session name. To save them
3875at a different location, use the `--output` option:
3876
3877[role="term"]
3878----
3879lttng create --output /tmp/some-directory my-session
3880----
3881
3882You may create as many tracing sessions as you wish:
3883
3884[role="term"]
3885----
3886lttng create other-session
3887lttng create yet-another-session
3888----
3889
3890You may view all existing tracing sessions using the `list` command:
3891
3892[role="term"]
3893----
3894lttng list
3895----
3896
3897The state of a _current tracing session_ is kept in path:{~/.lttngrc}. Each
3898invocation of `lttng` reads this file to set its current tracing
3899session name so that you don't have to specify a session name for each
3900command. You could edit this file manually, but the preferred way to
3901set the current tracing session is to use the `set-session` command:
3902
3903[role="term"]
3904----
3905lttng set-session other-session
3906----
3907
3908Most `lttng` commands accept a `--session` option to specify the name
3909of the target tracing session.
3910
3911Any existing tracing session may be destroyed using the `destroy`
3912command:
3913
3914[role="term"]
3915----
3916lttng destroy my-session
3917----
3918
3919Providing no argument to `lttng destroy` will destroy the current
3920tracing session. Destroying a tracing session will stop any tracing
3921running within the latter. Destroying a tracing session frees resources
3922acquired by the session daemon and tracer side, making sure to flush
3923all trace data.
3924
3925You can't do much with LTTng using only the `create`, `set-session`
3926and `destroy` commands of `lttng`, but it is essential to know them in
3927order to control LTTng tracing, which always happen within the scope of
3928a tracing session.
3929
3930
3931[[enabling-disabling-events]]
3932==== Enabling and disabling events
3933
3934Inside a tracing session, individual events may be enabled or disabled
3935so that tracing them may or may not generate trace data.
3936
3937We sometimes use the term _event_ metonymically throughout this text to
3938refer to a specific condition, or _rule_, that could lead, when
3939satisfied, to an actual occurring event (a point at a specific position
3940in source code/binary program, logical processor and time capturing
3941some payload) being recorded as trace data. This specific condition is
3942composed of:
3943
3944. A **domain** (kernel, user space or `java.util.logging`) (required).
3945. One or many **instrumentation points** in source code or binary
3946 program (tracepoint name, address, symbol name, function name,
3947 logger name, etc.) to be executed (required).
3948. A **log level** (each instrumentation point declares its own log
3949 level) or log level range to match (optional; only valid for user
3950 space domain).
3951. A **custom user expression**, or **filter**, that must evaluate to
3952 _true_ when a tracepoint is executed (optional; only valid for user
3953 space domain).
3954
3955All conditions are specified using arguments passed to the
3956`enable-event` command of the `lttng` tool.
3957
3958Condition 1 is specified using either `--kernel/-k` (kernel),
3959`--userspace/-u` (user space) or `--jul/-j`
3960(JUL). Exactly one of those
3961three arguments must be specified.
3962
3963Condition 2 is specified using one of:
3964
3965`--tracepoint`::
3966 Tracepoint.
3967
3968`--probe`::
3969 Dynamic probe (address, symbol name or combination
3970 of both in binary program; only valid for kernel domain).
3971
3972`--function`::
3973 function entry/exit (address, symbol name or
3974 combination of both in binary program; only valid for kernel domain).
3975
3976`--syscall`::
3977 System call entry/exit (only valid for kernel domain).
3978
3979When none of the above is specified, `enable-event` defaults to
3980using `--tracepoint`.
3981
3982Condition 3 is specified using one of:
3983
3984`--loglevel`::
3985 Log level range from the specified level to the most severe
3986 level.
3987
3988`--loglevel-only`::
3989 Specific log level.
3990
3991See `lttng enable-event --help` for the complete list of log level
3992names.
3993
3994Condition 4 is specified using the `--filter` option. This filter is
3995a C-like expression, potentially reading real-time values of event
3996fields, that has to evaluate to _true_ for the condition to be satisfied.
3997Event fields are read using plain identifiers while context fields
3998must be prefixed with `$ctx.`. See `lttng enable-event --help` for
3999all usage details.
4000
4001The aforementioned arguments are combined to create and enable events.
4002Each unique combination of arguments leads to a different
4003_enabled event_. The log level and filter arguments are optional, their
4004default values being respectively all log levels and a filter which
4005always returns _true_.
4006
4007Here are a few examples (you must
4008<<creating-destroying-tracing-sessions,create a tracing session>>
4009first):
4010
4011[role="term"]
4012----
4013lttng enable-event -u --tracepoint my_app:hello_world
4014lttng enable-event -u --tracepoint my_app:hello_you --loglevel TRACE_WARNING
4015lttng enable-event -u --tracepoint 'my_other_app:*'
4016lttng enable-event -u --tracepoint my_app:foo_bar \
4017 --filter 'some_field <= 23 && !other_field'
4018lttng enable-event -k --tracepoint sched_switch
4019lttng enable-event -k --tracepoint gpio_value
4020lttng enable-event -k --function usb_probe_device usb_probe_device
4021lttng enable-event -k --syscall --all
4022----
4023
4024The wildcard symbol, `*`, matches _anything_ and may only be used at
4025the end of the string when specifying a _tracepoint_. Make sure to
4026use it between single quotes in your favorite shell to avoid
4027undesired shell expansion.
4028
4029You can see a list of events (enabled or disabled) using
4030
4031[role="term"]
4032----
4033lttng list some-session
4034----
4035
4036where `some-session` is the name of the desired tracing session.
4037
4038What you're actually doing when enabling events with specific conditions
4039is creating a **whitelist** of traceable events for a given channel.
4040Thus, the following case presents redundancy:
4041
4042[role="term"]
4043----
4044lttng enable-event -u --tracepoint my_app:hello_you
4045lttng enable-event -u --tracepoint my_app:hello_you --loglevel TRACE_DEBUG
4046----
4047
4048The second command, matching a log level range, is useless since the first
4049command enables all tracepoints matching the same name,
4050`my_app:hello_you`.
4051
4052Disabling an event is simpler: you only need to provide the event
4053name to the `disable-event` command:
4054
4055[role="term"]
4056----
4057lttng disable-event --userspace my_app:hello_you
4058----
4059
4060This name has to match a name previously given to `enable-event` (it
4061has to be listed in the output of `lttng list some-session`).
4062The `*` wildcard is supported, as long as you also used it in a
4063previous `enable-event` invocation.
4064
4065Disabling an event does not add it to some blacklist: it simply removes
4066it from its channel's whitelist. This is why you cannot disable an event
4067which wasn't previously enabled.
4068
4069A disabled event will not generate any trace data, even if all its
4070specified conditions are met.
4071
4072Events may be enabled and disabled at will, either when LTTng tracers
4073are active or not. Events may be enabled before a user space application
4074is even started.
4075
4076
4077[[basic-tracing-session-control]]
4078==== Basic tracing session control
4079
4080Once you have
4081<<creating-destroying-tracing-sessions,created a tracing session>>
4082and <<enabling-disabling-events,enabled one or more events>>,
4083you may activate the LTTng tracers for the current tracing session at
4084any time:
4085
4086[role="term"]
4087----
4088lttng start
4089----
4090
4091Subsequently, you may stop the tracers:
4092
4093[role="term"]
4094----
4095lttng stop
4096----
4097
4098LTTng is very flexible: user space applications may be launched before
4099or after the tracers are started. Events will only be recorded if they
4100are properly enabled and if they occur while tracers are started.
4101
4102A tracing session name may be passed to both the `start` and `stop`
4103commands to start/stop tracing a session other than the current one.
4104
4105
4106[[enabling-disabling-channels]]
4107==== Enabling and disabling channels
4108
4109<<event,As mentioned>> in the
4110<<understanding-lttng,Understanding LTTng>> chapter, enabled
4111events are contained in a specific channel, itself contained in a
4112specific tracing session. A channel is a group of events with
4113tunable parameters (event loss mode, sub-buffer size, number of
4114sub-buffers, trace file sizes and count, etc.). A given channel may
4115only be responsible for enabled events belonging to one domain: either
4116kernel or user space.
4117
4118If you only used the `create`, `enable-event` and `start`/`stop`
4119commands of the `lttng` tool so far, one or two channels were
4120automatically created for you (one for the kernel domain and/or one
4121for the user space domain). The default channels are both named
4122`channel0`; channels from different domains may have the same name.
4123
4124The current channels of a given tracing session can be viewed with
4125
4126[role="term"]
4127----
4128lttng list some-session
4129----
4130
4131where `some-session` is the name of the desired tracing session.
4132
4133To create and enable a channel, use the `enable-channel` command:
4134
4135[role="term"]
4136----
4137lttng enable-channel --kernel my-channel
4138----
4139
4140This will create a kernel domain channel named `my-channel` with
4141default parameters in the current tracing session.
4142
4143[NOTE]
4144====
4145Because of a current limitation, all
4146channels must be _created_ prior to beginning tracing in a
4147given tracing session, i.e. before the first time you do
4148`lttng start`.
4149
4150Since a channel is automatically created by
4151`enable-event` only for the specified domain, you cannot,
4152for example, enable a kernel domain event, start tracing and then
4153enable a user space domain event because no user space channel
4154exists yet and it's too late to create one.
4155
4156For this reason, make sure to configure your channels properly
4157before starting the tracers for the first time!
4158====
4159
4160Here's another example:
4161
4162[role="term"]
4163----
4164lttng enable-channel --userspace --session other-session --overwrite \
4165 --tracefile-size 1048576 1mib-channel
4166----
4167
4168This will create a user space domain channel named `1mib-channel` in
4169the tracing session named `other-session` that loses new events by
4170overwriting previously recorded events (instead of the default mode of
4171discarding newer ones) and saves trace files with a maximum size of
41721{nbsp}MiB each.
4173
4174Note that channels may also be created using the `--channel` option of
4175the `enable-event` command when the provided channel name doesn't exist
4176for the specified domain:
4177
4178[role="term"]
4179----
4180lttng enable-event --kernel --channel some-channel sched_switch
4181----
4182
4183If no kernel domain channel named `some-channel` existed before calling
4184the above command, it would be created with default parameters.
4185
4186You may enable the same event in two different channels:
4187
4188[role="term"]
4189----
4190lttng enable-event --userspace --channel my-channel app:tp
4191lttng enable-event --userspace --channel other-channel app:tp
4192----
4193
4194If both channels are enabled, the occurring `app:tp` event will
4195generate two recorded events, one for each channel.
4196
4197Disabling a channel is done with the `disable-event` command:
4198
4199[role="term"]
4200----
4201lttng disable-event --kernel some-channel
4202----
4203
4204The state of a channel precedes the individual states of events within
4205it: events belonging to a disabled channel, even if they are
4206enabled, won't be recorded.
4207
4208
4209
4210[[fine-tuning-channels]]
4211===== Fine-tuning channels
4212
4213There are various parameters that may be fine-tuned with the
4214`enable-channel` command. The latter are well documented in
4215man:lttng(1) and in the <<channel,Channel>> section of the
4216<<understanding-lttng,Understanding LTTng>> chapter. For basic
4217tracing needs, their default values should be just fine, but here are a
4218few examples to break the ice.
4219
4220As the frequency of recorded events increases--either because the
4221event throughput is actually higher or because you enabled more events
4222than usual&#8212;__event loss__ might be experienced. Since LTTng never
4223waits, by design, for sub-buffer space availability (non-blocking
4224tracer), when a sub-buffer is full and no empty sub-buffers are left,
4225there are two possible outcomes: either the new events that do not fit
4226are rejected, or they start replacing the oldest recorded events.
4227The choice of which algorithm to use is a per-channel parameter, the
4228default being discarding the newest events until there is some space
4229left. If your situation always needs the latest events at the expense
4230of writing over the oldest ones, create a channel with the `--overwrite`
4231option:
4232
4233[role="term"]
4234----
4235lttng enable-channel --kernel --overwrite my-channel
4236----
4237
4238When an event is lost, it means no space was available in any
4239sub-buffer to accommodate it. Thus, if you want to cope with sporadic
4240high event throughput situations and avoid losing events, you need to
4241allocate more room for storing them in memory. This can be done by
4242either increasing the size of sub-buffers or by adding sub-buffers.
4243The following example creates a user space domain channel with
424416{nbsp}sub-buffers of 512{nbsp}kiB each:
4245
4246[role="term"]
4247----
4248lttng enable-channel --userspace --num-subbuf 16 --subbuf-size 512k big-channel
4249----
4250
4251Both values need to be powers of two, otherwise they are rounded up
4252to the next one.
4253
4254Two other interesting available parameters of `enable-channel` are
4255`--tracefile-size` and `--tracefile-count`, which respectively limit
4256the size of each trace file and the their count for a given channel.
4257When the number of written trace files reaches its limit for a given
4258channel-CPU pair, the next trace file will overwrite the very first
4259one. The following example creates a kernel domain channel with a
4260maximum of three trace files of 1{nbsp}MiB each:
4261
4262[role="term"]
4263----
4264lttng enable-channel --kernel --tracefile-size 1M --tracefile-count 3 my-channel
4265----
4266
4267An efficient way to make sure lots of events are generated is enabling
4268all kernel events in this channel and starting the tracer:
4269
4270[role="term"]
4271----
4272lttng enable-event --kernel --all --channel my-channel
4273lttng start
4274----
4275
4276After a few seconds, look at trace files in your tracing session
4277output directory. For two CPUs, it should look like:
4278
4279----
4280my-channel_0_0 my-channel_1_0
4281my-channel_0_1 my-channel_1_1
4282my-channel_0_2 my-channel_1_2
4283----
4284
4285Amongst the files above, you might see one in each group with a size
4286lower than 1{nbsp}MiB: they are the files currently being written.
4287
4288Since all those small files are valid LTTng trace files, LTTng trace
4289viewers may read them. It is the viewer's responsibility to properly
4290merge the streams so as to present an ordered list to the user.
4291http://diamon.org/babeltrace[Babeltrace]
4292merges LTTng trace files correctly and is fast at doing it.
4293
4294
4295[[adding-context]]
4296==== Adding some context to channels
4297
4298If you read all the sections of
4299<<controlling-tracing,Controlling tracing>> so far, you should be
4300able to create tracing sessions, create and enable channels and events
4301within them and start/stop the LTTng tracers. Event fields recorded in
4302trace files provide important information about occurring events, but
4303sometimes external context may help you solve a problem faster. This
4304section discusses how to add context information to events of a
4305specific channel using the `lttng` tool.
4306
4307There are various available context values which can accompany events
4308recorded by LTTng, for example:
4309
4310* **process information**:
4311** identifier (PID)
4312** name
4313** priority
4314** scheduling priority (niceness)
4315** thread identifier (TID)
4316* the **hostname** of the system on which the event occurred
4317* plenty of **performance counters** using perf:
4318** CPU cycles, stalled cycles, idle cycles, etc.
4319** cache misses
4320** branch instructions, misses, loads, etc.
4321** CPU faults
4322** etc.
4323
4324The full list is available in the output of `lttng add-context --help`.
4325Some of them are reserved for a specific domain (kernel or
4326user space) while others are available for both.
4327
4328To add context information to one or all channels of a given tracing
4329session, use the `add-context` command:
4330
4331[role="term"]
4332----
4333lttng add-context --userspace --type vpid --type perf:thread:cpu-cycles
4334----
4335
4336The above example adds the virtual process identifier and per-thread
4337CPU cycles count values to all recorded user space domain events of the
4338current tracing session. Use the `--channel` option to select a specific
4339channel:
4340
4341[role="term"]
4342----
4343lttng add-context --kernel --channel my-channel --type tid
4344----
4345
4346adds the thread identifier value to all recorded kernel domain events
4347in the channel `my-channel` of the current tracing session.
4348
4349Beware that context information cannot be removed from channels once
4350it's added for a given tracing session.
4351
4352
4353[[saving-loading-tracing-session]]
4354==== Saving and loading tracing session configurations
4355
4356Configuring a tracing session may be long: creating and enabling
4357channels with specific parameters, enabling kernel and user space
4358domain events with specific log levels and filters, adding context
4359to some channels, etc. If you're going to use LTTng to solve real
4360world problems, chances are you're going to have to record events using
4361the same tracing session setup over and over, modifying a few variables
4362each time in your instrumented program or environment. To avoid
4363constant tracing session reconfiguration, the `lttng` tool is able to
4364save and load tracing session configurations to/from XML files.
4365
4366To save a given tracing session configuration, do:
4367
4368[role="term"]
4369----
4370lttng save my-session
4371----
4372
4373where `my-session` is the name of the tracing session to save. Tracing
4374session configurations are saved to dir:{~/.lttng/sessions} by default;
4375use the `--output-path` option to change this destination directory.
4376
4377All configuration parameters are saved:
4378
4379* tracing session name
4380* trace data output path
4381* channels with their state and all their parameters
4382* context information added to channels
4383* events with their state, log level and filter
4384* tracing activity (started or stopped)
4385
4386To load a tracing session, simply do:
4387
4388[role="term"]
4389----
4390lttng load my-session
4391----
4392
4393or, if you used a custom path:
4394
4395[role="term"]
4396----
4397lttng load --input-path /path/to/my-session.lttng
4398----
4399
4400Your saved tracing session will be restored as if you just configured
4401it manually.
4402
4403
4404[[sending-trace-data-over-the-network]]
4405==== Sending trace data over the network
4406
4407The possibility of sending trace data over the network comes as a
4408built-in feature of LTTng-tools. For this to be possible, an LTTng
4409_relay daemon_ must be executed and listening on the machine where
4410trace data is to be received, and the user must create a tracing
4411session using appropriate options to forward trace data to the remote
4412relay daemon.
4413
4414The relay daemon listens on two different TCP ports: one for control
4415information and the other for actual trace data.
4416
4417Starting the relay daemon on the remote machine is as easy as:
4418
4419[role="term"]
4420----
4421lttng-relayd
4422----
4423
4424This will make it listen to its default ports: 5342 for control and
44255343 for trace data. The `--control-port` and `--data-port` options may
4426be used to specify different ports.
4427
4428Traces written by `lttng-relayd` are written to
4429+\~/lttng-traces/__hostname__/__session__+ by
4430default, where +__hostname__+ is the host name of the
4431traced (monitored) system and +__session__+ is the
4432tracing session name. Use the `--output` option to write trace data
4433outside dir:{~/lttng-traces}.
4434
4435On the sending side, a tracing session must be created using the
4436`lttng` tool with the `--set-url` option to connect to the distant
4437relay daemon:
4438
4439[role="term"]
4440----
4441lttng create my-session --set-url net://distant-host
4442----
4443
4444The URL format is described in the output of `lttng create --help`.
4445The above example will use the default ports; the `--ctrl-url` and
4446`--data-url` options may be used to set the control and data URLs
4447individually.
4448
4449Once this basic setup is completed and the connection is established,
4450you may use the `lttng` tool on the target machine as usual; everything
4451you do will be transparently forwarded to the remote machine if needed.
4452For example, a parameter changing the maximum size of trace files will
4453have an effect on the distant relay daemon actually writing the trace.
4454
4455
4456[[lttng-live]]
4457==== Viewing events as they arrive
4458
4459We have seen how trace files may be produced by LTTng out of generated
4460application and Linux kernel events. We have seen that those trace files
4461may be either recorded locally by consumer daemons or remotely using
4462a relay daemon. And we have seen that the maximum size and count of
4463trace files is configurable for each channel. With all those features,
4464it's still not possible to read a trace file as it is being written
4465because it could be incomplete and appear corrupted to the viewer.
4466There is a way to view events as they arrive, however: using
4467_LTTng live_.
4468
4469LTTng live is implemented, in LTTng, solely on the relay daemon side.
4470As trace data is sent over the network to a relay daemon by a (possibly
4471remote) consumer daemon, a _tee_ may be created: trace data will be
4472recorded to trace files _as well as_ being transmitted to a
4473connected live viewer:
4474
4475[role="img-90"]
4476.LTTng live and the relay daemon.
4477image::lttng-live-relayd.png[]
4478
4479In order to use this feature, a tracing session must created in live
4480mode on the target system:
4481
4482[role="term"]
4483----
4484lttng create --live
4485----
4486
4487An optional parameter may be passed to `--live` to set the interval
4488of time (in microseconds) between flushes to the network
4489(1{nbsp}second is the default):
4490
4491[role="term"]
4492----
4493lttng create --live 100000
4494----
4495
4496will flush every 100{nbsp}ms.
4497
4498If no network output is specified to the `create` command, a local
4499relay daemon will be spawned. In this very common case, viewing a live
4500trace is easy: enable events and start tracing as usual, then use
4501`lttng view` to start the default live viewer:
4502
4503[role="term"]
4504----
4505lttng view
4506----
4507
4508The correct arguments will be passed to the live viewer so that it
4509may connect to the local relay daemon and start reading live events.
4510
4511You may also wish to use a live viewer not running on the target
4512system. In this case, you should specify a network output when using
4513the `create` command (`--set-url` or `--ctrl-url`/`--data-url` options).
4514A distant LTTng relay daemon should also be started to receive control
4515and trace data. By default, `lttng-relayd` listens on 127.0.0.1:5344
4516for an LTTng live connection. Otherwise, the desired URL may be
4517specified using its `--live-port` option.
4518
4519The
4520http://diamon.org/babeltrace[`babeltrace`]
4521viewer supports LTTng live as one of its input formats. `babeltrace` is
4522the default viewer when using `lttng view`. To use it manually, first
4523list active tracing sessions by doing the following (assuming the relay
4524daemon to connect to runs on the same host):
4525
4526[role="term"]
4527----
4528babeltrace --input-format lttng-live net://localhost
4529----
4530
4531Then, choose a tracing session and start viewing events as they arrive
4532using LTTng live, e.g.:
4533
4534[role="term"]
4535----
4536babeltrace --input-format lttng-live net://localhost/host/hostname/my-session
4537----
4538
4539
4540[[taking-a-snapshot]]
4541==== Taking a snapshot
4542
4543The normal behavior of LTTng is to record trace data as trace files.
4544This is ideal for keeping a long history of events that occurred on
4545the target system and applications, but may be too much data in some
4546situations. For example, you may wish to trace your application
4547continuously until some critical situation happens, in which case you
4548would only need the latest few recorded events to perform the desired
4549analysis, not multi-gigabyte trace files.
4550
4551LTTng has an interesting feature called _snapshots_. When creating
4552a tracing session in snapshot mode, no trace files are written; the
4553tracers' sub-buffers are constantly overwriting the oldest recorded
4554events with the newest. At any time, either when the tracers are started
4555or stopped, you may take a snapshot of those sub-buffers.
4556
4557There is no difference between the format of a normal trace file and the
4558format of a snapshot: viewers of LTTng traces will also support LTTng
4559snapshots. By default, snapshots are written to disk, but they may also
4560be sent over the network.
4561
4562To create a tracing session in snapshot mode, do:
4563
4564[role="term"]
4565----
4566lttng create --snapshot my-snapshot-session
4567----
4568
4569Next, enable channels, events and add context to channels as usual.
4570Once a tracing session is created in snapshot mode, channels will be
4571forced to use the
4572<<channel-overwrite-mode-vs-discard-mode,overwrite>> mode
4573(`--overwrite` option of the `enable-channel` command; also called
4574_flight recorder mode_) and have an `mmap()` channel type
4575(`--output mmap`).
4576
4577Start tracing. When you're ready to take a snapshot, do:
4578
4579[role="term"]
4580----
4581lttng snapshot record --name my-snapshot
4582----
4583
4584This will record a snapshot named `my-snapshot` of all channels of
4585all domains of the current tracing session. By default, snapshots files
4586are recorded in the path returned by `lttng snapshot list-output`. You
4587may change this path or decide to send snapshots over the network
4588using either:
4589
4590. an output path/URL specified when creating the tracing session
4591 (`lttng create`)
4592. an added snapshot output path/URL using
4593 `lttng snapshot add-output`
4594. an output path/URL provided directly to the
4595 `lttng snapshot record` command
4596
4597Method 3 overrides method 2 which overrides method 1. When specifying
4598a URL, a relay daemon must be listening on some machine (see
4599<<sending-trace-data-over-the-network,Sending trace data over the network>>).
4600
4601If you need to make absolutely sure that the output file won't be
4602larger than a certain limit, you can set a maximum snapshot size when
4603taking it with the `--max-size` option:
4604
4605[role="term"]
4606----
4607lttng snapshot record --name my-snapshot --max-size 2M
4608----
4609
4610Older recorded events will be discarded in order to respect this
4611maximum size.
4612
4613
4614[[reference]]
4615== Reference
4616
4617This chapter presents various references for LTTng packages such as links
4618to online manpages, tables needed by the rest of the text, descriptions
4619of library functions, etc.
4620
4621
4622[[online-lttng-manpages]]
4623=== Online LTTng manpages
4624
4625LTTng packages currently install the following manpages, available
4626online using the links below:
4627
4628* **LTTng-tools**
4629** man:lttng(1)
4630** man:lttng-sessiond(8)
4631** man:lttng-relayd(8)
4632* **LTTng-UST**
4633** man:lttng-gen-tp(1)
4634** man:lttng-ust(3)
4635** man:lttng-ust-cyg-profile(3)
4636** man:lttng-ust-dl(3)
4637
4638
4639[[lttng-ust-ref]]
4640=== LTTng-UST
4641
4642This section presents references of the LTTng-UST package.
4643
4644
4645[[liblttng-ust]]
4646==== LTTng-UST library (+liblttng&#8209;ust+)
4647
4648The LTTng-UST library, or `liblttng-ust`, is the main shared object
4649against which user applications are linked to make LTTng user space
4650tracing possible.
4651
4652The <<c-application,C application>> guide shows the complete
4653process to instrument, build and run a C/$$C++$$ application using
4654LTTng-UST, while this section contains a few important tables.
4655
4656
4657[[liblttng-ust-tp-fields]]
4658===== Tracepoint fields macros (for `TP_FIELDS()`)
4659
4660The available macros to define tracepoint fields, which should be listed
4661within `TP_FIELDS()` in `TRACEPOINT_EVENT()`, are:
4662
4663[role="growable func-desc",cols="asciidoc,asciidoc"]
4664.Available macros to define LTTng-UST tracepoint fields
4665|====
4666|Macro |Description and parameters
4667
4668|
4669+ctf_integer(__t__, __n__, __e__)+
4670
4671+ctf_integer_nowrite(__t__, __n__, __e__)+
4672|
4673Standard integer, displayed in base 10.
4674
4675+__t__+::
4676 Integer C type (`int`, `long`, `size_t`, etc.).
4677
4678+__n__+::
4679 Field name.
4680
4681+__e__+::
4682 Argument expression.
4683
4684|+ctf_integer_hex(__t__, __n__, __e__)+
4685|
4686Standard integer, displayed in base 16.
4687
4688+__t__+::
4689 Integer C type.
4690
4691+__n__+::
4692 Field name.
4693
4694+__e__+::
4695 Argument expression.
4696
4697|+ctf_integer_network(__t__, __n__, __e__)+
4698|
4699Integer in network byte order (big endian), displayed in base 10.
4700
4701+__t__+::
4702 Integer C type.
4703
4704+__n__+::
4705 Field name.
4706
4707+__e__+::
4708 Argument expression.
4709
4710|+ctf_integer_network_hex(__t__, __n__, __e__)+
4711|
4712Integer in network byte order, displayed in base 16.
4713
4714+__t__+::
4715 Integer C type.
4716
4717+__n__+::
4718 Field name.
4719
4720+__e__+::
4721 Argument expression.
4722
4723|
4724+ctf_float(__t__, __n__, __e__)+
4725
4726+ctf_float_nowrite(__t__, __n__, __e__)+
4727|
4728Floating point number.
4729
4730+__t__+::
4731 Floating point number C type (`float` or `double`).
4732
4733+__n__+::
4734 Field name.
4735
4736+__e__+::
4737 Argument expression.
4738
4739|
4740+ctf_string(__n__, __e__)+
4741
4742+ctf_string_nowrite(__n__, __e__)+
4743|
4744Null-terminated string; undefined behavior if +__e__+ is `NULL`.
4745
4746+__n__+::
4747 Field name.
4748
4749+__e__+::
4750 Argument expression.
4751
4752|
4753+ctf_array(__t__, __n__, __e__, __s__)+
4754
4755+ctf_array_nowrite(__t__, __n__, __e__, __s__)+
4756|
4757Statically-sized array of integers
4758
4759+__t__+::
4760 Array element C type.
4761
4762+__n__+::
4763 Field name.
4764
4765+__e__+::
4766 Argument expression.
4767
4768+__s__+::
4769 Number of elements.
4770
4771|
4772+ctf_array_text(__t__, __n__, __e__, __s__)+
4773
4774+ctf_array_text_nowrite(__t__, __n__, __e__, __s__)+
4775|
4776Statically-sized array, printed as text.
4777
4778The string does not need to be null-terminated.
4779
4780+__t__+::
4781 Array element C type (always `char`).
4782
4783+__n__+::
4784 Field name.
4785
4786+__e__+::
4787 Argument expression.
4788
4789+__s__+::
4790 Number of elements.
4791
4792|
4793+ctf_sequence(__t__, __n__, __e__, __T__, __E__)+
4794
4795+ctf_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+
4796|
4797Dynamically-sized array of integers.
4798
4799The type of +__E__+ needs to be unsigned.
4800
4801+__t__+::
4802 Array element C type.
4803
4804+__n__+::
4805 Field name.
4806
4807+__e__+::
4808 Argument expression.
4809
4810+__T__+::
4811 Length expression C type.
4812
4813+__E__+::
4814 Length expression.
4815
4816|
4817+ctf_sequence_text(__t__, __n__, __e__, __T__, __E__)+
4818
4819+ctf_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+
4820|
4821Dynamically-sized array, displayed as text.
4822
4823The string does not need to be null-terminated.
4824
4825The type of +__E__+ needs to be unsigned.
4826
4827The behaviour is undefined if +__e__+ is `NULL`.
4828
4829+__t__+::
4830 Sequence element C type (always `char`).
4831
4832+__n__+::
4833 Field name.
4834
4835+__e__+::
4836 Argument expression.
4837
4838+__T__+::
4839 Length expression C type.
4840
4841+__E__+::
4842 Length expression.
4843|====
4844
4845The `_nowrite` versions omit themselves from the session trace, but are
4846otherwise identical. This means the `_nowrite` fields won't be written
4847in the recorded trace. Their primary purpose is to make some
4848of the event context available to the
4849<<enabling-disabling-events,event filters>> without having to
4850commit the data to sub-buffers.
4851
4852
4853[[liblttng-ust-tracepoint-loglevel]]
4854===== Tracepoint log levels (for `TRACEPOINT_LOGLEVEL()`)
4855
4856The following table shows the available log level values for the
4857`TRACEPOINT_LOGLEVEL()` macro:
4858
4859`TRACE_EMERG`::
4860 System is unusable.
4861
4862`TRACE_ALERT`::
4863 Action must be taken immediately.
4864
4865`TRACE_CRIT`::
4866 Critical conditions.
4867
4868`TRACE_ERR`::
4869 Error conditions.
4870
4871`TRACE_WARNING`::
4872 Warning conditions.
4873
4874`TRACE_NOTICE`::
4875 Normal, but significant, condition.
4876
4877`TRACE_INFO`::
4878 Informational message.
4879
4880`TRACE_DEBUG_SYSTEM`::
4881 Debug information with system-level scope (set of programs).
4882
4883`TRACE_DEBUG_PROGRAM`::
4884 Debug information with program-level scope (set of processes).
4885
4886`TRACE_DEBUG_PROCESS`::
4887 Debug information with process-level scope (set of modules).
4888
4889`TRACE_DEBUG_MODULE`::
4890 Debug information with module (executable/library) scope (set of units).
4891
4892`TRACE_DEBUG_UNIT`::
4893 Debug information with compilation unit scope (set of functions).
4894
4895`TRACE_DEBUG_FUNCTION`::
4896 Debug information with function-level scope.
4897
4898`TRACE_DEBUG_LINE`::
4899 Debug information with line-level scope (TRACEPOINT_EVENT default).
4900
4901`TRACE_DEBUG`::
4902 Debug-level message.
4903
4904Log levels `TRACE_EMERG` through `TRACE_INFO` and `TRACE_DEBUG` match
4905http://man7.org/linux/man-pages/man3/syslog.3.html[syslog]
4906level semantics. Log levels `TRACE_DEBUG_SYSTEM` through `TRACE_DEBUG`
4907offer more fine-grained selection of debug information.
4908
4909
4910[[lttng-modules-ref]]
4911=== LTTng-modules
4912
4913This section presents references of the LTTng-modules package.
4914
4915
4916[[lttng-modules-tp-struct-entry]]
4917==== Tracepoint fields macros (for `TP_STRUCT__entry()`)
4918
4919This table describes possible entries for the `TP_STRUCT__entry()` part
4920of `LTTNG_TRACEPOINT_EVENT()`:
4921
4922[role="growable func-desc",cols="asciidoc,asciidoc"]
4923.Available entries for `TP_STRUCT__entry()` (in `LTTNG_TRACEPOINT_EVENT()`)
4924|====
4925|Macro |Description and parameters
4926
4927|+\__field(__t__, __n__)+
4928|
4929Standard integer, displayed in base 10.
4930
4931+__t__+::
4932 Integer C type (`int`, `unsigned char`, `size_t`, etc.).
4933
4934+__n__+::
4935 Field name.
4936
4937|+\__field_hex(__t__, __n__)+
4938|
4939Standard integer, displayed in base 16.
4940
4941+__t__+::
4942 Integer C type.
4943
4944+__n__+::
4945 Field name.
4946
4947|+\__field_oct(__t__, __n__)+
4948|
4949Standard integer, displayed in base 8.
4950
4951+__t__+::
4952 Integer C type.
4953
4954+__n__+::
4955 Field name.
4956
4957|+\__field_network(__t__, __n__)+
4958|
4959Integer in network byte order (big endian), displayed in base 10.
4960
4961+__t__+::
4962 Integer C type.
4963
4964+__n__+::
4965 Field name.
4966
4967|+\__field_network_hex(__t__, __n__)+
4968|
4969Integer in network byte order (big endian), displayed in base 16.
4970
4971+__t__+::
4972 Integer C type.
4973
4974+__n__+::
4975 Field name.
4976
4977|+\__array(__t__, __n__, __s__)+
4978|
4979Statically-sized array, elements displayed in base 10.
4980
4981+__t__+::
4982 Array element C type.
4983
4984+__n__+::
4985 Field name.
4986
4987+__s__+::
4988 Number of elements.
4989
4990|+\__array_hex(__t__, __n__, __s__)+
4991|
4992Statically-sized array, elements displayed in base 16.
4993
4994+__t__+::
4995 array element C type.
4996+__n__+::
4997 field name.
4998+__s__+::
4999 number of elements.
5000
5001|+\__array_text(__t__, __n__, __s__)+
5002|
5003Statically-sized array, displayed as text.
5004
5005+__t__+::
5006 Array element C type (always char).
5007
5008+__n__+::
5009 Field name.
5010
5011+__s__+::
5012 Number of elements.
5013
5014|+\__dynamic_array(__t__, __n__, __s__)+
5015|
5016Dynamically-sized array, displayed in base 10.
5017
5018+__t__+::
5019 Array element C type.
5020
5021+__n__+::
5022 Field name.
5023
5024+__s__+::
5025 Length C expression.
5026
5027|+\__dynamic_array_hex(__t__, __n__, __s__)+
5028|
5029Dynamically-sized array, displayed in base 16.
5030
5031+__t__+::
5032 Array element C type.
5033
5034+__n__+::
5035 Field name.
5036
5037+__s__+::
5038 Length C expression.
5039
5040|+\__dynamic_array_text(__t__, __n__, __s__)+
5041|
5042Dynamically-sized array, displayed as text.
5043
5044+__t__+::
5045 Array element C type (always char).
5046
5047+__n__+::
5048 Field name.
5049
5050+__s__+::
5051 Length C expression.
5052
5053|+\__string(n, __s__)+
5054|
5055Null-terminated string.
5056
5057The behaviour is undefined behavior if +__s__+ is `NULL`.
5058
5059+__n__+::
5060 Field name.
5061
5062+__s__+::
5063 String source (pointer).
5064|====
5065
5066The above macros should cover the majority of cases. For advanced items,
5067see path:{probes/lttng-events.h}.
5068
5069
5070[[lttng-modules-tp-fast-assign]]
5071==== Tracepoint assignment macros (for `TP_fast_assign()`)
5072
5073This table describes possible entries for the `TP_fast_assign()` part
5074of `LTTNG_TRACEPOINT_EVENT()`:
5075
5076.Available entries for `TP_fast_assign()` (in `LTTNG_TRACEPOINT_EVENT()`)
5077[role="growable func-desc",cols="asciidoc,asciidoc"]
5078|====
5079|Macro |Description and parameters
5080
5081|+tp_assign(__d__, __s__)+
5082|
5083Assignment of C expression +__s__+ to tracepoint field +__d__+.
5084
5085+__d__+::
5086 Name of destination tracepoint field.
5087
5088+__s__+::
5089 Source C expression (may refer to tracepoint arguments).
5090
5091|+tp_memcpy(__d__, __s__, __l__)+
5092|
5093Memory copy of +__l__+ bytes from +__s__+ to tracepoint field
5094+__d__+ (use with array fields).
5095
5096+__d__+::
5097 Name of destination tracepoint field.
5098
5099+__s__+::
5100 Source C expression (may refer to tracepoint arguments).
5101
5102+__l__+::
5103 Number of bytes to copy.
5104
5105|+tp_memcpy_from_user(__d__, __s__, __l__)+
5106|
5107Memory copy of +__l__+ bytes from user space +__s__+ to tracepoint
5108field +__d__+ (use with array fields).
5109
5110+__d__+::
5111 Name of destination tracepoint field.
5112
5113+__s__+::
5114 Source C expression (may refer to tracepoint arguments).
5115
5116+__l__+::
5117 Number of bytes to copy.
5118
5119|+tp_memcpy_dyn(__d__, __s__)+
5120|
5121Memory copy of dynamically-sized array from +__s__+ to tracepoint field
5122+__d__+.
5123
5124The number of bytes is known from the field's length expression
5125(use with dynamically-sized array fields).
5126
5127+__d__+::
5128 Name of destination tracepoint field.
5129
5130+__s__+::
5131 Source C expression (may refer to tracepoint arguments).
5132
5133+__l__+::
5134 Number of bytes to copy.
5135
5136|+tp_strcpy(__d__, __s__)+
5137|
5138String copy of +__s__+ to tracepoint field +__d__+ (use with string
5139fields).
5140
5141+__d__+::
5142 Name of destination tracepoint field.
5143
5144+__s__+::
5145 Source C expression (may refer to tracepoint arguments).
5146|====
This page took 0.202991 seconds and 4 git commands to generate.