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