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