Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux...
[deliverable/linux.git] / kernel / trace / trace_export.c
CommitLineData
770cb243
SR
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
4e5292ea
SR
18#undef TRACE_SYSTEM
19#define TRACE_SYSTEM ftrace
da4d0302 20
4e5292ea
SR
21/* not needed for this file */
22#undef __field_struct
23#define __field_struct(type, item)
da4d0302 24
05ffa2d0
LZ
25#undef __field
26#define __field(type, item) type item;
27
28#undef __field_desc
29#define __field_desc(type, container, item) type item;
30
31#undef __array
32#define __array(type, item, size) type item[size];
33
34#undef __array_desc
35#define __array_desc(type, container, item, size) type item[size];
36
37#undef __dynamic_array
38#define __dynamic_array(type, item) type item[];
39
40#undef F_STRUCT
41#define F_STRUCT(args...) args
42
43#undef F_printk
44#define F_printk(fmt, args...) fmt, args
45
46#undef FTRACE_ENTRY
47#define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
48struct ____ftrace_##name { \
49 tstruct \
50}; \
51static void __used ____ftrace_check_##name(void) \
52{ \
53 struct ____ftrace_##name *__entry = NULL; \
54 \
55 /* force cmpile-time check on F_printk() */ \
56 printk(print); \
57}
58
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))
62
63#include "trace_entries.h"
64
65
4e5292ea
SR
66#undef __field
67#define __field(type, item) \
68 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
69 "offset:%zu;\tsize:%zu;\n", \
70 offsetof(typeof(field), item), \
71 sizeof(field.item)); \
72 if (!ret) \
73 return 0;
75db37d2 74
4e5292ea
SR
75#undef __field_desc
76#define __field_desc(type, container, item) \
da4d0302 77 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
4e5292ea
SR
78 "offset:%zu;\tsize:%zu;\n", \
79 offsetof(typeof(field), container.item), \
80 sizeof(field.container.item)); \
da4d0302
SR
81 if (!ret) \
82 return 0;
83
4e5292ea
SR
84#undef __array
85#define __array(type, item, len) \
86 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
87 "offset:%zu;\tsize:%zu;\n", \
88 offsetof(typeof(field), item), \
89 sizeof(field.item)); \
90 if (!ret) \
91 return 0;
da4d0302 92
4e5292ea
SR
93#undef __array_desc
94#define __array_desc(type, container, item, len) \
95 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
96 "offset:%zu;\tsize:%zu;\n", \
97 offsetof(typeof(field), container.item), \
98 sizeof(field.container.item)); \
da4d0302
SR
99 if (!ret) \
100 return 0;
770cb243 101
4e5292ea
SR
102#undef __dynamic_array
103#define __dynamic_array(type, item) \
104 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
105 "offset:%zu;\tsize:0;\n", \
106 offsetof(typeof(field), item)); \
156b5f17 107 if (!ret) \
770cb243
SR
108 return 0;
109
4e5292ea
SR
110#undef F_printk
111#define F_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
770cb243 112
4e5292ea
SR
113#undef __entry
114#define __entry REC
770cb243 115
4e5292ea
SR
116#undef FTRACE_ENTRY
117#define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
770cb243 118static int \
4e5292ea
SR
119ftrace_format_##name(struct ftrace_event_call *unused, \
120 struct trace_seq *s) \
770cb243 121{ \
4e5292ea
SR
122 struct struct_name field __attribute__((unused)); \
123 int ret = 0; \
770cb243
SR
124 \
125 tstruct; \
126 \
4e5292ea 127 trace_seq_printf(s, "\nprint fmt: " print); \
770cb243
SR
128 \
129 return ret; \
130}
131
4e5292ea
SR
132#include "trace_entries.h"
133
134
135#undef __field
136#define __field(type, item) \
137 ret = trace_define_field(event_call, #type, #item, \
138 offsetof(typeof(field), item), \
139 sizeof(field.item), \
140 is_signed_type(type), FILTER_OTHER); \
141 if (ret) \
142 return ret;
143
144#undef __field_desc
145#define __field_desc(type, container, item) \
146 ret = trace_define_field(event_call, #type, #item, \
147 offsetof(typeof(field), \
148 container.item), \
149 sizeof(field.container.item), \
150 is_signed_type(type), FILTER_OTHER); \
151 if (ret) \
152 return ret;
153
154#undef __array
155#define __array(type, item, len) \
156 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
157 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
158 offsetof(typeof(field), item), \
159 sizeof(field.item), 0, FILTER_OTHER); \
160 if (ret) \
161 return ret;
162
163#undef __array_desc
164#define __array_desc(type, container, item, len) \
165 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
166 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
167 offsetof(typeof(field), \
168 container.item), \
169 sizeof(field.container.item), 0, \
170 FILTER_OTHER); \
171 if (ret) \
172 return ret;
173
174#undef __dynamic_array
175#define __dynamic_array(type, item)
176
177#undef FTRACE_ENTRY
178#define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
179int \
180ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
e45f2e2b 181{ \
4e5292ea 182 struct struct_name field; \
e45f2e2b
TZ
183 int ret; \
184 \
4e5292ea
SR
185 ret = trace_define_common_fields(event_call); \
186 if (ret) \
187 return ret; \
e45f2e2b 188 \
4e5292ea 189 tstruct; \
e45f2e2b
TZ
190 \
191 return ret; \
192}
193
4e5292ea
SR
194#include "trace_entries.h"
195
196
197#undef __field
198#define __field(type, item)
199
200#undef __field_desc
201#define __field_desc(type, container, item)
202
203#undef __array
204#define __array(type, item, len)
205
206#undef __array_desc
207#define __array_desc(type, container, item, len)
208
209#undef __dynamic_array
210#define __dynamic_array(type, item)
211
4e5292ea
SR
212#undef FTRACE_ENTRY
213#define FTRACE_ENTRY(call, struct_name, type, tstruct, print) \
e1112b4d 214static int ftrace_raw_init_event_##call(void); \
770cb243 215 \
e1112b4d 216struct ftrace_event_call __used \
770cb243
SR
217__attribute__((__aligned__(4))) \
218__attribute__((section("_ftrace_events"))) event_##call = { \
ef18012b 219 .name = #call, \
4e5292ea 220 .id = type, \
770cb243 221 .system = __stringify(TRACE_SYSTEM), \
e1112b4d 222 .raw_init = ftrace_raw_init_event_##call, \
770cb243 223 .show_format = ftrace_format_##call, \
e1112b4d
TZ
224 .define_fields = ftrace_define_fields_##call, \
225}; \
226static int ftrace_raw_init_event_##call(void) \
227{ \
228 INIT_LIST_HEAD(&event_##call.fields); \
229 return 0; \
230} \
231
4e5292ea 232#include "trace_entries.h"
This page took 0.093947 seconds and 5 git commands to generate.