Update manual with license info
[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
79f9fac7 57* License::
5cd1099a
PMF
58* Supported platforms::
59@end menu
60
79f9fac7
PMF
61@node License
62@section License
63The LTTng Userspace Tracer is intended to be linkable to open source software
64as well as to proprietary applications. This was accomplished by licensing
65the code that needs to be linked to the traced program as @acronym{LGPL}.
66
67The @file{libust} library, including its headers, are licensed as @acronym{GNU}
68@acronym{LGPL} v2.1. It is also the case of some other helper libraries
69(@file{libmallocwrap}, @file{libinterfork}, @file{libustcomm}) that need to be linked to the traced
70program.
71
72The accompanying tools of the @acronym{UST} package are licensed as
73@acronym{GNU} @acronym{GPL} v2. These tools include the @file{ustctl} trace
74control program and the @file{ustd} daemon.
75
5cd1099a
PMF
76@node Supported platforms
77@section Supported platforms
78
79UST can currently trace applications running on Linux, on the x86-32 and x86-64 architectures.
80
81@node Installation
82@chapter Installation
83
84The LTTng userspace tracer is a library and a set of userspace tools.
85
86The following packages are required:
87
88@itemize @bullet
89@item
90ust
91
92This contains the tracing library, the ustd daemon, trace control tools
93and other helper tools.
94
95Repository: http://git.dorsal.polymtl.ca
96
97@item
98libkcompat
99
100This is a library that contains a userspace port of some kernel APIs.
101
102Repository: http://git.dorsal.polymtl.ca
103
104@item
105liburcu
106
107This is the userspace read-copy update library by Mathieu Desnoyers.
108
109Available in Debian as package liburcu-dev.
110
111Home page: http://lttng.org/?q=node/18
112
113@item
114LTTV
115
116LTTV is a graphical (and text) viewer for LTTng traces.
117
118Home page: http://lttng.org
119
120@end itemize
121
122Libkcompat and liburcu should be installed first. UST may then be compiled
123and installed. LTTV has no dependency on the other packages; it may therefore
124be installed on a system which does not have UST installed.
125
126Refer to the README in each of these packages for installation instructions.
127
128@c @menu
129@c @end menu
130
131@node Quick start
132@chapter Quick start
133
134First, instrument a program with a marker.
135
136@example
137@verbatim
138
139#include <ust/marker.h>
140
141int main(int argc, char **argv)
142{
143 int v;
144 char *st;
145
146 /* ... set values of v and st ... */
147
148 /* a marker: */
149 trace_mark(ust, myevent, "firstarg %d secondarg %s", v, st);
150
151 /* a marker without arguments: */
152 trace_mark(ust, myotherevent, MARK_NOARGS);
153
154 return 0;
155}
156
157@end verbatim
158@end example
159
160Then compile it in the regular way, linking it with libust. For example:
161
162@example
163gcc -o foo -lust foo.c
164@end example
165
166Run the program with @command{usttrace}. The @command{usttrace} output says where the trace
167was written.
168
169@example
170usttrace ./foo
171@end example
172
173Finally, open the trace in LTTV.
174
175@example
176lttv-gui -t /path/to/trace
177@end example
178
179The trace can also be dumped as text in the console:
180
181@example
182lttv -m textDump -t /path/to/trace
183@end example
184
185@node Instrumenting an application
186@chapter Instrumenting an application
187
188In order to record a trace of events occurring in a application, the
189application must be instrumented. Instrumentation points resemble function
190calls. When the program reaches an instrumentation point, an event is
191generated.
192
193There are no limitations on the type of code that may be instrumented.
194Multi-threaded programs may be instrumented without problem. Signal handlers
195may be instrumented as well.
196
197There are two APIs to instrument programs: markers and tracepoints. Markers are
198quick to add and are usually used for temporary instrumentation. Tracepoints
199provide a way to instrument code more cleanly and are suited for permanent
200instrumentation.
201
202In addition to executable programs, shared libraries may also be instrumented
203with the methods described in this chapter.
204
205@menu
206* Markers::
207* Tracepoints::
208@end menu
209
210@node Markers
211@section Markers
212
213Adding a marker is simply a matter of insert one line in the program.
214
215@example
216@verbatim
217#include <ust/marker.h>
218
219int main(int argc, char **argv)
220{
221 int v;
222 char *st;
223
224 /* ... set values of v and st ... */
225
226 /* a marker: */
227 trace_mark(main, myevent, "firstarg %d secondarg %s", v, st);
228
229 /* a marker without arguments: */
230 trace_mark(main, myotherevent, MARK_NOARGS);
231
232 return 0;
233}
234@end verbatim
235@end example
236
237The invocation of the trace_mark() macro requires at least 3 arguments. The
238first, here "main", is the name of the event category. It is also the name of
239the channel the event will go in. The second, here "myevent" is the name of the
240event. The third is a format string that announces the names and the types of
241the event arguments. Its format resembles that of a printf() format string; it
242is described thoroughly in Appendix x.
243
244A given Marker may appear more than once in the same program. Other Markers may
245have the same name and a different format string, although this might induce
246some confusion at analysis time.
247
248@node Tracepoints
249@section Tracepoints
250
251The Tracepoints API uses the Markers, but provides a higher-level abstraction.
252Whereas the markers API provides limited type checking, the Tracepoints API
253provides more thorough type checking and discharges from the need to insert
254format strings directly in the code and to have format strings appear more than
255once if a given marker is reused.
256
257@quotation Note Although this example uses @emph{mychannel} as the channel, the
258only channel name currently supported with early tracing is @strong{ust}. The
259@command{usttrace} tool always uses the early tracing mode. When using manual
260mode without early tracing, any channel name may be used. @end quotation
261
262A function instrumented with a tracepoint looks like this:
263
264@example
265@verbatim
266#include "tp.h"
267
268void function()
269{
270 int v;
271 char *st;
272
273 /* ... set values of v and st ... */
274
275 /* a tracepoint: */
276 trace_mychannel_myevent(v, st);
277}
278@end verbatim
279@end example
280
281Another file, here tp.h, contains declarations for the tracepoint.
282
283@example
284@verbatim
285#include <ust/tracepoint.h>
286
287DECLARE_TRACE(mychannel_myevent, TPPROTO(int v, char *st),
288 TPARGS(v, st));
289@end verbatim
290@end example
291
292A third file, here tp.c, contains definitions for the tracepoint.
293
294@example
295@verbatim
296#include <ust/marker.h>
297#include "tp.h"
298
299DEFINE_TRACE(mychannel_myevent);
300
301void mychannel_myevent_probe(int v, char *st)
302{
303 trace_mark(mychannel, myevent, "v %d st %s", v, st);
304}
305
306static void __attribute__((constructor)) init()
307{
308 register_trace_mychannel_myevent(mychannel_myevent_probe);
309}
310@end verbatim
311@end example
312
313Here, tp.h and tp.c could contain declarations and definitions for other
314tracepoints. The constructor would contain other register_* calls.
315
316@node Recording a trace
317@chapter Recording a trace
318
319@menu
320* Using @command{usttrace}::
321* Setting up the recording manually::
322* Using early tracing::
323* Crash recovery::
324* Tracing across @code{fork()} and @code{clone()}::
325* Tracing programs and libraries that were not linked to libust::
326@end menu
327
328@node Using @command{usttrace}
329@section Using @command{usttrace}
330
331The simplest way to record a trace is to use the @command{usttrace} script. An
332example is given in the quickstart above.
333
334The @command{usttrace} script automatically:
335@itemize @bullet
336@item creates a daemon
337@item enables all markers
338@item runs the command specified on the command line
339@item after the command ends, prints the location where the trace was saved
340@end itemize
341
342Each subdirectory of the save location contains the trace of one process that
343was generated by the command. The name of a subdirectory consists in the the PID
344of the process, followed by the timestamp of its creation.
345
346The save location also contains logs of the tracing.
347
348When using @command{usttrace}, the early tracing is always active, which means
349that the tracing is guaranteed to be started by the time the process enters its
350main() function.
351
352Several @command{usttrace}'s may be run simultaneously without risk of
353conflict. This facilitates the use of the tracer by idependent users on a
354system. Each instance of @command{usttrace} starts its own daemon which
355collects the events of the processes it creates.
356
357@node Setting up the recording manually
358@section Setting up the recording manually
359
360Instead of using @command{usttrace}, a trace may be recorded on an already
361running process.
362
363First the daemon must be started.
364
365@example
366@verbatim
367# Make sure the directory for the communication sockets exists.
368$ mkdir /tmp/ustsocks
369
370# Make sure the directory where ustd will write the trace exists.
371$ mkdir /tmp/trace
372
373# Start the daemon
374$ ustd
375
376# We assume the program we want to trace is already running and that
377# it has pid 1234.
378
379# List the available markers
380$ ustctl --list-markers 1234
381# A column indicates 0 for an inactive marker and 1 for an active marker.
382
383# Enable a marker
384$ ustctl --enable-marker 1234 ust/mymark
385
386# Create a trace
387$ ustctl --create-trace 1234
388
389# Start tracing
390$ ustctl --start-trace 1234
391
392# Do things...
393
394# Stop tracing
395$ ustctl --stop-trace 1234
1af1f1db
PMF
396
397# Destroy the trace
398$ ustctl --destroy-trace 1234
5cd1099a
PMF
399@end verbatim
400@end example
401
402@node Using early tracing
403@section Using early tracing
404
405Early tracing consists in starting the tracing as early as possible in the
406program, so no events are lost between program start and the point where the
407command to start the tracing is given. When using early tracing, it is
408guaranteed that by the time the traced program enters its @code{main()}
409function, the tracing will be started.
410
411When using @command{usttrace}, the early tracing is always active.
412
413When using the manual mode (@command{ustctl}), early tracing is enabled using
414environment variables. Setting @env{UST_TRACE} to @code{1}, enables early
415tracing, while setting @env{UST_AUTOPROBE} to @code{1} enables all markers
416automatically.
417
418
419@node Crash recovery
420@section Crash recovery
421
422When a process being traced crashes, the daemon is able to recover all the
423events in its buffers that were successfully commited. This is possible because
424the buffers are in a shared memory segment which remains available to the
425daemon even after the termination of the traced process.
426
427@node Tracing across @code{fork()} and @code{clone()}
428@section Tracing across @code{fork()} and @code{clone()}
429
430Tracing across @code{clone()} when @code{CLONE_VM} is specified is supported
431without any particular action.
432
433When @code{clone()} is called without @code{CLONE_VM} or @code{fork()} is
434called, a new address space is created and the tracer must be notified to
435create new buffers for it. @strong{TODO: specify how to do it.}
436
437This can be done automatically (for @code{fork()} only for now), by
438@env{LD_PRELOAD}'ing @file{libinterfork.so}. This library intercepts calls to
439@code{fork()} and informs the tracer it is being called. When using
440@command{usttrace}, this is accomplied by specifying the @option{-f} command
441line argument.
442
443@node Tracing programs and libraries that were not linked to libust
444@section Tracing programs and libraries that were not linked to libust
445
446Todo.
447
448@node Performance
449@chapter Performance
450
451Todo.
452
453@node Viewing traces
454@chapter Viewing traces
455
456@bye
This page took 0.037356 seconds and 4 git commands to generate.