Merge branch 'linus' into tracing/core
[safe/jmp/linux-2.6] / kernel / trace / trace_events_stage_2.h
1 /*
2  * Stage 2 of the trace events.
3  *
4  * Override the macros in <trace/trace_event_types.h> to include the following:
5  *
6  * enum print_line_t
7  * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
8  * {
9  *      struct trace_seq *s = &iter->seq;
10  *      struct ftrace_raw_<call> *field; <-- defined in stage 1
11  *      struct trace_entry *entry;
12  *      int ret;
13  *
14  *      entry = iter->ent;
15  *
16  *      if (entry->type != event_<call>.id) {
17  *              WARN_ON_ONCE(1);
18  *              return TRACE_TYPE_UNHANDLED;
19  *      }
20  *
21  *      field = (typeof(field))entry;
22  *
23  *      ret = trace_seq_printf(s, <TP_printk> "\n");
24  *      if (!ret)
25  *              return TRACE_TYPE_PARTIAL_LINE;
26  *
27  *      return TRACE_TYPE_HANDLED;
28  * }
29  *
30  * This is the method used to print the raw event to the trace
31  * output format. Note, this is not needed if the data is read
32  * in binary.
33  */
34
35 #undef __entry
36 #define __entry field
37
38 #undef TP_printk
39 #define TP_printk(fmt, args...) fmt "\n", args
40
41 #undef TRACE_EVENT
42 #define TRACE_EVENT(call, proto, args, tstruct, assign, print)          \
43 enum print_line_t                                                       \
44 ftrace_raw_output_##call(struct trace_iterator *iter, int flags)        \
45 {                                                                       \
46         struct trace_seq *s = &iter->seq;                               \
47         struct ftrace_raw_##call *field;                                \
48         struct trace_entry *entry;                                      \
49         int ret;                                                        \
50                                                                         \
51         entry = iter->ent;                                              \
52                                                                         \
53         if (entry->type != event_##call.id) {                           \
54                 WARN_ON_ONCE(1);                                        \
55                 return TRACE_TYPE_UNHANDLED;                            \
56         }                                                               \
57                                                                         \
58         field = (typeof(field))entry;                                   \
59                                                                         \
60         ret = trace_seq_printf(s, #call ": " print);                    \
61         if (!ret)                                                       \
62                 return TRACE_TYPE_PARTIAL_LINE;                         \
63                                                                         \
64         return TRACE_TYPE_HANDLED;                                      \
65 }
66         
67 #include <trace/trace_event_types.h>
68
69 /*
70  * Setup the showing format of trace point.
71  *
72  * int
73  * ftrace_format_##call(struct trace_seq *s)
74  * {
75  *      struct ftrace_raw_##call field;
76  *      int ret;
77  *
78  *      ret = trace_seq_printf(s, #type " " #item ";"
79  *                             " offset:%u; size:%u;\n",
80  *                             offsetof(struct ftrace_raw_##call, item),
81  *                             sizeof(field.type));
82  *
83  * }
84  */
85
86 #undef TP_STRUCT__entry
87 #define TP_STRUCT__entry(args...) args
88
89 #undef __field
90 #define __field(type, item)                                     \
91         ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t"      \
92                                "offset:%u;\tsize:%u;\n",                \
93                                (unsigned int)offsetof(typeof(field), item), \
94                                (unsigned int)sizeof(field.item));       \
95         if (!ret)                                                       \
96                 return 0;
97
98 #undef __array
99 #define __array(type, item, len)                                                \
100         ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t"    \
101                                "offset:%u;\tsize:%u;\n",                \
102                                (unsigned int)offsetof(typeof(field), item), \
103                                (unsigned int)sizeof(field.item));       \
104         if (!ret)                                                       \
105                 return 0;
106
107 #undef __entry
108 #define __entry REC
109
110 #undef TP_printk
111 #define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
112
113 #undef TP_fast_assign
114 #define TP_fast_assign(args...) args
115
116 #undef TRACE_EVENT
117 #define TRACE_EVENT(call, proto, args, tstruct, func, print)            \
118 static int                                                              \
119 ftrace_format_##call(struct trace_seq *s)                               \
120 {                                                                       \
121         struct ftrace_raw_##call field;                                 \
122         int ret;                                                        \
123                                                                         \
124         tstruct;                                                        \
125                                                                         \
126         trace_seq_printf(s, "\nprint fmt: " print);                     \
127                                                                         \
128         return ret;                                                     \
129 }
130
131 #include <trace/trace_event_types.h>
132
133 #undef __field
134 #define __field(type, item)                                             \
135         ret = trace_define_field(event_call, #type, #item,              \
136                                  offsetof(typeof(field), item),         \
137                                  sizeof(field.item));                   \
138         if (ret)                                                        \
139                 return ret;
140
141 #undef __array
142 #define __array(type, item, len)                                        \
143         ret = trace_define_field(event_call, #type "[" #len "]", #item, \
144                                  offsetof(typeof(field), item),         \
145                                  sizeof(field.item));                   \
146         if (ret)                                                        \
147                 return ret;
148
149 #undef TRACE_EVENT
150 #define TRACE_EVENT(call, proto, args, tstruct, func, print)            \
151 int                                                                     \
152 ftrace_define_fields_##call(void)                                       \
153 {                                                                       \
154         struct ftrace_raw_##call field;                                 \
155         struct ftrace_event_call *event_call = &event_##call;           \
156         int ret;                                                        \
157                                                                         \
158         __common_field(unsigned char, type);                            \
159         __common_field(unsigned char, flags);                           \
160         __common_field(unsigned char, preempt_count);                   \
161         __common_field(int, pid);                                       \
162         __common_field(int, tgid);                                      \
163                                                                         \
164         tstruct;                                                        \
165                                                                         \
166         return ret;                                                     \
167 }
168
169 #include <trace/trace_event_types.h>