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