Wiki » History » Version 1
David Goulet, 02/17/2012 10:52 AM
1 | 1 | David Goulet | h1. LTTng-tools Wiki |
---|---|---|---|
2 | |||
3 | h2. Quickstart |
||
4 | |||
5 | This is a quick start guide for the complete LTTng tool chain. This is divided |
||
6 | in three sections respectively kernel tracing, user-space tracing and reading a |
||
7 | trace. |
||
8 | |||
9 | See the README file for installation procedure or use the various Linux |
||
10 | distribution packages. |
||
11 | |||
12 | In order to trace the kernel, you''ll need the lttng-modules 2.0 compiled and |
||
13 | installed. See http://lttng.org/lttng2.0 for more instructions for that part. |
||
14 | For user-space tracing, you''ll need an instrumented application with lttng-ust |
||
15 | 2.0. |
||
16 | |||
17 | lttng-tools provide a session daemon (lttng-sessiond) that acts as a tracing |
||
18 | registry. To trace any instrumented applications or the kernel, a registered |
||
19 | tracing session is needed beforehand. To interact with the session daemon and a |
||
20 | tracing session, you should use the lttng command line UI (lttng). It is also |
||
21 | possible to use the liblttngctl library for tracing control (lttng.h). |
||
22 | |||
23 | Here is a list of some powerful features the LTTng 2.0 kernel tracer offers: |
||
24 | |||
25 | * Kprobes support |
||
26 | * Function Tracer support |
||
27 | * Context information support (add context data to an event) |
||
28 | * Perf counter support |
||
29 | * Tracepoint support |
||
30 | |||
31 | And for the LTTng UST 2.0 tracer: |
||
32 | |||
33 | * Applications registration |
||
34 | * Automatic tracepoints activation upon app. registration |
||
35 | * Context information support |
||
36 | * Safe buffers after application crash |
||
37 | * Per-user tracing (root access *not* mandatory) |
||
38 | |||
39 | The next sections explains how to do tracing :) |
||
40 | |||
41 | h3. Kernel Tracing |
||
42 | |||
43 | You can start the session daemon by invoking the command "lttng-sessiond", or |
||
44 | let the lttng command line tool do it for you. The session daemon loads the |
||
45 | LTTng tracer modules for you if those modules can be found on your system. If |
||
46 | they are not found, the kernel tracing feature will be unavailable. |
||
47 | |||
48 | List available kernel events: |
||
49 | |||
50 | # lttng list -k |
||
51 | |||
52 | 1) Create a tracing session. The .lttng directory will be created with .lttngrc |
||
53 | file in $HOME containing the session name (here ''mysession'') you are working |
||
54 | on. |
||
55 | |||
56 | # lttng create mysession |
||
57 | |||
58 | If you have multiple sessions, you can change the current session by using |
||
59 | |||
60 | # lttng set-session myothersession |
||
61 | |||
62 | 2) Enable all tracepoints and all system call events. |
||
63 | |||
64 | # lttng enable-event -a -k |
||
65 | |||
66 | 3) Enable tracepoint event(s). Here for example, we want only |
||
67 | ''sched_switch'' and ''sched_wakeup'' events for the kernel (-k/--kernel). |
||
68 | |||
69 | # lttng enable-event sched_switch,sched_wakeup -k |
||
70 | |||
71 | or enable ALL tracepoint events: |
||
72 | |||
73 | # lttng enable-event -a -k --tracepoint |
||
74 | |||
75 | 4) Enable all system call event(s). |
||
76 | |||
77 | # lttng enable-event -a -k --syscall |
||
78 | |||
79 | 5) Enable kprobes and/or the function tracer with lttng |
||
80 | |||
81 | This is a new feature made possible by the new LTTng 2.0 kernel tracer. You can |
||
82 | enable a dynamic probe and data will be output in the trace along side with |
||
83 | your tracing data. |
||
84 | |||
85 | # lttng enable-event aname -k --probe symbol+0x0 |
||
86 | |||
87 | or |
||
88 | |||
89 | # lttng enable-event aname -k --probe 0xffff7260695 |
||
90 | |||
91 | Either an <address> or a <symbol+offset> can be used for probes. |
||
92 | |||
93 | You can also enable function tracer, which uses the Ftrace API (by Steven |
||
94 | Rostedt). Again, data will be output in the trace. |
||
95 | |||
96 | # lttng enable-event aname -k --function <symbol_name> |
||
97 | |||
98 | 6) Enable context information for an event: |
||
99 | |||
100 | This is also a new feature which allows you to add context information to an |
||
101 | event. For example, you can add the PID along with the event information: |
||
102 | |||
103 | # lttng add-context -k -e sched_switch -t pid |
||
104 | |||
105 | At this point, you will have to look at ''lttng add-context --help'' for all |
||
106 | possible context type. |
||
107 | |||
108 | You can on the same line activate multiple context: |
||
109 | |||
110 | # lttng add-context -k -e sched_switch -t pid -t nice -t tid |
||
111 | |||
112 | 7) Enable perf counter for an event: |
||
113 | |||
114 | Again, a new powerful feature is the possibility to add perf counter data |
||
115 | (using the perf API by Ingo Molnar and Thomas Gleixner) to the trace on a per |
||
116 | event basis. Let say we want to get the CPU cycles at each event: |
||
117 | |||
118 | # lttng add-context -k -e sched_switch -t perf:cpu-cycles |
||
119 | |||
120 | You''ll have to use the add-context help for all possible perf counter values. |
||
121 | |||
122 | 8) Start tracing: |
||
123 | |||
124 | # lttng start |
||
125 | |||
126 | Tracing is in progress at this point and traces will be written in |
||
127 | $HOME/lttng-traces/mysession-<date>-<time> |
||
128 | |||
129 | NOTE: It will start tracing for *all* domain(s). |
||
130 | |||
131 | 9) Stop tracing: |
||
132 | |||
133 | # lttng stop |
||
134 | |||
135 | NOTE: At this point, you can restart the trace (lttng start), enable/disable |
||
136 | events or just go take a break and come back 3 days later to start it again :). |
||
137 | You can also read the trace since the buffers are flushed on stop command. |
||
138 | |||
139 | 10) Destroy your session after you are done with tracing |
||
140 | |||
141 | # lttng destroy |
||
142 | |||
143 | See Reading a trace section below to read you trace(s). |
||
144 | |||
145 | h3. User-space Tracing |
||
146 | |||
147 | Like kernel tracing, you can start the session daemon by invoking the command |
||
148 | "lttng-sessiond", or let the lttng command line tool do it for you. |
||
149 | |||
150 | NOTE: You do *not* need root credentials in order to tracer user-space |
||
151 | applications. However, if you run the session daemon under non-root user |
||
152 | rights, only applications of that user will be traced. |
||
153 | |||
154 | So, after instrumenting you applications with LTTng-ust 2.0 |
||
155 | (http://lttng.org/lttng2.0), upon startup, it will automatically register to |
||
156 | the session daemon. If there is none running, it will simply wait on a seperate |
||
157 | thread for a session daemon to appear and then register. |
||
158 | |||
159 | Start your instrumented application at any time but at least before starting |
||
160 | tracing :). |
||
161 | |||
162 | List available registered applications: |
||
163 | |||
164 | $ lttng list -u |
||
165 | |||
166 | 1) Create a tracing session. The .lttng directory will be created with a |
||
167 | .lttngrc file in $HOME containing the session name (here ''mysession'') you are |
||
168 | working on. |
||
169 | |||
170 | $ lttng create mysession |
||
171 | |||
172 | If you have multiple sessions, you can change the current session by using: |
||
173 | |||
174 | $ lttng set-session myothersession |
||
175 | |||
176 | 2) Enable all tracepoints for the global UST domain ("-u" alone). |
||
177 | |||
178 | $ lttng enable-event -a -u |
||
179 | |||
180 | or enable a single tracepoint event. |
||
181 | |||
182 | $ lttng enable-event ust_tests_hello:tptest -u |
||
183 | |||
184 | 3) This is also a new feature which allows you to add context information to an |
||
185 | event. For example, you can add the PID along with the event information: |
||
186 | |||
187 | $ lttng add-context -t pid -e ust_tests_hello:tptest -u |
||
188 | |||
189 | At this point, you will have to look at ''lttng add-context --help'' for all |
||
190 | possible context type. |
||
191 | |||
192 | You can on the same line activate multiple context: |
||
193 | |||
194 | $ lttng add-context -u -e ust_tests_hello:tptest -t pid -t nice -t tid |
||
195 | |||
196 | 4) Start tracing: |
||
197 | |||
198 | $ lttng start |
||
199 | |||
200 | Tracing is in progress at this point and traces will be written in |
||
201 | $HOME/lttng-traces/mysession-<date>-<time>/ust/<procname>-<pid>-<date>-<time> |
||
202 | |||
203 | NOTE: It will start tracing for *all* domain(s). |
||
204 | |||
205 | 5) Stop tracing: |
||
206 | |||
207 | $ lttng stop |
||
208 | |||
209 | NOTE: At this point, you can restart the trace (lttng start), enable/disable |
||
210 | events or just go take a break and come back 3 days later to start it again :). |
||
211 | You can also read the trace since the buffers are flushed on stop command. |
||
212 | |||
213 | 6) Destroy your session after you are done with tracing |
||
214 | |||
215 | $ lttng destroy |
||
216 | |||
217 | See "Reading a trace" section below to read you trace(s). |
||
218 | |||
219 | |||
220 | h3. Reading a trace |
||
221 | |||
222 | The tool "Babeltrace" can be used to dump your binary trace into a |
||
223 | human-readable text format. Please see http://www.efficios.com/babeltrace and |
||
224 | git tree http://git.efficios.com/?p=babeltrace.git |
||
225 | |||
226 | # babeltrace $HOME/lttng-traces/mysession-<date>-<time> | less |
||
227 | |||
228 | VoilĂ |