convert from svn repository: remove tags directory
[lttv.git] / trunk / obsolete / ltt-usertrace / README
CommitLineData
15146922 1
141274aa 2LTTng usertrace package
15146922 3
4Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
5March 2006
6
7This package contains all the user space headers and c files necessary to make
8your application and library trace through an active LTTng tracer. Here is a
9short quickstart guide of it.
10
11Here are the currently supported architectures :
12x86
141274aa 13(please add the ltt_trace_generic and ltt_register_generic system calls to
14other architectures as you need them : it will work magically)
15146922 15
16* Compile your kernel with the latest LTTng patch. Make sure the option
51a4c0d0 17 "Allow tracing from userspace" is _active_!
18 See the QUICKSTART guide at http://ltt.polymtl.ca/ for details about how to
19 setup a working tracer and viewer. See the genevent installation step : it is
20 required for method #2 below.
21
141274aa 22* Extract the latest ltt-usertrace archive :
15146922 23su
24cd /usr/src
141274aa 25wget http://ltt.polymtl.ca/packages/ltt-usertrace-x.x.tar.gz
26gzip -cd ltt-usertrace-x.x.tar.gz | tar xvof -
15146922 27
141274aa 28* Build the sample programs and install the headers and librairies into your
29system :
3a4541a5 30(32 bits)
15146922 31su
c47538ac 32cd /usr/src/ltt-usertrace
3a4541a5 33make clean
34make install (will build and install headers and libraries)
15146922 35make
3a4541a5 36(64 bits)
37su
38cd /usr/src/ltt-usertrace
39make clean
40LIB_DIR=/usr/lib64 make install CFLAGS=-m64
41make CFLAGS=-m64
15146922 42
141274aa 43Feel free to look at the sample programs and the Makefile : they demonstrate
44very well the features of the usertrace package and how to use them.
45
c47538ac 46* There are three ways to trace information from your application. The choice
47 will principally depend on the trace data rate.
15146922 48
491) Easy way, but slow (printf style)
51a4c0d0 50 See sample-printf.c for code example.
15146922 51
52- Add the following statements to your program source (the define must come
51a4c0d0 53 _before_ the includes!) :
15146922 54
55#define LTT_TRACE
56#define LTT_BLOCKING 1
57#include <ltt/ltt-facility-user_generic.h>
58#include <ltt/ltt-facility-custom-user_generic.h>
59
60Note the define of LTT_BLOCKING to 1 : if a trace buffer is full, your
61application will block. The default of this parameter is 0 (non blocking) :
62events are lost when trace buffer is full. The choice is up to you.
63
64- Add something like the following sample line in your code. Note that this is a
51a4c0d0 65 very standard format string, this is only a suggested presentation.
66
15146922 67trace_user_generic_slow_printf("in: %s at: %s:%d: Counter value is: %u.",
68 __FILE__, __func__, __LINE__, count);
69
70- Compile your application with at least these parameters to gcc (it is splitted
51a4c0d0 71 on two lines, joined by a "\") :
15146922 72gcc -D LTT_SHOW_DEBUG -I /usr/src/usertrace-generic -o myapp myapp.c \
73 /usr/src/usertrace-generic/ltt-facility-loader-user_generic.c
74
75To see what the final result looks like :
76- Start tracing
77- Start your application
51a4c0d0 78 ** You should see the following message when your program starts and the
79 LTT_SHOW_DEBUG is defined :
80 "LTT : ltt-facility-user_generic init in userspace"
81 If you don't then you forgot to compile the facility loader in your
82 application. If you find this output annoying, you can remove the
83 "-D LTT_SHOW_DEBUG" gcc parameter, which will make the facility loader
84 silent.
15146922 85- Stop tracing
86Then, to see only the user_generic events :
87lttv -m textDump -t /tmp/trace1 -e "event.facility=user_generic"
88
89It will show :
90user_generic.slow_printf: 35885.922829472 (/cpu_0), 15521, 7453, SYSCALL { "in: sample-printf.c at: main:18: Counter value is: 0." }
91user_generic.slow_printf: 35886.925685289 (/cpu_0), 15521, 7453, SYSCALL { "in: sample-printf.c at: main:18: Counter value is: 1." }
92...
93
94
95
c47538ac 962) The second way to log events is still easy. The advantage is that it
97 will make it easier to identify your data in the trace viewer afterward.
98 Please read the comments in method 1) explained previously, as they
99 are not repeated here.
100 See sample.c and sample-thread-slow.c for code example.
15146922 101
c47538ac 102- Go to the ltt-usertrace directory
15146922 103su
c47538ac 104cd /usr/src/ltt-usertrace
15146922 105
106- Create your own facility (i.e. user_myfacility.xml).
107 See the ones available in /usr/share/LinuxTraceToolkitViewer/facilities for
51a4c0d0 108 examples.
109 You facility _must_ be named following this standard : "user_*", where * is
110 whatever you like. If it is not, it will be rejected by the kernel with a
111 Operation not permitted (can be seen with the -D LTT_SHOW_DEBUG compilation
112 parameter).
15146922 113
114user_myfacility.xml:
115
50bb790b 116<?xml version="1.0"?>
15146922 117<facility name="user_myfacility">
51a4c0d0 118 <description>Sample facility</description>
119 <event name="myevent">
120 <description>Sample event</description>
121 <field name="file"><string></field>
122 <field name="function"><string></field>
123 <field name="line"><int></field>
124 <field name="firstval"><long></field>
125 <field name="secondval"><pointer></field>
126 </event>
15146922 127</facility>
128
129- AN IMPORTANT STEP FOLLOWS :
51a4c0d0 130 *copy* the user_myfacility.xml file in your system :
15146922 131su
132cp user_myfacility.xml /usr/share/LinuxTraceToolkitViewer/facilities
133
134- Use genevent to create the c code and headers :
135su
136cd /tmp
137mkdir genevent
138cd genevent
139for a in /usr/share/LinuxTraceToolkitViewer/facilities/user_*.xml;
51a4c0d0 140 do /usr/local/bin/genevent $a;
15146922 141done
142cd /usr/src/usertrace-generic
143cp /tmp/genevent/*load* .
144cd ltt
145cp /tmp/genevent/ltt-facility-id-user_myfacility.h .
146cp /tmp/genevent/ltt-facility-user_myfacility.h .
147cd ..
148make install
149
150- Add the following statements to your program source (the define must come
51a4c0d0 151 _before_ the includes!) :
15146922 152
153#define LTT_TRACE
154#define LTT_BLOCKING 1
155#include <ltt/ltt-facility-user_myfacility.h>
156
157- Add a call following the trace_user_myfacility_myevent function found in
51a4c0d0 158 /usr/include/ltt/ltt-facility-user_myfacility.h in your program.
15146922 159For instance :
160trace_user_myfacility_myevent(__FILE__, __func__, __LINE__, 1234, (void*)0xF0F0F0F0);
161
162- Compile your application with at least these parameters to gcc (it is splitted
51a4c0d0 163 on two lines, joined by a "\") :
15146922 164gcc -I /usr/src/usertrace-generic -o myapp myapp.c \
165 /usr/src/usertrace-generic/ltt-facility-loader-user_myfacility.c
166
167To see what the final result looks like :
168- Start tracing
169- Start your application
170- Stop tracing
171Then, to see only the user_myfacility events :
172lttv -m textDump -t /tmp/trace1 -e "event.facility=user_myfacility"
173
174It will show, for example :
175user_myfacility.myevent: 39507.805584526 (/cpu_1), 15829, 15736, SYSCALL { "myapp.c", "main", 8, 1234, 0xf0f0f0f0 }
176
177
c47538ac 1783) The third way to trace information from your application
179
180This method is cleary the _FASTEST_. It is principally I/O (disk and memory)
181bound. It will create a companion process for each of you program's thread which
182will dump the tracing information into /tmp/ltt-usertrace.
183
184See sample-highspeed.c and sample-thread-fast.c for code example.
185
186- Add the following statements to your program source (the define must come
187 _before_ the includes!) :
188
189#define LTT_TRACE
190#define LTT_TRACE_FAST
191#include <ltt/ltt-facility-user_myfacility.h>
192
193- Add a call following the trace_user_myfacility_myevent function found in
194 /usr/include/ltt/ltt-facility-user_myfacility.h in your program.
195For instance :
196trace_user_myfacility_myevent(__FILE__, __func__, __LINE__, 1234, (void*)0xF0F0F0F0);
197
198- Compile your application with at least these parameters to gcc (it is splitted
199 on two lines, joined by a "\") :
200gcc -lltt-usertrace-fast -I /usr/src/usertrace-generic -o myapp myapp.c \
201 /usr/src/usertrace-generic/ltt-facility-loader-user_myfacility.c
202
203It requires a supplementary operation when you take the trace :
204- Start tracing (with lttctl)
205- Start your application
206- Let your application run...
207- Stop tracing
208- Move or copy /tmp/ltt-usertrace info your trace.
209i.e., if your trace is in /tmp/trace1 :
210su
211mv /tmp/ltt-usertrace /tmp/trace1
212
213
214Then, to see only the user_myfacility events :
215lttv -m textDump -t /tmp/trace1 -e "event.facility=user_myfacility"
216
217It will show, for example :
218user_myfacility.myevent: 39507.805584526 (/ltt-usertrace/process-26174.26174.39236180500380_0), 15829, 15736, USER_MODE { "myapp.c", "main", 8, 1234, 0xf0f0f0f0 }
219
220
221
e90c7b86 222* Fun feature : function instrumentation
223
224Here is how to generate a full trace of you program function calls.
225See the sample-instrument-fct.c example program.
226
227- Compile your application with at least these parameters to gcc (it is splitted
228 on two lines, joined by a "\") :
6c5b57ff 229gcc -g -finstrument-functions \
230 -lltt-instrument-functions -o myapp myapp.c
e90c7b86 231
232To see what the final result looks like :
233- Start tracing
234- Start your application
235- Stop tracing
236Then, to see only the function_entry and function_exit events :
237lttv -m textDump -t /tmp/trace1 -e "event.facility=user_generic & (event.name=function_entry & event.name=function_exit)"
238
239It will show, for example :
c47538ac 240user_generic.function_entry: 59329.709939111 (/ltt-usertrace/process-26202.0.39949996866578_0), 19250, 18581, USER_MODE { 0x8048454, 0x80484c2 }
241user_generic.function_exit: 59329.709944613 (/ltt-usertrace/process-26202.0.39949996866578_0), 19250, 18581, USER_MODE { 0x8048454, 0x80484c2 }
e90c7b86 242
243you can then use (from the binutils package)
244addr2line -e sample-instrument-fct -i -f 0x8048454
245Which shows :
246test_function
247/usr/src/usertrace-generic/sample-instrument-fct.c:12
248
249The lookup in LTTV through libbfd has not been implemented yet.
250
15146922 251
47e83720 252* Instrumentation of a java program
253
254See the java/ directory of this package. You will have to create a C library
255that holds the tracing functions, following the java-instrument-string.c. It has
256to be called from the Java code as shown in Sample.java.
257
258The generate.sh scripts compiles and executes the Java program with the JNI
259tracing library.
260
This page took 0.045793 seconds and 4 git commands to generate.