Commit | Line | Data |
---|---|---|
f0287ae1 PP |
1 | The LTTng Documentation |
2 | ======================= | |
3 | Philippe Proulx <pproulx@efficios.com> | |
4 | v2.5, 21 October 2016 | |
5 | ||
6 | ||
7 | include::../common/copyright.txt[] | |
8 | ||
9 | ||
10 | include::../common/warning-not-maintained.txt[] | |
11 | ||
12 | ||
13 | include::../common/welcome.txt[] | |
14 | ||
15 | ||
16 | include::../common/audience.txt[] | |
17 | ||
18 | ||
19 | [[chapters]] | |
20 | === Chapter descriptions | |
21 | ||
22 | What follows is a list of brief descriptions of this documentation's | |
23 | chapters. The latter are ordered in such a way as to make the reading | |
24 | as 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 | ||
49 | We recommend that you read the above chapters in this order, although | |
50 | some 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 | |
52 | and LTTng. Also, you may jump over <<installing-lttng,Installing LTTng>> | |
53 | if LTTng is already properly installed on your target system. | |
54 | ||
55 | ||
56 | include::../common/convention.txt[] | |
57 | ||
58 | ||
59 | include::../common/acknowledgements.txt[] | |
60 | ||
61 | ||
62 | [[whats-new]] | |
63 | == What's new in LTTng {revision}? | |
64 | ||
65 | The **LTTng {revision}** toolchain introduces many interesting features, | |
66 | some of them which have been requested by users many times. | |
67 | ||
68 | It is now possible to | |
69 | <<saving-loading-tracing-session,save and restore tracing sessions>>. | |
70 | Sessions are saved to and loaded from XML files located by default in a | |
71 | subdirectory of the user's home directory. LTTng daemons are also | |
72 | configurable by configuration files as of LTTng-tools {revision}. This version | |
73 | also makes it possible to load user-defined kernel probes with the new | |
74 | session 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} | |
78 | which makes it possible to insert `printf()`-like tracepoints in C/$$C++$$ | |
79 | code for quick debugging. LTTng-UST {revision} also adds support for perf PMU | |
80 | counters in user space on the x86 architecture | |
81 | (see <<adding-context,Adding some context to channels>>). | |
82 | ||
83 | As of LTTng-modules {revision}, a new | |
84 | <<proc-lttng-logger-abi,LTTng logger ABI>> | |
85 | is made available, making tracing Bash scripts, for example, much more | |
86 | easier (just `echo` whatever you need to record to path:{/proc/lttng-logger} | |
87 | while tracing is active). On the kernel side, some tracepoints are | |
88 | added: state dumps of block devices, file descriptors, and file modes, | |
89 | as well as http://en.wikipedia.org/wiki/Video4Linux[V4L2] events. Linux | |
90 | 3.15 is now officially supported, and system call tracing is now | |
91 | possible on the MIPS32 architecture. | |
92 | ||
93 | To learn more about the new features of LTTng {revision}, see | |
94 | http://lttng.org/blog/2014/08/04/lttng-toolchain-2-5-0-is-out/[this | |
95 | release announcement]. | |
96 | ||
97 | ||
98 | [[nuts-and-bolts]] | |
99 | == Nuts and bolts | |
100 | ||
101 | What is LTTng? As its name suggests, the _Linux Trace Toolkit: next | |
102 | generation_ is a modern toolkit for tracing Linux systems and | |
103 | applications. So your first question might rather be: **what is | |
104 | tracing?** | |
105 | ||
106 | As the history of software engineering progressed and led to what | |
107 | we now take for granted--complex, numerous and | |
108 | interdependent software applications running in parallel on | |
109 | sophisticated operating systems like Linux--the authors of such | |
110 | components, or software developers, began feeling a natural | |
111 | urge of having tools to ensure the robustness and good performance | |
112 | of their masterpieces. | |
113 | ||
114 | One major achievement in this field is, inarguably, the | |
115 | https://www.gnu.org/software/gdb/[GNU debugger (GDB)], which is an | |
116 | essential tool for developers to find and fix bugs. But even the best | |
117 | debugger won't help make your software run faster, and nowadays, faster | |
118 | software means either more work done by the same hardware, or cheaper | |
119 | hardware for the same work. | |
120 | ||
121 | A _profiler_ is often the tool of choice to identify performance | |
122 | bottlenecks. Profiling is suitable to identify _where_ performance is | |
123 | lost in a given software; the profiler outputs a profile, a statistical | |
124 | summary of observed events, which you may use to know which functions | |
125 | took the most time to execute. However, a profiler won't report _why_ | |
126 | some identified functions are the bottleneck. Also, bottlenecks might | |
127 | only occur when specific conditions are met. For a thorough | |
128 | investigation of software performance issues, a history of execution, | |
129 | with historical values of chosen variables, is essential. This is where | |
130 | tracing comes in handy. | |
131 | ||
132 | _Tracing_ is a technique used to understand what goes on in a running | |
133 | software system. The software used for tracing is called a _tracer_, | |
134 | which is conceptually similar to a tape recorder. When recording, | |
135 | specific points placed in the software source code generate events that | |
136 | are saved on a giant tape: a _trace_ file. Both user applications and | |
137 | the operating system may be traced at the same time, opening the | |
138 | possibility of resolving a wide range of problems that are otherwise | |
139 | extremely challenging. | |
140 | ||
141 | Tracing is often compared to _logging_. However, tracers and loggers are | |
142 | two different types of tools, serving two different purposes. Tracers | |
143 | are designed to record much lower-level events that occur much more | |
144 | frequently than log messages, often in the thousands per second range, | |
145 | with very little execution overhead. Logging is more appropriate for | |
146 | very high-level analysis of less frequent events: user accesses, | |
147 | exceptional conditions (e.g., errors, warnings), database transactions, | |
148 | instant messaging communications, etc. More formally, logging is one of | |
149 | several use cases that can be accomplished with tracing. | |
150 | ||
151 | The list of recorded events inside a trace file may be read manually | |
152 | like a log file for the maximum level of detail, but it is generally | |
153 | much more interesting to perform application-specific analyses to | |
154 | produce reduced statistics and graphs that are useful to resolve a given | |
155 | problem. Trace viewers and analysers are specialized tools which achieve | |
156 | this. | |
157 | ||
158 | So, in the end, this is what LTTng is: a powerful, open source set of | |
159 | tools to trace the Linux kernel and user applications. LTTng is composed | |
160 | of several components actively maintained and developed by its | |
161 | http://lttng.org/community/#where[community]. | |
162 | ||
163 | Excluding proprietary solutions, a few competing software tracers exist | |
164 | for Linux. | |
165 | https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace] is the | |
166 | de facto function tracer of the Linux kernel. | |
167 | http://linux.die.net/man/1/strace[strace] is able to record all system | |
168 | calls made by a user process. | |
169 | https://sourceware.org/systemtap/[SystemTap] is a Linux kernel and user | |
170 | space tracer which uses custom user scripts to produce plain text | |
171 | traces. http://www.sysdig.org/[sysdig] also uses scripts, written in | |
172 | Lua, to trace and analyze the Linux kernel. | |
173 | ||
174 | The main distinctive features of LTTng is that it produces correlated | |
175 | kernel and user space traces, as well as doing so with the lowest | |
176 | overhead amongst other solutions. It produces trace files in the | |
177 | http://www.efficios.com/ctf[CTF] format, an optimized file format for | |
178 | production and analyses of multi-gigabyte data. LTTng is the result of | |
179 | close to 10 years of active development by a community of passionate | |
180 | developers. It is currently available on some major desktop, server, and | |
181 | embedded Linux distributions. | |
182 | ||
183 | The main interface for tracing control is a single command line tool | |
184 | named `lttng`. The latter can create several tracing sessions, | |
185 | enable/disable events on the fly, filter them efficiently with custom | |
186 | user expressions, start/stop tracing and do much more. Traces can be | |
187 | recorded on disk or sent over the network, kept totally or partially, | |
188 | and 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 | |
197 | instrumenting the Linux kernel and user applications and controlling | |
198 | tracing sessions (starting/stopping tracing, enabling/disabling events, | |
199 | etc.). Those components are bundled into the following packages: | |
200 | ||
201 | LTTng-tools:: | |
202 | Libraries and command line interface to control tracing sessions. | |
203 | ||
204 | LTTng-modules:: | |
205 | Linux kernel modules allowing Linux to be traced using LTTng. | |
206 | ||
207 | LTTng-UST:: | |
208 | User space tracing library. | |
209 | ||
210 | Most distributions mark the LTTng-modules and LTTng-UST packages as | |
211 | optional. In the following sections, we always provide the steps to | |
212 | install all three, but be aware that LTTng-modules is only required if | |
213 | you intend to trace the Linux kernel and LTTng-UST is only required if | |
214 | you intend to trace user space applications. | |
215 | ||
216 | This chapter shows how to install the above packages on a Linux system. | |
217 | The easiest way is to use the package manager of the system's | |
218 | distribution (<<desktop-distributions,desktop>> or | |
219 | <<embedded-distributions,embedded>>). Support is also available for | |
220 | <<enterprise-distributions,enterprise distributions>>, such as Red Hat | |
221 | Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SLES). | |
222 | Otherwise, you can | |
223 | <<building-from-source,build the LTTng packages from source>>. | |
224 | ||
225 | ||
226 | [[desktop-distributions]] | |
227 | === Desktop distributions | |
228 | ||
229 | Official LTTng {revision} packages are available for <<ubuntu,Ubuntu>> and | |
230 | <<debian,Debian>>. | |
231 | ||
232 | More recent versions of LTTng are available for Fedora, openSUSE, | |
233 | as well as Arch Linux. | |
234 | ||
235 | Should any issue arise when following the procedures below, please | |
236 | inform the http://lttng.org/community[community] about it. | |
237 | ||
238 | ||
239 | [[ubuntu]] | |
240 | ==== Ubuntu | |
241 | ||
242 | LTTng {revision} is packaged in Ubuntu 15.04 _Vivid Vervet_. For other | |
243 | releases of Ubuntu, you need to build and install LTTng | |
244 | <<building-from-source,from source>>. Ubuntu 15.10 _Wily Werewolf_ | |
245 | ships with link:/docs/v2.6/[LTTng 2.6]. | |
246 | ||
247 | To install LTTng {revision} from the official Ubuntu repositories, | |
248 | simply use `apt-get`: | |
249 | ||
250 | [role="term"] | |
251 | ---- | |
252 | sudo apt-get install lttng-tools | |
253 | sudo apt-get install lttng-modules-dkms | |
254 | sudo apt-get install liblttng-ust-dev | |
255 | ---- | |
256 | ||
257 | ||
258 | [[debian]] | |
259 | ==== Debian | |
260 | ||
261 | Debian "jessie" has official packages of LTTng {revision}: | |
262 | ||
263 | [role="term"] | |
264 | ---- | |
265 | sudo apt-get install lttng-tools | |
266 | sudo apt-get install lttng-modules-dkms | |
267 | sudo apt-get install liblttng-ust-dev | |
268 | ---- | |
269 | ||
270 | ||
271 | [[embedded-distributions]] | |
272 | === Embedded distributions | |
273 | ||
274 | Some developers may be interested in tracing the Linux kernel and user space | |
275 | applications running on embedded systems. LTTng is packaged by two popular | |
276 | embedded Linux distributions: <<buildroot,Buildroot>> and | |
277 | <<oe-yocto,OpenEmbedded/Yocto>>. | |
278 | ||
279 | ||
280 | [[buildroot]] | |
281 | ==== Buildroot | |
282 | ||
283 | LTTng {revision} packages in Buildroot 2014.11 and 2015.02 are named | |
284 | `lttng-tools`, `lttng-modules`, and `lttng-libust`. | |
285 | ||
286 | To enable them, start the Buildroot configuration menu as usual: | |
287 | ||
288 | [role="term"] | |
289 | ---- | |
290 | make menuconfig | |
291 | ---- | |
292 | ||
293 | In: | |
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 | ||
300 | In _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 | ||
308 | LTTng {revision} recipes are available in the `openembedded-core` layer of | |
309 | OpenEmbedded from August 15th, 2014 to February 8th, 2015 under the | |
310 | following names: | |
311 | ||
312 | * `lttng-tools` | |
313 | * `lttng-modules` | |
314 | * `lttng-ust` | |
315 | ||
316 | Using BitBake, the simplest way to include LTTng recipes in your | |
317 | target image is to add them to `IMAGE_INSTALL_append` in | |
318 | path:{conf/local.conf}: | |
319 | ||
320 | ---- | |
321 | IMAGE_INSTALL_append = " lttng-tools lttng-modules lttng-ust" | |
322 | ---- | |
323 | ||
324 | If you're using Hob, click _Edit image recipe_ once you have selected | |
325 | a machine and an image recipe. Then, in the _All recipes_ tab, search | |
326 | for `lttng` and you should find and be able to include the three LTTng | |
327 | recipes. | |
328 | ||
329 | ||
330 | [[enterprise-distributions]] | |
331 | === Enterprise distributions (RHEL, SLES) | |
332 | ||
333 | To install LTTng on enterprise Linux distributions | |
334 | (such as RHEL and SLES), please see | |
335 | http://packages.efficios.com/[EfficiOS Enterprise Packages]. | |
336 | ||
337 | ||
338 | [[building-from-source]] | |
339 | === Building from source | |
340 | ||
341 | As <<installing-lttng,previously stated>>, LTTng is shipped as three | |
342 | packages: LTTng-tools, LTTng-modules and LTTng-UST. LTTng-tools contains | |
343 | everything needed to control tracing sessions, while LTTng-modules is | |
344 | only needed for Linux kernel tracing and LTTng-UST is only needed for | |
345 | user space tracing. | |
346 | ||
347 | The tarballs are available in the | |
348 | http://lttng.org/download#build-from-source[Download section] | |
349 | of the LTTng website. | |
350 | ||
351 | Please refer to the path:{README.md} files provided by each package to | |
352 | properly build and install them. | |
353 | ||
354 | TIP: The aforementioned path:{README.md} files are rendered as | |
355 | rich text when https://github.com/lttng[viewed on GitHub]. | |
356 | ||
357 | ||
358 | [[getting-started]] | |
359 | == Getting started with LTTng | |
360 | ||
361 | This is a small guide to get started quickly with LTTng kernel and user | |
362 | space tracing. For intermediate to advanced use cases and a more | |
363 | thorough understanding of LTTng, see <<using-lttng,Using LTTng>> and | |
364 | <<understanding-lttng,Understanding LTTng>>. | |
365 | ||
366 | Before reading this guide, make sure LTTng | |
367 | <<installing-lttng,is installed>>. You will at least need LTTng-tools. | |
368 | Also install LTTng-modules for | |
369 | <<tracing-the-linux-kernel,tracing the Linux kernel>> | |
370 | and LTTng-UST for <<tracing-your-own-user-application,tracing your own | |
371 | user space applications>>. When your traces are finally written and | |
372 | complete, the | |
373 | <<viewing-and-analyzing-your-traces,Viewing and analyzing your traces>> | |
374 | section of this chapter will help you analyze your tracepoint | |
375 | events to investigate. | |
376 | ||
377 | ||
378 | [[tracing-the-linux-kernel]] | |
379 | === Tracing the Linux kernel | |
380 | ||
381 | Make sure LTTng-tools and LTTng-modules packages | |
382 | <<installing-lttng,are installed>>. | |
383 | ||
384 | Since you're about to trace the Linux kernel itself, let's look at the | |
385 | available kernel events using the `lttng` tool, which has a | |
386 | Git-like command line structure: | |
387 | ||
388 | [role="term"] | |
389 | ---- | |
390 | lttng list --kernel | |
391 | ---- | |
392 | ||
393 | Before tracing, you need to create a session: | |
394 | ||
395 | [role="term"] | |
396 | ---- | |
397 | sudo lttng create my-session | |
398 | ---- | |
399 | ||
400 | TIP: You can avoid using `sudo` in the previous and following commands | |
401 | if 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 | |
404 | like. `auto` will be used if omitted. | |
405 | ||
406 | Let's now enable some events for this session: | |
407 | ||
408 | [role="term"] | |
409 | ---- | |
410 | sudo lttng enable-event --kernel sched_switch,sched_process_fork | |
411 | ---- | |
412 | ||
413 | or you might want to simply enable all available kernel events (beware | |
414 | that trace files will grow rapidly when doing this): | |
415 | ||
416 | [role="term"] | |
417 | ---- | |
418 | sudo lttng enable-event --kernel --all | |
419 | ---- | |
420 | ||
421 | Start tracing: | |
422 | ||
423 | [role="term"] | |
424 | ---- | |
425 | sudo lttng start | |
426 | ---- | |
427 | ||
428 | By default, traces are saved in | |
429 | +\~/lttng-traces/__name__-__date__-__time__+, | |
430 | where +__name__+ is the session name. | |
431 | ||
432 | When you're done tracing: | |
433 | ||
434 | [role="term"] | |
435 | ---- | |
436 | sudo lttng stop | |
437 | sudo lttng destroy | |
438 | ---- | |
439 | ||
440 | Although `destroy` looks scary here, it doesn't actually destroy the | |
441 | outputted trace files: it only destroys the tracing session. | |
442 | ||
443 | What's next? Have a look at | |
444 | <<viewing-and-analyzing-your-traces,Viewing and analyzing your traces>> | |
445 | to view and analyze the trace you just recorded. | |
446 | ||
447 | ||
448 | [[tracing-your-own-user-application]] | |
449 | === Tracing your own user application | |
450 | ||
451 | The previous section helped you create a trace out of Linux kernel | |
452 | events. This section steps you through a simple example showing you how | |
453 | to trace a _Hello world_ program written in C. | |
454 | ||
455 | Make sure LTTng-tools and LTTng-UST packages | |
456 | <<installing-lttng,are installed>>. | |
457 | ||
458 | Tracing is just like having `printf()` calls at specific locations of | |
459 | your source code, albeit LTTng is much faster and more flexible than | |
460 | `printf()`. In the LTTng realm, **`tracepoint()`** is analogous to | |
461 | `printf()`. | |
462 | ||
463 | Unlike `printf()`, though, `tracepoint()` does not use a format string to | |
464 | know the types of its arguments: the formats of all tracepoints must be | |
465 | defined before using them. So before even writing our _Hello world_ program, | |
466 | we need to define the format of our tracepoint. This is done by writing a | |
467 | **template file**, with a name usually ending | |
468 | with the `.tp` extension (for **t**race**p**oint), | |
469 | which the `lttng-gen-tp` tool (shipped with LTTng-UST) will use to generate | |
470 | an object file (along with a `.c` file) and a header to be | |
471 | included in our application source code. | |
472 | ||
473 | Here's the whole flow: | |
474 | ||
475 | [role="img-80"] | |
476 | .Build workflow for LTTng application tracing. | |
477 | image::lttng-lttng-gen-tp.png[] | |
478 | ||
479 | The template file format is a list of tracepoint definitions | |
480 | and other optional definition entries which we will skip for | |
481 | this 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 | ||
494 | Here's a simple tracepoint definition example with two arguments: an integer | |
495 | and a string: | |
496 | ||
497 | [source,c] | |
498 | ---- | |
499 | TRACEPOINT_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 | ||
513 | The 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 | ||
517 | Save the above snippet as path:{hello-tp.tp} and run: | |
518 | ||
519 | [role="term"] | |
520 | ---- | |
521 | lttng-gen-tp hello-tp.tp | |
522 | ---- | |
523 | ||
524 | The 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 | ||
530 | path:{hello-tp.o} is the compiled object file of path:{hello-tp.c}. | |
531 | ||
532 | Now, by including path:{hello-tp.h} in your own application, you may use the | |
533 | tracepoint 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 | ||
541 | int 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 | ||
578 | Save this as path:{hello.c}, next to path:{hello-tp.tp}. | |
579 | ||
580 | Notice path:{hello-tp.h}, the header file generated by path:{lttng-gen-tp} from | |
581 | our template file path:{hello-tp.tp}, is included by path:{hello.c}. | |
582 | ||
583 | You are now ready to compile the application with LTTng-UST support: | |
584 | ||
585 | [role="term"] | |
586 | ---- | |
587 | gcc -o hello hello.c hello-tp.o -llttng-ust -ldl | |
588 | ---- | |
589 | ||
590 | If you followed the | |
591 | <<tracing-the-linux-kernel,Tracing the Linux kernel>> section, the | |
592 | following steps will look familiar. | |
593 | ||
594 | First, run the application with a few arguments: | |
595 | ||
596 | [role="term"] | |
597 | ---- | |
598 | ./hello world and beyond | |
599 | ---- | |
600 | ||
601 | You should see | |
602 | ||
603 | ---- | |
604 | Hello, World! | |
605 | Press Enter to continue... | |
606 | ---- | |
607 | ||
608 | Use the `lttng` tool to list all available user space events: | |
609 | ||
610 | [role="term"] | |
611 | ---- | |
612 | lttng list --userspace | |
613 | ---- | |
614 | ||
615 | You should see the `hello_world:my_first_tracepoint` tracepoint listed | |
616 | under the `./hello` process. | |
617 | ||
618 | Create a tracing session: | |
619 | ||
620 | [role="term"] | |
621 | ---- | |
622 | lttng create my-userspace-session | |
623 | ---- | |
624 | ||
625 | Enable the `hello_world:my_first_tracepoint` tracepoint: | |
626 | ||
627 | [role="term"] | |
628 | ---- | |
629 | lttng enable-event --userspace hello_world:my_first_tracepoint | |
630 | ---- | |
631 | ||
632 | Start tracing: | |
633 | ||
634 | [role="term"] | |
635 | ---- | |
636 | lttng start | |
637 | ---- | |
638 | ||
639 | Go back to the running path:{hello} application and press Enter. All | |
640 | `tracepoint()` calls will be executed and the program will finally exit. | |
641 | ||
642 | Stop tracing: | |
643 | ||
644 | [role="term"] | |
645 | ---- | |
646 | lttng stop | |
647 | ---- | |
648 | ||
649 | Done! You may use `lttng view` to list the recorded events. This command | |
650 | starts | |
651 | http://www.efficios.com/babeltrace[`babeltrace`] | |
652 | in the background, if it is installed: | |
653 | ||
654 | [role="term"] | |
655 | ---- | |
656 | lttng view | |
657 | ---- | |
658 | ||
659 | should 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 | ||
670 | When you're done, you may destroy the tracing session, which does _not_ | |
671 | destroy the generated trace files, leaving them available for further | |
672 | analysis: | |
673 | ||
674 | [role="term"] | |
675 | ---- | |
676 | lttng destroy my-userspace-session | |
677 | ---- | |
678 | ||
679 | The next section presents other alternatives to view and analyze your | |
680 | LTTng traces. | |
681 | ||
682 | ||
683 | [[viewing-and-analyzing-your-traces]] | |
684 | === Viewing and analyzing your traces | |
685 | ||
686 | This section describes how to visualize the data gathered after tracing | |
687 | the Linux kernel or a user space application. | |
688 | ||
689 | Many 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 | ||
705 | LTTng trace files are usually recorded in the path:{~/lttng-traces} directory. | |
706 | Let's now view the trace and perform a basic analysis using | |
707 | `babeltrace`. | |
708 | ||
709 | The simplest way to list all the recorded events of a trace is to pass its | |
710 | path to `babeltrace` with no options: | |
711 | ||
712 | [role="term"] | |
713 | ---- | |
714 | babeltrace ~/lttng-traces/my-session | |
715 | ---- | |
716 | ||
717 | `babeltrace` will find all traces within the given path recursively and | |
718 | output all their events, merging them intelligently. | |
719 | ||
720 | Listing all the system calls of a Linux kernel trace with their arguments is | |
721 | easy with `babeltrace` and `grep`: | |
722 | ||
723 | [role="term"] | |
724 | ---- | |
725 | babeltrace ~/lttng-traces/my-kernel-session | grep sys_ | |
726 | ---- | |
727 | ||
728 | Counting events is also straightforward: | |
729 | ||
730 | [role="term"] | |
731 | ---- | |
732 | babeltrace ~/lttng-traces/my-kernel-session | grep sys_read | wc --lines | |
733 | ---- | |
734 | ||
735 | The text output of `babeltrace` is useful for isolating events by simple | |
736 | matching using `grep` and similar utilities. However, more elaborate filters | |
737 | such as keeping only events with a field value falling within a specific range | |
738 | are not trivial to write using a shell. Moreover, reductions and even the | |
739 | most basic computations involving multiple events are virtually impossible | |
740 | to implement. | |
741 | ||
742 | Fortunately, Babeltrace ships with a Python 3 binding which makes it | |
743 | really easy to read the events of an LTTng trace sequentially and compute | |
744 | the desired information. | |
745 | ||
746 | Here's a simple example using the Babeltrace Python binding. The following | |
747 | script accepts an LTTng Linux kernel trace path as its first argument and | |
748 | outputs the short names of the top 5 running processes on CPU 0 during the | |
749 | whole trace: | |
750 | ||
751 | [source,python] | |
752 | ---- | |
753 | import sys | |
754 | from collections import Counter | |
755 | import babeltrace | |
756 | ||
757 | ||
758 | def 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 | ||
818 | if __name__ == '__main__': | |
819 | top5proc() | |
820 | ---- | |
821 | ||
822 | Save this script as path:{top5proc.py} and run it with Python 3, providing the | |
823 | path to an LTTng Linux kernel trace as the first argument: | |
824 | ||
825 | [role="term"] | |
826 | ---- | |
827 | python3 top5proc.py ~/lttng-sessions/my-session-.../kernel | |
828 | ---- | |
829 | ||
830 | Make sure the path you provide is the directory containing actual trace | |
831 | files (path:{channel0_0}, path:{metadata}, etc.): the `babeltrace` utility | |
832 | recurses directories, but the Python binding does not. | |
833 | ||
834 | Here's an example of output: | |
835 | ||
836 | ---- | |
837 | swapper/0 48.607245889 s | |
838 | chromium 7.192738188 s | |
839 | pavucontrol 0.709894415 s | |
840 | Compositor 0.660867933 s | |
841 | Xorg.bin 0.616753786 s | |
842 | ---- | |
843 | ||
844 | Note that `swapper/0` is the "idle" process of CPU 0 on Linux; since we | |
845 | weren't using the CPU that much when tracing, its first position in the list | |
846 | makes sense. | |
847 | ||
848 | ||
849 | [[understanding-lttng]] | |
850 | == Understanding LTTng | |
851 | ||
852 | If you're going to use LTTng in any serious way, it is fundamental that | |
853 | you become familiar with its core concepts. Technical terms like | |
854 | _tracing sessions_, _domains_, _channels_ and _events_ are used over | |
855 | and over in the <<using-lttng,Using LTTng>> chapter, | |
856 | and it is assumed that you understand what they mean when reading it. | |
857 | ||
858 | LTTng, as you already know, is a _toolkit_. It would be wrong | |
859 | to call it a simple _tool_ since it is composed of multiple interacting | |
860 | components. This chapter also describes the latter, providing details | |
861 | about their respective roles and how they connect together to form | |
862 | the current LTTng ecosystem. | |
863 | ||
864 | ||
865 | [[core-concepts]] | |
866 | === Core concepts | |
867 | ||
868 | This section explains the various elementary concepts a user has to deal | |
869 | with 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 | ||
880 | A _tracing session_ is--like any session--a container of | |
881 | state. Anything that is done when tracing using LTTng happens in the | |
882 | scope of a tracing session. In this regard, it is analogous to a bank | |
883 | website's session: you can't interact online with your bank account | |
884 | unless you are logged in a session, except for reading a few static | |
885 | webpages (LTTng, too, can report some static information that does not | |
886 | need a created tracing session). | |
887 | ||
888 | A tracing session holds the following attributes and objects (some of | |
889 | which 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 | ||
911 | All this information is completely isolated between tracing sessions. | |
912 | ||
913 | Conceptually, a tracing session is a per-user object; the | |
914 | <<plumbing,Plumbing>> section shows how this is actually | |
915 | implemented. Any user may create as many concurrent tracing sessions | |
916 | as desired. As you can see in the list above, even the tracing state | |
917 | is a per-tracing session attribute, so that you may trace your target | |
918 | system/application in a given tracing session with a specific | |
919 | configuration while another one stays inactive. | |
920 | ||
921 | The trace data generated in a tracing session may be either saved | |
922 | to disk, sent over the network or not saved at all (in which case | |
923 | snapshots may still be saved to disk or sent to a remote machine). | |
924 | ||
925 | ||
926 | [[domain]] | |
927 | ==== Domain | |
928 | ||
929 | A tracing _domain_ is the official term the LTTng project uses to | |
930 | designate a tracer category. | |
931 | ||
932 | There are currently three known domains: | |
933 | ||
934 | * Linux kernel | |
935 | * user space | |
936 | * `java.util.logging` (JUL) | |
937 | ||
938 | Different tracers expose common features in their own interfaces, but, | |
939 | from a user's perspective, you still need to target a specific type of | |
940 | tracer to perform some actions. For example, since both kernel and user | |
941 | space tracers support named tracepoints (probes manually inserted in | |
942 | source code), you need to specify which one is concerned when enabling | |
943 | an event because both domains could have existing events with the same | |
944 | name. | |
945 | ||
946 | Some features are not available in all domains. Filtering enabled | |
947 | events using custom expressions, for example, is currently not | |
948 | supported in the kernel domain, but support could be added in the | |
949 | future. | |
950 | ||
951 | ||
952 | [[channel]] | |
953 | ==== Channel | |
954 | ||
955 | A _channel_ is a set of events with specific parameters and potential | |
956 | added context information. Channels have unique names per domain within | |
957 | a tracing session. A given event is always registered to at least one | |
958 | channel; having an enabled event in two channels will produce a trace | |
959 | with this event recorded twice everytime it occurs. | |
960 | ||
961 | Channels may be individually enabled or disabled. Occurring events of | |
962 | a disabled channel will never make it to recorded events. | |
963 | ||
964 | The fundamental role of a channel is to keep a shared ring buffer, where | |
965 | events are eventually recorded by the tracer and consumed by a consumer | |
966 | daemon. This internal ring buffer is divided into many sub-buffers of | |
967 | equal size. | |
968 | ||
969 | Channels, when created, may be fine-tuned thanks to a few parameters, | |
970 | many of them related to sub-buffers. The following subsections explain | |
971 | what those parameters are and in which situations you should manually | |
972 | adjust them. | |
973 | ||
974 | ||
975 | [[channel-overwrite-mode-vs-discard-mode]] | |
976 | ===== Overwrite and discard event loss modes | |
977 | ||
978 | As previously mentioned, a channel's ring buffer is divided into many | |
979 | equally sized sub-buffers. | |
980 | ||
981 | As events occur, they are serialized as trace data into a specific | |
982 | sub-buffer (yellow arc in the following animation) until it is full: | |
983 | when this happens, the sub-buffer is marked as consumable (red) and | |
984 | another, _empty_ (white) sub-buffer starts receiving the following | |
985 | events. The marked sub-buffer will be consumed eventually by a consumer | |
986 | daemon (returns to white). | |
987 | ||
988 | [NOTE] | |
989 | [role="docsvg-channel-subbuf-anim"] | |
990 | ==== | |
991 | {note-no-anim} | |
992 | ==== | |
993 | ||
994 | In an ideal world, sub-buffers are consumed faster than filled, like it | |
995 | is the case above. In the real world, however, all sub-buffers could be | |
996 | full at some point, leaving no space to record the following events. By | |
997 | design, LTTng is a _non-blocking_ tracer: when no empty sub-buffer | |
998 | exists, losing events is acceptable when the alternative would be to | |
999 | cause substantial delays in the instrumented application's execution. | |
1000 | LTTng privileges performance over integrity, aiming at perturbing the | |
1001 | traced system as little as possible in order to make tracing of subtle | |
1002 | race conditions and rare interrupt cascades possible. | |
1003 | ||
1004 | When it comes to losing events because no empty sub-buffer is available, | |
1005 | the channel's _event loss mode_ determines what to do amongst: | |
1006 | ||
1007 | Discard:: | |
1008 | Drop the newest events until a sub-buffer is released. | |
1009 | ||
1010 | Overwrite:: | |
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 | ||
1016 | Which mechanism you should choose depends on your context: prioritize | |
1017 | the newest or the oldest events in the ring buffer? | |
1018 | ||
1019 | Beware that, in overwrite mode, a whole sub-buffer is abandoned as soon | |
1020 | as a new event doesn't find an empty sub-buffer, whereas in discard | |
1021 | mode, only the event that doesn't fit is discarded. | |
1022 | ||
1023 | Also note that a count of lost events will be incremented and saved in | |
1024 | the trace itself when an event is lost in discard mode, whereas no | |
1025 | information is kept when a sub-buffer gets overwritten before being | |
1026 | committed. | |
1027 | ||
1028 | There are known ways to decrease your probability of losing events. The | |
1029 | next section shows how tuning the sub-buffers count and size can be | |
1030 | used to virtually stop losing events. | |
1031 | ||
1032 | ||
1033 | [[channel-subbuf-size-vs-subbuf-count]] | |
1034 | ===== Sub-buffers count and size | |
1035 | ||
1036 | For each channel, an LTTng user may set its number of sub-buffers and | |
1037 | their size. | |
1038 | ||
1039 | Note that there is a noticeable tracer's CPU overhead introduced when | |
1040 | switching sub-buffers (marking a full one as consumable and switching | |
1041 | to an empty one for the following events to be recorded). Knowing this, | |
1042 | the following list presents a few practical situations along with how | |
1043 | to configure sub-buffers for them: | |
1044 | ||
1045 | High 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 | ||
1053 | Low 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 | ||
1059 | Low 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 | ||
1065 | You should know that LTTng uses CTF as its trace format, which means | |
1066 | event data is very compact. For example, the average LTTng Linux kernel | |
1067 | event weights about 32{nbsp}bytes. A sub-buffer size of 1{nbsp}MiB is | |
1068 | thus considered big. | |
1069 | ||
1070 | The previous situations highlight the major trade-off between a few big | |
1071 | sub-buffers and more, smaller sub-buffers: sub-buffer switching | |
1072 | frequency vs. how much data is lost in overwrite mode. Assuming a | |
1073 | constant event throughput and using the overwrite mode, the two | |
1074 | following 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 | ||
1090 | In discard mode, the sub-buffers count parameter is pointless: use two | |
1091 | sub-buffers and set their size according to the requirements of your | |
1092 | situation. | |
1093 | ||
1094 | ||
1095 | [[channel-switch-timer]] | |
1096 | ===== Switch timer | |
1097 | ||
1098 | The _switch timer_ period is another important configurable feature of | |
1099 | channels to ensure periodic sub-buffer flushing. | |
1100 | ||
1101 | When the _switch timer_ fires, a sub-buffer switch happens. This timer | |
1102 | may be used to ensure that event data is consumed and committed to | |
1103 | trace 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 | ||
1111 | It's also convenient when big sub-buffers are used to cope with | |
1112 | sporadic high event throughput, even if the throughput is normally | |
1113 | lower. | |
1114 | ||
1115 | ||
1116 | [[channel-buffering-schemes]] | |
1117 | ===== Buffering schemes | |
1118 | ||
1119 | In the user space tracing domain, two **buffering schemes** are | |
1120 | available when creating a channel: | |
1121 | ||
1122 | Per-PID buffering:: | |
1123 | Keep one ring buffer per process. | |
1124 | ||
1125 | Per-UID buffering:: | |
1126 | Keep one ring buffer for all processes of a single user. | |
1127 | ||
1128 | The per-PID buffering scheme will consume more memory than the per-UID | |
1129 | option if more than one process is instrumented for LTTng-UST. However, | |
1130 | per-PID buffering ensures that one process having a high event | |
1131 | throughput won't fill all the shared sub-buffers, only its own. | |
1132 | ||
1133 | The Linux kernel tracing domain only has one available buffering scheme | |
1134 | which is to use a single ring buffer for the whole system. | |
1135 | ||
1136 | ||
1137 | [[event]] | |
1138 | ==== Event | |
1139 | ||
1140 | An _event_, in LTTng's realm, is a term often used metonymically, | |
1141 | having 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 | ||
1156 | The whole <<core-concepts,Core concepts>> section focuses on the | |
1157 | third definition. An event is always registered to _one or more_ | |
1158 | channels and may be enabled or disabled at will per channel. A disabled | |
1159 | event will never lead to a recorded event, even if its channel | |
1160 | is enabled. | |
1161 | ||
1162 | An event (3) is enabled with a few conditions that must _all_ be met | |
1163 | when 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 | ||
1172 | The following illustration summarizes how tracing sessions, domains, | |
1173 | channels and events are related: | |
1174 | ||
1175 | [role="img-90"] | |
1176 | .Core concepts. | |
1177 | image::core-concepts.png[] | |
1178 | ||
1179 | This 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 | |
1181 | channel. | |
1182 | ||
1183 | ||
1184 | [[plumbing]] | |
1185 | === Plumbing | |
1186 | ||
1187 | The previous section described the concepts at the heart of LTTng. | |
1188 | This section summarizes LTTng's implementation: how those objects are | |
1189 | managed by different applications and libraries working together to | |
1190 | form the toolkit. | |
1191 | ||
1192 | ||
1193 | [[plumbing-overview]] | |
1194 | ==== Overview | |
1195 | ||
1196 | As <<installing-lttng,mentioned previously>>, the whole LTTng suite | |
1197 | is made of the following packages: LTTng-tools, LTTng-UST, and | |
1198 | LTTng-modules. Together, they provide different daemons, libraries, | |
1199 | kernel modules and command line interfaces. The following tree shows | |
1200 | which 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 | ||
1223 | The following diagram shows how the most important LTTng components | |
1224 | interact. Plain black arrows represent trace data paths while dashed | |
1225 | red arrows indicate control communications. The LTTng relay daemon is | |
1226 | shown running on a remote system, although it could as well run on the | |
1227 | target (monitored) system. | |
1228 | ||
1229 | [role="img-90"] | |
1230 | .LTTng plumbing. | |
1231 | image::plumbing.png[] | |
1232 | ||
1233 | Each component is described in the following subsections. | |
1234 | ||
1235 | ||
1236 | [[lttng-sessiond]] | |
1237 | ==== Session daemon | |
1238 | ||
1239 | At the heart of LTTng's plumbing is the _session daemon_, often called | |
1240 | by its command name, `lttng-sessiond`. | |
1241 | ||
1242 | The session daemon is responsible for managing tracing sessions and | |
1243 | what they logically contain (channel properties, enabled/disabled | |
1244 | events, 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 | ||
1248 | One of the many things that `lttng-sessiond` does is to keep | |
1249 | track of the available event types. User space applications and | |
1250 | libraries actively connect and register to the session daemon when they | |
1251 | start. By contrast, `lttng-sessiond` seeks out and loads the appropriate | |
1252 | LTTng kernel modules as part of its own initialization. Kernel event | |
1253 | types are _pulled_ by `lttng-sessiond`, whereas user space event types | |
1254 | are _pushed_ to it by the various user space tracepoint providers. | |
1255 | ||
1256 | Using a specific inter-process communication protocol with Linux kernel | |
1257 | and user space tracers, the session daemon can send channel information | |
1258 | so that they are initialized, enable/disable specific probes based on | |
1259 | enabled/disabled events by the user, send event filters information to | |
1260 | LTTng tracers so that filtering actually happens at the tracer site, | |
1261 | start/stop tracing a specific application or the Linux kernel, etc. | |
1262 | ||
1263 | The session daemon is not useful without some user controlling it, | |
1264 | because it's only a sophisticated control interchange and thus | |
1265 | doesn't make any decision on its own. `lttng-sessiond` opens a local | |
1266 | socket for controlling it, albeit the preferred way to control it is | |
1267 | using `liblttng-ctl`, an installed C library hiding the communication | |
1268 | protocol 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 | |
1272 | applications; the _consumer daemons_ are the programs responsible for | |
1273 | collecting trace data using shared ring buffers. However, the session | |
1274 | daemon is the one that must spawn a consumer daemon and establish | |
1275 | a control communication with it. | |
1276 | ||
1277 | Session daemons run on a per-user basis. Knowing this, multiple | |
1278 | instances of `lttng-sessiond` may run simultaneously, each belonging | |
1279 | to a different user and each operating independently of the others. | |
1280 | Only `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 | |
1282 | access on the target system, he cannot trace the system's kernel, but | |
1283 | should still be able to trace its own instrumented applications. | |
1284 | ||
1285 | It has to be noted that, although only `root`'s session daemon may | |
1286 | control the kernel tracer, the `lttng-sessiond` command has a `--group` | |
1287 | option which may be used to specify the name of a special user group | |
1288 | allowed to communicate with `root`'s session daemon and thus record | |
1289 | kernel traces. By default, this group is named `tracing`. | |
1290 | ||
1291 | If not done yet, the `lttng` tool, by default, automatically starts a | |
1292 | session daemon. `lttng-sessiond` may also be started manually: | |
1293 | ||
1294 | [role="term"] | |
1295 | ---- | |
1296 | lttng-sessiond | |
1297 | ---- | |
1298 | ||
1299 | This will start the session daemon in foreground. Use | |
1300 | ||
1301 | [role="term"] | |
1302 | ---- | |
1303 | lttng-sessiond --daemonize | |
1304 | ---- | |
1305 | ||
1306 | to start it as a true daemon. | |
1307 | ||
1308 | To kill the current user's session daemon, `pkill` may be used: | |
1309 | ||
1310 | [role="term"] | |
1311 | ---- | |
1312 | pkill lttng-sessiond | |
1313 | ---- | |
1314 | ||
1315 | The default `SIGTERM` signal will terminate it cleanly. | |
1316 | ||
1317 | Several other options are available and described in | |
1318 | man:lttng-sessiond(8) or by running `lttng-sessiond --help`. | |
1319 | ||
1320 | ||
1321 | [[lttng-consumerd]] | |
1322 | ==== Consumer daemon | |
1323 | ||
1324 | The _consumer daemon_, or `lttng-consumerd`, is a program sharing some | |
1325 | ring buffers with user applications or the LTTng kernel modules to | |
1326 | collect trace data and output it at some place (on disk or sent over | |
1327 | the network to an LTTng relay daemon). | |
1328 | ||
1329 | Consumer daemons are created by a session daemon as soon as events are | |
1330 | enabled within a tracing session, well before tracing is activated | |
1331 | for the latter. Entirely managed by session daemons, | |
1332 | consumer daemons survive session destruction to be reused later, | |
1333 | should a new tracing session be created. Consumer daemons are always | |
1334 | owned by the same user as their session daemon. When its owner session | |
1335 | daemon is killed, the consumer daemon also exits. This is because | |
1336 | the consumer daemon is always the child process of a session daemon. | |
1337 | Consumer daemons should never be started manually. For this reason, | |
1338 | they are not installed in one of the usual locations listed in the | |
1339 | `PATH` environment variable. `lttng-sessiond` has, however, a | |
1340 | bunch of options (see man:lttng-sessiond(8)) to | |
1341 | specify custom consumer daemon paths if, for some reason, a consumer | |
1342 | daemon other than the default installed one is needed. | |
1343 | ||
1344 | There are up to two running consumer daemons per user, whereas only one | |
1345 | session daemon may run per user. This is because each process has | |
1346 | independent bitness: if the target system runs a mixture of 32-bit and | |
1347 | 64-bit processes, it is more efficient to have separate corresponding | |
1348 | 32-bit and 64-bit consumer daemons. The `root` user is an exception: it | |
1349 | may have up to _three_ running consumer daemons: 32-bit and 64-bit | |
1350 | instances for its user space applications and one more reserved for | |
1351 | collecting kernel trace data. | |
1352 | ||
1353 | As new tracing domains are added to LTTng, the development community's | |
1354 | intent is to minimize the need for additionnal consumer daemon instances | |
1355 | dedicated to them. For instance, the `java.util.logging` (JUL) domain | |
1356 | events are in fact mapped to the user space domain, thus tracing this | |
1357 | particular domain is handled by existing user space domain consumer | |
1358 | daemons. | |
1359 | ||
1360 | ||
1361 | [[lttng-relayd]] | |
1362 | ==== Relay daemon | |
1363 | ||
1364 | When a tracing session is configured to send its trace data over the | |
1365 | network, an LTTng _relay daemon_ must be used at the other end to | |
1366 | receive trace packets and serialize them to trace files. This setup | |
1367 | makes it possible to trace a target system without ever committing trace | |
1368 | data to its local storage, a feature which is useful for embedded | |
1369 | systems, amongst others. The command implementing the relay daemon | |
1370 | is `lttng-relayd`. | |
1371 | ||
1372 | The basic use case of `lttng-relayd` is to transfer trace data received | |
1373 | over the network to trace files on the local file system. The relay | |
1374 | daemon must listen on two TCP ports to achieve this: one control port, | |
1375 | used by the target session daemon, and one data port, used by the | |
1376 | target consumer daemon. The relay and session daemons agree on common | |
1377 | default ports when custom ones are not specified. | |
1378 | ||
1379 | Since the communication transport protocol for both ports is standard | |
1380 | TCP, the relay daemon may be started either remotely or locally (on the | |
1381 | target system). | |
1382 | ||
1383 | While two instances of consumer daemons (32-bit and 64-bit) may run | |
1384 | concurrently for a given user, `lttng-relayd` needs only be of its | |
1385 | host operating system's bitness. | |
1386 | ||
1387 | The 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 | |
1389 | they arrive. The relay daemon will still record events in trace files, | |
1390 | but a _tee_ may be created to inspect incoming events. Using LTTng live | |
1391 | locally thus requires to run a local relay daemon. | |
1392 | ||
1393 | ||
1394 | [[liblttng-ctl-lttng]] | |
1395 | ==== [[lttng-cli]]Control library and command line interface | |
1396 | ||
1397 | The LTTng control library, `liblttng-ctl`, can be used to communicate | |
1398 | with the session daemon using a C API that hides the underlying | |
1399 | protocol'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 | ||
1408 | Some objects are referred by name (C string), such as tracing sessions, | |
1409 | but 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. | |
1412 | Every function/structure is thoroughly documented. | |
1413 | ||
1414 | The `lttng` program is the _de facto_ standard user interface to | |
1415 | control LTTng tracing sessions. `lttng` uses `liblttng-ctl` to | |
1416 | communicate with session daemons behind the scenes. | |
1417 | Its man page, man:lttng(1), is exhaustive, as well as its command | |
1418 | line help (+lttng _cmd_ --help+, where +_cmd_+ is the command name). | |
1419 | ||
1420 | The <<controlling-tracing,Controlling tracing>> section is a feature | |
1421 | tour of the `lttng` tool. | |
1422 | ||
1423 | ||
1424 | [[lttng-ust]] | |
1425 | ==== User space tracing library | |
1426 | ||
1427 | The user space tracing part of LTTng is possible thanks to the user | |
1428 | space tracing library, `liblttng-ust`, which is part of the LTTng-UST | |
1429 | package. | |
1430 | ||
1431 | `liblttng-ust` provides header files containing macros used to define | |
1432 | tracepoints and create tracepoint providers, as well as a shared object | |
1433 | that must be linked to individual applications to connect to and | |
1434 | communicate with a session daemon and a consumer daemon as soon as the | |
1435 | application starts. | |
1436 | ||
1437 | The exact mechanism by which an application is registered to the | |
1438 | session daemon is beyond the scope of this documentation. The only thing | |
1439 | you need to know is that, since the library constructor does this job | |
1440 | automatically, tracepoints may be safely inserted anywhere in the source | |
1441 | code without prior manual initialization of `liblttng-ust`. | |
1442 | ||
1443 | The `liblttng-ust`-session daemon collaboration also provides an | |
1444 | interesting feature: user space events may be enabled _before_ | |
1445 | applications actually start. By doing this and starting tracing before | |
1446 | launching the instrumented application, you make sure that even the | |
1447 | earliest occurring events can be recorded. | |
1448 | ||
1449 | The <<c-application,C application>> instrumenting guide of the | |
1450 | <<using-lttng,Using LTTng>> chapter focuses on using `liblttng-ust`: | |
1451 | instrumenting, building/linking and running a user application. | |
1452 | ||
1453 | ||
1454 | [[lttng-modules]] | |
1455 | ==== LTTng kernel modules | |
1456 | ||
1457 | The LTTng Linux kernel modules provide everything needed to trace the | |
1458 | Linux kernel: various probes, a ring buffer implementation for a | |
1459 | consumer daemon to read trace data and the tracer itself. | |
1460 | ||
1461 | Only in exceptional circumstances should you ever need to load the | |
1462 | LTTng 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 | |
1464 | probe module, however--for tracing a custom kernel or some kernel | |
1465 | module (this topic is covered in the | |
1466 | <<instrumenting-linux-kernel,Linux kernel>> instrumenting guide of | |
1467 | the <<using-lttng,Using LTTng>> chapter)--you should either | |
1468 | load it manually, or use the `--kmod-probes` option of the session | |
1469 | daemon to load a specific list of kernel probes (beware, however, | |
1470 | that the `--kmod-probes` option specifies an _absolute_ list, which | |
1471 | means you also have to specify the default probes you need). The | |
1472 | session and consumer daemons of regular users do not interact with the | |
1473 | LTTng kernel modules at all. | |
1474 | ||
1475 | LTTng kernel modules are installed, by default, in | |
1476 | +/usr/lib/modules/_release_/extra+, where +_release_+ is the | |
1477 | kernel release (see `uname --kernel-release`). | |
1478 | ||
1479 | ||
1480 | [[using-lttng]] | |
1481 | == Using LTTng | |
1482 | ||
1483 | Using LTTng involves two main activities: **instrumenting** and | |
1484 | **controlling tracing**. | |
1485 | ||
1486 | _<<instrumenting,Instrumenting>>_ is the process of inserting probes | |
1487 | into some source code. It can be done manually, by writing tracepoint | |
1488 | calls at specific locations in the source code of the program to trace, | |
1489 | or more automatically using dynamic probes (address in assembled code, | |
1490 | symbol name, function entry/return, etc.). | |
1491 | ||
1492 | It has to be noted that, as an LTTng user, you may not have to worry | |
1493 | about the instrumentation process. Indeed, you may want to trace a | |
1494 | program already instrumented. As an example, the Linux kernel is | |
1495 | thoroughly instrumented, which is why you can trace it without caring | |
1496 | about adding probes. | |
1497 | ||
1498 | _<<controlling-tracing,Controlling tracing>>_ is everything | |
1499 | that can be done by the LTTng session daemon, which is controlled using | |
1500 | `liblttng-ctl` or its command line utility, `lttng`: creating tracing | |
1501 | sessions, listing tracing sessions and events, enabling/disabling | |
1502 | events, starting/stopping the tracers, taking snapshots, etc. | |
1503 | ||
1504 | This chapter is a complete user guide of both activities, | |
1505 | with common use cases of LTTng exposed throughout the text. It is | |
1506 | assumed that you are familiar with LTTng's concepts (events, channels, | |
1507 | domains, tracing sessions) and that you understand the roles of its | |
1508 | components (daemons, libraries, command line tools); if not, we invite | |
1509 | you to read the <<understanding-lttng,Understanding LTTng>> chapter | |
1510 | before you begin reading this one. | |
1511 | ||
1512 | If you're new to LTTng, we suggest that you rather start with the | |
1513 | <<getting-started,Getting started>> small guide first, then come | |
1514 | back here to broaden your knowledge. | |
1515 | ||
1516 | If you're only interested in tracing the Linux kernel with its current | |
1517 | instrumentation, you may skip the | |
1518 | <<instrumenting,Instrumenting>> section. | |
1519 | ||
1520 | ||
1521 | [[instrumenting]] | |
1522 | === Instrumenting | |
1523 | ||
1524 | There are many examples of tracing and monitoring in our everyday life. | |
1525 | You have access to real-time and historical weather reports and forecasts | |
1526 | thanks to weather stations installed around the country. You know your | |
1527 | possibly hospitalized friends' and family's hearts are safe thanks to | |
1528 | electrocardiography. You make sure not to drive your car too fast | |
1529 | and have enough fuel to reach your destination thanks to gauges visible | |
1530 | on your dashboard. | |
1531 | ||
1532 | All the previous examples have something in common: they rely on | |
1533 | **probes**. Without electrodes attached to the surface of a body's | |
1534 | skin, cardiac monitoring would be futile. | |
1535 | ||
1536 | LTTng, as a tracer, is no different from the real life examples above. | |
1537 | If you're about to trace a software system, i.e. record its history of | |
1538 | execution, you better have probes in the subject you're | |
1539 | tracing: the actual software. Various ways were developed to do this. | |
1540 | The most straightforward one is to manually place probes, called | |
1541 | _tracepoints_, in the software's source code. The Linux kernel tracing | |
1542 | domain also allows probes added dynamically. | |
1543 | ||
1544 | If you're only interested in tracing the Linux kernel, it may very well | |
1545 | be that your tracing needs are already appropriately covered by LTTng's | |
1546 | built-in Linux kernel tracepoints and other probes. Or you may be in | |
1547 | possession of a user space application which has already been | |
1548 | instrumented. In such cases, the work will reside entirely in the design | |
1549 | and execution of tracing sessions, allowing you to jump to | |
1550 | <<controlling-tracing,Controlling tracing>> right now. | |
1551 | ||
1552 | This 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 | ||
1561 | Some advanced techniques are also presented at the very end of this | |
1562 | chapter. | |
1563 | ||
1564 | ||
1565 | [[c-application]] | |
1566 | ==== C application | |
1567 | ||
1568 | Instrumenting a C (or $$C++$$) application, be it an executable program or | |
1569 | a library, implies using LTTng-UST, the | |
1570 | user space tracing component of LTTng. For C/$$C++$$ applications, the | |
1571 | LTTng-UST package includes a dynamically loaded library | |
1572 | (`liblttng-ust`), C headers and the `lttng-gen-tp` command line utility. | |
1573 | ||
1574 | Since C and $$C++$$ are the base languages of virtually all other | |
1575 | programming languages | |
1576 | (Java virtual machine, Python, Perl, PHP and Node.js interpreters, etc.), | |
1577 | implementing user space tracing for an unsupported language is just a | |
1578 | matter of using the LTTng-UST C API at the right places. | |
1579 | ||
1580 | The usual work flow to instrument a user space C application with | |
1581 | LTTng-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 | ||
1589 | The steps above are discussed in greater detail in the following | |
1590 | subsections. | |
1591 | ||
1592 | ||
1593 | [[tracepoint-provider]] | |
1594 | ===== Tracepoint provider | |
1595 | ||
1596 | Before jumping into defining tracepoints and inserting | |
1597 | them into the application source code, you must understand what a | |
1598 | _tracepoint provider_ is. | |
1599 | ||
1600 | For 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 | ||
1616 | TRACEPOINT_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 | ||
1629 | TRACEPOINT_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 | ||
1653 | The two files above are defining a _tracepoint provider_. A tracepoint | |
1654 | provider is some sort of namespace for _tracepoint definitions_. Tracepoint | |
1655 | definitions are written above with the `TRACEPOINT_EVENT()` macro, and allow | |
1656 | eventual `tracepoint()` calls respecting their definitions to be inserted | |
1657 | into the user application's C source code (we explore this in a | |
1658 | later section). | |
1659 | ||
1660 | Many tracepoint definitions may be part of the same tracepoint provider | |
1661 | and many tracepoint providers may coexist in a user space application. A | |
1662 | tracepoint 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 | ||
1669 | The two files above, path:{tp.h} and path:{tp.c}, show a typical template for | |
1670 | writing a tracepoint provider. LTTng-UST was designed so that two | |
1671 | tracepoint providers should not be defined in the same header file. | |
1672 | ||
1673 | We will now go through the various parts of the above files and | |
1674 | give them a meaning. As you may have noticed, the LTTng-UST API for | |
1675 | C/$$C++$$ applications is some preprocessor sorcery. The LTTng-UST macros | |
1676 | used in your application and those in the LTTng-UST headers are | |
1677 | combined to produce actual source code needed to make tracing possible | |
1678 | using LTTng. | |
1679 | ||
1680 | Let'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 | |
1689 | following tracepoint definitions will belong. It is used internally by | |
1690 | LTTng-UST headers and _must_ be defined. Since `TRACEPOINT_PROVIDER` | |
1691 | could have been defined by another header file also included by the same | |
1692 | C source file, the best practice is to undefine it first. | |
1693 | ||
1694 | NOTE: Names in LTTng-UST follow the C | |
1695 | _identifier_ syntax (starting with a letter and containing either | |
1696 | letters, numbers or underscores); they are _not_ C strings | |
1697 | (not surrounded by double quotes). This is because LTTng-UST macros | |
1698 | use those identifier-like strings to create symbols (named types and | |
1699 | variables). | |
1700 | ||
1701 | The tracepoint provider is a group of tracepoint definitions; its chosen | |
1702 | name should reflect this. A hierarchy like Java packages is recommended, | |
1703 | using underscores instead of dots, e.g., `org_company_project_component`. | |
1704 | ||
1705 | Next is `TRACEPOINT_INCLUDE`: | |
1706 | ||
1707 | [source,c] | |
1708 | ---- | |
1709 | #undef TRACEPOINT_INCLUDE | |
1710 | #define TRACEPOINT_INCLUDE "./tp.h" | |
1711 | ---- | |
1712 | ||
1713 | This little bit of instrospection is needed by LTTng-UST to include | |
1714 | your header at various predefined places. | |
1715 | ||
1716 | Include guard follows: | |
1717 | ||
1718 | [source,c] | |
1719 | ---- | |
1720 | #if !defined(_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ) | |
1721 | #define _TP_H | |
1722 | ---- | |
1723 | ||
1724 | Add these precompiler conditionals to ensure the tracepoint event | |
1725 | generation can include this file more than once. | |
1726 | ||
1727 | The `TRACEPOINT_EVENT()` macro is defined in a LTTng-UST header file which | |
1728 | must be included: | |
1729 | ||
1730 | [source,c] | |
1731 | ---- | |
1732 | #include <lttng/tracepoint.h> | |
1733 | ---- | |
1734 | ||
1735 | This will also allow the application to use the `tracepoint()` macro. | |
1736 | ||
1737 | Next is a list of `TRACEPOINT_EVENT()` macro calls which create the | |
1738 | actual tracepoint definitions. We will skip this for the moment and | |
1739 | come back to how to use `TRACEPOINT_EVENT()` | |
1740 | <<defining-tracepoints,in a later section>>. Just pay attention to | |
1741 | the first argument: it's always the name of the tracepoint provider | |
1742 | being defined in this header file. | |
1743 | ||
1744 | End of include guard: | |
1745 | ||
1746 | [source,c] | |
1747 | ---- | |
1748 | #endif /* _TP_H */ | |
1749 | ---- | |
1750 | ||
1751 | Finally, include `<lttng/tracepoint-event.h>` to expand the macros: | |
1752 | ||
1753 | [source,c] | |
1754 | ---- | |
1755 | #include <lttng/tracepoint-event.h> | |
1756 | ---- | |
1757 | ||
1758 | That's it for path:{tp.h}. Of course, this is only a header file; it must be | |
1759 | included in some C source file to actually use it. This is the job of | |
1760 | path:{tp.c}: | |
1761 | ||
1762 | [source,c] | |
1763 | ---- | |
1764 | #define TRACEPOINT_CREATE_PROBES | |
1765 | ||
1766 | #include "tp.h" | |
1767 | ---- | |
1768 | ||
1769 | When `TRACEPOINT_CREATE_PROBES` is defined, the macros used in path:{tp.h}, | |
1770 | which is included just after, will actually create the source code for | |
1771 | LTTng-UST probes (global data structures and functions) out of your | |
1772 | tracepoint definitions. How exactly this is done is out of this text's scope. | |
1773 | `TRACEPOINT_CREATE_PROBES` is discussed further | |
1774 | in | |
1775 | <<building-tracepoint-providers-and-user-application,Building/linking | |
1776 | tracepoint providers and the user application>>. | |
1777 | ||
1778 | You could include other header files like path:{tp.h} here to create the probes | |
1779 | of 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 | ||
1789 | The rule is: probes of a given tracepoint provider | |
1790 | must be created in exactly one source file. This source file could be one | |
1791 | of your project's; it doesn't have to be on its own like | |
1792 | path:{tp.c}, although | |
1793 | <<building-tracepoint-providers-and-user-application,a later section>> | |
1794 | shows that doing so allows packaging the tracepoint providers | |
1795 | independently and keep them out of your application, also making it | |
1796 | possible to reuse them between projects. | |
1797 | ||
1798 | The following sections explain how to define tracepoints, how to use the | |
1799 | `tracepoint()` macro to instrument your user space C application and how | |
1800 | to build/link tracepoint providers and your application with LTTng-UST | |
1801 | support. | |
1802 | ||
1803 | ||
1804 | [[lttng-gen-tp]] | |
1805 | ===== Using `lttng-gen-tp` | |
1806 | ||
1807 | LTTng-UST ships with `lttng-gen-tp`, a handy command line utility for | |
1808 | generating most of the stuff discussed above. It takes a _template file_, | |
1809 | with a name usually ending with the `.tp` extension, containing only | |
1810 | tracepoint definitions, and outputs a tracepoint provider (either a C | |
1811 | source file or a precompiled object file) with its header file. | |
1812 | ||
1813 | `lttng-gen-tp` should suffice in <<static-linking,static linking>> | |
1814 | situations. When using it, write a template file containing a list of | |
1815 | `TRACEPOINT_EVENT()` macro calls. The tool will find the provider names | |
1816 | used and generate the appropriate files which are going to look a lot | |
1817 | like path:{tp.h} and path:{tp.c} above. | |
1818 | ||
1819 | Just call `lttng-gen-tp` like this: | |
1820 | ||
1821 | [role="term"] | |
1822 | ---- | |
1823 | lttng-gen-tp my-template.tp | |
1824 | ---- | |
1825 | ||
1826 | path:{my-template.c}, path:{my-template.o} and path:{my-template.h} | |
1827 | will be created in the same directory. | |
1828 | ||
1829 | You 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 | ---- | |
1834 | CFLAGS=-I/custom/include/path lttng-gen-tp my-template.tp | |
1835 | ---- | |
1836 | ||
1837 | For more information on `lttng-gen-tp`, see man:lttng-gen-tp(1). | |
1838 | ||
1839 | ||
1840 | [[defining-tracepoints]] | |
1841 | ===== Defining tracepoints | |
1842 | ||
1843 | As written in <<tracepoint-provider,Tracepoint provider>>, | |
1844 | tracepoints 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 | |
1847 | a specific event type with its own fields. | |
1848 | ||
1849 | Let's have another look at the example above, with a few added comments: | |
1850 | ||
1851 | [source,c] | |
1852 | ---- | |
1853 | TRACEPOINT_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 | ||
1874 | The tracepoint provider name must match the name of the tracepoint | |
1875 | provider in which this tracepoint is defined | |
1876 | (see <<tracepoint-provider,Tracepoint provider>>). In other words, | |
1877 | always use the same string as the value of `TRACEPOINT_PROVIDER` above. | |
1878 | ||
1879 | The tracepoint name will become the event name once events are recorded | |
1880 | by the LTTng-UST tracer. It must follow the tracepoint provider name | |
1881 | syntax: start with a letter and contain either letters, numbers or | |
1882 | underscores. Two tracepoints under the same provider cannot have the | |
1883 | same name, i.e. you cannot overload a tracepoint like you would | |
1884 | overload functions and methods in $$C++$$/Java. | |
1885 | ||
1886 | NOTE: The concatenation of the tracepoint | |
1887 | provider name and the tracepoint name cannot exceed 254 characters. If | |
1888 | it does, the instrumented application will compile and run, but LTTng | |
1889 | will issue multiple warnings and you could experience serious problems. | |
1890 | ||
1891 | The list of tracepoint arguments gives this tracepoint its signature: | |
1892 | see it like the declaration of a C function. The format of `TP_ARGS()` | |
1893 | arguments is: C type, then argument name; repeat as needed, up to ten | |
1894 | times. For example, if we were to replicate the signature of C standard | |
1895 | library'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 | ||
1906 | Of course, you will need to include appropriate header files before | |
1907 | the `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 | |
1910 | also accepted. | |
1911 | ||
1912 | The list of fields is where the fun really begins. The fields defined | |
1913 | in this list will be the fields of the events generated by the execution | |
1914 | of this tracepoint. Each tracepoint field definition has a C | |
1915 | _argument expression_ which will be evaluated when the execution reaches | |
1916 | the tracepoint. Tracepoint arguments _may be_ used freely in those | |
1917 | argument expressions, but they _don't_ have to. | |
1918 | ||
1919 | There are several types of tracepoint fields available. The macros to | |
1920 | define them are given and explained in the | |
1921 | <<liblttng-ust-tp-fields,LTTng-UST library reference>> section. | |
1922 | ||
1923 | Field names must follow the standard C identifier syntax: letter, then | |
1924 | optional sequence of letters, numbers or underscores. Each field must have | |
1925 | a different name. | |
1926 | ||
1927 | Those `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_ | |
1930 | accepted. | |
1931 | ||
1932 | The following snippet shows how argument expressions may be used in | |
1933 | tracepoint 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 | ||
1942 | TRACEPOINT_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 | ||
2012 | As you can see, having a custom argument expression for each field | |
2013 | makes tracepoints very flexible for tracing a user space C application. | |
2014 | This tracepoint definition is reused later in this guide, when | |
2015 | actually using tracepoints in a user space application. | |
2016 | ||
2017 | ||
2018 | [[using-tracepoint-classes]] | |
2019 | ===== Using tracepoint classes | |
2020 | ||
2021 | In LTTng-UST, a _tracepoint class_ is a class of tracepoints sharing the | |
2022 | same field types and names. A _tracepoint instance_ is one instance of | |
2023 | such a declared tracepoint class, with its own event name and tracepoint | |
2024 | provider name. | |
2025 | ||
2026 | What is documented in <<defining-tracepoints,Defining tracepoints>> | |
2027 | is actually how to declare a _tracepoint class_ and define a | |
2028 | _tracepoint instance_ at the same time. Without revealing the internals | |
2029 | of LTTng-UST too much, it has to be noted that one serialization | |
2030 | function is created for each tracepoint class. A serialization | |
2031 | function is responsible for serializing the fields of a tracepoint | |
2032 | into a sub-buffer when tracing. For various performance reasons, when | |
2033 | your situation requires multiple tracepoints with different names, but | |
2034 | with the same fields layout, the best practice is to manually create | |
2035 | a tracepoint class and instantiate as many tracepoint instances as | |
2036 | needed. One positive effect of such a design, amongst other advantages, | |
2037 | is that all tracepoint instances of the same tracepoint class will | |
2038 | reuse the same serialization function, thus reducing cache pollution. | |
2039 | ||
2040 | As an example, here are three tracepoint definitions as we know them: | |
2041 | ||
2042 | [source,c] | |
2043 | ---- | |
2044 | TRACEPOINT_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 | ||
2057 | TRACEPOINT_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 | ||
2070 | TRACEPOINT_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 | ||
2084 | In this case, three tracepoint classes are created, with one tracepoint | |
2085 | instance for each of them: `get_account`, `get_settings` and | |
2086 | `get_transaction`. However, they all share the same field names and | |
2087 | types. Declaring one tracepoint class and three tracepoint instances of | |
2088 | the latter is a better design choice: | |
2089 | ||
2090 | [source,c] | |
2091 | ---- | |
2092 | /* the tracepoint class */ | |
2093 | TRACEPOINT_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 */ | |
2114 | TRACEPOINT_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 | ) | |
2130 | TRACEPOINT_EVENT_INSTANCE( | |
2131 | my_app, | |
2132 | my_class, | |
2133 | get_settings, | |
2134 | TP_ARGS( | |
2135 | int, userid, | |
2136 | size_t, len | |
2137 | ) | |
2138 | ) | |
2139 | TRACEPOINT_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 | ||
2150 | Of course, all those names and `TP_ARGS()` invocations are redundant, | |
2151 | but 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 | ||
2161 | TRACEPOINT_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 | ||
2179 | MY_APP_TRACEPOINT_INSTANCE(get_account) | |
2180 | MY_APP_TRACEPOINT_INSTANCE(get_settings) | |
2181 | MY_APP_TRACEPOINT_INSTANCE(get_transaction) | |
2182 | ---- | |
2183 | ||
2184 | ||
2185 | [[assigning-log-levels]] | |
2186 | ===== Assigning log levels to tracepoints | |
2187 | ||
2188 | Optionally, a log level can be assigned to a defined tracepoint. | |
2189 | Assigning different levels of importance to tracepoints can be useful; | |
2190 | when controlling tracing sessions, | |
2191 | <<controlling-tracing,you can choose>> to only enable tracepoints | |
2192 | falling into a specific log level range. | |
2193 | ||
2194 | Log levels are assigned to defined tracepoints using the | |
2195 | `TRACEPOINT_LOGLEVEL()` macro. The latter must be used _after_ having | |
2196 | used `TRACEPOINT_EVENT()` for a given tracepoint. The | |
2197 | `TRACEPOINT_LOGLEVEL()` macro has the following construct: | |
2198 | ||
2199 | [source,c] | |
2200 | ---- | |
2201 | TRACEPOINT_LOGLEVEL(PROVIDER_NAME, TRACEPOINT_NAME, LOG_LEVEL) | |
2202 | ---- | |
2203 | ||
2204 | where the first two arguments are the same as the first two arguments | |
2205 | of `TRACEPOINT_EVENT()` and `LOG_LEVEL` is one | |
2206 | of the values given in the | |
2207 | <<liblttng-ust-tracepoint-loglevel,LTTng-UST library reference>> | |
2208 | section. | |
2209 | ||
2210 | As an example, let's assign a `TRACE_DEBUG_UNIT` log level to our | |
2211 | previous tracepoint definition: | |
2212 | ||
2213 | [source,c] | |
2214 | ---- | |
2215 | TRACEPOINT_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 | ||
2222 | Once tracepoints are properly defined within a tracepoint provider, | |
2223 | they may be inserted into the user application to be instrumented | |
2224 | using the `tracepoint()` macro. Its first argument is the tracepoint | |
2225 | provider name and its second is the tracepoint name. The next, optional | |
2226 | arguments are defined by the `TP_ARGS()` part of the definition of | |
2227 | the tracepoint to use. | |
2228 | ||
2229 | As an example, let us again take the following tracepoint definition: | |
2230 | ||
2231 | [source,c] | |
2232 | ---- | |
2233 | TRACEPOINT_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 | ||
2254 | Assuming this is part of a file named path:{tp.h} which defines the tracepoint | |
2255 | provider and which is included by path:{tp.c}, here's a complete C application | |
2256 | calling this tracepoint (multiple times): | |
2257 | ||
2258 | [source,c] | |
2259 | ---- | |
2260 | #define TRACEPOINT_DEFINE | |
2261 | #include "tp.h" | |
2262 | ||
2263 | int 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 | ||
2277 | For each tracepoint provider, `TRACEPOINT_DEFINE` must be defined into | |
2278 | exactly one translation unit (C source file) of the user application, | |
2279 | before including the tracepoint provider header file. In other words, | |
2280 | for a given tracepoint provider, you cannot define `TRACEPOINT_DEFINE`, | |
2281 | and then include its header file in two separate C source files of | |
2282 | the same application. `TRACEPOINT_DEFINE` is discussed further in | |
2283 | <<building-tracepoint-providers-and-user-application,Building/linking | |
2284 | tracepoint providers and the user application>>. | |
2285 | ||
2286 | As another example, remember this definition we wrote in a previous | |
2287 | section (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 | ||
2296 | TRACEPOINT_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 | ||
2319 | Here's an example of calling it: | |
2320 | ||
2321 | [source,c] | |
2322 | ---- | |
2323 | #define TRACEPOINT_DEFINE | |
2324 | #include "tp.h" | |
2325 | ||
2326 | int 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 | ||
2338 | When viewing the trace, assuming the file size of path:{/etc/fstab} is | |
2339 | 301{nbsp}bytes, the event generated by the execution of this tracepoint | |
2340 | should have the following fields, in this order: | |
2341 | ||
2342 | ---- | |
2343 | my_constant_field 40 | |
2344 | my_int_arg_field 23 | |
2345 | my_int_arg_field2 529 | |
2346 | sum4_field 389 | |
2347 | my_str_arg_field "Hello, World!" | |
2348 | size_field 0x12d | |
2349 | size_dbl_field 301.0 | |
2350 | half_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 | ||
2357 | The final step of using LTTng-UST for tracing a user space C application | |
2358 | (beside running the application) is building and linking tracepoint | |
2359 | providers and the application itself. | |
2360 | ||
2361 | As discussed above, the macros used by the user-written tracepoint provider | |
2362 | header file are useless until actually used to create probes code | |
2363 | (global data structures and functions) in a translation unit (C source file). | |
2364 | This is accomplished by defining `TRACEPOINT_CREATE_PROBES` in a translation | |
2365 | unit and then including the tracepoint provider header file. | |
2366 | When `TRACEPOINT_CREATE_PROBES` is defined, macros used and included by | |
2367 | the tracepoint provider header will output actual source code needed by any | |
2368 | application using the defined tracepoints. Defining | |
2369 | `TRACEPOINT_CREATE_PROBES` produces code used when registering | |
2370 | tracepoint providers when the tracepoint provider package loads. | |
2371 | ||
2372 | The other important definition is `TRACEPOINT_DEFINE`. This one creates | |
2373 | global, per-tracepoint structures referencing the tracepoint providers | |
2374 | data. Those structures are required by the actual functions inserted | |
2375 | where `tracepoint()` macros are placed and need to be defined by the | |
2376 | instrumented application. | |
2377 | ||
2378 | Both `TRACEPOINT_CREATE_PROBES` and `TRACEPOINT_DEFINE` need to be defined | |
2379 | at some places in order to trace a user space C application using LTTng. | |
2380 | Although explaining their exact mechanism is beyond the scope of this | |
2381 | document, the reason they both exist separately is to allow the trace | |
2382 | providers to be packaged as a shared object (dynamically loaded library). | |
2383 | ||
2384 | There are two ways to compile and link the tracepoint providers | |
2385 | with the application: _<<static-linking,statically>>_ or | |
2386 | _<<dynamic-linking,dynamically>>_. Both methods are covered in the | |
2387 | following subsections. | |
2388 | ||
2389 | ||
2390 | [[static-linking]] | |
2391 | ===== Static linking the tracepoint providers to the application | |
2392 | ||
2393 | With the static linking method, compiled tracepoint providers are copied | |
2394 | into 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 | ||
2403 | The first approach is to define `TRACEPOINT_CREATE_PROBES` and include | |
2404 | your tracepoint provider(s) header file(s) directly into an existing C | |
2405 | source 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 | ||
2419 | int 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 | ||
2431 | Again, before including a given tracepoint provider header file, | |
2432 | `TRACEPOINT_CREATE_PROBES` and `TRACEPOINT_DEFINE` must be defined in | |
2433 | one, **and only one**, translation unit. Other C source files of the | |
2434 | same application may include path:{tp.h} to use tracepoints with | |
2435 | the `tracepoint()` macro, but must not define | |
2436 | `TRACEPOINT_CREATE_PROBES`/`TRACEPOINT_DEFINE` again. | |
2437 | ||
2438 | This translation unit may be built as an object file by making sure to | |
2439 | add `.` to the include path: | |
2440 | ||
2441 | [role="term"] | |
2442 | ---- | |
2443 | gcc -c -I. file.c | |
2444 | ---- | |
2445 | ||
2446 | The second approach is to isolate the tracepoint provider code into a | |
2447 | separate 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 | |
2457 | application. Since we're talking about static linking here, it could as | |
2458 | well 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 | ||
2468 | This is actually what <<lttng-gen-tp,`lttng-gen-tp`>> does, and is | |
2469 | the recommended practice. | |
2470 | ||
2471 | Build the tracepoint provider: | |
2472 | ||
2473 | [role="term"] | |
2474 | ---- | |
2475 | gcc -c -I. tp.c | |
2476 | ---- | |
2477 | ||
2478 | Finally, the resulting object file may be archived to create a | |
2479 | more portable tracepoint provider static library: | |
2480 | ||
2481 | [role="term"] | |
2482 | ---- | |
2483 | ar rc tp.a tp.o | |
2484 | ---- | |
2485 | ||
2486 | Using a static library does have the advantage of centralising the | |
2487 | tracepoint providers objects so they can be shared between multiple | |
2488 | applications. This way, when the tracepoint provider is modified, the | |
2489 | source code changes don't have to be patched into each application's source | |
2490 | code tree. The applications need to be relinked after each change, but need | |
2491 | not to be otherwise recompiled (unless the tracepoint provider's API | |
2492 | changes). | |
2493 | ||
2494 | Regardless of which method you choose, you end up with an object file | |
2495 | (potentially archived) containing the trace providers assembled code. | |
2496 | To link this code with the rest of your application, you must also link | |
2497 | with `liblttng-ust` and `libdl`: | |
2498 | ||
2499 | [role="term"] | |
2500 | ---- | |
2501 | gcc -o app tp.o other.o files.o of.o your.o app.o -llttng-ust -ldl | |
2502 | ---- | |
2503 | ||
2504 | or | |
2505 | ||
2506 | [role="term"] | |
2507 | ---- | |
2508 | gcc -o app tp.a other.o files.o of.o your.o app.o -llttng-ust -ldl | |
2509 | ---- | |
2510 | ||
2511 | If you're using a BSD | |
2512 | system, replace `-ldl` with `-lc`: | |
2513 | ||
2514 | [role="term"] | |
2515 | ---- | |
2516 | gcc -o app tp.a other.o files.o of.o your.o app.o -llttng-ust -lc | |
2517 | ---- | |
2518 | ||
2519 | The application can be started as usual, e.g.: | |
2520 | ||
2521 | [role="term"] | |
2522 | ---- | |
2523 | ./app | |
2524 | ---- | |
2525 | ||
2526 | The `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 | ||
2533 | The second approach to package the tracepoint providers is to use | |
2534 | dynamic linking: the library and its member functions are explicitly | |
2535 | sought, loaded and unloaded at runtime using `libdl`. | |
2536 | ||
2537 | It has to be noted that, for a variety of reasons, the created shared | |
2538 | library will be dynamically _loaded_, as opposed to dynamically | |
2539 | _linked_. The tracepoint provider shared object is, however, linked | |
2540 | with `liblttng-ust`, so that `liblttng-ust` is guaranteed to be loaded | |
2541 | as soon as the tracepoint provider is. If the tracepoint provider is | |
2542 | not loaded, since the application itself is not linked with | |
2543 | `liblttng-ust`, the latter is not loaded at all and the tracepoint calls | |
2544 | become inert. | |
2545 | ||
2546 | The process to create the tracepoint provider shared object is pretty | |
2547 | much 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 | ||
2556 | Regarding `TRACEPOINT_DEFINE` and `TRACEPOINT_PROBE_DYNAMIC_LINKAGE`, | |
2557 | the recommended practice is to use a separate C source file in your | |
2558 | application to define them, and then include the tracepoint provider | |
2559 | header 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 | |
2574 | LTTng-UST headers) aware that the tracepoint provider is to be loaded | |
2575 | dynamically and not part of the application's executable. | |
2576 | ||
2577 | The tracepoint provider object file used to create the shared library | |
2578 | is built like it is using the static library method, only with the | |
2579 | `-fpic` option added: | |
2580 | ||
2581 | [role="term"] | |
2582 | ---- | |
2583 | gcc -c -fpic -I. tp.c | |
2584 | ---- | |
2585 | ||
2586 | It is then linked as a shared library like this: | |
2587 | ||
2588 | [role="term"] | |
2589 | ---- | |
2590 | gcc -shared -Wl,--no-as-needed -o tp.so -llttng-ust tp.o | |
2591 | ---- | |
2592 | ||
2593 | As previously stated, this tracepoint provider shared object isn't | |
2594 | linked with the user application: it will be loaded manually. This is | |
2595 | why the application is built with no mention of this tracepoint | |
2596 | provider, but still needs `libdl`: | |
2597 | ||
2598 | [role="term"] | |
2599 | ---- | |
2600 | gcc -o app other.o files.o of.o your.o app.o -ldl | |
2601 | ---- | |
2602 | ||
2603 | Now, to make LTTng-UST tracing available to the application, the | |
2604 | `LD_PRELOAD` environment variable is used to preload the tracepoint | |
2605 | provider shared library _before_ the application actually starts: | |
2606 | ||
2607 | [role="term"] | |
2608 | ---- | |
2609 | LD_PRELOAD=/path/to/tp.so ./app | |
2610 | ---- | |
2611 | ||
2612 | [NOTE] | |
2613 | ==== | |
2614 | It is not safe to use | |
2615 | `dlclose()` on a tracepoint provider shared object that | |
2616 | is being actively used for tracing, due to a lack of reference | |
2617 | counting from LTTng-UST to the shared object. | |
2618 | ||
2619 | For example, statically linking a tracepoint provider to a | |
2620 | shared object which is to be dynamically loaded by an application | |
2621 | (e.g., a plugin) is not safe: the shared object, which contains the | |
2622 | tracepoint provider, could be dynamically closed | |
2623 | (`dlclose()`) at any time by the application. | |
2624 | ||
2625 | To 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 | ||
2634 | Your application will still work without this preloading, albeit without | |
2635 | LTTng-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 | ||
2646 | Some extra care is needed when using `liblttng-ust` with daemon | |
2647 | applications that call `fork()`, `clone()` or BSD's `rfork()` without | |
2648 | a following `exec()` family system call. The `liblttng-ust-fork` | |
2649 | library must be preloaded for the application. | |
2650 | ||
2651 | Example: | |
2652 | ||
2653 | [role="term"] | |
2654 | ---- | |
2655 | LD_PRELOAD=liblttng-ust-fork.so ./app | |
2656 | ---- | |
2657 | ||
2658 | Or, if you're using a tracepoint provider shared library: | |
2659 | ||
2660 | [role="term"] | |
2661 | ---- | |
2662 | LD_PRELOAD="liblttng-ust-fork.so /path/to/tp.so" ./app | |
2663 | ---- | |
2664 | ||
2665 | ||
2666 | [[lttng-ust-pkg-config]] | |
2667 | ===== Using pkg-config | |
2668 | ||
2669 | On some distributions, LTTng-UST is shipped with a pkg-config metadata | |
2670 | file, so that you may use the `pkg-config` tool: | |
2671 | ||
2672 | [role="term"] | |
2673 | ---- | |
2674 | pkg-config --libs lttng-ust | |
2675 | ---- | |
2676 | ||
2677 | This will return `-llttng-ust -ldl` on Linux systems. | |
2678 | ||
2679 | You may also check the LTTng-UST version using `pkg-config`: | |
2680 | ||
2681 | [role="term"] | |
2682 | ---- | |
2683 | pkg-config --modversion lttng-ust | |
2684 | ---- | |
2685 | ||
2686 | For more information about pkg-config, see | |
2687 | http://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 | |
2694 | tracepoints and tracepoint providers. The signature of `tracef()` is | |
2695 | the same as `printf()`'s. | |
2696 | ||
2697 | The `tracef()` utility function was developed to make user space tracing | |
2698 | super simple, albeit with notable disadvantages compared to custom, | |
2699 | full-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 | ||
2714 | Thus, `tracef()` is useful for quick prototyping and debugging, but | |
2715 | should not be considered for any permanent/serious application | |
2716 | instrumentation. | |
2717 | ||
2718 | To use `tracef()`, first include `<lttng/tracef.h>` in the C source file | |
2719 | where you need to insert probes: | |
2720 | ||
2721 | [source,c] | |
2722 | ---- | |
2723 | #include <lttng/tracef.h> | |
2724 | ---- | |
2725 | ||
2726 | Use `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 | ||
2737 | Link your application with `liblttng-ust`: | |
2738 | ||
2739 | [role="term"] | |
2740 | ---- | |
2741 | gcc -o app app.c -llttng-ust | |
2742 | ---- | |
2743 | ||
2744 | Execute the application as usual: | |
2745 | ||
2746 | [role="term"] | |
2747 | ---- | |
2748 | ./app | |
2749 | ---- | |
2750 | ||
2751 | Voilà ! Use the `lttng` command line tool to | |
2752 | <<controlling-tracing,control tracing>>. You can enable `tracef()` | |
2753 | events like this: | |
2754 | ||
2755 | [role="term"] | |
2756 | ---- | |
2757 | lttng 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 | ||
2764 | A few special environment variables and compile flags may affect the | |
2765 | behavior of LTTng-UST. | |
2766 | ||
2767 | LTTng-UST's debugging can be activated by setting the environment | |
2768 | variable `LTTNG_UST_DEBUG` to `1` when launching the application. It | |
2769 | can also be enabled at compile time by defining `LTTNG_UST_DEBUG` when | |
2770 | compiling LTTng-UST (using the `-DLTTNG_UST_DEBUG` compiler option). | |
2771 | ||
2772 | The environment variable `LTTNG_UST_REGISTER_TIMEOUT` can be used to | |
2773 | specify how long the application should wait for the | |
2774 | <<lttng-sessiond,session daemon>>'s _registration done_ command | |
2775 | before proceeding to execute the main program. The timeout value is | |
2776 | specified in milliseconds. 0 means _don't wait_. -1 means | |
2777 | _wait forever_. Setting this environment variable to 0 is recommended | |
2778 | for applications with time contraints on the process startup time. | |
2779 | ||
2780 | The default value of `LTTNG_UST_REGISTER_TIMEOUT` (when not defined) | |
2781 | is **3000{nbsp}ms**. | |
2782 | ||
2783 | The compilation definition `LTTNG_UST_DEBUG_VALGRIND` should be enabled | |
2784 | at build time (`-DLTTNG_UST_DEBUG_VALGRIND`) to allow `liblttng-ust` | |
2785 | to be used with http://valgrind.org/[Valgrind]. | |
2786 | The side effect of defining `LTTNG_UST_DEBUG_VALGRIND` is that per-CPU | |
2787 | buffering is disabled. | |
2788 | ||
2789 | ||
2790 | [[cxx-application]] | |
2791 | ==== $$C++$$ application | |
2792 | ||
2793 | Because of $$C++$$'s cross-compatibility with the C language, $$C++$$ | |
2794 | applications can be readily instrumented with the LTTng-UST C API. | |
2795 | ||
2796 | Follow the <<c-application,C application>> user guide above. It | |
2797 | should be noted that, in this case, tracepoint providers should have | |
2798 | the typical `.cpp`, `.cxx` or `.cc` extension and be built with `g++` | |
2799 | instead of `gcc`. This is the easiest way of avoiding linking errors | |
2800 | due to symbol name mangling incompatibilities between both languages. | |
2801 | ||
2802 | ||
2803 | [[prebuilt-ust-helpers]] | |
2804 | ==== Prebuilt user space tracing helpers | |
2805 | ||
2806 | The LTTng-UST package provides a few helpers that one may find | |
2807 | useful in some situations. They all work the same way: you must | |
2808 | preload the appropriate shared object before running the user | |
2809 | application (using the `LD_PRELOAD` environment variable). | |
2810 | ||
2811 | The shared objects are normally found in dir:{/usr/lib}. | |
2812 | ||
2813 | The current installed helpers are: | |
2814 | ||
2815 | path:{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 | ||
2819 | path:{liblttng-ust-cyg-profile.so} and path:{liblttng-ust-cyg-profile-fast.so}:: | |
2820 | <<liblttng-ust-cyg-profile,Function tracing>>. | |
2821 | ||
2822 | path:{liblttng-ust-dl.so}:: | |
2823 | <<liblttng-ust-dl,Dynamic linker tracing>>. | |
2824 | ||
2825 | The following subsections document what helpers instrument exactly | |
2826 | and how to use them. | |
2827 | ||
2828 | ||
2829 | [[liblttng-ust-libc-pthread-wrapper]] | |
2830 | ===== C standard library and POSIX threads tracing | |
2831 | ||
2832 | path:{liblttng-ust-libc-wrapper.so} and path:{liblttng-ust-pthread-wrapper.so} | |
2833 | can add instrumentation to respectively some C standard library and | |
2834 | POSIX threads functions. | |
2835 | ||
2836 | The 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 | ||
2851 | The following functions are traceable by | |
2852 | path:{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 | ||
2865 | All tracepoints have fields corresponding to the arguments of the | |
2866 | function they instrument. | |
2867 | ||
2868 | To use one or the other with any user application, independently of | |
2869 | how the latter is built, do: | |
2870 | ||
2871 | [role="term"] | |
2872 | ---- | |
2873 | LD_PRELOAD=liblttng-ust-libc-wrapper.so my-app | |
2874 | ---- | |
2875 | ||
2876 | or | |
2877 | ||
2878 | [role="term"] | |
2879 | ---- | |
2880 | LD_PRELOAD=liblttng-ust-pthread-wrapper.so my-app | |
2881 | ---- | |
2882 | ||
2883 | To use both, do: | |
2884 | ||
2885 | [role="term"] | |
2886 | ---- | |
2887 | LD_PRELOAD="liblttng-ust-libc-wrapper.so liblttng-ust-pthread-wrapper.so" my-app | |
2888 | ---- | |
2889 | ||
2890 | When the shared object is preloaded, it effectively replaces the | |
2891 | functions listed in the above tables by wrappers which add tracepoints | |
2892 | and call the replaced functions. | |
2893 | ||
2894 | Of course, like any other tracepoint, the ones above need to be enabled | |
2895 | in 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 | ||
2903 | Function tracing is the recording of which functions are entered and | |
2904 | left during the execution of an application. Like with any LTTng event, | |
2905 | the precise time at which this happens is also kept. | |
2906 | ||
2907 | GCC and clang have an option named | |
2908 | https://gcc.gnu.org/onlinedocs/gcc-4.9.1/gcc/Code-Gen-Options.html[`-finstrument-functions`] | |
2909 | which generates instrumentation calls for entry and exit to functions. | |
2910 | The LTTng-UST function tracing helpers, path:{liblttng-ust-cyg-profile.so} | |
2911 | and path:{liblttng-ust-cyg-profile-fast.so}, take advantage of this feature | |
2912 | to add instrumentation to the two generated functions (which contain | |
2913 | `cyg_profile` in their names, hence the shared object's name). | |
2914 | ||
2915 | In order to use LTTng-UST function tracing, the translation units to | |
2916 | instrument must be built using the `-finstrument-functions` compiler | |
2917 | flag. | |
2918 | ||
2919 | LTTng-UST function tracing comes in two flavors, each providing | |
2920 | different trade-offs: path:{liblttng-ust-cyg-profile-fast.so} and | |
2921 | path:{liblttng-ust-cyg-profile.so}. | |
2922 | ||
2923 | **path:{liblttng-ust-cyg-profile-fast.so}** is a lightweight variant that | |
2924 | should only be used where it can be _guaranteed_ that the complete event | |
2925 | stream is recorded without any missing events. Any kind of duplicate | |
2926 | information is left out. This version registers the following | |
2927 | tracepoints: | |
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` | |
2937 | a|Function entry | |
2938 | ||
2939 | `addr`:: | |
2940 | Address of called function. | |
2941 | ||
2942 | |`func_exit` | |
2943 | |Function exit | |
2944 | |==== | |
2945 | ||
2946 | Assuming no event is lost, having only the function addresses on entry | |
2947 | is enough for creating a call graph (remember that a recorded event | |
2948 | always contains the ID of the CPU that generated it). A tool like | |
2949 | https://sourceware.org/binutils/docs/binutils/addr2line.html[`addr2line`] | |
2950 | may be used to convert function addresses back to source files names | |
2951 | and line numbers. | |
2952 | ||
2953 | The other helper, | |
2954 | **path:{liblttng-ust-cyg-profile.so}**, | |
2955 | is a more robust variant which also works for use cases where | |
2956 | events might get discarded or not recorded from application startup. | |
2957 | In these cases, the trace analyzer needs extra information to be | |
2958 | able to reconstruct the program flow. This version registers the | |
2959 | following 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` | |
2969 | a|Function entry | |
2970 | ||
2971 | `addr`:: | |
2972 | Address of called function. | |
2973 | ||
2974 | `call_site`:: | |
2975 | Call site address. | |
2976 | ||
2977 | |`func_exit` | |
2978 | a|Function exit | |
2979 | ||
2980 | `addr`:: | |
2981 | Address of called function. | |
2982 | ||
2983 | `call_site`:: | |
2984 | Call site address. | |
2985 | |==== | |
2986 | ||
2987 | To use one or the other variant with any user application, assuming at | |
2988 | least one translation unit of the latter is compiled with the | |
2989 | `-finstrument-functions` option, do: | |
2990 | ||
2991 | [role="term"] | |
2992 | ---- | |
2993 | LD_PRELOAD=liblttng-ust-cyg-profile-fast.so my-app | |
2994 | ---- | |
2995 | ||
2996 | or | |
2997 | ||
2998 | [role="term"] | |
2999 | ---- | |
3000 | LD_PRELOAD=liblttng-ust-cyg-profile.so my-app | |
3001 | ---- | |
3002 | ||
3003 | It might be necessary to limit the number of source files where | |
3004 | `-finstrument-functions` is used to prevent excessive amount of trace | |
3005 | data to be generated at runtime. | |
3006 | ||
3007 | TIP: 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 | ||
3012 | All events generated from LTTng-UST function tracing are provided on | |
3013 | log level `TRACE_DEBUG_FUNCTION`, which is useful to easily enable | |
3014 | function 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 | ||
3022 | This LTTng-UST helper causes all calls to `dlopen()` and `dlclose()` | |
3023 | in the target application to be traced with LTTng. | |
3024 | ||
3025 | The helper's shared object, path:{liblttng-ust-dl.so}, registers the | |
3026 | following 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` | |
3036 | a|`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` | |
3053 | a|Function exit | |
3054 | ||
3055 | `baddr`:: | |
3056 | Memory base address (where the dynamic linker placed the shared | |
3057 | object). | |
3058 | |==== | |
3059 | ||
3060 | To use this LTTng-UST helper with any user application, independently of | |
3061 | how the latter is built, do: | |
3062 | ||
3063 | [role="term"] | |
3064 | ---- | |
3065 | LD_PRELOAD=liblttng-ust-dl.so my-app | |
3066 | ---- | |
3067 | ||
3068 | Of course, like any other tracepoint, the ones above need to be enabled | |
3069 | in 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 | ||
3077 | LTTng-UST provides a _logging_ back-end for Java applications using | |
3078 | http://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 | |
3080 | responsible for communications with an LTTng session daemon. | |
3081 | ||
3082 | From the user's point of view, once the LTTng-UST JUL agent has been | |
3083 | initialized, JUL loggers may be created and used as usual. The agent | |
3084 | adds its own handler to the _root logger_, so that all loggers may | |
3085 | generate LTTng events with no effort. | |
3086 | ||
3087 | Common 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 | ||
3094 | Here's an example: | |
3095 | ||
3096 | [source,java] | |
3097 | ---- | |
3098 | import java.util.logging.Logger; | |
3099 | import org.lttng.ust.jul.LTTngAgent; | |
3100 | ||
3101 | public 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 | ||
3125 | The LTTng-UST JUL agent Java classes are packaged in a JAR file named | |
3126 | path:{liblttng-ust-jul.jar}. It is typically located in | |
3127 | dir:{/usr/lib/lttng/java}. To compile the snippet above | |
3128 | (saved as path:{Test.java}), do: | |
3129 | ||
3130 | [role="term"] | |
3131 | ---- | |
3132 | javac -cp /usr/lib/lttng/java/liblttng-ust-jul.jar Test.java | |
3133 | ---- | |
3134 | ||
3135 | You can run the resulting compiled class: | |
3136 | ||
3137 | [role="term"] | |
3138 | ---- | |
3139 | java -cp /usr/lib/lttng/java/liblttng-ust-jul.jar:. Test | |
3140 | ---- | |
3141 | ||
3142 | NOTE: http://openjdk.java.net/[OpenJDK] 7 is used for development and | |
3143 | continuous integration, thus this version is directly supported. | |
3144 | However, the LTTng-UST JUL agent has also been tested with OpenJDK 6. | |
3145 | ||
3146 | ||
3147 | [[instrumenting-linux-kernel]] | |
3148 | ==== Linux kernel | |
3149 | ||
3150 | The Linux kernel can be instrumented for LTTng tracing, either its core | |
3151 | source code or a kernel module. It has to be noted that Linux is | |
3152 | readily traceable using LTTng since many parts of its source code are | |
3153 | already instrumented: this is the job of the upstream | |
3154 | http://git.lttng.org/?p=lttng-modules.git[LTTng-modules] | |
3155 | package. This section presents how to add LTTng instrumentation where it | |
3156 | does not currently exist and how to instrument custom kernel modules. | |
3157 | ||
3158 | All LTTng instrumentation in the Linux kernel is based on an existing | |
3159 | infrastructure which bears the name of its main macro, `TRACE_EVENT()`. | |
3160 | This macro is used to define tracepoints, | |
3161 | each tracepoint having a name, usually with the | |
3162 | +__subsys_____name__+ format, | |
3163 | +_subsys_+ being the subsystem name and | |
3164 | +_name_+ the specific event name. | |
3165 | ||
3166 | Tracepoints defined with `TRACE_EVENT()` may be inserted anywhere in | |
3167 | the Linux kernel source code, after what callbacks, called _probes_, | |
3168 | may be registered to execute some action when a tracepoint is | |
3169 | executed. This mechanism is directly used by ftrace and perf, | |
3170 | but cannot be used as is by LTTng: an adaptation layer is added to | |
3171 | satisfy LTTng's specific needs. | |
3172 | ||
3173 | With that in mind, this documentation does not cover the `TRACE_EVENT()` | |
3174 | format and how to use it, but it is mandatory to understand it and use | |
3175 | it to instrument Linux for LTTng. A series of | |
3176 | LWN articles explain | |
3177 | `TRACE_EVENT()` in details: | |
3178 | http://lwn.net/Articles/379903/[part 1], | |
3179 | http://lwn.net/Articles/381064/[part 2], and | |
3180 | http://lwn.net/Articles/383362/[part 3]. | |
3181 | Once you master `TRACE_EVENT()` enough for your use case, continue | |
3182 | reading this section so that you can add the LTTng adaptation layer of | |
3183 | instrumentation. | |
3184 | ||
3185 | This section first discusses the general method of instrumenting the | |
3186 | Linux kernel for LTTng. This method is then reused for the specific | |
3187 | case of instrumenting a kernel module. | |
3188 | ||
3189 | ||
3190 | [[instrumenting-linux-kernel-itself]] | |
3191 | ===== Instrumenting the Linux kernel for LTTng | |
3192 | ||
3193 | The following subsections explain strictly how to add custom LTTng | |
3194 | instrumentation to the Linux kernel. They do not explain how the | |
3195 | macros actually work and the internal mechanics of the tracer. | |
3196 | ||
3197 | You should have a Linux kernel source code tree to work with. | |
3198 | Throughout this section, all file paths are relative to the root of | |
3199 | this tree unless otherwise stated. | |
3200 | ||
3201 | You will need a copy of the LTTng-modules Git repository: | |
3202 | ||
3203 | [role="term"] | |
3204 | ---- | |
3205 | git clone git://git.lttng.org/lttng-modules.git | |
3206 | ---- | |
3207 | ||
3208 | The steps to add custom LTTng instrumentation to a Linux kernel | |
3209 | involves defining and using the mainline `TRACE_EVENT()` tracepoints | |
3210 | first, then writing and using the LTTng adaptation layer. | |
3211 | ||
3212 | ||
3213 | [[mainline-trace-event]] | |
3214 | ===== Defining/using tracepoints with mainline `TRACE_EVENT()` infrastructure | |
3215 | ||
3216 | The first step is to define tracepoints using the mainline Linux | |
3217 | `TRACE_EVENT()` macro and insert tracepoints where you want them. | |
3218 | Your tracepoint definitions reside in a header file in | |
3219 | dir:{include/trace/events}. If you're adding tracepoints to an existing | |
3220 | subsystem, edit its appropriate header file. | |
3221 | ||
3222 | As an example, the following header file (let's call it | |
3223 | path:{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 | ||
3237 | TRACE_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 | ||
3259 | Notice that we don't use any of the last three arguments: they | |
3260 | are 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 | |
3262 | to also use this tracepoint for ftrace/perf. | |
3263 | ||
3264 | Once this is done, you may place calls to `trace_hello_world()` | |
3265 | wherever you want in the Linux source code. As an example, let us place | |
3266 | such 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 */ | |
3272 | static 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 | ||
3284 | This tracepoint should fire every time a USB device is plugged in. | |
3285 | ||
3286 | At the top of path:{driver.c}, we need to include our actual tracepoint | |
3287 | definition 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 | ||
3302 | Build your custom Linux kernel. In order to use LTTng, make sure the | |
3303 | following 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 | ||
3310 | Boot the custom kernel. The directory | |
3311 | dir:{/sys/kernel/debug/tracing/events/hello} should exist if everything | |
3312 | went right, with a dir:{hello_world} subdirectory. | |
3313 | ||
3314 | ||
3315 | [[lttng-adaptation-layer]] | |
3316 | ===== Adding the LTTng adaptation layer | |
3317 | ||
3318 | The steps to write the LTTng adaptation layer are, in your | |
3319 | LTTng-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 | ||
3334 | Following our `hello_world` event example, here's the content of | |
3335 | path:{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 | ||
3347 | LTTNG_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 | ||
3383 | Some possible entries for `TP_STRUCT__entry()` and `TP_fast_assign()`, | |
3384 | in the case of LTTng-modules, are shown in the | |
3385 | <<lttng-modules-ref,LTTng-modules reference>> section. | |
3386 | ||
3387 | The best way to learn how to use the above macros is to inspect | |
3388 | existing LTTng tracepoint definitions in | |
3389 | dir:{instrumentation/events/lttng-module} header files. Compare | |
3390 | them with the Linux kernel mainline versions in | |
3391 | dir:{include/trace/events}. | |
3392 | ||
3393 | The next step is writing the LTTng probe kernel module C source file. | |
3394 | This one is named +lttng-probe-__subsys__.c+ | |
3395 | in 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 | ||
3414 | MODULE_LICENSE("GPL and additional rights"); | |
3415 | MODULE_AUTHOR("Your name <your-email>"); | |
3416 | MODULE_DESCRIPTION("LTTng hello probes"); | |
3417 | MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "." | |
3418 | __stringify(LTTNG_MODULES_MINOR_VERSION) "." | |
3419 | __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION) | |
3420 | LTTNG_MODULES_EXTRAVERSION); | |
3421 | ---- | |
3422 | ||
3423 | Just replace `hello` with your subsystem name. In this example, | |
3424 | `<trace/events/hello.h>`, which is the original mainline tracepoint | |
3425 | definition header, is included for verification purposes: the | |
3426 | LTTng-modules build system is able to emit an error at build time when | |
3427 | the arguments of the mainline `TRACE_EVENT()` definitions do not match | |
3428 | the ones of the LTTng-modules adaptation layer | |
3429 | (`LTTNG_TRACEPOINT_EVENT()`). | |
3430 | ||
3431 | Edit path:{probes/Makefile} and add your new kernel module object | |
3432 | next to existing ones: | |
3433 | ||
3434 | [source,make] | |
3435 | ---- | |
3436 | # ... | |
3437 | ||
3438 | obj-m += lttng-probe-module.o | |
3439 | obj-m += lttng-probe-power.o | |
3440 | ||
3441 | obj-m += lttng-probe-hello.o | |
3442 | ||
3443 | # ... | |
3444 | ---- | |
3445 | ||
3446 | Time to build! Point to your custom Linux kernel source tree using | |
3447 | the `KERNELDIR` variable: | |
3448 | ||
3449 | [role="term"] | |
3450 | ---- | |
3451 | make KERNELDIR=/path/to/custom/linux | |
3452 | ---- | |
3453 | ||
3454 | Finally, install modules: | |
3455 | ||
3456 | [role="term"] | |
3457 | ---- | |
3458 | sudo make modules_install | |
3459 | ---- | |
3460 | ||
3461 | ||
3462 | [[instrumenting-linux-kernel-tracing]] | |
3463 | ===== Tracing | |
3464 | ||
3465 | The <<controlling-tracing,Controlling tracing>> section explains | |
3466 | how to use the `lttng` tool to create and control tracing sessions. | |
3467 | Although the `lttng` tool will load the appropriate _known_ LTTng kernel | |
3468 | modules when needed (by launching `root`'s session daemon), it won't | |
3469 | load your custom `lttng-probe-hello` module by default. You need to | |
3470 | manually load the `lttng-probe-hello` module, and start an LTTng session | |
3471 | daemon as `root`: | |
3472 | ||
3473 | [role="term"] | |
3474 | ---- | |
3475 | sudo pkill -u root lttng-sessiond | |
3476 | sudo modprobe lttng_probe_hello | |
3477 | sudo lttng-sessiond | |
3478 | ---- | |
3479 | ||
3480 | The first command makes sure any existing instance is killed. If | |
3481 | you're not interested in using the default probes, or if you only | |
3482 | want to use a few of them, you can use the `--kmod-probes` option | |
3483 | of `lttng-sessiond` instead, which specifies an absolute list of | |
3484 | probes to load (without the `lttng-probe-` prefix): | |
3485 | ||
3486 | [role="term"] | |
3487 | ---- | |
3488 | sudo lttng-sessiond --kmod-probes=hello,ext4,net,block,signal,sched | |
3489 | ---- | |
3490 | ||
3491 | Confirm the custom probe module is loaded: | |
3492 | ||
3493 | [role="term"] | |
3494 | ---- | |
3495 | lsmod | grep lttng_probe_hello | |
3496 | ---- | |
3497 | ||
3498 | The `hello_world` event should appear in the list when doing | |
3499 | ||
3500 | [role="term"] | |
3501 | ---- | |
3502 | lttng list --kernel | grep hello | |
3503 | ---- | |
3504 | ||
3505 | You may now create an LTTng tracing session, enable the `hello_world` | |
3506 | kernel event (and others if you wish) and start tracing: | |
3507 | ||
3508 | [role="term"] | |
3509 | ---- | |
3510 | sudo lttng create my-session | |
3511 | sudo lttng enable-event --kernel hello_world | |
3512 | sudo lttng start | |
3513 | ---- | |
3514 | ||
3515 | Plug a few USB devices, then stop tracing and inspect the trace (if | |
3516 | http://diamon.org/babeltrace[Babeltrace] | |
3517 | is installed): | |
3518 | ||
3519 | [role="term"] | |
3520 | ---- | |
3521 | sudo lttng stop | |
3522 | sudo lttng view | |
3523 | ---- | |
3524 | ||
3525 | Here'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 | ||
3533 | Two USB flash drives were used for this test. | |
3534 | ||
3535 | You may change your LTTng custom probe, rebuild it and reload it at | |
3536 | any time when not tracing. Make sure you remove the old module | |
3537 | (either by killing the root LTTng session daemon which loaded the | |
3538 | module in the first place (if you used `--kmod-probes`), or by | |
3539 | using `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 | ||
3545 | Instrumenting a custom Linux kernel module for LTTng follows the exact | |
3546 | same steps as | |
3547 | <<instrumenting-linux-kernel-itself,adding instrumentation | |
3548 | to the Linux kernel itself>>, | |
3549 | the only difference being that your mainline tracepoint definition | |
3550 | header doesn't reside in the mainline source tree, but in your | |
3551 | kernel module source tree. | |
3552 | ||
3553 | The only reference to this mainline header is in the LTTng custom | |
3554 | probe's source code (path:{probes/lttng-probe-hello.c} in our example), | |
3555 | for 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 | ||
3569 | The preferred, flexible way to include your module's mainline | |
3570 | tracepoint definition header is to put it in a specific directory | |
3571 | relative to your module's root, e.g., dir:{tracepoints}, and include it | |
3572 | relative to your module's root directory in the LTTng custom probe's | |
3573 | source: | |
3574 | ||
3575 | [source,c] | |
3576 | ---- | |
3577 | #include <tracepoints/hello.h> | |
3578 | ---- | |
3579 | ||
3580 | You may then build LTTng-modules by adding your module's root | |
3581 | directory as an include path to the extra C flags: | |
3582 | ||
3583 | [role="term"] | |
3584 | ---- | |
3585 | make ccflags-y=-I/path/to/kernel/module KERNELDIR=/path/to/custom/linux | |
3586 | ---- | |
3587 | ||
3588 | Using `ccflags-y` allows you to move your kernel module to another | |
3589 | directory and rebuild the LTTng-modules project with no change to | |
3590 | source files. | |
3591 | ||
3592 | ||
3593 | [[proc-lttng-logger-abi]] | |
3594 | ==== LTTng logger ABI | |
3595 | ||
3596 | The `lttng-tracer` Linux kernel module, installed by the LTTng-modules | |
3597 | package, creates a special LTTng logger ABI file path:{/proc/lttng-logger} | |
3598 | when loaded. Writing text data to this file generates an LTTng kernel | |
3599 | domain event named `lttng_logger`. | |
3600 | ||
3601 | Unlike other kernel domain events, `lttng_logger` may be enabled by | |
3602 | any user, not only root users or members of the tracing group. | |
3603 | ||
3604 | To use the LTTng logger ABI, simply write a string to | |
3605 | path:{/proc/lttng-logger}: | |
3606 | ||
3607 | [role="term"] | |
3608 | ---- | |
3609 | echo -n 'Hello, World!' > /proc/lttng-logger | |
3610 | ---- | |
3611 | ||
3612 | The `msg` field of the `lttng_logger` event contains the recorded | |
3613 | message. | |
3614 | ||
3615 | NOTE: Messages are split in chunks of 1024{nbsp}bytes. | |
3616 | ||
3617 | The LTTng logger ABI is a quick and easy way to trace some events from | |
3618 | user space through the kernel tracer. However, it is much more basic | |
3619 | than LTTng-UST: it's slower (involves system call round-trip to the | |
3620 | kernel and only supports logging strings). The LTTng logger ABI is | |
3621 | particularly useful for recording logs as LTTng traces from shell | |
3622 | scripts, potentially combining them with other Linux kernel/user space | |
3623 | events. | |
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 | |
3630 | application running on a 64-bit system, | |
3631 | LTTng must use a dedicated 32-bit | |
3632 | <<lttng-consumerd,consumer daemon>>. This section discusses how to | |
3633 | build that daemon (which is _not_ part of the default 64-bit LTTng | |
3634 | build) and the LTTng 32-bit tracing libraries, and how to instrument | |
3635 | a 32-bit application in that context. | |
3636 | ||
3637 | Make sure you install all 32-bit versions of LTTng dependencies. | |
3638 | Their names can be found in the path:{README.md} files of each LTTng package | |
3639 | source. How to find and install them will vary depending on your target | |
3640 | Linux distribution. `gcc-multilib` is a common package name for the | |
3641 | multilib version of GCC, which you will also need. | |
3642 | ||
3643 | The following packages will be built for 32-bit support on a 64-bit | |
3644 | system: http://urcu.so/[Userspace RCU], | |
3645 | LTTng-UST and LTTng-tools. | |
3646 | ||
3647 | ||
3648 | [[building-32-bit-userspace-rcu]] | |
3649 | ===== Building 32-bit Userspace RCU | |
3650 | ||
3651 | Follow this: | |
3652 | ||
3653 | [role="term"] | |
3654 | ---- | |
3655 | git clone git://git.urcu.so/urcu.git | |
3656 | cd urcu | |
3657 | ./bootstrap | |
3658 | ./configure --libdir=/usr/lib32 CFLAGS=-m32 | |
3659 | make | |
3660 | sudo make install | |
3661 | sudo ldconfig | |
3662 | ---- | |
3663 | ||
3664 | The `-m32` C compiler flag creates 32-bit object files and `--libdir` | |
3665 | indicates where to install the resulting libraries. | |
3666 | ||
3667 | ||
3668 | [[building-32-bit-lttng-ust]] | |
3669 | ===== Building 32-bit LTTng-UST | |
3670 | ||
3671 | Follow this: | |
3672 | ||
3673 | [role="term"] | |
3674 | ---- | |
3675 | git clone http://git.lttng.org/lttng-ust.git | |
3676 | cd lttng-ust | |
3677 | ./bootstrap | |
3678 | ./configure --prefix=/usr \ | |
3679 | --libdir=/usr/lib32 \ | |
3680 | CFLAGS=-m32 CXXFLAGS=-m32 \ | |
3681 | LDFLAGS=-L/usr/lib32 | |
3682 | make | |
3683 | sudo make install | |
3684 | sudo ldconfig | |
3685 | ---- | |
3686 | ||
3687 | `-L/usr/lib32` is required for the build to find the 32-bit versions | |
3688 | of Userspace RCU and other dependencies. | |
3689 | ||
3690 | [NOTE] | |
3691 | ==== | |
3692 | Depending on your Linux distribution, | |
3693 | 32-bit libraries could be installed at a different location than | |
3694 | dir:{/usr/lib32}. For example, Debian is known to install | |
3695 | some 32-bit libraries in dir:{/usr/lib/i386-linux-gnu}. | |
3696 | ||
3697 | In this case, make sure to set `LDFLAGS` to all the | |
3698 | relevant 32-bit library paths, e.g., | |
3699 | `LDFLAGS="-L/usr/lib32 -L/usr/lib/i386-linux-gnu"`. | |
3700 | ==== | |
3701 | ||
3702 | NOTE: You may add options to path:{./configure} if you need them, e.g., for | |
3703 | Java and SystemTap support. Look at `./configure --help` for more | |
3704 | information. | |
3705 | ||
3706 | ||
3707 | [[building-32-bit-lttng-tools]] | |
3708 | ===== Building 32-bit LTTng-tools | |
3709 | ||
3710 | Since the host is a 64-bit system, most 32-bit binaries and libraries of | |
3711 | LTTng-tools are not needed; the host will use their 64-bit counterparts. | |
3712 | The required step here is building and installing a 32-bit consumer | |
3713 | daemon. | |
3714 | ||
3715 | Follow this: | |
3716 | ||
3717 | [role="term"] | |
3718 | ---- | |
3719 | git clone http://git.lttng.org/lttng-tools.git | |
3720 | cd lttng-ust | |
3721 | ./bootstrap | |
3722 | ./configure --prefix=/usr \ | |
3723 | --libdir=/usr/lib32 CFLAGS=-m32 CXXFLAGS=-m32 \ | |
3724 | LDFLAGS=-L/usr/lib32 | |
3725 | make | |
3726 | cd src/bin/lttng-consumerd | |
3727 | sudo make install | |
3728 | sudo ldconfig | |
3729 | ---- | |
3730 | ||
3731 | The above commands build all the LTTng-tools project as 32-bit | |
3732 | applications, but only installs the 32-bit consumer daemon. | |
3733 | ||
3734 | ||
3735 | [[building-64-bit-lttng-tools]] | |
3736 | ===== Building 64-bit LTTng-tools | |
3737 | ||
3738 | Finally, you need to build a 64-bit version of LTTng-tools which is | |
3739 | aware of the 32-bit consumer daemon previously built and installed: | |
3740 | ||
3741 | [role="term"] | |
3742 | ---- | |
3743 | make clean | |
3744 | ./bootstrap | |
3745 | ./configure --prefix=/usr \ | |
3746 | --with-consumerd32-libdir=/usr/lib32 \ | |
3747 | --with-consumerd32-bin=/usr/lib32/lttng/libexec/lttng-consumerd | |
3748 | make | |
3749 | sudo make install | |
3750 | sudo ldconfig | |
3751 | ---- | |
3752 | ||
3753 | Henceforth, the 64-bit session daemon will automatically find the | |
3754 | 32-bit consumer daemon if required. | |
3755 | ||
3756 | ||
3757 | [[building-instrumented-32-bit-c-application]] | |
3758 | ===== Building an instrumented 32-bit C application | |
3759 | ||
3760 | Let 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 | ||
3764 | The instrumentation process is unaltered. | |
3765 | ||
3766 | First, a typical 64-bit build (assuming you're running a 64-bit system): | |
3767 | ||
3768 | [role="term"] | |
3769 | ---- | |
3770 | gcc -o hello64 -I. hello.c hello-tp.c -ldl -llttng-ust | |
3771 | ---- | |
3772 | ||
3773 | Now, a 32-bit build: | |
3774 | ||
3775 | [role="term"] | |
3776 | ---- | |
3777 | gcc -o hello32 -I. -m32 hello.c hello-tp.c -L/usr/lib32 \ | |
3778 | -ldl -llttng-ust -Wl,-rpath,/usr/lib32 | |
3779 | ---- | |
3780 | ||
3781 | The `-rpath` option, passed to the linker, will make the dynamic loader | |
3782 | check for libraries in dir:{/usr/lib32} before looking in its default paths, | |
3783 | where 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 | ||
3789 | Now, both 32-bit and 64-bit versions of the _Hello world_ example above | |
3790 | can be traced in the same tracing session. Use the `lttng` tool as usual | |
3791 | to create a tracing session and start tracing: | |
3792 | ||
3793 | [role="term"] | |
3794 | ---- | |
3795 | lttng create session-3264 | |
3796 | lttng enable-event -u -a | |
3797 | ./hello32 | |
3798 | ./hello64 | |
3799 | lttng stop | |
3800 | ---- | |
3801 | ||
3802 | Use `lttng view` to verify both processes were | |
3803 | successfully traced. | |
3804 | ||
3805 | ||
3806 | [[controlling-tracing]] | |
3807 | === Controlling tracing | |
3808 | ||
3809 | Once you're in possession of a software that is properly | |
3810 | <<instrumenting,instrumented>> for LTTng tracing, be it thanks to | |
3811 | the built-in LTTng probes for the Linux kernel, a custom user | |
3812 | application or a custom Linux kernel, all that is left is actually | |
3813 | tracing it. As a user, you control LTTng tracing using a single command | |
3814 | line interface: the `lttng` tool. This tool uses `liblttng-ctl` behind | |
3815 | the scene to connect to and communicate with session daemons. LTTng | |
3816 | session daemons may either be started manually (`lttng-sessiond`) or | |
3817 | automatically by the `lttng` command when needed. Trace data may | |
3818 | be forwarded to the network and used elsewhere using an LTTng relay | |
3819 | daemon (`lttng-relayd`). | |
3820 | ||
3821 | The manpages of `lttng`, `lttng-sessiond` and `lttng-relayd` are pretty | |
3822 | complete, thus this section is not an online copy of the latter (we | |
3823 | leave this contents for the | |
3824 | <<online-lttng-manpages,Online LTTng manpages>> section). | |
3825 | This section is rather a tour of LTTng | |
3826 | features through practical examples and tips. | |
3827 | ||
3828 | If not already done, make sure you understand the core concepts | |
3829 | and how LTTng components connect together by reading the | |
3830 | <<understanding-lttng,Understanding LTTng>> chapter; this section | |
3831 | assumes you are familiar with them. | |
3832 | ||
3833 | ||
3834 | [[creating-destroying-tracing-sessions]] | |
3835 | ==== Creating and destroying tracing sessions | |
3836 | ||
3837 | Whatever you want to do with `lttng`, it has to happen inside a | |
3838 | **tracing session**, created beforehand. A session, in general, is a | |
3839 | per-user container of state. A tracing session is no different; it | |
3840 | keeps 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 | ||
3848 | and more. | |
3849 | ||
3850 | A single user may have many active tracing sessions. LTTng session | |
3851 | daemons are the ultimate owners and managers of tracing sessions. For | |
3852 | user space tracing, each user has its own session daemon. Since Linux | |
3853 | kernel tracing requires root privileges, only `root`'s session daemon | |
3854 | may enable and trace kernel events. However, `lttng` has a `--group` | |
3855 | option (which is passed to `lttng-sessiond` when starting it) to | |
3856 | specify the name of a _tracing group_ which selected users may be part | |
3857 | of to be allowed to communicate with `root`'s session daemon. By | |
3858 | default, the tracing group name is `tracing`. | |
3859 | ||
3860 | To create a tracing session, do: | |
3861 | ||
3862 | [role="term"] | |
3863 | ---- | |
3864 | lttng create my-session | |
3865 | ---- | |
3866 | ||
3867 | This will create a new tracing session named `my-session` and make it | |
3868 | the current one. If you don't specify any name (calling only | |
3869 | `lttng create`), your tracing session will be named `auto`. Traces | |
3870 | are written in +\~/lttng-traces/__session__-+ followed | |
3871 | by the tracing session's creation date/time by default, where | |
3872 | +__session__+ is the tracing session name. To save them | |
3873 | at a different location, use the `--output` option: | |
3874 | ||
3875 | [role="term"] | |
3876 | ---- | |
3877 | lttng create --output /tmp/some-directory my-session | |
3878 | ---- | |
3879 | ||
3880 | You may create as many tracing sessions as you wish: | |
3881 | ||
3882 | [role="term"] | |
3883 | ---- | |
3884 | lttng create other-session | |
3885 | lttng create yet-another-session | |
3886 | ---- | |
3887 | ||
3888 | You may view all existing tracing sessions using the `list` command: | |
3889 | ||
3890 | [role="term"] | |
3891 | ---- | |
3892 | lttng list | |
3893 | ---- | |
3894 | ||
3895 | The state of a _current tracing session_ is kept in path:{~/.lttngrc}. Each | |
3896 | invocation of `lttng` reads this file to set its current tracing | |
3897 | session name so that you don't have to specify a session name for each | |
3898 | command. You could edit this file manually, but the preferred way to | |
3899 | set the current tracing session is to use the `set-session` command: | |
3900 | ||
3901 | [role="term"] | |
3902 | ---- | |
3903 | lttng set-session other-session | |
3904 | ---- | |
3905 | ||
3906 | Most `lttng` commands accept a `--session` option to specify the name | |
3907 | of the target tracing session. | |
3908 | ||
3909 | Any existing tracing session may be destroyed using the `destroy` | |
3910 | command: | |
3911 | ||
3912 | [role="term"] | |
3913 | ---- | |
3914 | lttng destroy my-session | |
3915 | ---- | |
3916 | ||
3917 | Providing no argument to `lttng destroy` will destroy the current | |
3918 | tracing session. Destroying a tracing session will stop any tracing | |
3919 | running within the latter. Destroying a tracing session frees resources | |
3920 | acquired by the session daemon and tracer side, making sure to flush | |
3921 | all trace data. | |
3922 | ||
3923 | You can't do much with LTTng using only the `create`, `set-session` | |
3924 | and `destroy` commands of `lttng`, but it is essential to know them in | |
3925 | order to control LTTng tracing, which always happen within the scope of | |
3926 | a tracing session. | |
3927 | ||
3928 | ||
3929 | [[enabling-disabling-events]] | |
3930 | ==== Enabling and disabling events | |
3931 | ||
3932 | Inside a tracing session, individual events may be enabled or disabled | |
3933 | so that tracing them may or may not generate trace data. | |
3934 | ||
3935 | We sometimes use the term _event_ metonymically throughout this text to | |
3936 | refer to a specific condition, or _rule_, that could lead, when | |
3937 | satisfied, to an actual occurring event (a point at a specific position | |
3938 | in source code/binary program, logical processor and time capturing | |
3939 | some payload) being recorded as trace data. This specific condition is | |
3940 | composed 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 | ||
3953 | All conditions are specified using arguments passed to the | |
3954 | `enable-event` command of the `lttng` tool. | |
3955 | ||
3956 | Condition 1 is specified using either `--kernel/-k` (kernel), | |
3957 | `--userspace/-u` (user space) or `--jul/-j` | |
3958 | (JUL). Exactly one of those | |
3959 | three arguments must be specified. | |
3960 | ||
3961 | Condition 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 | ||
3977 | When none of the above is specified, `enable-event` defaults to | |
3978 | using `--tracepoint`. | |
3979 | ||
3980 | Condition 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 | ||
3989 | See `lttng enable-event --help` for the complete list of log level | |
3990 | names. | |
3991 | ||
3992 | Condition 4 is specified using the `--filter` option. This filter is | |
3993 | a C-like expression, potentially reading real-time values of event | |
3994 | fields, that has to evaluate to _true_ for the condition to be satisfied. | |
3995 | Event fields are read using plain identifiers while context fields | |
3996 | must be prefixed with `$ctx.`. See `lttng enable-event --help` for | |
3997 | all usage details. | |
3998 | ||
3999 | The aforementioned arguments are combined to create and enable events. | |
4000 | Each unique combination of arguments leads to a different | |
4001 | _enabled event_. The log level and filter arguments are optional, their | |
4002 | default values being respectively all log levels and a filter which | |
4003 | always returns _true_. | |
4004 | ||
4005 | Here are a few examples (you must | |
4006 | <<creating-destroying-tracing-sessions,create a tracing session>> | |
4007 | first): | |
4008 | ||
4009 | [role="term"] | |
4010 | ---- | |
4011 | lttng enable-event -u --tracepoint my_app:hello_world | |
4012 | lttng enable-event -u --tracepoint my_app:hello_you --loglevel TRACE_WARNING | |
4013 | lttng enable-event -u --tracepoint 'my_other_app:*' | |
4014 | lttng enable-event -u --tracepoint my_app:foo_bar \ | |
4015 | --filter 'some_field <= 23 && !other_field' | |
4016 | lttng enable-event -k --tracepoint sched_switch | |
4017 | lttng enable-event -k --tracepoint gpio_value | |
4018 | lttng enable-event -k --function usb_probe_device usb_probe_device | |
4019 | lttng enable-event -k --syscall --all | |
4020 | ---- | |
4021 | ||
4022 | The wildcard symbol, `*`, matches _anything_ and may only be used at | |
4023 | the end of the string when specifying a _tracepoint_. Make sure to | |
4024 | use it between single quotes in your favorite shell to avoid | |
4025 | undesired shell expansion. | |
4026 | ||
4027 | You can see a list of events (enabled or disabled) using | |
4028 | ||
4029 | [role="term"] | |
4030 | ---- | |
4031 | lttng list some-session | |
4032 | ---- | |
4033 | ||
4034 | where `some-session` is the name of the desired tracing session. | |
4035 | ||
4036 | What you're actually doing when enabling events with specific conditions | |
4037 | is creating a **whitelist** of traceable events for a given channel. | |
4038 | Thus, the following case presents redundancy: | |
4039 | ||
4040 | [role="term"] | |
4041 | ---- | |
4042 | lttng enable-event -u --tracepoint my_app:hello_you | |
4043 | lttng enable-event -u --tracepoint my_app:hello_you --loglevel TRACE_DEBUG | |
4044 | ---- | |
4045 | ||
4046 | The second command, matching a log level range, is useless since the first | |
4047 | command enables all tracepoints matching the same name, | |
4048 | `my_app:hello_you`. | |
4049 | ||
4050 | Disabling an event is simpler: you only need to provide the event | |
4051 | name to the `disable-event` command: | |
4052 | ||
4053 | [role="term"] | |
4054 | ---- | |
4055 | lttng disable-event --userspace my_app:hello_you | |
4056 | ---- | |
4057 | ||
4058 | This name has to match a name previously given to `enable-event` (it | |
4059 | has to be listed in the output of `lttng list some-session`). | |
4060 | The `*` wildcard is supported, as long as you also used it in a | |
4061 | previous `enable-event` invocation. | |
4062 | ||
4063 | Disabling an event does not add it to some blacklist: it simply removes | |
4064 | it from its channel's whitelist. This is why you cannot disable an event | |
4065 | which wasn't previously enabled. | |
4066 | ||
4067 | A disabled event will not generate any trace data, even if all its | |
4068 | specified conditions are met. | |
4069 | ||
4070 | Events may be enabled and disabled at will, either when LTTng tracers | |
4071 | are active or not. Events may be enabled before a user space application | |
4072 | is even started. | |
4073 | ||
4074 | ||
4075 | [[basic-tracing-session-control]] | |
4076 | ==== Basic tracing session control | |
4077 | ||
4078 | Once you have | |
4079 | <<creating-destroying-tracing-sessions,created a tracing session>> | |
4080 | and <<enabling-disabling-events,enabled one or more events>>, | |
4081 | you may activate the LTTng tracers for the current tracing session at | |
4082 | any time: | |
4083 | ||
4084 | [role="term"] | |
4085 | ---- | |
4086 | lttng start | |
4087 | ---- | |
4088 | ||
4089 | Subsequently, you may stop the tracers: | |
4090 | ||
4091 | [role="term"] | |
4092 | ---- | |
4093 | lttng stop | |
4094 | ---- | |
4095 | ||
4096 | LTTng is very flexible: user space applications may be launched before | |
4097 | or after the tracers are started. Events will only be recorded if they | |
4098 | are properly enabled and if they occur while tracers are started. | |
4099 | ||
4100 | A tracing session name may be passed to both the `start` and `stop` | |
4101 | commands 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 | |
4109 | events are contained in a specific channel, itself contained in a | |
4110 | specific tracing session. A channel is a group of events with | |
4111 | tunable parameters (event loss mode, sub-buffer size, number of | |
4112 | sub-buffers, trace file sizes and count, etc.). A given channel may | |
4113 | only be responsible for enabled events belonging to one domain: either | |
4114 | kernel or user space. | |
4115 | ||
4116 | If you only used the `create`, `enable-event` and `start`/`stop` | |
4117 | commands of the `lttng` tool so far, one or two channels were | |
4118 | automatically created for you (one for the kernel domain and/or one | |
4119 | for the user space domain). The default channels are both named | |
4120 | `channel0`; channels from different domains may have the same name. | |
4121 | ||
4122 | The current channels of a given tracing session can be viewed with | |
4123 | ||
4124 | [role="term"] | |
4125 | ---- | |
4126 | lttng list some-session | |
4127 | ---- | |
4128 | ||
4129 | where `some-session` is the name of the desired tracing session. | |
4130 | ||
4131 | To create and enable a channel, use the `enable-channel` command: | |
4132 | ||
4133 | [role="term"] | |
4134 | ---- | |
4135 | lttng enable-channel --kernel my-channel | |
4136 | ---- | |
4137 | ||
4138 | This will create a kernel domain channel named `my-channel` with | |
4139 | default parameters in the current tracing session. | |
4140 | ||
4141 | [NOTE] | |
4142 | ==== | |
4143 | Because of a current limitation, all | |
4144 | channels must be _created_ prior to beginning tracing in a | |
4145 | given tracing session, i.e. before the first time you do | |
4146 | `lttng start`. | |
4147 | ||
4148 | Since a channel is automatically created by | |
4149 | `enable-event` only for the specified domain, you cannot, | |
4150 | for example, enable a kernel domain event, start tracing and then | |
4151 | enable a user space domain event because no user space channel | |
4152 | exists yet and it's too late to create one. | |
4153 | ||
4154 | For this reason, make sure to configure your channels properly | |
4155 | before starting the tracers for the first time! | |
4156 | ==== | |
4157 | ||
4158 | Here's another example: | |
4159 | ||
4160 | [role="term"] | |
4161 | ---- | |
4162 | lttng enable-channel --userspace --session other-session --overwrite \ | |
4163 | --tracefile-size 1048576 1mib-channel | |
4164 | ---- | |
4165 | ||
4166 | This will create a user space domain channel named `1mib-channel` in | |
4167 | the tracing session named `other-session` that loses new events by | |
4168 | overwriting previously recorded events (instead of the default mode of | |
4169 | discarding newer ones) and saves trace files with a maximum size of | |
4170 | 1{nbsp}MiB each. | |
4171 | ||
4172 | Note that channels may also be created using the `--channel` option of | |
4173 | the `enable-event` command when the provided channel name doesn't exist | |
4174 | for the specified domain: | |
4175 | ||
4176 | [role="term"] | |
4177 | ---- | |
4178 | lttng enable-event --kernel --channel some-channel sched_switch | |
4179 | ---- | |
4180 | ||
4181 | If no kernel domain channel named `some-channel` existed before calling | |
4182 | the above command, it would be created with default parameters. | |
4183 | ||
4184 | You may enable the same event in two different channels: | |
4185 | ||
4186 | [role="term"] | |
4187 | ---- | |
4188 | lttng enable-event --userspace --channel my-channel app:tp | |
4189 | lttng enable-event --userspace --channel other-channel app:tp | |
4190 | ---- | |
4191 | ||
4192 | If both channels are enabled, the occurring `app:tp` event will | |
4193 | generate two recorded events, one for each channel. | |
4194 | ||
4195 | Disabling a channel is done with the `disable-event` command: | |
4196 | ||
4197 | [role="term"] | |
4198 | ---- | |
4199 | lttng disable-event --kernel some-channel | |
4200 | ---- | |
4201 | ||
4202 | The state of a channel precedes the individual states of events within | |
4203 | it: events belonging to a disabled channel, even if they are | |
4204 | enabled, won't be recorded. | |
4205 | ||
4206 | ||
4207 | ||
4208 | [[fine-tuning-channels]] | |
4209 | ===== Fine-tuning channels | |
4210 | ||
4211 | There are various parameters that may be fine-tuned with the | |
4212 | `enable-channel` command. The latter are well documented in | |
4213 | man:lttng(1) and in the <<channel,Channel>> section of the | |
4214 | <<understanding-lttng,Understanding LTTng>> chapter. For basic | |
4215 | tracing needs, their default values should be just fine, but here are a | |
4216 | few examples to break the ice. | |
4217 | ||
4218 | As the frequency of recorded events increases--either because the | |
4219 | event throughput is actually higher or because you enabled more events | |
4220 | than usual—__event loss__ might be experienced. Since LTTng never | |
4221 | waits, by design, for sub-buffer space availability (non-blocking | |
4222 | tracer), when a sub-buffer is full and no empty sub-buffers are left, | |
4223 | there are two possible outcomes: either the new events that do not fit | |
4224 | are rejected, or they start replacing the oldest recorded events. | |
4225 | The choice of which algorithm to use is a per-channel parameter, the | |
4226 | default being discarding the newest events until there is some space | |
4227 | left. If your situation always needs the latest events at the expense | |
4228 | of writing over the oldest ones, create a channel with the `--overwrite` | |
4229 | option: | |
4230 | ||
4231 | [role="term"] | |
4232 | ---- | |
4233 | lttng enable-channel --kernel --overwrite my-channel | |
4234 | ---- | |
4235 | ||
4236 | When an event is lost, it means no space was available in any | |
4237 | sub-buffer to accommodate it. Thus, if you want to cope with sporadic | |
4238 | high event throughput situations and avoid losing events, you need to | |
4239 | allocate more room for storing them in memory. This can be done by | |
4240 | either increasing the size of sub-buffers or by adding sub-buffers. | |
4241 | The following example creates a user space domain channel with | |
4242 | 16{nbsp}sub-buffers of 512{nbsp}kiB each: | |
4243 | ||
4244 | [role="term"] | |
4245 | ---- | |
4246 | lttng enable-channel --userspace --num-subbuf 16 --subbuf-size 512k big-channel | |
4247 | ---- | |
4248 | ||
4249 | Both values need to be powers of two, otherwise they are rounded up | |
4250 | to the next one. | |
4251 | ||
4252 | Two other interesting available parameters of `enable-channel` are | |
4253 | `--tracefile-size` and `--tracefile-count`, which respectively limit | |
4254 | the size of each trace file and the their count for a given channel. | |
4255 | When the number of written trace files reaches its limit for a given | |
4256 | channel-CPU pair, the next trace file will overwrite the very first | |
4257 | one. The following example creates a kernel domain channel with a | |
4258 | maximum of three trace files of 1{nbsp}MiB each: | |
4259 | ||
4260 | [role="term"] | |
4261 | ---- | |
4262 | lttng enable-channel --kernel --tracefile-size 1M --tracefile-count 3 my-channel | |
4263 | ---- | |
4264 | ||
4265 | An efficient way to make sure lots of events are generated is enabling | |
4266 | all kernel events in this channel and starting the tracer: | |
4267 | ||
4268 | [role="term"] | |
4269 | ---- | |
4270 | lttng enable-event --kernel --all --channel my-channel | |
4271 | lttng start | |
4272 | ---- | |
4273 | ||
4274 | After a few seconds, look at trace files in your tracing session | |
4275 | output directory. For two CPUs, it should look like: | |
4276 | ||
4277 | ---- | |
4278 | my-channel_0_0 my-channel_1_0 | |
4279 | my-channel_0_1 my-channel_1_1 | |
4280 | my-channel_0_2 my-channel_1_2 | |
4281 | ---- | |
4282 | ||
4283 | Amongst the files above, you might see one in each group with a size | |
4284 | lower than 1{nbsp}MiB: they are the files currently being written. | |
4285 | ||
4286 | Since all those small files are valid LTTng trace files, LTTng trace | |
4287 | viewers may read them. It is the viewer's responsibility to properly | |
4288 | merge the streams so as to present an ordered list to the user. | |
4289 | http://diamon.org/babeltrace[Babeltrace] | |
4290 | merges LTTng trace files correctly and is fast at doing it. | |
4291 | ||
4292 | ||
4293 | [[adding-context]] | |
4294 | ==== Adding some context to channels | |
4295 | ||
4296 | If you read all the sections of | |
4297 | <<controlling-tracing,Controlling tracing>> so far, you should be | |
4298 | able to create tracing sessions, create and enable channels and events | |
4299 | within them and start/stop the LTTng tracers. Event fields recorded in | |
4300 | trace files provide important information about occurring events, but | |
4301 | sometimes external context may help you solve a problem faster. This | |
4302 | section discusses how to add context information to events of a | |
4303 | specific channel using the `lttng` tool. | |
4304 | ||
4305 | There are various available context values which can accompany events | |
4306 | recorded 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 | ||
4322 | The full list is available in the output of `lttng add-context --help`. | |
4323 | Some of them are reserved for a specific domain (kernel or | |
4324 | user space) while others are available for both. | |
4325 | ||
4326 | To add context information to one or all channels of a given tracing | |
4327 | session, use the `add-context` command: | |
4328 | ||
4329 | [role="term"] | |
4330 | ---- | |
4331 | lttng add-context --userspace --type vpid --type perf:thread:cpu-cycles | |
4332 | ---- | |
4333 | ||
4334 | The above example adds the virtual process identifier and per-thread | |
4335 | CPU cycles count values to all recorded user space domain events of the | |
4336 | current tracing session. Use the `--channel` option to select a specific | |
4337 | channel: | |
4338 | ||
4339 | [role="term"] | |
4340 | ---- | |
4341 | lttng add-context --kernel --channel my-channel --type tid | |
4342 | ---- | |
4343 | ||
4344 | adds the thread identifier value to all recorded kernel domain events | |
4345 | in the channel `my-channel` of the current tracing session. | |
4346 | ||
4347 | Beware that context information cannot be removed from channels once | |
4348 | it's added for a given tracing session. | |
4349 | ||
4350 | ||
4351 | [[saving-loading-tracing-session]] | |
4352 | ==== Saving and loading tracing session configurations | |
4353 | ||
4354 | Configuring a tracing session may be long: creating and enabling | |
4355 | channels with specific parameters, enabling kernel and user space | |
4356 | domain events with specific log levels and filters, adding context | |
4357 | to some channels, etc. If you're going to use LTTng to solve real | |
4358 | world problems, chances are you're going to have to record events using | |
4359 | the same tracing session setup over and over, modifying a few variables | |
4360 | each time in your instrumented program or environment. To avoid | |
4361 | constant tracing session reconfiguration, the `lttng` tool is able to | |
4362 | save and load tracing session configurations to/from XML files. | |
4363 | ||
4364 | To save a given tracing session configuration, do: | |
4365 | ||
4366 | [role="term"] | |
4367 | ---- | |
4368 | lttng save my-session | |
4369 | ---- | |
4370 | ||
4371 | where `my-session` is the name of the tracing session to save. Tracing | |
4372 | session configurations are saved to dir:{~/.lttng/sessions} by default; | |
4373 | use the `--output-path` option to change this destination directory. | |
4374 | ||
4375 | All 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 | ||
4384 | To load a tracing session, simply do: | |
4385 | ||
4386 | [role="term"] | |
4387 | ---- | |
4388 | lttng load my-session | |
4389 | ---- | |
4390 | ||
4391 | or, if you used a custom path: | |
4392 | ||
4393 | [role="term"] | |
4394 | ---- | |
4395 | lttng load --input-path /path/to/my-session.lttng | |
4396 | ---- | |
4397 | ||
4398 | Your saved tracing session will be restored as if you just configured | |
4399 | it manually. | |
4400 | ||
4401 | ||
4402 | [[sending-trace-data-over-the-network]] | |
4403 | ==== Sending trace data over the network | |
4404 | ||
4405 | The possibility of sending trace data over the network comes as a | |
4406 | built-in feature of LTTng-tools. For this to be possible, an LTTng | |
4407 | _relay daemon_ must be executed and listening on the machine where | |
4408 | trace data is to be received, and the user must create a tracing | |
4409 | session using appropriate options to forward trace data to the remote | |
4410 | relay daemon. | |
4411 | ||
4412 | The relay daemon listens on two different TCP ports: one for control | |
4413 | information and the other for actual trace data. | |
4414 | ||
4415 | Starting the relay daemon on the remote machine is as easy as: | |
4416 | ||
4417 | [role="term"] | |
4418 | ---- | |
4419 | lttng-relayd | |
4420 | ---- | |
4421 | ||
4422 | This will make it listen to its default ports: 5342 for control and | |
4423 | 5343 for trace data. The `--control-port` and `--data-port` options may | |
4424 | be used to specify different ports. | |
4425 | ||
4426 | Traces written by `lttng-relayd` are written to | |
4427 | +\~/lttng-traces/__hostname__/__session__+ by | |
4428 | default, where +__hostname__+ is the host name of the | |
4429 | traced (monitored) system and +__session__+ is the | |
4430 | tracing session name. Use the `--output` option to write trace data | |
4431 | outside dir:{~/lttng-traces}. | |
4432 | ||
4433 | On the sending side, a tracing session must be created using the | |
4434 | `lttng` tool with the `--set-url` option to connect to the distant | |
4435 | relay daemon: | |
4436 | ||
4437 | [role="term"] | |
4438 | ---- | |
4439 | lttng create my-session --set-url net://distant-host | |
4440 | ---- | |
4441 | ||
4442 | The URL format is described in the output of `lttng create --help`. | |
4443 | The 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 | |
4445 | individually. | |
4446 | ||
4447 | Once this basic setup is completed and the connection is established, | |
4448 | you may use the `lttng` tool on the target machine as usual; everything | |
4449 | you do will be transparently forwarded to the remote machine if needed. | |
4450 | For example, a parameter changing the maximum size of trace files will | |
4451 | have an effect on the distant relay daemon actually writing the trace. | |
4452 | ||
4453 | ||
4454 | [[lttng-live]] | |
4455 | ==== Viewing events as they arrive | |
4456 | ||
4457 | We have seen how trace files may be produced by LTTng out of generated | |
4458 | application and Linux kernel events. We have seen that those trace files | |
4459 | may be either recorded locally by consumer daemons or remotely using | |
4460 | a relay daemon. And we have seen that the maximum size and count of | |
4461 | trace files is configurable for each channel. With all those features, | |
4462 | it's still not possible to read a trace file as it is being written | |
4463 | because it could be incomplete and appear corrupted to the viewer. | |
4464 | There is a way to view events as they arrive, however: using | |
4465 | _LTTng live_. | |
4466 | ||
4467 | LTTng live is implemented, in LTTng, solely on the relay daemon side. | |
4468 | As trace data is sent over the network to a relay daemon by a (possibly | |
4469 | remote) consumer daemon, a _tee_ may be created: trace data will be | |
4470 | recorded to trace files _as well as_ being transmitted to a | |
4471 | connected live viewer: | |
4472 | ||
4473 | [role="img-90"] | |
4474 | .LTTng live and the relay daemon. | |
4475 | image::lttng-live-relayd.png[] | |
4476 | ||
4477 | In order to use this feature, a tracing session must created in live | |
4478 | mode on the target system: | |
4479 | ||
4480 | [role="term"] | |
4481 | ---- | |
4482 | lttng create --live | |
4483 | ---- | |
4484 | ||
4485 | An optional parameter may be passed to `--live` to set the interval | |
4486 | of time (in microseconds) between flushes to the network | |
4487 | (1{nbsp}second is the default): | |
4488 | ||
4489 | [role="term"] | |
4490 | ---- | |
4491 | lttng create --live 100000 | |
4492 | ---- | |
4493 | ||
4494 | will flush every 100{nbsp}ms. | |
4495 | ||
4496 | If no network output is specified to the `create` command, a local | |
4497 | relay daemon will be spawned. In this very common case, viewing a live | |
4498 | trace 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 | ---- | |
4503 | lttng view | |
4504 | ---- | |
4505 | ||
4506 | The correct arguments will be passed to the live viewer so that it | |
4507 | may connect to the local relay daemon and start reading live events. | |
4508 | ||
4509 | You may also wish to use a live viewer not running on the target | |
4510 | system. In this case, you should specify a network output when using | |
4511 | the `create` command (`--set-url` or `--ctrl-url`/`--data-url` options). | |
4512 | A distant LTTng relay daemon should also be started to receive control | |
4513 | and trace data. By default, `lttng-relayd` listens on 127.0.0.1:5344 | |
4514 | for an LTTng live connection. Otherwise, the desired URL may be | |
4515 | specified using its `--live-port` option. | |
4516 | ||
4517 | The | |
4518 | http://diamon.org/babeltrace[`babeltrace`] | |
4519 | viewer supports LTTng live as one of its input formats. `babeltrace` is | |
4520 | the default viewer when using `lttng view`. To use it manually, first | |
4521 | list active tracing sessions by doing the following (assuming the relay | |
4522 | daemon to connect to runs on the same host): | |
4523 | ||
4524 | [role="term"] | |
4525 | ---- | |
4526 | babeltrace --input-format lttng-live net://localhost | |
4527 | ---- | |
4528 | ||
4529 | Then, choose a tracing session and start viewing events as they arrive | |
4530 | using LTTng live, e.g.: | |
4531 | ||
4532 | [role="term"] | |
4533 | ---- | |
4534 | babeltrace --input-format lttng-live net://localhost/host/hostname/my-session | |
4535 | ---- | |
4536 | ||
4537 | ||
4538 | [[taking-a-snapshot]] | |
4539 | ==== Taking a snapshot | |
4540 | ||
4541 | The normal behavior of LTTng is to record trace data as trace files. | |
4542 | This is ideal for keeping a long history of events that occurred on | |
4543 | the target system and applications, but may be too much data in some | |
4544 | situations. For example, you may wish to trace your application | |
4545 | continuously until some critical situation happens, in which case you | |
4546 | would only need the latest few recorded events to perform the desired | |
4547 | analysis, not multi-gigabyte trace files. | |
4548 | ||
4549 | LTTng has an interesting feature called _snapshots_. When creating | |
4550 | a tracing session in snapshot mode, no trace files are written; the | |
4551 | tracers' sub-buffers are constantly overwriting the oldest recorded | |
4552 | events with the newest. At any time, either when the tracers are started | |
4553 | or stopped, you may take a snapshot of those sub-buffers. | |
4554 | ||
4555 | There is no difference between the format of a normal trace file and the | |
4556 | format of a snapshot: viewers of LTTng traces will also support LTTng | |
4557 | snapshots. By default, snapshots are written to disk, but they may also | |
4558 | be sent over the network. | |
4559 | ||
4560 | To create a tracing session in snapshot mode, do: | |
4561 | ||
4562 | [role="term"] | |
4563 | ---- | |
4564 | lttng create --snapshot my-snapshot-session | |
4565 | ---- | |
4566 | ||
4567 | Next, enable channels, events and add context to channels as usual. | |
4568 | Once a tracing session is created in snapshot mode, channels will be | |
4569 | forced 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 | ||
4575 | Start tracing. When you're ready to take a snapshot, do: | |
4576 | ||
4577 | [role="term"] | |
4578 | ---- | |
4579 | lttng snapshot record --name my-snapshot | |
4580 | ---- | |
4581 | ||
4582 | This will record a snapshot named `my-snapshot` of all channels of | |
4583 | all domains of the current tracing session. By default, snapshots files | |
4584 | are recorded in the path returned by `lttng snapshot list-output`. You | |
4585 | may change this path or decide to send snapshots over the network | |
4586 | using 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 | ||
4595 | Method 3 overrides method 2 which overrides method 1. When specifying | |
4596 | a 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 | ||
4599 | If you need to make absolutely sure that the output file won't be | |
4600 | larger than a certain limit, you can set a maximum snapshot size when | |
4601 | taking it with the `--max-size` option: | |
4602 | ||
4603 | [role="term"] | |
4604 | ---- | |
4605 | lttng snapshot record --name my-snapshot --max-size 2M | |
4606 | ---- | |
4607 | ||
4608 | Older recorded events will be discarded in order to respect this | |
4609 | maximum size. | |
4610 | ||
4611 | ||
4612 | [[reference]] | |
4613 | == Reference | |
4614 | ||
4615 | This chapter presents various references for LTTng packages such as links | |
4616 | to online manpages, tables needed by the rest of the text, descriptions | |
4617 | of library functions, etc. | |
4618 | ||
4619 | ||
4620 | [[online-lttng-manpages]] | |
4621 | === Online LTTng manpages | |
4622 | ||
4623 | LTTng packages currently install the following manpages, available | |
4624 | online 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 | ||
4640 | This section presents references of the LTTng-UST package. | |
4641 | ||
4642 | ||
4643 | [[liblttng-ust]] | |
4644 | ==== LTTng-UST library (+liblttng‑ust+) | |
4645 | ||
4646 | The LTTng-UST library, or `liblttng-ust`, is the main shared object | |
4647 | against which user applications are linked to make LTTng user space | |
4648 | tracing possible. | |
4649 | ||
4650 | The <<c-application,C application>> guide shows the complete | |
4651 | process to instrument, build and run a C/$$C++$$ application using | |
4652 | LTTng-UST, while this section contains a few important tables. | |
4653 | ||
4654 | ||
4655 | [[liblttng-ust-tp-fields]] | |
4656 | ===== Tracepoint fields macros (for `TP_FIELDS()`) | |
4657 | ||
4658 | The available macros to define tracepoint fields, which should be listed | |
4659 | within `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 | | | |
4671 | Standard 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 | | | |
4684 | Standard 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 | | | |
4697 | Integer 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 | | | |
4710 | Integer 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 | | | |
4726 | Floating 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 | | | |
4742 | Null-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 | | | |
4755 | Statically-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 | | | |
4774 | Statically-sized array, printed as text. | |
4775 | ||
4776 | The 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 | | | |
4795 | Dynamically-sized array of integers. | |
4796 | ||
4797 | The 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 | | | |
4819 | Dynamically-sized array, displayed as text. | |
4820 | ||
4821 | The string does not need to be null-terminated. | |
4822 | ||
4823 | The type of +__E__+ needs to be unsigned. | |
4824 | ||
4825 | The 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 | ||
4843 | The `_nowrite` versions omit themselves from the session trace, but are | |
4844 | otherwise identical. This means the `_nowrite` fields won't be written | |
4845 | in the recorded trace. Their primary purpose is to make some | |
4846 | of the event context available to the | |
4847 | <<enabling-disabling-events,event filters>> without having to | |
4848 | commit the data to sub-buffers. | |
4849 | ||
4850 | ||
4851 | [[liblttng-ust-tracepoint-loglevel]] | |
4852 | ===== Tracepoint log levels (for `TRACEPOINT_LOGLEVEL()`) | |
4853 | ||
4854 | The 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 | ||
4902 | Log levels `TRACE_EMERG` through `TRACE_INFO` and `TRACE_DEBUG` match | |
4903 | http://man7.org/linux/man-pages/man3/syslog.3.html[syslog] | |
4904 | level semantics. Log levels `TRACE_DEBUG_SYSTEM` through `TRACE_DEBUG` | |
4905 | offer more fine-grained selection of debug information. | |
4906 | ||
4907 | ||
4908 | [[lttng-modules-ref]] | |
4909 | === LTTng-modules | |
4910 | ||
4911 | This 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 | ||
4917 | This table describes possible entries for the `TP_STRUCT__entry()` part | |
4918 | of `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 | | | |
4927 | Standard 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 | | | |
4937 | Standard 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 | | | |
4947 | Standard 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 | | | |
4957 | Integer 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 | | | |
4967 | Integer 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 | | | |
4977 | Statically-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 | | | |
4990 | Statically-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 | | | |
5001 | Statically-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 | | | |
5014 | Dynamically-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 | | | |
5027 | Dynamically-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 | | | |
5040 | Dynamically-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 | | | |
5053 | Null-terminated string. | |
5054 | ||
5055 | The behaviour is undefined behavior if +__s__+ is `NULL`. | |
5056 | ||
5057 | +__n__+:: | |
5058 | Field name. | |
5059 | ||
5060 | +__s__+:: | |
5061 | String source (pointer). | |
5062 | |==== | |
5063 | ||
5064 | The above macros should cover the majority of cases. For advanced items, | |
5065 | see path:{probes/lttng-events.h}. | |
5066 | ||
5067 | ||
5068 | [[lttng-modules-tp-fast-assign]] | |
5069 | ==== Tracepoint assignment macros (for `TP_fast_assign()`) | |
5070 | ||
5071 | This table describes possible entries for the `TP_fast_assign()` part | |
5072 | of `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 | | | |
5081 | Assignment 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 | | | |
5091 | Memory 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 | | | |
5105 | Memory copy of +__l__+ bytes from user space +__s__+ to tracepoint | |
5106 | field +__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 | | | |
5119 | Memory copy of dynamically-sized array from +__s__+ to tracepoint field | |
5120 | +__d__+. | |
5121 | ||
5122 | The 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 | | | |
5136 | String copy of +__s__+ to tracepoint field +__d__+ (use with string | |
5137 | fields). | |
5138 | ||
5139 | +__d__+:: | |
5140 | Name of destination tracepoint field. | |
5141 | ||
5142 | +__s__+:: | |
5143 | Source C expression (may refer to tracepoint arguments). | |
5144 | |==== |