blob: 70875303ae463301e57ee12029f73d1ae7c4a1d8 [file] [log] [blame]
Steven Rostedt770cb242009-03-05 21:35:29 -05001/*
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
Steven Rostedtda4d0302009-03-09 17:14:30 -040018
19#undef TRACE_STRUCT
20#define TRACE_STRUCT(args...) args
21
Steven Rostedt75db37d2009-03-26 11:43:36 -040022extern void __bad_type_size(void);
23
Steven Rostedtda4d0302009-03-09 17:14:30 -040024#undef TRACE_FIELD
25#define TRACE_FIELD(type, item, assign) \
Steven Rostedt75db37d2009-03-26 11:43:36 -040026 if (sizeof(type) != sizeof(field.item)) \
27 __bad_type_size(); \
Steven Rostedtda4d0302009-03-09 17:14:30 -040028 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)); \
32 if (!ret) \
33 return 0;
34
35
36#undef TRACE_FIELD_SPECIAL
Tom Zanussie1112b42009-03-31 00:48:49 -050037#define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
Steven Rostedtda4d0302009-03-09 17:14:30 -040038 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)); \
42 if (!ret) \
43 return 0;
Steven Rostedt770cb242009-03-05 21:35:29 -050044
45#undef TRACE_FIELD_ZERO_CHAR
Steven Rostedt156b5f12009-03-06 10:50:53 -050046#define TRACE_FIELD_ZERO_CHAR(item) \
Zhaolei1bbe2a82009-04-03 18:24:46 +080047 ret = trace_seq_printf(s, "\tfield:char " #item ";\t" \
Steven Rostedt156b5f12009-03-06 10:50:53 -050048 "offset:%u;\tsize:0;\n", \
49 (unsigned int)offsetof(typeof(field), item)); \
50 if (!ret) \
Steven Rostedt770cb242009-03-05 21:35:29 -050051 return 0;
52
Tom Zanussia118e4d2009-04-28 03:04:53 -050053#undef TRACE_FIELD_SIGN
54#define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
55 TRACE_FIELD(type, item, assign)
Steven Rostedt770cb242009-03-05 21:35:29 -050056
Steven Rostedt2939b042009-03-09 15:47:18 -040057#undef TP_RAW_FMT
58#define TP_RAW_FMT(args...) args
Steven Rostedt770cb242009-03-05 21:35:29 -050059
60#undef TRACE_EVENT_FORMAT
61#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
62static int \
Frederic Weisbeckere8f9f4d2009-08-11 17:42:52 +020063ftrace_format_##call(struct ftrace_event_call *unused, \
64 struct trace_seq *s) \
Steven Rostedt770cb242009-03-05 21:35:29 -050065{ \
66 struct args field; \
67 int ret; \
68 \
69 tstruct; \
70 \
71 trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
72 \
73 return ret; \
74}
75
Tom Zanussie45f2e22009-03-31 00:49:16 -050076#undef TRACE_EVENT_FORMAT_NOFILTER
77#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
78 tpfmt) \
79static int \
Frederic Weisbeckere8f9f4d2009-08-11 17:42:52 +020080ftrace_format_##call(struct ftrace_event_call *unused, \
81 struct trace_seq *s) \
Tom Zanussie45f2e22009-03-31 00:49:16 -050082{ \
83 struct args field; \
84 int ret; \
85 \
86 tstruct; \
87 \
88 trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
89 \
90 return ret; \
91}
92
Steven Rostedt770cb242009-03-05 21:35:29 -050093#include "trace_event_types.h"
94
95#undef TRACE_ZERO_CHAR
96#define TRACE_ZERO_CHAR(arg)
97
98#undef TRACE_FIELD
99#define TRACE_FIELD(type, item, assign)\
100 entry->item = assign;
101
102#undef TRACE_FIELD
103#define TRACE_FIELD(type, item, assign)\
104 entry->item = assign;
105
Tom Zanussia118e4d2009-04-28 03:04:53 -0500106#undef TRACE_FIELD_SIGN
107#define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
108 TRACE_FIELD(type, item, assign)
109
Steven Rostedt2939b042009-03-09 15:47:18 -0400110#undef TP_CMD
111#define TP_CMD(cmd...) cmd
Steven Rostedt770cb242009-03-05 21:35:29 -0500112
113#undef TRACE_ENTRY
114#define TRACE_ENTRY entry
115
116#undef TRACE_FIELD_SPECIAL
Tom Zanussie1112b42009-03-31 00:48:49 -0500117#define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
Steven Rostedt770cb242009-03-05 21:35:29 -0500118 cmd;
119
120#undef TRACE_EVENT_FORMAT
121#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
Li Zefan14be96c2009-08-19 15:53:52 +0800122int ftrace_define_fields_##call(struct ftrace_event_call *event_call); \
Tom Zanussie1112b42009-03-31 00:48:49 -0500123static int ftrace_raw_init_event_##call(void); \
Steven Rostedt770cb242009-03-05 21:35:29 -0500124 \
Tom Zanussie1112b42009-03-31 00:48:49 -0500125struct ftrace_event_call __used \
Steven Rostedt770cb242009-03-05 21:35:29 -0500126__attribute__((__aligned__(4))) \
127__attribute__((section("_ftrace_events"))) event_##call = { \
Steven Rostedtef180122009-03-10 14:10:56 -0400128 .name = #call, \
Steven Rostedt770cb242009-03-05 21:35:29 -0500129 .id = proto, \
130 .system = __stringify(TRACE_SYSTEM), \
Tom Zanussie1112b42009-03-31 00:48:49 -0500131 .raw_init = ftrace_raw_init_event_##call, \
Steven Rostedt770cb242009-03-05 21:35:29 -0500132 .show_format = ftrace_format_##call, \
Tom Zanussie1112b42009-03-31 00:48:49 -0500133 .define_fields = ftrace_define_fields_##call, \
134}; \
135static int ftrace_raw_init_event_##call(void) \
136{ \
137 INIT_LIST_HEAD(&event_##call.fields); \
Tom Zanussi0a19e532009-04-13 03:17:50 -0500138 init_preds(&event_##call); \
Tom Zanussie1112b42009-03-31 00:48:49 -0500139 return 0; \
140} \
141
Tom Zanussie45f2e22009-03-31 00:49:16 -0500142#undef TRACE_EVENT_FORMAT_NOFILTER
143#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
144 tpfmt) \
145 \
146struct ftrace_event_call __used \
147__attribute__((__aligned__(4))) \
148__attribute__((section("_ftrace_events"))) event_##call = { \
149 .name = #call, \
150 .id = proto, \
151 .system = __stringify(TRACE_SYSTEM), \
152 .show_format = ftrace_format_##call, \
153};
154
Tom Zanussie1112b42009-03-31 00:48:49 -0500155#include "trace_event_types.h"
156
157#undef TRACE_FIELD
158#define TRACE_FIELD(type, item, assign) \
159 ret = trace_define_field(event_call, #type, #item, \
160 offsetof(typeof(field), item), \
Tom Zanussia118e4d2009-04-28 03:04:53 -0500161 sizeof(field.item), is_signed_type(type)); \
Tom Zanussie1112b42009-03-31 00:48:49 -0500162 if (ret) \
163 return ret;
164
165#undef TRACE_FIELD_SPECIAL
166#define TRACE_FIELD_SPECIAL(type, item, len, cmd) \
167 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
168 offsetof(typeof(field), item), \
Tom Zanussia118e4d2009-04-28 03:04:53 -0500169 sizeof(field.item), 0); \
170 if (ret) \
171 return ret;
172
173#undef TRACE_FIELD_SIGN
174#define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
175 ret = trace_define_field(event_call, #type, #item, \
176 offsetof(typeof(field), item), \
177 sizeof(field.item), is_signed); \
Tom Zanussie1112b42009-03-31 00:48:49 -0500178 if (ret) \
179 return ret;
180
181#undef TRACE_FIELD_ZERO_CHAR
182#define TRACE_FIELD_ZERO_CHAR(item)
183
184#undef TRACE_EVENT_FORMAT
185#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
186int \
Li Zefan14be96c2009-08-19 15:53:52 +0800187ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
Tom Zanussie1112b42009-03-31 00:48:49 -0500188{ \
Tom Zanussie1112b42009-03-31 00:48:49 -0500189 struct args field; \
190 int ret; \
191 \
Li Zefane647d6b2009-08-19 15:54:32 +0800192 ret = trace_define_common_fields(event_call); \
193 if (ret) \
194 return ret; \
Tom Zanussie1112b42009-03-31 00:48:49 -0500195 \
196 tstruct; \
197 \
198 return ret; \
Steven Rostedt770cb242009-03-05 21:35:29 -0500199}
Tom Zanussie1112b42009-03-31 00:48:49 -0500200
Tom Zanussie45f2e22009-03-31 00:49:16 -0500201#undef TRACE_EVENT_FORMAT_NOFILTER
202#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
203 tpfmt)
204
Steven Rostedt770cb242009-03-05 21:35:29 -0500205#include "trace_event_types.h"