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"
20 #define TRACE_STRUCT(args...) args
22 extern void __bad_type_size(void);
25 #define TRACE_FIELD(type, item, assign) \
26 if (sizeof(type) != sizeof(field.item)) \
28 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
29 "offset:%u;\tsize:%u;\n", \
30 (unsigned int)offsetof(typeof(field), item), \
31 (unsigned int)sizeof(field.item)); \
36 #undef TRACE_FIELD_SPECIAL
37 #define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
38 ret = trace_seq_printf(s, "\tfield special:" #type_item ";\t" \
39 "offset:%u;\tsize:%u;\n", \
40 (unsigned int)offsetof(typeof(field), item), \
41 (unsigned int)sizeof(field.item)); \
45 #undef TRACE_FIELD_ZERO_CHAR
46 #define TRACE_FIELD_ZERO_CHAR(item) \
47 ret = trace_seq_printf(s, "\tfield:char " #item ";\t" \
48 "offset:%u;\tsize:0;\n", \
49 (unsigned int)offsetof(typeof(field), item)); \
53 #undef TRACE_FIELD_SIGN
54 #define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
55 TRACE_FIELD(type, item, assign)
58 #define TP_RAW_FMT(args...) args
60 #undef TRACE_EVENT_FORMAT
61 #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
63 ftrace_format_##call(struct trace_seq *s) \
70 trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
75 #undef TRACE_EVENT_FORMAT_NOFILTER
76 #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
79 ftrace_format_##call(struct trace_seq *s) \
86 trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
91 #include "trace_event_types.h"
93 #undef TRACE_ZERO_CHAR
94 #define TRACE_ZERO_CHAR(arg)
97 #define TRACE_FIELD(type, item, assign)\
101 #define TRACE_FIELD(type, item, assign)\
102 entry->item = assign;
104 #undef TRACE_FIELD_SIGN
105 #define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
106 TRACE_FIELD(type, item, assign)
109 #define TP_CMD(cmd...) cmd
112 #define TRACE_ENTRY entry
114 #undef TRACE_FIELD_SPECIAL
115 #define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
118 #undef TRACE_EVENT_FORMAT
119 #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
120 int ftrace_define_fields_##call(void); \
121 static int ftrace_raw_init_event_##call(void); \
123 struct ftrace_event_call __used \
124 __attribute__((__aligned__(4))) \
125 __attribute__((section("_ftrace_events"))) event_##call = { \
128 .system = __stringify(TRACE_SYSTEM), \
129 .raw_init = ftrace_raw_init_event_##call, \
130 .show_format = ftrace_format_##call, \
131 .define_fields = ftrace_define_fields_##call, \
133 static int ftrace_raw_init_event_##call(void) \
135 INIT_LIST_HEAD(&event_##call.fields); \
136 init_preds(&event_##call); \
140 #undef TRACE_EVENT_FORMAT_NOFILTER
141 #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
144 struct ftrace_event_call __used \
145 __attribute__((__aligned__(4))) \
146 __attribute__((section("_ftrace_events"))) event_##call = { \
149 .system = __stringify(TRACE_SYSTEM), \
150 .show_format = ftrace_format_##call, \
153 #include "trace_event_types.h"
156 #define TRACE_FIELD(type, item, assign) \
157 ret = trace_define_field(event_call, #type, #item, \
158 offsetof(typeof(field), item), \
159 sizeof(field.item), is_signed_type(type)); \
163 #undef TRACE_FIELD_SPECIAL
164 #define TRACE_FIELD_SPECIAL(type, item, len, cmd) \
165 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
166 offsetof(typeof(field), item), \
167 sizeof(field.item), 0); \
171 #undef TRACE_FIELD_SIGN
172 #define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
173 ret = trace_define_field(event_call, #type, #item, \
174 offsetof(typeof(field), item), \
175 sizeof(field.item), is_signed); \
179 #undef TRACE_FIELD_ZERO_CHAR
180 #define TRACE_FIELD_ZERO_CHAR(item)
182 #undef TRACE_EVENT_FORMAT
183 #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
185 ftrace_define_fields_##call(void) \
187 struct ftrace_event_call *event_call = &event_##call; \
191 __common_field(unsigned char, type, 0); \
192 __common_field(unsigned char, flags, 0); \
193 __common_field(unsigned char, preempt_count, 0); \
194 __common_field(int, pid, 1); \
195 __common_field(int, tgid, 1); \
202 #undef TRACE_EVENT_FORMAT_NOFILTER
203 #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
206 #include "trace_event_types.h"