diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-03-10 12:58:51 -0400 |
---|---|---|
committer | Steven Rostedt <srostedt@redhat.com> | 2009-03-10 12:58:51 -0400 |
commit | 823f9124fb2e33eeb624d139978a52089f8a02ae (patch) | |
tree | e1094e94a958e2098c3946de4ac648a7d87a1bcb /include | |
parent | 30a8fecc2d34f086df34fe2f2b926f080e002600 (diff) |
tracing: document TRACE_EVENT macro in tracepoint.h
Impact: clean up / comments
Kosaki Motohiro asked about an explanation to the TRACE_EVENT macro.
Ingo Molnar replied with a nice description.
This patch takes the description that Ingo wrote (with some slight
modifications) and adds it to the tracepoint.h file.
Reported-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/tracepoint.h | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index c7b09452514b..119ece224c21 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h | |||
@@ -157,6 +157,109 @@ static inline void tracepoint_synchronize_unregister(void) | |||
157 | #define TRACE_FORMAT(name, proto, args, fmt) \ | 157 | #define TRACE_FORMAT(name, proto, args, fmt) \ |
158 | DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) | 158 | DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) |
159 | 159 | ||
160 | |||
161 | /* | ||
162 | * For use with the TRACE_EVENT macro: | ||
163 | * | ||
164 | * We define a tracepoint, its arguments, its printk format | ||
165 | * and its 'fast binay record' layout. | ||
166 | * | ||
167 | * Firstly, name your tracepoint via TRACE_EVENT(name : the | ||
168 | * 'subsystem_event' notation is fine. | ||
169 | * | ||
170 | * Think about this whole construct as the | ||
171 | * 'trace_sched_switch() function' from now on. | ||
172 | * | ||
173 | * | ||
174 | * TRACE_EVENT(sched_switch, | ||
175 | * | ||
176 | * * | ||
177 | * * A function has a regular function arguments | ||
178 | * * prototype, declare it via TP_PROTO(): | ||
179 | * * | ||
180 | * | ||
181 | * TP_PROTO(struct rq *rq, struct task_struct *prev, | ||
182 | * struct task_struct *next), | ||
183 | * | ||
184 | * * | ||
185 | * * Define the call signature of the 'function'. | ||
186 | * * (Design sidenote: we use this instead of a | ||
187 | * * TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.) | ||
188 | * * | ||
189 | * | ||
190 | * TP_ARGS(rq, prev, next), | ||
191 | * | ||
192 | * * | ||
193 | * * Fast binary tracing: define the trace record via | ||
194 | * * TP_STRUCT__entry(). You can think about it like a | ||
195 | * * regular C structure local variable definition. | ||
196 | * * | ||
197 | * * This is how the trace record is structured and will | ||
198 | * * be saved into the ring buffer. These are the fields | ||
199 | * * that will be exposed to user-space in | ||
200 | * * /debug/tracing/events/<*>/format. | ||
201 | * * | ||
202 | * * The declared 'local variable' is called '__entry' | ||
203 | * * | ||
204 | * * __field(pid_t, prev_prid) is equivalent to a standard declariton: | ||
205 | * * | ||
206 | * * pid_t prev_pid; | ||
207 | * * | ||
208 | * * __array(char, prev_comm, TASK_COMM_LEN) is equivalent to: | ||
209 | * * | ||
210 | * * char prev_comm[TASK_COMM_LEN]; | ||
211 | * * | ||
212 | * | ||
213 | * TP_STRUCT__entry( | ||
214 | * __array( char, prev_comm, TASK_COMM_LEN ) | ||
215 | * __field( pid_t, prev_pid ) | ||
216 | * __field( int, prev_prio ) | ||
217 | * __array( char, next_comm, TASK_COMM_LEN ) | ||
218 | * __field( pid_t, next_pid ) | ||
219 | * __field( int, next_prio ) | ||
220 | * ), | ||
221 | * | ||
222 | * * | ||
223 | * * Assign the entry into the trace record, by embedding | ||
224 | * * a full C statement block into TP_fast_assign(). You | ||
225 | * * can refer to the trace record as '__entry' - | ||
226 | * * otherwise you can put arbitrary C code in here. | ||
227 | * * | ||
228 | * * Note: this C code will execute every time a trace event | ||
229 | * * happens, on an active tracepoint. | ||
230 | * * | ||
231 | * | ||
232 | * TP_fast_assign( | ||
233 | * memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); | ||
234 | * __entry->prev_pid = prev->pid; | ||
235 | * __entry->prev_prio = prev->prio; | ||
236 | * memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); | ||
237 | * __entry->next_pid = next->pid; | ||
238 | * __entry->next_prio = next->prio; | ||
239 | * ) | ||
240 | * | ||
241 | * * | ||
242 | * * Formatted output of a trace record via TP_printk(). | ||
243 | * * This is how the tracepoint will appear under ftrace | ||
244 | * * plugins that make use of this tracepoint. | ||
245 | * * | ||
246 | * * (raw-binary tracing wont actually perform this step.) | ||
247 | * * | ||
248 | * | ||
249 | * TP_printk("task %s:%d [%d] ==> %s:%d [%d]", | ||
250 | * __entry->prev_comm, __entry->prev_pid, __entry->prev_prio, | ||
251 | * __entry->next_comm, __entry->next_pid, __entry->next_prio), | ||
252 | * | ||
253 | * ); | ||
254 | * | ||
255 | * This macro construct is thus used for the regular printk format | ||
256 | * tracing setup, it is used to construct a function pointer based | ||
257 | * tracepoint callback (this is used by programmatic plugins and | ||
258 | * can also by used by generic instrumentation like SystemTap), and | ||
259 | * it is also used to expose a structured trace record in | ||
260 | * /debug/tracing/events/. | ||
261 | */ | ||
262 | |||
160 | #define TRACE_EVENT(name, proto, args, struct, assign, print) \ | 263 | #define TRACE_EVENT(name, proto, args, struct, assign, print) \ |
161 | DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) | 264 | DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) |
162 | 265 | ||