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