2 * trace_export.c - export basic ftrace utilities to user space
4 * Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
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>
16 #include "trace_output.h"
19 #define TRACE_SYSTEM ftrace
21 /* not needed for this file */
23 #define __field_struct(type, item)
26 #define __field(type, item) type item;
29 #define __field_desc(type, container, item) type item;
32 #define __array(type, item, size) type item[size];
35 #define __array_desc(type, container, item, size) type item[size];
37 #undef __dynamic_array
38 #define __dynamic_array(type, item) type item[];
41 #define F_STRUCT(args...) args
44 #define F_printk(fmt, args...) fmt, args
47 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
48 struct ____ftrace_##name { \
51 static void __used ____ftrace_check_##name(void) \
53 struct ____ftrace_##name *__entry = NULL; \
55 /* force cmpile-time check on F_printk() */ \
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"
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)); \
76 #define __field_desc(type, container, item) \
77 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
78 "offset:%zu;\tsize:%zu;\n", \
79 offsetof(typeof(field), container.item), \
80 sizeof(field.container.item)); \
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)); \
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)); \
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)); \
111 #define F_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
117 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
119 ftrace_format_##name(struct ftrace_event_call *unused, \
120 struct trace_seq *s) \
122 struct struct_name field __attribute__((unused)); \
127 trace_seq_printf(s, "\nprint fmt: " print); \
132 #include "trace_entries.h"
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); \
145 #define __field_desc(type, container, item) \
146 ret = trace_define_field(event_call, #type, #item, \
147 offsetof(typeof(field), \
149 sizeof(field.container.item), \
150 is_signed_type(type), FILTER_OTHER); \
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); \
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), \
169 sizeof(field.container.item), 0, \
174 #undef __dynamic_array
175 #define __dynamic_array(type, item)
178 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
180 ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
182 struct struct_name field; \
185 ret = trace_define_common_fields(event_call); \
194 #include "trace_entries.h"
198 #define __field(type, item)
201 #define __field_desc(type, container, item)
204 #define __array(type, item, len)
207 #define __array_desc(type, container, item, len)
209 #undef __dynamic_array
210 #define __dynamic_array(type, item)
213 #define FTRACE_ENTRY(call, struct_name, type, tstruct, print) \
214 static int ftrace_raw_init_event_##call(void); \
216 struct ftrace_event_call __used \
217 __attribute__((__aligned__(4))) \
218 __attribute__((section("_ftrace_events"))) event_##call = { \
221 .system = __stringify(TRACE_SYSTEM), \
222 .raw_init = ftrace_raw_init_event_##call, \
223 .show_format = ftrace_format_##call, \
224 .define_fields = ftrace_define_fields_##call, \
226 static int ftrace_raw_init_event_##call(void) \
228 INIT_LIST_HEAD(&event_##call.fields); \
232 #include "trace_entries.h"