]> git.karo-electronics.de Git - karo-tx-linux.git/blob - kernel/trace/trace_export.c
tracing: Create class struct for events
[karo-tx-linux.git] / kernel / trace / trace_export.c
1 /*
2  * trace_export.c - export basic ftrace utilities to user space
3  *
4  * Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
5  */
6 #include <linux/stringify.h>
7 #include <linux/kallsyms.h>
8 #include <linux/seq_file.h>
9 #include <linux/debugfs.h>
10 #include <linux/uaccess.h>
11 #include <linux/ftrace.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/fs.h>
15
16 #include "trace_output.h"
17
18 #undef TRACE_SYSTEM
19 #define TRACE_SYSTEM    ftrace
20
21 struct ftrace_event_class event_class_ftrace = {
22         .system                 = __stringify(TRACE_SYSTEM),
23 };
24
25 /* not needed for this file */
26 #undef __field_struct
27 #define __field_struct(type, item)
28
29 #undef __field
30 #define __field(type, item)                             type item;
31
32 #undef __field_desc
33 #define __field_desc(type, container, item)             type item;
34
35 #undef __array
36 #define __array(type, item, size)                       type item[size];
37
38 #undef __array_desc
39 #define __array_desc(type, container, item, size)       type item[size];
40
41 #undef __dynamic_array
42 #define __dynamic_array(type, item)                     type item[];
43
44 #undef F_STRUCT
45 #define F_STRUCT(args...)                               args
46
47 #undef F_printk
48 #define F_printk(fmt, args...) fmt, args
49
50 #undef FTRACE_ENTRY
51 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print)     \
52 struct ____ftrace_##name {                                      \
53         tstruct                                                 \
54 };                                                              \
55 static void __always_unused ____ftrace_check_##name(void)       \
56 {                                                               \
57         struct ____ftrace_##name *__entry = NULL;               \
58                                                                 \
59         /* force compile-time check on F_printk() */            \
60         printk(print);                                          \
61 }
62
63 #undef FTRACE_ENTRY_DUP
64 #define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print) \
65         FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
66
67 #include "trace_entries.h"
68
69 #undef __field
70 #define __field(type, item)                                             \
71         ret = trace_define_field(event_call, #type, #item,              \
72                                  offsetof(typeof(field), item),         \
73                                  sizeof(field.item),                    \
74                                  is_signed_type(type), FILTER_OTHER);   \
75         if (ret)                                                        \
76                 return ret;
77
78 #undef __field_desc
79 #define __field_desc(type, container, item)     \
80         ret = trace_define_field(event_call, #type, #item,              \
81                                  offsetof(typeof(field),                \
82                                           container.item),              \
83                                  sizeof(field.container.item),          \
84                                  is_signed_type(type), FILTER_OTHER);   \
85         if (ret)                                                        \
86                 return ret;
87
88 #undef __array
89 #define __array(type, item, len)                                        \
90         BUILD_BUG_ON(len > MAX_FILTER_STR_VAL);                         \
91         ret = trace_define_field(event_call, #type "[" #len "]", #item, \
92                                  offsetof(typeof(field), item),         \
93                                  sizeof(field.item),                    \
94                                  is_signed_type(type), FILTER_OTHER);   \
95         if (ret)                                                        \
96                 return ret;
97
98 #undef __array_desc
99 #define __array_desc(type, container, item, len)                        \
100         BUILD_BUG_ON(len > MAX_FILTER_STR_VAL);                         \
101         ret = trace_define_field(event_call, #type "[" #len "]", #item, \
102                                  offsetof(typeof(field),                \
103                                           container.item),              \
104                                  sizeof(field.container.item),          \
105                                  is_signed_type(type), FILTER_OTHER);   \
106         if (ret)                                                        \
107                 return ret;
108
109 #undef __dynamic_array
110 #define __dynamic_array(type, item)                                     \
111         ret = trace_define_field(event_call, #type, #item,              \
112                                  offsetof(typeof(field), item),         \
113                                  0, is_signed_type(type), FILTER_OTHER);\
114         if (ret)                                                        \
115                 return ret;
116
117 #undef FTRACE_ENTRY
118 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print)             \
119 int                                                                     \
120 ftrace_define_fields_##name(struct ftrace_event_call *event_call)       \
121 {                                                                       \
122         struct struct_name field;                                       \
123         int ret;                                                        \
124                                                                         \
125         tstruct;                                                        \
126                                                                         \
127         return ret;                                                     \
128 }
129
130 #include "trace_entries.h"
131
132 static int ftrace_raw_init_event(struct ftrace_event_call *call)
133 {
134         INIT_LIST_HEAD(&call->fields);
135         return 0;
136 }
137
138 #undef __entry
139 #define __entry REC
140
141 #undef __field
142 #define __field(type, item)
143
144 #undef __field_desc
145 #define __field_desc(type, container, item)
146
147 #undef __array
148 #define __array(type, item, len)
149
150 #undef __array_desc
151 #define __array_desc(type, container, item, len)
152
153 #undef __dynamic_array
154 #define __dynamic_array(type, item)
155
156 #undef F_printk
157 #define F_printk(fmt, args...) #fmt ", "  __stringify(args)
158
159 #undef FTRACE_ENTRY
160 #define FTRACE_ENTRY(call, struct_name, type, tstruct, print)           \
161                                                                         \
162 struct ftrace_event_call __used                                         \
163 __attribute__((__aligned__(4)))                                         \
164 __attribute__((section("_ftrace_events"))) event_##call = {             \
165         .name                   = #call,                                \
166         .id                     = type,                                 \
167         .class                  = &event_class_ftrace,                  \
168         .raw_init               = ftrace_raw_init_event,                \
169         .print_fmt              = print,                                \
170         .define_fields          = ftrace_define_fields_##call,          \
171 };                                                                      \
172
173 #include "trace_entries.h"