tracing: new format for specialized trace points
[linux-2.6.git] / kernel / trace / trace_events_stage_3.h
1 /*
2  * Stage 3 of the trace events.
3  *
4  * Override the macros in <trace/trace_event_types.h> to include the following:
5  *
6  * static void ftrace_event_<call>(proto)
7  * {
8  *      event_trace_printk(_RET_IP_, "<call>: " <fmt>);
9  * }
10  *
11  * static int ftrace_reg_event_<call>(void)
12  * {
13  *      int ret;
14  *
15  *      ret = register_trace_<call>(ftrace_event_<call>);
16  *      if (!ret)
17  *              pr_info("event trace: Could not activate trace point "
18  *                      "probe to  <call>");
19  *      return ret;
20  * }
21  *
22  * static void ftrace_unreg_event_<call>(void)
23  * {
24  *      unregister_trace_<call>(ftrace_event_<call>);
25  * }
26  *
27  * For those macros defined with TRACE_FORMAT:
28  *
29  * static struct ftrace_event_call __used
30  * __attribute__((__aligned__(4)))
31  * __attribute__((section("_ftrace_events"))) event_<call> = {
32  *      .name                   = "<call>",
33  *      .regfunc                = ftrace_reg_event_<call>,
34  *      .unregfunc              = ftrace_unreg_event_<call>,
35  * }
36  *
37  *
38  * For those macros defined with TRACE_EVENT_FORMAT:
39  *
40  * static struct ftrace_event_call event_<call>;
41  *
42  * static void ftrace_raw_event_<call>(proto)
43  * {
44  *      struct ring_buffer_event *event;
45  *      struct ftrace_raw_<call> *entry; <-- defined in stage 1
46  *      unsigned long irq_flags;
47  *      int pc;
48  *
49  *      local_save_flags(irq_flags);
50  *      pc = preempt_count();
51  *
52  *      event = trace_current_buffer_lock_reserve(event_<call>.id,
53  *                                sizeof(struct ftrace_raw_<call>),
54  *                                irq_flags, pc);
55  *      if (!event)
56  *              return;
57  *      entry   = ring_buffer_event_data(event);
58  *
59  *      <tstruct>;  <-- Here we assign the entries by the TRACE_FIELD.
60  *
61  *      trace_current_buffer_unlock_commit(event, irq_flags, pc);
62  * }
63  *
64  * static int ftrace_raw_reg_event_<call>(void)
65  * {
66  *      int ret;
67  *
68  *      ret = register_trace_<call>(ftrace_raw_event_<call>);
69  *      if (!ret)
70  *              pr_info("event trace: Could not activate trace point "
71  *                      "probe to <call>");
72  *      return ret;
73  * }
74  *
75  * static void ftrace_unreg_event_<call>(void)
76  * {
77  *      unregister_trace_<call>(ftrace_raw_event_<call>);
78  * }
79  *
80  * static struct trace_event ftrace_event_type_<call> = {
81  *      .trace                  = ftrace_raw_output_<call>, <-- stage 2
82  * };
83  *
84  * static int ftrace_raw_init_event_<call>(void)
85  * {
86  *      int id;
87  *
88  *      id = register_ftrace_event(&ftrace_event_type_<call>);
89  *      if (!id)
90  *              return -ENODEV;
91  *      event_<call>.id = id;
92  *      return 0;
93  * }
94  *
95  * static struct ftrace_event_call __used
96  * __attribute__((__aligned__(4)))
97  * __attribute__((section("_ftrace_events"))) event_<call> = {
98  *      .name                   = "<call>",
99  *      .regfunc                = ftrace_reg_event_<call>,
100  *      .unregfunc              = ftrace_unreg_event_<call>,
101  *      .raw_init               = ftrace_raw_init_event_<call>,
102  *      .raw_reg                = ftrace_raw_reg_event_<call>,
103  *      .raw_unreg              = ftrace_raw_unreg_event_<call>,
104  *      .show_format            = ftrace_format_<call>,
105  * }
106  *
107  */
108
109 #undef TP_FMT
110 #define TP_FMT(fmt, args...)    fmt "\n", ##args
111
112 #define _TRACE_FORMAT(call, proto, args, fmt)                           \
113 static void ftrace_event_##call(proto)                                  \
114 {                                                                       \
115         event_trace_printk(_RET_IP_, #call ": " fmt);                   \
116 }                                                                       \
117                                                                         \
118 static int ftrace_reg_event_##call(void)                                \
119 {                                                                       \
120         int ret;                                                        \
121                                                                         \
122         ret = register_trace_##call(ftrace_event_##call);               \
123         if (ret)                                                        \
124                 pr_info("event trace: Could not activate trace point "  \
125                         "probe to " #call "\n");                        \
126         return ret;                                                     \
127 }                                                                       \
128                                                                         \
129 static void ftrace_unreg_event_##call(void)                             \
130 {                                                                       \
131         unregister_trace_##call(ftrace_event_##call);                   \
132 }                                                                       \
133
134
135 #undef TRACE_FORMAT
136 #define TRACE_FORMAT(call, proto, args, fmt)                            \
137 _TRACE_FORMAT(call, PARAMS(proto), PARAMS(args), PARAMS(fmt))           \
138 static struct ftrace_event_call __used                                  \
139 __attribute__((__aligned__(4)))                                         \
140 __attribute__((section("_ftrace_events"))) event_##call = {             \
141         .name                   = #call,                                \
142         .system                 = __stringify(TRACE_SYSTEM),            \
143         .regfunc                = ftrace_reg_event_##call,              \
144         .unregfunc              = ftrace_unreg_event_##call,            \
145 }
146
147 #undef TRACE_EVENT_FORMAT
148 #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, raw)        \
149         TRACE_FORMAT(call, PARAMS(proto), PARAMS(args), PARAMS(fmt))
150
151 #undef __entry
152 #define __entry entry
153
154 #undef TRACE_EVENT
155 #define TRACE_EVENT(call, proto, args, tstruct, print, assign)          \
156                                                                         \
157 static struct ftrace_event_call event_##call;                           \
158                                                                         \
159 static void ftrace_raw_event_##call(proto)                              \
160 {                                                                       \
161         struct ring_buffer_event *event;                                \
162         struct ftrace_raw_##call *entry;                                \
163         unsigned long irq_flags;                                        \
164         int pc;                                                         \
165                                                                         \
166         local_save_flags(irq_flags);                                    \
167         pc = preempt_count();                                           \
168                                                                         \
169         event = trace_current_buffer_lock_reserve(event_##call.id,      \
170                                   sizeof(struct ftrace_raw_##call),     \
171                                   irq_flags, pc);                       \
172         if (!event)                                                     \
173                 return;                                                 \
174         entry   = ring_buffer_event_data(event);                        \
175                                                                         \
176         assign;                                                         \
177                                                                         \
178         trace_current_buffer_unlock_commit(event, irq_flags, pc);       \
179 }                                                                       \
180                                                                         \
181 static int ftrace_raw_reg_event_##call(void)                            \
182 {                                                                       \
183         int ret;                                                        \
184                                                                         \
185         ret = register_trace_##call(ftrace_raw_event_##call);           \
186         if (ret)                                                        \
187                 pr_info("event trace: Could not activate trace point "  \
188                         "probe to " #call "\n");                        \
189         return ret;                                                     \
190 }                                                                       \
191                                                                         \
192 static void ftrace_raw_unreg_event_##call(void)                         \
193 {                                                                       \
194         unregister_trace_##call(ftrace_raw_event_##call);               \
195 }                                                                       \
196                                                                         \
197 static struct trace_event ftrace_event_type_##call = {                  \
198         .trace                  = ftrace_raw_output_##call,             \
199 };                                                                      \
200                                                                         \
201 static int ftrace_raw_init_event_##call(void)                           \
202 {                                                                       \
203         int id;                                                         \
204                                                                         \
205         id = register_ftrace_event(&ftrace_event_type_##call);          \
206         if (!id)                                                        \
207                 return -ENODEV;                                         \
208         event_##call.id = id;                                           \
209         return 0;                                                       \
210 }                                                                       \
211                                                                         \
212 static struct ftrace_event_call __used                                  \
213 __attribute__((__aligned__(4)))                                         \
214 __attribute__((section("_ftrace_events"))) event_##call = {             \
215         .name                   = #call,                                \
216         .system                 = __stringify(TRACE_SYSTEM),            \
217         .raw_init               = ftrace_raw_init_event_##call,         \
218         .regfunc                = ftrace_raw_reg_event_##call,          \
219         .unregfunc              = ftrace_raw_unreg_event_##call,        \
220         .show_format            = ftrace_format_##call,                 \
221 }