mm-only debug patch...
[mmotm.git] / kernel / trace / trace_export.c
blob31da218ee10f317e6076eaa016e2b28eff599027
1 /*
2 * trace_export.c - export basic ftrace utilities to user space
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>
16 #include "trace_output.h"
18 #undef TRACE_SYSTEM
19 #define TRACE_SYSTEM ftrace
21 /* not needed for this file */
22 #undef __field_struct
23 #define __field_struct(type, item)
25 #undef __field
26 #define __field(type, item) type item;
28 #undef __field_desc
29 #define __field_desc(type, container, item) type item;
31 #undef __array
32 #define __array(type, item, size) type item[size];
34 #undef __array_desc
35 #define __array_desc(type, container, item, size) type item[size];
37 #undef __dynamic_array
38 #define __dynamic_array(type, item) type item[];
40 #undef F_STRUCT
41 #define F_STRUCT(args...) args
43 #undef F_printk
44 #define F_printk(fmt, args...) fmt, args
46 #undef FTRACE_ENTRY
47 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
48 struct ____ftrace_##name { \
49 tstruct \
50 }; \
51 static void __used ____ftrace_check_##name(void) \
52 { \
53 struct ____ftrace_##name *__entry = NULL; \
55 /* force cmpile-time check on F_printk() */ \
56 printk(print); \
59 #undef FTRACE_ENTRY_DUP
60 #define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print) \
61 FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
63 #include "trace_entries.h"
66 #undef __field
67 #define __field(type, item) \
68 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
69 "offset:%zu;\tsize:%zu;\tsigned:%u;\n", \
70 offsetof(typeof(field), item), \
71 sizeof(field.item), is_signed_type(type)); \
72 if (!ret) \
73 return 0;
75 #undef __field_desc
76 #define __field_desc(type, container, item) \
77 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
78 "offset:%zu;\tsize:%zu;\tsigned:%u;\n", \
79 offsetof(typeof(field), container.item), \
80 sizeof(field.container.item), \
81 is_signed_type(type)); \
82 if (!ret) \
83 return 0;
85 #undef __array
86 #define __array(type, item, len) \
87 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
88 "offset:%zu;\tsize:%zu;\tsigned:%u;\n", \
89 offsetof(typeof(field), item), \
90 sizeof(field.item), is_signed_type(type)); \
91 if (!ret) \
92 return 0;
94 #undef __array_desc
95 #define __array_desc(type, container, item, len) \
96 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
97 "offset:%zu;\tsize:%zu;\tsigned:%u;\n", \
98 offsetof(typeof(field), container.item), \
99 sizeof(field.container.item), \
100 is_signed_type(type)); \
101 if (!ret) \
102 return 0;
104 #undef __dynamic_array
105 #define __dynamic_array(type, item) \
106 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
107 "offset:%zu;\tsize:0;\tsigned:%u;\n", \
108 offsetof(typeof(field), item), \
109 is_signed_type(type)); \
110 if (!ret) \
111 return 0;
113 #undef F_printk
114 #define F_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
116 #undef __entry
117 #define __entry REC
119 #undef FTRACE_ENTRY
120 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
121 static int \
122 ftrace_format_##name(struct ftrace_event_call *unused, \
123 struct trace_seq *s) \
125 struct struct_name field __attribute__((unused)); \
126 int ret = 0; \
128 tstruct; \
130 trace_seq_printf(s, "\nprint fmt: " print); \
132 return ret; \
135 #include "trace_entries.h"
138 #undef __field
139 #define __field(type, item) \
140 ret = trace_define_field(event_call, #type, #item, \
141 offsetof(typeof(field), item), \
142 sizeof(field.item), \
143 is_signed_type(type), FILTER_OTHER); \
144 if (ret) \
145 return ret;
147 #undef __field_desc
148 #define __field_desc(type, container, item) \
149 ret = trace_define_field(event_call, #type, #item, \
150 offsetof(typeof(field), \
151 container.item), \
152 sizeof(field.container.item), \
153 is_signed_type(type), FILTER_OTHER); \
154 if (ret) \
155 return ret;
157 #undef __array
158 #define __array(type, item, len) \
159 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
160 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
161 offsetof(typeof(field), item), \
162 sizeof(field.item), 0, FILTER_OTHER); \
163 if (ret) \
164 return ret;
166 #undef __array_desc
167 #define __array_desc(type, container, item, len) \
168 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
169 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
170 offsetof(typeof(field), \
171 container.item), \
172 sizeof(field.container.item), 0, \
173 FILTER_OTHER); \
174 if (ret) \
175 return ret;
177 #undef __dynamic_array
178 #define __dynamic_array(type, item)
180 #undef FTRACE_ENTRY
181 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
182 int \
183 ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
185 struct struct_name field; \
186 int ret; \
188 ret = trace_define_common_fields(event_call); \
189 if (ret) \
190 return ret; \
192 tstruct; \
194 return ret; \
197 #include "trace_entries.h"
200 #undef __field
201 #define __field(type, item)
203 #undef __field_desc
204 #define __field_desc(type, container, item)
206 #undef __array
207 #define __array(type, item, len)
209 #undef __array_desc
210 #define __array_desc(type, container, item, len)
212 #undef __dynamic_array
213 #define __dynamic_array(type, item)
215 #undef FTRACE_ENTRY
216 #define FTRACE_ENTRY(call, struct_name, type, tstruct, print) \
217 static int ftrace_raw_init_event_##call(void); \
219 struct ftrace_event_call __used \
220 __attribute__((__aligned__(4))) \
221 __attribute__((section("_ftrace_events"))) event_##call = { \
222 .name = #call, \
223 .id = type, \
224 .system = __stringify(TRACE_SYSTEM), \
225 .raw_init = ftrace_raw_init_event_##call, \
226 .show_format = ftrace_format_##call, \
227 .define_fields = ftrace_define_fields_##call, \
228 }; \
229 static int ftrace_raw_init_event_##call(void) \
231 INIT_LIST_HEAD(&event_##call.fields); \
232 return 0; \
235 #include "trace_entries.h"