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 __always_unused ____ftrace_check_##name(void) \
53 struct ____ftrace_##name *__entry = NULL; \
55 /* force compile-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;\tsigned:%u;\n", \
70 offsetof(typeof(field), item), \
71 sizeof(field.item), is_signed_type(type)); \
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)); \
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)); \
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)); \
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)); \
114 #define F_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
120 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
122 ftrace_format_##name(struct ftrace_event_call *unused, \
123 struct trace_seq *s) \
125 struct struct_name field __attribute__((unused)); \
130 trace_seq_printf(s, "\nprint fmt: " print); \
135 #include "trace_entries.h"
138 #define __field(type, item) \
139 ret = trace_define_field(event_call, #type, #item, \
140 offsetof(typeof(field), item), \
141 sizeof(field.item), \
142 is_signed_type(type), FILTER_OTHER); \
147 #define __field_desc(type, container, item) \
148 ret = trace_define_field(event_call, #type, #item, \
149 offsetof(typeof(field), \
151 sizeof(field.container.item), \
152 is_signed_type(type), FILTER_OTHER); \
157 #define __array(type, item, len) \
158 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
159 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
160 offsetof(typeof(field), item), \
161 sizeof(field.item), 0, FILTER_OTHER); \
166 #define __array_desc(type, container, item, len) \
167 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
168 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
169 offsetof(typeof(field), \
171 sizeof(field.container.item), 0, \
176 #undef __dynamic_array
177 #define __dynamic_array(type, item)
180 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
182 ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
184 struct struct_name field; \
187 ret = trace_define_common_fields(event_call); \
196 #include "trace_entries.h"
198 static int ftrace_raw_init_event(struct ftrace_event_call
*call
)
200 INIT_LIST_HEAD(&call
->fields
);
205 #define __field(type, item)
208 #define __field_desc(type, container, item)
211 #define __array(type, item, len)
214 #define __array_desc(type, container, item, len)
216 #undef __dynamic_array
217 #define __dynamic_array(type, item)
220 #define FTRACE_ENTRY(call, struct_name, type, tstruct, print) \
222 struct ftrace_event_call __used \
223 __attribute__((__aligned__(4))) \
224 __attribute__((section("_ftrace_events"))) event_##call = { \
227 .system = __stringify(TRACE_SYSTEM), \
228 .raw_init = ftrace_raw_init_event, \
229 .show_format = ftrace_format_##call, \
230 .define_fields = ftrace_define_fields_##call, \
233 #include "trace_entries.h"