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