tracing: add print format to event trace format files
[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, <TPRAWFMT> "%s", <ARGS> "\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 TRACE_STRUCT
36 #define TRACE_STRUCT(args...) args
37
38 #undef TRACE_FIELD
39 #define TRACE_FIELD(type, item, assign) \
40         field->item,
41
42 #undef TRACE_FIELD_SPECIAL
43 #define TRACE_FIELD_SPECIAL(type_item, item, cmd) \
44         field->item,
45
46
47 #undef TPRAWFMT
48 #define TPRAWFMT(args...)       args
49
50 #undef TRACE_EVENT_FORMAT
51 #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt)      \
52 enum print_line_t                                                       \
53 ftrace_raw_output_##call(struct trace_iterator *iter, int flags)        \
54 {                                                                       \
55         struct trace_seq *s = &iter->seq;                               \
56         struct ftrace_raw_##call *field;                                \
57         struct trace_entry *entry;                                      \
58         int ret;                                                        \
59                                                                         \
60         entry = iter->ent;                                              \
61                                                                         \
62         if (entry->type != event_##call.id) {                           \
63                 WARN_ON_ONCE(1);                                        \
64                 return TRACE_TYPE_UNHANDLED;                            \
65         }                                                               \
66                                                                         \
67         field = (typeof(field))entry;                                   \
68                                                                         \
69         ret = trace_seq_printf(s, tpfmt "%s", tstruct "\n");            \
70         if (!ret)                                                       \
71                 return TRACE_TYPE_PARTIAL_LINE;                         \
72                                                                         \
73         return TRACE_TYPE_HANDLED;                                      \
74 }
75
76 #include <trace/trace_event_types.h>
77
78 /*
79  * Setup the showing format of trace point.
80  *
81  * int
82  * ftrace_format_##call(struct trace_seq *s)
83  * {
84  *      struct ftrace_raw_##call field;
85  *      int ret;
86  *
87  *      ret = trace_seq_printf(s, #type " " #item ";"
88  *                             " size:%d; offset:%d;\n",
89  *                             sizeof(field.type),
90  *                             offsetof(struct ftrace_raw_##call,
91  *                                      item));
92  *
93  * }
94  */
95
96 #undef TRACE_FIELD
97 #define TRACE_FIELD(type, item, assign)                                 \
98         ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t"      \
99                                "offset:%lu;\tsize:%lu;\n",              \
100                                offsetof(typeof(field), item),           \
101                                sizeof(field.item));                     \
102         if (!ret)                                                       \
103                 return 0;
104
105
106 #undef TRACE_FIELD_SPECIAL
107 #define TRACE_FIELD_SPECIAL(type_item, item, cmd)                       \
108         ret = trace_seq_printf(s, "\tfield special:" #type_item ";\t"   \
109                                "offset:%lu;\tsize:%lu;\n",              \
110                                offsetof(typeof(field), item),           \
111                                sizeof(field.item));                     \
112         if (!ret)                                                       \
113                 return 0;
114
115 #undef TRACE_EVENT_FORMAT
116 #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt)      \
117 int                                                                     \
118 ftrace_format_##call(struct trace_seq *s)                               \
119 {                                                                       \
120         struct ftrace_raw_##call field;                                 \
121         int ret;                                                        \
122                                                                         \
123         tstruct;                                                        \
124                                                                         \
125         trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt);            \
126                                                                         \
127         return ret;                                                     \
128 }
129
130 #include <trace/trace_event_types.h>