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