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