tracing/filters: distinguish between signed and unsigned fields
[linux-2.6/mini2440.git] / include / trace / ftrace.h
blobedb02bc9f8fffe0afa208095c83b562cf90960ba
1 /*
2 * Stage 1 of the trace events.
4 * Override the macros in <trace/trace_events.h> to include the following:
6 * struct ftrace_raw_<call> {
7 * struct trace_entry ent;
8 * <type> <item>;
9 * <type2> <item2>[<len>];
10 * [...]
11 * };
13 * The <type> <item> is created by the __field(type, item) macro or
14 * the __array(type2, item2, len) macro.
15 * We simply do "type item;", and that will create the fields
16 * in the structure.
19 #include <linux/ftrace_event.h>
21 #undef __array
22 #define __array(type, item, len) type item[len];
24 #undef __field
25 #define __field(type, item) type item;
27 #undef __string
28 #define __string(item, src) int __str_loc_##item;
30 #undef TP_STRUCT__entry
31 #define TP_STRUCT__entry(args...) args
33 #undef TRACE_EVENT
34 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
35 struct ftrace_raw_##name { \
36 struct trace_entry ent; \
37 tstruct \
38 char __str_data[0]; \
39 }; \
40 static struct ftrace_event_call event_##name
42 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
46 * Stage 2 of the trace events.
48 * Include the following:
50 * struct ftrace_str_offsets_<call> {
51 * int <str1>;
52 * int <str2>;
53 * [...]
54 * };
56 * The __string() macro will create each int <str>, this is to
57 * keep the offset of each string from the beggining of the event
58 * once we perform the strlen() of the src strings.
62 #undef __array
63 #define __array(type, item, len)
65 #undef __field
66 #define __field(type, item);
68 #undef __string
69 #define __string(item, src) int item;
71 #undef TRACE_EVENT
72 #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
73 struct ftrace_str_offsets_##call { \
74 tstruct; \
77 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
80 * Stage 3 of the trace events.
82 * Override the macros in <trace/trace_events.h> to include the following:
84 * enum print_line_t
85 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
86 * {
87 * struct trace_seq *s = &iter->seq;
88 * struct ftrace_raw_<call> *field; <-- defined in stage 1
89 * struct trace_entry *entry;
90 * int ret;
92 * entry = iter->ent;
94 * if (entry->type != event_<call>.id) {
95 * WARN_ON_ONCE(1);
96 * return TRACE_TYPE_UNHANDLED;
97 * }
99 * field = (typeof(field))entry;
101 * ret = trace_seq_printf(s, <TP_printk> "\n");
102 * if (!ret)
103 * return TRACE_TYPE_PARTIAL_LINE;
105 * return TRACE_TYPE_HANDLED;
108 * This is the method used to print the raw event to the trace
109 * output format. Note, this is not needed if the data is read
110 * in binary.
113 #undef __entry
114 #define __entry field
116 #undef TP_printk
117 #define TP_printk(fmt, args...) fmt "\n", args
119 #undef __get_str
120 #define __get_str(field) ((char *)__entry + __entry->__str_loc_##field)
122 #undef TRACE_EVENT
123 #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
124 enum print_line_t \
125 ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
127 struct trace_seq *s = &iter->seq; \
128 struct ftrace_raw_##call *field; \
129 struct trace_entry *entry; \
130 int ret; \
132 entry = iter->ent; \
134 if (entry->type != event_##call.id) { \
135 WARN_ON_ONCE(1); \
136 return TRACE_TYPE_UNHANDLED; \
139 field = (typeof(field))entry; \
141 ret = trace_seq_printf(s, #call ": " print); \
142 if (!ret) \
143 return TRACE_TYPE_PARTIAL_LINE; \
145 return TRACE_TYPE_HANDLED; \
148 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
151 * Setup the showing format of trace point.
153 * int
154 * ftrace_format_##call(struct trace_seq *s)
156 * struct ftrace_raw_##call field;
157 * int ret;
159 * ret = trace_seq_printf(s, #type " " #item ";"
160 * " offset:%u; size:%u;\n",
161 * offsetof(struct ftrace_raw_##call, item),
162 * sizeof(field.type));
167 #undef TP_STRUCT__entry
168 #define TP_STRUCT__entry(args...) args
170 #undef __field
171 #define __field(type, item) \
172 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
173 "offset:%u;\tsize:%u;\n", \
174 (unsigned int)offsetof(typeof(field), item), \
175 (unsigned int)sizeof(field.item)); \
176 if (!ret) \
177 return 0;
179 #undef __array
180 #define __array(type, item, len) \
181 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
182 "offset:%u;\tsize:%u;\n", \
183 (unsigned int)offsetof(typeof(field), item), \
184 (unsigned int)sizeof(field.item)); \
185 if (!ret) \
186 return 0;
188 #undef __string
189 #define __string(item, src) \
190 ret = trace_seq_printf(s, "\tfield: __str_loc " #item ";\t" \
191 "offset:%u;tsize:%u;\n", \
192 (unsigned int)offsetof(typeof(field), \
193 __str_loc_##item), \
194 (unsigned int)sizeof(field.__str_loc_##item)); \
195 if (!ret) \
196 return 0;
198 #undef __entry
199 #define __entry REC
201 #undef TP_printk
202 #define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
204 #undef TP_fast_assign
205 #define TP_fast_assign(args...) args
207 #undef TRACE_EVENT
208 #define TRACE_EVENT(call, proto, args, tstruct, func, print) \
209 static int \
210 ftrace_format_##call(struct trace_seq *s) \
212 struct ftrace_raw_##call field __attribute__((unused)); \
213 int ret = 0; \
215 tstruct; \
217 trace_seq_printf(s, "\nprint fmt: " print); \
219 return ret; \
222 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
224 #undef __field
225 #define __field(type, item) \
226 ret = trace_define_field(event_call, #type, #item, \
227 offsetof(typeof(field), item), \
228 sizeof(field.item), is_signed_type(type)); \
229 if (ret) \
230 return ret;
232 #undef __array
233 #define __array(type, item, len) \
234 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
235 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
236 offsetof(typeof(field), item), \
237 sizeof(field.item), 0); \
238 if (ret) \
239 return ret;
241 #undef __string
242 #define __string(item, src) \
243 ret = trace_define_field(event_call, "__str_loc", #item, \
244 offsetof(typeof(field), __str_loc_##item), \
245 sizeof(field.__str_loc_##item), 0);
247 #undef TRACE_EVENT
248 #define TRACE_EVENT(call, proto, args, tstruct, func, print) \
249 int \
250 ftrace_define_fields_##call(void) \
252 struct ftrace_raw_##call field; \
253 struct ftrace_event_call *event_call = &event_##call; \
254 int ret; \
256 __common_field(int, type, 1); \
257 __common_field(unsigned char, flags, 0); \
258 __common_field(unsigned char, preempt_count, 0); \
259 __common_field(int, pid, 1); \
260 __common_field(int, tgid, 1); \
262 tstruct; \
264 return ret; \
267 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
270 * Stage 4 of the trace events.
272 * Override the macros in <trace/trace_events.h> to include the following:
274 * static void ftrace_event_<call>(proto)
276 * event_trace_printk(_RET_IP_, "<call>: " <fmt>);
279 * static int ftrace_reg_event_<call>(void)
281 * int ret;
283 * ret = register_trace_<call>(ftrace_event_<call>);
284 * if (!ret)
285 * pr_info("event trace: Could not activate trace point "
286 * "probe to <call>");
287 * return ret;
290 * static void ftrace_unreg_event_<call>(void)
292 * unregister_trace_<call>(ftrace_event_<call>);
296 * For those macros defined with TRACE_EVENT:
298 * static struct ftrace_event_call event_<call>;
300 * static void ftrace_raw_event_<call>(proto)
302 * struct ring_buffer_event *event;
303 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
304 * unsigned long irq_flags;
305 * int pc;
307 * local_save_flags(irq_flags);
308 * pc = preempt_count();
310 * event = trace_current_buffer_lock_reserve(event_<call>.id,
311 * sizeof(struct ftrace_raw_<call>),
312 * irq_flags, pc);
313 * if (!event)
314 * return;
315 * entry = ring_buffer_event_data(event);
317 * <assign>; <-- Here we assign the entries by the __field and
318 * __array macros.
320 * trace_current_buffer_unlock_commit(event, irq_flags, pc);
323 * static int ftrace_raw_reg_event_<call>(void)
325 * int ret;
327 * ret = register_trace_<call>(ftrace_raw_event_<call>);
328 * if (!ret)
329 * pr_info("event trace: Could not activate trace point "
330 * "probe to <call>");
331 * return ret;
334 * static void ftrace_unreg_event_<call>(void)
336 * unregister_trace_<call>(ftrace_raw_event_<call>);
339 * static struct trace_event ftrace_event_type_<call> = {
340 * .trace = ftrace_raw_output_<call>, <-- stage 2
341 * };
343 * static int ftrace_raw_init_event_<call>(void)
345 * int id;
347 * id = register_ftrace_event(&ftrace_event_type_<call>);
348 * if (!id)
349 * return -ENODEV;
350 * event_<call>.id = id;
351 * return 0;
354 * static struct ftrace_event_call __used
355 * __attribute__((__aligned__(4)))
356 * __attribute__((section("_ftrace_events"))) event_<call> = {
357 * .name = "<call>",
358 * .system = "<system>",
359 * .raw_init = ftrace_raw_init_event_<call>,
360 * .regfunc = ftrace_reg_event_<call>,
361 * .unregfunc = ftrace_unreg_event_<call>,
362 * .show_format = ftrace_format_<call>,
367 #undef TP_FMT
368 #define TP_FMT(fmt, args...) fmt "\n", ##args
370 #ifdef CONFIG_EVENT_PROFILE
371 #define _TRACE_PROFILE(call, proto, args) \
372 static void ftrace_profile_##call(proto) \
374 extern void perf_tpcounter_event(int); \
375 perf_tpcounter_event(event_##call.id); \
378 static int ftrace_profile_enable_##call(struct ftrace_event_call *call) \
380 int ret = 0; \
382 if (!atomic_inc_return(&call->profile_count)) \
383 ret = register_trace_##call(ftrace_profile_##call); \
385 return ret; \
388 static void ftrace_profile_disable_##call(struct ftrace_event_call *call) \
390 if (atomic_add_negative(-1, &call->profile_count)) \
391 unregister_trace_##call(ftrace_profile_##call); \
394 #define _TRACE_PROFILE_INIT(call) \
395 .profile_count = ATOMIC_INIT(-1), \
396 .profile_enable = ftrace_profile_enable_##call, \
397 .profile_disable = ftrace_profile_disable_##call,
399 #else
400 #define _TRACE_PROFILE(call, proto, args)
401 #define _TRACE_PROFILE_INIT(call)
402 #endif
404 #undef __entry
405 #define __entry entry
407 #undef __field
408 #define __field(type, item)
410 #undef __array
411 #define __array(type, item, len)
413 #undef __string
414 #define __string(item, src) \
415 __str_offsets.item = __str_size + \
416 offsetof(typeof(*entry), __str_data); \
417 __str_size += strlen(src) + 1;
419 #undef __assign_str
420 #define __assign_str(dst, src) \
421 __entry->__str_loc_##dst = __str_offsets.dst; \
422 strcpy(__get_str(dst), src);
424 #undef TRACE_EVENT
425 #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
426 _TRACE_PROFILE(call, PARAMS(proto), PARAMS(args)) \
428 static struct ftrace_event_call event_##call; \
430 static void ftrace_raw_event_##call(proto) \
432 struct ftrace_str_offsets_##call __maybe_unused __str_offsets; \
433 struct ftrace_event_call *call = &event_##call; \
434 struct ring_buffer_event *event; \
435 struct ftrace_raw_##call *entry; \
436 unsigned long irq_flags; \
437 int __str_size = 0; \
438 int pc; \
440 local_save_flags(irq_flags); \
441 pc = preempt_count(); \
443 tstruct; \
445 event = trace_current_buffer_lock_reserve(event_##call.id, \
446 sizeof(struct ftrace_raw_##call) + __str_size,\
447 irq_flags, pc); \
448 if (!event) \
449 return; \
450 entry = ring_buffer_event_data(event); \
452 assign; \
454 if (!filter_current_check_discard(call, entry, event)) \
455 trace_nowake_buffer_unlock_commit(event, irq_flags, pc); \
458 static int ftrace_raw_reg_event_##call(void) \
460 int ret; \
462 ret = register_trace_##call(ftrace_raw_event_##call); \
463 if (ret) \
464 pr_info("event trace: Could not activate trace point " \
465 "probe to " #call "\n"); \
466 return ret; \
469 static void ftrace_raw_unreg_event_##call(void) \
471 unregister_trace_##call(ftrace_raw_event_##call); \
474 static struct trace_event ftrace_event_type_##call = { \
475 .trace = ftrace_raw_output_##call, \
476 }; \
478 static int ftrace_raw_init_event_##call(void) \
480 int id; \
482 id = register_ftrace_event(&ftrace_event_type_##call); \
483 if (!id) \
484 return -ENODEV; \
485 event_##call.id = id; \
486 INIT_LIST_HEAD(&event_##call.fields); \
487 init_preds(&event_##call); \
488 return 0; \
491 static struct ftrace_event_call __used \
492 __attribute__((__aligned__(4))) \
493 __attribute__((section("_ftrace_events"))) event_##call = { \
494 .name = #call, \
495 .system = __stringify(TRACE_SYSTEM), \
496 .event = &ftrace_event_type_##call, \
497 .raw_init = ftrace_raw_init_event_##call, \
498 .regfunc = ftrace_raw_reg_event_##call, \
499 .unregfunc = ftrace_raw_unreg_event_##call, \
500 .show_format = ftrace_format_##call, \
501 .define_fields = ftrace_define_fields_##call, \
502 _TRACE_PROFILE_INIT(call) \
505 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
507 #undef _TRACE_PROFILE
508 #undef _TRACE_PROFILE_INIT