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