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