Commit | Line | Data |
---|---|---|
50e95807 PP |
1 | The LTTng Documentation |
2 | ======================= | |
3 | Philippe Proulx <pproulx@efficios.com> | |
f9bace78 | 4 | v2.13, 28 November 2023 |
50e95807 PP |
5 | |
6 | ||
7 | include::../common/copyright.txt[] | |
8 | ||
9 | ||
10 | include::../common/welcome.txt[] | |
11 | ||
12 | ||
13 | include::../common/audience.txt[] | |
14 | ||
15 | ||
16 | [[chapters]] | |
17 | === What's in this documentation? | |
18 | ||
19 | The LTTng Documentation is divided into the following sections: | |
20 | ||
21 | * ``**<<nuts-and-bolts,Nuts and bolts>>**'' explains the | |
22 | rudiments of software tracing and the rationale behind the | |
23 | LTTng project. | |
24 | + | |
25 | Skip this section if you’re familiar with software tracing and with the | |
26 | LTTng project. | |
27 | ||
28 | * ``**<<installing-lttng,Installation>>**'' describes the steps to | |
29 | install the LTTng packages on common Linux distributions and from | |
30 | their sources. | |
31 | + | |
32 | Skip this section if you already properly installed LTTng on your target | |
33 | system. | |
34 | ||
35 | * ``**<<getting-started,Quick start>>**'' is a concise guide to | |
36 | get started quickly with LTTng kernel and user space tracing. | |
37 | + | |
38 | We recommend this section if you're new to LTTng or to software tracing | |
39 | in general. | |
40 | + | |
41 | Skip this section if you're not new to LTTng. | |
42 | ||
43 | * ``**<<core-concepts,Core concepts>>**'' explains the concepts at | |
44 | the heart of LTTng. | |
45 | + | |
46 | It's a good idea to become familiar with the core concepts | |
47 | before attempting to use the toolkit. | |
48 | ||
49 | * ``**<<plumbing,Components of LTTng>>**'' describes the various | |
50 | components of the LTTng machinery, like the daemons, the libraries, | |
51 | and the command-line interface. | |
52 | ||
53 | * ``**<<instrumenting,Instrumentation>>**'' shows different ways to | |
54 | instrument user applications and the Linux kernel for LTTng tracing. | |
55 | + | |
56 | Instrumenting source code is essential to provide a meaningful | |
57 | source of events. | |
58 | + | |
59 | Skip this section if you don't have a programming background. | |
60 | ||
61 | * ``**<<controlling-tracing,Tracing control>>**'' is divided into topics | |
62 | which demonstrate how to use the vast array of features that | |
63 | LTTng{nbsp}{revision} offers. | |
64 | ||
65 | * ``**<<reference,Reference>>**'' contains API reference tables. | |
66 | ||
67 | * ``**<<glossary,Glossary>>**'' is a specialized dictionary of terms | |
68 | related to LTTng or to the field of software tracing. | |
69 | ||
70 | ||
71 | include::../common/convention.txt[] | |
72 | ||
73 | ||
74 | include::../common/acknowledgements.txt[] | |
75 | ||
76 | ||
77 | [[whats-new]] | |
78 | == What's new in LTTng{nbsp}{revision}? | |
79 | ||
80 | LTTng{nbsp}{revision} bears the name _Nordicité_, the product of a | |
81 | collaboration between https://champlibre.co/[Champ Libre] and | |
075bb206 | 82 | https://www.boreale.com/[Boréale]. This farmhouse IPA is brewed with |
50e95807 PP |
83 | https://en.wikipedia.org/wiki/Kveik[Kveik] yeast and Québec-grown |
84 | barley, oats, and juniper branches. The result is a remarkable, fruity, | |
85 | hazy golden IPA that offers a balanced touch of resinous and woodsy | |
86 | bitterness. | |
87 | ||
88 | New features and changes in LTTng{nbsp}{revision}: | |
89 | ||
90 | General:: | |
91 | + | |
92 | * The LTTng trigger API of <<liblttng-ctl-lttng,`liblttng-ctl`>> now | |
93 | offers the ``__event rule matches__'' condition (an <<event-rule,event | |
94 | rule>> matches an event) as well as the following new actions: | |
95 | + | |
96 | -- | |
97 | * <<basic-tracing-session-control,Start or stop>> a recording session. | |
98 | * <<session-rotation,Archive the current trace chunk>> of a | |
99 | recording session (rotate). | |
100 | * <<taking-a-snapshot,Take a snapshot>> of a recording session. | |
101 | -- | |
102 | + | |
103 | As a reminder, a <<trigger,trigger>> is a condition-actions pair. When | |
104 | the condition of a trigger is satisfied, LTTng attempts to execute its | |
105 | actions. | |
106 | + | |
107 | This feature is also available with the new man:lttng-add-trigger(1), | |
108 | man:lttng-remove-trigger(1), and man:lttng-list-triggers(1) | |
109 | <<lttng-cli,cmd:lttng>> commands. | |
110 | + | |
111 | Starting from LTTng{nbsp}{revision}, a trigger may have more than one | |
112 | action. | |
113 | + | |
114 | See “<<add-event-rule-matches-trigger,Add an ``event rule matches'' | |
115 | trigger to a session daemon>>” to learn more. | |
116 | ||
117 | * The LTTng <<lttng-ust,user space>> and <<lttng-modules,kernel>> | |
118 | tracers offer the new namespace context field `time_ns`, which is the | |
119 | inode number, in the proc file system, of the current clock namespace. | |
120 | + | |
121 | See man:lttng-add-context(1), man:lttng-ust(3), and | |
122 | man:time_namespaces(7). | |
123 | ||
124 | * The link:/man[manual pages] of LTTng-tools now have a terminology and | |
125 | style which match the LTTng Documentation, many fixes, more internal | |
126 | and manual page links, clearer lists and procedures, superior | |
127 | consistency, and usage examples. | |
128 | + | |
129 | The new man:lttng-event-rule(7) manual page explains the new, common | |
130 | way to specify an event rule on the command line. | |
131 | + | |
132 | The new man:lttng-concepts(7) manual page explains the core concepts of | |
133 | LTTng. Its contents is essentially the ``<<core-concepts,Core | |
134 | concepts>>'' section of this documentation, but more adapted to the | |
135 | manual page style. | |
136 | ||
137 | User space tracing:: | |
138 | + | |
139 | [IMPORTANT] | |
140 | ==== | |
141 | The major version part of the `liblttng-ust` | |
142 | https://en.wikipedia.org/wiki/Soname[soname] is bumped, which means you | |
143 | **must recompile** your instrumented applications/libraries and | |
144 | <<tracepoint-provider,tracepoint provider packages>> to use | |
145 | LTTng-UST{nbsp}{revision}. | |
146 | ||
147 | This change became a necessity to clean up the library and for | |
148 | `liblttng-ust` to stop exporting private symbols. | |
149 | ||
150 | Also, LTTng{nbsp}{revision} prepends the `lttng_ust_` and `LTTNG_UST_` | |
151 | prefix to all public macro/definition/function names to offer a | |
152 | consistent API namespace. The LTTng{nbsp}2.12 API is still available; | |
153 | see the ``Compatibility with previous APIs'' section of | |
154 | man:lttng-ust(3). | |
155 | ==== | |
156 | + | |
157 | Other notable changes: | |
158 | + | |
159 | * The `liblttng-ust` C{nbsp}API offers the new man:lttng_ust_vtracef(3) | |
160 | and man:lttng_ust_vtracelog(3) macros which are to | |
161 | man:lttng_ust_tracef(3) and man:lttng_ust_tracelog(3) what | |
162 | man:vprintf(3) is to man:printf(3). | |
163 | ||
164 | * LTTng-UST now only depends on https://liburcu.org/[`liburcu`] at build | |
165 | time, not at run time. | |
166 | ||
167 | Kernel tracing:: | |
168 | + | |
169 | * The preferred display base of event record integer fields which | |
170 | contain memory addresses is now hexadecimal instead of decimal. | |
171 | ||
172 | * The `pid` field is removed from `lttng_statedump_file_descriptor` | |
173 | event records and the `file_table_address` field is added. | |
174 | + | |
175 | This new field is the address of the `files_struct` structure which | |
176 | contains the file descriptor. | |
177 | + | |
178 | See the | |
179 | ``https://github.com/lttng/lttng-modules/commit/e7a0ca7205fd4be7c829d171baa8823fe4784c90[statedump: introduce `file_table_address`]'' | |
180 | patch to learn more. | |
181 | ||
182 | * The `flags` field of `syscall_entry_clone` event records is now a | |
183 | structure containing two enumerations (exit signal and options). | |
184 | + | |
185 | This change makes the flag values more readable and meaningful. | |
186 | + | |
187 | See the | |
188 | ``https://github.com/lttng/lttng-modules/commit/d775625e2ba4825b73b5897e7701ad6e2bdba115[syscalls: Make `clone()`'s `flags` field a 2 enum struct]'' | |
189 | patch to learn more. | |
190 | ||
191 | * The memory footprint of the kernel tracer is improved: the latter only | |
192 | generates metadata for the specific system call recording event rules | |
193 | that you <<enabling-disabling-events,create>>. | |
194 | ||
195 | ||
196 | [[nuts-and-bolts]] | |
197 | == Nuts and bolts | |
198 | ||
199 | What is LTTng? As its name suggests, the _Linux Trace Toolkit: next | |
200 | generation_ is a modern toolkit for tracing Linux systems and | |
201 | applications. So your first question might be: | |
202 | **what is tracing?** | |
203 | ||
204 | ||
205 | [[what-is-tracing]] | |
206 | === What is tracing? | |
207 | ||
208 | As the history of software engineering progressed and led to what | |
209 | we now take for granted--complex, numerous and | |
210 | interdependent software applications running in parallel on | |
211 | sophisticated operating systems like Linux--the authors of such | |
212 | components, software developers, began feeling a natural | |
213 | urge to have tools that would ensure the robustness and good performance | |
214 | of their masterpieces. | |
215 | ||
216 | One major achievement in this field is, inarguably, the | |
217 | https://www.gnu.org/software/gdb/[GNU debugger (GDB)], | |
218 | an essential tool for developers to find and fix bugs. But even the best | |
219 | debugger won't help make your software run faster, and nowadays, faster | |
220 | software means either more work done by the same hardware, or cheaper | |
221 | hardware for the same work. | |
222 | ||
223 | A _profiler_ is often the tool of choice to identify performance | |
224 | bottlenecks. Profiling is suitable to identify _where_ performance is | |
225 | lost in a given piece of software. The profiler outputs a profile, a | |
226 | statistical summary of observed events, which you may use to discover | |
227 | which functions took the most time to execute. However, a profiler won't | |
228 | report _why_ some identified functions are the bottleneck. Bottlenecks | |
229 | might only occur when specific conditions are met, conditions that are | |
230 | sometimes impossible to capture by a statistical profiler, or impossible | |
231 | to reproduce with an application altered by the overhead of an | |
232 | event-based profiler. For a thorough investigation of software | |
233 | performance issues, a history of execution is essential, with the | |
234 | recorded values of variables and context fields you choose, and with as | |
235 | little influence as possible on the instrumented application. This is | |
236 | where tracing comes in handy. | |
237 | ||
238 | _Tracing_ is a technique used to understand what goes on in a running | |
239 | software system. The piece of software used for tracing is called a | |
240 | _tracer_, which is conceptually similar to a tape recorder. When | |
241 | recording, specific instrumentation points placed in the software source | |
242 | code generate events that are saved on a giant tape: a _trace_ file. You | |
243 | can record user application and operating system events at the same | |
244 | time, opening the possibility of resolving a wide range of problems that | |
245 | would otherwise be extremely challenging. | |
246 | ||
247 | Tracing is often compared to _logging_. However, tracers and loggers are | |
248 | two different tools, serving two different purposes. Tracers are | |
249 | designed to record much lower-level events that occur much more | |
250 | frequently than log messages, often in the range of thousands per | |
251 | second, with very little execution overhead. Logging is more appropriate | |
252 | for a very high-level analysis of less frequent events: user accesses, | |
253 | exceptional conditions (errors and warnings, for example), database | |
254 | transactions, instant messaging communications, and such. Simply put, | |
255 | logging is one of the many use cases that can be satisfied with tracing. | |
256 | ||
257 | The list of recorded events inside a trace file can be read manually | |
258 | like a log file for the maximum level of detail, but it's generally | |
259 | much more interesting to perform application-specific analyses to | |
260 | produce reduced statistics and graphs that are useful to resolve a | |
261 | given problem. Trace viewers and analyzers are specialized tools | |
262 | designed to do this. | |
263 | ||
264 | In the end, this is what LTTng is: a powerful, open source set of | |
265 | tools to trace the Linux kernel and user applications at the same time. | |
266 | LTTng is composed of several components actively maintained and | |
267 | developed by its link:/community/#where[community]. | |
268 | ||
269 | ||
270 | [[lttng-alternatives]] | |
271 | === Alternatives to noch:{LTTng} | |
272 | ||
273 | Excluding proprietary solutions, a few competing software tracers | |
274 | exist for Linux: | |
275 | ||
276 | https://github.com/dtrace4linux/linux[dtrace4linux]:: | |
277 | A port of Sun Microsystems' DTrace to Linux. | |
278 | + | |
279 | The cmd:dtrace tool interprets user scripts and is responsible for | |
280 | loading code into the Linux kernel for further execution and collecting | |
281 | the outputted data. | |
282 | ||
283 | https://en.wikipedia.org/wiki/Berkeley_Packet_Filter[eBPF]:: | |
284 | A subsystem in the Linux kernel in which a virtual machine can | |
285 | execute programs passed from the user space to the kernel. | |
286 | + | |
287 | You can attach such programs to tracepoints and kprobes thanks to a | |
288 | system call, and they can output data to the user space when executed | |
289 | thanks to different mechanisms (pipe, VM register values, and eBPF maps, | |
290 | to name a few). | |
291 | ||
292 | https://www.kernel.org/doc/Documentation/trace/ftrace.txt[ftrace]:: | |
293 | The de facto function tracer of the Linux kernel. | |
294 | + | |
295 | Its user interface is a set of special files in sysfs. | |
296 | ||
297 | https://perf.wiki.kernel.org/[perf]:: | |
298 | A performance analysis tool for Linux which supports hardware | |
299 | performance counters, tracepoints, as well as other counters and | |
300 | types of probes. | |
301 | + | |
302 | The controlling utility of perf is the cmd:perf command line/text UI | |
303 | tool. | |
304 | ||
305 | https://linux.die.net/man/1/strace[strace]:: | |
306 | A command-line utility which records system calls made by a | |
307 | user process, as well as signal deliveries and changes of process | |
308 | state. | |
309 | + | |
310 | strace makes use of https://en.wikipedia.org/wiki/Ptrace[ptrace] to | |
311 | fulfill its function. | |
312 | ||
313 | https://www.sysdig.org/[sysdig]:: | |
314 | Like SystemTap, uses scripts to analyze Linux kernel events. | |
315 | + | |
316 | You write scripts, or _chisels_ in the jargon of sysdig, in Lua and | |
317 | sysdig executes them while it traces the system or afterwards. The | |
318 | interface of sysdig is the cmd:sysdig command-line tool as well as the | |
319 | text UI-based cmd:csysdig tool. | |
320 | ||
321 | https://sourceware.org/systemtap/[SystemTap]:: | |
322 | A Linux kernel and user space tracer which uses custom user scripts | |
323 | to produce plain text traces. | |
324 | + | |
325 | SystemTap converts the scripts to the C language, and then compiles them | |
326 | as Linux kernel modules which are loaded to produce trace data. The | |
327 | primary user interface of SystemTap is the cmd:stap command-line tool. | |
328 | ||
329 | The main distinctive features of LTTng is that it produces correlated | |
330 | kernel and user space traces, as well as doing so with the lowest | |
331 | overhead amongst other solutions. It produces trace files in the | |
332 | https://diamon.org/ctf[CTF] format, a file format optimized | |
333 | for the production and analyses of multi-gigabyte data. | |
334 | ||
335 | LTTng is the result of more than 10{nbsp}years of active open source | |
336 | development by a community of passionate developers. LTTng is currently | |
337 | available on major desktop and server Linux distributions. | |
338 | ||
339 | The main interface for tracing control is a single command-line tool | |
340 | named cmd:lttng. The latter can create several recording sessions, enable | |
341 | and disable recording event rules on the fly, filter events efficiently | |
342 | with custom user expressions, start and stop tracing, and much more. | |
343 | LTTng can write the traces on the file system or send them over the | |
344 | network, and keep them totally or partially. You can make LTTng execute | |
345 | user-defined actions when LTTng emits an event. You can view the traces | |
346 | once tracing becomes inactive or as LTTng records events. | |
347 | ||
348 | <<installing-lttng,Install LTTng now>> and | |
349 | <<getting-started,start tracing>>! | |
350 | ||
351 | ||
352 | [[installing-lttng]] | |
353 | == Installation | |
354 | ||
355 | **LTTng** is a set of software <<plumbing,components>> which interact to | |
356 | <<instrumenting,instrument>> the Linux kernel and user applications, and | |
357 | to <<controlling-tracing,control tracing>> (start and stop | |
358 | recording, create recording event rules, and the rest). Those | |
359 | components are bundled into the following packages: | |
360 | ||
361 | LTTng-tools:: | |
362 | Libraries and command-line interface to control tracing. | |
363 | ||
364 | LTTng-modules:: | |
365 | Linux kernel modules to instrument and trace the kernel. | |
366 | ||
367 | LTTng-UST:: | |
368 | Libraries and Java/Python packages to instrument and trace user | |
369 | applications. | |
370 | ||
371 | Most distributions mark the LTTng-modules and LTTng-UST packages as | |
372 | optional when installing LTTng-tools (which is always required). In the | |
373 | following sections, we always provide the steps to install all three, | |
374 | but note that: | |
375 | ||
376 | * You only need to install LTTng-modules if you intend to use | |
377 | the Linux kernel LTTng tracer. | |
378 | ||
379 | * You only need to install LTTng-UST if you intend to use the user | |
380 | space LTTng tracer. | |
381 | ||
60cb79ae KS |
382 | [role="growable"] |
383 | .Availability of LTTng{nbsp}{revision} for major Linux distributions as of 17{nbsp}October{nbsp}2023. | |
384 | ||
385 | |=== | |
386 | |Distribution |Available in releases | |
387 | ||
388 | |https://www.ubuntu.com/[Ubuntu] | |
389 | |xref:ubuntu[Ubuntu 22.04 LTS _Jammy Jellyfish_, Ubuntu 23.04 _Lunar Lobster_, and Ubuntu 23.10 _Mantic Minotaur_]. | |
390 | ||
391 | Ubuntu{nbsp}18.04 LTS _Bionic Beaver_ and Ubuntu{nbsp}20.04 LTS _Focal Fossa_: | |
392 | <<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>. | |
393 | ||
394 | |https://www.debian.org/[Debian] | |
395 | |<<debian,Debian{nbsp}12 _bookworm_>>. | |
396 | ||
397 | |https://getfedora.org/[Fedora] | |
398 | |xref:fedora[Fedora{nbsp}37, Fedora{nbsp}38, and Fedora{nbsp}39]. | |
399 | ||
400 | |https://www.archlinux.org/[Arch Linux] | |
401 | |<<arch-linux,_extra_ repository and AUR>>. | |
402 | ||
403 | |https://alpinelinux.org/[Alpine Linux] | |
404 | |xref:alpine-linux[Alpine Linux{nbsp}3.16, Alpine Linux{nbsp}3.17, and Alpine Linux{nbsp}3.18]. | |
405 | ||
406 | |https://buildroot.org/[Buildroot] | |
407 | |xref:buildroot[Buildroot{nbsp}2022.02, Buildroot{nbsp}2022.05, | |
408 | Buildroot{nbsp}2022.08, Buildroot{nbsp}2022.11, Buildroot{nbsp}2023.02, | |
409 | Buildroot{nbsp}2023.05, and Buildroot{nbsp}2023.08]. | |
410 | ||
411 | |https://www.openembedded.org/wiki/Main_Page[OpenEmbedded] and | |
412 | https://www.yoctoproject.org/[Yocto] | |
413 | |xref:oe-yocto[Yocto Project{nbsp}3.3 _Honister_, Yocto Project{nbsp}4.0 _Kirkstone_, | |
414 | Yocto Project{nbsp}4.1 _Langdale_, Yocto Project{nbsp}4.2 _Mickledore_, and | |
415 | Yocto Project{nbsp}4.3 _Nanbield_]. | |
416 | ||
417 | |==== | |
418 | ||
50e95807 PP |
419 | [NOTE] |
420 | ==== | |
50e95807 PP |
421 | For https://www.redhat.com/[RHEL] and https://www.suse.com/[SLES] |
422 | packages, see https://packages.efficios.com/[EfficiOS Enterprise | |
423 | Packages]. | |
424 | ||
425 | For other distributions, <<building-from-source,build LTTng from | |
426 | source>>. | |
427 | ==== | |
428 | ||
60cb79ae KS |
429 | [[ubuntu]] |
430 | === [[ubuntu-official-repository]]Ubuntu | |
431 | ||
432 | LTTng{nbsp}{revision} is available on Ubuntu 22.04 LTS _Jammy Jellyfish_, Ubuntu 23.04 _Lunar Lobster_, and Ubuntu 23.10 _Mantic Minotaur_. For previous supported releases of Ubuntu, <<ubuntu-ppa,use the LTTng Stable{nbsp}{revision} PPA>>. | |
433 | ||
434 | To install LTTng{nbsp}{revision} on Ubuntu{nbsp}22.04 LTS _Jammy Jellyfish_: | |
435 | ||
436 | . Install the main LTTng{nbsp}{revision} packages: | |
437 | + | |
438 | -- | |
439 | [role="term"] | |
440 | ---- | |
441 | # apt-get install lttng-tools | |
442 | # apt-get install lttng-modules-dkms | |
443 | # apt-get install liblttng-ust-dev | |
444 | ---- | |
445 | -- | |
446 | ||
447 | . **If you need to instrument and trace <<java-application,Java applications>>**, | |
448 | install the LTTng-UST Java agent: | |
449 | + | |
450 | -- | |
451 | [role="term"] | |
452 | ---- | |
453 | # apt-get install liblttng-ust-agent-java | |
454 | ---- | |
455 | -- | |
456 | ||
457 | . **If you need to instrument and trace <<python-application,Python{nbsp}3 | |
458 | applications>>**, install the LTTng-UST Python agent: | |
459 | + | |
460 | -- | |
461 | [role="term"] | |
462 | ---- | |
463 | # apt-get install python3-lttngust | |
464 | ---- | |
465 | -- | |
466 | ||
467 | [[ubuntu-ppa]] | |
468 | === Ubuntu: noch:{LTTng} Stable {revision} PPA | |
469 | ||
470 | The https://launchpad.net/~lttng/+archive/ubuntu/stable-{revision}[LTTng | |
471 | Stable{nbsp}{revision} PPA] offers the latest stable LTTng{nbsp}{revision} | |
472 | packages for Ubuntu{nbsp}18.04 LTS _Bionic Beaver_, Ubuntu{nbsp}20.04 LTS _Focal Fossa_, | |
473 | and Ubuntu{nbsp}22.04 LTS _Jammy Jellyfish_. | |
474 | ||
475 | To install LTTng{nbsp}{revision} from the LTTng Stable{nbsp}{revision} | |
476 | PPA: | |
477 | ||
478 | . Add the LTTng Stable{nbsp}{revision} PPA repository and update the | |
479 | list of packages: | |
480 | + | |
481 | -- | |
482 | [role="term",subs="attributes"] | |
483 | ---- | |
484 | # apt-add-repository ppa:lttng/stable-{revision} | |
485 | # apt-get update | |
486 | ---- | |
487 | -- | |
488 | ||
489 | . Install the main LTTng{nbsp}{revision} packages: | |
490 | + | |
491 | -- | |
492 | [role="term"] | |
493 | ---- | |
494 | # apt-get install lttng-tools | |
495 | # apt-get install lttng-modules-dkms | |
496 | # apt-get install liblttng-ust-dev | |
497 | ---- | |
498 | -- | |
499 | ||
500 | . **If you need to instrument and trace | |
501 | <<java-application,Java applications>>**, install the LTTng-UST | |
502 | Java agent: | |
503 | + | |
504 | -- | |
505 | [role="term"] | |
506 | ---- | |
507 | # apt-get install liblttng-ust-agent-java | |
508 | ---- | |
509 | -- | |
510 | ||
511 | . **If you need to instrument and trace | |
512 | <<python-application,Python{nbsp}3 applications>>**, install the | |
513 | LTTng-UST Python agent: | |
514 | + | |
515 | -- | |
516 | [role="term"] | |
517 | ---- | |
518 | # apt-get install python3-lttngust | |
519 | ---- | |
520 | -- | |
521 | ||
522 | [[debian]] | |
523 | === Debian | |
524 | ||
525 | To install LTTng{nbsp}{revision} on Debian{nbsp}12 _bookworm_: | |
526 | ||
527 | . Install the main LTTng{nbsp}{revision} packages: | |
528 | + | |
529 | -- | |
530 | [role="term"] | |
531 | ---- | |
532 | # apt install lttng-modules-dkms | |
533 | # apt install liblttng-ust-dev | |
534 | # apt install lttng-tools | |
535 | ---- | |
536 | -- | |
537 | ||
538 | . **If you need to instrument and trace <<java-application,Java | |
539 | applications>>**, install the LTTng-UST Java agent: | |
540 | + | |
541 | -- | |
542 | [role="term"] | |
543 | ---- | |
544 | # apt install liblttng-ust-agent-java | |
545 | ---- | |
546 | -- | |
547 | ||
548 | . **If you need to instrument and trace <<python-application,Python | |
549 | applications>>**, install the LTTng-UST Python agent: | |
550 | + | |
551 | -- | |
552 | [role="term"] | |
553 | ---- | |
554 | # apt install python3-lttngust | |
555 | ---- | |
556 | -- | |
557 | ||
558 | [[fedora]] | |
559 | === Fedora | |
560 | ||
561 | To install LTTng{nbsp}{revision} on Fedora{nbsp}37, Fedora{nbsp}38, or | |
562 | Fedora{nbsp}39: | |
563 | ||
564 | . Install the LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision} | |
565 | packages: | |
566 | + | |
567 | -- | |
568 | [role="term"] | |
569 | ---- | |
570 | # yum install lttng-tools | |
571 | # yum install lttng-ust | |
572 | ---- | |
573 | -- | |
574 | ||
575 | . Download, build, and install the latest LTTng-modules{nbsp}{revision}: | |
576 | + | |
577 | -- | |
89332957 | 578 | [role="term",subs="attributes,specialcharacters"] |
60cb79ae KS |
579 | ---- |
580 | $ cd $(mktemp -d) && | |
581 | wget http://lttng.org/files/lttng-modules/lttng-modules-latest-{revision}.tar.bz2 && | |
582 | tar -xf lttng-modules-latest-{revision}.tar.bz2 && | |
583 | cd lttng-modules-{revision}.* && | |
584 | make && | |
585 | sudo make modules_install && | |
586 | sudo depmod -a | |
587 | ---- | |
588 | -- | |
589 | ||
590 | [IMPORTANT] | |
591 | .Java and Python application instrumentation and tracing | |
592 | ==== | |
593 | If you need to instrument and trace <<java-application,Java | |
594 | applications>> on Fedora, you need to build and install | |
595 | LTTng-UST{nbsp}{revision} <<building-from-source,from source>> and pass | |
596 | the `--enable-java-agent-jul`, `--enable-java-agent-log4j`, or | |
597 | `--enable-java-agent-all` options to the `configure` script, depending | |
598 | on which Java logging framework you use. | |
599 | ||
600 | If you need to instrument and trace <<python-application,Python | |
601 | applications>> on Fedora, you need to build and install | |
602 | LTTng-UST{nbsp}{revision} from source and pass the | |
603 | `--enable-python-agent` option to the `configure` script. | |
604 | ==== | |
605 | ||
606 | ||
607 | [[arch-linux]] | |
608 | === Arch Linux | |
609 | ||
610 | LTTng-UST{nbsp}{revision} is available in the _extra_ | |
611 | repository of Arch Linux, while LTTng-tools{nbsp}{revision} and | |
612 | LTTng-modules{nbsp}{revision} are available in the | |
613 | https://aur.archlinux.org/[AUR]. | |
614 | ||
615 | To install LTTng{nbsp}{revision} on Arch Linux, using | |
616 | https://github.com/Jguer/yay[yay] for the AUR packages: | |
617 | ||
618 | . Install the main LTTng{nbsp}{revision} packages: | |
619 | + | |
620 | -- | |
621 | [role="term"] | |
622 | ---- | |
623 | # pacman -Sy lttng-ust | |
624 | $ yay -Sy lttng-tools | |
625 | $ yay -Sy lttng-modules | |
626 | ---- | |
627 | -- | |
628 | ||
629 | . **If you need to instrument and trace <<python-application,Python | |
630 | applications>>**, install the LTTng-UST Python agent: | |
631 | + | |
632 | -- | |
633 | [role="term"] | |
634 | ---- | |
635 | # pacman -Sy python-lttngust | |
636 | ---- | |
637 | -- | |
638 | ||
639 | ||
640 | [[alpine-linux]] | |
641 | === Alpine Linux | |
642 | ||
643 | To install LTTng-tools{nbsp}{revision} and LTTng-UST{nbsp}{revision} on | |
644 | Alpine Linux{nbsp}3.16, Alpine Linux{nbsp}3.17, or Alpine Linux{nbsp}3.18: | |
645 | ||
646 | . Add the LTTng packages: | |
647 | + | |
648 | -- | |
649 | [role="term"] | |
650 | ---- | |
651 | # apk add lttng-tools | |
652 | # apk add lttng-ust-dev | |
653 | ---- | |
654 | -- | |
655 | ||
656 | . Download, build, and install the latest LTTng-modules{nbsp}{revision}: | |
657 | + | |
658 | -- | |
89332957 | 659 | [role="term",subs="attributes,specialcharacters"] |
60cb79ae KS |
660 | ---- |
661 | $ cd $(mktemp -d) && | |
662 | wget http://lttng.org/files/lttng-modules/lttng-modules-latest-{revision}.tar.bz2 && | |
663 | tar -xf lttng-modules-latest-{revision}.tar.bz2 && | |
664 | cd lttng-modules-{revision}.* && | |
665 | make && | |
666 | sudo make modules_install && | |
667 | sudo depmod -a | |
668 | ---- | |
669 | -- | |
670 | ||
671 | ||
672 | [[buildroot]] | |
673 | === Buildroot | |
674 | ||
675 | To install LTTng{nbsp}{revision} on Buildroot{nbsp}2022.02, Buildroot{nbsp}2022.05, | |
676 | Buildroot{nbsp}2022.08, Buildroot{nbsp}2022.11, Buildroot{nbsp}2023.02, | |
677 | Buildroot{nbsp}2023.05, or Buildroot{nbsp}2023.08: | |
678 | ||
679 | . Launch the Buildroot configuration tool: | |
680 | + | |
681 | -- | |
682 | [role="term"] | |
683 | ---- | |
684 | $ make menuconfig | |
685 | ---- | |
686 | -- | |
687 | ||
688 | . In **Kernel**, check **Linux kernel**. | |
689 | . In **Toolchain**, check **Enable WCHAR support**. | |
690 | . In **Target packages**{nbsp}→ **Debugging, profiling and benchmark**, | |
691 | check **lttng-modules** and **lttng-tools**. | |
692 | . In **Target packages**{nbsp}→ **Libraries**{nbsp}→ | |
693 | **Other**, check **lttng-libust**. | |
694 | ||
695 | ||
696 | [[oe-yocto]] | |
697 | === OpenEmbedded and Yocto | |
698 | ||
699 | LTTng{nbsp}{revision} recipes are available in the | |
700 | https://layers.openembedded.org/layerindex/branch/master/layer/openembedded-core/[`openembedded-core`] | |
701 | layer for Yocto Project{nbsp}3.3 _Honister_, Yocto Project{nbsp}4.0 _Kirkstone_, | |
702 | Yocto Project{nbsp}4.1 _Langdale_, Yocto Project{nbsp}4.2 _Mickledore_, and | |
703 | Yocto Project{nbsp}4.3 _Nanbield_ under the following names: | |
704 | ||
705 | * `lttng-tools` | |
706 | * `lttng-modules` | |
707 | * `lttng-ust` | |
708 | ||
709 | With BitBake, the simplest way to include LTTng recipes in your target | |
710 | image is to add them to `IMAGE_INSTALL_append` in path:{conf/local.conf}: | |
711 | ||
712 | ---- | |
713 | IMAGE_INSTALL_append = " lttng-tools lttng-modules lttng-ust" | |
714 | ---- | |
715 | ||
716 | If you use Hob: | |
717 | ||
718 | . Select a machine and an image recipe. | |
719 | . Click **Edit image recipe**. | |
720 | . Under the **All recipes** tab, search for **lttng**. | |
721 | . Check the desired LTTng recipes. | |
722 | ||
50e95807 PP |
723 | |
724 | [[building-from-source]] | |
725 | === Build from source | |
726 | ||
727 | To build and install LTTng{nbsp}{revision} from source: | |
728 | ||
729 | . Using the package manager of your distribution, or from source, | |
730 | install the following dependencies of LTTng-tools and LTTng-UST: | |
731 | + | |
732 | -- | |
733 | * https://sourceforge.net/projects/libuuid/[libuuid] | |
734 | * https://directory.fsf.org/wiki/Popt[popt] | |
735 | * https://liburcu.org/[Userspace RCU] | |
736 | * http://www.xmlsoft.org/[libxml2] | |
737 | * **Optional**: https://github.com/numactl/numactl[numactl] | |
738 | -- | |
739 | ||
740 | . Download, build, and install the latest LTTng-modules{nbsp}{revision}: | |
741 | + | |
742 | -- | |
743 | [role="term"] | |
744 | ---- | |
745 | $ cd $(mktemp -d) && | |
746 | wget https://lttng.org/files/lttng-modules/lttng-modules-latest-2.13.tar.bz2 && | |
747 | tar -xf lttng-modules-latest-2.13.tar.bz2 && | |
748 | cd lttng-modules-2.13.* && | |
749 | make && | |
750 | sudo make modules_install && | |
751 | sudo depmod -a | |
752 | ---- | |
753 | -- | |
754 | ||
755 | . Download, build, and install the latest LTTng-UST{nbsp}{revision}: | |
756 | + | |
757 | -- | |
758 | [role="term"] | |
759 | ---- | |
760 | $ cd $(mktemp -d) && | |
761 | wget https://lttng.org/files/lttng-ust/lttng-ust-latest-2.13.tar.bz2 && | |
762 | tar -xf lttng-ust-latest-2.13.tar.bz2 && | |
763 | cd lttng-ust-2.13.* && | |
764 | ./configure && | |
765 | make && | |
766 | sudo make install && | |
767 | sudo ldconfig | |
768 | ---- | |
769 | -- | |
770 | + | |
771 | Add `--disable-numa` to `./configure` if you don't have | |
772 | https://github.com/numactl/numactl[numactl]. | |
773 | + | |
774 | -- | |
775 | [IMPORTANT] | |
776 | .Java and Python application tracing | |
777 | ==== | |
778 | If you need to instrument and have LTTng trace <<java-application,Java | |
779 | applications>>, pass the `--enable-java-agent-jul`, | |
780 | `--enable-java-agent-log4j`, or `--enable-java-agent-all` options to the | |
781 | `configure` script, depending on which Java logging framework you use. | |
782 | ||
783 | If you need to instrument and have LTTng trace | |
784 | <<python-application,Python applications>>, pass the | |
785 | `--enable-python-agent` option to the `configure` script. You can set | |
786 | the env:PYTHON environment variable to the path to the Python interpreter | |
787 | for which to install the LTTng-UST Python agent package. | |
788 | ==== | |
789 | -- | |
790 | + | |
791 | -- | |
792 | [NOTE] | |
793 | ==== | |
794 | By default, LTTng-UST libraries are installed to | |
795 | dir:{/usr/local/lib}, which is the de facto directory in which to | |
796 | keep self-compiled and third-party libraries. | |
797 | ||
798 | When <<building-tracepoint-providers-and-user-application,linking an | |
799 | instrumented user application with `liblttng-ust`>>: | |
800 | ||
801 | * Append `/usr/local/lib` to the env:LD_LIBRARY_PATH environment | |
802 | variable. | |
803 | ||
804 | * Pass the `-L/usr/local/lib` and `-Wl,-rpath,/usr/local/lib` options to | |
805 | man:gcc(1), man:g++(1), or man:clang(1). | |
806 | ==== | |
807 | -- | |
808 | ||
809 | . Download, build, and install the latest LTTng-tools{nbsp}{revision}: | |
810 | + | |
811 | -- | |
812 | [role="term"] | |
813 | ---- | |
814 | $ cd $(mktemp -d) && | |
815 | wget https://lttng.org/files/lttng-tools/lttng-tools-latest-2.13.tar.bz2 && | |
816 | tar -xf lttng-tools-latest-2.13.tar.bz2 && | |
817 | cd lttng-tools-2.13.* && | |
818 | ./configure && | |
819 | make && | |
820 | sudo make install && | |
821 | sudo ldconfig | |
822 | ---- | |
823 | -- | |
824 | ||
825 | TIP: The https://github.com/eepp/vlttng[vlttng tool] can do all the | |
826 | previous steps automatically for a given version of LTTng and confine | |
827 | the installed files to a specific directory. This can be useful to try | |
828 | LTTng without installing it on your system. | |
829 | ||
f9bace78 PP |
830 | [[linux-kernel-sig]] |
831 | === Linux kernel module signature | |
832 | ||
833 | Linux kernel modules require trusted signatures in order to be loaded | |
834 | when any of the following is true: | |
835 | ||
836 | * The system boots with | |
837 | https://uefi.org/specs/UEFI/2.10/32_Secure_Boot_and_Driver_Signing.html#secure-boot-and-driver-signing[Secure Boot] | |
838 | enabled. | |
839 | ||
840 | * The Linux kernel which boots is configured with | |
841 | `CONFIG_MODULE_SIG_FORCE`. | |
842 | ||
843 | * The Linux kernel boots with a command line containing | |
844 | `module.sig_enforce=1`. | |
845 | ||
846 | .`root` user running <<lttng-sessiond,`lttng-sessiond`>> which fails to load a required <<lttng-modules,kernel module>> due to the signature enforcement policies. | |
847 | ==== | |
848 | [role="term"] | |
849 | ---- | |
850 | # lttng-sessiond | |
851 | Warning: No tracing group detected | |
852 | modprobe: ERROR: could not insert 'lttng_ring_buffer_client_discard': Key was rejected by service | |
853 | Error: Unable to load required module lttng-ring-buffer-client-discard | |
854 | Warning: No kernel tracer available | |
855 | ---- | |
856 | ==== | |
857 | ||
858 | There are several methods to enroll trusted keys for signing modules | |
859 | that are built from source. The precise details vary from one Linux | |
860 | version to another, and distributions may have their own mechanisms. For | |
861 | example, https://github.com/dell/dkms[DKMS] may autogenerate a key and | |
862 | sign modules, but the key isn't automatically enrolled. | |
863 | ||
864 | See | |
865 | https://www.kernel.org/doc/html/latest/admin-guide/module-signing.html[Kernel | |
866 | module signing facility] and the documentation of your distribution | |
867 | to learn more about signing Linux kernel modules. | |
50e95807 PP |
868 | |
869 | [[getting-started]] | |
870 | == Quick start | |
871 | ||
872 | This is a short guide to get started quickly with LTTng kernel and user | |
873 | space tracing. | |
874 | ||
875 | Before you follow this guide, make sure to <<installing-lttng,install>> | |
876 | LTTng. | |
877 | ||
878 | This tutorial walks you through the steps to: | |
879 | ||
880 | . <<tracing-the-linux-kernel,Record Linux kernel events>>. | |
881 | ||
882 | . <<tracing-your-own-user-application,Record the events of a user | |
883 | application>> written in C. | |
884 | ||
885 | . <<viewing-and-analyzing-your-traces,View and analyze the | |
886 | recorded events>>. | |
887 | ||
888 | ||
889 | [[tracing-the-linux-kernel]] | |
890 | === Record Linux kernel events | |
891 | ||
892 | NOTE: The following command lines start with the `#` prompt because you | |
893 | need root privileges to control the Linux kernel LTTng tracer. You can | |
894 | also control the kernel tracer as a regular user if your Unix user is a | |
895 | member of the <<tracing-group,tracing group>>. | |
896 | ||
897 | . Create a <<tracing-session,recording session>> to write LTTng traces | |
898 | to dir:{/tmp/my-kernel-trace}: | |
899 | + | |
900 | -- | |
901 | [role="term"] | |
902 | ---- | |
903 | # lttng create my-kernel-session --output=/tmp/my-kernel-trace | |
904 | ---- | |
905 | -- | |
906 | ||
907 | . List the available kernel tracepoints and system calls: | |
908 | + | |
909 | -- | |
910 | [role="term"] | |
911 | ---- | |
912 | # lttng list --kernel | |
913 | # lttng list --kernel --syscall | |
914 | ---- | |
915 | -- | |
916 | ||
917 | . Create <<event,recording event rules>> which match events having | |
918 | the desired names, for example the `sched_switch` and | |
919 | `sched_process_fork` tracepoints, and the man:open(2) and man:close(2) | |
920 | system calls: | |
921 | + | |
922 | -- | |
923 | [role="term"] | |
924 | ---- | |
925 | # lttng enable-event --kernel sched_switch,sched_process_fork | |
926 | # lttng enable-event --kernel --syscall open,close | |
927 | ---- | |
928 | -- | |
929 | + | |
930 | Create a recording event rule which matches _all_ the Linux kernel | |
931 | tracepoint events with the opt:lttng-enable-event(1):--all option | |
932 | (recording with such a recording event rule generates a lot of data): | |
933 | + | |
934 | -- | |
935 | [role="term"] | |
936 | ---- | |
937 | # lttng enable-event --kernel --all | |
938 | ---- | |
939 | -- | |
940 | ||
941 | . <<basic-tracing-session-control,Start recording>>: | |
942 | + | |
943 | -- | |
944 | [role="term"] | |
945 | ---- | |
946 | # lttng start | |
947 | ---- | |
948 | -- | |
949 | ||
950 | . Do some operation on your system for a few seconds. For example, | |
951 | load a website, or list the files of a directory. | |
952 | ||
953 | . <<creating-destroying-tracing-sessions,Destroy>> the current | |
954 | recording session: | |
955 | + | |
956 | -- | |
957 | [role="term"] | |
958 | ---- | |
959 | # lttng destroy | |
960 | ---- | |
961 | -- | |
962 | + | |
963 | The man:lttng-destroy(1) command doesn't destroy the trace data; it | |
964 | only destroys the state of the recording session. | |
965 | + | |
966 | The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command | |
967 | implicitly (see ``<<basic-tracing-session-control,Start and stop a | |
968 | recording session>>''). You need to stop recording to make LTTng flush | |
969 | the remaining trace data and make the trace readable. | |
970 | ||
971 | . For the sake of this example, make the recorded trace accessible to | |
972 | the non-root users: | |
973 | + | |
974 | -- | |
975 | [role="term"] | |
976 | ---- | |
977 | # chown -R $(whoami) /tmp/my-kernel-trace | |
978 | ---- | |
979 | -- | |
980 | ||
981 | See ``<<viewing-and-analyzing-your-traces,View and analyze the | |
982 | recorded events>>'' to view the recorded events. | |
983 | ||
984 | ||
985 | [[tracing-your-own-user-application]] | |
986 | === Record user application events | |
987 | ||
988 | This section walks you through a simple example to record the events of | |
989 | a _Hello world_ program written in{nbsp}C. | |
990 | ||
991 | To create the traceable user application: | |
992 | ||
993 | . Create the tracepoint provider header file, which defines the | |
994 | tracepoints and the events they can generate: | |
995 | + | |
996 | -- | |
997 | [source,c] | |
998 | .path:{hello-tp.h} | |
999 | ---- | |
1000 | #undef LTTNG_UST_TRACEPOINT_PROVIDER | |
1001 | #define LTTNG_UST_TRACEPOINT_PROVIDER hello_world | |
1002 | ||
1003 | #undef LTTNG_UST_TRACEPOINT_INCLUDE | |
1004 | #define LTTNG_UST_TRACEPOINT_INCLUDE "./hello-tp.h" | |
1005 | ||
1006 | #if !defined(_HELLO_TP_H) || defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ) | |
1007 | #define _HELLO_TP_H | |
1008 | ||
1009 | #include <lttng/tracepoint.h> | |
1010 | ||
1011 | LTTNG_UST_TRACEPOINT_EVENT( | |
1012 | hello_world, | |
1013 | my_first_tracepoint, | |
1014 | LTTNG_UST_TP_ARGS( | |
1015 | int, my_integer_arg, | |
1016 | char *, my_string_arg | |
1017 | ), | |
1018 | LTTNG_UST_TP_FIELDS( | |
1019 | lttng_ust_field_string(my_string_field, my_string_arg) | |
1020 | lttng_ust_field_integer(int, my_integer_field, my_integer_arg) | |
1021 | ) | |
1022 | ) | |
1023 | ||
1024 | #endif /* _HELLO_TP_H */ | |
1025 | ||
1026 | #include <lttng/tracepoint-event.h> | |
1027 | ---- | |
1028 | -- | |
1029 | ||
1030 | . Create the tracepoint provider package source file: | |
1031 | + | |
1032 | -- | |
1033 | [source,c] | |
1034 | .path:{hello-tp.c} | |
1035 | ---- | |
1036 | #define LTTNG_UST_TRACEPOINT_CREATE_PROBES | |
1037 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
1038 | ||
1039 | #include "hello-tp.h" | |
1040 | ---- | |
1041 | -- | |
1042 | ||
1043 | . Build the tracepoint provider package: | |
1044 | + | |
1045 | -- | |
1046 | [role="term"] | |
1047 | ---- | |
1048 | $ gcc -c -I. hello-tp.c | |
1049 | ---- | |
1050 | -- | |
1051 | ||
1052 | . Create the _Hello World_ application source file: | |
1053 | + | |
1054 | -- | |
1055 | [source,c] | |
1056 | .path:{hello.c} | |
1057 | ---- | |
1058 | #include <stdio.h> | |
1059 | #include "hello-tp.h" | |
1060 | ||
1061 | int main(int argc, char *argv[]) | |
1062 | { | |
1063 | unsigned int i; | |
1064 | ||
1065 | puts("Hello, World!\nPress Enter to continue..."); | |
1066 | ||
1067 | /* | |
1068 | * The following getchar() call only exists for the purpose of this | |
1069 | * demonstration, to pause the application in order for you to have | |
1070 | * time to list its tracepoints. You don't need it otherwise. | |
1071 | */ | |
1072 | getchar(); | |
1073 | ||
1074 | /* | |
1075 | * An lttng_ust_tracepoint() call. | |
1076 | * | |
1077 | * Arguments, as defined in `hello-tp.h`: | |
1078 | * | |
1079 | * 1. Tracepoint provider name (required) | |
1080 | * 2. Tracepoint name (required) | |
1081 | * 3. `my_integer_arg` (first user-defined argument) | |
1082 | * 4. `my_string_arg` (second user-defined argument) | |
1083 | * | |
1084 | * Notice the tracepoint provider and tracepoint names are | |
1085 | * C identifiers, NOT strings: they're in fact parts of variables | |
1086 | * that the macros in `hello-tp.h` create. | |
1087 | */ | |
1088 | lttng_ust_tracepoint(hello_world, my_first_tracepoint, 23, | |
1089 | "hi there!"); | |
1090 | ||
1091 | for (i = 0; i < argc; i++) { | |
1092 | lttng_ust_tracepoint(hello_world, my_first_tracepoint, | |
1093 | i, argv[i]); | |
1094 | } | |
1095 | ||
1096 | puts("Quitting now!"); | |
1097 | lttng_ust_tracepoint(hello_world, my_first_tracepoint, | |
1098 | i * i, "i^2"); | |
1099 | return 0; | |
1100 | } | |
1101 | ---- | |
1102 | -- | |
1103 | ||
1104 | . Build the application: | |
1105 | + | |
1106 | -- | |
1107 | [role="term"] | |
1108 | ---- | |
1109 | $ gcc -c hello.c | |
1110 | ---- | |
1111 | -- | |
1112 | ||
1113 | . Link the application with the tracepoint provider package, | |
1114 | `liblttng-ust` and `libdl`: | |
1115 | + | |
1116 | -- | |
1117 | [role="term"] | |
1118 | ---- | |
1119 | $ gcc -o hello hello.o hello-tp.o -llttng-ust -ldl | |
1120 | ---- | |
1121 | -- | |
1122 | ||
1123 | Here's the whole build process: | |
1124 | ||
1125 | [role="img-100"] | |
1126 | .Build steps of the user space tracing tutorial. | |
1127 | image::ust-flow.png[] | |
1128 | ||
1129 | To record the events of the user application: | |
1130 | ||
1131 | . Run the application with a few arguments: | |
1132 | + | |
1133 | -- | |
1134 | [role="term"] | |
1135 | ---- | |
1136 | $ ./hello world and beyond | |
1137 | ---- | |
1138 | -- | |
1139 | + | |
1140 | You see: | |
1141 | + | |
1142 | -- | |
1143 | ---- | |
1144 | Hello, World! | |
1145 | Press Enter to continue... | |
1146 | ---- | |
1147 | -- | |
1148 | ||
1149 | . Start an LTTng <<lttng-sessiond,session daemon>>: | |
1150 | + | |
1151 | -- | |
1152 | [role="term"] | |
1153 | ---- | |
1154 | $ lttng-sessiond --daemonize | |
1155 | ---- | |
1156 | -- | |
1157 | + | |
1158 | NOTE: A session daemon might already be running, for example as a | |
1159 | service that the service manager of your distribution started. | |
1160 | ||
1161 | . List the available user space tracepoints: | |
1162 | + | |
1163 | -- | |
1164 | [role="term"] | |
1165 | ---- | |
1166 | $ lttng list --userspace | |
1167 | ---- | |
1168 | -- | |
1169 | + | |
1170 | You see the `hello_world:my_first_tracepoint` tracepoint listed | |
1171 | under the `./hello` process. | |
1172 | ||
1173 | . Create a <<tracing-session,recording session>>: | |
1174 | + | |
1175 | -- | |
1176 | [role="term"] | |
1177 | ---- | |
1178 | $ lttng create my-user-space-session | |
1179 | ---- | |
1180 | -- | |
1181 | ||
1182 | . Create a <<event,recording event rule>> which matches user space | |
1183 | tracepoint events named `hello_world:my_first_tracepoint`: | |
1184 | + | |
1185 | -- | |
1186 | [role="term"] | |
1187 | ---- | |
1188 | $ lttng enable-event --userspace hello_world:my_first_tracepoint | |
1189 | ---- | |
1190 | -- | |
1191 | ||
1192 | . <<basic-tracing-session-control,Start recording>>: | |
1193 | + | |
1194 | -- | |
1195 | [role="term"] | |
1196 | ---- | |
1197 | $ lttng start | |
1198 | ---- | |
1199 | -- | |
1200 | ||
1201 | . Go back to the running `hello` application and press **Enter**. | |
1202 | + | |
1203 | The program executes all `lttng_ust_tracepoint()` instrumentation | |
1204 | points, emitting events as the event rule you created in step{nbsp}5 | |
1205 | matches them, and | |
1206 | exits. | |
1207 | ||
1208 | . <<creating-destroying-tracing-sessions,Destroy>> the current | |
1209 | recording session: | |
1210 | + | |
1211 | -- | |
1212 | [role="term"] | |
1213 | ---- | |
1214 | $ lttng destroy | |
1215 | ---- | |
1216 | -- | |
1217 | + | |
1218 | The man:lttng-destroy(1) command doesn't destroy the trace data; it | |
1219 | only destroys the state of the recording session. | |
1220 | + | |
1221 | The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command | |
1222 | implicitly (see ``<<basic-tracing-session-control,Start and stop a | |
1223 | recording session>>''). You need to stop recording to make LTTng flush | |
1224 | the remaining trace data and make the trace readable. | |
1225 | ||
1226 | By default, LTTng saves the traces to the | |
1227 | +$LTTNG_HOME/lttng-traces/__NAME__-__DATE__-__TIME__+ directory, where | |
1228 | +__NAME__+ is the recording session name. The env:LTTNG_HOME environment | |
1229 | variable defaults to `$HOME` if not set. | |
1230 | ||
1231 | ||
1232 | [[viewing-and-analyzing-your-traces]] | |
1233 | === View and analyze the recorded events | |
1234 | ||
1235 | Once you have completed the <<tracing-the-linux-kernel,Record Linux | |
1236 | kernel events>> and <<tracing-your-own-user-application,Record user | |
1237 | application events>> tutorials, you can inspect the recorded events. | |
1238 | ||
1239 | There are many tools you can use to read LTTng traces: | |
1240 | ||
1241 | https://babeltrace.org/[Babeltrace{nbsp}2]:: | |
1242 | A rich, flexible trace manipulation toolkit which includes | |
1243 | a versatile command-line interface | |
1244 | (man:babeltrace2(1)), | |
1245 | a https://babeltrace.org/docs/v2.0/libbabeltrace2/[C{nbsp}library], | |
1246 | and https://babeltrace.org/docs/v2.0/python/bt2/[Python{nbsp}3 bindings] | |
1247 | so that you can easily process or convert an LTTng trace with | |
1248 | your own script. | |
1249 | + | |
1250 | The Babeltrace{nbsp}2 project ships with a plugin | |
1251 | (man:babeltrace2-plugin-ctf(7)) which supports the format of the traces | |
1252 | which LTTng produces, https://diamon.org/ctf/[CTF]. | |
1253 | ||
1254 | http://tracecompass.org/[Trace Compass]:: | |
1255 | A graphical user interface for viewing and analyzing any type of | |
1256 | logs or traces, including those of LTTng. | |
1257 | ||
1258 | https://github.com/lttng/lttng-analyses[LTTng analyses]:: | |
1259 | An experimental project which includes many high-level analyses of | |
1260 | LTTng kernel traces, like scheduling statistics, interrupt | |
1261 | frequency distribution, top CPU usage, and more. | |
1262 | ||
1263 | NOTE: This section assumes that LTTng wrote the traces it recorded | |
1264 | during the previous tutorials to their default location, in the | |
1265 | dir:{$LTTNG_HOME/lttng-traces} directory. The env:LTTNG_HOME | |
1266 | environment variable defaults to `$HOME` if not set. | |
1267 | ||
1268 | ||
1269 | [[viewing-and-analyzing-your-traces-bt]] | |
1270 | ==== Use the cmd:babeltrace2 command-line tool | |
1271 | ||
1272 | The simplest way to list all the recorded events of an LTTng trace is to | |
1273 | pass its path to man:babeltrace2(1), without options: | |
1274 | ||
1275 | [role="term"] | |
1276 | ---- | |
1277 | $ babeltrace2 ~/lttng-traces/my-user-space-session* | |
1278 | ---- | |
1279 | ||
1280 | The cmd:babeltrace2 command finds all traces recursively within the | |
1281 | given path and prints all their events, sorting them chronologically. | |
1282 | ||
1283 | Pipe the output of cmd:babeltrace2 into a tool like man:grep(1) for | |
1284 | further filtering: | |
1285 | ||
1286 | [role="term"] | |
1287 | ---- | |
1288 | $ babeltrace2 /tmp/my-kernel-trace | grep _switch | |
1289 | ---- | |
1290 | ||
1291 | Pipe the output of cmd:babeltrace2 into a tool like man:wc(1) to count | |
1292 | the recorded events: | |
1293 | ||
1294 | [role="term"] | |
1295 | ---- | |
1296 | $ babeltrace2 /tmp/my-kernel-trace | grep _open | wc --lines | |
1297 | ---- | |
1298 | ||
1299 | ||
1300 | [[viewing-and-analyzing-your-traces-bt-python]] | |
1301 | ==== Use the Babeltrace{nbsp}2 Python bindings | |
1302 | ||
1303 | The <<viewing-and-analyzing-your-traces-bt,text output of | |
1304 | cmd:babeltrace2>> is useful to isolate event records by simple matching | |
1305 | using man:grep(1) and similar utilities. However, more elaborate | |
1306 | filters, such as keeping only event records with a field value falling | |
1307 | within a specific range, are not trivial to write using a shell. | |
1308 | Moreover, reductions and even the most basic computations involving | |
1309 | multiple event records are virtually impossible to implement. | |
1310 | ||
1311 | Fortunately, Babeltrace{nbsp}2 ships with | |
1312 | https://babeltrace.org/docs/v2.0/python/bt2/[Python{nbsp}3 bindings] | |
1313 | which make it easy to read the event records of an LTTng trace | |
1314 | sequentially and compute the desired information. | |
1315 | ||
1316 | The following script accepts an LTTng Linux kernel trace path as its | |
1317 | first argument and prints the short names of the top five running | |
1318 | processes on CPU{nbsp}0 during the whole trace: | |
1319 | ||
1320 | [source,python] | |
1321 | .path:{top5proc.py} | |
1322 | ---- | |
1323 | import bt2 | |
1324 | import sys | |
1325 | import collections | |
1326 | ||
1327 | ||
1328 | def top5proc(): | |
1329 | # Get the trace path from the first command-line argument | |
1330 | it = bt2.TraceCollectionMessageIterator(sys.argv[1]) | |
1331 | ||
1332 | # This counter dictionary will hold execution times: | |
1333 | # | |
1334 | # Task command name -> Total execution time (ns) | |
1335 | exec_times = collections.Counter() | |
1336 | ||
1337 | # This holds the last `sched_switch` timestamp | |
1338 | last_ts = None | |
1339 | ||
1340 | for msg in it: | |
1341 | # We only care about event messages | |
1342 | if type(msg) is not bt2._EventMessageConst: | |
1343 | continue | |
1344 | ||
1345 | # Event of the event message | |
1346 | event = msg.event | |
1347 | ||
1348 | # Keep only `sched_switch` events | |
1349 | if event.cls.name != 'sched_switch': | |
1350 | continue | |
1351 | ||
1352 | # Keep only records of events which LTTng emitted from CPU 0 | |
1353 | if event.packet.context_field['cpu_id'] != 0: | |
1354 | continue | |
1355 | ||
1356 | # Event timestamp (ns) | |
1357 | cur_ts = msg.default_clock_snapshot.ns_from_origin | |
1358 | ||
1359 | if last_ts is None: | |
1360 | # Start here | |
1361 | last_ts = cur_ts | |
1362 | ||
1363 | # (Short) name of the previous task command | |
1364 | prev_comm = str(event.payload_field['prev_comm']) | |
1365 | ||
1366 | # Initialize an entry in our dictionary if not done yet | |
1367 | if prev_comm not in exec_times: | |
1368 | exec_times[prev_comm] = 0 | |
1369 | ||
1370 | # Compute previous command execution time | |
1371 | diff = cur_ts - last_ts | |
1372 | ||
1373 | # Update execution time of this command | |
1374 | exec_times[prev_comm] += diff | |
1375 | ||
1376 | # Update last timestamp | |
1377 | last_ts = cur_ts | |
1378 | ||
1379 | # Print top 5 | |
1380 | for name, ns in exec_times.most_common(5): | |
1381 | print('{:20}{} s'.format(name, ns / 1e9)) | |
1382 | ||
1383 | ||
1384 | if __name__ == '__main__': | |
1385 | top5proc() | |
1386 | ---- | |
1387 | ||
1388 | Run this script: | |
1389 | ||
1390 | [role="term"] | |
1391 | ---- | |
1392 | $ python3 top5proc.py /tmp/my-kernel-trace/kernel | |
1393 | ---- | |
1394 | ||
1395 | Output example: | |
1396 | ||
1397 | ---- | |
1398 | swapper/0 48.607245889 s | |
1399 | chromium 7.192738188 s | |
1400 | pavucontrol 0.709894415 s | |
1401 | Compositor 0.660867933 s | |
1402 | Xorg.bin 0.616753786 s | |
1403 | ---- | |
1404 | ||
1405 | Note that `swapper/0` is the ``idle'' process of CPU{nbsp}0 on Linux; | |
1406 | since we weren't using the CPU that much when recording, its first | |
1407 | position in the list makes sense. | |
1408 | ||
1409 | ||
1410 | [[core-concepts]] | |
1411 | == [[understanding-lttng]]Core concepts | |
1412 | ||
1413 | From a user's perspective, the LTTng system is built on a few concepts, | |
1414 | or objects, on which the <<lttng-cli,cmd:lttng command-line tool>> | |
1415 | operates by sending commands to the <<lttng-sessiond,session daemon>> | |
1416 | (through <<liblttng-ctl-lttng,`liblttng-ctl`>>). | |
1417 | ||
1418 | Understanding how those objects relate to each other is key to master | |
1419 | the toolkit. | |
1420 | ||
1421 | The core concepts of LTTng are: | |
1422 | ||
1423 | * <<"event-rule","Instrumentation point, event rule, and event">> | |
1424 | * <<trigger,Trigger>> | |
1425 | * <<tracing-session,Recording session>> | |
1426 | * <<domain,Tracing domain>> | |
1427 | * <<channel,Channel and ring buffer>> | |
1428 | * <<event,Recording event rule and event record>> | |
1429 | ||
1430 | NOTE: The man:lttng-concepts(7) manual page also documents the core | |
1431 | concepts of LTTng, with more links to other LTTng-tools manual pages. | |
1432 | ||
1433 | ||
1434 | [[event-rule]] | |
1435 | === Instrumentation point, event rule, and event | |
1436 | ||
1437 | An _instrumentation point_ is a point, within a piece of software, | |
1438 | which, when executed, creates an LTTng _event_. | |
1439 | ||
1440 | LTTng offers various <<instrumentation-point-types,types of | |
1441 | instrumentation>>. | |
1442 | ||
1443 | An _event rule_ is a set of conditions to match a set of events. | |
1444 | ||
1445 | When LTTng creates an event{nbsp}__E__, an event rule{nbsp}__ER__ is | |
1446 | said to __match__{nbsp}__E__ when{nbsp}__E__ satisfies _all_ the | |
1447 | conditions of{nbsp}__ER__. This concept is similar to a | |
1448 | https://en.wikipedia.org/wiki/Regular_expression[regular expression] | |
1449 | which matches a set of strings. | |
1450 | ||
1451 | When an event rule matches an event, LTTng _emits_ the event, therefore | |
1452 | attempting to execute one or more actions. | |
1453 | ||
1454 | [IMPORTANT] | |
1455 | ==== | |
1456 | [[event-creation-emission-opti]]The event creation and emission | |
1457 | processes are documentation concepts to help understand the journey from | |
1458 | an instrumentation point to the execution of actions. | |
1459 | ||
1460 | The actual creation of an event can be costly because LTTng needs to | |
1461 | evaluate the arguments of the instrumentation point. | |
1462 | ||
1463 | In practice, LTTng implements various optimizations for the Linux kernel | |
1464 | and user space <<domain,tracing domains>> to avoid actually creating an | |
1465 | event when the tracer knows, thanks to properties which are independent | |
1466 | from the event payload and current context, that it would never emit | |
1467 | such an event. Those properties are: | |
1468 | ||
1469 | * The <<instrumentation-point-types,instrumentation point type>>. | |
1470 | ||
1471 | * The instrumentation point name. | |
1472 | ||
1473 | * The instrumentation point log level. | |
1474 | ||
1475 | * For a <<event,recording event rule>>: | |
1476 | ** The status of the rule itself. | |
1477 | ** The status of the <<channel,channel>>. | |
1478 | ** The activity of the <<tracing-session,recording session>>. | |
1479 | ** Whether or not the process for which LTTng would create the event is | |
1480 | <<pid-tracking,allowed to record events>>. | |
1481 | ||
1482 | In other words: if, for a given instrumentation point{nbsp}__IP__, the | |
1483 | LTTng tracer knows that it would never emit an event, | |
1484 | executing{nbsp}__IP__ represents a simple boolean variable check and, | |
1485 | for a Linux kernel recording event rule, a few process attribute checks. | |
1486 | ==== | |
1487 | ||
1488 | As of LTTng{nbsp}{revision}, there are two places where you can find an | |
1489 | event rule: | |
1490 | ||
1491 | <<event,Recording event rule>>:: | |
1492 | A specific type of event rule of which the action is to record the | |
1493 | matched event as an event record. | |
1494 | + | |
1495 | See ``<<enabling-disabling-events,Create and enable a recording event | |
1496 | rule>>'' to learn more. | |
1497 | ||
1498 | ``Event rule matches'' <<trigger,trigger>> condition (since LTTng{nbsp}2.13):: | |
1499 | When the event rule of the trigger condition matches an event, LTTng | |
1500 | can execute user-defined actions such as sending an LTTng | |
1501 | notification, | |
1502 | <<basic-tracing-session-control,starting a recording session>>, | |
1503 | and more. | |
1504 | + | |
1505 | See “<<add-event-rule-matches-trigger,Add an ``event rule matches'' | |
1506 | trigger to a session daemon>>” to learn more. | |
1507 | ||
1508 | For LTTng to emit an event{nbsp}__E__,{nbsp}__E__ must satisfy _all_ the | |
1509 | basic conditions of an event rule{nbsp}__ER__, that is: | |
1510 | ||
1511 | * The instrumentation point from which LTTng | |
1512 | creates{nbsp}__E__ has a specific | |
1513 | <<instrumentation-point-types,type>>. | |
1514 | ||
1515 | * A pattern matches the name of{nbsp}__E__ while another pattern | |
1516 | doesn't. | |
1517 | ||
1518 | * The log level of the instrumentation point from which LTTng | |
1519 | creates{nbsp}__E__ is at least as severe as some value, or is exactly | |
1520 | some value. | |
1521 | ||
1522 | * The fields of the payload of{nbsp}__E__ and the current context fields | |
1523 | satisfy a filter expression. | |
1524 | ||
1525 | A <<event,recording event rule>> has additional, implicit conditions to | |
1526 | satisfy. | |
1527 | ||
1528 | ||
1529 | [[instrumentation-point-types]] | |
1530 | ==== Instrumentation point types | |
1531 | ||
1532 | As of LTTng{nbsp}{revision}, the available instrumentation point | |
1533 | types are, depending on the <<domain,tracing domain>>: | |
1534 | ||
1535 | Linux kernel:: | |
1536 | LTTng tracepoint::: | |
1537 | A statically defined point in the source code of the kernel | |
1538 | image or of a kernel module using the | |
1539 | <<lttng-modules,LTTng-modules>> macros. | |
1540 | ||
1541 | Linux kernel system call::: | |
1542 | Entry, exit, or both of a Linux kernel system call. | |
1543 | ||
1544 | Linux https://www.kernel.org/doc/html/latest/trace/kprobes.html[kprobe]::: | |
1545 | A single probe dynamically placed in the compiled kernel code. | |
1546 | + | |
1547 | When you create such an instrumentation point, you set its memory | |
1548 | address or symbol name. | |
1549 | ||
1550 | Linux user space probe::: | |
1551 | A single probe dynamically placed at the entry of a compiled | |
1552 | user space application/library function through the kernel. | |
1553 | + | |
1554 | When you create such an instrumentation point, you set: | |
1555 | + | |
1556 | -- | |
1557 | With the ELF method:: | |
1558 | Its application/library path and its symbol name. | |
1559 | ||
1560 | With the USDT method:: | |
1561 | Its application/library path, its provider name, and its probe name. | |
1562 | + | |
1563 | ``USDT'' stands for _SystemTap User-level Statically Defined Tracing_, | |
1564 | a http://dtrace.org/blogs/about/[DTrace]-style marker. | |
1565 | -- | |
1566 | + | |
1567 | As of LTTng{nbsp}{revision}, LTTng only supports USDT probes which | |
1568 | are _not_ reference-counted. | |
1569 | ||
1570 | Linux https://www.kernel.org/doc/html/latest/trace/kprobes.html[kretprobe]::: | |
1571 | Entry, exit, or both of a Linux kernel function. | |
1572 | + | |
1573 | When you create such an instrumentation point, you set the memory | |
1574 | address or symbol name of its function. | |
1575 | ||
1576 | User space:: | |
1577 | LTTng tracepoint::: | |
1578 | A statically defined point in the source code of a C/$$C++$$ | |
1579 | application/library using the | |
1580 | <<lttng-ust,LTTng-UST>> macros. | |
1581 | ||
1582 | `java.util.logging`, Apache log4j, and Python:: | |
1583 | Java or Python logging statement::: | |
1584 | A method call on a Java or Python logger attached to an | |
1585 | LTTng-UST handler. | |
1586 | ||
1587 | See ``<<list-instrumentation-points,List the available instrumentation | |
1588 | points>>'' to learn how to list available Linux kernel, user space, and | |
1589 | logging instrumentation points. | |
1590 | ||
1591 | ||
1592 | [[trigger]] | |
1593 | === Trigger | |
1594 | ||
1595 | A _trigger_ associates a condition to one or more actions. | |
1596 | ||
1597 | When the condition of a trigger is satisfied, LTTng attempts to execute | |
1598 | its actions. | |
1599 | ||
1600 | As of LTTng{nbsp}{revision}, the available trigger conditions and | |
1601 | actions are: | |
1602 | ||
1603 | Conditions:: | |
1604 | + | |
1605 | * The consumed buffer size of a given <<tracing-session,recording | |
1606 | session>> becomes greater than some value. | |
1607 | ||
1608 | * The buffer usage of a given <<channel,channel>> becomes greater than | |
1609 | some value. | |
1610 | ||
1611 | * The buffer usage of a given channel becomes less than some value. | |
1612 | ||
1613 | * There's an ongoing <<session-rotation,recording session rotation>>. | |
1614 | ||
1615 | * A recording session rotation becomes completed. | |
1616 | ||
1617 | * An <<add-event-rule-matches-trigger,event rule matches>> an event. | |
1618 | ||
1619 | Actions:: | |
1620 | + | |
1621 | * <<trigger-event-notif,Send a notification>> to a user application. | |
1622 | * <<basic-tracing-session-control,Start>> a given recording session. | |
1623 | * <<basic-tracing-session-control,Stop>> a given recording session. | |
1624 | * <<session-rotation,Archive the current trace chunk>> of a given | |
1625 | recording session (rotate). | |
1626 | * <<taking-a-snapshot,Take a snapshot>> of a given recording session. | |
1627 | ||
1628 | A trigger belongs to a <<lttng-sessiond,session daemon>>, not to a | |
1629 | specific recording session. For a given session daemon, each Unix user has | |
1630 | its own, private triggers. Note, however, that the `root` Unix user may, | |
1631 | for the root session daemon: | |
1632 | ||
1633 | * Add a trigger as another Unix user. | |
1634 | ||
1635 | * List all the triggers, regardless of their owner. | |
1636 | ||
1637 | * Remove a trigger which belongs to another Unix user. | |
1638 | ||
1639 | For a given session daemon and Unix user, a trigger has a unique name. | |
1640 | ||
1641 | ||
1642 | [[tracing-session]] | |
1643 | === Recording session | |
1644 | ||
1645 | A _recording session_ (named ``tracing session'' prior to | |
1646 | LTTng{nbsp}2.13) is a stateful dialogue between you and a | |
1647 | <<lttng-sessiond,session daemon>> for everything related to | |
1648 | <<event,event recording>>. | |
1649 | ||
1650 | Everything that you do when you control LTTng tracers to record events | |
1651 | happens within a recording session. In particular, a recording session: | |
1652 | ||
1653 | * Has its own name, unique for a given session daemon. | |
1654 | ||
1655 | * Has its own set of trace files, if any. | |
1656 | ||
1657 | * Has its own state of activity (started or stopped). | |
1658 | + | |
1659 | An active recording session is an implicit <<event,recording event rule>> | |
1660 | condition. | |
1661 | ||
1662 | * Has its own <<tracing-session-mode,mode>> (local, network streaming, | |
1663 | snapshot, or live). | |
1664 | ||
1665 | * Has its own <<channel,channels>> to which are attached their own | |
1666 | recording event rules. | |
1667 | ||
1668 | * Has its own <<pid-tracking,process attribute inclusion sets>>. | |
1669 | ||
1670 | [role="img-100"] | |
1671 | .A _recording session_ contains <<channel,channels>> that are members of <<domain,tracing domains>> and contain <<event,recording event rules>>. | |
1672 | image::concepts.png[] | |
1673 | ||
1674 | Those attributes and objects are completely isolated between different | |
1675 | recording sessions. | |
1676 | ||
1677 | A recording session is like an | |
1678 | https://en.wikipedia.org/wiki/Automated_teller_machine[ATM] session: the | |
1679 | operations you do on the banking system through the ATM don't alter the | |
1680 | data of other users of the same system. In the case of the ATM, a | |
1681 | session lasts as long as your bank card is inside. In the case of LTTng, | |
1682 | a recording session lasts from the man:lttng-create(1) command to the | |
1683 | man:lttng-destroy(1) command. | |
1684 | ||
1685 | [role="img-100"] | |
1686 | .Each Unix user has its own set of recording sessions. | |
1687 | image::many-sessions.png[] | |
1688 | ||
1689 | A recording session belongs to a <<lttng-sessiond,session daemon>>. For a | |
1690 | given session daemon, each Unix user has its own, private recording | |
1691 | sessions. Note, however, that the `root` Unix user may operate on or | |
1692 | destroy another user's recording session. | |
1693 | ||
1694 | ||
1695 | [[tracing-session-mode]] | |
1696 | ==== Recording session mode | |
1697 | ||
1698 | LTTng offers four recording session modes: | |
1699 | ||
1700 | [[local-mode]]Local mode:: | |
1701 | Write the trace data to the local file system. | |
1702 | ||
1703 | [[net-streaming-mode]]Network streaming mode:: | |
1704 | Send the trace data over the network to a listening | |
1705 | <<lttng-relayd,relay daemon>>. | |
1706 | ||
1707 | [[snapshot-mode]]Snapshot mode:: | |
1708 | Only write the trace data to the local file system or send it to a | |
1709 | listening relay daemon when LTTng <<taking-a-snapshot,takes a | |
1710 | snapshot>>. | |
1711 | + | |
1712 | LTTng forces all the <<channel,channels>> | |
1713 | to be created to be configured to be snapshot-ready. | |
1714 | + | |
1715 | LTTng takes a snapshot of such a recording session when: | |
1716 | + | |
1717 | -- | |
1718 | * You run the man:lttng-snapshot(1) command. | |
1719 | ||
1720 | * LTTng executes a `snapshot-session` <<trigger,trigger>> action. | |
1721 | -- | |
1722 | ||
1723 | [[live-mode]]Live mode:: | |
1724 | Send the trace data over the network to a listening relay daemon | |
1725 | for <<lttng-live,live reading>>. | |
1726 | + | |
1727 | An LTTng live reader (for example, man:babeltrace2(1)) can connect to | |
1728 | the same relay daemon to receive trace data while the recording session is | |
1729 | active. | |
1730 | ||
1731 | ||
1732 | [[domain]] | |
1733 | === Tracing domain | |
1734 | ||
1735 | A _tracing domain_ identifies a type of LTTng tracer. | |
1736 | ||
1737 | A tracing domain has its own properties and features. | |
1738 | ||
1739 | There are currently five available tracing domains: | |
1740 | ||
1741 | * Linux kernel | |
1742 | * User space | |
1743 | * `java.util.logging` (JUL) | |
1744 | * log4j | |
1745 | * Python | |
1746 | ||
1747 | You must specify a tracing domain to target a type of LTTng tracer when | |
1748 | using some <<lttng-cli,cmd:lttng>> commands to avoid ambiguity. For | |
1749 | example, because the Linux kernel and user space tracing domains support | |
1750 | named tracepoints as <<event-rule,instrumentation points>>, you need to | |
1751 | specify a tracing domain when you <<enabling-disabling-events,create | |
1752 | an event rule>> because both tracing domains could have tracepoints | |
1753 | sharing the same name. | |
1754 | ||
1755 | You can create <<channel,channels>> in the Linux kernel and user space | |
1756 | tracing domains. The other tracing domains have a single, default | |
1757 | channel. | |
1758 | ||
1759 | ||
1760 | [[channel]] | |
1761 | === Channel and ring buffer | |
1762 | ||
1763 | A _channel_ is an object which is responsible for a set of | |
1764 | _ring buffers_. | |
1765 | ||
1766 | Each ring buffer is divided into multiple _sub-buffers_. When a | |
1767 | <<event,recording event rule>> | |
1768 | matches an event, LTTng can record it to one or more sub-buffers of one | |
1769 | or more channels. | |
1770 | ||
1771 | When you <<enabling-disabling-channels,create a channel>>, you set its | |
1772 | final attributes, that is: | |
1773 | ||
1774 | * Its <<channel-buffering-schemes,buffering scheme>>. | |
1775 | ||
1776 | * What to do <<channel-overwrite-mode-vs-discard-mode,when there's no | |
1777 | space left>> for a new event record because all sub-buffers are full. | |
1778 | ||
1779 | * The <<channel-subbuf-size-vs-subbuf-count,size of each ring buffer and | |
1780 | how many sub-buffers>> a ring buffer has. | |
1781 | ||
1782 | * The <<tracefile-rotation,size of each trace file LTTng writes for this | |
1783 | channel and the maximum count>> of trace files. | |
1784 | ||
1785 | * The periods of its <<channel-read-timer,read>>, | |
1786 | <<channel-switch-timer,switch>>, and <<channel-monitor-timer,monitor>> | |
1787 | timers. | |
1788 | ||
1789 | * For a Linux kernel channel: its output type. | |
1790 | + | |
1791 | See the opt:lttng-enable-channel(1):--output option of the | |
1792 | man:lttng-enable-channel(1) command. | |
1793 | ||
1794 | * For a user space channel: the value of its | |
1795 | <<blocking-timeout-example,blocking timeout>>. | |
1796 | ||
1797 | A channel is always associated to a <<domain,tracing domain>>. The | |
1798 | `java.util.logging` (JUL), log4j, and Python tracing domains each have a | |
1799 | default channel which you can't configure. | |
1800 | ||
1801 | A channel owns <<event,recording event rules>>. | |
1802 | ||
1803 | ||
1804 | [[channel-buffering-schemes]] | |
1805 | ==== Buffering scheme | |
1806 | ||
1807 | A channel has at least one ring buffer _per CPU_. LTTng always records | |
1808 | an event to the ring buffer dedicated to the CPU which emits it. | |
1809 | ||
1810 | The buffering scheme of a user space channel determines what has its own | |
1811 | set of per-CPU ring buffers: | |
1812 | ||
1813 | Per-user buffering:: | |
1814 | Allocate one set of ring buffers--one per CPU--shared by all the | |
1815 | instrumented processes of: | |
1816 | If your Unix user is `root`::: | |
1817 | Each Unix user. | |
1818 | + | |
1819 | -- | |
1820 | [role="img-100"] | |
1821 | .Per-user buffering scheme (recording session belongs to the `root` Unix user). | |
1822 | image::per-user-buffering-root.png[] | |
1823 | -- | |
1824 | ||
1825 | Otherwise::: | |
1826 | Your Unix user. | |
1827 | + | |
1828 | -- | |
1829 | [role="img-100"] | |
1830 | .Per-user buffering scheme (recording session belongs to the `Bob` Unix user). | |
1831 | image::per-user-buffering.png[] | |
1832 | -- | |
1833 | ||
1834 | Per-process buffering:: | |
1835 | Allocate one set of ring buffers--one per CPU--for each | |
1836 | instrumented process of: | |
1837 | If your Unix user is `root`::: | |
1838 | All Unix users. | |
1839 | + | |
1840 | -- | |
1841 | [role="img-100"] | |
1842 | .Per-process buffering scheme (recording session belongs to the `root` Unix user). | |
1843 | image::per-process-buffering-root.png[] | |
1844 | -- | |
1845 | ||
1846 | Otherwise::: | |
1847 | Your Unix user. | |
1848 | + | |
1849 | -- | |
1850 | [role="img-100"] | |
1851 | .Per-process buffering scheme (recording session belongs to the `Bob` Unix user). | |
1852 | image::per-process-buffering.png[] | |
1853 | -- | |
1854 | ||
1855 | The per-process buffering scheme tends to consume more memory than the | |
1856 | per-user option because systems generally have more instrumented | |
1857 | processes than Unix users running instrumented processes. However, the | |
1858 | per-process buffering scheme ensures that one process having a high | |
1859 | event throughput won't fill all the shared sub-buffers of the same Unix | |
1860 | user, only its own. | |
1861 | ||
1862 | The buffering scheme of a Linux kernel channel is always to allocate a | |
1863 | single set of ring buffers for the whole system. This scheme is similar | |
1864 | to the per-user option, but with a single, global user ``running'' the | |
1865 | kernel. | |
1866 | ||
1867 | ||
1868 | [[channel-overwrite-mode-vs-discard-mode]] | |
1869 | ==== Event record loss mode | |
1870 | ||
1871 | When LTTng emits an event, LTTng can record it to a specific, available | |
1872 | sub-buffer within the ring buffers of specific channels. When there's no | |
1873 | space left in a sub-buffer, the tracer marks it as consumable and | |
1874 | another, available sub-buffer starts receiving the following event | |
1875 | records. An LTTng <<lttng-consumerd,consumer daemon>> eventually | |
1876 | consumes the marked sub-buffer, which returns to the available state. | |
1877 | ||
1878 | [NOTE] | |
1879 | [role="docsvg-channel-subbuf-anim"] | |
1880 | ==== | |
1881 | {note-no-anim} | |
1882 | ==== | |
1883 | ||
50e95807 PP |
1884 | In an ideal world, sub-buffers are consumed faster than they're filled, |
1885 | as it's the case in the previous animation. In the real world, | |
1886 | however, all sub-buffers can be full at some point, leaving no space to | |
1887 | record the following events. | |
1888 | ||
1889 | By default, <<lttng-modules,LTTng-modules>> and <<lttng-ust,LTTng-UST>> | |
1890 | are _non-blocking_ tracers: when there's no available sub-buffer to | |
1891 | record an event, it's acceptable to lose event records when the | |
1892 | alternative would be to cause substantial delays in the execution of the | |
1893 | instrumented application. LTTng privileges performance over integrity; | |
1894 | it aims at perturbing the instrumented application as little as possible | |
1895 | in order to make the detection of subtle race conditions and rare | |
1896 | interrupt cascades possible. | |
1897 | ||
1898 | Since LTTng{nbsp}2.10, the LTTng user space tracer, LTTng-UST, supports | |
1899 | a _blocking mode_. See the <<blocking-timeout-example,blocking timeout | |
1900 | example>> to learn how to use the blocking mode. | |
1901 | ||
1902 | When it comes to losing event records because there's no available | |
1903 | sub-buffer, or because the blocking timeout of | |
1904 | the channel is reached, the _event record loss mode_ of the channel | |
1905 | determines what to do. The available event record loss modes are: | |
1906 | ||
1907 | [[discard-mode]]Discard mode:: | |
1908 | Drop the newest event records until a sub-buffer becomes available. | |
1909 | + | |
1910 | This is the only available mode when you specify a blocking timeout. | |
1911 | + | |
1912 | With this mode, LTTng increments a count of lost event records when an | |
1913 | event record is lost and saves this count to the trace. A trace reader | |
1914 | can use the saved discarded event record count of the trace to decide | |
1915 | whether or not to perform some analysis even if trace data is known to | |
1916 | be missing. | |
1917 | ||
1918 | [[overwrite-mode]]Overwrite mode:: | |
1919 | Clear the sub-buffer containing the oldest event records and start | |
1920 | writing the newest event records there. | |
1921 | + | |
1922 | This mode is sometimes called _flight recorder mode_ because it's | |
1923 | similar to a https://en.wikipedia.org/wiki/Flight_recorder[flight | |
1924 | recorder]: always keep a fixed amount of the latest data. It's also | |
1925 | similar to the roll mode of an oscilloscope. | |
1926 | + | |
1927 | Since LTTng{nbsp}2.8, with this mode, LTTng writes to a given sub-buffer | |
1928 | its sequence number within its data stream. With a <<local-mode,local>>, | |
1929 | <<net-streaming-mode,network streaming>>, or <<live-mode,live>> recording | |
1930 | session, a trace reader can use such sequence numbers to report lost | |
1931 | packets. A trace reader can use the saved discarded sub-buffer (packet) | |
1932 | count of the trace to decide whether or not to perform some analysis | |
1933 | even if trace data is known to be missing. | |
1934 | + | |
1935 | With this mode, LTTng doesn't write to the trace the exact number of | |
1936 | lost event records in the lost sub-buffers. | |
1937 | ||
1938 | Which mechanism you should choose depends on your context: prioritize | |
1939 | the newest or the oldest event records in the ring buffer? | |
1940 | ||
1941 | Beware that, in overwrite mode, the tracer abandons a _whole sub-buffer_ | |
1942 | as soon as a there's no space left for a new event record, whereas in | |
1943 | discard mode, the tracer only discards the event record that doesn't | |
1944 | fit. | |
1945 | ||
1946 | There are a few ways to decrease your probability of losing event | |
1947 | records. The ``<<channel-subbuf-size-vs-subbuf-count,Sub-buffer size and | |
1948 | count>>'' section shows how to fine-tune the sub-buffer size and count | |
1949 | of a channel to virtually stop losing event records, though at the cost | |
1950 | of greater memory usage. | |
1951 | ||
1952 | ||
1953 | [[channel-subbuf-size-vs-subbuf-count]] | |
1954 | ==== Sub-buffer size and count | |
1955 | ||
1956 | A channel has one or more ring buffer for each CPU of the target system. | |
1957 | ||
1958 | See the ``<<channel-buffering-schemes,Buffering scheme>>'' section to | |
1959 | learn how many ring buffers of a given channel are dedicated to each CPU | |
1960 | depending on its buffering scheme. | |
1961 | ||
1962 | Set the size of each sub-buffer the ring buffers of a channel contain | |
1963 | and how many there are | |
1964 | when you <<enabling-disabling-channels,create it>>. | |
1965 | ||
1966 | Note that LTTng switching the current sub-buffer of a ring buffer | |
1967 | (marking a full one as consumable and switching to an available one for | |
1968 | LTTng to record the next events) introduces noticeable CPU overhead. | |
1969 | Knowing this, the following list presents a few practical situations | |
1970 | along with how to configure the sub-buffer size and count for them: | |
1971 | ||
1972 | High event throughput:: | |
1973 | In general, prefer large sub-buffers to lower the risk of losing | |
1974 | event records. | |
1975 | + | |
1976 | Having larger sub-buffers also ensures a lower sub-buffer switching | |
1977 | frequency. | |
1978 | + | |
1979 | The sub-buffer count is only meaningful if you create the channel in | |
1980 | <<overwrite-mode,overwrite mode>>: in this case, if LTTng overwrites a | |
1981 | sub-buffer, then the other sub-buffers are left unaltered. | |
1982 | ||
1983 | Low event throughput:: | |
1984 | In general, prefer smaller sub-buffers since the risk of losing | |
1985 | event records is low. | |
1986 | + | |
1987 | Because LTTng emits events less frequently, the sub-buffer switching | |
1988 | frequency should remain low and therefore the overhead of the tracer | |
1989 | shouldn't be a problem. | |
1990 | ||
1991 | Low memory system:: | |
1992 | If your target system has a low memory limit, prefer fewer first, | |
1993 | then smaller sub-buffers. | |
1994 | + | |
1995 | Even if the system is limited in memory, you want to keep the | |
1996 | sub-buffers as large as possible to avoid a high sub-buffer switching | |
1997 | frequency. | |
1998 | ||
1999 | Note that LTTng uses https://diamon.org/ctf/[CTF] as its trace format, | |
2000 | which means event record data is very compact. For example, the average | |
2001 | LTTng kernel event record weights about 32{nbsp}bytes. Therefore, a | |
2002 | sub-buffer size of 1{nbsp}MiB is considered large. | |
2003 | ||
2004 | The previous scenarios highlight the major trade-off between a few large | |
2005 | sub-buffers and more, smaller sub-buffers: sub-buffer switching | |
2006 | frequency vs. how many event records are lost in overwrite mode. | |
2007 | Assuming a constant event throughput and using the overwrite mode, the | |
2008 | two following configurations have the same ring buffer total size: | |
2009 | ||
2010 | [NOTE] | |
2011 | [role="docsvg-channel-subbuf-size-vs-count-anim"] | |
2012 | ==== | |
2013 | {note-no-anim} | |
2014 | ==== | |
2015 | ||
2016 | Two sub-buffers of 4{nbsp}MiB each:: | |
2017 | Expect a very low sub-buffer switching frequency, but if LTTng | |
2018 | ever needs to overwrite a sub-buffer, half of the event records so | |
2019 | far (4{nbsp}MiB) are definitely lost. | |
2020 | ||
2021 | Eight sub-buffers of 1{nbsp}MiB each:: | |
2022 | Expect four times the tracer overhead of the configuration above, | |
2023 | but if LTTng needs to overwrite a sub-buffer, only the eighth of | |
2024 | event records so far (1{nbsp}MiB) are definitely lost. | |
2025 | ||
2026 | In <<discard-mode,discard mode>>, the sub-buffer count parameter is | |
2027 | pointless: use two sub-buffers and set their size according to your | |
2028 | requirements. | |
2029 | ||
2030 | ||
2031 | [[tracefile-rotation]] | |
2032 | ==== Maximum trace file size and count (trace file rotation) | |
2033 | ||
2034 | By default, trace files can grow as large as needed. | |
2035 | ||
2036 | Set the maximum size of each trace file that LTTng writes of a given | |
2037 | channel when you <<enabling-disabling-channels,create it>>. | |
2038 | ||
2039 | When the size of a trace file reaches the fixed maximum size of the | |
2040 | channel, LTTng creates another file to contain the next event records. | |
2041 | LTTng appends a file count to each trace file name in this case. | |
2042 | ||
2043 | If you set the trace file size attribute when you create a channel, the | |
2044 | maximum number of trace files that LTTng creates is _unlimited_ by | |
2045 | default. To limit them, set a maximum number of trace files. When the | |
2046 | number of trace files reaches the fixed maximum count of the channel, | |
2047 | LTTng overwrites the oldest trace file. This mechanism is called _trace | |
2048 | file rotation_. | |
2049 | ||
2050 | [IMPORTANT] | |
2051 | ==== | |
2052 | Even if you don't limit the trace file count, always assume that LTTng | |
2053 | manages all the trace files of the recording session. | |
2054 | ||
2055 | In other words, there's no safe way to know if LTTng still holds a given | |
2056 | trace file open with the trace file rotation feature. | |
2057 | ||
2058 | The only way to obtain an unmanaged, self-contained LTTng trace before | |
2059 | you <<creating-destroying-tracing-sessions,destroy the recording session>> | |
2060 | is with the <<session-rotation,recording session rotation>> feature, which | |
2061 | is available since LTTng{nbsp}2.11. | |
2062 | ==== | |
2063 | ||
2064 | ||
2065 | [[channel-timers]] | |
2066 | ==== Timers | |
2067 | ||
2068 | Each channel can have up to three optional timers: | |
2069 | ||
2070 | [[channel-switch-timer]]Switch timer:: | |
2071 | When this timer expires, a sub-buffer switch happens: for each ring | |
2072 | buffer of the channel, LTTng marks the current sub-buffer as | |
2073 | consumable and _switches_ to an available one to record the next | |
2074 | events. | |
2075 | + | |
2076 | [NOTE] | |
2077 | [role="docsvg-channel-switch-timer"] | |
2078 | ==== | |
2079 | {note-no-anim} | |
2080 | ==== | |
2081 | + | |
2082 | A switch timer is useful to ensure that LTTng consumes and commits trace | |
2083 | data to trace files or to a distant <<lttng-relayd,relay daemon>> | |
2084 | periodically in case of a low event throughput. | |
2085 | + | |
2086 | Such a timer is also convenient when you use large | |
2087 | <<channel-subbuf-size-vs-subbuf-count,sub-buffers>> to cope with a | |
2088 | sporadic high event throughput, even if the throughput is otherwise low. | |
2089 | + | |
2090 | Set the period of the switch timer of a channel when you | |
2091 | <<enabling-disabling-channels,create it>> with | |
2092 | the opt:lttng-enable-channel(1):--switch-timer option. | |
2093 | ||
2094 | [[channel-read-timer]]Read timer:: | |
2095 | When this timer expires, LTTng checks for full, consumable | |
2096 | sub-buffers. | |
2097 | + | |
2098 | By default, the LTTng tracers use an asynchronous message mechanism to | |
2099 | signal a full sub-buffer so that a <<lttng-consumerd,consumer daemon>> | |
2100 | can consume it. | |
2101 | + | |
2102 | When such messages must be avoided, for example in real-time | |
2103 | applications, use this timer instead. | |
2104 | + | |
2105 | Set the period of the read timer of a channel when you | |
2106 | <<enabling-disabling-channels,create it>> with the | |
2107 | opt:lttng-enable-channel(1):--read-timer option. | |
2108 | ||
2109 | [[channel-monitor-timer]]Monitor timer:: | |
2110 | When this timer expires, the consumer daemon samples some channel | |
2111 | statistics to evaluate the following <<trigger,trigger>> | |
2112 | conditions: | |
2113 | + | |
2114 | -- | |
2115 | . The consumed buffer size of a given <<tracing-session,recording | |
2116 | session>> becomes greater than some value. | |
2117 | . The buffer usage of a given channel becomes greater than some value. | |
2118 | . The buffer usage of a given channel becomes less than some value. | |
2119 | -- | |
2120 | + | |
2121 | If you disable the monitor timer of a channel{nbsp}__C__: | |
2122 | + | |
2123 | -- | |
2124 | * The consumed buffer size value of the recording session of{nbsp}__C__ | |
2125 | could be wrong for trigger condition type{nbsp}1: the consumed buffer | |
2126 | size of{nbsp}__C__ won't be part of the grand total. | |
2127 | ||
2128 | * The buffer usage trigger conditions (types{nbsp}2 and{nbsp}3) | |
2129 | for{nbsp}__C__ will never be satisfied. | |
2130 | -- | |
2131 | + | |
2132 | Set the period of the monitor timer of a channel when you | |
2133 | <<enabling-disabling-channels,create it>> with the | |
2134 | opt:lttng-enable-channel(1):--monitor-timer option. | |
2135 | ||
2136 | ||
2137 | [[event]] | |
2138 | === Recording event rule and event record | |
2139 | ||
2140 | A _recording event rule_ is a specific type of <<event-rule,event rule>> | |
2141 | of which the action is to serialize and record the matched event as an | |
2142 | _event record_. | |
2143 | ||
2144 | Set the explicit conditions of a recording event rule when you | |
2145 | <<enabling-disabling-events,create it>>. A recording event rule also has | |
2146 | the following implicit conditions: | |
2147 | ||
2148 | * The recording event rule itself is enabled. | |
2149 | + | |
2150 | A recording event rule is enabled on creation. | |
2151 | ||
2152 | * The <<channel,channel>> to which the recording event rule is attached | |
2153 | is enabled. | |
2154 | + | |
2155 | A channel is enabled on creation. | |
2156 | ||
2157 | * The <<tracing-session,recording session>> of the recording event rule is | |
2158 | <<basic-tracing-session-control,active>> (started). | |
2159 | + | |
2160 | A recording session is inactive (stopped) on creation. | |
2161 | ||
2162 | * The process for which LTTng creates an event to match is | |
2163 | <<pid-tracking,allowed to record events>>. | |
2164 | + | |
2165 | All processes are allowed to record events on recording session | |
2166 | creation. | |
2167 | ||
2168 | You always attach a recording event rule to a channel, which belongs to | |
2169 | a recording session, when you create it. | |
2170 | ||
2171 | When a recording event rule{nbsp}__ER__ matches an event{nbsp}__E__, | |
2172 | LTTng attempts to serialize and record{nbsp}__E__ to one of the | |
2173 | available sub-buffers of the channel to which{nbsp}__E__ is attached. | |
2174 | ||
2175 | When multiple matching recording event rules are attached to the same | |
2176 | channel, LTTng attempts to serialize and record the matched event | |
2177 | _once_. In the following example, the second recording event rule is | |
2178 | redundant when both are enabled: | |
2179 | ||
2180 | [role="term"] | |
2181 | ---- | |
2182 | $ lttng enable-event --userspace hello:world | |
2183 | $ lttng enable-event --userspace hello:world --loglevel=INFO | |
2184 | ---- | |
2185 | ||
2186 | [role="img-100"] | |
2187 | .Logical path from an instrumentation point to an event record. | |
2188 | image::event-rule.png[] | |
2189 | ||
2190 | As of LTTng{nbsp}{revision}, you cannot remove a recording event | |
2191 | rule: it exists as long as its recording session exists. | |
2192 | ||
2193 | ||
2194 | [[plumbing]] | |
2195 | == Components of noch:{LTTng} | |
2196 | ||
2197 | The second _T_ in _LTTng_ stands for _toolkit_: it would be wrong | |
2198 | to call LTTng a simple _tool_ since it's composed of multiple | |
2199 | interacting components. | |
2200 | ||
2201 | This section describes those components, explains their respective | |
2202 | roles, and shows how they connect together to form the LTTng ecosystem. | |
2203 | ||
2204 | The following diagram shows how the most important components of LTTng | |
2205 | interact with user applications, the Linux kernel, and you: | |
2206 | ||
2207 | [role="img-100"] | |
2208 | .Control and trace data paths between LTTng components. | |
2209 | image::plumbing.png[] | |
2210 | ||
2211 | The LTTng project integrates: | |
2212 | ||
2213 | LTTng-tools:: | |
2214 | Libraries and command-line interface to control recording sessions: | |
2215 | + | |
2216 | * <<lttng-sessiond,Session daemon>> (man:lttng-sessiond(8)). | |
2217 | * <<lttng-consumerd,Consumer daemon>> (cmd:lttng-consumerd). | |
2218 | * <<lttng-relayd,Relay daemon>> (man:lttng-relayd(8)). | |
2219 | * <<liblttng-ctl-lttng,Tracing control library>> (`liblttng-ctl`). | |
2220 | * <<lttng-cli,Tracing control command-line tool>> (man:lttng(1)). | |
2221 | * <<persistent-memory-file-systems,`lttng-crash` command-line tool>> | |
2222 | (man:lttng-crash(1)). | |
2223 | ||
2224 | LTTng-UST:: | |
2225 | Libraries and Java/Python packages to instrument and trace user | |
2226 | applications: | |
2227 | + | |
2228 | * <<lttng-ust,User space tracing library>> (`liblttng-ust`) and its | |
2229 | headers to instrument and trace any native user application. | |
2230 | * <<prebuilt-ust-helpers,Preloadable user space tracing helpers>>: | |
2231 | ** `liblttng-ust-libc-wrapper` | |
2232 | ** `liblttng-ust-pthread-wrapper` | |
2233 | ** `liblttng-ust-cyg-profile` | |
2234 | ** `liblttng-ust-cyg-profile-fast` | |
2235 | ** `liblttng-ust-dl` | |
2236 | * <<lttng-ust-agents,LTTng-UST Java agent>> to instrument and trace | |
2237 | Java applications using `java.util.logging` or | |
2238 | Apache log4j{nbsp}1.2 logging. | |
2239 | * <<lttng-ust-agents,LTTng-UST Python agent>> to instrument | |
2240 | Python applications using the standard `logging` package. | |
2241 | ||
2242 | LTTng-modules:: | |
2243 | <<lttng-modules,Linux kernel modules>> to instrument and trace the | |
2244 | kernel: | |
2245 | + | |
2246 | * LTTng kernel tracer module. | |
2247 | * Recording ring buffer kernel modules. | |
2248 | * Probe kernel modules. | |
2249 | * LTTng logger kernel module. | |
2250 | ||
2251 | ||
2252 | [[lttng-cli]] | |
2253 | === Tracing control command-line interface | |
2254 | ||
2255 | The _man:lttng(1) command-line tool_ is the standard user interface to | |
2256 | control LTTng <<tracing-session,recording sessions>>. | |
2257 | ||
2258 | The cmd:lttng tool is part of LTTng-tools. | |
2259 | ||
2260 | The cmd:lttng tool is linked with | |
2261 | <<liblttng-ctl-lttng,`liblttng-ctl`>> to communicate with | |
2262 | one or more <<lttng-sessiond,session daemons>> behind the scenes. | |
2263 | ||
2264 | The cmd:lttng tool has a Git-like interface: | |
2265 | ||
2266 | [role="term"] | |
2267 | ---- | |
2268 | $ lttng [GENERAL OPTIONS] <COMMAND> [COMMAND OPTIONS] | |
2269 | ---- | |
2270 | ||
2271 | The ``<<controlling-tracing,Tracing control>>'' section explores the | |
2272 | available features of LTTng through its cmd:lttng tool. | |
2273 | ||
2274 | ||
2275 | [[liblttng-ctl-lttng]] | |
2276 | === Tracing control library | |
2277 | ||
2278 | [role="img-100"] | |
2279 | .The tracing control library. | |
2280 | image::plumbing-liblttng-ctl.png[] | |
2281 | ||
2282 | The _LTTng control library_, `liblttng-ctl`, is used to communicate with | |
2283 | a <<lttng-sessiond,session daemon>> using a C{nbsp}API that hides the | |
2284 | underlying details of the protocol. | |
2285 | ||
2286 | `liblttng-ctl` is part of LTTng-tools. | |
2287 | ||
2288 | The <<lttng-cli,cmd:lttng command-line tool>> is linked with | |
2289 | `liblttng-ctl`. | |
2290 | ||
2291 | Use `liblttng-ctl` in C or $$C++$$ source code by including its | |
2292 | ``master'' header: | |
2293 | ||
2294 | [source,c] | |
2295 | ---- | |
2296 | #include <lttng/lttng.h> | |
2297 | ---- | |
2298 | ||
2299 | As of LTTng{nbsp}{revision}, the best available developer documentation | |
2300 | for `liblttng-ctl` is its installed header files. Functions and | |
2301 | structures are documented with header comments. | |
2302 | ||
2303 | ||
2304 | [[lttng-ust]] | |
2305 | === User space tracing library | |
2306 | ||
2307 | [role="img-100"] | |
2308 | .The user space tracing library. | |
2309 | image::plumbing-liblttng-ust.png[] | |
2310 | ||
2311 | The _user space tracing library_, `liblttng-ust` (see man:lttng-ust(3)), | |
2312 | is the LTTng user space tracer. | |
2313 | ||
2314 | `liblttng-ust` receives commands from a <<lttng-sessiond,session | |
2315 | daemon>>, for example to allow specific instrumentation points to emit | |
2316 | LTTng <<event-rule,events>>, and writes event records to <<channel,ring | |
2317 | buffers>> shared with a <<lttng-consumerd,consumer daemon>>. | |
2318 | ||
2319 | `liblttng-ust` is part of LTTng-UST. | |
2320 | ||
2321 | `liblttng-ust` can also send asynchronous messages to the session daemon | |
2322 | when it emits an event. This supports the ``event rule matches'' | |
2323 | <<trigger,trigger>> condition feature (see | |
2324 | “<<add-event-rule-matches-trigger,Add an ``event rule matches'' trigger | |
2325 | to a session daemon>>”). | |
2326 | ||
2327 | Public C{nbsp}header files are installed beside `liblttng-ust` to | |
2328 | instrument any <<c-application,C or $$C++$$ application>>. | |
2329 | ||
2330 | <<lttng-ust-agents,LTTng-UST agents>>, which are regular Java and Python | |
2331 | packages, use their own <<tracepoint-provider,tracepoint provider | |
2332 | package>> which is linked with `liblttng-ust`. | |
2333 | ||
2334 | An application or library doesn't have to initialize `liblttng-ust` | |
2335 | manually: its constructor does the necessary tasks to register the | |
2336 | application to a session daemon. The initialization phase also | |
2337 | configures instrumentation points depending on the <<event-rule,event | |
2338 | rules>> that you already created. | |
2339 | ||
2340 | ||
2341 | [[lttng-ust-agents]] | |
2342 | === User space tracing agents | |
2343 | ||
2344 | [role="img-100"] | |
2345 | .The user space tracing agents. | |
2346 | image::plumbing-lttng-ust-agents.png[] | |
2347 | ||
2348 | The _LTTng-UST Java and Python agents_ are regular Java and Python | |
2349 | packages which add LTTng tracing capabilities to the | |
2350 | native logging frameworks. | |
2351 | ||
2352 | The LTTng-UST agents are part of LTTng-UST. | |
2353 | ||
2354 | In the case of Java, the | |
2355 | https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[`java.util.logging` | |
2356 | core logging facilities] and | |
2357 | https://logging.apache.org/log4j/1.2/[Apache log4j{nbsp}1.2] are supported. | |
2358 | Note that Apache Log4j{nbsp}2 isn't supported. | |
2359 | ||
2360 | In the case of Python, the standard | |
2361 | https://docs.python.org/3/library/logging.html[`logging`] package | |
2362 | is supported. Both Python{nbsp}2 and Python{nbsp}3 modules can import the | |
2363 | LTTng-UST Python agent package. | |
2364 | ||
2365 | The applications using the LTTng-UST agents are in the | |
2366 | `java.util.logging` (JUL), log4j, and Python <<domain,tracing domains>>. | |
2367 | ||
2368 | Both agents use the same mechanism to convert log statements to LTTng | |
2369 | events. When an agent initializes, it creates a log handler that | |
2370 | attaches to the root logger. The agent also registers to a | |
2371 | <<lttng-sessiond,session daemon>>. When the user application executes a | |
2372 | log statement, the root logger passes it to the log handler of the | |
2373 | agent. The custom log handler of the agent calls a native function in a | |
2374 | tracepoint provider package shared library linked with | |
2375 | <<lttng-ust,`liblttng-ust`>>, passing the formatted log message and | |
2376 | other fields, like its logger name and its log level. This native | |
2377 | function contains a user space instrumentation point, therefore tracing | |
2378 | the log statement. | |
2379 | ||
2380 | The log level condition of a <<event,recording event rule>> is | |
2381 | considered when tracing a Java or a Python application, and it's | |
2382 | compatible with the standard `java.util.logging`, log4j, and Python log | |
2383 | levels. | |
2384 | ||
2385 | ||
2386 | [[lttng-modules]] | |
2387 | === LTTng kernel modules | |
2388 | ||
2389 | [role="img-100"] | |
2390 | .The LTTng kernel modules. | |
2391 | image::plumbing-lttng-modules.png[] | |
2392 | ||
2393 | The _LTTng kernel modules_ are a set of Linux kernel modules | |
2394 | which implement the kernel tracer of the LTTng project. | |
2395 | ||
2396 | The LTTng kernel modules are part of LTTng-modules. | |
2397 | ||
2398 | The LTTng kernel modules include: | |
2399 | ||
2400 | * A set of _probe_ modules. | |
2401 | + | |
2402 | Each module attaches to a specific subsystem | |
2403 | of the Linux kernel using its tracepoint instrument points. | |
2404 | + | |
2405 | There are also modules to attach to the entry and return points of the | |
2406 | Linux system call functions. | |
2407 | ||
2408 | * _Ring buffer_ modules. | |
2409 | + | |
2410 | A ring buffer implementation is provided as kernel modules. The LTTng | |
2411 | kernel tracer writes to ring buffers; a | |
2412 | <<lttng-consumerd,consumer daemon>> reads from ring buffers. | |
2413 | ||
2414 | * The _LTTng kernel tracer_ module. | |
2415 | * The <<proc-lttng-logger-abi,_LTTng logger_>> module. | |
2416 | + | |
2417 | The LTTng logger module implements the special path:{/proc/lttng-logger} | |
2418 | (and path:{/dev/lttng-logger}, since LTTng{nbsp}2.11) files so that any | |
2419 | executable can generate LTTng events by opening those files and | |
2420 | writing to them. | |
2421 | ||
2422 | The LTTng kernel tracer can also send asynchronous messages to the | |
2423 | <<lttng-sessiond,session daemon>> when it emits an event. | |
2424 | This supports the ``event rule matches'' | |
2425 | <<trigger,trigger>> condition feature (see | |
2426 | “<<add-event-rule-matches-trigger,Add an ``event rule matches'' trigger | |
2427 | to a session daemon>>”). | |
2428 | ||
2429 | Generally, you don't have to load the LTTng kernel modules manually | |
2430 | (using man:modprobe(8), for example): a root session daemon loads the | |
2431 | necessary modules when starting. If you have extra probe modules, you | |
2432 | can specify to load them to the session daemon on the command line | |
f9bace78 PP |
2433 | (see the opt:lttng-sessiond(8):--extra-kmod-probes option). See also |
2434 | <<linux-kernel-sig,Linux kernel module signature>>. | |
50e95807 PP |
2435 | |
2436 | The LTTng kernel modules are installed in | |
2437 | +/usr/lib/modules/__release__/extra+ by default, where +__release__+ is | |
2438 | the kernel release (output of `uname --kernel-release`). | |
2439 | ||
2440 | ||
2441 | [[lttng-sessiond]] | |
2442 | === Session daemon | |
2443 | ||
2444 | [role="img-100"] | |
2445 | .The session daemon. | |
2446 | image::plumbing-sessiond.png[] | |
2447 | ||
2448 | The _session daemon_, man:lttng-sessiond(8), is a | |
2449 | https://en.wikipedia.org/wiki/Daemon_(computing)[daemon] which: | |
2450 | ||
2451 | * Manages <<tracing-session,recording sessions>>. | |
2452 | ||
2453 | * Controls the various components (like tracers and | |
2454 | <<lttng-consumerd,consumer daemons>>) of LTTng. | |
2455 | ||
2456 | * Sends <<notif-trigger-api,asynchronous notifications>> to user | |
2457 | applications. | |
2458 | ||
2459 | The session daemon is part of LTTng-tools. | |
2460 | ||
2461 | The session daemon sends control requests to and receives control | |
2462 | responses from: | |
2463 | ||
2464 | * The <<lttng-ust,user space tracing library>>. | |
2465 | + | |
2466 | Any instance of the user space tracing library first registers to | |
2467 | a session daemon. Then, the session daemon can send requests to | |
2468 | this instance, such as: | |
2469 | + | |
2470 | -- | |
2471 | ** Get the list of tracepoints. | |
2472 | ** Share a <<event,recording event rule>> so that the user space tracing | |
2473 | library can decide whether or not a given tracepoint can emit events. | |
2474 | Amongst the possible conditions of a recording event rule is a filter | |
2475 | expression which `liblttng-ust` evaluates before it emits an event. | |
2476 | ** Share <<channel,channel>> attributes and ring buffer locations. | |
2477 | -- | |
2478 | + | |
2479 | The session daemon and the user space tracing library use a Unix | |
2480 | domain socket to communicate. | |
2481 | ||
2482 | * The <<lttng-ust-agents,user space tracing agents>>. | |
2483 | + | |
2484 | Any instance of a user space tracing agent first registers to | |
2485 | a session daemon. Then, the session daemon can send requests to | |
2486 | this instance, such as: | |
2487 | + | |
2488 | -- | |
2489 | ** Get the list of loggers. | |
2490 | ** Enable or disable a specific logger. | |
2491 | -- | |
2492 | + | |
2493 | The session daemon and the user space tracing agent use a TCP connection | |
2494 | to communicate. | |
2495 | ||
2496 | * The <<lttng-modules,LTTng kernel tracer>>. | |
2497 | * The <<lttng-consumerd,consumer daemon>>. | |
2498 | + | |
2499 | The session daemon sends requests to the consumer daemon to instruct | |
2500 | it where to send the trace data streams, amongst other information. | |
2501 | ||
2502 | * The <<lttng-relayd,relay daemon>>. | |
2503 | ||
2504 | The session daemon receives commands from the | |
2505 | <<liblttng-ctl-lttng,tracing control library>>. | |
2506 | ||
2507 | The session daemon can receive asynchronous messages from the | |
2508 | <<lttng-ust,user space>> and <<lttng-modules,kernel>> tracers | |
2509 | when they emit events. This supports the ``event rule matches'' | |
2510 | <<trigger,trigger>> condition feature (see | |
2511 | “<<add-event-rule-matches-trigger,Add an ``event rule matches'' trigger | |
2512 | to a session daemon>>”). | |
2513 | ||
2514 | The root session daemon loads the appropriate | |
2515 | <<lttng-modules,LTTng kernel modules>> on startup. It also spawns | |
2516 | one or more <<lttng-consumerd,consumer daemons>> as soon as you create | |
2517 | a <<event,recording event rule>>. | |
2518 | ||
2519 | The session daemon doesn't send and receive trace data: this is the | |
2520 | role of the <<lttng-consumerd,consumer daemon>> and | |
2521 | <<lttng-relayd,relay daemon>>. It does, however, generate the | |
2522 | https://diamon.org/ctf/[CTF] metadata stream. | |
2523 | ||
2524 | Each Unix user can have its own session daemon instance. The | |
2525 | recording sessions which different session daemons manage are completely | |
2526 | independent. | |
2527 | ||
2528 | The root user's session daemon is the only one which is | |
2529 | allowed to control the LTTng kernel tracer, and its spawned consumer | |
2530 | daemon is the only one which is allowed to consume trace data from the | |
2531 | LTTng kernel tracer. Note, however, that any Unix user which is a member | |
2532 | of the <<tracing-group,tracing group>> is allowed | |
2533 | to create <<channel,channels>> in the | |
2534 | Linux kernel <<domain,tracing domain>>, and therefore to use the Linux | |
2535 | kernel LTTng tracer. | |
2536 | ||
2537 | The <<lttng-cli,cmd:lttng command-line tool>> automatically starts a | |
2538 | session daemon when using its `create` command if none is currently | |
2539 | running. You can also start the session daemon manually. | |
2540 | ||
2541 | ||
2542 | [[lttng-consumerd]] | |
2543 | === Consumer daemon | |
2544 | ||
2545 | [role="img-100"] | |
2546 | .The consumer daemon. | |
2547 | image::plumbing-consumerd.png[] | |
2548 | ||
2549 | The _consumer daemon_, cmd:lttng-consumerd, is a | |
2550 | https://en.wikipedia.org/wiki/Daemon_(computing)[daemon] which shares | |
2551 | ring buffers with user applications or with the LTTng kernel modules to | |
2552 | collect trace data and send it to some location (file system or to a | |
2553 | <<lttng-relayd,relay daemon>> over the network). | |
2554 | ||
2555 | The consumer daemon is part of LTTng-tools. | |
2556 | ||
2557 | You don't start a consumer daemon manually: a consumer daemon is always | |
2558 | spawned by a <<lttng-sessiond,session daemon>> as soon as you create a | |
2559 | <<event,recording event rule>>, that is, before you start recording. When | |
2560 | you kill its owner session daemon, the consumer daemon also exits | |
2561 | because it's the child process of the session daemon. Command-line | |
2562 | options of man:lttng-sessiond(8) target the consumer daemon process. | |
2563 | ||
2564 | There are up to two running consumer daemons per Unix user, whereas only | |
2565 | one session daemon can run per user. This is because each process can be | |
2566 | either 32-bit or 64-bit: if the target system runs a mixture of 32-bit | |
2567 | and 64-bit processes, it's more efficient to have separate | |
2568 | corresponding 32-bit and 64-bit consumer daemons. The root user is an | |
2569 | exception: it can have up to _three_ running consumer daemons: 32-bit | |
2570 | and 64-bit instances for its user applications, and one more | |
2571 | reserved for collecting kernel trace data. | |
2572 | ||
2573 | ||
2574 | [[lttng-relayd]] | |
2575 | === Relay daemon | |
2576 | ||
2577 | [role="img-100"] | |
2578 | .The relay daemon. | |
2579 | image::plumbing-relayd.png[] | |
2580 | ||
2581 | The _relay daemon_, man:lttng-relayd(8), is a | |
2582 | https://en.wikipedia.org/wiki/Daemon_(computing)[daemon] acting as a bridge | |
2583 | between remote session and consumer daemons, local trace files, and a | |
2584 | remote live trace reader. | |
2585 | ||
2586 | The relay daemon is part of LTTng-tools. | |
2587 | ||
2588 | The main purpose of the relay daemon is to implement a receiver of | |
2589 | <<sending-trace-data-over-the-network,trace data over the network>>. | |
2590 | This is useful when the target system doesn't have much file system | |
2591 | space to write trace files locally. | |
2592 | ||
2593 | The relay daemon is also a server to which a | |
2594 | <<lttng-live,live trace reader>> can | |
2595 | connect. The live trace reader sends requests to the relay daemon to | |
2596 | receive trace data as the target system records events. The | |
2597 | communication protocol is named _LTTng live_; it's used over TCP | |
2598 | connections. | |
2599 | ||
2600 | Note that you can start the relay daemon on the target system directly. | |
2601 | This is the setup of choice when the use case is to view/analyze events | |
2602 | as the target system records them without the need of a remote system. | |
2603 | ||
2604 | ||
2605 | [[instrumenting]] | |
2606 | == [[using-lttng]]Instrumentation | |
2607 | ||
2608 | There are many examples of tracing and monitoring in our everyday life: | |
2609 | ||
2610 | * You have access to real-time and historical weather reports and | |
2611 | forecasts thanks to weather stations installed around the country. | |
2612 | * You know your heart is safe thanks to an electrocardiogram. | |
2613 | * You make sure not to drive your car too fast and to have enough fuel | |
2614 | to reach your destination thanks to gauges visible on your dashboard. | |
2615 | ||
2616 | All the previous examples have something in common: they rely on | |
2617 | **instruments**. Without the electrodes attached to the surface of your | |
2618 | body skin, cardiac monitoring is futile. | |
2619 | ||
2620 | LTTng, as a tracer, is no different from those real life examples. If | |
2621 | you're about to trace a software system or, in other words, record its | |
2622 | history of execution, you better have **instrumentation points** in the | |
2623 | subject you're tracing, that is, the actual software system. | |
2624 | ||
2625 | <<instrumentation-point-types,Various ways>> were developed to | |
2626 | instrument a piece of software for LTTng tracing. The most | |
2627 | straightforward one is to manually place static instrumentation points, | |
2628 | called _tracepoints_, in the source code of the application. The Linux | |
2629 | kernel <<domain,tracing domain>> also makes it possible to dynamically | |
2630 | add instrumentation points. | |
2631 | ||
2632 | If you're only interested in tracing the Linux kernel, your | |
2633 | instrumentation needs are probably already covered by the built-in | |
2634 | <<lttng-modules,Linux kernel instrumentation points>> of LTTng. You may | |
2635 | also wish to have LTTng trace a user application which is already | |
2636 | instrumented for LTTng tracing. In such cases, skip this whole section | |
2637 | and read the topics of the ``<<controlling-tracing,Tracing control>>'' | |
2638 | section. | |
2639 | ||
2640 | Many methods are available to instrument a piece of software for LTTng | |
2641 | tracing: | |
2642 | ||
2643 | * <<c-application,Instrument a C/$$C++$$ user application>>. | |
2644 | * <<prebuilt-ust-helpers,Load a prebuilt user space tracing helper>>. | |
2645 | * <<java-application,Instrument a Java application>>. | |
2646 | * <<python-application,Instrument a Python application>>. | |
2647 | * <<proc-lttng-logger-abi,Use the LTTng logger>>. | |
2648 | * <<instrumenting-linux-kernel,Instrument a Linux kernel image or module>>. | |
2649 | ||
2650 | ||
2651 | [[c-application]] | |
2652 | === [[cxx-application]]Instrument a C/$$C++$$ user application | |
2653 | ||
2654 | The high level procedure to instrument a C or $$C++$$ user application | |
2655 | with the <<lttng-ust,LTTng user space tracing library>>, `liblttng-ust`, | |
2656 | is: | |
2657 | ||
2658 | . <<tracepoint-provider,Create the source files of a tracepoint provider | |
2659 | package>>. | |
2660 | ||
2661 | . <<probing-the-application-source-code,Add tracepoints to | |
2662 | the source code of the application>>. | |
2663 | ||
2664 | . <<building-tracepoint-providers-and-user-application,Build and link | |
2665 | a tracepoint provider package and the user application>>. | |
2666 | ||
2667 | If you need quick, man:printf(3)-like instrumentation, skip those steps | |
2668 | and use <<tracef,`lttng_ust_tracef()`>> or | |
2669 | <<tracelog,`lttng_ust_tracelog()`>> instead. | |
2670 | ||
2671 | IMPORTANT: You need to <<installing-lttng,install>> LTTng-UST to | |
2672 | instrument a user application with `liblttng-ust`. | |
2673 | ||
2674 | ||
2675 | [[tracepoint-provider]] | |
2676 | ==== Create the source files of a tracepoint provider package | |
2677 | ||
2678 | A _tracepoint provider_ is a set of compiled functions which provide | |
2679 | **tracepoints** to an application, the type of instrumentation point | |
2680 | which LTTng-UST provides. | |
2681 | ||
2682 | Those functions can make LTTng emit events with user-defined fields and | |
2683 | serialize those events as event records to one or more LTTng-UST | |
2684 | <<channel,channel>> sub-buffers. The `lttng_ust_tracepoint()` macro, | |
2685 | which you <<probing-the-application-source-code,insert in the source | |
2686 | code of a user application>>, calls those functions. | |
2687 | ||
2688 | A _tracepoint provider package_ is an object file (`.o`) or a shared | |
2689 | library (`.so`) which contains one or more tracepoint providers. Its | |
2690 | source files are: | |
2691 | ||
2692 | * One or more <<tpp-header,tracepoint provider header>> (`.h`). | |
2693 | * A <<tpp-source,tracepoint provider package source>> (`.c`). | |
2694 | ||
2695 | A tracepoint provider package is dynamically linked with `liblttng-ust`, | |
2696 | the LTTng user space tracer, at run time. | |
2697 | ||
2698 | [role="img-100"] | |
2699 | .User application linked with `liblttng-ust` and containing a tracepoint provider. | |
2700 | image::ust-app.png[] | |
2701 | ||
2702 | NOTE: If you need quick, man:printf(3)-like instrumentation, skip | |
2703 | creating and using a tracepoint provider and use | |
2704 | <<tracef,`lttng_ust_tracef()`>> or <<tracelog,`lttng_ust_tracelog()`>> | |
2705 | instead. | |
2706 | ||
2707 | ||
2708 | [[tpp-header]] | |
2709 | ===== Create a tracepoint provider header file template | |
2710 | ||
2711 | A _tracepoint provider header file_ contains the tracepoint definitions | |
2712 | of a tracepoint provider. | |
2713 | ||
2714 | To create a tracepoint provider header file: | |
2715 | ||
2716 | . Start from this template: | |
2717 | + | |
2718 | -- | |
2719 | [source,c] | |
2720 | .Tracepoint provider header file template (`.h` file extension). | |
2721 | ---- | |
2722 | #undef LTTNG_UST_TRACEPOINT_PROVIDER | |
2723 | #define LTTNG_UST_TRACEPOINT_PROVIDER provider_name | |
2724 | ||
2725 | #undef LTTNG_UST_TRACEPOINT_INCLUDE | |
2726 | #define LTTNG_UST_TRACEPOINT_INCLUDE "./tp.h" | |
2727 | ||
2728 | #if !defined(_TP_H) || defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ) | |
2729 | #define _TP_H | |
2730 | ||
2731 | #include <lttng/tracepoint.h> | |
2732 | ||
2733 | /* | |
2734 | * Use LTTNG_UST_TRACEPOINT_EVENT(), LTTNG_UST_TRACEPOINT_EVENT_CLASS(), | |
2735 | * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(), and | |
2736 | * LTTNG_UST_TRACEPOINT_LOGLEVEL() here. | |
2737 | */ | |
2738 | ||
2739 | #endif /* _TP_H */ | |
2740 | ||
2741 | #include <lttng/tracepoint-event.h> | |
2742 | ---- | |
2743 | -- | |
2744 | + | |
2745 | Replace: | |
2746 | + | |
2747 | * +__provider_name__+ with the name of your tracepoint provider. | |
2748 | * `"tp.h"` with the name of your tracepoint provider header file. | |
2749 | ||
2750 | . Below the `#include <lttng/tracepoint.h>` line, put your | |
2751 | <<defining-tracepoints,tracepoint definitions>>. | |
2752 | ||
2753 | Your tracepoint provider name must be unique amongst all the possible | |
2754 | tracepoint provider names used on the same target system. We suggest to | |
2755 | include the name of your project or company in the name, for example, | |
2756 | `org_lttng_my_project_tpp`. | |
2757 | ||
2758 | ||
2759 | [[defining-tracepoints]] | |
2760 | ===== Create a tracepoint definition | |
2761 | ||
2762 | A _tracepoint definition_ defines, for a given tracepoint: | |
2763 | ||
2764 | * Its **input arguments**. | |
2765 | + | |
2766 | They're the macro parameters that the `lttng_ust_tracepoint()` macro | |
2767 | accepts for this particular tracepoint in the source code of the user | |
2768 | application. | |
2769 | ||
2770 | * Its **output event fields**. | |
2771 | + | |
2772 | They're the sources of event fields that form the payload of any event | |
2773 | that the execution of the `lttng_ust_tracepoint()` macro emits for this | |
2774 | particular tracepoint. | |
2775 | ||
2776 | Create a tracepoint definition with the | |
2777 | `LTTNG_UST_TRACEPOINT_EVENT()` macro below the `#include <lttng/tracepoint.h>` | |
2778 | line in the | |
2779 | <<tpp-header,tracepoint provider header file template>>. | |
2780 | ||
2781 | The syntax of the `LTTNG_UST_TRACEPOINT_EVENT()` macro is: | |
2782 | ||
2783 | [source,c] | |
2784 | .`LTTNG_UST_TRACEPOINT_EVENT()` macro syntax. | |
2785 | ---- | |
2786 | LTTNG_UST_TRACEPOINT_EVENT( | |
2787 | /* Tracepoint provider name */ | |
2788 | provider_name, | |
2789 | ||
2790 | /* Tracepoint name */ | |
2791 | tracepoint_name, | |
2792 | ||
2793 | /* Input arguments */ | |
2794 | LTTNG_UST_TP_ARGS( | |
2795 | arguments | |
2796 | ), | |
2797 | ||
2798 | /* Output event fields */ | |
2799 | LTTNG_UST_TP_FIELDS( | |
2800 | fields | |
2801 | ) | |
2802 | ) | |
2803 | ---- | |
2804 | ||
2805 | Replace: | |
2806 | ||
2807 | * +__provider_name__+ with your tracepoint provider name. | |
2808 | * +__tracepoint_name__+ with your tracepoint name. | |
2809 | * +__arguments__+ with the <<tpp-def-input-args,input arguments>>. | |
2810 | * +__fields__+ with the <<tpp-def-output-fields,output event field>> | |
2811 | definitions. | |
2812 | ||
2813 | The full name of this tracepoint is `provider_name:tracepoint_name`. | |
2814 | ||
2815 | [IMPORTANT] | |
2816 | .Event name length limitation | |
2817 | ==== | |
2818 | The concatenation of the tracepoint provider name and the tracepoint | |
2819 | name must not exceed **254{nbsp}characters**. If it does, the | |
2820 | instrumented application compiles and runs, but LTTng throws multiple | |
2821 | warnings and you could experience serious issues. | |
2822 | ==== | |
2823 | ||
2824 | [[tpp-def-input-args]]The syntax of the `LTTNG_UST_TP_ARGS()` macro is: | |
2825 | ||
2826 | [source,c] | |
2827 | .`LTTNG_UST_TP_ARGS()` macro syntax. | |
2828 | ---- | |
2829 | LTTNG_UST_TP_ARGS( | |
2830 | type, arg_name | |
2831 | ) | |
2832 | ---- | |
2833 | ||
2834 | Replace: | |
2835 | ||
2836 | * +__type__+ with the C{nbsp}type of the argument. | |
2837 | * +__arg_name__+ with the argument name. | |
2838 | ||
2839 | You can repeat +__type__+ and +__arg_name__+ up to 10{nbsp}times to have | |
2840 | more than one argument. | |
2841 | ||
2842 | .`LTTNG_UST_TP_ARGS()` usage with three arguments. | |
2843 | ==== | |
2844 | [source,c] | |
2845 | ---- | |
2846 | LTTNG_UST_TP_ARGS( | |
2847 | int, count, | |
2848 | float, ratio, | |
2849 | const char*, query | |
2850 | ) | |
2851 | ---- | |
2852 | ==== | |
2853 | ||
2854 | The `LTTNG_UST_TP_ARGS()` and `LTTNG_UST_TP_ARGS(void)` forms are valid | |
2855 | to create a tracepoint definition with no input arguments. | |
2856 | ||
2857 | [[tpp-def-output-fields]]The `LTTNG_UST_TP_FIELDS()` macro contains a | |
2858 | list of `lttng_ust_field_*()` macros. Each `lttng_ust_field_*()` macro | |
2859 | defines one event field. See man:lttng-ust(3) for a complete description | |
2860 | of the available `lttng_ust_field_*()` macros. A `lttng_ust_field_*()` | |
2861 | macro specifies the type, size, and byte order of one event field. | |
2862 | ||
2863 | Each `lttng_ust_field_*()` macro takes an _argument expression_ | |
2864 | parameter. This is a C{nbsp}expression that the tracer evaluates at the | |
2865 | `lttng_ust_tracepoint()` macro site in the source code of the | |
2866 | application. This expression provides the source of data of a field. The | |
2867 | argument expression can include input argument names listed in the | |
2868 | `LTTNG_UST_TP_ARGS()` macro. | |
2869 | ||
2870 | Each `lttng_ust_field_*()` macro also takes a _field name_ parameter. | |
2871 | Field names must be unique within a given tracepoint definition. | |
2872 | ||
2873 | Here's a complete tracepoint definition example: | |
2874 | ||
2875 | .Tracepoint definition. | |
2876 | ==== | |
2877 | The following tracepoint definition defines a tracepoint which takes | |
2878 | three input arguments and has four output event fields. | |
2879 | ||
2880 | [source,c] | |
2881 | ---- | |
2882 | #include "my-custom-structure.h" | |
2883 | ||
2884 | LTTNG_UST_TRACEPOINT_EVENT( | |
2885 | my_provider, | |
2886 | my_tracepoint, | |
2887 | LTTNG_UST_TP_ARGS( | |
2888 | const struct my_custom_structure *, my_custom_structure, | |
2889 | float, ratio, | |
2890 | const char *, query | |
2891 | ), | |
2892 | LTTNG_UST_TP_FIELDS( | |
2893 | lttng_ust_field_string(query_field, query) | |
2894 | lttng_ust_field_float(double, ratio_field, ratio) | |
2895 | lttng_ust_field_integer(int, recv_size, | |
2896 | my_custom_structure->recv_size) | |
2897 | lttng_ust_field_integer(int, send_size, | |
2898 | my_custom_structure->send_size) | |
2899 | ) | |
2900 | ) | |
2901 | ---- | |
2902 | ||
2903 | Refer to this tracepoint definition with the `lttng_ust_tracepoint()` | |
2904 | macro in the source code of your application like this: | |
2905 | ||
2906 | [source,c] | |
2907 | ---- | |
2908 | lttng_ust_tracepoint(my_provider, my_tracepoint, | |
2909 | my_structure, some_ratio, the_query); | |
2910 | ---- | |
2911 | ==== | |
2912 | ||
2913 | NOTE: The LTTng-UST tracer only evaluates the arguments of a tracepoint | |
2914 | at run time when such a tracepoint _could_ emit an event. See | |
2915 | <<event-creation-emission-opti,this note>> to learn more. | |
2916 | ||
2917 | ||
2918 | [[using-tracepoint-classes]] | |
2919 | ===== Use a tracepoint class | |
2920 | ||
2921 | A _tracepoint class_ is a class of tracepoints which share the same | |
2922 | output event field definitions. A _tracepoint instance_ is one | |
2923 | instance of such a defined tracepoint class, with its own tracepoint | |
2924 | name. | |
2925 | ||
2926 | The <<defining-tracepoints,`LTTNG_UST_TRACEPOINT_EVENT()` macro>> is | |
2927 | actually a shorthand which defines both a tracepoint class and a | |
2928 | tracepoint instance at the same time. | |
2929 | ||
2930 | When you build a tracepoint provider package, the C or $$C++$$ compiler | |
2931 | creates one serialization function for each **tracepoint class**. A | |
2932 | serialization function is responsible for serializing the event fields | |
2933 | of a tracepoint to a sub-buffer when recording. | |
2934 | ||
2935 | For various performance reasons, when your situation requires multiple | |
2936 | tracepoint definitions with different names, but with the same event | |
2937 | fields, we recommend that you manually create a tracepoint class and | |
2938 | instantiate as many tracepoint instances as needed. One positive effect | |
2939 | of such a design, amongst other advantages, is that all tracepoint | |
2940 | instances of the same tracepoint class reuse the same serialization | |
2941 | function, thus reducing | |
2942 | https://en.wikipedia.org/wiki/Cache_pollution[cache pollution]. | |
2943 | ||
2944 | .Use a tracepoint class and tracepoint instances. | |
2945 | ==== | |
2946 | Consider the following three tracepoint definitions: | |
2947 | ||
2948 | [source,c] | |
2949 | ---- | |
2950 | LTTNG_UST_TRACEPOINT_EVENT( | |
2951 | my_app, | |
2952 | get_account, | |
2953 | LTTNG_UST_TP_ARGS( | |
2954 | int, userid, | |
2955 | size_t, len | |
2956 | ), | |
2957 | LTTNG_UST_TP_FIELDS( | |
2958 | lttng_ust_field_integer(int, userid, userid) | |
2959 | lttng_ust_field_integer(size_t, len, len) | |
2960 | ) | |
2961 | ) | |
2962 | ||
2963 | LTTNG_UST_TRACEPOINT_EVENT( | |
2964 | my_app, | |
2965 | get_settings, | |
2966 | LTTNG_UST_TP_ARGS( | |
2967 | int, userid, | |
2968 | size_t, len | |
2969 | ), | |
2970 | LTTNG_UST_TP_FIELDS( | |
2971 | lttng_ust_field_integer(int, userid, userid) | |
2972 | lttng_ust_field_integer(size_t, len, len) | |
2973 | ) | |
2974 | ) | |
2975 | ||
2976 | LTTNG_UST_TRACEPOINT_EVENT( | |
2977 | my_app, | |
2978 | get_transaction, | |
2979 | LTTNG_UST_TP_ARGS( | |
2980 | int, userid, | |
2981 | size_t, len | |
2982 | ), | |
2983 | LTTNG_UST_TP_FIELDS( | |
2984 | lttng_ust_field_integer(int, userid, userid) | |
2985 | lttng_ust_field_integer(size_t, len, len) | |
2986 | ) | |
2987 | ) | |
2988 | ---- | |
2989 | ||
2990 | In this case, we create three tracepoint classes, with one implicit | |
2991 | tracepoint instance for each of them: `get_account`, `get_settings`, and | |
2992 | `get_transaction`. However, they all share the same event field names | |
2993 | and types. Hence three identical, yet independent serialization | |
2994 | functions are created when you build the tracepoint provider package. | |
2995 | ||
2996 | A better design choice is to define a single tracepoint class and three | |
2997 | tracepoint instances: | |
2998 | ||
2999 | [source,c] | |
3000 | ---- | |
3001 | /* The tracepoint class */ | |
3002 | LTTNG_UST_TRACEPOINT_EVENT_CLASS( | |
3003 | /* Tracepoint class provider name */ | |
3004 | my_app, | |
3005 | ||
3006 | /* Tracepoint class name */ | |
3007 | my_class, | |
3008 | ||
3009 | /* Input arguments */ | |
3010 | LTTNG_UST_TP_ARGS( | |
3011 | int, userid, | |
3012 | size_t, len | |
3013 | ), | |
3014 | ||
3015 | /* Output event fields */ | |
3016 | LTTNG_UST_TP_FIELDS( | |
3017 | lttng_ust_field_integer(int, userid, userid) | |
3018 | lttng_ust_field_integer(size_t, len, len) | |
3019 | ) | |
3020 | ) | |
3021 | ||
3022 | /* The tracepoint instances */ | |
3023 | LTTNG_UST_TRACEPOINT_EVENT_INSTANCE( | |
3024 | /* Tracepoint class provider name */ | |
3025 | my_app, | |
3026 | ||
3027 | /* Tracepoint class name */ | |
3028 | my_class, | |
3029 | ||
3030 | /* Instance provider name */ | |
3031 | my_app, | |
3032 | ||
3033 | /* Tracepoint name */ | |
3034 | get_account, | |
3035 | ||
3036 | /* Input arguments */ | |
3037 | LTTNG_UST_TP_ARGS( | |
3038 | int, userid, | |
3039 | size_t, len | |
3040 | ) | |
3041 | ) | |
3042 | LTTNG_UST_TRACEPOINT_EVENT_INSTANCE( | |
3043 | my_app, | |
3044 | my_class, | |
3045 | get_settings, | |
3046 | LTTNG_UST_TP_ARGS( | |
3047 | int, userid, | |
3048 | size_t, len | |
3049 | ) | |
3050 | ) | |
3051 | LTTNG_UST_TRACEPOINT_EVENT_INSTANCE( | |
3052 | my_app, | |
3053 | my_class, | |
3054 | get_transaction, | |
3055 | LTTNG_UST_TP_ARGS( | |
3056 | int, userid, | |
3057 | size_t, len | |
3058 | ) | |
3059 | ) | |
3060 | ---- | |
3061 | ==== | |
3062 | ||
3063 | The tracepoint class and instance provider names must be the same if the | |
3064 | `LTTNG_UST_TRACEPOINT_EVENT_CLASS()` and | |
3065 | `LTTNG_UST_TRACEPOINT_EVENT_INSTANCE()` expansions are part of the same | |
3066 | translation unit. See man:lttng-ust(3) to learn more. | |
3067 | ||
3068 | ||
3069 | [[assigning-log-levels]] | |
3070 | ===== Assign a log level to a tracepoint definition | |
3071 | ||
3072 | Assign a _log level_ to a <<defining-tracepoints,tracepoint definition>> | |
3073 | with the `LTTNG_UST_TRACEPOINT_LOGLEVEL()` macro. | |
3074 | ||
3075 | Assigning different levels of severity to tracepoint definitions can be | |
3076 | useful: when you <<enabling-disabling-events,create a recording event | |
3077 | rule>>, you can target tracepoints having a log level at least as severe | |
3078 | as a specific value. | |
3079 | ||
3080 | The concept of LTTng-UST log levels is similar to the levels found | |
3081 | in typical logging frameworks: | |
3082 | ||
3083 | * In a logging framework, the log level is given by the function | |
3084 | or method name you use at the log statement site: `debug()`, | |
3085 | `info()`, `warn()`, `error()`, and so on. | |
3086 | ||
3087 | * In LTTng-UST, you statically assign the log level to a tracepoint | |
3088 | definition; any `lttng_ust_tracepoint()` macro invocation which refers | |
3089 | to this definition has this log level. | |
3090 | ||
3091 | You must use `LTTNG_UST_TRACEPOINT_LOGLEVEL()` _after_ the | |
3092 | <<defining-tracepoints,`LTTNG_UST_TRACEPOINT_EVENT()`>> or | |
3093 | <<using-tracepoint-classes,`LTTNG_UST_TRACEPOINT_INSTANCE()`>> macro for | |
3094 | a given tracepoint. | |
3095 | ||
3096 | The syntax of the `LTTNG_UST_TRACEPOINT_LOGLEVEL()` macro is: | |
3097 | ||
3098 | [source,c] | |
3099 | .`LTTNG_UST_TRACEPOINT_LOGLEVEL()` macro syntax. | |
3100 | ---- | |
3101 | LTTNG_UST_TRACEPOINT_LOGLEVEL(provider_name, tracepoint_name, log_level) | |
3102 | ---- | |
3103 | ||
3104 | Replace: | |
3105 | ||
3106 | * +__provider_name__+ with the tracepoint provider name. | |
3107 | * +__tracepoint_name__+ with the tracepoint name. | |
3108 | * +__log_level__+ with the log level to assign to the tracepoint | |
3109 | definition named +__tracepoint_name__+ in the +__provider_name__+ | |
3110 | tracepoint provider. | |
3111 | + | |
3112 | See man:lttng-ust(3) for a list of available log level names. | |
3113 | ||
fc360555 | 3114 | .Assign the `LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_UNIT` log level to a tracepoint definition. |
50e95807 PP |
3115 | ==== |
3116 | [source,c] | |
3117 | ---- | |
3118 | /* Tracepoint definition */ | |
3119 | LTTNG_UST_TRACEPOINT_EVENT( | |
3120 | my_app, | |
3121 | get_transaction, | |
3122 | LTTNG_UST_TP_ARGS( | |
3123 | int, userid, | |
3124 | size_t, len | |
3125 | ), | |
3126 | LTTNG_UST_TP_FIELDS( | |
3127 | lttng_ust_field_integer(int, userid, userid) | |
3128 | lttng_ust_field_integer(size_t, len, len) | |
3129 | ) | |
3130 | ) | |
3131 | ||
3132 | /* Log level assignment */ | |
3133 | LTTNG_UST_TRACEPOINT_LOGLEVEL(my_app, get_transaction, | |
3134 | LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_UNIT) | |
3135 | ---- | |
3136 | ==== | |
3137 | ||
3138 | ||
3139 | [[tpp-source]] | |
3140 | ===== Create a tracepoint provider package source file | |
3141 | ||
3142 | A _tracepoint provider package source file_ is a C source file which | |
3143 | includes a <<tpp-header,tracepoint provider header file>> to expand its | |
3144 | macros into event serialization and other functions. | |
3145 | ||
3146 | Use the following tracepoint provider package source file template: | |
3147 | ||
3148 | [source,c] | |
3149 | .Tracepoint provider package source file template. | |
3150 | ---- | |
3151 | #define LTTNG_UST_TRACEPOINT_CREATE_PROBES | |
3152 | ||
3153 | #include "tp.h" | |
3154 | ---- | |
3155 | ||
3156 | Replace `tp.h` with the name of your <<tpp-header,tracepoint provider | |
3157 | header file>> name. You may also include more than one tracepoint | |
3158 | provider header file here to create a tracepoint provider package | |
3159 | holding more than one tracepoint providers. | |
3160 | ||
3161 | ||
3162 | [[probing-the-application-source-code]] | |
3163 | ==== Add tracepoints to the source code of an application | |
3164 | ||
3165 | Once you <<tpp-header,create a tracepoint provider header file>>, use | |
3166 | the `lttng_ust_tracepoint()` macro in the source code of your | |
3167 | application to insert the tracepoints that this header | |
3168 | <<defining-tracepoints,defines>>. | |
3169 | ||
3170 | The `lttng_ust_tracepoint()` macro takes at least two parameters: the | |
3171 | tracepoint provider name and the tracepoint name. The corresponding | |
3172 | tracepoint definition defines the other parameters. | |
3173 | ||
3174 | .`lttng_ust_tracepoint()` usage. | |
3175 | ==== | |
3176 | The following <<defining-tracepoints,tracepoint definition>> defines a | |
3177 | tracepoint which takes two input arguments and has two output event | |
3178 | fields. | |
3179 | ||
3180 | [source,c] | |
3181 | .Tracepoint provider header file. | |
3182 | ---- | |
3183 | #include "my-custom-structure.h" | |
3184 | ||
3185 | LTTNG_UST_TRACEPOINT_EVENT( | |
3186 | my_provider, | |
3187 | my_tracepoint, | |
3188 | LTTNG_UST_TP_ARGS( | |
3189 | int, argc, | |
3190 | const char *, cmd_name | |
3191 | ), | |
3192 | LTTNG_UST_TP_FIELDS( | |
3193 | lttng_ust_field_string(cmd_name, cmd_name) | |
3194 | lttng_ust_field_integer(int, number_of_args, argc) | |
3195 | ) | |
3196 | ) | |
3197 | ---- | |
3198 | ||
3199 | Refer to this tracepoint definition with the `lttng_ust_tracepoint()` | |
3200 | macro in the source code of your application like this: | |
3201 | ||
3202 | [source,c] | |
3203 | .Application source file. | |
3204 | ---- | |
3205 | #include "tp.h" | |
3206 | ||
3207 | int main(int argc, char* argv[]) | |
3208 | { | |
3209 | lttng_ust_tracepoint(my_provider, my_tracepoint, argc, argv[0]); | |
3210 | return 0; | |
3211 | } | |
3212 | ---- | |
3213 | ||
3214 | Note how the source code of the application includes | |
3215 | the tracepoint provider header file containing the tracepoint | |
3216 | definitions to use, path:{tp.h}. | |
3217 | ==== | |
3218 | ||
3219 | .`lttng_ust_tracepoint()` usage with a complex tracepoint definition. | |
3220 | ==== | |
3221 | Consider this complex tracepoint definition, where multiple event | |
3222 | fields refer to the same input arguments in their argument expression | |
3223 | parameter: | |
3224 | ||
3225 | [source,c] | |
3226 | .Tracepoint provider header file. | |
3227 | ---- | |
3228 | /* For `struct stat` */ | |
3229 | #include <sys/types.h> | |
3230 | #include <sys/stat.h> | |
3231 | #include <unistd.h> | |
3232 | ||
3233 | LTTNG_UST_TRACEPOINT_EVENT( | |
3234 | my_provider, | |
3235 | my_tracepoint, | |
3236 | LTTNG_UST_TP_ARGS( | |
3237 | int, my_int_arg, | |
3238 | char *, my_str_arg, | |
3239 | struct stat *, st | |
3240 | ), | |
3241 | LTTNG_UST_TP_FIELDS( | |
3242 | lttng_ust_field_integer(int, my_constant_field, 23 + 17) | |
3243 | lttng_ust_field_integer(int, my_int_arg_field, my_int_arg) | |
3244 | lttng_ust_field_integer(int, my_int_arg_field2, | |
3245 | my_int_arg * my_int_arg) | |
3246 | lttng_ust_field_integer(int, sum4_field, | |
3247 | my_str_arg[0] + my_str_arg[1] + | |
3248 | my_str_arg[2] + my_str_arg[3]) | |
3249 | lttng_ust_field_string(my_str_arg_field, my_str_arg) | |
3250 | lttng_ust_field_integer_hex(off_t, size_field, st->st_size) | |
3251 | lttng_ust_field_float(double, size_dbl_field, (double) st->st_size) | |
3252 | lttng_ust_field_sequence_text(char, half_my_str_arg_field, | |
3253 | my_str_arg, size_t, | |
3254 | strlen(my_str_arg) / 2) | |
3255 | ) | |
3256 | ) | |
3257 | ---- | |
3258 | ||
3259 | Refer to this tracepoint definition with the `lttng_ust_tracepoint()` | |
3260 | macro in the source code of your application like this: | |
3261 | ||
3262 | [source,c] | |
3263 | .Application source file. | |
3264 | ---- | |
3265 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
3266 | #include "tp.h" | |
3267 | ||
3268 | int main(void) | |
3269 | { | |
3270 | struct stat s; | |
3271 | ||
3272 | stat("/etc/fstab", &s); | |
3273 | lttng_ust_tracepoint(my_provider, my_tracepoint, 23, | |
3274 | "Hello, World!", &s); | |
3275 | ||
3276 | return 0; | |
3277 | } | |
3278 | ---- | |
3279 | ||
3280 | If you look at the event record that LTTng writes when recording this | |
3281 | program, assuming the file size of path:{/etc/fstab} is 301{nbsp}bytes, | |
3282 | it should look like this: | |
3283 | ||
3284 | .Event record fields | |
3285 | |==== | |
3286 | |Field name |Field value | |
3287 | |`my_constant_field` |40 | |
3288 | |`my_int_arg_field` |23 | |
3289 | |`my_int_arg_field2` |529 | |
3290 | |`sum4_field` |389 | |
3291 | |`my_str_arg_field` |`Hello, World!` | |
3292 | |`size_field` |0x12d | |
3293 | |`size_dbl_field` |301.0 | |
3294 | |`half_my_str_arg_field` |`Hello,` | |
3295 | |==== | |
3296 | ==== | |
3297 | ||
3298 | Sometimes, the arguments you pass to `lttng_ust_tracepoint()` are | |
3299 | expensive to evaluate--they use the call stack, for example. To avoid | |
3300 | this computation when LTTng wouldn't emit any event anyway, use the | |
3301 | `lttng_ust_tracepoint_enabled()` and `lttng_ust_do_tracepoint()` macros. | |
3302 | ||
3303 | The syntax of the `lttng_ust_tracepoint_enabled()` and | |
3304 | `lttng_ust_do_tracepoint()` macros is: | |
3305 | ||
3306 | [source,c] | |
3307 | .`lttng_ust_tracepoint_enabled()` and `lttng_ust_do_tracepoint()` macros syntax. | |
3308 | ---- | |
3309 | lttng_ust_tracepoint_enabled(provider_name, tracepoint_name) | |
3310 | ||
3311 | lttng_ust_do_tracepoint(provider_name, tracepoint_name, ...) | |
3312 | ---- | |
3313 | ||
3314 | Replace: | |
3315 | ||
3316 | * +__provider_name__+ with the tracepoint provider name. | |
3317 | * +__tracepoint_name__+ with the tracepoint name. | |
3318 | ||
3319 | `lttng_ust_tracepoint_enabled()` returns a non-zero value if executing | |
3320 | the tracepoint named `tracepoint_name` from the provider named | |
3321 | `provider_name` _could_ make LTTng emit an event, depending on the | |
3322 | payload of said event. | |
3323 | ||
3324 | `lttng_ust_do_tracepoint()` is like `lttng_ust_tracepoint()`, except | |
3325 | that it doesn't check what `lttng_ust_tracepoint_enabled()` checks. | |
3326 | Using `lttng_ust_tracepoint()` with `lttng_ust_tracepoint_enabled()` is | |
3327 | dangerous because `lttng_ust_tracepoint()` also contains the | |
3328 | `lttng_ust_tracepoint_enabled()` check; therefore, a race condition is | |
3329 | possible in this situation: | |
3330 | ||
3331 | [source,c] | |
3332 | .Possible race condition when using `lttng_ust_tracepoint_enabled()` with `lttng_ust_tracepoint()`. | |
3333 | ---- | |
3334 | if (lttng_ust_tracepoint_enabled(my_provider, my_tracepoint)) { | |
3335 | stuff = prepare_stuff(); | |
3336 | } | |
3337 | ||
3338 | lttng_ust_tracepoint(my_provider, my_tracepoint, stuff); | |
3339 | ---- | |
3340 | ||
3341 | If `lttng_ust_tracepoint_enabled()` is false, but would be true after | |
3342 | the conditional block, then `stuff` isn't prepared: the emitted event | |
3343 | will either contain wrong data, or the whole application could crash | |
3344 | (with a segmentation fault, for example). | |
3345 | ||
3346 | NOTE: Neither `lttng_ust_tracepoint_enabled()` nor | |
3347 | `lttng_ust_do_tracepoint()` have an `STAP_PROBEV()` call. If you need | |
3348 | it, you must emit this call yourself. | |
3349 | ||
3350 | ||
3351 | [[building-tracepoint-providers-and-user-application]] | |
3352 | ==== Build and link a tracepoint provider package and an application | |
3353 | ||
3354 | Once you have one or more <<tpp-header,tracepoint provider header | |
3355 | files>> and a <<tpp-source,tracepoint provider package source file>>, | |
3356 | create the tracepoint provider package by compiling its source | |
3357 | file. From here, multiple build and run scenarios are possible. The | |
3358 | following table shows common application and library configurations | |
3359 | along with the required command lines to achieve them. | |
3360 | ||
3361 | In the following diagrams, we use the following file names: | |
3362 | ||
3363 | `app`:: | |
3364 | Executable application. | |
3365 | ||
3366 | `app.o`:: | |
3367 | Application object file. | |
3368 | ||
3369 | `tpp.o`:: | |
3370 | Tracepoint provider package object file. | |
3371 | ||
3372 | `tpp.a`:: | |
3373 | Tracepoint provider package archive file. | |
3374 | ||
3375 | `libtpp.so`:: | |
3376 | Tracepoint provider package shared object file. | |
3377 | ||
3378 | `emon.o`:: | |
3379 | User library object file. | |
3380 | ||
3381 | `libemon.so`:: | |
3382 | User library shared object file. | |
3383 | ||
3384 | We use the following symbols in the diagrams of table below: | |
3385 | ||
3386 | [role="img-100"] | |
3387 | .Symbols used in the build scenario diagrams. | |
3388 | image::ust-sit-symbols.png[] | |
3389 | ||
3390 | We assume that path:{.} is part of the env:LD_LIBRARY_PATH environment | |
3391 | variable in the following instructions. | |
3392 | ||
3393 | [role="growable ust-scenarios",cols="asciidoc,asciidoc"] | |
3394 | .Common tracepoint provider package scenarios. | |
3395 | |==== | |
3396 | |Scenario |Instructions | |
3397 | ||
3398 | | | |
3399 | The instrumented application is statically linked with | |
3400 | the tracepoint provider package object. | |
3401 | ||
3402 | image::ust-sit+app-linked-with-tp-o+app-instrumented.png[] | |
3403 | ||
3404 | | | |
3405 | include::../common/ust-sit-step-tp-o.txt[] | |
3406 | ||
3407 | To build the instrumented application: | |
3408 | ||
3409 | . In path:{app.c}, before including path:{tpp.h}, add the following line: | |
3410 | + | |
3411 | -- | |
3412 | [source,c] | |
3413 | ---- | |
3414 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
3415 | ---- | |
3416 | -- | |
3417 | ||
3418 | . Compile the application source file: | |
3419 | + | |
3420 | -- | |
3421 | [role="term"] | |
3422 | ---- | |
3423 | $ gcc -c app.c | |
3424 | ---- | |
3425 | -- | |
3426 | ||
3427 | . Build the application: | |
3428 | + | |
3429 | -- | |
3430 | [role="term"] | |
3431 | ---- | |
3432 | $ gcc -o app app.o tpp.o -llttng-ust -ldl | |
3433 | ---- | |
3434 | -- | |
3435 | ||
3436 | To run the instrumented application: | |
3437 | ||
3438 | * Start the application: | |
3439 | + | |
3440 | -- | |
3441 | [role="term"] | |
3442 | ---- | |
3443 | $ ./app | |
3444 | ---- | |
3445 | -- | |
3446 | ||
3447 | | | |
3448 | The instrumented application is statically linked with the | |
3449 | tracepoint provider package archive file. | |
3450 | ||
3451 | image::ust-sit+app-linked-with-tp-a+app-instrumented.png[] | |
3452 | ||
3453 | | | |
3454 | To create the tracepoint provider package archive file: | |
3455 | ||
3456 | . Compile the <<tpp-source,tracepoint provider package source file>>: | |
3457 | + | |
3458 | -- | |
3459 | [role="term"] | |
3460 | ---- | |
3461 | $ gcc -I. -c tpp.c | |
3462 | ---- | |
3463 | -- | |
3464 | ||
3465 | . Create the tracepoint provider package archive file: | |
3466 | + | |
3467 | -- | |
3468 | [role="term"] | |
3469 | ---- | |
3470 | $ ar rcs tpp.a tpp.o | |
3471 | ---- | |
3472 | -- | |
3473 | ||
3474 | To build the instrumented application: | |
3475 | ||
3476 | . In path:{app.c}, before including path:{tpp.h}, add the following line: | |
3477 | + | |
3478 | -- | |
3479 | [source,c] | |
3480 | ---- | |
3481 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
3482 | ---- | |
3483 | -- | |
3484 | ||
3485 | . Compile the application source file: | |
3486 | + | |
3487 | -- | |
3488 | [role="term"] | |
3489 | ---- | |
3490 | $ gcc -c app.c | |
3491 | ---- | |
3492 | -- | |
3493 | ||
3494 | . Build the application: | |
3495 | + | |
3496 | -- | |
3497 | [role="term"] | |
3498 | ---- | |
3499 | $ gcc -o app app.o tpp.a -llttng-ust -ldl | |
3500 | ---- | |
3501 | -- | |
3502 | ||
3503 | To run the instrumented application: | |
3504 | ||
3505 | * Start the application: | |
3506 | + | |
3507 | -- | |
3508 | [role="term"] | |
3509 | ---- | |
3510 | $ ./app | |
3511 | ---- | |
3512 | -- | |
3513 | ||
3514 | | | |
3515 | The instrumented application is linked with the tracepoint provider | |
3516 | package shared object. | |
3517 | ||
3518 | image::ust-sit+app-linked-with-tp-so+app-instrumented.png[] | |
3519 | ||
3520 | | | |
3521 | include::../common/ust-sit-step-tp-so.txt[] | |
3522 | ||
3523 | To build the instrumented application: | |
3524 | ||
3525 | . In path:{app.c}, before including path:{tpp.h}, add the following line: | |
3526 | + | |
3527 | -- | |
3528 | [source,c] | |
3529 | ---- | |
3530 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
3531 | ---- | |
3532 | -- | |
3533 | ||
3534 | . Compile the application source file: | |
3535 | + | |
3536 | -- | |
3537 | [role="term"] | |
3538 | ---- | |
3539 | $ gcc -c app.c | |
3540 | ---- | |
3541 | -- | |
3542 | ||
3543 | . Build the application: | |
3544 | + | |
3545 | -- | |
3546 | [role="term"] | |
3547 | ---- | |
3548 | $ gcc -o app app.o -ldl -L. -ltpp | |
3549 | ---- | |
3550 | -- | |
3551 | ||
3552 | To run the instrumented application: | |
3553 | ||
3554 | * Start the application: | |
3555 | + | |
3556 | -- | |
3557 | [role="term"] | |
3558 | ---- | |
3559 | $ ./app | |
3560 | ---- | |
3561 | -- | |
3562 | ||
3563 | | | |
3564 | The tracepoint provider package shared object is preloaded before the | |
3565 | instrumented application starts. | |
3566 | ||
3567 | image::ust-sit+tp-so-preloaded+app-instrumented.png[] | |
3568 | ||
3569 | | | |
3570 | include::../common/ust-sit-step-tp-so.txt[] | |
3571 | ||
3572 | To build the instrumented application: | |
3573 | ||
3574 | . In path:{app.c}, before including path:{tpp.h}, add the | |
3575 | following lines: | |
3576 | + | |
3577 | -- | |
3578 | [source,c] | |
3579 | ---- | |
3580 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
3581 | #define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE | |
3582 | ---- | |
3583 | -- | |
3584 | ||
3585 | . Compile the application source file: | |
3586 | + | |
3587 | -- | |
3588 | [role="term"] | |
3589 | ---- | |
3590 | $ gcc -c app.c | |
3591 | ---- | |
3592 | -- | |
3593 | ||
3594 | . Build the application: | |
3595 | + | |
3596 | -- | |
3597 | [role="term"] | |
3598 | ---- | |
3599 | $ gcc -o app app.o -ldl | |
3600 | ---- | |
3601 | -- | |
3602 | ||
3603 | To run the instrumented application with tracing support: | |
3604 | ||
3605 | * Preload the tracepoint provider package shared object and | |
3606 | start the application: | |
3607 | + | |
3608 | -- | |
3609 | [role="term"] | |
3610 | ---- | |
3611 | $ LD_PRELOAD=./libtpp.so ./app | |
3612 | ---- | |
3613 | -- | |
3614 | ||
3615 | To run the instrumented application without tracing support: | |
3616 | ||
3617 | * Start the application: | |
3618 | + | |
3619 | -- | |
3620 | [role="term"] | |
3621 | ---- | |
3622 | $ ./app | |
3623 | ---- | |
3624 | -- | |
3625 | ||
3626 | | | |
3627 | The instrumented application dynamically loads the tracepoint provider | |
3628 | package shared object. | |
3629 | ||
3630 | image::ust-sit+app-dlopens-tp-so+app-instrumented.png[] | |
3631 | ||
3632 | | | |
3633 | include::../common/ust-sit-step-tp-so.txt[] | |
3634 | ||
3635 | To build the instrumented application: | |
3636 | ||
3637 | . In path:{app.c}, before including path:{tpp.h}, add the | |
3638 | following lines: | |
3639 | + | |
3640 | -- | |
3641 | [source,c] | |
3642 | ---- | |
3643 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
3644 | #define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE | |
3645 | ---- | |
3646 | -- | |
3647 | ||
3648 | . Compile the application source file: | |
3649 | + | |
3650 | -- | |
3651 | [role="term"] | |
3652 | ---- | |
3653 | $ gcc -c app.c | |
3654 | ---- | |
3655 | -- | |
3656 | ||
3657 | . Build the application: | |
3658 | + | |
3659 | -- | |
3660 | [role="term"] | |
3661 | ---- | |
3662 | $ gcc -o app app.o -ldl | |
3663 | ---- | |
3664 | -- | |
3665 | ||
3666 | To run the instrumented application: | |
3667 | ||
3668 | * Start the application: | |
3669 | + | |
3670 | -- | |
3671 | [role="term"] | |
3672 | ---- | |
3673 | $ ./app | |
3674 | ---- | |
3675 | -- | |
3676 | ||
3677 | | | |
3678 | The application is linked with the instrumented user library. | |
3679 | ||
3680 | The instrumented user library is statically linked with the tracepoint | |
3681 | provider package object file. | |
3682 | ||
3683 | image::ust-sit+app-linked-with-lib+lib-linked-with-tp-o+lib-instrumented.png[] | |
3684 | ||
3685 | | | |
3686 | include::../common/ust-sit-step-tp-o-fpic.txt[] | |
3687 | ||
3688 | To build the instrumented user library: | |
3689 | ||
3690 | . In path:{emon.c}, before including path:{tpp.h}, add the | |
3691 | following line: | |
3692 | + | |
3693 | -- | |
3694 | [source,c] | |
3695 | ---- | |
3696 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
3697 | ---- | |
3698 | -- | |
3699 | ||
3700 | . Compile the user library source file: | |
3701 | + | |
3702 | -- | |
3703 | [role="term"] | |
3704 | ---- | |
3705 | $ gcc -I. -fpic -c emon.c | |
3706 | ---- | |
3707 | -- | |
3708 | ||
3709 | . Build the user library shared object: | |
3710 | + | |
3711 | -- | |
3712 | [role="term"] | |
3713 | ---- | |
3714 | $ gcc -shared -o libemon.so emon.o tpp.o -llttng-ust -ldl | |
3715 | ---- | |
3716 | -- | |
3717 | ||
3718 | To build the application: | |
3719 | ||
3720 | . Compile the application source file: | |
3721 | + | |
3722 | -- | |
3723 | [role="term"] | |
3724 | ---- | |
3725 | $ gcc -c app.c | |
3726 | ---- | |
3727 | -- | |
3728 | ||
3729 | . Build the application: | |
3730 | + | |
3731 | -- | |
3732 | [role="term"] | |
3733 | ---- | |
3734 | $ gcc -o app app.o -L. -lemon | |
3735 | ---- | |
3736 | -- | |
3737 | ||
3738 | To run the application: | |
3739 | ||
3740 | * Start the application: | |
3741 | + | |
3742 | -- | |
3743 | [role="term"] | |
3744 | ---- | |
3745 | $ ./app | |
3746 | ---- | |
3747 | -- | |
3748 | ||
3749 | | | |
3750 | The application is linked with the instrumented user library. | |
3751 | ||
3752 | The instrumented user library is linked with the tracepoint provider | |
3753 | package shared object. | |
3754 | ||
3755 | image::ust-sit+app-linked-with-lib+lib-linked-with-tp-so+lib-instrumented.png[] | |
3756 | ||
3757 | | | |
3758 | include::../common/ust-sit-step-tp-so.txt[] | |
3759 | ||
3760 | To build the instrumented user library: | |
3761 | ||
3762 | . In path:{emon.c}, before including path:{tpp.h}, add the | |
3763 | following line: | |
3764 | + | |
3765 | -- | |
3766 | [source,c] | |
3767 | ---- | |
3768 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
3769 | ---- | |
3770 | -- | |
3771 | ||
3772 | . Compile the user library source file: | |
3773 | + | |
3774 | -- | |
3775 | [role="term"] | |
3776 | ---- | |
3777 | $ gcc -I. -fpic -c emon.c | |
3778 | ---- | |
3779 | -- | |
3780 | ||
3781 | . Build the user library shared object: | |
3782 | + | |
3783 | -- | |
3784 | [role="term"] | |
3785 | ---- | |
3786 | $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp | |
3787 | ---- | |
3788 | -- | |
3789 | ||
3790 | To build the application: | |
3791 | ||
3792 | . Compile the application source file: | |
3793 | + | |
3794 | -- | |
3795 | [role="term"] | |
3796 | ---- | |
3797 | $ gcc -c app.c | |
3798 | ---- | |
3799 | -- | |
3800 | ||
3801 | . Build the application: | |
3802 | + | |
3803 | -- | |
3804 | [role="term"] | |
3805 | ---- | |
3806 | $ gcc -o app app.o -L. -lemon | |
3807 | ---- | |
3808 | -- | |
3809 | ||
3810 | To run the application: | |
3811 | ||
3812 | * Start the application: | |
3813 | + | |
3814 | -- | |
3815 | [role="term"] | |
3816 | ---- | |
3817 | $ ./app | |
3818 | ---- | |
3819 | -- | |
3820 | ||
3821 | | | |
3822 | The tracepoint provider package shared object is preloaded before the | |
3823 | application starts. | |
3824 | ||
3825 | The application is linked with the instrumented user library. | |
3826 | ||
3827 | image::ust-sit+tp-so-preloaded+app-linked-with-lib+lib-instrumented.png[] | |
3828 | ||
3829 | | | |
3830 | include::../common/ust-sit-step-tp-so.txt[] | |
3831 | ||
3832 | To build the instrumented user library: | |
3833 | ||
3834 | . In path:{emon.c}, before including path:{tpp.h}, add the | |
3835 | following lines: | |
3836 | + | |
3837 | -- | |
3838 | [source,c] | |
3839 | ---- | |
3840 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
3841 | #define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE | |
3842 | ---- | |
3843 | -- | |
3844 | ||
3845 | . Compile the user library source file: | |
3846 | + | |
3847 | -- | |
3848 | [role="term"] | |
3849 | ---- | |
3850 | $ gcc -I. -fpic -c emon.c | |
3851 | ---- | |
3852 | -- | |
3853 | ||
3854 | . Build the user library shared object: | |
3855 | + | |
3856 | -- | |
3857 | [role="term"] | |
3858 | ---- | |
3859 | $ gcc -shared -o libemon.so emon.o -ldl | |
3860 | ---- | |
3861 | -- | |
3862 | ||
3863 | To build the application: | |
3864 | ||
3865 | . Compile the application source file: | |
3866 | + | |
3867 | -- | |
3868 | [role="term"] | |
3869 | ---- | |
3870 | $ gcc -c app.c | |
3871 | ---- | |
3872 | -- | |
3873 | ||
3874 | . Build the application: | |
3875 | + | |
3876 | -- | |
3877 | [role="term"] | |
3878 | ---- | |
3879 | $ gcc -o app app.o -L. -lemon | |
3880 | ---- | |
3881 | -- | |
3882 | ||
3883 | To run the application with tracing support: | |
3884 | ||
3885 | * Preload the tracepoint provider package shared object and | |
3886 | start the application: | |
3887 | + | |
3888 | -- | |
3889 | [role="term"] | |
3890 | ---- | |
3891 | $ LD_PRELOAD=./libtpp.so ./app | |
3892 | ---- | |
3893 | -- | |
3894 | ||
3895 | To run the application without tracing support: | |
3896 | ||
3897 | * Start the application: | |
3898 | + | |
3899 | -- | |
3900 | [role="term"] | |
3901 | ---- | |
3902 | $ ./app | |
3903 | ---- | |
3904 | -- | |
3905 | ||
3906 | | | |
3907 | The application is linked with the instrumented user library. | |
3908 | ||
3909 | The instrumented user library dynamically loads the tracepoint provider | |
3910 | package shared object. | |
3911 | ||
3912 | image::ust-sit+app-linked-with-lib+lib-dlopens-tp-so+lib-instrumented.png[] | |
3913 | ||
3914 | | | |
3915 | include::../common/ust-sit-step-tp-so.txt[] | |
3916 | ||
3917 | To build the instrumented user library: | |
3918 | ||
3919 | . In path:{emon.c}, before including path:{tpp.h}, add the | |
3920 | following lines: | |
3921 | + | |
3922 | -- | |
3923 | [source,c] | |
3924 | ---- | |
3925 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
3926 | #define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE | |
3927 | ---- | |
3928 | -- | |
3929 | ||
3930 | . Compile the user library source file: | |
3931 | + | |
3932 | -- | |
3933 | [role="term"] | |
3934 | ---- | |
3935 | $ gcc -I. -fpic -c emon.c | |
3936 | ---- | |
3937 | -- | |
3938 | ||
3939 | . Build the user library shared object: | |
3940 | + | |
3941 | -- | |
3942 | [role="term"] | |
3943 | ---- | |
3944 | $ gcc -shared -o libemon.so emon.o -ldl | |
3945 | ---- | |
3946 | -- | |
3947 | ||
3948 | To build the application: | |
3949 | ||
3950 | . Compile the application source file: | |
3951 | + | |
3952 | -- | |
3953 | [role="term"] | |
3954 | ---- | |
3955 | $ gcc -c app.c | |
3956 | ---- | |
3957 | -- | |
3958 | ||
3959 | . Build the application: | |
3960 | + | |
3961 | -- | |
3962 | [role="term"] | |
3963 | ---- | |
3964 | $ gcc -o app app.o -L. -lemon | |
3965 | ---- | |
3966 | -- | |
3967 | ||
3968 | To run the application: | |
3969 | ||
3970 | * Start the application: | |
3971 | + | |
3972 | -- | |
3973 | [role="term"] | |
3974 | ---- | |
3975 | $ ./app | |
3976 | ---- | |
3977 | -- | |
3978 | ||
3979 | | | |
3980 | The application dynamically loads the instrumented user library. | |
3981 | ||
3982 | The instrumented user library is linked with the tracepoint provider | |
3983 | package shared object. | |
3984 | ||
3985 | image::ust-sit+app-dlopens-lib+lib-linked-with-tp-so+lib-instrumented.png[] | |
3986 | ||
3987 | | | |
3988 | include::../common/ust-sit-step-tp-so.txt[] | |
3989 | ||
3990 | To build the instrumented user library: | |
3991 | ||
3992 | . In path:{emon.c}, before including path:{tpp.h}, add the | |
3993 | following line: | |
3994 | + | |
3995 | -- | |
3996 | [source,c] | |
3997 | ---- | |
3998 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
3999 | ---- | |
4000 | -- | |
4001 | ||
4002 | . Compile the user library source file: | |
4003 | + | |
4004 | -- | |
4005 | [role="term"] | |
4006 | ---- | |
4007 | $ gcc -I. -fpic -c emon.c | |
4008 | ---- | |
4009 | -- | |
4010 | ||
4011 | . Build the user library shared object: | |
4012 | + | |
4013 | -- | |
4014 | [role="term"] | |
4015 | ---- | |
4016 | $ gcc -shared -o libemon.so emon.o -ldl -L. -ltpp | |
4017 | ---- | |
4018 | -- | |
4019 | ||
4020 | To build the application: | |
4021 | ||
4022 | . Compile the application source file: | |
4023 | + | |
4024 | -- | |
4025 | [role="term"] | |
4026 | ---- | |
4027 | $ gcc -c app.c | |
4028 | ---- | |
4029 | -- | |
4030 | ||
4031 | . Build the application: | |
4032 | + | |
4033 | -- | |
4034 | [role="term"] | |
4035 | ---- | |
4036 | $ gcc -o app app.o -ldl -L. -lemon | |
4037 | ---- | |
4038 | -- | |
4039 | ||
4040 | To run the application: | |
4041 | ||
4042 | * Start the application: | |
4043 | + | |
4044 | -- | |
4045 | [role="term"] | |
4046 | ---- | |
4047 | $ ./app | |
4048 | ---- | |
4049 | -- | |
4050 | ||
4051 | | | |
4052 | The application dynamically loads the instrumented user library. | |
4053 | ||
4054 | The instrumented user library dynamically loads the tracepoint provider | |
4055 | package shared object. | |
4056 | ||
4057 | image::ust-sit+app-dlopens-lib+lib-dlopens-tp-so+lib-instrumented.png[] | |
4058 | ||
4059 | | | |
4060 | include::../common/ust-sit-step-tp-so.txt[] | |
4061 | ||
4062 | To build the instrumented user library: | |
4063 | ||
4064 | . In path:{emon.c}, before including path:{tpp.h}, add the | |
4065 | following lines: | |
4066 | + | |
4067 | -- | |
4068 | [source,c] | |
4069 | ---- | |
4070 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
4071 | #define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE | |
4072 | ---- | |
4073 | -- | |
4074 | ||
4075 | . Compile the user library source file: | |
4076 | + | |
4077 | -- | |
4078 | [role="term"] | |
4079 | ---- | |
4080 | $ gcc -I. -fpic -c emon.c | |
4081 | ---- | |
4082 | -- | |
4083 | ||
4084 | . Build the user library shared object: | |
4085 | + | |
4086 | -- | |
4087 | [role="term"] | |
4088 | ---- | |
4089 | $ gcc -shared -o libemon.so emon.o -ldl | |
4090 | ---- | |
4091 | -- | |
4092 | ||
4093 | To build the application: | |
4094 | ||
4095 | . Compile the application source file: | |
4096 | + | |
4097 | -- | |
4098 | [role="term"] | |
4099 | ---- | |
4100 | $ gcc -c app.c | |
4101 | ---- | |
4102 | -- | |
4103 | ||
4104 | . Build the application: | |
4105 | + | |
4106 | -- | |
4107 | [role="term"] | |
4108 | ---- | |
4109 | $ gcc -o app app.o -ldl -L. -lemon | |
4110 | ---- | |
4111 | -- | |
4112 | ||
4113 | To run the application: | |
4114 | ||
4115 | * Start the application: | |
4116 | + | |
4117 | -- | |
4118 | [role="term"] | |
4119 | ---- | |
4120 | $ ./app | |
4121 | ---- | |
4122 | -- | |
4123 | ||
4124 | | | |
4125 | The tracepoint provider package shared object is preloaded before the | |
4126 | application starts. | |
4127 | ||
4128 | The application dynamically loads the instrumented user library. | |
4129 | ||
4130 | image::ust-sit+tp-so-preloaded+app-dlopens-lib+lib-instrumented.png[] | |
4131 | ||
4132 | | | |
4133 | include::../common/ust-sit-step-tp-so.txt[] | |
4134 | ||
4135 | To build the instrumented user library: | |
4136 | ||
4137 | . In path:{emon.c}, before including path:{tpp.h}, add the | |
4138 | following lines: | |
4139 | + | |
4140 | -- | |
4141 | [source,c] | |
4142 | ---- | |
4143 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
4144 | #define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE | |
4145 | ---- | |
4146 | -- | |
4147 | ||
4148 | . Compile the user library source file: | |
4149 | + | |
4150 | -- | |
4151 | [role="term"] | |
4152 | ---- | |
4153 | $ gcc -I. -fpic -c emon.c | |
4154 | ---- | |
4155 | -- | |
4156 | ||
4157 | . Build the user library shared object: | |
4158 | + | |
4159 | -- | |
4160 | [role="term"] | |
4161 | ---- | |
4162 | $ gcc -shared -o libemon.so emon.o -ldl | |
4163 | ---- | |
4164 | -- | |
4165 | ||
4166 | To build the application: | |
4167 | ||
4168 | . Compile the application source file: | |
4169 | + | |
4170 | -- | |
4171 | [role="term"] | |
4172 | ---- | |
4173 | $ gcc -c app.c | |
4174 | ---- | |
4175 | -- | |
4176 | ||
4177 | . Build the application: | |
4178 | + | |
4179 | -- | |
4180 | [role="term"] | |
4181 | ---- | |
4182 | $ gcc -o app app.o -L. -lemon | |
4183 | ---- | |
4184 | -- | |
4185 | ||
4186 | To run the application with tracing support: | |
4187 | ||
4188 | * Preload the tracepoint provider package shared object and | |
4189 | start the application: | |
4190 | + | |
4191 | -- | |
4192 | [role="term"] | |
4193 | ---- | |
4194 | $ LD_PRELOAD=./libtpp.so ./app | |
4195 | ---- | |
4196 | -- | |
4197 | ||
4198 | To run the application without tracing support: | |
4199 | ||
4200 | * Start the application: | |
4201 | + | |
4202 | -- | |
4203 | [role="term"] | |
4204 | ---- | |
4205 | $ ./app | |
4206 | ---- | |
4207 | -- | |
4208 | ||
4209 | | | |
4210 | The application is statically linked with the tracepoint provider | |
4211 | package object file. | |
4212 | ||
4213 | The application is linked with the instrumented user library. | |
4214 | ||
4215 | image::ust-sit+app-linked-with-tp-o+app-linked-with-lib+lib-instrumented.png[] | |
4216 | ||
4217 | | | |
4218 | include::../common/ust-sit-step-tp-o.txt[] | |
4219 | ||
4220 | To build the instrumented user library: | |
4221 | ||
4222 | . In path:{emon.c}, before including path:{tpp.h}, add the | |
4223 | following line: | |
4224 | + | |
4225 | -- | |
4226 | [source,c] | |
4227 | ---- | |
4228 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
4229 | ---- | |
4230 | -- | |
4231 | ||
4232 | . Compile the user library source file: | |
4233 | + | |
4234 | -- | |
4235 | [role="term"] | |
4236 | ---- | |
4237 | $ gcc -I. -fpic -c emon.c | |
4238 | ---- | |
4239 | -- | |
4240 | ||
4241 | . Build the user library shared object: | |
4242 | + | |
4243 | -- | |
4244 | [role="term"] | |
4245 | ---- | |
4246 | $ gcc -shared -o libemon.so emon.o | |
4247 | ---- | |
4248 | -- | |
4249 | ||
4250 | To build the application: | |
4251 | ||
4252 | . Compile the application source file: | |
4253 | + | |
4254 | -- | |
4255 | [role="term"] | |
4256 | ---- | |
4257 | $ gcc -c app.c | |
4258 | ---- | |
4259 | -- | |
4260 | ||
4261 | . Build the application: | |
4262 | + | |
4263 | -- | |
4264 | [role="term"] | |
4265 | ---- | |
4266 | $ gcc -o app app.o tpp.o -llttng-ust -ldl -L. -lemon | |
4267 | ---- | |
4268 | -- | |
4269 | ||
4270 | To run the instrumented application: | |
4271 | ||
4272 | * Start the application: | |
4273 | + | |
4274 | -- | |
4275 | [role="term"] | |
4276 | ---- | |
4277 | $ ./app | |
4278 | ---- | |
4279 | -- | |
4280 | ||
4281 | | | |
4282 | The application is statically linked with the tracepoint provider | |
4283 | package object file. | |
4284 | ||
4285 | The application dynamically loads the instrumented user library. | |
4286 | ||
4287 | image::ust-sit+app-linked-with-tp-o+app-dlopens-lib+lib-instrumented.png[] | |
4288 | ||
4289 | | | |
4290 | include::../common/ust-sit-step-tp-o.txt[] | |
4291 | ||
4292 | To build the application: | |
4293 | ||
4294 | . In path:{app.c}, before including path:{tpp.h}, add the following line: | |
4295 | + | |
4296 | -- | |
4297 | [source,c] | |
4298 | ---- | |
4299 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
4300 | ---- | |
4301 | -- | |
4302 | ||
4303 | . Compile the application source file: | |
4304 | + | |
4305 | -- | |
4306 | [role="term"] | |
4307 | ---- | |
4308 | $ gcc -c app.c | |
4309 | ---- | |
4310 | -- | |
4311 | ||
4312 | . Build the application: | |
4313 | + | |
4314 | -- | |
4315 | [role="term"] | |
4316 | ---- | |
4317 | $ gcc -Wl,--export-dynamic -o app app.o tpp.o \ | |
4318 | -llttng-ust -ldl | |
4319 | ---- | |
4320 | -- | |
4321 | + | |
4322 | The `--export-dynamic` option passed to the linker is necessary for the | |
4323 | dynamically loaded library to ``see'' the tracepoint symbols defined in | |
4324 | the application. | |
4325 | ||
4326 | To build the instrumented user library: | |
4327 | ||
4328 | . Compile the user library source file: | |
4329 | + | |
4330 | -- | |
4331 | [role="term"] | |
4332 | ---- | |
4333 | $ gcc -I. -fpic -c emon.c | |
4334 | ---- | |
4335 | -- | |
4336 | ||
4337 | . Build the user library shared object: | |
4338 | + | |
4339 | -- | |
4340 | [role="term"] | |
4341 | ---- | |
4342 | $ gcc -shared -o libemon.so emon.o | |
4343 | ---- | |
4344 | -- | |
4345 | ||
4346 | To run the application: | |
4347 | ||
4348 | * Start the application: | |
4349 | + | |
4350 | -- | |
4351 | [role="term"] | |
4352 | ---- | |
4353 | $ ./app | |
4354 | ---- | |
4355 | -- | |
4356 | |==== | |
4357 | ||
4358 | ||
4359 | [[using-lttng-ust-with-daemons]] | |
4360 | ===== Use noch:{LTTng-UST} with daemons | |
4361 | ||
4362 | If your instrumented application calls man:fork(2), man:clone(2), | |
4363 | or BSD's man:rfork(2), without a following man:exec(3)-family | |
4364 | system call, you must preload the path:{liblttng-ust-fork.so} shared | |
4365 | object when you start the application. | |
4366 | ||
4367 | [role="term"] | |
4368 | ---- | |
4369 | $ LD_PRELOAD=liblttng-ust-fork.so ./my-app | |
4370 | ---- | |
4371 | ||
4372 | If your tracepoint provider package is | |
4373 | a shared library which you also preload, you must put both | |
4374 | shared objects in env:LD_PRELOAD: | |
4375 | ||
4376 | [role="term"] | |
4377 | ---- | |
4378 | $ LD_PRELOAD=liblttng-ust-fork.so:/path/to/tp.so ./my-app | |
4379 | ---- | |
4380 | ||
4381 | ||
4382 | [role="since-2.9"] | |
4383 | [[liblttng-ust-fd]] | |
4384 | ===== Use noch:{LTTng-UST} with applications which close file descriptors that don't belong to them | |
4385 | ||
4386 | If your instrumented application closes one or more file descriptors | |
4387 | which it did not open itself, you must preload the | |
4388 | path:{liblttng-ust-fd.so} shared object when you start the application: | |
4389 | ||
4390 | [role="term"] | |
4391 | ---- | |
4392 | $ LD_PRELOAD=liblttng-ust-fd.so ./my-app | |
4393 | ---- | |
4394 | ||
4395 | Typical use cases include closing all the file descriptors after | |
4396 | man:fork(2) or man:rfork(2) and buggy applications doing | |
4397 | ``double closes''. | |
4398 | ||
4399 | ||
4400 | [[lttng-ust-pkg-config]] | |
4401 | ===== Use noch:{pkg-config} | |
4402 | ||
4403 | On some distributions, LTTng-UST ships with a | |
4404 | https://www.freedesktop.org/wiki/Software/pkg-config/[pkg-config] | |
4405 | metadata file. If this is your case, then use cmd:pkg-config to | |
4406 | build an application on the command line: | |
4407 | ||
4408 | [role="term"] | |
4409 | ---- | |
4410 | $ gcc -o my-app my-app.o tp.o $(pkg-config --cflags --libs lttng-ust) | |
4411 | ---- | |
4412 | ||
4413 | ||
4414 | [[instrumenting-32-bit-app-on-64-bit-system]] | |
4415 | ===== [[advanced-instrumenting-techniques]]Build a 32-bit instrumented application for a 64-bit target system | |
4416 | ||
4417 | In order to trace a 32-bit application running on a 64-bit system, | |
4418 | LTTng must use a dedicated 32-bit | |
4419 | <<lttng-consumerd,consumer daemon>>. | |
4420 | ||
4421 | The following steps show how to build and install a 32-bit consumer | |
4422 | daemon, which is _not_ part of the default 64-bit LTTng build, how to | |
4423 | build and install the 32-bit LTTng-UST libraries, and how to build and | |
4424 | link an instrumented 32-bit application in that context. | |
4425 | ||
4426 | To build a 32-bit instrumented application for a 64-bit target system, | |
4427 | assuming you have a fresh target system with no installed Userspace RCU | |
4428 | or LTTng packages: | |
4429 | ||
4430 | . Download, build, and install a 32-bit version of Userspace RCU: | |
4431 | + | |
4432 | -- | |
4433 | [role="term"] | |
4434 | ---- | |
4435 | $ cd $(mktemp -d) && | |
4436 | wget https://lttng.org/files/urcu/userspace-rcu-latest-0.13.tar.bz2 && | |
4437 | tar -xf userspace-rcu-latest-0.13.tar.bz2 && | |
4438 | cd userspace-rcu-0.13.* && | |
4439 | ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 && | |
4440 | make && | |
4441 | sudo make install && | |
4442 | sudo ldconfig | |
4443 | ---- | |
4444 | -- | |
4445 | ||
4446 | . Using the package manager of your distribution, or from source, | |
4447 | install the 32-bit versions of the following dependencies of | |
4448 | LTTng-tools and LTTng-UST: | |
4449 | + | |
4450 | -- | |
4451 | * https://sourceforge.net/projects/libuuid/[libuuid] | |
4452 | * https://directory.fsf.org/wiki/Popt[popt] | |
4453 | * https://www.xmlsoft.org/[libxml2] | |
4454 | * **Optional**: https://github.com/numactl/numactl[numactl] | |
4455 | -- | |
4456 | ||
4457 | . Download, build, and install a 32-bit version of the latest | |
4458 | LTTng-UST{nbsp}{revision}: | |
4459 | + | |
4460 | -- | |
4461 | [role="term"] | |
4462 | ---- | |
4463 | $ cd $(mktemp -d) && | |
4464 | wget https://lttng.org/files/lttng-ust/lttng-ust-latest-2.13.tar.bz2 && | |
4465 | tar -xf lttng-ust-latest-2.13.tar.bz2 && | |
4466 | cd lttng-ust-2.13.* && | |
4467 | ./configure --libdir=/usr/local/lib32 \ | |
4468 | CFLAGS=-m32 CXXFLAGS=-m32 \ | |
4469 | LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' && | |
4470 | make && | |
4471 | sudo make install && | |
4472 | sudo ldconfig | |
4473 | ---- | |
4474 | -- | |
4475 | + | |
4476 | Add `--disable-numa` to `./configure` if you don't have | |
4477 | https://github.com/numactl/numactl[numactl]. | |
4478 | + | |
4479 | [NOTE] | |
4480 | ==== | |
4481 | Depending on your distribution, 32-bit libraries could be installed at a | |
4482 | different location than `/usr/lib32`. For example, Debian is known to | |
4483 | install some 32-bit libraries in `/usr/lib/i386-linux-gnu`. | |
4484 | ||
4485 | In this case, make sure to set `LDFLAGS` to all the | |
4486 | relevant 32-bit library paths, for example: | |
4487 | ||
4488 | [role="term"] | |
4489 | ---- | |
4490 | $ LDFLAGS='-L/usr/lib/i386-linux-gnu -L/usr/lib32' | |
4491 | ---- | |
4492 | ==== | |
4493 | ||
4494 | . Download the latest LTTng-tools{nbsp}{revision}, build, and install | |
4495 | the 32-bit consumer daemon: | |
4496 | + | |
4497 | -- | |
4498 | [role="term"] | |
4499 | ---- | |
4500 | $ cd $(mktemp -d) && | |
4501 | wget https://lttng.org/files/lttng-tools/lttng-tools-latest-2.13.tar.bz2 && | |
4502 | tar -xf lttng-tools-latest-2.13.tar.bz2 && | |
4503 | cd lttng-tools-2.13.* && | |
4504 | ./configure --libdir=/usr/local/lib32 CFLAGS=-m32 CXXFLAGS=-m32 \ | |
4505 | LDFLAGS='-L/usr/local/lib32 -L/usr/lib32' \ | |
4506 | --disable-bin-lttng --disable-bin-lttng-crash \ | |
4507 | --disable-bin-lttng-relayd --disable-bin-lttng-sessiond && | |
4508 | make && | |
4509 | cd src/bin/lttng-consumerd && | |
4510 | sudo make install && | |
4511 | sudo ldconfig | |
4512 | ---- | |
4513 | -- | |
4514 | ||
4515 | . From your distribution or from source, <<installing-lttng,install>> | |
4516 | the 64-bit versions of LTTng-UST and Userspace RCU. | |
4517 | ||
4518 | . Download, build, and install the 64-bit version of the | |
4519 | latest LTTng-tools{nbsp}{revision}: | |
4520 | + | |
4521 | -- | |
4522 | [role="term"] | |
4523 | ---- | |
4524 | $ cd $(mktemp -d) && | |
4525 | wget https://lttng.org/files/lttng-tools/lttng-tools-latest-2.13.tar.bz2 && | |
4526 | tar -xf lttng-tools-latest-2.13.tar.bz2 && | |
4527 | cd lttng-tools-2.13.* && | |
4528 | ./configure --with-consumerd32-libdir=/usr/local/lib32 \ | |
4529 | --with-consumerd32-bin=/usr/local/lib32/lttng/libexec/lttng-consumerd && | |
4530 | make && | |
4531 | sudo make install && | |
4532 | sudo ldconfig | |
4533 | ---- | |
4534 | -- | |
4535 | ||
4536 | . Pass the following options to man:gcc(1), man:g++(1), or man:clang(1) | |
4537 | when linking your 32-bit application: | |
4538 | + | |
4539 | ---- | |
4540 | -m32 -L/usr/lib32 -L/usr/local/lib32 \ | |
4541 | -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32 | |
4542 | ---- | |
4543 | + | |
4544 | For example, let's rebuild the quick start example in | |
4545 | ``<<tracing-your-own-user-application,Record user application events>>'' | |
4546 | as an instrumented 32-bit application: | |
4547 | + | |
4548 | -- | |
4549 | [role="term"] | |
4550 | ---- | |
4551 | $ gcc -m32 -c -I. hello-tp.c | |
4552 | $ gcc -m32 -c hello.c | |
4553 | $ gcc -m32 -o hello hello.o hello-tp.o \ | |
4554 | -L/usr/lib32 -L/usr/local/lib32 \ | |
4555 | -Wl,-rpath,/usr/lib32,-rpath,/usr/local/lib32 \ | |
4556 | -llttng-ust -ldl | |
4557 | ---- | |
4558 | -- | |
4559 | ||
4560 | No special action is required to execute the 32-bit application and | |
4561 | for LTTng to trace it: use the command-line man:lttng(1) tool as usual. | |
4562 | ||
4563 | ||
4564 | [role="since-2.5"] | |
4565 | [[tracef]] | |
4566 | ==== Use `lttng_ust_tracef()` | |
4567 | ||
4568 | man:lttng_ust_tracef(3) is a small LTTng-UST API designed for quick, | |
4569 | man:printf(3)-like instrumentation without the burden of | |
4570 | <<tracepoint-provider,creating>> and | |
4571 | <<building-tracepoint-providers-and-user-application,building>> | |
4572 | a tracepoint provider package. | |
4573 | ||
4574 | To use `lttng_ust_tracef()` in your application: | |
4575 | ||
4576 | . In the C or $$C++$$ source files where you need to use | |
4577 | `lttng_ust_tracef()`, include `<lttng/tracef.h>`: | |
4578 | + | |
4579 | -- | |
4580 | [source,c] | |
4581 | ---- | |
4582 | #include <lttng/tracef.h> | |
4583 | ---- | |
4584 | -- | |
4585 | ||
4586 | . In the source code of the application, use `lttng_ust_tracef()` like | |
4587 | you would use man:printf(3): | |
4588 | + | |
4589 | -- | |
4590 | [source,c] | |
4591 | ---- | |
4592 | /* ... */ | |
4593 | ||
4594 | lttng_ust_tracef("my message: %d (%s)", my_integer, my_string); | |
4595 | ||
4596 | /* ... */ | |
4597 | ---- | |
4598 | -- | |
4599 | ||
4600 | . Link your application with `liblttng-ust`: | |
4601 | + | |
4602 | -- | |
4603 | [role="term"] | |
4604 | ---- | |
4605 | $ gcc -o app app.c -llttng-ust | |
4606 | ---- | |
4607 | -- | |
4608 | ||
4609 | To record the events that `lttng_ust_tracef()` calls emit: | |
4610 | ||
4611 | * <<enabling-disabling-events,Create a recording event rule>> which | |
4612 | matches user space events named `lttng_ust_tracef:*`: | |
4613 | + | |
4614 | -- | |
4615 | [role="term"] | |
4616 | ---- | |
4617 | $ lttng enable-event --userspace 'lttng_ust_tracef:*' | |
4618 | ---- | |
4619 | -- | |
4620 | ||
4621 | [IMPORTANT] | |
4622 | .Limitations of `lttng_ust_tracef()` | |
4623 | ==== | |
4624 | The `lttng_ust_tracef()` utility function was developed to make user | |
4625 | space tracing super simple, albeit with notable disadvantages compared | |
4626 | to <<defining-tracepoints,user-defined tracepoints>>: | |
4627 | ||
4628 | * All the created events have the same tracepoint provider and | |
4629 | tracepoint names, respectively `lttng_ust_tracef` and `event`. | |
4630 | * There's no static type checking. | |
4631 | * The only event record field you actually get, named `msg`, is a string | |
4632 | potentially containing the values you passed to `lttng_ust_tracef()` | |
4633 | using your own format string. This also means that you can't filter | |
4634 | events with a custom expression at run time because there are no | |
4635 | isolated fields. | |
4636 | * Since `lttng_ust_tracef()` uses the man:vasprintf(3) function of the | |
4637 | C{nbsp}standard library behind the scenes to format the strings at run | |
4638 | time, its expected performance is lower than with user-defined | |
4639 | tracepoints, which don't require a conversion to a string. | |
4640 | ||
4641 | Taking this into consideration, `lttng_ust_tracef()` is useful for some | |
4642 | quick prototyping and debugging, but you shouldn't consider it for any | |
4643 | permanent and serious applicative instrumentation. | |
4644 | ==== | |
4645 | ||
4646 | ||
4647 | [role="since-2.7"] | |
4648 | [[tracelog]] | |
4649 | ==== Use `lttng_ust_tracelog()` | |
4650 | ||
4651 | The man:tracelog(3) API is very similar to | |
4652 | <<tracef,`lttng_ust_tracef()`>>, with the difference that it accepts an | |
4653 | additional log level parameter. | |
4654 | ||
4655 | The goal of `lttng_ust_tracelog()` is to ease the migration from logging | |
4656 | to tracing. | |
4657 | ||
4658 | To use `lttng_ust_tracelog()` in your application: | |
4659 | ||
4660 | . In the C or $$C++$$ source files where you need to use `tracelog()`, | |
4661 | include `<lttng/tracelog.h>`: | |
4662 | + | |
4663 | -- | |
4664 | [source,c] | |
4665 | ---- | |
4666 | #include <lttng/tracelog.h> | |
4667 | ---- | |
4668 | -- | |
4669 | ||
4670 | . In the source code of the application, use `lttng_ust_tracelog()` like | |
4671 | you would use man:printf(3), except for the first parameter which is | |
4672 | the log level: | |
4673 | + | |
4674 | -- | |
4675 | [source,c] | |
4676 | ---- | |
4677 | /* ... */ | |
4678 | ||
4679 | tracelog(LTTNG_UST_TRACEPOINT_LOGLEVEL_WARNING, | |
4680 | "my message: %d (%s)", my_integer, my_string); | |
4681 | ||
4682 | /* ... */ | |
4683 | ---- | |
4684 | -- | |
4685 | + | |
4686 | See man:lttng-ust(3) for a list of available log level names. | |
4687 | ||
4688 | . Link your application with `liblttng-ust`: | |
4689 | + | |
4690 | -- | |
4691 | [role="term"] | |
4692 | ---- | |
4693 | $ gcc -o app app.c -llttng-ust | |
4694 | ---- | |
4695 | -- | |
4696 | ||
4697 | To record the events that `lttng_ust_tracelog()` calls emit with a log | |
4698 | level _at least as severe as_ a specific log level: | |
4699 | ||
4700 | * <<enabling-disabling-events,Create a recording event rule>> which | |
4701 | matches user space tracepoint events named `lttng_ust_tracelog:*` and | |
4702 | with some minimum level of severity: | |
4703 | + | |
4704 | -- | |
4705 | [role="term"] | |
4706 | ---- | |
4707 | $ lttng enable-event --userspace 'lttng_ust_tracelog:*' \ | |
4708 | --loglevel=WARNING | |
4709 | ---- | |
4710 | -- | |
4711 | ||
4712 | To record the events that `lttng_ust_tracelog()` calls emit with a | |
4713 | _specific log level_: | |
4714 | ||
4715 | * Create a recording event rule which matches tracepoint events named | |
4716 | `lttng_ust_tracelog:*` and with a specific log level: | |
4717 | + | |
4718 | -- | |
4719 | [role="term"] | |
4720 | ---- | |
4721 | $ lttng enable-event --userspace 'lttng_ust_tracelog:*' \ | |
4722 | --loglevel-only=INFO | |
4723 | ---- | |
4724 | -- | |
4725 | ||
4726 | ||
4727 | [[prebuilt-ust-helpers]] | |
4728 | === Load a prebuilt user space tracing helper | |
4729 | ||
4730 | The LTTng-UST package provides a few helpers in the form of preloadable | |
4731 | shared objects which automatically instrument system functions and | |
4732 | calls. | |
4733 | ||
4734 | The helper shared objects are normally found in dir:{/usr/lib}. If you | |
4735 | built LTTng-UST <<building-from-source,from source>>, they're probably | |
4736 | located in dir:{/usr/local/lib}. | |
4737 | ||
4738 | The installed user space tracing helpers in LTTng-UST{nbsp}{revision} | |
4739 | are: | |
4740 | ||
4741 | path:{liblttng-ust-libc-wrapper.so}:: | |
4742 | path:{liblttng-ust-pthread-wrapper.so}:: | |
4743 | <<liblttng-ust-libc-pthread-wrapper,C{nbsp}standard library | |
4744 | memory and POSIX threads function tracing>>. | |
4745 | ||
4746 | path:{liblttng-ust-cyg-profile.so}:: | |
4747 | path:{liblttng-ust-cyg-profile-fast.so}:: | |
4748 | <<liblttng-ust-cyg-profile,Function entry and exit tracing>>. | |
4749 | ||
4750 | path:{liblttng-ust-dl.so}:: | |
4751 | <<liblttng-ust-dl,Dynamic linker tracing>>. | |
4752 | ||
4753 | To use a user space tracing helper with any user application: | |
4754 | ||
4755 | * Preload the helper shared object when you start the application: | |
4756 | + | |
4757 | -- | |
4758 | [role="term"] | |
4759 | ---- | |
4760 | $ LD_PRELOAD=liblttng-ust-libc-wrapper.so my-app | |
4761 | ---- | |
4762 | -- | |
4763 | + | |
4764 | You can preload more than one helper: | |
4765 | + | |
4766 | -- | |
4767 | [role="term"] | |
4768 | ---- | |
4769 | $ LD_PRELOAD=liblttng-ust-libc-wrapper.so:liblttng-ust-dl.so my-app | |
4770 | ---- | |
4771 | -- | |
4772 | ||
4773 | ||
4774 | [role="since-2.3"] | |
4775 | [[liblttng-ust-libc-pthread-wrapper]] | |
4776 | ==== Instrument C standard library memory and POSIX threads functions | |
4777 | ||
4778 | The path:{liblttng-ust-libc-wrapper.so} and | |
4779 | path:{liblttng-ust-pthread-wrapper.so} helpers | |
4780 | add instrumentation to some C standard library and POSIX | |
4781 | threads functions. | |
4782 | ||
4783 | [role="growable"] | |
4784 | .Functions instrumented by preloading path:{liblttng-ust-libc-wrapper.so}. | |
4785 | |==== | |
4786 | |TP provider name |TP name |Instrumented function | |
4787 | ||
4788 | .6+|`lttng_ust_libc` |`malloc` |man:malloc(3) | |
4789 | |`calloc` |man:calloc(3) | |
4790 | |`realloc` |man:realloc(3) | |
4791 | |`free` |man:free(3) | |
4792 | |`memalign` |man:memalign(3) | |
4793 | |`posix_memalign` |man:posix_memalign(3) | |
4794 | |==== | |
4795 | ||
4796 | [role="growable"] | |
4797 | .Functions instrumented by preloading path:{liblttng-ust-pthread-wrapper.so}. | |
4798 | |==== | |
4799 | |TP provider name |TP name |Instrumented function | |
4800 | ||
4801 | .4+|`lttng_ust_pthread` |`pthread_mutex_lock_req` |man:pthread_mutex_lock(3p) (request time) | |
4802 | |`pthread_mutex_lock_acq` |man:pthread_mutex_lock(3p) (acquire time) | |
4803 | |`pthread_mutex_trylock` |man:pthread_mutex_trylock(3p) | |
4804 | |`pthread_mutex_unlock` |man:pthread_mutex_unlock(3p) | |
4805 | |==== | |
4806 | ||
4807 | When you preload the shared object, it replaces the functions listed | |
4808 | in the previous tables by wrappers which contain tracepoints and call | |
4809 | the replaced functions. | |
4810 | ||
4811 | ||
4812 | [[liblttng-ust-cyg-profile]] | |
4813 | ==== Instrument function entry and exit | |
4814 | ||
4815 | The path:{liblttng-ust-cyg-profile*.so} helpers can add instrumentation | |
4816 | to the entry and exit points of functions. | |
4817 | ||
4818 | man:gcc(1) and man:clang(1) have an option named | |
4819 | https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html[`-finstrument-functions`] | |
4820 | which generates instrumentation calls for entry and exit to functions. | |
4821 | The LTTng-UST function tracing helpers, | |
4822 | path:{liblttng-ust-cyg-profile.so} and | |
4823 | path:{liblttng-ust-cyg-profile-fast.so}, take advantage of this feature | |
4824 | to add tracepoints to the two generated functions (which contain | |
4825 | `cyg_profile` in their names, hence the name of the helper). | |
4826 | ||
4827 | To use the LTTng-UST function tracing helper, the source files to | |
4828 | instrument must be built using the `-finstrument-functions` compiler | |
4829 | flag. | |
4830 | ||
4831 | There are two versions of the LTTng-UST function tracing helper: | |
4832 | ||
4833 | * **path:{liblttng-ust-cyg-profile-fast.so}** is a lightweight variant | |
4834 | that you should only use when it can be _guaranteed_ that the | |
4835 | complete event stream is recorded without any lost event record. | |
4836 | Any kind of duplicate information is left out. | |
4837 | + | |
4838 | Assuming no event record is lost, having only the function addresses on | |
4839 | entry is enough to create a call graph, since an event record always | |
4840 | contains the ID of the CPU that generated it. | |
4841 | + | |
4842 | Use a tool like man:addr2line(1) to convert function addresses back to | |
4843 | source file names and line numbers. | |
4844 | ||
4845 | * **path:{liblttng-ust-cyg-profile.so}** is a more robust variant | |
4846 | which also works in use cases where event records might get discarded or | |
4847 | not recorded from application startup. | |
4848 | In these cases, the trace analyzer needs more information to be | |
4849 | able to reconstruct the program flow. | |
4850 | ||
4851 | See man:lttng-ust-cyg-profile(3) to learn more about the instrumentation | |
4852 | points of this helper. | |
4853 | ||
4854 | All the tracepoints that this helper provides have the log level | |
4855 | `LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_FUNCTION` (see man:lttng-ust(3)). | |
4856 | ||
4857 | TIP: It's sometimes a good idea to limit the number of source files that | |
4858 | you compile with the `-finstrument-functions` option to prevent LTTng | |
4859 | from writing an excessive amount of trace data at run time. When using | |
4860 | man:gcc(1), use the | |
4861 | `-finstrument-functions-exclude-function-list` option to avoid | |
4862 | instrument entries and exits of specific function names. | |
4863 | ||
4864 | ||
4865 | [role="since-2.4"] | |
4866 | [[liblttng-ust-dl]] | |
4867 | ==== Instrument the dynamic linker | |
4868 | ||
4869 | The path:{liblttng-ust-dl.so} helper adds instrumentation to the | |
4870 | man:dlopen(3) and man:dlclose(3) function calls. | |
4871 | ||
4872 | See man:lttng-ust-dl(3) to learn more about the instrumentation points | |
4873 | of this helper. | |
4874 | ||
4875 | ||
4876 | [role="since-2.4"] | |
4877 | [[java-application]] | |
4878 | === Instrument a Java application | |
4879 | ||
4880 | You can instrument any Java application which uses one of the following | |
4881 | logging frameworks: | |
4882 | ||
4883 | * The https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[**`java.util.logging`**] | |
4884 | (JUL) core logging facilities. | |
4885 | ||
4886 | * https://logging.apache.org/log4j/1.2/[**Apache log4j{nbsp}1.2**], since | |
4887 | LTTng{nbsp}2.6. Note that Apache Log4j{nbsp}2 isn't supported. | |
4888 | ||
4889 | [role="img-100"] | |
4890 | .LTTng-UST Java agent imported by a Java application. | |
4891 | image::java-app.png[] | |
4892 | ||
4893 | Note that the methods described below are new in LTTng{nbsp}2.8. | |
4894 | Previous LTTng versions use another technique. | |
4895 | ||
4896 | NOTE: We use https://openjdk.java.net/[OpenJDK]{nbsp}8 for development | |
4897 | and https://ci.lttng.org/[continuous integration], thus this version is | |
4898 | directly supported. However, the LTTng-UST Java agent is also tested | |
4899 | with OpenJDK{nbsp}7. | |
4900 | ||
4901 | ||
4902 | [role="since-2.8"] | |
4903 | [[jul]] | |
4904 | ==== Use the LTTng-UST Java agent for `java.util.logging` | |
4905 | ||
4906 | To use the LTTng-UST Java agent in a Java application which uses | |
4907 | `java.util.logging` (JUL): | |
4908 | ||
4909 | . In the source code of the Java application, import the LTTng-UST log | |
4910 | handler package for `java.util.logging`: | |
4911 | + | |
4912 | -- | |
4913 | [source,java] | |
4914 | ---- | |
4915 | import org.lttng.ust.agent.jul.LttngLogHandler; | |
4916 | ---- | |
4917 | -- | |
4918 | ||
4919 | . Create an LTTng-UST `java.util.logging` log handler: | |
4920 | + | |
4921 | -- | |
4922 | [source,java] | |
4923 | ---- | |
4924 | Handler lttngUstLogHandler = new LttngLogHandler(); | |
4925 | ---- | |
4926 | -- | |
4927 | ||
4928 | . Add this handler to the `java.util.logging` loggers which should emit | |
4929 | LTTng events: | |
4930 | + | |
4931 | -- | |
4932 | [source,java] | |
4933 | ---- | |
4934 | Logger myLogger = Logger.getLogger("some-logger"); | |
4935 | ||
4936 | myLogger.addHandler(lttngUstLogHandler); | |
4937 | ---- | |
4938 | -- | |
4939 | ||
4940 | . Use `java.util.logging` log statements and configuration as usual. | |
4941 | The loggers with an attached LTTng-UST log handler can emit | |
4942 | LTTng events. | |
4943 | ||
4944 | . Before exiting the application, remove the LTTng-UST log handler from | |
4945 | the loggers attached to it and call its `close()` method: | |
4946 | + | |
4947 | -- | |
4948 | [source,java] | |
4949 | ---- | |
4950 | myLogger.removeHandler(lttngUstLogHandler); | |
4951 | lttngUstLogHandler.close(); | |
4952 | ---- | |
4953 | -- | |
4954 | + | |
4955 | This isn't strictly necessary, but it's recommended for a clean | |
4956 | disposal of the resources of the handler. | |
4957 | ||
4958 | . Include the common and JUL-specific JAR files of the LTTng-UST Java agent, | |
4959 | path:{lttng-ust-agent-common.jar} and path:{lttng-ust-agent-jul.jar}, | |
4960 | in the | |
4961 | https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class | |
4962 | path] when you build the Java application. | |
4963 | + | |
4964 | The JAR files are typically located in dir:{/usr/share/java}. | |
4965 | + | |
4966 | IMPORTANT: The LTTng-UST Java agent must be | |
4967 | <<installing-lttng,installed>> for the logging framework your | |
4968 | application uses. | |
4969 | ||
4970 | .Use the LTTng-UST Java agent for `java.util.logging`. | |
4971 | ==== | |
4972 | [source,java] | |
4973 | .path:{Test.java} | |
4974 | ---- | |
4975 | import java.io.IOException; | |
4976 | import java.util.logging.Handler; | |
4977 | import java.util.logging.Logger; | |
4978 | import org.lttng.ust.agent.jul.LttngLogHandler; | |
4979 | ||
4980 | public class Test | |
4981 | { | |
4982 | private static final int answer = 42; | |
4983 | ||
4984 | public static void main(String[] argv) throws Exception | |
4985 | { | |
4986 | // Create a logger | |
4987 | Logger logger = Logger.getLogger("jello"); | |
4988 | ||
4989 | // Create an LTTng-UST log handler | |
4990 | Handler lttngUstLogHandler = new LttngLogHandler(); | |
4991 | ||
4992 | // Add the LTTng-UST log handler to our logger | |
4993 | logger.addHandler(lttngUstLogHandler); | |
4994 | ||
4995 | // Log at will! | |
4996 | logger.info("some info"); | |
4997 | logger.warning("some warning"); | |
4998 | Thread.sleep(500); | |
4999 | logger.finer("finer information; the answer is " + answer); | |
5000 | Thread.sleep(123); | |
5001 | logger.severe("error!"); | |
5002 | ||
5003 | // Not mandatory, but cleaner | |
5004 | logger.removeHandler(lttngUstLogHandler); | |
5005 | lttngUstLogHandler.close(); | |
5006 | } | |
5007 | } | |
5008 | ---- | |
5009 | ||
5010 | Build this example: | |
5011 | ||
5012 | [role="term"] | |
5013 | ---- | |
5014 | $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java | |
5015 | ---- | |
5016 | ||
5017 | <<creating-destroying-tracing-sessions,Create a recording session>>, | |
5018 | <<enabling-disabling-events,create a recording event rule>> matching JUL | |
5019 | events named `jello`, and <<basic-tracing-session-control,start | |
5020 | recording>>: | |
5021 | ||
5022 | [role="term"] | |
5023 | ---- | |
5024 | $ lttng create | |
5025 | $ lttng enable-event --jul jello | |
5026 | $ lttng start | |
5027 | ---- | |
5028 | ||
5029 | Run the compiled class: | |
5030 | ||
5031 | [role="term"] | |
5032 | ---- | |
5033 | $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test | |
5034 | ---- | |
5035 | ||
5036 | <<basic-tracing-session-control,Stop recording>> and inspect the | |
5037 | recorded events: | |
5038 | ||
5039 | [role="term"] | |
5040 | ---- | |
5041 | $ lttng stop | |
5042 | $ lttng view | |
5043 | ---- | |
5044 | ==== | |
5045 | ||
5046 | In the resulting trace, an <<event,event record>> which a Java | |
5047 | application using `java.util.logging` generated is named | |
5048 | `lttng_jul:event` and has the following fields: | |
5049 | ||
5050 | `msg`:: | |
5051 | Log record message. | |
5052 | ||
5053 | `logger_name`:: | |
5054 | Logger name. | |
5055 | ||
5056 | `class_name`:: | |
5057 | Name of the class in which the log statement was executed. | |
5058 | ||
5059 | `method_name`:: | |
5060 | Name of the method in which the log statement was executed. | |
5061 | ||
5062 | `long_millis`:: | |
5063 | Logging time (timestamp in milliseconds). | |
5064 | ||
5065 | `int_loglevel`:: | |
5066 | Log level integer value. | |
5067 | ||
5068 | `int_threadid`:: | |
5069 | ID of the thread in which the log statement was executed. | |
5070 | ||
5071 | Use the opt:lttng-enable-event(1):--loglevel or | |
5072 | opt:lttng-enable-event(1):--loglevel-only option of the | |
5073 | man:lttng-enable-event(1) command to target a range of | |
5074 | `java.util.logging` log levels or a specific `java.util.logging` log | |
5075 | level. | |
5076 | ||
5077 | ||
5078 | [role="since-2.8"] | |
5079 | [[log4j]] | |
5080 | ==== Use the LTTng-UST Java agent for Apache log4j | |
5081 | ||
5082 | To use the LTTng-UST Java agent in a Java application which uses | |
5083 | Apache log4j{nbsp}1.2: | |
5084 | ||
5085 | . In the source code of the Java application, import the LTTng-UST log | |
5086 | appender package for Apache log4j: | |
5087 | + | |
5088 | -- | |
5089 | [source,java] | |
5090 | ---- | |
5091 | import org.lttng.ust.agent.log4j.LttngLogAppender; | |
5092 | ---- | |
5093 | -- | |
5094 | ||
5095 | . Create an LTTng-UST log4j log appender: | |
5096 | + | |
5097 | -- | |
5098 | [source,java] | |
5099 | ---- | |
5100 | Appender lttngUstLogAppender = new LttngLogAppender(); | |
5101 | ---- | |
5102 | -- | |
5103 | ||
5104 | . Add this appender to the log4j loggers which should emit LTTng events: | |
5105 | + | |
5106 | -- | |
5107 | [source,java] | |
5108 | ---- | |
5109 | Logger myLogger = Logger.getLogger("some-logger"); | |
5110 | ||
5111 | myLogger.addAppender(lttngUstLogAppender); | |
5112 | ---- | |
5113 | -- | |
5114 | ||
5115 | . Use Apache log4j log statements and configuration as usual. The | |
5116 | loggers with an attached LTTng-UST log appender can emit LTTng events. | |
5117 | ||
5118 | . Before exiting the application, remove the LTTng-UST log appender from | |
5119 | the loggers attached to it and call its `close()` method: | |
5120 | + | |
5121 | -- | |
5122 | [source,java] | |
5123 | ---- | |
5124 | myLogger.removeAppender(lttngUstLogAppender); | |
5125 | lttngUstLogAppender.close(); | |
5126 | ---- | |
5127 | -- | |
5128 | + | |
5129 | This isn't strictly necessary, but it's recommended for a clean | |
5130 | disposal of the resources of the appender. | |
5131 | ||
5132 | . Include the common and log4j-specific JAR | |
5133 | files of the LTTng-UST Java agent, path:{lttng-ust-agent-common.jar} and | |
5134 | path:{lttng-ust-agent-log4j.jar}, in the | |
5135 | https://docs.oracle.com/javase/tutorial/essential/environment/paths.html[class | |
5136 | path] when you build the Java application. | |
5137 | + | |
5138 | The JAR files are typically located in dir:{/usr/share/java}. | |
5139 | + | |
5140 | IMPORTANT: The LTTng-UST Java agent must be | |
5141 | <<installing-lttng,installed>> for the logging framework your | |
5142 | application uses. | |
5143 | ||
5144 | .Use the LTTng-UST Java agent for Apache log4j. | |
5145 | ==== | |
5146 | [source,java] | |
5147 | .path:{Test.java} | |
5148 | ---- | |
5149 | import org.apache.log4j.Appender; | |
5150 | import org.apache.log4j.Logger; | |
5151 | import org.lttng.ust.agent.log4j.LttngLogAppender; | |
5152 | ||
5153 | public class Test | |
5154 | { | |
5155 | private static final int answer = 42; | |
5156 | ||
5157 | public static void main(String[] argv) throws Exception | |
5158 | { | |
5159 | // Create a logger | |
5160 | Logger logger = Logger.getLogger("jello"); | |
5161 | ||
5162 | // Create an LTTng-UST log appender | |
5163 | Appender lttngUstLogAppender = new LttngLogAppender(); | |
5164 | ||
5165 | // Add the LTTng-UST log appender to our logger | |
5166 | logger.addAppender(lttngUstLogAppender); | |
5167 | ||
5168 | // Log at will! | |
5169 | logger.info("some info"); | |
5170 | logger.warn("some warning"); | |
5171 | Thread.sleep(500); | |
5172 | logger.debug("debug information; the answer is " + answer); | |
5173 | Thread.sleep(123); | |
5174 | logger.fatal("error!"); | |
5175 | ||
5176 | // Not mandatory, but cleaner | |
5177 | logger.removeAppender(lttngUstLogAppender); | |
5178 | lttngUstLogAppender.close(); | |
5179 | } | |
5180 | } | |
5181 | ||
5182 | ---- | |
5183 | ||
5184 | Build this example (`$LOG4JPATH` is the path to the Apache log4j JAR | |
5185 | file): | |
5186 | ||
5187 | [role="term"] | |
5188 | ---- | |
5189 | $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH Test.java | |
5190 | ---- | |
5191 | ||
5192 | <<creating-destroying-tracing-sessions,Create a recording session>>, | |
5193 | <<enabling-disabling-events,create a recording event rule>> matching | |
5194 | log4j events named `jello`, and <<basic-tracing-session-control,start | |
5195 | recording>>: | |
5196 | ||
5197 | [role="term"] | |
5198 | ---- | |
5199 | $ lttng create | |
5200 | $ lttng enable-event --log4j jello | |
5201 | $ lttng start | |
5202 | ---- | |
5203 | ||
5204 | Run the compiled class: | |
5205 | ||
5206 | [role="term"] | |
5207 | ---- | |
5208 | $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-log4j.jar:$LOG4JPATH:. Test | |
5209 | ---- | |
5210 | ||
5211 | <<basic-tracing-session-control,Stop recording>> and inspect the | |
5212 | recorded events: | |
5213 | ||
5214 | [role="term"] | |
5215 | ---- | |
5216 | $ lttng stop | |
5217 | $ lttng view | |
5218 | ---- | |
5219 | ==== | |
5220 | ||
5221 | In the resulting trace, an <<event,event record>> which a Java | |
5222 | application using log4j generated is named `lttng_log4j:event` and | |
5223 | has the following fields: | |
5224 | ||
5225 | `msg`:: | |
5226 | Log record message. | |
5227 | ||
5228 | `logger_name`:: | |
5229 | Logger name. | |
5230 | ||
5231 | `class_name`:: | |
5232 | Name of the class in which the log statement was executed. | |
5233 | ||
5234 | `method_name`:: | |
5235 | Name of the method in which the log statement was executed. | |
5236 | ||
5237 | `filename`:: | |
5238 | Name of the file in which the executed log statement is located. | |
5239 | ||
5240 | `line_number`:: | |
5241 | Line number at which the log statement was executed. | |
5242 | ||
5243 | `timestamp`:: | |
5244 | Logging timestamp. | |
5245 | ||
5246 | `int_loglevel`:: | |
5247 | Log level integer value. | |
5248 | ||
5249 | `thread_name`:: | |
5250 | Name of the Java thread in which the log statement was executed. | |
5251 | ||
5252 | Use the opt:lttng-enable-event(1):--loglevel or | |
5253 | opt:lttng-enable-event(1):--loglevel-only option of the | |
5254 | man:lttng-enable-event(1) command to target a range of Apache log4j | |
5255 | log levels or a specific log4j log level. | |
5256 | ||
5257 | ||
5258 | [role="since-2.8"] | |
5259 | [[java-application-context]] | |
5260 | ==== Provide application-specific context fields in a Java application | |
5261 | ||
5262 | A Java application-specific context field is a piece of state which | |
5263 | the Java application provides. You can <<adding-context,add>> such | |
5264 | a context field to be recorded, using the | |
5265 | man:lttng-add-context(1) command, to each <<event,event record>> | |
5266 | which the log statements of this application produce. | |
5267 | ||
5268 | For example, a given object might have a current request ID variable. | |
5269 | You can create a context information retriever for this object and | |
5270 | assign a name to this current request ID. You can then, using the | |
5271 | man:lttng-add-context(1) command, add this context field by name so that | |
5272 | LTTng writes it to the event records of a given `java.util.logging` or | |
5273 | log4j <<channel,channel>>. | |
5274 | ||
5275 | To provide application-specific context fields in a Java application: | |
5276 | ||
5277 | . In the source code of the Java application, import the LTTng-UST | |
5278 | Java agent context classes and interfaces: | |
5279 | + | |
5280 | -- | |
5281 | [source,java] | |
5282 | ---- | |
5283 | import org.lttng.ust.agent.context.ContextInfoManager; | |
5284 | import org.lttng.ust.agent.context.IContextInfoRetriever; | |
5285 | ---- | |
5286 | -- | |
5287 | ||
5288 | . Create a context information retriever class, that is, a class which | |
5289 | implements the `IContextInfoRetriever` interface: | |
5290 | + | |
5291 | -- | |
5292 | [source,java] | |
5293 | ---- | |
5294 | class MyContextInfoRetriever implements IContextInfoRetriever | |
5295 | { | |
5296 | @Override | |
5297 | public Object retrieveContextInfo(String key) | |
5298 | { | |
5299 | if (key.equals("intCtx")) { | |
5300 | return (short) 17; | |
5301 | } else if (key.equals("strContext")) { | |
5302 | return "context value!"; | |
5303 | } else { | |
5304 | return null; | |
5305 | } | |
5306 | } | |
5307 | } | |
5308 | ---- | |
5309 | -- | |
5310 | + | |
5311 | This `retrieveContextInfo()` method is the only member of the | |
5312 | `IContextInfoRetriever` interface. Its role is to return the current | |
5313 | value of a state by name to create a context field. The names of the | |
5314 | context fields and which state variables they return depends on your | |
5315 | specific scenario. | |
5316 | + | |
5317 | All primitive types and objects are supported as context fields. | |
5318 | When `retrieveContextInfo()` returns an object, the context field | |
5319 | serializer calls its `toString()` method to add a string field to | |
5320 | event records. The method can also return `null`, which means that | |
5321 | no context field is available for the required name. | |
5322 | ||
5323 | . Register an instance of your context information retriever class to | |
5324 | the context information manager singleton: | |
5325 | + | |
5326 | -- | |
5327 | [source,java] | |
5328 | ---- | |
5329 | IContextInfoRetriever cir = new MyContextInfoRetriever(); | |
5330 | ContextInfoManager cim = ContextInfoManager.getInstance(); | |
5331 | cim.registerContextInfoRetriever("retrieverName", cir); | |
5332 | ---- | |
5333 | -- | |
5334 | ||
5335 | . Before exiting the application, remove your context information | |
5336 | retriever from the context information manager singleton: | |
5337 | + | |
5338 | -- | |
5339 | [source,java] | |
5340 | ---- | |
5341 | ContextInfoManager cim = ContextInfoManager.getInstance(); | |
5342 | cim.unregisterContextInfoRetriever("retrieverName"); | |
5343 | ---- | |
5344 | -- | |
5345 | + | |
5346 | This isn't strictly necessary, but it's recommended for a clean | |
5347 | disposal of some resources of the manager. | |
5348 | ||
5349 | . Build your Java application with LTTng-UST Java agent support as | |
5350 | usual, following the procedure for either the | |
5351 | <<jul,`java.util.logging`>> or <<log4j,Apache log4j>> framework. | |
5352 | ||
5353 | .Provide application-specific context fields in a Java application. | |
5354 | ==== | |
5355 | [source,java] | |
5356 | .path:{Test.java} | |
5357 | ---- | |
5358 | import java.util.logging.Handler; | |
5359 | import java.util.logging.Logger; | |
5360 | import org.lttng.ust.agent.jul.LttngLogHandler; | |
5361 | import org.lttng.ust.agent.context.ContextInfoManager; | |
5362 | import org.lttng.ust.agent.context.IContextInfoRetriever; | |
5363 | ||
5364 | public class Test | |
5365 | { | |
5366 | // Our context information retriever class | |
5367 | private static class MyContextInfoRetriever | |
5368 | implements IContextInfoRetriever | |
5369 | { | |
5370 | @Override | |
5371 | public Object retrieveContextInfo(String key) { | |
5372 | if (key.equals("intCtx")) { | |
5373 | return (short) 17; | |
5374 | } else if (key.equals("strContext")) { | |
5375 | return "context value!"; | |
5376 | } else { | |
5377 | return null; | |
5378 | } | |
5379 | } | |
5380 | } | |
5381 | ||
5382 | private static final int answer = 42; | |
5383 | ||
5384 | public static void main(String args[]) throws Exception | |
5385 | { | |
5386 | // Get the context information manager instance | |
5387 | ContextInfoManager cim = ContextInfoManager.getInstance(); | |
5388 | ||
5389 | // Create and register our context information retriever | |
5390 | IContextInfoRetriever cir = new MyContextInfoRetriever(); | |
5391 | cim.registerContextInfoRetriever("myRetriever", cir); | |
5392 | ||
5393 | // Create a logger | |
5394 | Logger logger = Logger.getLogger("jello"); | |
5395 | ||
5396 | // Create an LTTng-UST log handler | |
5397 | Handler lttngUstLogHandler = new LttngLogHandler(); | |
5398 | ||
5399 | // Add the LTTng-UST log handler to our logger | |
5400 | logger.addHandler(lttngUstLogHandler); | |
5401 | ||
5402 | // Log at will! | |
5403 | logger.info("some info"); | |
5404 | logger.warning("some warning"); | |
5405 | Thread.sleep(500); | |
5406 | logger.finer("finer information; the answer is " + answer); | |
5407 | Thread.sleep(123); | |
5408 | logger.severe("error!"); | |
5409 | ||
5410 | // Not mandatory, but cleaner | |
5411 | logger.removeHandler(lttngUstLogHandler); | |
5412 | lttngUstLogHandler.close(); | |
5413 | cim.unregisterContextInfoRetriever("myRetriever"); | |
5414 | } | |
5415 | } | |
5416 | ---- | |
5417 | ||
5418 | Build this example: | |
5419 | ||
5420 | [role="term"] | |
5421 | ---- | |
5422 | $ javac -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar Test.java | |
5423 | ---- | |
5424 | ||
5425 | <<creating-destroying-tracing-sessions,Create a recording session>> and | |
5426 | <<enabling-disabling-events,create a recording event rule>> matching | |
5427 | `java.util.logging` events named `jello`: | |
5428 | ||
5429 | [role="term"] | |
5430 | ---- | |
5431 | $ lttng create | |
5432 | $ lttng enable-event --jul jello | |
5433 | ---- | |
5434 | ||
5435 | <<adding-context,Add the application-specific context fields>> to be | |
5436 | recorded to the event records of the `java.util.logging` channel: | |
5437 | ||
5438 | [role="term"] | |
5439 | ---- | |
5440 | $ lttng add-context --jul --type='$app.myRetriever:intCtx' | |
5441 | $ lttng add-context --jul --type='$app.myRetriever:strContext' | |
5442 | ---- | |
5443 | ||
5444 | <<basic-tracing-session-control,Start recording>>: | |
5445 | ||
5446 | [role="term"] | |
5447 | ---- | |
5448 | $ lttng start | |
5449 | ---- | |
5450 | ||
5451 | Run the compiled class: | |
5452 | ||
5453 | [role="term"] | |
5454 | ---- | |
5455 | $ java -cp /usr/share/java/jarpath/lttng-ust-agent-common.jar:/usr/share/java/jarpath/lttng-ust-agent-jul.jar:. Test | |
5456 | ---- | |
5457 | ||
5458 | <<basic-tracing-session-control,Stop recording>> and inspect the | |
5459 | recorded events: | |
5460 | ||
5461 | [role="term"] | |
5462 | ---- | |
5463 | $ lttng stop | |
5464 | $ lttng view | |
5465 | ---- | |
5466 | ==== | |
5467 | ||
5468 | ||
5469 | [role="since-2.7"] | |
5470 | [[python-application]] | |
5471 | === Instrument a Python application | |
5472 | ||
5473 | You can instrument a Python{nbsp}2 or Python{nbsp}3 application which | |
5474 | uses the standard | |
5475 | https://docs.python.org/3/library/logging.html[`logging`] package. | |
5476 | ||
5477 | Each log statement creates an LTTng event once the application module | |
5478 | imports the <<lttng-ust-agents,LTTng-UST Python agent>> package. | |
5479 | ||
5480 | [role="img-100"] | |
5481 | .A Python application importing the LTTng-UST Python agent. | |
5482 | image::python-app.png[] | |
5483 | ||
5484 | To use the LTTng-UST Python agent: | |
5485 | ||
5486 | . In the source code of the Python application, import the LTTng-UST | |
5487 | Python agent: | |
5488 | + | |
5489 | -- | |
5490 | [source,python] | |
5491 | ---- | |
5492 | import lttngust | |
5493 | ---- | |
5494 | -- | |
5495 | + | |
5496 | The LTTng-UST Python agent automatically adds its logging handler to the | |
5497 | root logger at import time. | |
5498 | + | |
5499 | A log statement that the application executes before this import doesn't | |
5500 | create an LTTng event. | |
5501 | + | |
5502 | IMPORTANT: The LTTng-UST Python agent must be | |
5503 | <<installing-lttng,installed>>. | |
5504 | ||
5505 | . Use log statements and logging configuration as usual. | |
5506 | Since the LTTng-UST Python agent adds a handler to the _root_ | |
5507 | logger, any log statement from any logger can emit an LTTng event. | |
5508 | ||
5509 | .Use the LTTng-UST Python agent. | |
5510 | ==== | |
5511 | [source,python] | |
5512 | .path:{test.py} | |
5513 | ---- | |
5514 | import lttngust | |
5515 | import logging | |
5516 | import time | |
5517 | ||
5518 | ||
5519 | def example(): | |
5520 | logging.basicConfig() | |
5521 | logger = logging.getLogger('my-logger') | |
5522 | ||
5523 | while True: | |
5524 | logger.debug('debug message') | |
5525 | logger.info('info message') | |
5526 | logger.warn('warn message') | |
5527 | logger.error('error message') | |
5528 | logger.critical('critical message') | |
5529 | time.sleep(1) | |
5530 | ||
5531 | ||
5532 | if __name__ == '__main__': | |
5533 | example() | |
5534 | ---- | |
5535 | ||
5536 | NOTE: `logging.basicConfig()`, which adds to the root logger a basic | |
5537 | logging handler which prints to the standard error stream, isn't | |
5538 | strictly required for LTTng-UST tracing to work, but in versions of | |
5539 | Python preceding{nbsp}3.2, you could see a warning message which | |
5540 | indicates that no handler exists for the logger `my-logger`. | |
5541 | ||
5542 | <<creating-destroying-tracing-sessions,Create a recording session>>, | |
5543 | <<enabling-disabling-events,create a recording event rule>> matching | |
5544 | Python logging events named `my-logger`, and | |
5545 | <<basic-tracing-session-control,start recording>>: | |
5546 | ||
5547 | [role="term"] | |
5548 | ---- | |
5549 | $ lttng create | |
5550 | $ lttng enable-event --python my-logger | |
5551 | $ lttng start | |
5552 | ---- | |
5553 | ||
5554 | Run the Python script: | |
5555 | ||
5556 | [role="term"] | |
5557 | ---- | |
5558 | $ python test.py | |
5559 | ---- | |
5560 | ||
5561 | <<basic-tracing-session-control,Stop recording>> and inspect the | |
5562 | recorded events: | |
5563 | ||
5564 | [role="term"] | |
5565 | ---- | |
5566 | $ lttng stop | |
5567 | $ lttng view | |
5568 | ---- | |
5569 | ==== | |
5570 | ||
5571 | In the resulting trace, an <<event,event record>> which a Python | |
5572 | application generated is named `lttng_python:event` and has the | |
5573 | following fields: | |
5574 | ||
5575 | `asctime`:: | |
5576 | Logging time (string). | |
5577 | ||
5578 | `msg`:: | |
5579 | Log record message. | |
5580 | ||
5581 | `logger_name`:: | |
5582 | Logger name. | |
5583 | ||
5584 | `funcName`:: | |
5585 | Name of the function in which the log statement was executed. | |
5586 | ||
5587 | `lineno`:: | |
5588 | Line number at which the log statement was executed. | |
5589 | ||
5590 | `int_loglevel`:: | |
5591 | Log level integer value. | |
5592 | ||
5593 | `thread`:: | |
5594 | ID of the Python thread in which the log statement was executed. | |
5595 | ||
5596 | `threadName`:: | |
5597 | Name of the Python thread in which the log statement was executed. | |
5598 | ||
5599 | Use the opt:lttng-enable-event(1):--loglevel or | |
5600 | opt:lttng-enable-event(1):--loglevel-only option of the | |
5601 | man:lttng-enable-event(1) command to target a range of Python log levels | |
5602 | or a specific Python log level. | |
5603 | ||
5604 | When an application imports the LTTng-UST Python agent, the agent tries | |
5605 | to register to a <<lttng-sessiond,session daemon>>. Note that you must | |
5606 | <<start-sessiond,start the session daemon>> _before_ you run the Python | |
5607 | application. If a session daemon is found, the agent tries to register | |
5608 | to it during five seconds, after which the application continues | |
5609 | without LTTng tracing support. Override this timeout value with | |
5610 | the env:LTTNG_UST_PYTHON_REGISTER_TIMEOUT environment variable | |
5611 | (milliseconds). | |
5612 | ||
5613 | If the session daemon stops while a Python application with an imported | |
5614 | LTTng-UST Python agent runs, the agent retries to connect and to | |
5615 | register to a session daemon every three seconds. Override this | |
5616 | delay with the env:LTTNG_UST_PYTHON_REGISTER_RETRY_DELAY environment | |
5617 | variable. | |
5618 | ||
5619 | ||
5620 | [role="since-2.5"] | |
5621 | [[proc-lttng-logger-abi]] | |
5622 | === Use the LTTng logger | |
5623 | ||
5624 | The `lttng-tracer` Linux kernel module, part of | |
5625 | <<lttng-modules,LTTng-modules>>, creates the special LTTng logger files | |
5626 | path:{/proc/lttng-logger} and path:{/dev/lttng-logger} (since | |
5627 | LTTng{nbsp}2.11) when it's loaded. Any application can write text data | |
5628 | to any of those files to create one or more LTTng events. | |
5629 | ||
5630 | [role="img-100"] | |
5631 | .An application writes to the LTTng logger file to create one or more LTTng events. | |
5632 | image::lttng-logger.png[] | |
5633 | ||
5634 | The LTTng logger is the quickest method--not the most efficient, | |
5635 | however--to add instrumentation to an application. It's designed | |
5636 | mostly to instrument shell scripts: | |
5637 | ||
5638 | [role="term"] | |
5639 | ---- | |
5640 | $ echo "Some message, some $variable" > /dev/lttng-logger | |
5641 | ---- | |
5642 | ||
5643 | Any event that the LTTng logger creates is named `lttng_logger` and | |
5644 | belongs to the Linux kernel <<domain,tracing domain>>. However, unlike | |
5645 | other instrumentation points in the kernel tracing domain, **any Unix | |
5646 | user** can <<enabling-disabling-events,create a recording event rule>> | |
5647 | which matches events named `lttng_logger`, not only the root user or | |
5648 | users in the <<tracing-group,tracing group>>. | |
5649 | ||
5650 | To use the LTTng logger: | |
5651 | ||
5652 | * From any application, write text data to the path:{/dev/lttng-logger} | |
5653 | file. | |
5654 | ||
5655 | The `msg` field of `lttng_logger` event records contains the | |
5656 | recorded message. | |
5657 | ||
5658 | NOTE: The maximum message length of an LTTng logger event is | |
5659 | 1024{nbsp}bytes. Writing more than this makes the LTTng logger emit more | |
5660 | than one event to contain the remaining data. | |
5661 | ||
5662 | You shouldn't use the LTTng logger to trace a user application which you | |
5663 | can instrument in a more efficient way, namely: | |
5664 | ||
5665 | * <<c-application,C and $$C++$$ applications>>. | |
5666 | * <<java-application,Java applications>>. | |
5667 | * <<python-application,Python applications>>. | |
5668 | ||
5669 | .Use the LTTng logger. | |
5670 | ==== | |
5671 | [source,bash] | |
5672 | .path:{test.bash} | |
5673 | ---- | |
5674 | echo 'Hello, World!' > /dev/lttng-logger | |
5675 | sleep 2 | |
5676 | df --human-readable --print-type / > /dev/lttng-logger | |
5677 | ---- | |
5678 | ||
5679 | <<creating-destroying-tracing-sessions,Create a recording session>>, | |
5680 | <<enabling-disabling-events,create a recording event rule>> matching | |
5681 | Linux kernel tracepoint events named `lttng_logger`, and | |
5682 | <<basic-tracing-session-control,start recording>>: | |
5683 | ||
5684 | [role="term"] | |
5685 | ---- | |
5686 | $ lttng create | |
5687 | $ lttng enable-event --kernel lttng_logger | |
5688 | $ lttng start | |
5689 | ---- | |
5690 | ||
5691 | Run the Bash script: | |
5692 | ||
5693 | [role="term"] | |
5694 | ---- | |
5695 | $ bash test.bash | |
5696 | ---- | |
5697 | ||
5698 | <<basic-tracing-session-control,Stop recording>> and inspect the recorded | |
5699 | events: | |
5700 | ||
5701 | [role="term"] | |
5702 | ---- | |
5703 | $ lttng stop | |
5704 | $ lttng view | |
5705 | ---- | |
5706 | ==== | |
5707 | ||
5708 | ||
5709 | [[instrumenting-linux-kernel]] | |
5710 | === Instrument a Linux kernel image or module | |
5711 | ||
5712 | NOTE: This section shows how to _add_ instrumentation points to the | |
5713 | Linux kernel. The subsystems of the kernel are already thoroughly | |
5714 | instrumented at strategic points for LTTng when you | |
5715 | <<installing-lttng,install>> the <<lttng-modules,LTTng-modules>> | |
5716 | package. | |
5717 | ||
5718 | ||
5719 | [[linux-add-lttng-layer]] | |
5720 | ==== [[instrumenting-linux-kernel-itself]][[mainline-trace-event]][[lttng-adaptation-layer]]Add an LTTng layer to an existing ftrace tracepoint | |
5721 | ||
5722 | This section shows how to add an LTTng layer to existing ftrace | |
5723 | instrumentation using the `TRACE_EVENT()` API. | |
5724 | ||
5725 | This section doesn't document the `TRACE_EVENT()` macro. Read the | |
5726 | following articles to learn more about this API: | |
5727 | ||
5728 | * https://lwn.net/Articles/379903/[Using the TRACE_EVENT() macro (Part{nbsp}1)] | |
5729 | * https://lwn.net/Articles/381064/[Using the TRACE_EVENT() macro (Part{nbsp}2)] | |
5730 | * https://lwn.net/Articles/383362/[Using the TRACE_EVENT() macro (Part{nbsp}3)] | |
5731 | ||
5732 | The following procedure assumes that your ftrace tracepoints are | |
5733 | correctly defined in their own header and that they're created in | |
5734 | one source file using the `CREATE_TRACE_POINTS` definition. | |
5735 | ||
5736 | To add an LTTng layer over an existing ftrace tracepoint: | |
5737 | ||
5738 | . Make sure the following kernel configuration options are | |
5739 | enabled: | |
5740 | + | |
5741 | -- | |
5742 | * `CONFIG_MODULES` | |
5743 | * `CONFIG_KALLSYMS` | |
5744 | * `CONFIG_HIGH_RES_TIMERS` | |
5745 | * `CONFIG_TRACEPOINTS` | |
5746 | -- | |
5747 | ||
5748 | . Build the Linux source tree with your custom ftrace tracepoints. | |
5749 | . Boot the resulting Linux image on your target system. | |
5750 | + | |
5751 | Confirm that the tracepoints exist by looking for their names in the | |
5752 | dir:{/sys/kernel/debug/tracing/events/subsys} directory, where `subsys` | |
5753 | is your subsystem name. | |
5754 | ||
5755 | . Get a copy of the latest LTTng-modules{nbsp}{revision}: | |
5756 | + | |
5757 | -- | |
5758 | [role="term"] | |
5759 | ---- | |
5760 | $ cd $(mktemp -d) && | |
5761 | wget https://lttng.org/files/lttng-modules/lttng-modules-latest-2.13.tar.bz2 && | |
5762 | tar -xf lttng-modules-latest-2.13.tar.bz2 && | |
5763 | cd lttng-modules-2.13.* | |
5764 | ---- | |
5765 | -- | |
5766 | ||
5767 | . In dir:{instrumentation/events/lttng-module}, relative to the root | |
5768 | of the LTTng-modules source tree, create a header file named | |
5769 | +__subsys__.h+ for your custom subsystem +__subsys__+ and write your | |
5770 | LTTng-modules tracepoint definitions using the LTTng-modules | |
5771 | macros in it. | |
5772 | + | |
5773 | Start with this template: | |
5774 | + | |
5775 | -- | |
5776 | [source,c] | |
5777 | .path:{instrumentation/events/lttng-module/my_subsys.h} | |
5778 | ---- | |
5779 | #undef TRACE_SYSTEM | |
5780 | #define TRACE_SYSTEM my_subsys | |
5781 | ||
5782 | #if !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ) | |
5783 | #define _LTTNG_MY_SUBSYS_H | |
5784 | ||
5785 | #include "../../../probes/lttng-tracepoint-event.h" | |
5786 | #include <linux/tracepoint.h> | |
5787 | ||
5788 | LTTNG_TRACEPOINT_EVENT( | |
5789 | /* | |
5790 | * Format is identical to the TRACE_EVENT() version for the three | |
5791 | * following macro parameters: | |
5792 | */ | |
5793 | my_subsys_my_event, | |
5794 | TP_PROTO(int my_int, const char *my_string), | |
5795 | TP_ARGS(my_int, my_string), | |
5796 | ||
5797 | /* LTTng-modules specific macros */ | |
5798 | TP_FIELDS( | |
5799 | ctf_integer(int, my_int_field, my_int) | |
5800 | ctf_string(my_bar_field, my_bar) | |
5801 | ) | |
5802 | ) | |
5803 | ||
5804 | #endif /* !defined(_LTTNG_MY_SUBSYS_H) || defined(TRACE_HEADER_MULTI_READ) */ | |
5805 | ||
5806 | #include "../../../probes/define_trace.h" | |
5807 | ---- | |
5808 | -- | |
5809 | + | |
5810 | The entries in the `TP_FIELDS()` section are the list of fields for the | |
5811 | LTTng tracepoint. This is similar to the `TP_STRUCT__entry()` part of | |
5812 | the `TRACE_EVENT()` ftrace macro. | |
5813 | + | |
5814 | See ``<<lttng-modules-tp-fields,Tracepoint fields macros>>'' for a | |
5815 | complete description of the available `ctf_*()` macros. | |
5816 | ||
5817 | . Create the kernel module C{nbsp}source file of the LTTng-modules | |
5818 | probe, +probes/lttng-probe-__subsys__.c+, where +__subsys__+ is your | |
5819 | subsystem name: | |
5820 | + | |
5821 | -- | |
5822 | [source,c] | |
5823 | .path:{probes/lttng-probe-my-subsys.c} | |
5824 | ---- | |
5825 | #include <linux/module.h> | |
5826 | #include "../lttng-tracer.h" | |
5827 | ||
5828 | /* | |
5829 | * Build-time verification of mismatch between mainline | |
5830 | * TRACE_EVENT() arguments and the LTTng-modules adaptation | |
5831 | * layer LTTNG_TRACEPOINT_EVENT() arguments. | |
5832 | */ | |
5833 | #include <trace/events/my_subsys.h> | |
5834 | ||
5835 | /* Create LTTng tracepoint probes */ | |
5836 | #define LTTNG_PACKAGE_BUILD | |
5837 | #define CREATE_TRACE_POINTS | |
5838 | #define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module | |
5839 | ||
5840 | #include "../instrumentation/events/lttng-module/my_subsys.h" | |
5841 | ||
5842 | MODULE_LICENSE("GPL and additional rights"); | |
5843 | MODULE_AUTHOR("Your name <your-email>"); | |
5844 | MODULE_DESCRIPTION("LTTng my_subsys probes"); | |
5845 | MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "." | |
5846 | __stringify(LTTNG_MODULES_MINOR_VERSION) "." | |
5847 | __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION) | |
5848 | LTTNG_MODULES_EXTRAVERSION); | |
5849 | ---- | |
5850 | -- | |
5851 | ||
5852 | . Edit path:{probes/KBuild} and add your new kernel module object | |
5853 | next to the existing ones: | |
5854 | + | |
5855 | -- | |
5856 | [source,make] | |
5857 | .path:{probes/KBuild} | |
5858 | ---- | |
5859 | # ... | |
5860 | ||
5861 | obj-m += lttng-probe-module.o | |
5862 | obj-m += lttng-probe-power.o | |
5863 | ||
5864 | obj-m += lttng-probe-my-subsys.o | |
5865 | ||
5866 | # ... | |
5867 | ---- | |
5868 | -- | |
5869 | ||
5870 | . Build and install the LTTng kernel modules: | |
5871 | + | |
5872 | -- | |
5873 | [role="term"] | |
5874 | ---- | |
5875 | $ make KERNELDIR=/path/to/linux | |
5876 | # make modules_install && depmod -a | |
5877 | ---- | |
5878 | -- | |
5879 | + | |
5880 | Replace `/path/to/linux` with the path to the Linux source tree where | |
5881 | you defined and used tracepoints with the `TRACE_EVENT()` ftrace macro. | |
5882 | ||
5883 | Note that you can also use the | |
5884 | <<lttng-tracepoint-event-code,`LTTNG_TRACEPOINT_EVENT_CODE()` macro>> | |
5885 | instead of `LTTNG_TRACEPOINT_EVENT()` to use custom local variables and | |
5886 | C{nbsp}code that need to be executed before LTTng records the event | |
5887 | fields. | |
5888 | ||
5889 | The best way to learn how to use the previous LTTng-modules macros is to | |
5890 | inspect the existing LTTng-modules tracepoint definitions in the | |
5891 | dir:{instrumentation/events/lttng-module} header files. Compare them | |
5892 | with the Linux kernel mainline versions in the | |
5893 | dir:{include/trace/events} directory of the Linux source tree. | |
5894 | ||
5895 | ||
5896 | [role="since-2.7"] | |
5897 | [[lttng-tracepoint-event-code]] | |
5898 | ===== Use custom C code to access the data for tracepoint fields | |
5899 | ||
5900 | Although we recommended to always use the | |
5901 | <<lttng-adaptation-layer,`LTTNG_TRACEPOINT_EVENT()`>> macro to describe | |
5902 | the arguments and fields of an LTTng-modules tracepoint when possible, | |
5903 | sometimes you need a more complex process to access the data that the | |
5904 | tracer records as event record fields. In other words, you need local | |
5905 | variables and multiple C{nbsp}statements instead of simple | |
5906 | argument-based expressions that you pass to the | |
5907 | <<lttng-modules-tp-fields,`ctf_*()` macros of `TP_FIELDS()`>>. | |
5908 | ||
5909 | Use the `LTTNG_TRACEPOINT_EVENT_CODE()` macro instead of | |
5910 | `LTTNG_TRACEPOINT_EVENT()` to declare custom local variables and define | |
5911 | a block of C{nbsp}code to be executed before LTTng records the fields. | |
5912 | The structure of this macro is: | |
5913 | ||
5914 | [source,c] | |
5915 | .`LTTNG_TRACEPOINT_EVENT_CODE()` macro syntax. | |
5916 | ---- | |
5917 | LTTNG_TRACEPOINT_EVENT_CODE( | |
5918 | /* | |
5919 | * Format identical to the LTTNG_TRACEPOINT_EVENT() | |
5920 | * version for the following three macro parameters: | |
5921 | */ | |
5922 | my_subsys_my_event, | |
5923 | TP_PROTO(int my_int, const char *my_string), | |
5924 | TP_ARGS(my_int, my_string), | |
5925 | ||
5926 | /* Declarations of custom local variables */ | |
5927 | TP_locvar( | |
5928 | int a = 0; | |
5929 | unsigned long b = 0; | |
5930 | const char *name = "(undefined)"; | |
5931 | struct my_struct *my_struct; | |
5932 | ), | |
5933 | ||
5934 | /* | |
5935 | * Custom code which uses both tracepoint arguments | |
5936 | * (in TP_ARGS()) and local variables (in TP_locvar()). | |
5937 | * | |
5938 | * Local variables are actually members of a structure pointed | |
5939 | * to by the special variable tp_locvar. | |
5940 | */ | |
5941 | TP_code( | |
5942 | if (my_int) { | |
5943 | tp_locvar->a = my_int + 17; | |
5944 | tp_locvar->my_struct = get_my_struct_at(tp_locvar->a); | |
5945 | tp_locvar->b = my_struct_compute_b(tp_locvar->my_struct); | |
5946 | tp_locvar->name = my_struct_get_name(tp_locvar->my_struct); | |
5947 | put_my_struct(tp_locvar->my_struct); | |
5948 | ||
5949 | if (tp_locvar->b) { | |
5950 | tp_locvar->a = 1; | |
5951 | } | |
5952 | } | |
5953 | ), | |
5954 | ||
5955 | /* | |
5956 | * Format identical to the LTTNG_TRACEPOINT_EVENT() | |
5957 | * version for this, except that tp_locvar members can be | |
5958 | * used in the argument expression parameters of | |
5959 | * the ctf_*() macros. | |
5960 | */ | |
5961 | TP_FIELDS( | |
5962 | ctf_integer(unsigned long, my_struct_b, tp_locvar->b) | |
5963 | ctf_integer(int, my_struct_a, tp_locvar->a) | |
5964 | ctf_string(my_string_field, my_string) | |
5965 | ctf_string(my_struct_name, tp_locvar->name) | |
5966 | ) | |
5967 | ) | |
5968 | ---- | |
5969 | ||
5970 | IMPORTANT: The C code defined in `TP_code()` must not have any side | |
5971 | effects when executed. In particular, the code must not allocate | |
5972 | memory or get resources without deallocating this memory or putting | |
5973 | those resources afterwards. | |
5974 | ||
5975 | ||
5976 | [[instrumenting-linux-kernel-tracing]] | |
5977 | ==== Load and unload a custom probe kernel module | |
5978 | ||
5979 | You must load a <<lttng-adaptation-layer,created LTTng-modules probe | |
5980 | kernel module>> in the kernel before it can emit LTTng events. | |
5981 | ||
5982 | To load the default probe kernel modules and a custom probe kernel | |
5983 | module: | |
5984 | ||
5985 | * Use the opt:lttng-sessiond(8):--extra-kmod-probes option to give extra | |
5986 | probe modules to load when starting a root <<lttng-sessiond,session | |
5987 | daemon>>: | |
5988 | + | |
5989 | -- | |
5990 | .Load the `my_subsys`, `usb`, and the default probe modules. | |
5991 | ==== | |
5992 | [role="term"] | |
5993 | ---- | |
5994 | # lttng-sessiond --extra-kmod-probes=my_subsys,usb | |
5995 | ---- | |
5996 | ==== | |
5997 | -- | |
5998 | + | |
5999 | You only need to pass the subsystem name, not the whole kernel module | |
6000 | name. | |
6001 | ||
6002 | To load _only_ a given custom probe kernel module: | |
6003 | ||
6004 | * Use the opt:lttng-sessiond(8):--kmod-probes option to give the probe | |
6005 | modules to load when starting a root session daemon: | |
6006 | + | |
6007 | -- | |
6008 | .Load only the `my_subsys` and `usb` probe modules. | |
6009 | ==== | |
6010 | [role="term"] | |
6011 | ---- | |
6012 | # lttng-sessiond --kmod-probes=my_subsys,usb | |
6013 | ---- | |
6014 | ==== | |
6015 | -- | |
6016 | ||
6017 | To confirm that a probe module is loaded: | |
6018 | ||
6019 | * Use man:lsmod(8): | |
6020 | + | |
6021 | -- | |
6022 | [role="term"] | |
6023 | ---- | |
6024 | $ lsmod | grep lttng_probe_usb | |
6025 | ---- | |
6026 | -- | |
6027 | ||
6028 | To unload the loaded probe modules: | |
6029 | ||
6030 | * Kill the session daemon with `SIGTERM`: | |
6031 | + | |
6032 | -- | |
6033 | [role="term"] | |
6034 | ---- | |
6035 | # pkill lttng-sessiond | |
6036 | ---- | |
6037 | -- | |
6038 | + | |
6039 | You can also use the `--remove` option of man:modprobe(8) if the session | |
6040 | daemon terminates abnormally. | |
6041 | ||
6042 | ||
6043 | [[controlling-tracing]] | |
6044 | == Tracing control | |
6045 | ||
6046 | Once an application or a Linux kernel is <<instrumenting,instrumented>> | |
6047 | for LTTng tracing, you can _trace_ it. | |
6048 | ||
6049 | In the LTTng context, _tracing_ means making sure that LTTng attempts to | |
6050 | execute some action(s) when a CPU executes an instrumentation point. | |
6051 | ||
6052 | This section is divided in topics on how to use the various | |
6053 | <<plumbing,components of LTTng>>, in particular the | |
6054 | <<lttng-cli,cmd:lttng command-line tool>>, to _control_ the LTTng | |
6055 | daemons and tracers. | |
6056 | ||
6057 | NOTE: In the following subsections, we refer to an man:lttng(1) command | |
6058 | using its man page name. For example, instead of ``Run the `create` | |
6059 | command to'', we write ``Run the man:lttng-create(1) command to''. | |
6060 | ||
6061 | ||
6062 | [[start-sessiond]] | |
6063 | === Start a session daemon | |
6064 | ||
6065 | In some situations, you need to run a <<lttng-sessiond,session daemon>> | |
6066 | (man:lttng-sessiond(8)) _before_ you can use the man:lttng(1) | |
6067 | command-line tool. | |
6068 | ||
6069 | You will see the following error when you run a command while no session | |
6070 | daemon is running: | |
6071 | ||
6072 | ---- | |
6073 | Error: No session daemon is available | |
6074 | ---- | |
6075 | ||
6076 | The only command that automatically runs a session daemon is | |
6077 | man:lttng-create(1), which you use to | |
6078 | <<creating-destroying-tracing-sessions,create a recording session>>. While | |
6079 | this could be your most used first operation, sometimes it's not. Some | |
6080 | examples are: | |
6081 | ||
6082 | * <<list-instrumentation-points,List the available instrumentation points>>. | |
6083 | * <<saving-loading-tracing-session,Load a recording session configuration>>. | |
6084 | * <<add-event-rule-matches-trigger,Add a trigger>>. | |
6085 | ||
6086 | All the examples above don't require a recording session to operate on. | |
6087 | ||
6088 | [[tracing-group]] Each Unix user can have its own running session daemon | |
6089 | to use the user space LTTng tracer. The session daemon that the `root` | |
6090 | user starts is the only one allowed to control the LTTng kernel tracer. | |
6091 | Members of the Unix _tracing group_ may connect to and control the root | |
6092 | session daemon, even for user space tracing. See the ``Session daemon | |
6093 | connection'' section of man:lttng(1) to learn more about the Unix | |
6094 | tracing group. | |
6095 | ||
6096 | To start a user session daemon: | |
6097 | ||
6098 | * Run man:lttng-sessiond(8): | |
6099 | + | |
6100 | -- | |
6101 | [role="term"] | |
6102 | ---- | |
6103 | $ lttng-sessiond --daemonize | |
6104 | ---- | |
6105 | -- | |
6106 | ||
6107 | To start the root session daemon: | |
6108 | ||
6109 | * Run man:lttng-sessiond(8) as the `root` user: | |
6110 | + | |
6111 | -- | |
6112 | [role="term"] | |
6113 | ---- | |
6114 | # lttng-sessiond --daemonize | |
6115 | ---- | |
6116 | -- | |
6117 | ||
6118 | In both cases, remove the opt:lttng-sessiond(8):--daemonize option to | |
6119 | start the session daemon in foreground. | |
6120 | ||
6121 | To stop a session daemon, kill its process (see man:kill(1)) with the | |
6122 | standard `TERM` signal. | |
6123 | ||
6124 | Note that some Linux distributions could manage the LTTng session daemon | |
6125 | as a service. In this case, we suggest that you use the service manager | |
6126 | to start, restart, and stop session daemons. | |
6127 | ||
6128 | ||
6129 | [[creating-destroying-tracing-sessions]] | |
6130 | === Create and destroy a recording session | |
6131 | ||
6132 | Many LTTng control operations happen in the scope of a | |
6133 | <<tracing-session,recording session>>, which is the dialogue between the | |
6134 | <<lttng-sessiond,session daemon>> and you for everything related to | |
6135 | <<event,event recording>>. | |
6136 | ||
6137 | To create a recording session with a generated name: | |
6138 | ||
6139 | * Use the man:lttng-create(1) command: | |
6140 | + | |
6141 | -- | |
6142 | [role="term"] | |
6143 | ---- | |
6144 | $ lttng create | |
6145 | ---- | |
6146 | -- | |
6147 | ||
6148 | The name of the created recording session is `auto` followed by the | |
6149 | creation date. | |
6150 | ||
6151 | To create a recording session with a specific name: | |
6152 | ||
6153 | * Use the optional argument of the man:lttng-create(1) command: | |
6154 | + | |
6155 | -- | |
6156 | [role="term"] | |
6157 | ---- | |
6158 | $ lttng create SESSION | |
6159 | ---- | |
6160 | -- | |
6161 | + | |
6162 | Replace +__SESSION__+ with your specific recording session name. | |
6163 | ||
6164 | In <<local-mode,local mode>>, LTTng writes the traces of a recording | |
6165 | session to the +$LTTNG_HOME/lttng-traces/__NAME__-__DATE__-__TIME__+ | |
6166 | directory by default, where +__NAME__+ is the name of the recording | |
6167 | session. Note that the env:LTTNG_HOME environment variable defaults to | |
6168 | `$HOME` if not set. | |
6169 | ||
6170 | To output LTTng traces to a non-default location: | |
6171 | ||
6172 | * Use the opt:lttng-create(1):--output option of the man:lttng-create(1) | |
6173 | command: | |
6174 | + | |
6175 | -- | |
6176 | [role="term"] | |
6177 | ---- | |
6178 | $ lttng create my-session --output=/tmp/some-directory | |
6179 | ---- | |
6180 | -- | |
6181 | ||
6182 | You may create as many recording sessions as you wish. | |
6183 | ||
6184 | To list all the existing recording sessions for your Unix user, or for | |
6185 | all users if your Unix user is `root`: | |
6186 | ||
6187 | * Use the man:lttng-list(1) command: | |
6188 | + | |
6189 | -- | |
6190 | [role="term"] | |
6191 | ---- | |
6192 | $ lttng list | |
6193 | ---- | |
6194 | -- | |
6195 | ||
6196 | [[cur-tracing-session]]When you create a recording session, the | |
6197 | man:lttng-create(1) command sets it as the _current recording session_. | |
6198 | The following man:lttng(1) commands operate on the current recording | |
6199 | session when you don't specify one: | |
6200 | ||
6201 | [role="list-3-cols"] | |
6202 | * man:lttng-add-context(1) | |
6203 | * man:lttng-clear(1) | |
6204 | * man:lttng-destroy(1) | |
6205 | * man:lttng-disable-channel(1) | |
6206 | * man:lttng-disable-event(1) | |
6207 | * man:lttng-disable-rotation(1) | |
6208 | * man:lttng-enable-channel(1) | |
6209 | * man:lttng-enable-event(1) | |
6210 | * man:lttng-enable-rotation(1) | |
6211 | * man:lttng-load(1) | |
6212 | * man:lttng-regenerate(1) | |
6213 | * man:lttng-rotate(1) | |
6214 | * man:lttng-save(1) | |
6215 | * man:lttng-snapshot(1) | |
6216 | * man:lttng-start(1) | |
6217 | * man:lttng-status(1) | |
6218 | * man:lttng-stop(1) | |
6219 | * man:lttng-track(1) | |
6220 | * man:lttng-untrack(1) | |
6221 | * man:lttng-view(1) | |
6222 | ||
6223 | To change the current recording session: | |
6224 | ||
6225 | * Use the man:lttng-set-session(1) command: | |
6226 | + | |
6227 | -- | |
6228 | [role="term"] | |
6229 | ---- | |
6230 | $ lttng set-session SESSION | |
6231 | ---- | |
6232 | -- | |
6233 | + | |
6234 | Replace +__SESSION__+ with the name of the new current recording session. | |
6235 | ||
6236 | When you're done recording in a given recording session, destroy it. | |
6237 | This operation frees the resources taken by the recording session to | |
6238 | destroy; it doesn't destroy the trace data that LTTng wrote for this | |
6239 | recording session (see ``<<clear,Clear a recording session>>'' for one | |
6240 | way to do this). | |
6241 | ||
6242 | To destroy the current recording session: | |
6243 | ||
6244 | * Use the man:lttng-destroy(1) command: | |
6245 | + | |
6246 | -- | |
6247 | [role="term"] | |
6248 | ---- | |
6249 | $ lttng destroy | |
6250 | ---- | |
6251 | -- | |
6252 | ||
6253 | The man:lttng-destroy(1) command also runs the man:lttng-stop(1) command | |
6254 | implicitly (see ``<<basic-tracing-session-control,Start and stop a | |
6255 | recording session>>''). You need to stop recording to make LTTng flush the | |
6256 | remaining trace data and make the trace readable. | |
6257 | ||
6258 | ||
6259 | [[list-instrumentation-points]] | |
6260 | === List the available instrumentation points | |
6261 | ||
6262 | The <<lttng-sessiond,session daemon>> can query the running instrumented | |
6263 | user applications and the Linux kernel to get a list of available | |
6264 | instrumentation points: | |
6265 | ||
6266 | * LTTng tracepoints and system calls for the Linux kernel | |
6267 | <<domain,tracing domain>>. | |
6268 | ||
6269 | * LTTng tracepoints for the user space tracing domain. | |
6270 | ||
6271 | To list the available instrumentation points: | |
6272 | ||
6273 | . <<start-sessiond,Make sure>> there's a running | |
6274 | <<lttng-sessiond,session daemon>> to which your Unix user can | |
6275 | connect. | |
6276 | ||
6277 | . Use the man:lttng-list(1) command with the option of the requested | |
6278 | tracing domain amongst: | |
6279 | + | |
6280 | -- | |
6281 | opt:lttng-list(1):--kernel:: | |
6282 | Linux kernel tracepoints. | |
6283 | + | |
6284 | Your Unix user must be `root`, or it must be a member of the Unix | |
6285 | <<tracing-group,tracing group>>. | |
6286 | ||
6287 | opt:lttng-list(1):--kernel with opt:lttng-list(1):--syscall:: | |
6288 | Linux kernel system calls. | |
6289 | + | |
6290 | Your Unix user must be `root`, or it must be a member of the Unix | |
6291 | <<tracing-group,tracing group>>. | |
6292 | ||
6293 | opt:lttng-list(1):--userspace:: | |
6294 | User space tracepoints. | |
6295 | ||
6296 | opt:lttng-list(1):--jul:: | |
6297 | `java.util.logging` loggers. | |
6298 | ||
6299 | opt:lttng-list(1):--log4j:: | |
6300 | Apache log4j loggers. | |
6301 | ||
6302 | opt:lttng-list(1):--python:: | |
6303 | Python loggers. | |
6304 | -- | |
6305 | ||
6306 | .List the available user space tracepoints. | |
6307 | ==== | |
6308 | [role="term"] | |
6309 | ---- | |
6310 | $ lttng list --userspace | |
6311 | ---- | |
6312 | ==== | |
6313 | ||
6314 | .List the available Linux kernel system calls. | |
6315 | ==== | |
6316 | [role="term"] | |
6317 | ---- | |
6318 | $ lttng list --kernel --syscall | |
6319 | ---- | |
6320 | ==== | |
6321 | ||
6322 | ||
6323 | [[enabling-disabling-events]] | |
6324 | === Create and enable a recording event rule | |
6325 | ||
6326 | Once you <<creating-destroying-tracing-sessions,create a recording | |
6327 | session>>, you can create <<event,recording event rules>> with the | |
6328 | man:lttng-enable-event(1) command. | |
6329 | ||
6330 | The man:lttng-enable-event(1) command always attaches an event rule to a | |
6331 | <<channel,channel>> on creation. The command can create a _default | |
6332 | channel_, named `channel0`, for you. The man:lttng-enable-event(1) | |
6333 | command reuses the default channel each time you run it for the same | |
6334 | tracing domain and session. | |
6335 | ||
6336 | A recording event rule is always enabled at creation time. | |
6337 | ||
6338 | The following examples show how to combine the command-line arguments of | |
6339 | the man:lttng-enable-event(1) command to create simple to more complex | |
6340 | recording event rules within the <<cur-tracing-session,current recording | |
6341 | session>>. | |
6342 | ||
6343 | .Create a recording event rule matching specific Linux kernel tracepoint events (default channel). | |
6344 | ==== | |
6345 | [role="term"] | |
6346 | ---- | |
6347 | # lttng enable-event --kernel sched_switch | |
6348 | ---- | |
6349 | ==== | |
6350 | ||
6351 | .Create a recording event rule matching Linux kernel system call events with four specific names (default channel). | |
6352 | ==== | |
6353 | [role="term"] | |
6354 | ---- | |
6355 | # lttng enable-event --kernel --syscall open,write,read,close | |
6356 | ---- | |
6357 | ==== | |
6358 | ||
6359 | .Create recording event rules matching tracepoint events which satisfy a filter expressions (default channel). | |
6360 | ==== | |
6361 | [role="term"] | |
6362 | ---- | |
6363 | # lttng enable-event --kernel sched_switch --filter='prev_comm == "bash"' | |
6364 | ---- | |
6365 | ||
6366 | [role="term"] | |
6367 | ---- | |
6368 | # lttng enable-event --kernel --all \ | |
6369 | --filter='$ctx.tid == 1988 || $ctx.tid == 1534' | |
6370 | ---- | |
6371 | ||
6372 | [role="term"] | |
6373 | ---- | |
6374 | $ lttng enable-event --jul my_logger \ | |
6375 | --filter='$app.retriever:cur_msg_id > 3' | |
6376 | ---- | |
6377 | ||
6378 | IMPORTANT: Make sure to always single-quote the filter string when you | |
6379 | run man:lttng(1) from a shell. | |
6380 | ||
6381 | See also ``<<pid-tracking,Allow specific processes to record events>>'' | |
6382 | which offers another, more efficient filtering mechanism for process ID, | |
6383 | user ID, and group ID attributes. | |
6384 | ==== | |
6385 | ||
6386 | .Create a recording event rule matching any user space event from the `my_app` tracepoint provider and with a log level range (default channel). | |
6387 | ==== | |
6388 | [role="term"] | |
6389 | ---- | |
6390 | $ lttng enable-event --userspace my_app:'*' --loglevel=INFO | |
6391 | ---- | |
6392 | ||
6393 | IMPORTANT: Make sure to always single-quote the wildcard character when | |
6394 | you run man:lttng(1) from a shell. | |
6395 | ==== | |
6396 | ||
6397 | .Create a recording event rule matching user space events named specifically, but with name exclusions (default channel). | |
6398 | ==== | |
6399 | [role="term"] | |
6400 | ---- | |
6401 | $ lttng enable-event --userspace my_app:'*' \ | |
6402 | --exclude=my_app:set_user,my_app:handle_sig | |
6403 | ---- | |
6404 | ==== | |
6405 | ||
6406 | .Create a recording event rule matching any Apache log4j event with a specific log level (default channel). | |
6407 | ==== | |
6408 | [role="term"] | |
6409 | ---- | |
6410 | $ lttng enable-event --log4j --all --loglevel-only=WARN | |
6411 | ---- | |
6412 | ==== | |
6413 | ||
6414 | .Create a recording event rule, attached to a specific channel, and matching user space tracepoint events named `my_app:my_tracepoint`. | |
6415 | ==== | |
6416 | [role="term"] | |
6417 | ---- | |
6418 | $ lttng enable-event --userspace my_app:my_tracepoint \ | |
6419 | --channel=my-channel | |
6420 | ---- | |
6421 | ==== | |
6422 | ||
6423 | .Create a recording event rule matching user space probe events for the `malloc` function entry in path:{/usr/lib/libc.so.6}: | |
6424 | ==== | |
6425 | [role="term"] | |
6426 | ---- | |
6427 | # lttng enable-event --kernel \ | |
6428 | --userspace-probe=/usr/lib/libc.so.6:malloc \ | |
6429 | libc_malloc | |
6430 | ---- | |
6431 | ==== | |
6432 | ||
6433 | .Create a recording event rule matching user space probe events for the `server`/`accept_request` https://www.sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps[USDT probe] in path:{/usr/bin/serv}: | |
6434 | ==== | |
6435 | [role="term"] | |
6436 | ---- | |
6437 | # lttng enable-event --kernel \ | |
6438 | --userspace-probe=sdt:serv:server:accept_request \ | |
6439 | server_accept_request | |
6440 | ---- | |
6441 | ==== | |
6442 | ||
6443 | The recording event rules of a given channel form a whitelist: as soon | |
6444 | as an event rule matches an event, LTTng emits it _once_ and therefore | |
6445 | <<channel-overwrite-mode-vs-discard-mode,can>> record it. For example, | |
6446 | the following rules both match user space tracepoint events named | |
6447 | `my_app:my_tracepoint` with an `INFO` log level: | |
6448 | ||
6449 | [role="term"] | |
6450 | ---- | |
6451 | $ lttng enable-event --userspace my_app:my_tracepoint | |
6452 | $ lttng enable-event --userspace my_app:my_tracepoint \ | |
6453 | --loglevel=INFO | |
6454 | ---- | |
6455 | ||
6456 | The second recording event rule is redundant: the first one includes the | |
6457 | second one. | |
6458 | ||
6459 | ||
6460 | [[disable-event-rule]] | |
6461 | === Disable a recording event rule | |
6462 | ||
6463 | To disable a <<event,recording event rule>> that you | |
6464 | <<enabling-disabling-events,created>> previously, use the | |
6465 | man:lttng-disable-event(1) command. | |
6466 | ||
6467 | man:lttng-disable-event(1) can only find recording event rules to | |
6468 | disable by their <<instrumentation-point-types,instrumentation point | |
6469 | type>> and event name conditions. Therefore, you cannot disable | |
6470 | recording event rules having a specific instrumentation point log level | |
6471 | condition, for example. | |
6472 | ||
6473 | LTTng doesn't emit (and, therefore, won't record) an event which only | |
6474 | _disabled_ recording event rules match. | |
6475 | ||
6476 | .Disable event rules matching Python logging events from the `my-logger` logger (default <<channel,channel>>, <<cur-tracing-session,current recording session>>). | |
6477 | ==== | |
6478 | [role="term"] | |
6479 | ---- | |
6480 | $ lttng disable-event --python my-logger | |
6481 | ---- | |
6482 | ==== | |
6483 | ||
6484 | .Disable event rules matching all `java.util.logging` events (default channel, recording session `my-session`). | |
6485 | ==== | |
6486 | [role="term"] | |
6487 | ---- | |
6488 | $ lttng disable-event --jul --session=my-session '*' | |
6489 | ---- | |
6490 | ==== | |
6491 | ||
6492 | .Disable _all_ the Linux kernel recording event rules (channel `my-chan`, current recording session). | |
6493 | ==== | |
6494 | The opt:lttng-disable-event(1):--all-events option isn't, like the | |
6495 | opt:lttng-enable-event(1):--all option of the man:lttng-enable-event(1) | |
6496 | command, an alias for the event name globbing pattern `*`: it disables | |
6497 | _all_ the recording event rules of a given channel. | |
6498 | ||
6499 | [role="term"] | |
6500 | ---- | |
6501 | # lttng disable-event --kernel --channel=my-chan --all-events | |
6502 | ---- | |
6503 | ==== | |
6504 | ||
6505 | NOTE: You can't _remove_ a recording event rule once you create it. | |
6506 | ||
6507 | ||
6508 | [[status]] | |
6509 | === Get the status of a recording session | |
6510 | ||
6511 | To get the status of the <<cur-tracing-session,current recording | |
6512 | session>>, that is, its parameters, its channels, recording event rules, | |
6513 | and their attributes: | |
6514 | ||
6515 | * Use the man:lttng-status(1) command: | |
6516 | + | |
6517 | -- | |
6518 | [role="term"] | |
6519 | ---- | |
6520 | $ lttng status | |
6521 | ---- | |
6522 | -- | |
6523 | ||
6524 | To get the status of any recording session: | |
6525 | ||
6526 | * Use the man:lttng-list(1) command with the name of the recording | |
6527 | session: | |
6528 | + | |
6529 | -- | |
6530 | [role="term"] | |
6531 | ---- | |
6532 | $ lttng list SESSION | |
6533 | ---- | |
6534 | -- | |
6535 | + | |
6536 | Replace +__SESSION__+ with the recording session name. | |
6537 | ||
6538 | ||
6539 | [[basic-tracing-session-control]] | |
6540 | === Start and stop a recording session | |
6541 | ||
6542 | Once you <<creating-destroying-tracing-sessions,create a recording | |
6543 | session>> and <<enabling-disabling-events,create one or more recording | |
6544 | event rules>>, you can start and stop the tracers for this recording | |
6545 | session. | |
6546 | ||
6547 | To start the <<cur-tracing-session,current recording session>>: | |
6548 | ||
6549 | * Use the man:lttng-start(1) command: | |
6550 | + | |
6551 | -- | |
6552 | [role="term"] | |
6553 | ---- | |
6554 | $ lttng start | |
6555 | ---- | |
6556 | -- | |
6557 | ||
6558 | LTTng is flexible: you can launch user applications before or after you | |
6559 | start the tracers. An LTTng tracer only <<event,records an event>> if a | |
6560 | recording event rule matches it, which means the tracer is active. | |
6561 | ||
6562 | The `start-session` <<trigger,trigger>> action can also start a recording | |
6563 | session. | |
6564 | ||
6565 | To stop the current recording session: | |
6566 | ||
6567 | * Use the man:lttng-stop(1) command: | |
6568 | + | |
6569 | -- | |
6570 | [role="term"] | |
6571 | ---- | |
6572 | $ lttng stop | |
6573 | ---- | |
6574 | -- | |
6575 | + | |
6576 | If there were <<channel-overwrite-mode-vs-discard-mode,lost event | |
6577 | records>> or lost sub-buffers since the last time you ran | |
6578 | man:lttng-start(1), the man:lttng-stop(1) command prints corresponding | |
6579 | warnings. | |
6580 | ||
6581 | IMPORTANT: You need to stop recording to make LTTng flush the remaining | |
6582 | trace data and make the trace readable. Note that the | |
6583 | man:lttng-destroy(1) command (see | |
6584 | ``<<creating-destroying-tracing-sessions,Create and destroy a recording | |
6585 | session>>'') also runs the man:lttng-stop(1) command implicitly. | |
6586 | ||
6587 | The `stop-session` <<trigger,trigger>> action can also stop a recording | |
6588 | session. | |
6589 | ||
6590 | [role="since-2.12"] | |
6591 | [[clear]] | |
6592 | === Clear a recording session | |
6593 | ||
6594 | You might need to remove all the current tracing data of one or more | |
6595 | <<tracing-session,recording sessions>> between multiple attempts to | |
6596 | reproduce a problem without interrupting the LTTng recording activity. | |
6597 | ||
6598 | To clear the tracing data of the | |
6599 | <<cur-tracing-session,current recording session>>: | |
6600 | ||
6601 | * Use the man:lttng-clear(1) command: | |
6602 | + | |
6603 | -- | |
6604 | [role="term"] | |
6605 | ---- | |
6606 | $ lttng clear | |
6607 | ---- | |
6608 | -- | |
6609 | ||
6610 | To clear the tracing data of all the recording sessions: | |
6611 | ||
6612 | * Use the `lttng clear` command with its opt:lttng-clear(1):--all | |
6613 | option: | |
6614 | + | |
6615 | -- | |
6616 | [role="term"] | |
6617 | ---- | |
6618 | $ lttng clear --all | |
6619 | ---- | |
6620 | -- | |
6621 | ||
6622 | ||
6623 | [[enabling-disabling-channels]] | |
6624 | === Create a channel | |
6625 | ||
6626 | Once you <<creating-destroying-tracing-sessions,create a recording | |
6627 | session>>, you can create a <<channel,channel>> with the | |
6628 | man:lttng-enable-channel(1) command. | |
6629 | ||
6630 | Note that LTTng can automatically create a default channel when you | |
6631 | <<enabling-disabling-events,create a recording event rule>>. | |
6632 | Therefore, you only need to create a channel when you need non-default | |
6633 | attributes. | |
6634 | ||
6635 | Specify each non-default channel attribute with a command-line | |
6636 | option when you run the man:lttng-enable-channel(1) command. | |
6637 | ||
6638 | You can only create a custom channel in the Linux kernel and user space | |
6639 | <<domain,tracing domains>>: the Java/Python logging tracing domains have | |
6640 | their own default channel which LTTng automatically creates when you | |
6641 | <<enabling-disabling-events,create a recording event rule>>. | |
6642 | ||
6643 | [IMPORTANT] | |
6644 | ==== | |
6645 | As of LTTng{nbsp}{revision}, you may _not_ perform the | |
6646 | following operations with the man:lttng-enable-channel(1) command: | |
6647 | ||
6648 | * Change an attribute of an existing channel. | |
6649 | ||
6650 | * Enable a disabled channel once its recording session has been | |
6651 | <<basic-tracing-session-control,active>> at least once. | |
6652 | ||
6653 | * Create a channel once its recording session has been active at | |
6654 | least once. | |
6655 | ||
6656 | * Create a user space channel with a given | |
6657 | <<channel-buffering-schemes,buffering scheme>> and create a second | |
6658 | user space channel with a different buffering scheme in the same | |
6659 | recording session. | |
6660 | ==== | |
6661 | ||
6662 | The following examples show how to combine the command-line options of | |
6663 | the man:lttng-enable-channel(1) command to create simple to more complex | |
6664 | channels within the <<cur-tracing-session,current recording session>>. | |
6665 | ||
6666 | .Create a Linux kernel channel with default attributes. | |
6667 | ==== | |
6668 | [role="term"] | |
6669 | ---- | |
6670 | # lttng enable-channel --kernel my-channel | |
6671 | ---- | |
6672 | ==== | |
6673 | ||
6674 | .Create a user space channel with four sub-buffers or 1{nbsp}MiB each, per CPU, per instrumented process. | |
6675 | ==== | |
6676 | [role="term"] | |
6677 | ---- | |
6678 | $ lttng enable-channel --userspace --num-subbuf=4 --subbuf-size=1M \ | |
6679 | --buffers-pid my-channel | |
6680 | ---- | |
6681 | ==== | |
6682 | ||
6683 | .[[blocking-timeout-example]]Create a default user space channel with an infinite blocking timeout. | |
6684 | ==== | |
6685 | <<creating-destroying-tracing-sessions,Create a recording session>>, | |
6686 | create the channel, <<enabling-disabling-events,create a recording event | |
6687 | rule>>, and <<basic-tracing-session-control,start recording>>: | |
6688 | ||
6689 | [role="term"] | |
6690 | ---- | |
6691 | $ lttng create | |
6692 | $ lttng enable-channel --userspace --blocking-timeout=inf blocking-chan | |
6693 | $ lttng enable-event --userspace --channel=blocking-chan --all | |
6694 | $ lttng start | |
6695 | ---- | |
6696 | ||
6697 | Run an application instrumented with LTTng-UST tracepoints and allow it | |
6698 | to block: | |
6699 | ||
6700 | [role="term"] | |
6701 | ---- | |
6702 | $ LTTNG_UST_ALLOW_BLOCKING=1 my-app | |
6703 | ---- | |
6704 | ==== | |
6705 | ||
6706 | .Create a Linux kernel channel which rotates eight trace files of 4{nbsp}MiB each for each stream. | |
6707 | ==== | |
6708 | [role="term"] | |
6709 | ---- | |
6710 | # lttng enable-channel --kernel --tracefile-count=8 \ | |
6711 | --tracefile-size=4194304 my-channel | |
6712 | ---- | |
6713 | ==== | |
6714 | ||
6715 | .Create a user space channel in <<overwrite-mode,overwrite>> (or ``flight recorder'') mode. | |
6716 | ==== | |
6717 | [role="term"] | |
6718 | ---- | |
6719 | $ lttng enable-channel --userspace --overwrite my-channel | |
6720 | ---- | |
6721 | ==== | |
6722 | ||
6723 | .<<enabling-disabling-events,Create>> the same <<event,recording event rule>> attached to two different channels. | |
6724 | ==== | |
6725 | [role="term"] | |
6726 | ---- | |
6727 | $ lttng enable-event --userspace --channel=my-channel app:tp | |
6728 | $ lttng enable-event --userspace --channel=other-channel app:tp | |
6729 | ---- | |
6730 | ||
6731 | When a CPU executes the `app:tp` <<c-application,user space | |
6732 | tracepoint>>, the two recording event rules above match the created | |
6733 | event, making LTTng emit the event. Because the recording event rules | |
6734 | are not attached to the same channel, LTTng records the event twice. | |
6735 | ==== | |
6736 | ||
6737 | ||
6738 | [[disable-channel]] | |
6739 | === Disable a channel | |
6740 | ||
6741 | To disable a specific channel that you | |
6742 | <<enabling-disabling-channels,created>> previously, use the | |
6743 | man:lttng-disable-channel(1) command. | |
6744 | ||
6745 | .Disable a specific Linux kernel channel (<<cur-tracing-session,current recording session>>). | |
6746 | ==== | |
6747 | [role="term"] | |
6748 | ---- | |
6749 | # lttng disable-channel --kernel my-channel | |
6750 | ---- | |
6751 | ==== | |
6752 | ||
6753 | An enabled channel is an implicit <<event,recording event rule>> | |
6754 | condition. | |
6755 | ||
6756 | NOTE: As of LTTng{nbsp}{revision}, you may _not_ enable a disabled | |
6757 | channel once its recording session has been | |
6758 | <<basic-tracing-session-control,started>> at least once. | |
6759 | ||
6760 | ||
6761 | [[adding-context]] | |
6762 | === Add context fields to be recorded to the event records of a channel | |
6763 | ||
6764 | <<event,Event record>> fields in trace files provide important | |
6765 | information about previously emitted events, but sometimes some external | |
6766 | context may help you solve a problem faster. | |
6767 | ||
6768 | Examples of context fields are: | |
6769 | ||
6770 | * The **process ID**, **thread ID**, **process name**, and | |
6771 | **process priority** of the thread from which LTTng emits the event. | |
6772 | ||
6773 | * The **hostname** of the system on which LTTng emits the event. | |
6774 | ||
6775 | * The Linux kernel and user call stacks (since LTTng{nbsp}2.11). | |
6776 | ||
6777 | * The current values of many possible **performance counters** using | |
6778 | perf, for example: | |
6779 | ||
6780 | ** CPU cycles, stalled cycles, idle cycles, and the other cycle types. | |
6781 | ** Cache misses. | |
6782 | ** Branch instructions, misses, and loads. | |
6783 | ** CPU faults. | |
6784 | ||
6785 | * Any state defined at the application level (supported for the | |
6786 | `java.util.logging` and Apache log4j <<domain,tracing domains>>). | |
6787 | ||
6788 | To get the full list of available context fields: | |
6789 | ||
6790 | * Use the opt:lttng-add-context(1):--list option of the | |
6791 | man:lttng-add-context(1) command: | |
6792 | + | |
6793 | [role="term"] | |
6794 | ---- | |
6795 | $ lttng add-context --list | |
6796 | ---- | |
6797 | ||
6798 | .Add context fields to be recorded to the event records of all the <<channel,channels>> of the <<cur-tracing-session,current recording session>>. | |
6799 | ==== | |
6800 | The following command line adds the virtual process identifier and the | |
6801 | per-thread CPU cycles count fields to all the user space channels of the | |
6802 | current recording session. | |
6803 | ||
6804 | [role="term"] | |
6805 | ---- | |
6806 | $ lttng add-context --userspace --type=vpid --type=perf:thread:cpu-cycles | |
6807 | ---- | |
6808 | ==== | |
6809 | ||
6810 | .Add performance counter context fields by raw ID | |
6811 | ==== | |
6812 | See man:lttng-add-context(1) for the exact format of the context field | |
6813 | type, which is partly compatible with the format used in | |
6814 | man:perf-record(1). | |
6815 | ||
6816 | [role="term"] | |
6817 | ---- | |
6818 | # lttng add-context --userspace --type=perf:thread:raw:r0110:test | |
6819 | # lttng add-context --kernel --type=perf:cpu:raw:r0013c:x86unhalted | |
6820 | ---- | |
6821 | ==== | |
6822 | ||
6823 | .Add context fields to be recorded to the event records of a specific channel. | |
6824 | ==== | |
6825 | The following command line adds the thread identifier and user call | |
6826 | stack context fields to the Linux kernel channel named `my-channel` of | |
6827 | the <<cur-tracing-session,current recording session>>. | |
6828 | ||
6829 | [role="term"] | |
6830 | ---- | |
6831 | # lttng add-context --kernel --channel=my-channel \ | |
6832 | --type=tid --type=callstack-user | |
6833 | ---- | |
6834 | ==== | |
6835 | ||
6836 | .Add an <<java-application-context,application-specific context field>> to be recorded to the event records of a specific channel. | |
6837 | ==== | |
6838 | The following command line makes sure LTTng writes the `cur_msg_id` | |
6839 | context field of the `retriever` context retriever to all the Java | |
6840 | logging <<event,event records>> of the channel named `my-channel`: | |
6841 | ||
6842 | [role="term"] | |
6843 | ---- | |
6844 | # lttng add-context --kernel --channel=my-channel \ | |
6845 | --type='$app:retriever:cur_msg_id' | |
6846 | ---- | |
6847 | ||
6848 | IMPORTANT: Make sure to always single-quote the `$` character when you | |
6849 | run man:lttng-add-context(1) from a shell. | |
6850 | ==== | |
6851 | ||
6852 | NOTE: You can't undo what the man:lttng-add-context(1) command does. | |
6853 | ||
6854 | ||
6855 | [role="since-2.7"] | |
6856 | [[pid-tracking]] | |
6857 | === Allow specific processes to record events | |
6858 | ||
6859 | It's often useful to only allow processes with specific attributes to | |
6860 | record events. For example, you may wish to record all the system calls | |
6861 | which a given process makes (à la man:strace(1)). | |
6862 | ||
6863 | The man:lttng-track(1) and man:lttng-untrack(1) commands serve this | |
6864 | purpose. Both commands operate on _inclusion sets_ of process | |
6865 | attributes. The available process attribute types are: | |
6866 | ||
6867 | Linux kernel <<domain,tracing domain>>:: | |
6868 | + | |
6869 | * Process ID (PID). | |
6870 | ||
6871 | * Virtual process ID (VPID). | |
6872 | + | |
6873 | This is the PID as seen by the application. | |
6874 | ||
6875 | * Unix user ID (UID). | |
6876 | ||
6877 | * Virtual Unix user ID (VUID). | |
6878 | + | |
6879 | This is the UID as seen by the application. | |
6880 | ||
6881 | * Unix group ID (GID). | |
6882 | ||
6883 | * Virtual Unix group ID (VGID). | |
6884 | + | |
6885 | This is the GID as seen by the application. | |
6886 | ||
6887 | User space tracing domain:: | |
6888 | + | |
6889 | * VPID | |
6890 | * VUID | |
6891 | * VGID | |
6892 | ||
6893 | A <<tracing-session,recording session>> has nine process | |
6894 | attribute inclusion sets: six for the Linux kernel <<domain,tracing domain>> | |
6895 | and three for the user space tracing domain. | |
6896 | ||
6897 | For a given recording session, a process{nbsp}__P__ is allowed to record | |
6898 | LTTng events for a given <<domain,tracing domain>>{nbsp}__D__ if _all_ | |
6899 | the attributes of{nbsp}__P__ are part of the inclusion sets | |
6900 | of{nbsp}__D__. | |
6901 | ||
6902 | Whether a process is allowed or not to record LTTng events is an | |
6903 | implicit condition of all <<event,recording event rules>>. Therefore, if | |
6904 | LTTng creates an event{nbsp}__E__ for a given process, but this process | |
6905 | may not record events, then no recording event rule matches{nbsp}__E__, | |
6906 | which means LTTng won't emit and record{nbsp}__E__. | |
6907 | ||
6908 | When you <<creating-destroying-tracing-sessions,create a recording | |
6909 | session>>, all its process attribute inclusion sets contain all the | |
6910 | possible values. In other words, all processes are allowed to record | |
6911 | events. | |
6912 | ||
6913 | Add values to an inclusion set with the man:lttng-track(1) command and | |
6914 | remove values with the man:lttng-untrack(1) command. | |
6915 | ||
6916 | [NOTE] | |
6917 | ==== | |
6918 | The process attribute values are _numeric_. | |
6919 | ||
6920 | Should a process with a given ID (part of an inclusion set), for | |
6921 | example, exit, and then a new process be given this same ID, then the | |
6922 | latter would also be allowed to record events. | |
6923 | ||
6924 | With the man:lttng-track(1) command, you can add Unix user and group | |
6925 | _names_ to the user and group inclusion sets: the | |
6926 | <<lttng-sessiond,session daemon>> finds the corresponding UID, VUID, | |
6927 | GID, or VGID once on _addition_ to the inclusion set. This means that if | |
6928 | you rename the user or group after you run the man:lttng-track(1) | |
6929 | command, its user/group ID remains part of the inclusion sets. | |
6930 | ==== | |
6931 | ||
6932 | .Allow processes to record events based on their virtual process ID (VPID). | |
6933 | ==== | |
6934 | For the sake of the following example, assume the target system has | |
6935 | 16{nbsp}possible VPIDs. | |
6936 | ||
6937 | When you | |
6938 | <<creating-destroying-tracing-sessions,create a recording session>>, | |
6939 | the user space VPID inclusion set contains _all_ the possible VPIDs: | |
6940 | ||
6941 | [role="img-100"] | |
6942 | .The VPID inclusion set is full. | |
6943 | image::track-all.png[] | |
6944 | ||
6945 | When the inclusion set is full and you run the man:lttng-track(1) | |
6946 | command to specify some VPIDs, LTTng: | |
6947 | ||
6948 | . Clears the inclusion set. | |
6949 | . Adds the specific VPIDs to the inclusion set. | |
6950 | ||
6951 | After: | |
6952 | ||
6953 | [role="term"] | |
6954 | ---- | |
6955 | $ lttng track --userspace --vpid=3,4,7,10,13 | |
6956 | ---- | |
6957 | ||
6958 | the VPID inclusion set is: | |
6959 | ||
6960 | [role="img-100"] | |
6961 | .The VPID inclusion set contains the VPIDs 3, 4, 7, 10, and 13. | |
6962 | image::track-3-4-7-10-13.png[] | |
6963 | ||
6964 | Add more VPIDs to the inclusion set afterwards: | |
6965 | ||
6966 | [role="term"] | |
6967 | ---- | |
6968 | $ lttng track --userspace --vpid=1,15,16 | |
6969 | ---- | |
6970 | ||
6971 | The result is: | |
6972 | ||
6973 | [role="img-100"] | |
6974 | .VPIDs 1, 15, and 16 are added to the inclusion set. | |
6975 | image::track-1-3-4-7-10-13-15-16.png[] | |
6976 | ||
6977 | The man:lttng-untrack(1) command removes entries from process attribute | |
6978 | inclusion sets. Given the previous example, the following command: | |
6979 | ||
6980 | [role="term"] | |
6981 | ---- | |
6982 | $ lttng untrack --userspace --vpid=3,7,10,13 | |
6983 | ---- | |
6984 | ||
6985 | leads to this VPID inclusion set: | |
6986 | ||
6987 | [role="img-100"] | |
6988 | .VPIDs 3, 7, 10, and 13 are removed from the inclusion set. | |
6989 | image::track-1-4-15-16.png[] | |
6990 | ||
6991 | You can make the VPID inclusion set full again with the | |
6992 | opt:lttng-track(1):--all option: | |
6993 | ||
6994 | [role="term"] | |
6995 | ---- | |
6996 | $ lttng track --userspace --vpid --all | |
6997 | ---- | |
6998 | ||
6999 | The result is, again: | |
7000 | ||
7001 | [role="img-100"] | |
7002 | .The VPID inclusion set is full. | |
7003 | image::track-all.png[] | |
7004 | ==== | |
7005 | ||
7006 | .Allow specific processes to record events based on their user ID (UID). | |
7007 | ==== | |
7008 | A typical use case with process attribute inclusion sets is to start | |
7009 | with an empty inclusion set, then <<basic-tracing-session-control,start | |
7010 | the tracers>>, and finally add values manually while the tracers are | |
7011 | active. | |
7012 | ||
7013 | Use the opt:lttng-untrack(1):--all option of the | |
7014 | man:lttng-untrack(1) command to clear the inclusion set after you | |
7015 | <<creating-destroying-tracing-sessions,create a recording session>>, for | |
7016 | example (with UIDs): | |
7017 | ||
7018 | [role="term"] | |
7019 | ---- | |
7020 | # lttng untrack --kernel --uid --all | |
7021 | ---- | |
7022 | ||
7023 | gives: | |
7024 | ||
7025 | [role="img-100"] | |
7026 | .The UID inclusion set is empty. | |
7027 | image::untrack-all.png[] | |
7028 | ||
7029 | If the LTTng tracer runs with this inclusion set configuration, it | |
7030 | records no events within the <<cur-tracing-session,current recording | |
7031 | session>> because no processes is allowed to do so. Use the | |
7032 | man:lttng-track(1) command as usual to add specific values to the UID | |
7033 | inclusion set when you need to, for example: | |
7034 | ||
7035 | [role="term"] | |
7036 | ---- | |
7037 | # lttng track --kernel --uid=http,11 | |
7038 | ---- | |
7039 | ||
7040 | Result: | |
7041 | ||
7042 | [role="img-100"] | |
7043 | .UIDs 6 (`http`) and 11 are part of the UID inclusion set. | |
7044 | image::track-6-11.png[] | |
7045 | ==== | |
7046 | ||
7047 | ||
7048 | [role="since-2.5"] | |
7049 | [[saving-loading-tracing-session]] | |
7050 | === Save and load recording session configurations | |
7051 | ||
7052 | Configuring a <<tracing-session,recording session>> can be long. Some of | |
7053 | the tasks involved are: | |
7054 | ||
7055 | * <<enabling-disabling-channels,Create channels>> with | |
7056 | specific attributes. | |
7057 | ||
7058 | * <<adding-context,Add context fields>> to be recorded to the | |
7059 | <<event,event records>> of specific channels. | |
7060 | ||
7061 | * <<enabling-disabling-events,Create recording event rules>> with | |
7062 | specific log level, filter, and other conditions. | |
7063 | ||
7064 | If you use LTTng to solve real world problems, chances are you have to | |
7065 | record events using the same recording session setup over and over, | |
7066 | modifying a few variables each time in your instrumented program or | |
7067 | environment. | |
7068 | ||
7069 | To avoid constant recording session reconfiguration, the man:lttng(1) | |
7070 | command-line tool can save and load recording session configurations | |
7071 | to/from XML files. | |
7072 | ||
7073 | To save a given recording session configuration: | |
7074 | ||
7075 | * Use the man:lttng-save(1) command: | |
7076 | + | |
7077 | -- | |
7078 | [role="term"] | |
7079 | ---- | |
7080 | $ lttng save SESSION | |
7081 | ---- | |
7082 | -- | |
7083 | + | |
7084 | Replace +__SESSION__+ with the name of the recording session to save. | |
7085 | ||
7086 | LTTng saves recording session configurations to | |
7087 | dir:{$LTTNG_HOME/.lttng/sessions} by default. Note that the | |
7088 | env:LTTNG_HOME environment variable defaults to `$HOME` if not set. See | |
7089 | man:lttng-save(1) to learn more about the recording session configuration | |
7090 | output path. | |
7091 | ||
7092 | LTTng saves all configuration parameters, for example: | |
7093 | ||
7094 | * The recording session name. | |
7095 | * The trace data output path. | |
7096 | * The <<channel,channels>>, with their state and all their attributes. | |
7097 | * The context fields you added to channels. | |
7098 | * The <<event,recording event rules>> with their state and conditions. | |
7099 | ||
7100 | To load a recording session: | |
7101 | ||
7102 | * Use the man:lttng-load(1) command: | |
7103 | + | |
7104 | -- | |
7105 | [role="term"] | |
7106 | ---- | |
7107 | $ lttng load SESSION | |
7108 | ---- | |
7109 | -- | |
7110 | + | |
7111 | Replace +__SESSION__+ with the name of the recording session to load. | |
7112 | ||
7113 | When LTTng loads a configuration, it restores your saved recording session | |
7114 | as if you just configured it manually. | |
7115 | ||
7116 | You can also save and load many sessions at a time; see | |
7117 | man:lttng-save(1) and man:lttng-load(1) to learn more. | |
7118 | ||
7119 | ||
7120 | [[sending-trace-data-over-the-network]] | |
7121 | === Send trace data over the network | |
7122 | ||
7123 | LTTng can send the recorded trace data of a <<tracing-session,recording | |
7124 | session>> to a remote system over the network instead of writing it to | |
7125 | the local file system. | |
7126 | ||
7127 | To send the trace data over the network: | |
7128 | ||
7129 | . On the _remote_ system (which can also be the target system), | |
7130 | start an LTTng <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)): | |
7131 | + | |
7132 | -- | |
7133 | [role="term"] | |
7134 | ---- | |
7135 | $ lttng-relayd | |
7136 | ---- | |
7137 | -- | |
7138 | ||
7139 | . On the _target_ system, create a recording session | |
7140 | <<net-streaming-mode,configured>> to send trace data over the network: | |
7141 | + | |
7142 | -- | |
7143 | [role="term"] | |
7144 | ---- | |
7145 | $ lttng create my-session --set-url=net://remote-system | |
7146 | ---- | |
7147 | -- | |
7148 | + | |
7149 | Replace +__remote-system__+ with the host name or IP address of the | |
7150 | remote system. See man:lttng-create(1) for the exact URL format. | |
7151 | ||
7152 | . On the target system, use the man:lttng(1) command-line tool as usual. | |
7153 | + | |
7154 | When recording is <<basic-tracing-session-control,active>>, the | |
7155 | <<lttng-consumerd,consumer daemon>> of the target sends the contents of | |
7156 | <<channel,sub-buffers>> to the remote relay daemon instead of flushing | |
7157 | them to the local file system. The relay daemon writes the received | |
7158 | packets to its local file system. | |
7159 | ||
7160 | See the ``Output directory'' section of man:lttng-relayd(8) to learn | |
7161 | where a relay daemon writes its received trace data. | |
7162 | ||
7163 | ||
7164 | [role="since-2.4"] | |
7165 | [[lttng-live]] | |
7166 | === View events as LTTng records them (noch:{LTTng} live) | |
7167 | ||
7168 | _LTTng live_ is a network protocol implemented by the | |
7169 | <<lttng-relayd,relay daemon>> (man:lttng-relayd(8)) to allow compatible | |
7170 | trace readers to display or analyze <<event,event records>> as LTTng | |
7171 | records events on the target system while recording is | |
7172 | <<basic-tracing-session-control,active>>. | |
7173 | ||
7174 | The relay daemon creates a _tee_: it forwards the trace data to both the | |
7175 | local file system and to connected live readers: | |
7176 | ||
7177 | [role="img-90"] | |
7178 | .The relay daemon creates a _tee_, forwarding the trace data to both trace files and a connected live reader. | |
7179 | image::live.png[] | |
7180 | ||
7181 | To use LTTng live: | |
7182 | ||
7183 | . On the _target system_, create a <<tracing-session,recording session>> | |
7184 | in _live mode_: | |
7185 | + | |
7186 | -- | |
7187 | [role="term"] | |
7188 | ---- | |
7189 | $ lttng create my-session --live | |
7190 | ---- | |
7191 | -- | |
7192 | + | |
7193 | This operation spawns a local relay daemon. | |
7194 | ||
7195 | . Start the live reader and configure it to connect to the relay daemon. | |
7196 | + | |
7197 | For example, with man:babeltrace2(1): | |
7198 | + | |
7199 | -- | |
7200 | [role="term"] | |
7201 | ---- | |
7202 | $ babeltrace2 net://localhost/host/HOSTNAME/my-session | |
7203 | ---- | |
7204 | -- | |
7205 | + | |
7206 | Replace +__HOSTNAME__+ with the host name of the target system. | |
7207 | ||
7208 | . Configure the recording session as usual with the man:lttng(1) | |
7209 | command-line tool, and <<basic-tracing-session-control,start recording>>. | |
7210 | ||
7211 | List the available live recording sessions with man:babeltrace2(1): | |
7212 | ||
7213 | [role="term"] | |
7214 | ---- | |
7215 | $ babeltrace2 net://localhost | |
7216 | ---- | |
7217 | ||
7218 | You can start the relay daemon on another system. In this case, you need | |
7219 | to specify the URL of the relay daemon when you | |
7220 | <<creating-destroying-tracing-sessions,create the recording session>> with | |
7221 | the opt:lttng-create(1):--set-url option of the man:lttng-create(1) | |
7222 | command. You also need to replace +__localhost__+ in the procedure above | |
7223 | with the host name of the system on which the relay daemon runs. | |
7224 | ||
7225 | ||
7226 | [role="since-2.3"] | |
7227 | [[taking-a-snapshot]] | |
7228 | === Take a snapshot of the current sub-buffers of a recording session | |
7229 | ||
7230 | The normal behavior of LTTng is to append full sub-buffers to growing | |
7231 | trace data files. This is ideal to keep a full history of the events | |
7232 | which the target system emitted, but it can represent too much data in | |
7233 | some situations. | |
7234 | ||
7235 | For example, you may wish to have LTTng record your application | |
7236 | continuously until some critical situation happens, in which case you | |
7237 | only need the latest few recorded events to perform the desired | |
7238 | analysis, not multi-gigabyte trace files. | |
7239 | ||
7240 | With the man:lttng-snapshot(1) command, you can take a _snapshot_ of the | |
7241 | current <<channel,sub-buffers>> of a given <<tracing-session,recording | |
7242 | session>>. LTTng can write the snapshot to the local file system or send | |
7243 | it over the network. | |
7244 | ||
7245 | [role="img-100"] | |
7246 | .A snapshot is a copy of the current sub-buffers, which LTTng does _not_ clear after the operation. | |
7247 | image::snapshot.png[] | |
7248 | ||
7249 | The snapshot feature of LTTng is similar to how a | |
7250 | https://en.wikipedia.org/wiki/Flight_recorder[flight recorder] or the | |
7251 | ``roll'' mode of an oscilloscope work. | |
7252 | ||
7253 | TIP: If you wish to create unmanaged, self-contained, non-overlapping | |
7254 | trace chunk archives instead of a simple copy of the current | |
7255 | sub-buffers, see the <<session-rotation,recording session rotation>> | |
7256 | feature (available since LTTng{nbsp}2.11). | |
7257 | ||
7258 | To take a snapshot of the <<cur-tracing-session,current recording | |
7259 | session>>: | |
7260 | ||
7261 | . Create a recording session in <<snapshot-mode,snapshot mode>>: | |
7262 | + | |
7263 | -- | |
7264 | [role="term"] | |
7265 | ---- | |
7266 | $ lttng create my-session --snapshot | |
7267 | ---- | |
7268 | -- | |
7269 | + | |
7270 | The <<channel-overwrite-mode-vs-discard-mode,event record loss mode>> of | |
7271 | <<channel,channels>> created in this mode is automatically set to | |
7272 | <<overwrite-mode,_overwrite_>>. | |
7273 | ||
7274 | . Configure the recording session as usual with the man:lttng(1) | |
7275 | command-line tool, and <<basic-tracing-session-control,start | |
7276 | recording>>. | |
7277 | ||
7278 | . **Optional**: When you need to take a snapshot, | |
7279 | <<basic-tracing-session-control,stop recording>>. | |
7280 | + | |
7281 | You can take a snapshot when the tracers are active, but if you stop | |
7282 | them first, you're guaranteed that the trace data in the sub-buffers | |
7283 | doesn't change before you actually take the snapshot. | |
7284 | ||
7285 | . Take a snapshot: | |
7286 | + | |
7287 | -- | |
7288 | [role="term"] | |
7289 | ---- | |
7290 | $ lttng snapshot record --name=my-first-snapshot | |
7291 | ---- | |
7292 | -- | |
7293 | + | |
7294 | LTTng writes the current sub-buffers of all the channels of the | |
7295 | <<cur-tracing-session,current recording session>> to | |
7296 | trace files on the local file system. Those trace files have | |
7297 | `my-first-snapshot` in their name. | |
7298 | ||
7299 | There's no difference between the format of a normal trace file and the | |
7300 | format of a snapshot: LTTng trace readers also support LTTng snapshots. | |
7301 | ||
7302 | By default, LTTng writes snapshot files to the path shown by | |
7303 | ||
7304 | [role="term"] | |
7305 | ---- | |
7306 | $ lttng snapshot list-output | |
7307 | ---- | |
7308 | ||
7309 | You can change this path or decide to send snapshots over the network | |
7310 | using either: | |
7311 | ||
7312 | . An output path or URL that you specify when you | |
7313 | <<creating-destroying-tracing-sessions,create the recording session>>. | |
7314 | ||
7315 | . A snapshot output path or URL that you add using the | |
7316 | `add-output` action of the man:lttng-snapshot(1) command. | |
7317 | ||
7318 | . An output path or URL that you provide directly to the | |
7319 | `record` action of the man:lttng-snapshot(1) command. | |
7320 | ||
7321 | Method{nbsp}3 overrides method{nbsp}2, which overrides method 1. When | |
7322 | you specify a URL, a <<lttng-relayd,relay daemon>> must listen on a | |
7323 | remote system (see ``<<sending-trace-data-over-the-network,Send trace | |
7324 | data over the network>>''). | |
7325 | ||
7326 | The `snapshot-session` <<trigger,trigger>> action can also take | |
7327 | a recording session snapshot. | |
7328 | ||
7329 | ||
7330 | [role="since-2.11"] | |
7331 | [[session-rotation]] | |
7332 | === Archive the current trace chunk (rotate a recording session) | |
7333 | ||
7334 | The <<taking-a-snapshot,snapshot user guide>> shows how to dump the | |
7335 | current sub-buffers of a recording session to the file system or send them | |
7336 | over the network. When you take a snapshot, LTTng doesn't clear the ring | |
7337 | buffers of the recording session: if you take another snapshot immediately | |
7338 | after, both snapshots could contain overlapping trace data. | |
7339 | ||
7340 | Inspired by https://en.wikipedia.org/wiki/Log_rotation[log rotation], | |
7341 | _recording session rotation_ is a feature which appends the content of the | |
7342 | ring buffers to what's already on the file system or sent over the | |
7343 | network since the creation of the recording session or since the last | |
7344 | rotation, and then clears those ring buffers to avoid trace data | |
7345 | overlaps. | |
7346 | ||
7347 | What LTTng is about to write when performing a recording session rotation | |
7348 | is called the _current trace chunk_. When LTTng writes or sends over the | |
7349 | network this current trace chunk, it becomes a _trace chunk archive_. | |
7350 | Therefore, a recording session rotation operation _archives_ the current | |
7351 | trace chunk. | |
7352 | ||
7353 | [role="img-100"] | |
7354 | .A recording session rotation operation _archives_ the current trace chunk. | |
7355 | image::rotation.png[] | |
7356 | ||
7357 | A trace chunk archive is a self-contained LTTng trace which LTTng | |
7358 | doesn't manage anymore: you can read it, modify it, move it, or remove | |
7359 | it. | |
7360 | ||
7361 | As of LTTng{nbsp}{revision}, there are three methods to perform a | |
7362 | recording session rotation: | |
7363 | ||
7364 | * <<immediate-rotation,Immediately>>. | |
7365 | ||
7366 | * With a <<rotation-schedule,rotation schedule>>. | |
7367 | ||
7368 | * Through the execution of a `rotate-session` <<trigger,trigger>> | |
7369 | action. | |
7370 | ||
7371 | [[immediate-rotation]]To perform an immediate rotation of the | |
7372 | <<cur-tracing-session,current recording session>>: | |
7373 | ||
7374 | . <<creating-destroying-tracing-sessions,Create a recording session>> in | |
7375 | <<local-mode,local mode>> or <<net-streaming-mode,network streaming | |
7376 | mode>> (only those two recording session modes support recording session | |
7377 | rotation): | |
7378 | + | |
7379 | -- | |
7380 | [role="term"] | |
7381 | ---- | |
7382 | # lttng create my-session | |
7383 | ---- | |
7384 | -- | |
7385 | ||
7386 | . <<enabling-disabling-events,Create one or more recording event rules>> | |
7387 | and <<basic-tracing-session-control,start recording>>: | |
7388 | + | |
7389 | -- | |
7390 | [role="term"] | |
7391 | ---- | |
7392 | # lttng enable-event --kernel sched_'*' | |
7393 | # lttng start | |
7394 | ---- | |
7395 | -- | |
7396 | ||
7397 | . When needed, immediately rotate the current recording session: | |
7398 | + | |
7399 | -- | |
7400 | [role="term"] | |
7401 | ---- | |
7402 | # lttng rotate | |
7403 | ---- | |
7404 | -- | |
7405 | + | |
7406 | The man:lttng-rotate(1) command prints the path to the created trace | |
7407 | chunk archive. See its manual page to learn about the format of trace | |
7408 | chunk archive directory names. | |
7409 | + | |
7410 | Perform other immediate rotations while the recording session is active. | |
7411 | It's guaranteed that all the trace chunk archives don't contain | |
7412 | overlapping trace data. You can also perform an immediate rotation once | |
7413 | you have <<basic-tracing-session-control,stopped>> the recording session. | |
7414 | ||
7415 | . When you're done recording, | |
7416 | <<creating-destroying-tracing-sessions,destroy the current recording | |
7417 | session>>: | |
7418 | + | |
7419 | -- | |
7420 | [role="term"] | |
7421 | ---- | |
7422 | # lttng destroy | |
7423 | ---- | |
7424 | -- | |
7425 | + | |
7426 | The recording session destruction operation creates one last trace chunk | |
7427 | archive from the current trace chunk. | |
7428 | ||
7429 | [[rotation-schedule]]A recording session rotation schedule is a planned | |
7430 | rotation which LTTng performs automatically based on one of the | |
7431 | following conditions: | |
7432 | ||
7433 | * A timer with a configured period expires. | |
7434 | ||
7435 | * The total size of the _flushed_ part of the current trace chunk | |
7436 | becomes greater than or equal to a configured value. | |
7437 | ||
7438 | To schedule a rotation of the <<cur-tracing-session,current recording | |
7439 | session>>, set a _rotation schedule_: | |
7440 | ||
7441 | . <<creating-destroying-tracing-sessions,Create a recording session>> in | |
7442 | <<local-mode,local mode>> or <<net-streaming-mode,network streaming | |
7443 | mode>> (only those two creation modes support recording session | |
7444 | rotation): | |
7445 | + | |
7446 | -- | |
7447 | [role="term"] | |
7448 | ---- | |
7449 | # lttng create my-session | |
7450 | ---- | |
7451 | -- | |
7452 | ||
7453 | . <<enabling-disabling-events,Create one or more recording event rules>>: | |
7454 | + | |
7455 | -- | |
7456 | [role="term"] | |
7457 | ---- | |
7458 | # lttng enable-event --kernel sched_'*' | |
7459 | ---- | |
7460 | -- | |
7461 | ||
7462 | . Set a recording session rotation schedule: | |
7463 | + | |
7464 | -- | |
7465 | [role="term"] | |
7466 | ---- | |
7467 | # lttng enable-rotation --timer=10s | |
7468 | ---- | |
7469 | -- | |
7470 | + | |
7471 | In this example, we set a rotation schedule so that LTTng performs a | |
7472 | recording session rotation every ten seconds. | |
7473 | + | |
7474 | See man:lttng-enable-rotation(1) to learn more about other ways to set a | |
7475 | rotation schedule. | |
7476 | ||
7477 | . <<basic-tracing-session-control,Start recording>>: | |
7478 | + | |
7479 | -- | |
7480 | [role="term"] | |
7481 | ---- | |
7482 | # lttng start | |
7483 | ---- | |
7484 | -- | |
7485 | + | |
7486 | LTTng performs recording session rotations automatically while the | |
7487 | recording session is active thanks to the rotation schedule. | |
7488 | ||
7489 | . When you're done recording, | |
7490 | <<creating-destroying-tracing-sessions,destroy the current recording | |
7491 | session>>: | |
7492 | + | |
7493 | -- | |
7494 | [role="term"] | |
7495 | ---- | |
7496 | # lttng destroy | |
7497 | ---- | |
7498 | -- | |
7499 | + | |
7500 | The recording session destruction operation creates one last trace chunk | |
7501 | archive from the current trace chunk. | |
7502 | ||
7503 | Unset a recording session rotation schedule with the | |
7504 | man:lttng-disable-rotation(1) command. | |
7505 | ||
7506 | ||
7507 | [role="since-2.13"] | |
7508 | [[add-event-rule-matches-trigger]] | |
7509 | === Add an ``event rule matches'' trigger to a session daemon | |
7510 | ||
7511 | With the man:lttng-add-trigger(1) command, you can add a | |
7512 | <<trigger,trigger>> to a <<lttng-sessiond,session daemon>>. | |
7513 | ||
7514 | A trigger associates an LTTng tracing condition to one or more actions: | |
7515 | when the condition is satisfied, LTTng attempts to execute the actions. | |
7516 | ||
7517 | A trigger doesn't need any <<tracing-session,recording session>> to exist: | |
7518 | it belongs to a session daemon. | |
7519 | ||
7520 | As of LTTng{nbsp}{revision}, many condition types are available through | |
7521 | the <<liblttng-ctl-lttng,`liblttng-ctl`>> C{nbsp}API, but the | |
7522 | man:lttng-add-trigger(1) command only accepts the ``event rule matches'' | |
7523 | condition. | |
7524 | ||
7525 | An ``event rule matches'' condition is satisfied when its event rule | |
7526 | matches an event. | |
7527 | ||
7528 | Unlike a <<event,recording event rule>>, the event rule of an | |
7529 | ``event rule matches'' trigger condition has no implicit conditions, | |
7530 | that is: | |
7531 | ||
7532 | * It has no enabled/disabled state. | |
7533 | * It has no attached <<channel,channel>>. | |
7534 | * It doesn't belong to a <<tracing-session,recording session>>. | |
7535 | ||
7536 | Both the man:lttng-add-trigger(1) and man:lttng-enable-event(1) commands | |
7537 | accept command-line arguments to specify an <<event-rule,event rule>>. | |
7538 | That being said, the former is a more recent command and therefore | |
7539 | follows the common event rule specification format (see | |
7540 | man:lttng-event-rule(7)). | |
7541 | ||
7542 | .Start a <<tracing-session,recording session>> when an event rule matches. | |
7543 | ==== | |
7544 | This example shows how to add the following trigger to the root | |
7545 | <<lttng-sessiond,session daemon>>: | |
7546 | ||
7547 | Condition:: | |
7548 | An event rule matches a Linux kernel system call event of which the | |
7549 | name starts with `exec` and `*/ls` matches the `filename` payload | |
7550 | field. | |
7551 | + | |
7552 | With such an event rule, LTTng emits an event when the cmd:ls program | |
7553 | starts. | |
7554 | ||
7555 | Action:: | |
7556 | <<basic-tracing-session-control,Start the recording session>> | |
7557 | named `pitou`. | |
7558 | ||
7559 | To add such a trigger to the root session daemon: | |
7560 | ||
7561 | . **If there's no currently running LTTng root session daemon**, start | |
7562 | one: | |
7563 | + | |
7564 | [role="term"] | |
7565 | ---- | |
7566 | # lttng-sessiond --daemonize | |
7567 | ---- | |
7568 | ||
7569 | . <<creating-destroying-tracing-sessions,Create a recording session>> | |
7570 | named `pitou` and | |
7571 | <<enabling-disabling-events,create a recording event rule>> matching | |
7572 | all the system call events: | |
7573 | + | |
7574 | [role="term"] | |
7575 | ---- | |
7576 | # lttng create pitou | |
7577 | # lttng enable-event --kernel --syscall --all | |
7578 | ---- | |
7579 | ||
7580 | . Add the trigger to the root session daemon: | |
7581 | + | |
7582 | [role="term"] | |
7583 | ---- | |
7584 | # lttng add-trigger --condition=event-rule-matches \ | |
7585 | --type=syscall --name='exec*' \ | |
7586 | --filter='filename == "*/ls"' \ | |
7587 | --action=start-session pitou | |
7588 | ---- | |
7589 | + | |
7590 | Confirm that the trigger exists with the man:lttng-list-triggers(1) | |
7591 | command: | |
7592 | + | |
7593 | [role="term"] | |
7594 | ---- | |
7595 | # lttng list-triggers | |
7596 | ---- | |
7597 | ||
7598 | . Make sure the `pitou` recording session is still inactive (stopped): | |
7599 | + | |
7600 | [role="term"] | |
7601 | ---- | |
7602 | # lttng list pitou | |
7603 | ---- | |
7604 | + | |
7605 | The first line should be something like: | |
7606 | + | |
7607 | ---- | |
7608 | Recording session pitou: [inactive] | |
7609 | ---- | |
7610 | ||
7611 | Run the cmd:ls program to fire the LTTng trigger above: | |
7612 | ||
7613 | [role="term"] | |
7614 | ---- | |
7615 | $ ls ~ | |
7616 | ---- | |
7617 | ||
7618 | At this point, the `pitou` recording session should be active | |
7619 | (started). Confirm this with the man:lttng-list(1) command again: | |
7620 | ||
7621 | [role="term"] | |
7622 | ---- | |
7623 | # lttng list pitou | |
7624 | ---- | |
7625 | ||
7626 | The first line should now look like: | |
7627 | ||
7628 | ---- | |
7629 | Recording session pitou: [active] | |
7630 | ---- | |
7631 | ||
7632 | This line confirms that the LTTng trigger you added fired, therefore | |
7633 | starting the `pitou` recording session. | |
7634 | ==== | |
7635 | ||
7636 | .[[trigger-event-notif]]Send a notification to a user application when an event rule matches. | |
7637 | ==== | |
7638 | This example shows how to add the following trigger to the root | |
7639 | <<lttng-sessiond,session daemon>>: | |
7640 | ||
7641 | Condition:: | |
7642 | An event rule matches a Linux kernel tracepoint event named | |
7643 | `sched_switch` and of which the value of the `next_comm` payload | |
7644 | field is `bash`. | |
7645 | + | |
7646 | With such an event rule, LTTng emits an event when Linux gives access to | |
7647 | the processor to a process named `bash`. | |
7648 | ||
7649 | Action:: | |
7650 | Send an LTTng notification to a user application. | |
7651 | ||
7652 | Moreover, we'll specify a _capture descriptor_ with the | |
7653 | `event-rule-matches` trigger condition so that the user application can | |
7654 | get the value of a specific `sched_switch` event payload field. | |
7655 | ||
7656 | First, write and build the user application: | |
7657 | ||
7658 | . Create the C{nbsp}source file of the application: | |
7659 | + | |
7660 | -- | |
7661 | [source,c] | |
7662 | .path:{notif-app.c} | |
7663 | ---- | |
7664 | #include <stdlib.h> | |
7665 | #include <stdio.h> | |
7666 | #include <stdbool.h> | |
7667 | #include <assert.h> | |
7668 | #include <string.h> | |
7669 | #include <lttng/lttng.h> | |
7670 | ||
7671 | /* | |
7672 | * Subscribes to notifications, through the notification channel | |
7673 | * `notification_channel`, which match the condition of the trigger | |
7674 | * named `trigger_name`. | |
7675 | * | |
7676 | * Returns `true` on success. | |
7677 | */ | |
7678 | static bool subscribe(struct lttng_notification_channel *notification_channel, | |
7679 | const char *trigger_name) | |
7680 | { | |
7681 | const struct lttng_condition *condition = NULL; | |
7682 | struct lttng_triggers *triggers = NULL; | |
7683 | unsigned int trigger_count; | |
7684 | unsigned int i; | |
7685 | enum lttng_error_code error_code; | |
7686 | enum lttng_trigger_status trigger_status; | |
7687 | bool ret = false; | |
7688 | ||
7689 | /* Get all LTTng triggers */ | |
7690 | error_code = lttng_list_triggers(&triggers); | |
7691 | assert(error_code == LTTNG_OK); | |
7692 | ||
7693 | /* Get the number of triggers */ | |
7694 | trigger_status = lttng_triggers_get_count(triggers, &trigger_count); | |
7695 | assert(trigger_status == LTTNG_TRIGGER_STATUS_OK); | |
7696 | ||
7697 | /* Find the trigger named `trigger_name` */ | |
7698 | for (i = 0; i < trigger_count; i++) { | |
7699 | const struct lttng_trigger *trigger; | |
7700 | const char *this_trigger_name; | |
7701 | ||
7702 | trigger = lttng_triggers_get_at_index(triggers, i); | |
7703 | trigger_status = lttng_trigger_get_name(trigger, &this_trigger_name); | |
7704 | assert(trigger_status == LTTNG_TRIGGER_STATUS_OK); | |
7705 | ||
7706 | if (strcmp(this_trigger_name, trigger_name) == 0) { | |
7707 | /* Trigger found: subscribe with its condition */ | |
7708 | enum lttng_notification_channel_status notification_channel_status; | |
7709 | ||
7710 | notification_channel_status = lttng_notification_channel_subscribe( | |
7711 | notification_channel, | |
7712 | lttng_trigger_get_const_condition(trigger)); | |
7713 | assert(notification_channel_status == | |
7714 | LTTNG_NOTIFICATION_CHANNEL_STATUS_OK); | |
7715 | ret = true; | |
7716 | break; | |
7717 | } | |
7718 | } | |
7719 | ||
7720 | lttng_triggers_destroy(triggers); | |
7721 | return ret; | |
7722 | } | |
7723 | ||
7724 | /* | |
7725 | * Handles the evaluation `evaluation` of a single notification. | |
7726 | */ | |
7727 | static void handle_evaluation(const struct lttng_evaluation *evaluation) | |
7728 | { | |
7729 | enum lttng_evaluation_status evaluation_status; | |
7730 | const struct lttng_event_field_value *array_field_value; | |
7731 | const struct lttng_event_field_value *string_field_value; | |
7732 | enum lttng_event_field_value_status event_field_value_status; | |
7733 | const char *string_field_string_value; | |
7734 | ||
7735 | /* Get the value of the first captured (string) field */ | |
7736 | evaluation_status = lttng_evaluation_event_rule_matches_get_captured_values( | |
7737 | evaluation, &array_field_value); | |
7738 | assert(evaluation_status == LTTNG_EVALUATION_STATUS_OK); | |
7739 | event_field_value_status = | |
7740 | lttng_event_field_value_array_get_element_at_index( | |
7741 | array_field_value, 0, &string_field_value); | |
7742 | assert(event_field_value_status == LTTNG_EVENT_FIELD_VALUE_STATUS_OK); | |
7743 | assert(lttng_event_field_value_get_type(string_field_value) == | |
7744 | LTTNG_EVENT_FIELD_VALUE_TYPE_STRING); | |
7745 | event_field_value_status = lttng_event_field_value_string_get_value( | |
7746 | string_field_value, &string_field_string_value); | |
7747 | assert(event_field_value_status == LTTNG_EVENT_FIELD_VALUE_STATUS_OK); | |
7748 | ||
7749 | /* Print the string value of the field */ | |
7750 | puts(string_field_string_value); | |
7751 | } | |
7752 | ||
7753 | int main(int argc, char *argv[]) | |
7754 | { | |
7755 | int exit_status = EXIT_SUCCESS; | |
7756 | struct lttng_notification_channel *notification_channel; | |
7757 | enum lttng_notification_channel_status notification_channel_status; | |
7758 | const struct lttng_condition *condition; | |
7759 | const char *trigger_name; | |
7760 | bool subscribe_res; | |
7761 | ||
7762 | assert(argc >= 2); | |
7763 | trigger_name = argv[1]; | |
7764 | ||
7765 | /* | |
7766 | * Create a notification channel. | |
7767 | * | |
7768 | * A notification channel connects the user application to the LTTng | |
7769 | * session daemon. | |
7770 | * | |
7771 | * You can use this notification channel to listen to various types | |
7772 | * of notifications. | |
7773 | */ | |
7774 | notification_channel = lttng_notification_channel_create( | |
7775 | lttng_session_daemon_notification_endpoint); | |
7776 | assert(notification_channel); | |
7777 | ||
7778 | /* | |
7779 | * Subscribe to notifications which match the condition of the | |
7780 | * trigger named `trigger_name`. | |
7781 | */ | |
7782 | if (!subscribe(notification_channel, trigger_name)) { | |
7783 | fprintf(stderr, | |
7784 | "Error: Failed to subscribe to notifications (trigger `%s`).\n", | |
7785 | trigger_name); | |
7786 | exit_status = EXIT_FAILURE; | |
7787 | goto end; | |
7788 | } | |
7789 | ||
7790 | /* | |
7791 | * Notification loop. | |
7792 | * | |
7793 | * Put this in a dedicated thread to avoid blocking the main thread. | |
7794 | */ | |
7795 | while (true) { | |
7796 | struct lttng_notification *notification; | |
7797 | enum lttng_notification_channel_status status; | |
7798 | const struct lttng_evaluation *notification_evaluation; | |
7799 | ||
7800 | /* Receive the next notification */ | |
7801 | status = lttng_notification_channel_get_next_notification( | |
7802 | notification_channel, ¬ification); | |
7803 | ||
7804 | switch (status) { | |
7805 | case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK: | |
7806 | break; | |
7807 | case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED: | |
7808 | /* | |
7809 | * The session daemon can drop notifications if a receiving | |
7810 | * application doesn't consume the notifications fast | |
7811 | * enough. | |
7812 | */ | |
7813 | continue; | |
7814 | case LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED: | |
7815 | /* | |
7816 | * The session daemon closed the notification channel. | |
7817 | * | |
7818 | * This is typically caused by a session daemon shutting | |
7819 | * down. | |
7820 | */ | |
7821 | goto end; | |
7822 | default: | |
7823 | /* Unhandled conditions or errors */ | |
7824 | exit_status = EXIT_FAILURE; | |
7825 | goto end; | |
7826 | } | |
7827 | ||
7828 | /* | |
7829 | * Handle the condition evaluation. | |
7830 | * | |
7831 | * A notification provides, amongst other things: | |
7832 | * | |
7833 | * * The condition that caused LTTng to send this notification. | |
7834 | * | |
7835 | * * The condition evaluation, which provides more specific | |
7836 | * information on the evaluation of the condition. | |
7837 | */ | |
7838 | handle_evaluation(lttng_notification_get_evaluation(notification)); | |
7839 | ||
7840 | /* Destroy the notification object */ | |
7841 | lttng_notification_destroy(notification); | |
7842 | } | |
7843 | ||
7844 | end: | |
7845 | lttng_notification_channel_destroy(notification_channel); | |
7846 | return exit_status; | |
7847 | } | |
7848 | ---- | |
7849 | -- | |
7850 | + | |
7851 | This application prints the first captured string field value of the | |
7852 | condition evaluation of each LTTng notification it receives. | |
7853 | ||
7854 | . Build the `notif-app` application, | |
7855 | using https://www.freedesktop.org/wiki/Software/pkg-config/[pkg-config] | |
7856 | to provide the right compiler and linker flags: | |
7857 | + | |
7858 | -- | |
7859 | [role="term"] | |
7860 | ---- | |
7861 | $ gcc -o notif-app notif-app.c $(pkg-config --cflags --libs lttng-ctl) | |
7862 | ---- | |
7863 | -- | |
7864 | ||
7865 | Now, to add the trigger to the root session daemon: | |
7866 | ||
7867 | [start=3] | |
7868 | . **If there's no currently running LTTng root session daemon**, start | |
7869 | one: | |
7870 | + | |
7871 | [role="term"] | |
7872 | ---- | |
7873 | # lttng-sessiond --daemonize | |
7874 | ---- | |
7875 | ||
7876 | . Add the trigger, naming it `sched-switch-notif`, to the root | |
7877 | session daemon: | |
7878 | + | |
7879 | [role="term"] | |
7880 | ---- | |
7881 | # lttng add-trigger --name=sched-switch-notif \ | |
7882 | --condition=event-rule-matches \ | |
7883 | --type=kernel --name=sched_switch \ | |
7884 | --filter='next_comm == "bash"' --capture=prev_comm \ | |
7885 | --action=notify | |
7886 | ---- | |
7887 | + | |
7888 | Confirm that the `sched-switch-notif` trigger exists with the | |
7889 | man:lttng-list-triggers(1) command: | |
7890 | + | |
7891 | [role="term"] | |
7892 | ---- | |
7893 | # lttng list-triggers | |
7894 | ---- | |
7895 | ||
7896 | Run the cmd:notif-app application, passing the name of the trigger | |
7897 | of which to watch the notifications: | |
7898 | ||
7899 | [role="term"] | |
7900 | ---- | |
7901 | # ./notif-app sched-switch-notif | |
7902 | ---- | |
7903 | ||
7904 | Now, in an interactive Bash, type a few keys to fire the | |
7905 | `sched-switch-notif` trigger. Watch the `notif-app` application print | |
7906 | the previous process names. | |
7907 | ==== | |
7908 | ||
7909 | [role="since-2.6"] | |
7910 | [[mi]] | |
7911 | === Use the machine interface | |
7912 | ||
7913 | With any command of the man:lttng(1) command-line tool, set the | |
7914 | opt:lttng(1):--mi option to `xml` (before the command name) to get an | |
7915 | XML machine interface output, for example: | |
7916 | ||
7917 | [role="term"] | |
7918 | ---- | |
7919 | $ lttng --mi=xml list my-session | |
7920 | ---- | |
7921 | ||
7922 | A schema definition (XSD) is | |
7923 | https://github.com/lttng/lttng-tools/blob/stable-{revision}/src/common/mi-lttng-4.0.xsd[available] | |
7924 | to ease the integration with external tools as much as possible. | |
7925 | ||
7926 | ||
7927 | [role="since-2.8"] | |
7928 | [[metadata-regenerate]] | |
7929 | === Regenerate the metadata of an LTTng trace | |
7930 | ||
7931 | An LTTng trace, which is a https://diamon.org/ctf[CTF] trace, has both | |
7932 | data stream files and a metadata stream file. This metadata file | |
7933 | contains, amongst other things, information about the offset of the | |
7934 | clock sources which LTTng uses to assign timestamps to <<event,event | |
7935 | records>> when recording. | |
7936 | ||
7937 | If, once a <<tracing-session,recording session>> is | |
7938 | <<basic-tracing-session-control,started>>, a major | |
7939 | https://en.wikipedia.org/wiki/Network_Time_Protocol[NTP] correction | |
7940 | happens, the clock offset of the trace also needs to be updated. Use | |
7941 | the `metadata` item of the man:lttng-regenerate(1) command to do so. | |
7942 | ||
7943 | The main use case of this command is to allow a system to boot with | |
7944 | an incorrect wall time and have LTTng trace it before its wall time | |
7945 | is corrected. Once the system is known to be in a state where its | |
7946 | wall time is correct, you can run `lttng regenerate metadata`. | |
7947 | ||
7948 | To regenerate the metadata stream files of the | |
7949 | <<cur-tracing-session,current recording session>>: | |
7950 | ||
7951 | * Use the `metadata` item of the man:lttng-regenerate(1) command: | |
7952 | + | |
7953 | -- | |
7954 | [role="term"] | |
7955 | ---- | |
7956 | $ lttng regenerate metadata | |
7957 | ---- | |
7958 | -- | |
7959 | ||
7960 | ||
7961 | [role="since-2.9"] | |
7962 | [[regenerate-statedump]] | |
7963 | === Regenerate the state dump event records of a recording session | |
7964 | ||
7965 | The LTTng kernel and user space tracers generate state dump | |
7966 | <<event,event records>> when the application starts or when you | |
7967 | <<basic-tracing-session-control,start a recording session>>. | |
7968 | ||
7969 | An analysis can use the state dump event records to set an initial state | |
7970 | before it builds the rest of the state from the subsequent event | |
7971 | records. http://tracecompass.org/[Trace Compass] and | |
7972 | https://github.com/lttng/lttng-analyses[LTTng analyses] are notable | |
7973 | examples of applications which use the state dump of an LTTng trace. | |
7974 | ||
7975 | When you <<taking-a-snapshot,take a snapshot>>, it's possible that the | |
7976 | state dump event records aren't included in the snapshot trace files | |
7977 | because they were recorded to a <<channel,sub-buffer>> that has been | |
7978 | consumed or <<overwrite-mode,overwritten>> already. | |
7979 | ||
7980 | Use the `statedump` item of the man:lttng-regenerate(1) command to emit | |
7981 | and record the state dump events again. | |
7982 | ||
7983 | To regenerate the state dump of the <<cur-tracing-session,current | |
7984 | recording session>>, provided you created it in <<snapshot-mode,snapshot | |
7985 | mode>>, before you take a snapshot: | |
7986 | ||
7987 | . Use the `statedump` item of the man:lttng-regenerate(1) command: | |
7988 | + | |
7989 | -- | |
7990 | [role="term"] | |
7991 | ---- | |
7992 | $ lttng regenerate statedump | |
7993 | ---- | |
7994 | -- | |
7995 | ||
7996 | . <<basic-tracing-session-control,Stop the recording session>>: | |
7997 | + | |
7998 | -- | |
7999 | [role="term"] | |
8000 | ---- | |
8001 | $ lttng stop | |
8002 | ---- | |
8003 | -- | |
8004 | ||
8005 | . <<taking-a-snapshot,Take a snapshot>>: | |
8006 | + | |
8007 | -- | |
8008 | [role="term"] | |
8009 | ---- | |
8010 | $ lttng snapshot record --name=my-snapshot | |
8011 | ---- | |
8012 | -- | |
8013 | ||
8014 | Depending on the event throughput, you should run steps{nbsp}1 | |
8015 | and{nbsp}2 as closely as possible. | |
8016 | ||
8017 | [NOTE] | |
8018 | ==== | |
8019 | To record the state dump events, you need to | |
8020 | <<enabling-disabling-events,create recording event rules>> which enable | |
8021 | them: | |
8022 | ||
8023 | * The names of LTTng-UST state dump tracepoints start with | |
8024 | `lttng_ust_statedump:`. | |
8025 | ||
8026 | * The names of LTTng-modules state dump tracepoints start with | |
8027 | `lttng_statedump_`. | |
8028 | ==== | |
8029 | ||
8030 | ||
8031 | [role="since-2.7"] | |
8032 | [[persistent-memory-file-systems]] | |
8033 | === Record trace data on persistent memory file systems | |
8034 | ||
8035 | https://en.wikipedia.org/wiki/Non-volatile_random-access_memory[Non-volatile | |
8036 | random-access memory] (NVRAM) is random-access memory that retains its | |
8037 | information when power is turned off (non-volatile). Systems with such | |
8038 | memory can store data structures in RAM and retrieve them after a | |
8039 | reboot, without flushing to typical _storage_. | |
8040 | ||
8041 | Linux supports NVRAM file systems thanks to either | |
50e95807 | 8042 | https://www.kernel.org/doc/Documentation/filesystems/dax.txt[DAX]{nbsp}+{nbsp}http://lkml.iu.edu/hypermail/linux/kernel/1504.1/03463.html[pmem] |
b67a670c | 8043 | (requires Linux{nbsp}4.1+) or http://pramfs.sourceforge.net/[PRAMFS] (requires Linux{nbsp}<{nbsp}4). |
50e95807 PP |
8044 | |
8045 | This section doesn't describe how to operate such file systems; we | |
8046 | assume that you have a working persistent memory file system. | |
8047 | ||
8048 | When you <<creating-destroying-tracing-sessions,create a recording | |
8049 | session>>, you can specify the path of the shared memory holding the | |
8050 | sub-buffers. If you specify a location on an NVRAM file system, then you | |
8051 | can retrieve the latest recorded trace data when the system reboots | |
8052 | after a crash. | |
8053 | ||
8054 | To record trace data on a persistent memory file system and retrieve the | |
8055 | trace data after a system crash: | |
8056 | ||
8057 | . Create a recording session with a <<channel,sub-buffer>> shared memory | |
8058 | path located on an NVRAM file system: | |
8059 | + | |
8060 | -- | |
8061 | [role="term"] | |
8062 | ---- | |
8063 | $ lttng create my-session --shm-path=/path/to/shm/on/nvram | |
8064 | ---- | |
8065 | -- | |
8066 | ||
8067 | . Configure the recording session as usual with the man:lttng(1) | |
8068 | command-line tool, and <<basic-tracing-session-control,start | |
8069 | recording>>. | |
8070 | ||
8071 | . After a system crash, use the man:lttng-crash(1) command-line tool to | |
8072 | read the trace data recorded on the NVRAM file system: | |
8073 | + | |
8074 | -- | |
8075 | [role="term"] | |
8076 | ---- | |
8077 | $ lttng-crash /path/to/shm/on/nvram | |
8078 | ---- | |
8079 | -- | |
8080 | ||
8081 | The binary layout of the ring buffer files isn't exactly the same as the | |
8082 | trace files layout. This is why you need to use man:lttng-crash(1) | |
8083 | instead of some standard LTTng trace reader. | |
8084 | ||
8085 | To convert the ring buffer files to LTTng trace files: | |
8086 | ||
8087 | * Use the opt:lttng-crash(1):--extract option of man:lttng-crash(1): | |
8088 | + | |
8089 | -- | |
8090 | [role="term"] | |
8091 | ---- | |
8092 | $ lttng-crash --extract=/path/to/trace /path/to/shm/on/nvram | |
8093 | ---- | |
8094 | -- | |
8095 | ||
8096 | ||
8097 | [role="since-2.10"] | |
8098 | [[notif-trigger-api]] | |
8099 | === Get notified when the buffer usage of a channel is too high or too low | |
8100 | ||
8101 | With the notification and <<trigger,trigger>> C{nbsp}API of | |
8102 | <<liblttng-ctl-lttng,`liblttng-ctl`>>, LTTng can notify your user | |
8103 | application when the buffer usage of one or more <<channel,channels>> | |
8104 | becomes too low or too high. | |
8105 | ||
8106 | Use this API and enable or disable <<event,recording event rules>> while | |
8107 | a recording session <<basic-tracing-session-control,is active>> to avoid | |
8108 | <<channel-overwrite-mode-vs-discard-mode,discarded event records>>, for | |
8109 | example. | |
8110 | ||
8111 | .Send a notification to a user application when the buffer usage of an LTTng channel is too high. | |
8112 | ==== | |
8113 | In this example, we create and build an application which gets notified | |
8114 | when the buffer usage of a specific LTTng channel is higher than | |
8115 | 75{nbsp}%. | |
8116 | ||
8117 | We only print that it's the case in this example, but we could as well | |
8118 | use the `liblttng-ctl` C{nbsp}API to <<enabling-disabling-events,disable | |
8119 | recording event rules>> when this happens, for example. | |
8120 | ||
8121 | . Create the C{nbsp}source file of the application: | |
8122 | + | |
8123 | -- | |
8124 | [source,c] | |
8125 | .path:{notif-app.c} | |
8126 | ---- | |
8127 | #include <stdlib.h> | |
8128 | #include <stdio.h> | |
8129 | #include <assert.h> | |
8130 | #include <lttng/lttng.h> | |
8131 | ||
8132 | int main(int argc, char *argv[]) | |
8133 | { | |
8134 | int exit_status = EXIT_SUCCESS; | |
8135 | struct lttng_notification_channel *notification_channel; | |
8136 | struct lttng_condition *condition; | |
8137 | struct lttng_action *action; | |
8138 | struct lttng_trigger *trigger; | |
8139 | const char *recording_session_name; | |
8140 | const char *channel_name; | |
8141 | ||
8142 | assert(argc >= 3); | |
8143 | recording_session_name = argv[1]; | |
8144 | channel_name = argv[2]; | |
8145 | ||
8146 | /* | |
8147 | * Create a notification channel. | |
8148 | * | |
8149 | * A notification channel connects the user application to the LTTng | |
8150 | * session daemon. | |
8151 | * | |
8152 | * You can use this notification channel to listen to various types | |
8153 | * of notifications. | |
8154 | */ | |
8155 | notification_channel = lttng_notification_channel_create( | |
8156 | lttng_session_daemon_notification_endpoint); | |
8157 | ||
8158 | /* | |
8159 | * Create a "buffer usage becomes greater than" condition. | |
8160 | * | |
8161 | * In this case, the condition is satisfied when the buffer usage | |
8162 | * becomes greater than or equal to 75 %. | |
8163 | * | |
8164 | * We create the condition for a specific recording session name, | |
8165 | * channel name, and for the user space tracing domain. | |
8166 | * | |
8167 | * The following condition types also exist: | |
8168 | * | |
8169 | * * The buffer usage of a channel becomes less than a given value. | |
8170 | * | |
8171 | * * The consumed data size of a recording session becomes greater | |
8172 | * than a given value. | |
8173 | * | |
8174 | * * A recording session rotation becomes ongoing. | |
8175 | * | |
8176 | * * A recording session rotation becomes completed. | |
8177 | * | |
8178 | * * A given event rule matches an event. | |
8179 | */ | |
8180 | condition = lttng_condition_buffer_usage_high_create(); | |
8181 | lttng_condition_buffer_usage_set_threshold_ratio(condition, .75); | |
8182 | lttng_condition_buffer_usage_set_session_name(condition, | |
8183 | recording_session_name); | |
8184 | lttng_condition_buffer_usage_set_channel_name(condition, | |
8185 | channel_name); | |
8186 | lttng_condition_buffer_usage_set_domain_type(condition, | |
8187 | LTTNG_DOMAIN_UST); | |
8188 | ||
8189 | /* | |
8190 | * Create an action (receive a notification) to execute when the | |
8191 | * condition created above is satisfied. | |
8192 | */ | |
8193 | action = lttng_action_notify_create(); | |
8194 | ||
8195 | /* | |
8196 | * Create a trigger. | |
8197 | * | |
8198 | * A trigger associates a condition to an action: LTTng executes | |
8199 | * the action when the condition is satisfied. | |
8200 | */ | |
8201 | trigger = lttng_trigger_create(condition, action); | |
8202 | ||
8203 | /* Register the trigger to the LTTng session daemon. */ | |
8204 | lttng_register_trigger(trigger); | |
8205 | ||
8206 | /* | |
8207 | * Now that we have registered a trigger, LTTng will send a | |
8208 | * notification every time its condition is met through a | |
8209 | * notification channel. | |
8210 | * | |
8211 | * To receive this notification, we must subscribe to notifications | |
8212 | * which match the same condition. | |
8213 | */ | |
8214 | lttng_notification_channel_subscribe(notification_channel, | |
8215 | condition); | |
8216 | ||
8217 | /* | |
8218 | * Notification loop. | |
8219 | * | |
8220 | * Put this in a dedicated thread to avoid blocking the main thread. | |
8221 | */ | |
8222 | for (;;) { | |
8223 | struct lttng_notification *notification; | |
8224 | enum lttng_notification_channel_status status; | |
8225 | const struct lttng_evaluation *notification_evaluation; | |
8226 | const struct lttng_condition *notification_condition; | |
8227 | double buffer_usage; | |
8228 | ||
8229 | /* Receive the next notification. */ | |
8230 | status = lttng_notification_channel_get_next_notification( | |
8231 | notification_channel, ¬ification); | |
8232 | ||
8233 | switch (status) { | |
8234 | case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK: | |
8235 | break; | |
8236 | case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED: | |
8237 | /* | |
8238 | * The session daemon can drop notifications if a monitoring | |
8239 | * application isn't consuming the notifications fast | |
8240 | * enough. | |
8241 | */ | |
8242 | continue; | |
8243 | case LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED: | |
8244 | /* | |
8245 | * The session daemon closed the notification channel. | |
8246 | * | |
8247 | * This is typically caused by a session daemon shutting | |
8248 | * down. | |
8249 | */ | |
8250 | goto end; | |
8251 | default: | |
8252 | /* Unhandled conditions or errors. */ | |
8253 | exit_status = EXIT_FAILURE; | |
8254 | goto end; | |
8255 | } | |
8256 | ||
8257 | /* | |
8258 | * A notification provides, amongst other things: | |
8259 | * | |
8260 | * * The condition that caused LTTng to send this notification. | |
8261 | * | |
8262 | * * The condition evaluation, which provides more specific | |
8263 | * information on the evaluation of the condition. | |
8264 | * | |
8265 | * The condition evaluation provides the buffer usage | |
8266 | * value at the moment the condition was satisfied. | |
8267 | */ | |
8268 | notification_condition = lttng_notification_get_condition( | |
8269 | notification); | |
8270 | notification_evaluation = lttng_notification_get_evaluation( | |
8271 | notification); | |
8272 | ||
8273 | /* We're subscribed to only one condition. */ | |
8274 | assert(lttng_condition_get_type(notification_condition) == | |
8275 | LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH); | |
8276 | ||
8277 | /* | |
8278 | * Get the exact sampled buffer usage from the condition | |
8279 | * evaluation. | |
8280 | */ | |
8281 | lttng_evaluation_buffer_usage_get_usage_ratio( | |
8282 | notification_evaluation, &buffer_usage); | |
8283 | ||
8284 | /* | |
8285 | * At this point, instead of printing a message, we could do | |
8286 | * something to reduce the buffer usage of the channel, like | |
8287 | * disable specific events, for example. | |
8288 | */ | |
8289 | printf("Buffer usage is %f %% in recording session \"%s\", " | |
8290 | "user space channel \"%s\".\n", buffer_usage * 100, | |
8291 | recording_session_name, channel_name); | |
8292 | ||
8293 | /* Destroy the notification object. */ | |
8294 | lttng_notification_destroy(notification); | |
8295 | } | |
8296 | ||
8297 | end: | |
8298 | lttng_action_destroy(action); | |
8299 | lttng_condition_destroy(condition); | |
8300 | lttng_trigger_destroy(trigger); | |
8301 | lttng_notification_channel_destroy(notification_channel); | |
8302 | return exit_status; | |
8303 | } | |
8304 | ---- | |
8305 | -- | |
8306 | ||
8307 | . Build the `notif-app` application, linking it with `liblttng-ctl`: | |
8308 | + | |
8309 | -- | |
8310 | [role="term"] | |
8311 | ---- | |
8312 | $ gcc -o notif-app notif-app.c $(pkg-config --cflags --libs lttng-ctl) | |
8313 | ---- | |
8314 | -- | |
8315 | ||
8316 | . <<creating-destroying-tracing-sessions,Create a recording session>>, | |
8317 | <<enabling-disabling-events,create a recording event rule>> matching | |
8318 | all the user space tracepoint events, and | |
8319 | <<basic-tracing-session-control,start recording>>: | |
8320 | + | |
8321 | -- | |
8322 | [role="term"] | |
8323 | ---- | |
8324 | $ lttng create my-session | |
8325 | $ lttng enable-event --userspace --all | |
8326 | $ lttng start | |
8327 | ---- | |
8328 | -- | |
8329 | + | |
8330 | If you create the channel manually with the man:lttng-enable-channel(1) | |
8331 | command, you can set its <<channel-monitor-timer,monitor timer>> to | |
8332 | control how frequently LTTng samples the current values of the channel | |
8333 | properties to evaluate user conditions. | |
8334 | ||
8335 | . Run the `notif-app` application. | |
8336 | + | |
8337 | This program accepts the <<tracing-session,recording session>> and | |
8338 | user space channel names as its two first arguments. The channel | |
8339 | which LTTng automatically creates with the man:lttng-enable-event(1) | |
8340 | command above is named `channel0`: | |
8341 | + | |
8342 | -- | |
8343 | [role="term"] | |
8344 | ---- | |
8345 | $ ./notif-app my-session channel0 | |
8346 | ---- | |
8347 | -- | |
8348 | ||
8349 | . In another terminal, run an application with a very high event | |
8350 | throughput so that the 75{nbsp}% buffer usage condition is reached. | |
8351 | + | |
8352 | In the first terminal, the application should print lines like this: | |
8353 | + | |
8354 | ---- | |
8355 | Buffer usage is 81.45197 % in recording session "my-session", user space | |
8356 | channel "channel0". | |
8357 | ---- | |
8358 | + | |
8359 | If you don't see anything, try to make the threshold of the condition in | |
8360 | path:{notif-app.c} lower (0.1{nbsp}%, for example), and then rebuild the | |
8361 | `notif-app` application (step{nbsp}2) and run it again (step{nbsp}4). | |
8362 | ==== | |
8363 | ||
8364 | ||
8365 | [[reference]] | |
8366 | == Reference | |
8367 | ||
8368 | [[lttng-modules-ref]] | |
8369 | === noch:{LTTng-modules} | |
8370 | ||
8371 | ||
8372 | [role="since-2.9"] | |
8373 | [[lttng-tracepoint-enum]] | |
8374 | ==== `LTTNG_TRACEPOINT_ENUM()` usage | |
8375 | ||
8376 | Use the `LTTNG_TRACEPOINT_ENUM()` macro to define an enumeration: | |
8377 | ||
8378 | [source,c] | |
8379 | ---- | |
8380 | LTTNG_TRACEPOINT_ENUM(name, TP_ENUM_VALUES(entries)) | |
8381 | ---- | |
8382 | ||
8383 | Replace: | |
8384 | ||
8385 | * `name` with the name of the enumeration (C identifier, unique | |
8386 | amongst all the defined enumerations). | |
8387 | * `entries` with a list of enumeration entries. | |
8388 | ||
8389 | The available enumeration entry macros are: | |
8390 | ||
8391 | +ctf_enum_value(__name__, __value__)+:: | |
8392 | Entry named +__name__+ mapped to the integral value +__value__+. | |
8393 | ||
8394 | +ctf_enum_range(__name__, __begin__, __end__)+:: | |
8395 | Entry named +__name__+ mapped to the range of integral values between | |
8396 | +__begin__+ (included) and +__end__+ (included). | |
8397 | ||
8398 | +ctf_enum_auto(__name__)+:: | |
8399 | Entry named +__name__+ mapped to the integral value following the | |
8400 | last mapping value. | |
8401 | + | |
8402 | The last value of a `ctf_enum_value()` entry is its +__value__+ | |
8403 | parameter. | |
8404 | + | |
8405 | The last value of a `ctf_enum_range()` entry is its +__end__+ parameter. | |
8406 | + | |
8407 | If `ctf_enum_auto()` is the first entry in the list, its integral | |
8408 | value is 0. | |
8409 | ||
8410 | Use the `ctf_enum()` <<lttng-modules-tp-fields,field definition macro>> | |
8411 | to use a defined enumeration as a tracepoint field. | |
8412 | ||
8413 | .Define an enumeration with `LTTNG_TRACEPOINT_ENUM()`. | |
8414 | ==== | |
8415 | [source,c] | |
8416 | ---- | |
8417 | LTTNG_TRACEPOINT_ENUM( | |
8418 | my_enum, | |
8419 | TP_ENUM_VALUES( | |
8420 | ctf_enum_auto("AUTO: EXPECT 0") | |
8421 | ctf_enum_value("VALUE: 23", 23) | |
8422 | ctf_enum_value("VALUE: 27", 27) | |
8423 | ctf_enum_auto("AUTO: EXPECT 28") | |
8424 | ctf_enum_range("RANGE: 101 TO 303", 101, 303) | |
8425 | ctf_enum_auto("AUTO: EXPECT 304") | |
8426 | ) | |
8427 | ) | |
8428 | ---- | |
8429 | ==== | |
8430 | ||
8431 | ||
8432 | [role="since-2.7"] | |
8433 | [[lttng-modules-tp-fields]] | |
8434 | ==== Tracepoint fields macros (for `TP_FIELDS()`) | |
8435 | ||
8436 | [[tp-fast-assign]][[tp-struct-entry]]The available macros to define | |
8437 | tracepoint fields, which must be listed within `TP_FIELDS()` in | |
8438 | `LTTNG_TRACEPOINT_EVENT()`, are: | |
8439 | ||
8440 | [role="func-desc growable",cols="asciidoc,asciidoc"] | |
8441 | .Available macros to define LTTng-modules tracepoint fields | |
8442 | |==== | |
8443 | |Macro |Description and parameters | |
8444 | ||
8445 | | | |
8446 | +ctf_integer(__t__, __n__, __e__)+ | |
8447 | ||
8448 | +ctf_integer_nowrite(__t__, __n__, __e__)+ | |
8449 | ||
8450 | +ctf_user_integer(__t__, __n__, __e__)+ | |
8451 | ||
8452 | +ctf_user_integer_nowrite(__t__, __n__, __e__)+ | |
8453 | | | |
8454 | Standard integer, displayed in base{nbsp}10. | |
8455 | ||
8456 | +__t__+:: | |
8457 | Integer C type (`int`, `long`, `size_t`, ...). | |
8458 | ||
8459 | +__n__+:: | |
8460 | Field name. | |
8461 | ||
8462 | +__e__+:: | |
8463 | Argument expression. | |
8464 | ||
8465 | | | |
8466 | +ctf_integer_hex(__t__, __n__, __e__)+ | |
8467 | ||
8468 | +ctf_user_integer_hex(__t__, __n__, __e__)+ | |
8469 | | | |
8470 | Standard integer, displayed in base{nbsp}16. | |
8471 | ||
8472 | +__t__+:: | |
8473 | Integer C type. | |
8474 | ||
8475 | +__n__+:: | |
8476 | Field name. | |
8477 | ||
8478 | +__e__+:: | |
8479 | Argument expression. | |
8480 | ||
8481 | |+ctf_integer_oct(__t__, __n__, __e__)+ | |
8482 | | | |
8483 | Standard integer, displayed in base{nbsp}8. | |
8484 | ||
8485 | +__t__+:: | |
8486 | Integer C type. | |
8487 | ||
8488 | +__n__+:: | |
8489 | Field name. | |
8490 | ||
8491 | +__e__+:: | |
8492 | Argument expression. | |
8493 | ||
8494 | | | |
8495 | +ctf_integer_network(__t__, __n__, __e__)+ | |
8496 | ||
8497 | +ctf_user_integer_network(__t__, __n__, __e__)+ | |
8498 | | | |
8499 | Integer in network byte order (big-endian), displayed in base{nbsp}10. | |
8500 | ||
8501 | +__t__+:: | |
8502 | Integer C type. | |
8503 | ||
8504 | +__n__+:: | |
8505 | Field name. | |
8506 | ||
8507 | +__e__+:: | |
8508 | Argument expression. | |
8509 | ||
8510 | | | |
8511 | +ctf_integer_network_hex(__t__, __n__, __e__)+ | |
8512 | ||
8513 | +ctf_user_integer_network_hex(__t__, __n__, __e__)+ | |
8514 | | | |
8515 | Integer in network byte order, displayed in base{nbsp}16. | |
8516 | ||
8517 | +__t__+:: | |
8518 | Integer C type. | |
8519 | ||
8520 | +__n__+:: | |
8521 | Field name. | |
8522 | ||
8523 | +__e__+:: | |
8524 | Argument expression. | |
8525 | ||
8526 | | | |
8527 | +ctf_enum(__N__, __t__, __n__, __e__)+ | |
8528 | ||
8529 | +ctf_enum_nowrite(__N__, __t__, __n__, __e__)+ | |
8530 | ||
8531 | +ctf_user_enum(__N__, __t__, __n__, __e__)+ | |
8532 | ||
8533 | +ctf_user_enum_nowrite(__N__, __t__, __n__, __e__)+ | |
8534 | | | |
8535 | Enumeration. | |
8536 | ||
8537 | +__N__+:: | |
8538 | Name of a <<lttng-tracepoint-enum,previously defined enumeration>>. | |
8539 | ||
8540 | +__t__+:: | |
8541 | Integer C type (`int`, `long`, `size_t`, ...). | |
8542 | ||
8543 | +__n__+:: | |
8544 | Field name. | |
8545 | ||
8546 | +__e__+:: | |
8547 | Argument expression. | |
8548 | ||
8549 | | | |
8550 | +ctf_string(__n__, __e__)+ | |
8551 | ||
8552 | +ctf_string_nowrite(__n__, __e__)+ | |
8553 | ||
8554 | +ctf_user_string(__n__, __e__)+ | |
8555 | ||
8556 | +ctf_user_string_nowrite(__n__, __e__)+ | |
8557 | | | |
8558 | Null-terminated string; undefined behavior if +__e__+ is `NULL`. | |
8559 | ||
8560 | +__n__+:: | |
8561 | Field name. | |
8562 | ||
8563 | +__e__+:: | |
8564 | Argument expression. | |
8565 | ||
8566 | | | |
8567 | +ctf_array(__t__, __n__, __e__, __s__)+ | |
8568 | ||
8569 | +ctf_array_nowrite(__t__, __n__, __e__, __s__)+ | |
8570 | ||
8571 | +ctf_user_array(__t__, __n__, __e__, __s__)+ | |
8572 | ||
8573 | +ctf_user_array_nowrite(__t__, __n__, __e__, __s__)+ | |
8574 | | | |
8575 | Statically-sized array of integers. | |
8576 | ||
8577 | +__t__+:: | |
8578 | Array element C type. | |
8579 | ||
8580 | +__n__+:: | |
8581 | Field name. | |
8582 | ||
8583 | +__e__+:: | |
8584 | Argument expression. | |
8585 | ||
8586 | +__s__+:: | |
8587 | Number of elements. | |
8588 | ||
8589 | | | |
8590 | +ctf_array_bitfield(__t__, __n__, __e__, __s__)+ | |
8591 | ||
8592 | +ctf_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+ | |
8593 | ||
8594 | +ctf_user_array_bitfield(__t__, __n__, __e__, __s__)+ | |
8595 | ||
8596 | +ctf_user_array_bitfield_nowrite(__t__, __n__, __e__, __s__)+ | |
8597 | | | |
8598 | Statically-sized array of bits. | |
8599 | ||
8600 | The type of +__e__+ must be an integer type. +__s__+ is the number | |
8601 | of elements of such type in +__e__+, not the number of bits. | |
8602 | ||
8603 | +__t__+:: | |
8604 | Array element C type. | |
8605 | ||
8606 | +__n__+:: | |
8607 | Field name. | |
8608 | ||
8609 | +__e__+:: | |
8610 | Argument expression. | |
8611 | ||
8612 | +__s__+:: | |
8613 | Number of elements. | |
8614 | ||
8615 | | | |
8616 | +ctf_array_text(__t__, __n__, __e__, __s__)+ | |
8617 | ||
8618 | +ctf_array_text_nowrite(__t__, __n__, __e__, __s__)+ | |
8619 | ||
8620 | +ctf_user_array_text(__t__, __n__, __e__, __s__)+ | |
8621 | ||
8622 | +ctf_user_array_text_nowrite(__t__, __n__, __e__, __s__)+ | |
8623 | | | |
8624 | Statically-sized array, printed as text. | |
8625 | ||
8626 | The string doesn't need to be null-terminated. | |
8627 | ||
8628 | +__t__+:: | |
8629 | Array element C type (always `char`). | |
8630 | ||
8631 | +__n__+:: | |
8632 | Field name. | |
8633 | ||
8634 | +__e__+:: | |
8635 | Argument expression. | |
8636 | ||
8637 | +__s__+:: | |
8638 | Number of elements. | |
8639 | ||
8640 | | | |
8641 | +ctf_sequence(__t__, __n__, __e__, __T__, __E__)+ | |
8642 | ||
8643 | +ctf_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+ | |
8644 | ||
8645 | +ctf_user_sequence(__t__, __n__, __e__, __T__, __E__)+ | |
8646 | ||
8647 | +ctf_user_sequence_nowrite(__t__, __n__, __e__, __T__, __E__)+ | |
8648 | | | |
8649 | Dynamically-sized array of integers. | |
8650 | ||
8651 | The type of +__E__+ must be unsigned. | |
8652 | ||
8653 | +__t__+:: | |
8654 | Array element C type. | |
8655 | ||
8656 | +__n__+:: | |
8657 | Field name. | |
8658 | ||
8659 | +__e__+:: | |
8660 | Argument expression. | |
8661 | ||
8662 | +__T__+:: | |
8663 | Length expression C type. | |
8664 | ||
8665 | +__E__+:: | |
8666 | Length expression. | |
8667 | ||
8668 | | | |
8669 | +ctf_sequence_hex(__t__, __n__, __e__, __T__, __E__)+ | |
8670 | ||
8671 | +ctf_user_sequence_hex(__t__, __n__, __e__, __T__, __E__)+ | |
8672 | | | |
8673 | Dynamically-sized array of integers, displayed in base{nbsp}16. | |
8674 | ||
8675 | The type of +__E__+ must be unsigned. | |
8676 | ||
8677 | +__t__+:: | |
8678 | Array element C type. | |
8679 | ||
8680 | +__n__+:: | |
8681 | Field name. | |
8682 | ||
8683 | +__e__+:: | |
8684 | Argument expression. | |
8685 | ||
8686 | +__T__+:: | |
8687 | Length expression C type. | |
8688 | ||
8689 | +__E__+:: | |
8690 | Length expression. | |
8691 | ||
8692 | |+ctf_sequence_network(__t__, __n__, __e__, __T__, __E__)+ | |
8693 | | | |
8694 | Dynamically-sized array of integers in network byte order (big-endian), | |
8695 | displayed in base{nbsp}10. | |
8696 | ||
8697 | The type of +__E__+ must be unsigned. | |
8698 | ||
8699 | +__t__+:: | |
8700 | Array element C type. | |
8701 | ||
8702 | +__n__+:: | |
8703 | Field name. | |
8704 | ||
8705 | +__e__+:: | |
8706 | Argument expression. | |
8707 | ||
8708 | +__T__+:: | |
8709 | Length expression C type. | |
8710 | ||
8711 | +__E__+:: | |
8712 | Length expression. | |
8713 | ||
8714 | | | |
8715 | +ctf_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+ | |
8716 | ||
8717 | +ctf_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+ | |
8718 | ||
8719 | +ctf_user_sequence_bitfield(__t__, __n__, __e__, __T__, __E__)+ | |
8720 | ||
8721 | +ctf_user_sequence_bitfield_nowrite(__t__, __n__, __e__, __T__, __E__)+ | |
8722 | | | |
8723 | Dynamically-sized array of bits. | |
8724 | ||
8725 | The type of +__e__+ must be an integer type. +__s__+ is the number | |
8726 | of elements of such type in +__e__+, not the number of bits. | |
8727 | ||
8728 | The type of +__E__+ must be unsigned. | |
8729 | ||
8730 | +__t__+:: | |
8731 | Array element C type. | |
8732 | ||
8733 | +__n__+:: | |
8734 | Field name. | |
8735 | ||
8736 | +__e__+:: | |
8737 | Argument expression. | |
8738 | ||
8739 | +__T__+:: | |
8740 | Length expression C type. | |
8741 | ||
8742 | +__E__+:: | |
8743 | Length expression. | |
8744 | ||
8745 | | | |
8746 | +ctf_sequence_text(__t__, __n__, __e__, __T__, __E__)+ | |
8747 | ||
8748 | +ctf_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+ | |
8749 | ||
8750 | +ctf_user_sequence_text(__t__, __n__, __e__, __T__, __E__)+ | |
8751 | ||
8752 | +ctf_user_sequence_text_nowrite(__t__, __n__, __e__, __T__, __E__)+ | |
8753 | | | |
8754 | Dynamically-sized array, displayed as text. | |
8755 | ||
8756 | The string doesn't need to be null-terminated. | |
8757 | ||
8758 | The type of +__E__+ must be unsigned. | |
8759 | ||
8760 | The behaviour is undefined if +__e__+ is `NULL`. | |
8761 | ||
8762 | +__t__+:: | |
8763 | Sequence element C type (always `char`). | |
8764 | ||
8765 | +__n__+:: | |
8766 | Field name. | |
8767 | ||
8768 | +__e__+:: | |
8769 | Argument expression. | |
8770 | ||
8771 | +__T__+:: | |
8772 | Length expression C type. | |
8773 | ||
8774 | +__E__+:: | |
8775 | Length expression. | |
8776 | |==== | |
8777 | ||
8778 | Use the `_user` versions when the argument expression, `e`, is | |
8779 | a user space address. In the cases of `ctf_user_integer*()` and | |
8780 | `ctf_user_float*()`, `&e` must be a user space address, thus `e` must | |
8781 | be addressable. | |
8782 | ||
8783 | The `_nowrite` versions omit themselves from the trace data, but are | |
8784 | otherwise identical. This means LTTng won't write the `_nowrite` fields | |
8785 | to the recorded trace. Their primary purpose is to make some of the | |
8786 | event context available to the <<enabling-disabling-events,recording | |
8787 | event rule filters>> without having to commit the data to | |
8788 | <<channel,sub-buffers>>. | |
8789 | ||
8790 | ||
8791 | [[glossary]] | |
8792 | == Glossary | |
8793 | ||
8794 | Terms related to LTTng and to tracing in general: | |
8795 | ||
8796 | [[def-action]]action:: | |
8797 | The part of a <<def-trigger,trigger>> which LTTng executes when the | |
8798 | trigger <<def-condition,condition>> is satisfied. | |
8799 | ||
8800 | Babeltrace:: | |
8801 | The https://diamon.org/babeltrace[Babeltrace] project, which includes: | |
8802 | + | |
8803 | * The | |
8804 | https://babeltrace.org/docs/v2.0/man1/babeltrace2.1/[cmd:babeltrace2] | |
8805 | command-line interface. | |
8806 | * The libbabeltrace2 library which offers a | |
8807 | https://babeltrace.org/docs/v2.0/libbabeltrace2/[C API]. | |
8808 | * https://babeltrace.org/docs/v2.0/python/bt2/[Python{nbsp}3 bindings]. | |
8809 | * Plugins. | |
8810 | ||
8811 | [[def-buffering-scheme]]<<channel-buffering-schemes,buffering scheme>>:: | |
8812 | A layout of <<def-sub-buffer,sub-buffers>> applied to a given channel. | |
8813 | ||
8814 | [[def-channel]]<<channel,channel>>:: | |
8815 | An entity which is responsible for a set of | |
8816 | <<def-ring-buffer,ring buffers>>. | |
8817 | + | |
8818 | <<def-recording-event-rule,Recording event rules>> are always attached | |
8819 | to a specific channel. | |
8820 | ||
8821 | clock:: | |
8822 | A source of time for a <<def-tracer,tracer>>. | |
8823 | ||
8824 | [[def-condition]]condition:: | |
8825 | The part of a <<def-trigger,trigger>> which must be satisfied for | |
8826 | LTTng to attempt to execute the trigger <<def-action,actions>>. | |
8827 | ||
8828 | [[def-consumer-daemon]]<<lttng-consumerd,consumer daemon>>:: | |
8829 | A program which is responsible for consuming the full | |
8830 | <<def-sub-buffer,sub-buffers>> and write them to a file system or | |
8831 | send them over the network. | |
8832 | ||
8833 | [[def-current-trace-chunk]]current trace chunk:: | |
8834 | A <<def-trace-chunk,trace chunk>> which includes the current content | |
8835 | of all the <<def-sub-buffer,sub-buffers>> of the | |
8836 | <<def-tracing-session,recording session>> and the stream files | |
8837 | produced since the latest event amongst: | |
8838 | + | |
8839 | * The creation of the recording session. | |
8840 | * The last <<def-tracing-session-rotation,recording session rotation>>, if | |
8841 | any. | |
8842 | ||
8843 | <<channel-overwrite-mode-vs-discard-mode,discard mode>>:: | |
8844 | The <<def-event-record-loss-mode,event record loss mode>> in which | |
8845 | the <<def-tracer,tracer>> _discards_ new <<def-event-record,event | |
8846 | records>> when there's no <<def-sub-buffer,sub-buffer>> space left to | |
8847 | store them. | |
8848 | ||
8849 | [[def-event]]event:: | |
8850 | The execution of an <<def-instrumentation-point,instrumentation | |
8851 | point>>, like a <<def-tracepoint,tracepoint>> that you manually place | |
8852 | in some source code, or a Linux kprobe. | |
8853 | + | |
8854 | When an instrumentation point is executed, LTTng creates an event. | |
8855 | + | |
8856 | When an <<def-event-rule,event rule>> matches the event, | |
8857 | <<def-lttng,LTTng>> executes some action, for example: | |
8858 | + | |
8859 | * Record its payload to a <<def-sub-buffer,sub-buffer>> as an | |
8860 | <<def-event-record,event record>>. | |
8861 | * Attempt to execute the user-defined actions of a | |
8862 | <<def-trigger,trigger>> with an | |
8863 | <<add-event-rule-matches-trigger,``event rule matches''>> condition. | |
8864 | ||
8865 | [[def-event-name]]event name:: | |
8866 | The name of an <<def-event,event>>, which is also the name of the | |
8867 | <<def-event-record,event record>>. | |
8868 | + | |
8869 | This is also called the _instrumentation point name_. | |
8870 | ||
8871 | [[def-event-record]]event record:: | |
8872 | A record (binary serialization), in a <<def-trace,trace>>, of the | |
8873 | payload of an <<def-event,event>>. | |
8874 | + | |
8875 | The payload of an event record has zero or more _fields_. | |
8876 | ||
8877 | [[def-event-record-loss-mode]]<<channel-overwrite-mode-vs-discard-mode,event record loss mode>>:: | |
8878 | The mechanism by which event records of a given | |
8879 | <<def-channel,channel>> are lost (not recorded) when there's no | |
8880 | <<def-sub-buffer,sub-buffer>> space left to store them. | |
8881 | ||
8882 | [[def-event-rule]]<<event-rule,event rule>>:: | |
8883 | Set of conditions which an <<def-event,event>> must satisfy | |
8884 | for LTTng to execute some action. | |
8885 | + | |
8886 | An event rule is said to _match_ events, like a | |
8887 | https://en.wikipedia.org/wiki/Regular_expression[regular expression] | |
8888 | matches strings. | |
8889 | + | |
8890 | A <<def-recording-event-rule,recording event rule>> is a specific type | |
8891 | of event rule of which the action is to <<def-record,record>> the event | |
8892 | to a <<def-sub-buffer,sub-buffer>>. | |
8893 | ||
8894 | [[def-incl-set]]inclusion set:: | |
8895 | In the <<pid-tracking,process attribute inclusion set>> context: a | |
8896 | set of <<def-proc-attr,process attributes>> of a given type. | |
8897 | ||
8898 | <<instrumenting,instrumentation>>:: | |
8899 | The use of <<def-lttng,LTTng>> probes to make a kernel or | |
8900 | <<def-user-application,user application>> traceable. | |
8901 | ||
8902 | [[def-instrumentation-point]]instrumentation point:: | |
8903 | A point in the execution path of a kernel or | |
8904 | <<def-user-application,user application>> which, when executed, | |
8905 | create an <<def-event,event>>. | |
8906 | ||
8907 | instrumentation point name:: | |
8908 | See _<<def-event-name,event name>>_. | |
8909 | ||
8910 | `java.util.logging`:: | |
8911 | The | |
8912 | https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html[core logging facilities] | |
8913 | of the Java platform. | |
8914 | ||
8915 | log4j:: | |
8916 | A https://logging.apache.org/log4j/1.2/[logging library] for Java | |
8917 | developed by the Apache Software Foundation. | |
8918 | ||
8919 | log level:: | |
8920 | Level of severity of a log statement or user space | |
8921 | <<def-instrumentation-point,instrumentation point>>. | |
8922 | ||
8923 | [[def-lttng]]LTTng:: | |
8924 | The _Linux Trace Toolkit: next generation_ project. | |
8925 | ||
8926 | <<lttng-cli,cmd:lttng>>:: | |
8927 | A command-line tool provided by the <<def-lttng-tools,LTTng-tools>> | |
8928 | project which you can use to send and receive control messages to and | |
8929 | from a <<def-session-daemon,session daemon>>. | |
8930 | ||
8931 | LTTng analyses:: | |
8932 | The https://github.com/lttng/lttng-analyses[LTTng analyses] project, | |
8933 | which is a set of analyzing programs that you can use to obtain a | |
8934 | higher level view of an <<def-lttng,LTTng>> <<def-trace,trace>>. | |
8935 | ||
8936 | cmd:lttng-consumerd:: | |
8937 | The name of the <<def-consumer-daemon,consumer daemon>> program. | |
8938 | ||
8939 | cmd:lttng-crash:: | |
8940 | A utility provided by the <<def-lttng-tools,LTTng-tools>> project | |
8941 | which can convert <<def-ring-buffer,ring buffer>> files (usually | |
8942 | <<persistent-memory-file-systems,saved on a persistent memory file | |
8943 | system>>) to <<def-trace,trace>> files. | |
8944 | + | |
8945 | See man:lttng-crash(1). | |
8946 | ||
8947 | LTTng Documentation:: | |
8948 | This document. | |
8949 | ||
8950 | <<lttng-live,LTTng live>>:: | |
8951 | A communication protocol between the <<lttng-relayd,relay daemon>> and | |
8952 | live readers which makes it possible to show or analyze | |
8953 | <<def-event-record,event records>> ``live'', as they're received by | |
8954 | the <<def-relay-daemon,relay daemon>>. | |
8955 | ||
8956 | <<lttng-modules,LTTng-modules>>:: | |
8957 | The https://github.com/lttng/lttng-modules[LTTng-modules] project, | |
8958 | which contains the Linux kernel modules to make the Linux kernel | |
8959 | <<def-instrumentation-point,instrumentation points>> available for | |
8960 | <<def-lttng,LTTng>> tracing. | |
8961 | ||
8962 | cmd:lttng-relayd:: | |
8963 | The name of the <<def-relay-daemon,relay daemon>> program. | |
8964 | ||
8965 | cmd:lttng-sessiond:: | |
8966 | The name of the <<def-session-daemon,session daemon>> program. | |
8967 | ||
8968 | [[def-lttng-tools]]LTTng-tools:: | |
8969 | The https://github.com/lttng/lttng-tools[LTTng-tools] project, which | |
8970 | contains the various programs and libraries used to | |
8971 | <<controlling-tracing,control tracing>>. | |
8972 | ||
8973 | [[def-lttng-ust]]<<lttng-ust,LTTng-UST>>:: | |
8974 | The https://github.com/lttng/lttng-ust[LTTng-UST] project, which | |
8975 | contains libraries to instrument | |
8976 | <<def-user-application,user applications>>. | |
8977 | ||
8978 | <<lttng-ust-agents,LTTng-UST Java agent>>:: | |
8979 | A Java package provided by the <<def-lttng-ust,LTTng-UST>> project to | |
8980 | allow the LTTng instrumentation of `java.util.logging` and Apache | |
8981 | log4j{nbsp}1.2 logging statements. | |
8982 | ||
8983 | <<lttng-ust-agents,LTTng-UST Python agent>>:: | |
8984 | A Python package provided by the <<def-lttng-ust,LTTng-UST>> project | |
8985 | to allow the <<def-lttng,LTTng>> instrumentation of Python logging | |
8986 | statements. | |
8987 | ||
8988 | <<channel-overwrite-mode-vs-discard-mode,overwrite mode>>:: | |
8989 | The <<def-event-record-loss-mode,event record loss mode>> in which new | |
8990 | <<def-event-record,event records>> _overwrite_ older event records | |
8991 | when there's no <<def-sub-buffer,sub-buffer>> space left to store | |
8992 | them. | |
8993 | ||
8994 | <<channel-buffering-schemes,per-process buffering>>:: | |
8995 | A <<def-buffering-scheme,buffering scheme>> in which each instrumented | |
8996 | process has its own <<def-sub-buffer,sub-buffers>> for a given user | |
8997 | space <<def-channel,channel>>. | |
8998 | ||
8999 | <<channel-buffering-schemes,per-user buffering>>:: | |
9000 | A <<def-buffering-scheme,buffering scheme>> in which all the processes | |
9001 | of a Unix user share the same <<def-sub-buffer,sub-buffers>> for a | |
9002 | given user space <<def-channel,channel>>. | |
9003 | ||
9004 | [[def-proc-attr]]process attribute:: | |
9005 | In the <<pid-tracking,process attribute inclusion set>> context: | |
9006 | + | |
9007 | * A process ID. | |
9008 | * A virtual process ID. | |
9009 | * A Unix user ID. | |
9010 | * A virtual Unix user ID. | |
9011 | * A Unix group ID. | |
9012 | * A virtual Unix group ID. | |
9013 | ||
9014 | record (_noun_):: | |
9015 | See <<def-event-record,_event record_>>. | |
9016 | ||
9017 | [[def-record]]record (_verb_):: | |
9018 | Serialize the binary payload of an <<def-event,event>> to a | |
9019 | <<def-sub-buffer,sub-buffer>>. | |
9020 | ||
9021 | [[def-recording-event-rule]]<<event,recording event rule>>:: | |
9022 | Specific type of <<def-event-rule,event rule>> of which the action is | |
9023 | to <<def-record,record>> the matched event to a | |
9024 | <<def-sub-buffer,sub-buffer>>. | |
9025 | ||
9026 | [[def-tracing-session]][[def-recording-session]]<<tracing-session,recording session>>:: | |
9027 | A stateful dialogue between you and a <<lttng-sessiond,session daemon>>. | |
9028 | ||
9029 | [[def-tracing-session-rotation]]<<session-rotation,recording session rotation>>:: | |
9030 | The action of archiving the | |
9031 | <<def-current-trace-chunk,current trace chunk>> of a | |
9032 | <<def-tracing-session,recording session>>. | |
9033 | ||
9034 | [[def-relay-daemon]]<<lttng-relayd,relay daemon>>:: | |
9035 | A process which is responsible for receiving the <<def-trace,trace>> | |
9036 | data which a distant <<def-consumer-daemon,consumer daemon>> sends. | |
9037 | ||
9038 | [[def-ring-buffer]]ring buffer:: | |
9039 | A set of <<def-sub-buffer,sub-buffers>>. | |
9040 | ||
9041 | rotation:: | |
9042 | See _<<def-tracing-session-rotation,recording session rotation>>_. | |
9043 | ||
9044 | [[def-session-daemon]]<<lttng-sessiond,session daemon>>:: | |
9045 | A process which receives control commands from you and orchestrates | |
9046 | the <<def-tracer,tracers>> and various <<def-lttng,LTTng>> daemons. | |
9047 | ||
9048 | <<taking-a-snapshot,snapshot>>:: | |
9049 | A copy of the current data of all the <<def-sub-buffer,sub-buffers>> | |
9050 | of a given <<def-tracing-session,recording session>>, saved as | |
9051 | <<def-trace,trace>> files. | |
9052 | ||
9053 | [[def-sub-buffer]]sub-buffer:: | |
9054 | One part of an <<def-lttng,LTTng>> <<def-ring-buffer,ring buffer>> | |
9055 | which contains <<def-event-record,event records>>. | |
9056 | ||
9057 | timestamp:: | |
9058 | The time information attached to an <<def-event,event>> when LTTng | |
9059 | creates it. | |
9060 | ||
9061 | [[def-trace]]trace (_noun_):: | |
9062 | A set of: | |
9063 | + | |
9064 | * One https://diamon.org/ctf/[CTF] metadata stream file. | |
9065 | * One or more CTF data stream files which are the concatenations of one | |
9066 | or more flushed <<def-sub-buffer,sub-buffers>>. | |
9067 | ||
9068 | [[def-trace-verb]]trace (_verb_):: | |
9069 | From the perspective of a <<def-tracer,tracer>>: attempt to execute | |
9070 | one or more actions when emitting an <<def-event,event>> in an | |
9071 | application or in a system. | |
9072 | ||
9073 | [[def-trace-chunk]]trace chunk:: | |
9074 | A self-contained <<def-trace,trace>> which is part of a | |
9075 | <<def-tracing-session,recording session>>. Each | |
9076 | <<def-tracing-session-rotation, recording session rotation>> produces a | |
9077 | <<def-trace-chunk-archive,trace chunk archive>>. | |
9078 | ||
9079 | [[def-trace-chunk-archive]]trace chunk archive:: | |
9080 | The result of a <<def-tracing-session-rotation, recording session | |
9081 | rotation>>. | |
9082 | + | |
9083 | <<def-lttng,LTTng>> doesn't manage any trace chunk archive, even if its | |
9084 | containing <<def-tracing-session,recording session>> is still active: you | |
9085 | are free to read it, modify it, move it, or remove it. | |
9086 | ||
9087 | Trace Compass:: | |
9088 | The http://tracecompass.org[Trace Compass] project and application. | |
9089 | ||
9090 | [[def-tracepoint]]tracepoint:: | |
9091 | An instrumentation point using the tracepoint mechanism of the Linux | |
9092 | kernel or of <<def-lttng-ust,LTTng-UST>>. | |
9093 | ||
9094 | tracepoint definition:: | |
9095 | The definition of a single <<def-tracepoint,tracepoint>>. | |
9096 | ||
9097 | tracepoint name:: | |
9098 | The name of a <<def-tracepoint,tracepoint>>. | |
9099 | ||
9100 | [[def-tracepoint-provider]]tracepoint provider:: | |
9101 | A set of functions providing <<def-tracepoint,tracepoints>> to an | |
9102 | instrumented <<def-user-application,user application>>. | |
9103 | + | |
9104 | Not to be confused with a <<def-tracepoint-provider-package,tracepoint | |
9105 | provider package>>: many tracepoint providers can exist within a | |
9106 | tracepoint provider package. | |
9107 | ||
9108 | [[def-tracepoint-provider-package]]tracepoint provider package:: | |
9109 | One or more <<def-tracepoint-provider,tracepoint providers>> compiled | |
9110 | as an https://en.wikipedia.org/wiki/Object_file[object file] or as a | |
9111 | link:https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries[shared | |
9112 | library]. | |
9113 | ||
9114 | [[def-tracer]]tracer:: | |
9115 | A piece of software which executes some action when it emits | |
9116 | an <<def-event,event>>, like <<def-record,record>> it to some | |
9117 | buffer. | |
9118 | ||
9119 | <<domain,tracing domain>>:: | |
9120 | A type of LTTng <<def-tracer,tracer>>. | |
9121 | ||
9122 | <<tracing-group,tracing group>>:: | |
9123 | The Unix group which a Unix user can be part of to be allowed to | |
9124 | control the Linux kernel LTTng <<def-tracer,tracer>>. | |
9125 | ||
9126 | [[def-trigger]]<<trigger,trigger>>:: | |
9127 | A <<def-condition,condition>>-<<def-action,actions>> pair; when the | |
9128 | condition of a trigger is satisfied, LTTng attempts to execute its | |
9129 | actions. | |
9130 | ||
9131 | [[def-user-application]]user application:: | |
9132 | An application (program or library) running in user space, as opposed | |
9133 | to a Linux kernel module, for example. |