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