documentation update
[ust.git] / doc / manual / manual.texinfo
CommitLineData
5cd1099a
PMF
1\input texinfo @c -*-texinfo-*-
2@c %**start of header
3@setfilename ust.info
4@settitle LTTng Userspace Tracer (UST) Manual
5@c %**end of header
6
7@copying
8This manual is for program, version version.
9
10Copyright @copyright{} copyright-owner.
11
12@quotation
13Permission is granted to ...
14@end quotation
15@end copying
16
17@titlepage
18@title LTTng Userspace Tracer (UST) Manual
19@c @subtitle subtitle-if-any
20@c @subtitle second-subtitle
21@c @author author
22
23@c The following two commands
24@c start the copyright page.
25@c @page
26@c @vskip 0pt plus 1filll
27@c @insertcopying
28
29@c Published by ...
30@end titlepage
31
32@c So the toc is printed at the start.
33@contents
34
35@ifnottex
36@node Top
37@top LTTng Userspace Tracer
38
39This manual is for UST 0.1.
40@end ifnottex
41
42@menu
43* Overview::
44* Installation::
45* Quick start::
46* Instrumenting an application::
47* Recording a trace::
48* Viewing traces::
49* Performance::
50@c * Copying:: Your rights and freedoms.
51@end menu
52
53@node Overview
54@chapter Overview
55
56@menu
70e55dbe 57* What is UST?::
79f9fac7 58* License::
5cd1099a
PMF
59* Supported platforms::
60@end menu
61
70e55dbe
PMF
62@node What is UST?
63@section What is UST?
64
65The LTTng Userspace Tracer (UST) is a library accompanied by a set of tools to
66trace userspace code.
67
68Code may be instrumented with either markers or tracepoints. A highly efficient
69lockless tracer records these events to a trace buffers. These buffers are reaped
70by a deamon which writes trace data to disk.
71
72High performance is achieved by the use of lockless buffering algorithms, RCU and
73per-cpu buffers. In addition, special care is taken to minize cache impact.
74
79f9fac7
PMF
75@node License
76@section License
77The LTTng Userspace Tracer is intended to be linkable to open source software
78as well as to proprietary applications. This was accomplished by licensing
79the code that needs to be linked to the traced program as @acronym{LGPL}.
80
675ac4ab
PMF
81Components licensed as LGPL v2.1:
82@itemize @bullet
83@item libust
84@item libinterfork
85@item libustcomm
86@end itemize
87
88Components licensed as GPL v2:
89@itemize @bullet
90@item ustctl
91@item libustcmd
92@item ustd
93@end itemize
79f9fac7 94
5cd1099a
PMF
95@node Supported platforms
96@section Supported platforms
97
98UST can currently trace applications running on Linux, on the x86-32 and x86-64 architectures.
99
100@node Installation
101@chapter Installation
102
103The LTTng userspace tracer is a library and a set of userspace tools.
104
105The following packages are required:
106
107@itemize @bullet
108@item
109ust
110
111This contains the tracing library, the ustd daemon, trace control tools
112and other helper tools.
113
114Repository: http://git.dorsal.polymtl.ca
115
116@item
117libkcompat
118
119This is a library that contains a userspace port of some kernel APIs.
120
121Repository: http://git.dorsal.polymtl.ca
122
123@item
124liburcu
125
126This is the userspace read-copy update library by Mathieu Desnoyers.
127
128Available in Debian as package liburcu-dev.
129
130Home page: http://lttng.org/?q=node/18
131
132@item
133LTTV
134
135LTTV is a graphical (and text) viewer for LTTng traces.
136
137Home page: http://lttng.org
138
139@end itemize
140
141Libkcompat and liburcu should be installed first. UST may then be compiled
142and installed. LTTV has no dependency on the other packages; it may therefore
143be installed on a system which does not have UST installed.
144
145Refer to the README in each of these packages for installation instructions.
146
147@c @menu
148@c @end menu
149
150@node Quick start
151@chapter Quick start
152
153First, instrument a program with a marker.
154
155@example
156@verbatim
157
158#include <ust/marker.h>
159
160int main(int argc, char **argv)
161{
162 int v;
163 char *st;
164
165 /* ... set values of v and st ... */
166
167 /* a marker: */
168 trace_mark(ust, myevent, "firstarg %d secondarg %s", v, st);
169
170 /* a marker without arguments: */
171 trace_mark(ust, myotherevent, MARK_NOARGS);
172
173 return 0;
174}
175
176@end verbatim
177@end example
178
179Then compile it in the regular way, linking it with libust. For example:
180
181@example
182gcc -o foo -lust foo.c
183@end example
184
185Run the program with @command{usttrace}. The @command{usttrace} output says where the trace
186was written.
187
188@example
189usttrace ./foo
190@end example
191
192Finally, open the trace in LTTV.
193
194@example
195lttv-gui -t /path/to/trace
196@end example
197
198The trace can also be dumped as text in the console:
199
200@example
201lttv -m textDump -t /path/to/trace
202@end example
203
204@node Instrumenting an application
205@chapter Instrumenting an application
206
207In order to record a trace of events occurring in a application, the
208application must be instrumented. Instrumentation points resemble function
209calls. When the program reaches an instrumentation point, an event is
210generated.
211
212There are no limitations on the type of code that may be instrumented.
213Multi-threaded programs may be instrumented without problem. Signal handlers
214may be instrumented as well.
215
216There are two APIs to instrument programs: markers and tracepoints. Markers are
217quick to add and are usually used for temporary instrumentation. Tracepoints
218provide a way to instrument code more cleanly and are suited for permanent
219instrumentation.
220
221In addition to executable programs, shared libraries may also be instrumented
222with the methods described in this chapter.
223
224@menu
225* Markers::
226* Tracepoints::
227@end menu
228
229@node Markers
230@section Markers
231
70e55dbe 232Adding a marker is simply a matter of inserting one line in the program.
5cd1099a
PMF
233
234@example
235@verbatim
236#include <ust/marker.h>
237
238int main(int argc, char **argv)
239{
240 int v;
241 char *st;
242
243 /* ... set values of v and st ... */
244
245 /* a marker: */
246 trace_mark(main, myevent, "firstarg %d secondarg %s", v, st);
247
70e55dbe 248 /* another marker without arguments: */
5cd1099a
PMF
249 trace_mark(main, myotherevent, MARK_NOARGS);
250
251 return 0;
252}
253@end verbatim
254@end example
255
256The invocation of the trace_mark() macro requires at least 3 arguments. The
257first, here "main", is the name of the event category. It is also the name of
258the channel the event will go in. The second, here "myevent" is the name of the
259event. The third is a format string that announces the names and the types of
260the event arguments. Its format resembles that of a printf() format string; it
261is described thoroughly in Appendix x.
262
263A given Marker may appear more than once in the same program. Other Markers may
264have the same name and a different format string, although this might induce
265some confusion at analysis time.
266
267@node Tracepoints
268@section Tracepoints
269
270The Tracepoints API uses the Markers, but provides a higher-level abstraction.
271Whereas the markers API provides limited type checking, the Tracepoints API
272provides more thorough type checking and discharges from the need to insert
273format strings directly in the code and to have format strings appear more than
274once if a given marker is reused.
275
276@quotation Note Although this example uses @emph{mychannel} as the channel, the
277only channel name currently supported with early tracing is @strong{ust}. The
278@command{usttrace} tool always uses the early tracing mode. When using manual
279mode without early tracing, any channel name may be used. @end quotation
280
281A function instrumented with a tracepoint looks like this:
282
283@example
284@verbatim
285#include "tp.h"
286
287void function()
288{
289 int v;
290 char *st;
291
292 /* ... set values of v and st ... */
293
294 /* a tracepoint: */
295 trace_mychannel_myevent(v, st);
296}
297@end verbatim
298@end example
299
300Another file, here tp.h, contains declarations for the tracepoint.
301
302@example
303@verbatim
304#include <ust/tracepoint.h>
305
23e3d1f6
PMF
306DECLARE_TRACE(mychannel_myevent, TP_PROTO(int v, char *st),
307 TP_ARGS(v, st));
5cd1099a
PMF
308@end verbatim
309@end example
310
311A third file, here tp.c, contains definitions for the tracepoint.
312
313@example
314@verbatim
315#include <ust/marker.h>
316#include "tp.h"
317
318DEFINE_TRACE(mychannel_myevent);
319
320void mychannel_myevent_probe(int v, char *st)
321{
322 trace_mark(mychannel, myevent, "v %d st %s", v, st);
323}
324
325static void __attribute__((constructor)) init()
326{
327 register_trace_mychannel_myevent(mychannel_myevent_probe);
328}
329@end verbatim
330@end example
331
332Here, tp.h and tp.c could contain declarations and definitions for other
333tracepoints. The constructor would contain other register_* calls.
334
335@node Recording a trace
336@chapter Recording a trace
337
338@menu
339* Using @command{usttrace}::
340* Setting up the recording manually::
341* Using early tracing::
342* Crash recovery::
343* Tracing across @code{fork()} and @code{clone()}::
344* Tracing programs and libraries that were not linked to libust::
345@end menu
346
347@node Using @command{usttrace}
348@section Using @command{usttrace}
349
350The simplest way to record a trace is to use the @command{usttrace} script. An
351example is given in the quickstart above.
352
353The @command{usttrace} script automatically:
354@itemize @bullet
355@item creates a daemon
356@item enables all markers
357@item runs the command specified on the command line
358@item after the command ends, prints the location where the trace was saved
359@end itemize
360
361Each subdirectory of the save location contains the trace of one process that
362was generated by the command. The name of a subdirectory consists in the the PID
363of the process, followed by the timestamp of its creation.
364
365The save location also contains logs of the tracing.
366
367When using @command{usttrace}, the early tracing is always active, which means
368that the tracing is guaranteed to be started by the time the process enters its
369main() function.
370
371Several @command{usttrace}'s may be run simultaneously without risk of
372conflict. This facilitates the use of the tracer by idependent users on a
373system. Each instance of @command{usttrace} starts its own daemon which
374collects the events of the processes it creates.
375
376@node Setting up the recording manually
377@section Setting up the recording manually
378
379Instead of using @command{usttrace}, a trace may be recorded on an already
380running process.
381
382First the daemon must be started.
383
384@example
385@verbatim
386# Make sure the directory for the communication sockets exists.
387$ mkdir /tmp/ustsocks
388
389# Make sure the directory where ustd will write the trace exists.
390$ mkdir /tmp/trace
391
392# Start the daemon
393$ ustd
394
395# We assume the program we want to trace is already running and that
396# it has pid 1234.
397
398# List the available markers
399$ ustctl --list-markers 1234
400# A column indicates 0 for an inactive marker and 1 for an active marker.
401
402# Enable a marker
e61c1b29 403$ ustctl --enable-marker ust/mymark 1234
5cd1099a
PMF
404
405# Create a trace
406$ ustctl --create-trace 1234
407
408# Start tracing
409$ ustctl --start-trace 1234
410
411# Do things...
412
413# Stop tracing
414$ ustctl --stop-trace 1234
1af1f1db
PMF
415
416# Destroy the trace
417$ ustctl --destroy-trace 1234
5cd1099a
PMF
418@end verbatim
419@end example
420
c3947c25
PMF
421For more information about the manual mode, see the ustctl(1) man page.
422
5cd1099a
PMF
423@node Using early tracing
424@section Using early tracing
425
426Early tracing consists in starting the tracing as early as possible in the
427program, so no events are lost between program start and the point where the
428command to start the tracing is given. When using early tracing, it is
429guaranteed that by the time the traced program enters its @code{main()}
430function, the tracing will be started.
431
432When using @command{usttrace}, the early tracing is always active.
433
434When using the manual mode (@command{ustctl}), early tracing is enabled using
435environment variables. Setting @env{UST_TRACE} to @code{1}, enables early
436tracing, while setting @env{UST_AUTOPROBE} to @code{1} enables all markers
437automatically.
438
439
440@node Crash recovery
441@section Crash recovery
442
443When a process being traced crashes, the daemon is able to recover all the
444events in its buffers that were successfully commited. This is possible because
445the buffers are in a shared memory segment which remains available to the
446daemon even after the termination of the traced process.
447
448@node Tracing across @code{fork()} and @code{clone()}
449@section Tracing across @code{fork()} and @code{clone()}
450
2669948d
PMF
451Tracing across @code{clone()} when the @code{CLONE_VM} flag is specified is
452supported without any particular action.
5cd1099a
PMF
453
454When @code{clone()} is called without @code{CLONE_VM} or @code{fork()} is
455called, a new address space is created and the tracer must be notified to
2669948d
PMF
456create new buffers for it.
457
458This can be done automatically, by @env{LD_PRELOAD}'ing @file{libinterfork.so}.
459This library intercepts calls to @code{fork()} and informs the tracer it is
460being called. When using @command{usttrace}, this is accomplied by specifying
461the @option{-f} command line argument.
462
463Alternatively, the program can call @code{ust_before_fork()} before calling
464@code{fork()} or @code{clone()} with @code{CLONE_VM}. After the call,
465@code{ust_after_fork_parent()} must be called in the parent process and
466@code{ust_after_fork_child()} must be called in the child process.
5cd1099a 467
5cd1099a
PMF
468
469@node Tracing programs and libraries that were not linked to libust
470@section Tracing programs and libraries that were not linked to libust
471
2669948d
PMF
472Some programs need to be traced even though they were not linked to libust
473either because they were not instrumented or because it was not practical.
474
475An executable that is not instrumented can still yield interesting traces when
476at least one of its dynamic libraries is instrumented. It is also possible to
477trace certain function calls by intercepting them with a specially crafted
478library that is linked with @env{LD_PRELOAD} at program start.
479
480In any case, a program that was not linked to libust at compile time must be
481linked to it at run time with @env{LD_PRELOAD}. This can be accomplished with
482@command{usttrace}'s @option{-l} option. It can also be done by setting the
483@env{LD_PRELOAD} environment variable on the command line. For example:
484
485@example
486@verbatim
487# Run ls with usttrace, LD_PRELOAD'ing libust
488# (assuming one of the libraries used by ls is instrumented).
489$ usttrace -l ls
490
491# Run ls, manually adding the LD_PRELOAD.
492$ LD_PRELOAD=/usr/local/lib/libust.so.0 ls
493@end verbatim
494@end example
495
5cd1099a
PMF
496
497@node Performance
498@chapter Performance
499
500Todo.
501
502@node Viewing traces
503@chapter Viewing traces
504
2669948d
PMF
505Traces may be viewed with LTTV. An example of command for launching LTTV is
506given in the quickstart.
507
508@menu
509* Viewing multiple traces::
510* Combined kernel-userspace tracing::
511@end menu
512
513@node Viewing multiple traces
514@section Viewing multiple traces
515
516When tracing multi-process applications or several applications simultaneously,
517more than one trace will be obtained. LTTV can open and display all these
518traces simultaneously.
519
520@node Combined kernel-userspace tracing
521@section Combined kernel-userspace tracing
522
523In addition to multiple userspace traces, LTTV can open a kernel trace recorded
524with the LTTng kernel tracer. This provides events that enable the rendering of
525the Control Flow View and the Resource View.
526
527When doing so, it is necessary to use the same time source for the kernel
528tracer as well as the userspace tracer. Currently, the recommended method is to
529use the timestamp counter for both. The TSC can however only be used on architectures
530where it is synchronized across cores.
531
5cd1099a 532@bye
This page took 0.04557 seconds and 4 git commands to generate.