add readme
[lttv.git] / usertrace-generic / README
CommitLineData
15146922 1
2LTTng usertrace generic package
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
13(please add the ltt_* system calls to other architectures as you need them : it
14will work magically)
15
16* Compile your kernel with the latest LTTng patch. Make sure the option
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
22* Extract the latest usertrace-generic archive :
23su
24cd /usr/src
25wget http://ltt.polymtl.ca/packages/usertrace-generic-x.x.tar.gz
26gzip -cd usertrace-generic-x.x.tar.gz | tar xvof -
27
28* Build the sample programs and install the headers into your system :
29su
30cd /usr/src/usertrace-generic
31make
32make install
33
34* There are two ways to trace information from your application :
35
361) Easy way, but slow (printf style)
37 See sample-printf.c for code example.
38
39- Add the following statements to your program source (the define must come
40 _before_ the includes!) :
41
42#define LTT_TRACE
43#define LTT_BLOCKING 1
44#include <ltt/ltt-facility-user_generic.h>
45#include <ltt/ltt-facility-custom-user_generic.h>
46
47Note the define of LTT_BLOCKING to 1 : if a trace buffer is full, your
48application will block. The default of this parameter is 0 (non blocking) :
49events are lost when trace buffer is full. The choice is up to you.
50
51- Add something like the following sample line in your code. Note that this is a
52 very standard format string, this is only a suggested presentation.
53
54trace_user_generic_slow_printf("in: %s at: %s:%d: Counter value is: %u.",
55 __FILE__, __func__, __LINE__, count);
56
57- Compile your application with at least these parameters to gcc (it is splitted
58 on two lines, joined by a "\") :
59gcc -D LTT_SHOW_DEBUG -I /usr/src/usertrace-generic -o myapp myapp.c \
60 /usr/src/usertrace-generic/ltt-facility-loader-user_generic.c
61
62To see what the final result looks like :
63- Start tracing
64- Start your application
65 ** You should see the following message when your program starts and the
66 LTT_SHOW_DEBUG is defined :
67 "LTT : ltt-facility-user_generic init in userspace"
68 If you don't then you forgot to compile the facility loader in your
69 application. If you find this output annoying, you can remove the
70 "-D LTT_SHOW_DEBUG" gcc parameter, which will make the facility loader
71 silent.
72- Stop tracing
73Then, to see only the user_generic events :
74lttv -m textDump -t /tmp/trace1 -e "event.facility=user_generic"
75
76It will show :
77user_generic.slow_printf: 35885.922829472 (/cpu_0), 15521, 7453, SYSCALL { "in: sample-printf.c at: main:18: Counter value is: 0." }
78user_generic.slow_printf: 35886.925685289 (/cpu_0), 15521, 7453, SYSCALL { "in: sample-printf.c at: main:18: Counter value is: 1." }
79...
80
81
82
832) The second way to log events is still easy, yet faster. It requires creating
84 your own XML description of your data structures. It will make it easier to
85 identify your data in the trace. Please read the comments in method 1)
86 explained previously, as they are not repeated here.
87 See sample.c for code example.
88
89- Go to the usertrace-generic directory
90su
91cd /usr/src/usertrace-generic
92
93- Create your own facility (i.e. user_myfacility.xml).
94 See the ones available in /usr/share/LinuxTraceToolkitViewer/facilities for
95 examples.
96 You facility _must_ be named following this standard : "user_*", where * is
97 whatever you like. If it is not, it will be rejected by the kernel with a
98 Operation not permitted (can be seen with the -D LTT_SHOW_DEBUG compilation
99 parameter).
100
101user_myfacility.xml:
102
103<facility name="user_myfacility">
104 <description>Sample facility</description>
105 <event name="myevent">
106 <description>Sample event</description>
107 <field name="file"><string></field>
108 <field name="function"><string></field>
109 <field name="line"><int></field>
110 <field name="firstval"><long></field>
111 <field name="secondval"><pointer></field>
112 </event>
113</facility>
114
115- AN IMPORTANT STEP FOLLOWS :
116 *copy* the user_myfacility.xml file in your system :
117su
118cp user_myfacility.xml /usr/share/LinuxTraceToolkitViewer/facilities
119
120- Use genevent to create the c code and headers :
121su
122cd /tmp
123mkdir genevent
124cd genevent
125for a in /usr/share/LinuxTraceToolkitViewer/facilities/user_*.xml;
126 do /usr/local/bin/genevent $a;
127done
128cd /usr/src/usertrace-generic
129cp /tmp/genevent/*load* .
130cd ltt
131cp /tmp/genevent/ltt-facility-id-user_myfacility.h .
132cp /tmp/genevent/ltt-facility-user_myfacility.h .
133cd ..
134make install
135
136- Add the following statements to your program source (the define must come
137 _before_ the includes!) :
138
139#define LTT_TRACE
140#define LTT_BLOCKING 1
141#include <ltt/ltt-facility-user_myfacility.h>
142
143- Add a call following the trace_user_myfacility_myevent function found in
144 /usr/include/ltt/ltt-facility-user_myfacility.h in your program.
145For instance :
146trace_user_myfacility_myevent(__FILE__, __func__, __LINE__, 1234, (void*)0xF0F0F0F0);
147
148- Compile your application with at least these parameters to gcc (it is splitted
149 on two lines, joined by a "\") :
150gcc -I /usr/src/usertrace-generic -o myapp myapp.c \
151 /usr/src/usertrace-generic/ltt-facility-loader-user_myfacility.c
152
153To see what the final result looks like :
154- Start tracing
155- Start your application
156- Stop tracing
157Then, to see only the user_myfacility events :
158lttv -m textDump -t /tmp/trace1 -e "event.facility=user_myfacility"
159
160It will show, for example :
161user_myfacility.myevent: 39507.805584526 (/cpu_1), 15829, 15736, SYSCALL { "myapp.c", "main", 8, 1234, 0xf0f0f0f0 }
162
163
164
This page took 0.029084 seconds and 4 git commands to generate.