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