398498913f104e6456bb87abedf38b7fc7f12e84
[lttng-ust.git] / doc / man / lttng-ust.3
1 .TH "LTTNG-UST" "3" "February 16, 2012" "" ""
2
3 .SH "NAME"
4 lttng-ust \(em Linux Trace Toolkit Next Generation User-Space Tracer 2.x
5
6 .SH "SYNOPSIS"
7
8 .PP
9 .nf
10 Link liblttng-ust.so with applications, following this manpage.
11 .fi
12 .SH "DESCRIPTION"
13
14 .PP
15 LTTng-UST, the Linux Trace Toolkit Next Generation Userspace Tracer, is a
16 port of the low-overhead tracing capabilities of the LTTng kernel tracer
17 to user-space. The library "liblttng-ust" enables tracing of
18 applications and libraries.
19
20 .SH "USAGE WITH TRACEF"
21 .PP
22 The simplest way to add instrumentation to your code is by far the
23 tracef() API. To do it, in a nutshell:
24
25 1) #include <lttng/tracef.h>
26
27 2) /* in your code, use like a printf */
28 tracef("my message, this integer %d", 1234);
29
30 3) Link your program against liblttng-ust.so.
31
32 4) Enable UST events when tracing with the following sequence of commands
33 from lttng-tools:
34
35 lttng create
36 lttng enable-event -u -a
37 lttng start
38 [... run your program ...]
39 lttng stop
40 lttng view
41
42 That's it!
43
44 If you want to have more flexibility and control on the event names,
45 payload typing, etc, you can continue reading on and use the tracepoints
46 below. "tracef()" is there for quick and dirty ad hoc instrumentation,
47 whereas tracepoint.h is meant for thorough instrumentation of a code
48 base to be integrated with an upstream project.
49 .PP
50
51 .SH "USAGE WITH TRACELOG"
52 .PP
53 If you want to migrate existing logging (info, errors, ...)
54 to LTTng UST, you can use the tracelog() interface.
55 To do it, in a nutshell:
56
57 1) #include <lttng/tracelog.h>
58
59 2) /* in your code, use like a printf, with extra loglevel info. */
60 tracelog(TRACE_INFO, "Message with integer %d", 1234);
61
62 3) Link your program against liblttng-ust.so.
63
64 4) Enable UST events when tracing with the following sequence of commands
65 from lttng-tools:
66
67 lttng create
68 lttng enable-event -u "lttng_ust_tracelog:*"
69 lttng start
70 [... run your program ...]
71 lttng stop
72 lttng view
73
74 That's it!
75
76 You can replace the enable-event line above with a selection of
77 loglevels, e.g.:
78
79 lttng enable-event -u -a --loglevel TRACE_INFO
80
81 Which will gather all events from TRACE_INFO and more important
82 loglevels.
83
84 .PP
85
86 .SH "USAGE WITH TRACEPOINT"
87 .PP
88 The simple way to generate the lttng-ust tracepoint probes is to use the
89 lttng-gen-tp(1) tool. See the lttng-gen-tp(1) manpage for explanation.
90 .PP
91
92 .PP
93 Here is the way to do it manually, without the lttng-gen-tp(1) helper
94 script, through an example:
95 .PP
96
97 .SH "CREATION OF TRACEPOINT PROVIDER"
98
99 .nf
100
101 To create a tracepoint provider, within a build tree similar to
102 examples/easy-ust installed with lttng-ust documentation, see
103 sample_component_provider.h for the general layout. You will need to
104 define TRACEPOINT_CREATE_PROBES before including your tracepoint
105 provider probe in one source file of your application. See tp.c from
106 easy-ust for an example of a tracepoint probe source file. This manpage
107 will focus on the various types that can be recorded into a trace
108 event:
109
110 TRACEPOINT_EVENT(
111 /*
112 * provider name, not a variable but a string starting with a
113 * letter and containing either letters, numbers or underscores.
114 * Needs to be the same as TRACEPOINT_PROVIDER. Needs to
115 * follow the namespacing guide-lines in lttng/tracepoint.h:
116 *
117 * Must be included before include tracepoint provider
118 * ex.: project_event
119 * ex.: project_component_event
120 *
121 * Optional company name goes here
122 * ex.: com_efficios_project_component_event
123 *
124 * In this example, "sample" is the project, and "component" is the
125 * component.
126 */
127 sample_component,
128
129 /*
130 * tracepoint name, characters permitted follow the same
131 * constraints as the provider name. The name of this example
132 * event is "sample_event".
133 */
134 sample_event,
135
136 /*
137 * TP_ARGS macro contains the arguments passed for the tracepoint
138 * it is in the following format
139 * TP_ARGS(type1, name1, type2, name2, ... type10,
140 name10)
141 * where there can be from zero to ten elements.
142 * typeN is the datatype, such as int, struct or double **.
143 * name is the variable name (in "int myInt" the name would be
144 * myint)
145 * TP_ARGS() is valid to mean no arguments
146 * TP_ARGS(void) is valid too
147 */
148 TP_ARGS(int, anint, int, netint, long *, values,
149 char *, text, size_t, textlen,
150 double, doublearg, float, floatarg),
151
152 /*
153 * TP_FIELDS describes how to write the fields of the trace event.
154 * You can put expressions in the "argument expression" area,
155 * typically using the input arguments from TP_ARGS.
156 */
157 TP_FIELDS(
158 /*
159 * ctf_integer: standard integer field.
160 * args: (type, field name, argument expression)
161 */
162 ctf_integer(int, intfield, anint)
163 ctf_integer(long, longfield, anint)
164
165 /*
166 * ctf_integer_hex: integer field printed as hexadecimal.
167 * args: (type, field name, argument expression)
168 */
169 ctf_integer_hex(int, intfield2, anint)
170
171 /*
172 * ctf_integer_network: integer field in network byte
173 * order. (_hex: printed as hexadecimal too)
174 * args: (type, field name, argument expression)
175 */
176 ctf_integer_network(int, netintfield, netint)
177 ctf_integer_network_hex(int, netintfieldhex, netint)
178
179 /*
180 * ctf_array: a statically-sized array.
181 * args: (type, field name, argument expression, value)
182 */
183 ctf_array(long, arrfield1, values, 3)
184
185 /*
186 * ctf_array_text: a statically-sized array, printed as
187 * a string. No need to be terminated by a null
188 * character.
189 * Behavior is undefined if "text" argument is NULL.
190 */
191 ctf_array_text(char, arrfield2, text, 10)
192
193 /*
194 * ctf_sequence: a dynamically-sized array.
195 * args: (type, field name, argument expression,
196 * type of length expression, length expression)
197 * The "type of length expression" needs to be an
198 * unsigned type. As a reminder, "unsigned char" should
199 * be preferred to "char", since the signedness of
200 * "char" is implementation-defined.
201 * Behavior is undefined if "text" argument is NULL.
202 */
203 ctf_sequence(char, seqfield1, text,
204 size_t, textlen)
205
206 /*
207 * ctf_sequence_text: a dynamically-sized array, printed
208 * as string. No need to be null-terminated.
209 * Behavior is undefined if "text" argument is NULL.
210 */
211 ctf_sequence_text(char, seqfield2, text,
212 size_t, textlen)
213
214 /*
215 * ctf_string: null-terminated string.
216 * args: (field name, argument expression)
217 * Behavior is undefined if "text" argument is NULL.
218 */
219 ctf_string(stringfield, text)
220
221 /*
222 * ctf_float: floating-point number.
223 * args: (type, field name, argument expression)
224 */
225 ctf_float(float, floatfield, floatarg)
226 ctf_float(double, doublefield, doublearg)
227 )
228 )
229
230 There can be an arbitrary number of tracepoint providers within an
231 application, but they must each have their own provider name. Duplicate
232 provider names are not allowed.
233
234 .fi
235
236 .SH "ASSIGNING LOGLEVEL TO EVENTS"
237
238 .nf
239
240 Optionally, a loglevel can be assigned to a TRACEPOINT_EVENT using the
241 following construct:
242
243 TRACEPOINT_LOGLEVEL(< [com_company_]project[_component] >,
244 < event >, < loglevel_name >)
245
246 The first field is the provider name, the second field is the name of
247 the tracepoint, and the third field is the loglevel name. A
248 TRACEPOINT_EVENT should be declared prior to the the TRACEPOINT_LOGLEVEL
249 for a given tracepoint name. The TRACEPOINT_PROVIDER must be already
250 declared before declaring a TRACEPOINT_LOGLEVEL.
251
252 The loglevels go from 0 to 14. Higher numbers imply the most verbosity
253 (higher event throughput expected.
254
255 Loglevels 0 through 6, and loglevel 14, match syslog(3) loglevels
256 semantic. Loglevels 7 through 13 offer more fine-grained selection of
257 debug information.
258
259 TRACE_EMERG 0
260 system is unusable
261
262 TRACE_ALERT 1
263 action must be taken immediately
264
265 TRACE_CRIT 2
266 critical conditions
267
268 TRACE_ERR 3
269 error conditions
270
271 TRACE_WARNING 4
272 warning conditions
273
274 TRACE_NOTICE 5
275 normal, but significant, condition
276
277 TRACE_INFO 6
278 informational message
279
280 TRACE_DEBUG_SYSTEM 7
281 debug information with system-level scope (set of programs)
282
283 TRACE_DEBUG_PROGRAM 8
284 debug information with program-level scope (set of processes)
285
286 TRACE_DEBUG_PROCESS 9
287 debug information with process-level scope (set of modules)
288
289 TRACE_DEBUG_MODULE 10
290 debug information with module (executable/library) scope (set of
291 units)
292
293 TRACE_DEBUG_UNIT 11
294 debug information with compilation unit scope (set of functions)
295
296 TRACE_DEBUG_FUNCTION 12
297 debug information with function-level scope
298
299 TRACE_DEBUG_LINE 13
300 debug information with line-level scope (TRACEPOINT_EVENT default)
301
302 TRACE_DEBUG 14
303 debug-level message
304
305 See lttng(1) for information on how to use LTTng-UST loglevels.
306
307 .fi
308
309 .SH "ADDING TRACEPOINTS TO YOUR CODE"
310
311 .nf
312
313 Include the provider header in each C files you plan to instrument,
314 following the building/linking directives in the next section.
315
316 For instance, add within a function:
317
318 tracepoint(ust_tests_hello, tptest, i, netint, values,
319 text, strlen(text), dbl, flt);
320
321 As a call to the tracepoint. It will only be activated when requested by
322 lttng(1) through lttng-sessiond(8).
323
324 Even though LTTng-UST supports tracepoint() call site duplicates having
325 the same provider and event name, it is recommended to use a
326 provider event name pair only once within the source code to help
327 map events back to their call sites when analyzing the trace.
328
329 Sometimes arguments to the probe are expensive to compute (e.g.
330 take call stack). To avoid the computation when the tracepoint is
331 disabled one can use more 'low level' tracepoint_enabled() and
332 do_tracepoint() macros as following:
333
334 if (tracepoint_enabled(ust_tests_hello, tptest)) {
335 /* prepare arguments */
336 do_tracepoint(ust_tests_hello, tptest, i, netint, values,
337 text, strlen(text), dbl, flt);
338 }
339
340 Here do_tracepoint() doesn't contain check if the tracepoint is enabled.
341 Using tracepoint() in such scenario is dangerous since it also contains
342 enabled check and thus race condition is possible in the following code
343 if the tracepoint has been enabled after check in tracepoint_enabled()
344 but before tracepoint():
345
346 if (tracepoint_enabled(provider, name)) { /* tracepoint is disabled */
347 prepare(args);
348 }
349 /* tracepoint is enabled by 'lttng' tool */
350 tracepoint(provider, name, args); /* args wasn't prepared properly */
351
352 Note also that neither tracepoint_enabled() nor do_tracepoint() have
353 STAP_PROBEV() call so if you need it you should emit this call yourself.
354
355 .fi
356
357 .SH "BUILDING/LINKING THE TRACEPOINT PROVIDER"
358
359 .nf
360 There are 2 ways to compile the Tracepoint Provider with the
361 application: either statically or dynamically. Please follow
362 carefully:
363
364 1) Compile the Tracepoint Provider with the application, either
365 directly or through a static library (.a):
366 - Into exactly one object of your application, define
367 "TRACEPOINT_DEFINE" and include the tracepoint provider.
368 - Use "\-I." for the compilation unit containing the tracepoint
369 provider include (e.g., tp.c).
370 - Link the application with "\-llttng-ust" and "\-ldl".
371 - Include the tracepoint provider header into all C files using
372 the provider.
373 - Examples:
374 - doc/examples/easy-ust/ sample.c sample_component_provider.h tp.c
375 Makefile
376 - doc/examples/hello-static-lib/ hello.c tp.c ust_test_hello.h Makefile
377
378 2) Compile the Tracepoint Provider separately from the application,
379 using dynamic linking:
380 - Into exactly one object of your application: define
381 "TRACEPOINT_DEFINE" _and_ also define
382 "TRACEPOINT_PROBE_DYNAMIC_LINKAGE", then include the tracepoint
383 provider header.
384 - Include the tracepoint provider header into all instrumented C
385 files that use the provider.
386 - Compile the tracepoint provider with "\-I.".
387 - Link the tracepoint provider with "\-llttng-ust".
388 - Link application with "\-ldl".
389 - Set a LD_PRELOAD environment to preload the tracepoint provider
390 shared object before starting the application when tracing is
391 needed. Another way is to dlopen the tracepoint probe when needed
392 by the application.
393 - Example:
394 - doc/examples/demo demo.c tp*.c ust_tests_demo*.h demo-trace Makefile
395
396 - Note about dlclose() usage: it is not safe to use dlclose on a
397 provider shared object that is being actively used for tracing due
398 to a lack of reference counting from lttng-ust to the used shared
399 object.
400 - Enable instrumentation and control tracing with the "lttng" command
401 from lttng-tools. See lttng-tools doc/quickstart.txt.
402 - Note for C++ support: although an application instrumented with
403 tracepoints can be compiled with g++, tracepoint probes should be
404 compiled with gcc (only tested with gcc so far).
405
406 .fi
407
408 .SH "USING LTTNG UST WITH DAEMONS"
409
410 .nf
411 Some extra care is needed when using liblttng-ust with daemon
412 applications that call fork(), clone(), or BSD rfork() without a
413 following exec() family system call. The library "liblttng-ust-fork.so"
414 needs to be preloaded for the application (launch with e.g.
415 LD_PRELOAD=liblttng-ust-fork.so appname).
416
417 .fi
418
419 .SH "CONTEXT"
420
421 .PP
422 Context information can be prepended by the tracer before each, or some,
423 events. The following context information is supported by LTTng-UST:
424 .PP
425
426 .PP
427 .IP "vtid"
428 Virtual thread ID: thread ID as seen from the point of view of the
429 process namespace.
430 .PP
431
432 .PP
433 .IP "vpid"
434 Virtual process ID: process ID as seen from the point of view of the
435 process namespace.
436 .PP
437
438 .PP
439 .IP "ip"
440 Instruction pointer: Enables recording of the exact location where a tracepoint
441 was emitted. Can be used to reverse-lookup the source location that caused the
442 event to be emitted.
443 .PP
444
445 .PP
446 .IP "procname"
447 Thread name, as set by exec() or prctl(). It is recommended that
448 programs set their thread name with prctl() before hitting the first
449 tracepoint for that thread.
450 .PP
451
452 .PP
453 .IP "pthread_id"
454 Pthread identifier. Can be used on architectures where pthread_t maps
455 nicely to an unsigned long type.
456 .PP
457
458 .SH "BASE ADDRESS STATEDUMP"
459
460 .PP
461 If an application that uses liblttng-ust.so becomes part of a session,
462 information about its currently loaded shared objects will be traced to the
463 session at session-enable time. To record this information, the following event
464 needs to be enabled:
465 .PP
466 .IP "ust_baddr_statedump:soinfo"
467 This event is used to trace a currently loaded shared object. The base address
468 (where the dynamic linker has placed the shared object) is recorded in the
469 "baddr" field. The path to the shared object gets recorded in the
470 "sopath" field (as string). The file size of the loaded object (in
471 bytes) is recorded to the "size" field and its time of last modification
472 (in seconds since Epoch) is recorded in the "mtime" field.
473 .PP
474 If the event above is enabled, a series of "ust_baddr_statedump:soinfo"
475 events is recorded at session-enable time. It represents the state of
476 currently loaded shared objects for the traced process. If this
477 information gets combined with the lttng-ust-dl(3) instrumentation, all
478 aspects of dynamic loading that are relevant for symbol and
479 line number lookup are traced by LTTng.
480 .PP
481 .SH "ENVIRONMENT VARIABLES"
482
483 .PP
484 .IP "LTTNG_UST_DEBUG"
485 Activate liblttng-ust debug and error output.
486 .PP
487 .IP "LTTNG_UST_REGISTER_TIMEOUT"
488 The environment variable "LTTNG_UST_REGISTER_TIMEOUT" can be used to
489 specify how long the applications should wait for sessiond
490 "registration done" command before proceeding to execute the main
491 program. The default is 3000ms (3 seconds). The timeout value is
492 specified in milliseconds. The value 0 means "don't wait". The value
493 \-1 means "wait forever". Setting this environment variable to 0 is
494 recommended for applications with time constraints on the process
495 startup time.
496 .PP
497 .IP "LTTNG_UST_WITHOUT_BADDR_STATEDUMP"
498 Prevent liblttng-ust to perform a base-address statedump on session-enable.
499 .PP
500 .IP "LTTNG_UST_GETCPU_PLUGIN"
501 Used by the getcpu override plugin system. The environment variable
502 provides the path to the shared object which will act as the getcpu override
503 plugin. An example can be found in the lttng-ust documentation under
504 examples/getcpu-override .
505 .PP
506 .IP "LTTNG_UST_CLOCK_PLUGIN"
507 Used by the clock override plugin system. The environment variable
508 provides the path to the shared object wich will act as the clock override
509 plugin. An example can be found in the lttng-ust documentation under
510 doc/examples/clock-override .
511 .PP
512
513 .SH "SEE ALSO"
514
515 .PP
516 lttng-gen-tp(1), lttng(1), babeltrace(1), lttng-ust-cyg-profile(3),
517 lttng-ust-dl(3), lttng-sessiond(8)
518 .PP
519
520 .SH "COMPATIBILITY"
521
522 .PP
523 Older lttng-ust libraries reject more recent, and incompatible, probe
524 providers. Newer lttng-ust libraries accept older probe providers, even
525 though some newer features might not be available with those providers.
526 .PP
527
528 .SH "BUGS"
529
530 .PP
531 LTTng-UST 2.0 and 2.1 lttng-ust libraries do not check for probe
532 provider version compatibility. This can lead to out-of-bound accesses
533 when using a more recent probe provider with an older lttng-ust library.
534 These error only trigger when tracing is active. This issue has been
535 fixed in LTTng-UST 2.2.
536
537 If you encounter any issues or usability problem, please report it on
538 our mailing list <lttng-dev@lists.lttng.org> to help improve this
539 project.
540 .SH "CREDITS"
541
542 liblttng-ust is distributed under the GNU Lesser General Public License
543 version 2.1. The headers are distributed under the MIT license.
544 .PP
545 See http://lttng.org for more information on the LTTng project.
546 .PP
547 Mailing list for support and development: <lttng-dev@lists.lttng.org>.
548 .PP
549 You can find us on IRC server irc.oftc.net (OFTC) in #lttng.
550 .PP
551 .SH "THANKS"
552
553 Thanks to Ericsson for funding this work, providing real-life use-cases,
554 and testing.
555
556 Special thanks to Michel Dagenais and the DORSAL laboratory at
557 Polytechnique de Montreal for the LTTng journey.
558 .PP
559 .SH "AUTHORS"
560
561 .PP
562 liblttng-ust was originally written by Mathieu Desnoyers, with additional
563 contributions from various other people. It is currently maintained by
564 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>.
565 .PP
This page took 0.038987 seconds and 3 git commands to generate.