5be3cfaa081a669cb8d9b9e990117dd63f9bc735
[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
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"
21 .PP
22 The simple way to generate the lttng-ust tracepoint probes is to use the
23 lttng-gen-tp(1) tool. See the lttng-gen-tp(1) manpage for explanation.
24 .PP
25
26 .PP
27 Here is the way to do it manually, without the lttng-gen-tp(1) helper
28 script, through an example:
29 .PP
30
31 .SH "CREATION OF TRACEPOINT PROVIDER"
32
33 .nf
34
35 To create a tracepoint provider, within a build tree similar to
36 examples/easy-ust installed with lttng-ust documentation, a
37 sample_component_provider.h for the general layout. This manpage will
38 focus on the various types that can be recorded into a trace event:
39
40 TRACEPOINT_EVENT(
41 /*
42 * provider name, not a variable but a string starting with a
43 * letter and containing either letters, numbers or underscores.
44 * Needs to be the same as TRACEPOINT_PROVIDER. Needs to
45 * follow the namespacing guide-lines in lttng/tracepoint.h:
46 *
47 * Must be included before include tracepoint provider
48 * ex.: project_event
49 * ex.: project_component_event
50 *
51 * Optional company name goes here
52 * ex.: com_efficios_project_component_event
53 *
54 * In this example, "sample" is the project, and "component" is the
55 * component.
56 */
57 sample_component,
58
59 /*
60 * tracepoint name, same format as sample provider. Does not
61 * need to be declared before. in this case the name is
62 * "message"
63 */
64 message,
65
66 /*
67 * TP_ARGS macro contains the arguments passed for the tracepoint
68 * it is in the following format
69 * TP_ARGS(type1, name1, type2, name2, ... type10,
70 name10)
71 * where there can be from zero to ten elements.
72 * typeN is the datatype, such as int, struct or double **.
73 * name is the variable name (in "int myInt" the name would be
74 * myint)
75 * TP_ARGS() is valid to mean no arguments
76 * TP_ARGS(void) is valid too
77 */
78 TP_ARGS(int, anint, int, netint, long *, values,
79 char *, text, size_t, textlen,
80 double, doublearg, float, floatarg),
81
82 /*
83 * TP_FIELDS describes how to write the fields of the trace event.
84 * You can put expressions in the "argument expression" area,
85 * typically using the input arguments from TP_ARGS.
86 */
87 TP_FIELDS(
88 /*
89 * ctf_integer: standard integer field.
90 * args: (type, field name, argument expression)
91 */
92 ctf_integer(int, intfield, anint)
93 ctf_integer(long, longfield, anint)
94
95 /*
96 * ctf_integer_hex: integer field printed as hexadecimal.
97 * args: (type, field name, argument expression)
98 */
99 ctf_integer_hex(int, intfield2, anint)
100
101 /*
102 * ctf_integer_network: integer field in network byte
103 * order. (_hex: printed as hexadecimal too)
104 * args: (type, field name, argument expression)
105 */
106 ctf_integer_network(int, netintfield, netint)
107 ctf_integer_network_hex(int, netintfieldhex, netint)
108
109 /*
110 * ctf_array: a statically-sized array.
111 * args: (type, field name, argument expression, value)
112 */
113 ctf_array(long, arrfield1, values, 3)
114
115 /*
116 * ctf_array_text: a statically-sized array, printed as
117 * a string. No need to be terminated by a null
118 * character.
119 */
120 ctf_array_text(char, arrfield2, text, 10)
121
122 /*
123 * ctf_sequence: a dynamically-sized array.
124 * args: (type, field name, argument expression,
125 * type of length expression, length expression)
126 * The "type of length expression" needs to be an
127 * unsigned type. As a reminder, "unsigned char" should
128 * be preferred to "char", since the signedness of
129 * "char" is implementation-defined.
130 */
131 ctf_sequence(char, seqfield1, text,
132 size_t, textlen)
133
134 /*
135 * ctf_sequence_text: a dynamically-sized array, printed
136 * as string. No need to be null-terminated.
137 */
138 ctf_sequence_text(char, seqfield2, text,
139 size_t, textlen)
140
141 /*
142 * ctf_string: null-terminated string.
143 * args: (field name, argument expression)
144 */
145 ctf_string(stringfield, text)
146
147 /*
148 * ctf_float: floating-point number.
149 * args: (type, field name, argument expression)
150 */
151 ctf_float(float, floatfield, floatarg)
152 ctf_float(double, doublefield, doublearg)
153 )
154 )
155 .fi
156
157 .SH "ASSIGNING LOGLEVEL TO EVENTS"
158
159 .nf
160
161 Optionally, a loglevel can be assigned to a TRACEPOINT_EVENT using the
162 following construct:
163
164 TRACEPOINT_LOGLEVEL(< [com_company_]project[_component] >,
165 < event >, < loglevel_name >)
166
167 The first field is the provider name, the second field is the name of
168 the tracepoint, and the third field is the loglevel name. A
169 TRACEPOINT_EVENT should be declared prior to the the TRACEPOINT_LOGLEVEL
170 for a given tracepoint name. The TRACEPOINT_PROVIDER must be already
171 declared before declaring a TRACEPOINT_LOGLEVEL.
172
173 The loglevels go from 0 to 14. Higher numbers imply the most verbosity
174 (higher event throughput expected.
175
176 Loglevels 0 through 6, and loglevel 14, match syslog(3) loglevels
177 semantic. Loglevels 7 through 13 offer more fine-grained selection of
178 debug information.
179
180 TRACE_EMERG 0
181 system is unusable
182
183 TRACE_ALERT 1
184 action must be taken immediately
185
186 TRACE_CRIT 2
187 critical conditions
188
189 TRACE_ERR 3
190 error conditions
191
192 TRACE_WARNING 4
193 warning conditions
194
195 TRACE_NOTICE 5
196 normal, but significant, condition
197
198 TRACE_INFO 6
199 informational message
200
201 TRACE_DEBUG_SYSTEM 7
202 debug information with system-level scope (set of programs)
203
204 TRACE_DEBUG_PROGRAM 8
205 debug information with program-level scope (set of processes)
206
207 TRACE_DEBUG_PROCESS 9
208 debug information with process-level scope (set of modules)
209
210 TRACE_DEBUG_MODULE 10
211 debug information with module (executable/library) scope (set of
212 units)
213
214 TRACE_DEBUG_UNIT 11
215 debug information with compilation unit scope (set of functions)
216
217 TRACE_DEBUG_FUNCTION 12
218 debug information with function-level scope
219
220 TRACE_DEBUG_LINE 13
221 debug information with line-level scope (TRACEPOINT_EVENT default)
222
223 TRACE_DEBUG 14
224 debug-level message (trace_printf default)
225
226 See lttng(1) for information on how to use LTTng-UST loglevels.
227
228 .fi
229
230 .SH "ADDING TRACEPOINTS TO YOUR CODE"
231
232 .nf
233
234 Include the provider header in each C files you plan to instrument,
235 following the building/linking directives in the next section.
236
237 For instance, add within a function:
238
239 tracepoint(ust_tests_hello, tptest, i, netint, values,
240 text, strlen(text), dbl, flt);
241
242 As a call to the tracepoint. It will only be activated when requested by
243 lttng(1) through lttng-sessiond(8).
244
245 Even though LTTng-UST supports tracepoint() call site duplicates having
246 the same provider and event name, it is recommended to use a
247 provider event name pair only once within the source code to help
248 mapping events back to their call sites when analyzing the trace.
249 .fi
250
251 .SH "BUILDING/LINKING THE TRACEPOINT PROVIDER"
252
253 .nf
254 There are 2 ways to compile the Tracepoint Provider with the
255 application: either statically or dynamically. Please follow
256 carefully:
257
258 1.1) Compile the Tracepoint provider with the application, either
259 directly or through a static library (.a):
260 - Into exactly one object of your application: define
261 "TRACEPOINT_DEFINE" and include the tracepoint provider.
262 - Use "\-I." for the compilation unit containing the tracepoint
263 provider include (e.g. tp.c).
264 - Link application with "\-ldl".
265 - If building the provider directly into the application,
266 link the application with "\-llttng-ust".
267 - If building a static library for the provider, link the static
268 library with "\-llttng-ust".
269 - Include the tracepoint provider header into all C files using
270 the provider.
271 - Example:
272 - tests/hello/ hello.c tp.c ust_tests_hello.h Makefile.example
273
274 2) Compile the Tracepoint Provider separately from the application,
275 using dynamic linking:
276 - Into exactly one object of your application: define
277 "TRACEPOINT_DEFINE" _and_ also define
278 "TRACEPOINT_PROBE_DYNAMIC_LINKAGE", then include the tracepoint
279 provider header.
280 - Include the tracepoint provider header into all instrumented C
281 files that use the provider.
282 - Compile the tracepoint provider with "\-I.".
283 - Link the tracepoint provider with "\-llttng-ust".
284 - Link application with "\-ldl".
285 - Set a LD_PRELOAD environment to preload the tracepoint provider
286 shared object before starting the application when tracing is
287 needed. Another way is to dlopen the tracepoint probe when needed
288 by the application.
289 - Example:
290 - doc/examples/demo demo.c tp*.c ust_tests_demo*.h demo-trace
291
292 - Note about dlclose() usage: it is not safe to use dlclose on a
293 provider shared object that is being actively used for tracing due
294 to a lack of reference counting from lttng-ust to the used shared
295 object.
296 - Enable instrumentation and control tracing with the "lttng" command
297 from lttng-tools. See lttng-tools doc/quickstart.txt.
298 - Note for C++ support: although an application instrumented with
299 tracepoints can be compiled with g++, tracepoint probes should be
300 compiled with gcc (only tested with gcc so far).
301
302 .fi
303
304 .SH "USING LTTNG UST WITH DAEMONS"
305
306 .nf
307 Some extra care is needed when using liblttng-ust with daemon
308 applications that call fork(), clone(), or BSD rfork() without a
309 following exec() family system call. The library "liblttng-ust-fork.so"
310 needs to be preloaded for the application (launch with e.g.
311 LD_PRELOAD=liblttng-ust-fork.so appname).
312
313 .fi
314
315 .SH "CONTEXT"
316
317 .PP
318 Context information can be prepended by the tracer before each, or some,
319 events. The following context information is supported by LTTng-UST:
320 .PP
321
322 .PP
323 .IP "vtid"
324 Virtual thread ID: thread ID as seen from the point of view of the
325 process namespace.
326 .PP
327
328 .PP
329 .IP "vpid"
330 Virtual process ID: process ID as seen from the point of view of the
331 process namespace.
332 .PP
333
334 .PP
335 .IP "procname"
336 Thread name, as set by exec() or prctl(). It is recommended that
337 programs set their thread name with prctl() before hitting the first
338 tracepoint for that thread.
339 .PP
340
341 .PP
342 .IP "pthread_id"
343 Pthread identifier. Can be used on architectures where pthread_t maps
344 nicely to an unsigned long type.
345 .PP
346
347 .SH "ENVIRONMENT VARIABLES"
348
349 .PP
350 .IP "LTTNG_UST_DEBUG"
351 Activate liblttng-ust debug output.
352 .PP
353 .IP "LTTNG_UST_REGISTER_TIMEOUT"
354 The environment variable "LTTNG_UST_REGISTER_TIMEOUT" can be used to
355 specify how long the applications should wait for sessiond
356 "registration done" command before proceeding to execute the main
357 program. The default is 3000ms (3 seconds). The timeout value is
358 specified in milliseconds. The value 0 means "don't wait". The value
359 \-1 means "wait forever". Setting this environment variable to 0 is
360 recommended for applications with time constraints on the process
361 startup time.
362 .PP
363
364 .SH "SEE ALSO"
365
366 .PP
367 lttng-gen-tp(1), lttng(1), babeltrace(1), lttng-ust-cyg-profile(3),
368 lttng-sessiond(8)
369 .PP
370 .SH "BUGS"
371
372 .PP
373 No known bugs at this point.
374
375 If you encounter any issues or usability problem, please report it on
376 our mailing list <lttng-dev@lists.lttng.org> to help improve this
377 project.
378 .SH "CREDITS"
379
380 liblttng-ust is distributed under the GNU Lesser General Public License
381 version 2.1. The headers are distributed under the MIT license.
382 .PP
383 See http://lttng.org for more information on the LTTng project.
384 .PP
385 Mailing list for support and development: <lttng-dev@lists.lttng.org>.
386 .PP
387 You can find us on IRC server irc.oftc.net (OFTC) in #lttng.
388 .PP
389 .SH "THANKS"
390
391 Thanks to Ericsson for funding this work, providing real-life use-cases,
392 and testing.
393
394 Special thanks to Michel Dagenais and the DORSAL laboratory at
395 Polytechnique de Montreal for the LTTng journey.
396 .PP
397 .SH "AUTHORS"
398
399 .PP
400 liblttng-ust was originally written by Mathieu Desnoyers, with additional
401 contributions from various other people. It is currently maintained by
402 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>.
403 .PP
This page took 0.036702 seconds and 3 git commands to generate.