Skip to content

Commit 4e5292e

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing: use the new trace_entries.h to create format files
This patch changes the way the format files in debugfs/tracing/events/ftrace/*/format are created. It uses the new trace_entries.h file to automate the creation of the format files to ensure that they are always in sync with the actual structures. This is the same methodology used to create the format files for the TRACE_EVENT macro. This also updates the filter creation that was built on the creation of the format files. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent d731509 commit 4e5292e

3 files changed

Lines changed: 136 additions & 118 deletions

File tree

‎kernel/trace/trace.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/clocksource.h>
88
#include <linux/ring_buffer.h>
99
#include <linux/mmiotrace.h>
10+
#include <linux/tracepoint.h>
1011
#include <linux/ftrace.h>
1112
#include <trace/boot.h>
1213
#include <linux/kmemtrace.h>
@@ -746,11 +747,12 @@ extern struct list_head ftrace_events;
746747
extern const char *__start___trace_bprintk_fmt[];
747748
extern const char *__stop___trace_bprintk_fmt[];
748749

749-
#undef TRACE_EVENT_FORMAT
750-
#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
750+
#undef FTRACE_ENTRY
751+
#define FTRACE_ENTRY(call, struct_name, id, tstruct, print) \
751752
extern struct ftrace_event_call event_##call;
752-
#undef TRACE_EVENT_FORMAT_NOFILTER
753-
#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, tpfmt)
754-
#include "trace_event_types.h"
753+
#undef FTRACE_ENTRY_DUP
754+
#define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print) \
755+
FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))
756+
#include "trace_entries.h"
755757

756758
#endif /* _LINUX_KERNEL_TRACE_H */

‎kernel/trace/trace_events.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "trace_output.h"
2323

24+
#undef TRACE_SYSTEM
2425
#define TRACE_SYSTEM "TRACE_SYSTEM"
2526

2627
DEFINE_MUTEX(event_mutex);

‎kernel/trace/trace_export.c‎

Lines changed: 128 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -15,82 +15,163 @@
1515

1616
#include "trace_output.h"
1717

18+
#undef TRACE_SYSTEM
19+
#define TRACE_SYSTEM ftrace
1820

19-
#undef TRACE_STRUCT
20-
#define TRACE_STRUCT(args...) args
21+
/* not needed for this file */
22+
#undef __field_struct
23+
#define __field_struct(type, item)
2124

22-
extern void __bad_type_size(void);
25+
#undef __field
26+
#define __field(type, item) \
27+
ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
28+
"offset:%zu;\tsize:%zu;\n", \
29+
offsetof(typeof(field), item), \
30+
sizeof(field.item)); \
31+
if (!ret) \
32+
return 0;
2333

24-
#undef TRACE_FIELD
25-
#define TRACE_FIELD(type, item, assign) \
26-
if (sizeof(type) != sizeof(field.item)) \
27-
__bad_type_size(); \
34+
#undef __field_desc
35+
#define __field_desc(type, container, item) \
2836
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)); \
37+
"offset:%zu;\tsize:%zu;\n", \
38+
offsetof(typeof(field), container.item), \
39+
sizeof(field.container.item)); \
3240
if (!ret) \
3341
return 0;
3442

43+
#undef __array
44+
#define __array(type, item, len) \
45+
ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
46+
"offset:%zu;\tsize:%zu;\n", \
47+
offsetof(typeof(field), item), \
48+
sizeof(field.item)); \
49+
if (!ret) \
50+
return 0;
3551

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)); \
52+
#undef __array_desc
53+
#define __array_desc(type, container, item, len) \
54+
ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
55+
"offset:%zu;\tsize:%zu;\n", \
56+
offsetof(typeof(field), container.item), \
57+
sizeof(field.container.item)); \
4258
if (!ret) \
4359
return 0;
4460

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)); \
61+
#undef __dynamic_array
62+
#define __dynamic_array(type, item) \
63+
ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
64+
"offset:%zu;\tsize:0;\n", \
65+
offsetof(typeof(field), item)); \
5066
if (!ret) \
5167
return 0;
5268

53-
#undef TRACE_FIELD_SIGN
54-
#define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
55-
TRACE_FIELD(type, item, assign)
69+
#undef F_printk
70+
#define F_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
5671

57-
#undef TP_RAW_FMT
58-
#define TP_RAW_FMT(args...) args
72+
#undef __entry
73+
#define __entry REC
5974

60-
#undef TRACE_EVENT_FORMAT
61-
#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
75+
#undef FTRACE_ENTRY
76+
#define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
6277
static int \
63-
ftrace_format_##call(struct ftrace_event_call *unused, \
64-
struct trace_seq *s) \
78+
ftrace_format_##name(struct ftrace_event_call *unused, \
79+
struct trace_seq *s) \
6580
{ \
66-
struct args field; \
67-
int ret; \
81+
struct struct_name field __attribute__((unused)); \
82+
int ret = 0; \
6883
\
6984
tstruct; \
7085
\
71-
trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
86+
trace_seq_printf(s, "\nprint fmt: " print); \
7287
\
7388
return ret; \
7489
}
7590

76-
#undef TRACE_EVENT_FORMAT_NOFILTER
77-
#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
78-
tpfmt) \
79-
static int \
80-
ftrace_format_##call(struct ftrace_event_call *unused, \
81-
struct trace_seq *s) \
91+
#undef FTRACE_ENTRY_DUP
92+
#define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print) \
93+
FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
94+
95+
#include "trace_entries.h"
96+
97+
98+
#undef __field
99+
#define __field(type, item) \
100+
ret = trace_define_field(event_call, #type, #item, \
101+
offsetof(typeof(field), item), \
102+
sizeof(field.item), \
103+
is_signed_type(type), FILTER_OTHER); \
104+
if (ret) \
105+
return ret;
106+
107+
#undef __field_desc
108+
#define __field_desc(type, container, item) \
109+
ret = trace_define_field(event_call, #type, #item, \
110+
offsetof(typeof(field), \
111+
container.item), \
112+
sizeof(field.container.item), \
113+
is_signed_type(type), FILTER_OTHER); \
114+
if (ret) \
115+
return ret;
116+
117+
#undef __array
118+
#define __array(type, item, len) \
119+
BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
120+
ret = trace_define_field(event_call, #type "[" #len "]", #item, \
121+
offsetof(typeof(field), item), \
122+
sizeof(field.item), 0, FILTER_OTHER); \
123+
if (ret) \
124+
return ret;
125+
126+
#undef __array_desc
127+
#define __array_desc(type, container, item, len) \
128+
BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
129+
ret = trace_define_field(event_call, #type "[" #len "]", #item, \
130+
offsetof(typeof(field), \
131+
container.item), \
132+
sizeof(field.container.item), 0, \
133+
FILTER_OTHER); \
134+
if (ret) \
135+
return ret;
136+
137+
#undef __dynamic_array
138+
#define __dynamic_array(type, item)
139+
140+
#undef FTRACE_ENTRY
141+
#define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
142+
int \
143+
ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
82144
{ \
83-
struct args field; \
145+
struct struct_name field; \
84146
int ret; \
85147
\
86-
tstruct; \
148+
ret = trace_define_common_fields(event_call); \
149+
if (ret) \
150+
return ret; \
87151
\
88-
trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
152+
tstruct; \
89153
\
90154
return ret; \
91155
}
92156

93-
#include "trace_event_types.h"
157+
#include "trace_entries.h"
158+
159+
160+
#undef __field
161+
#define __field(type, item)
162+
163+
#undef __field_desc
164+
#define __field_desc(type, container, item)
165+
166+
#undef __array
167+
#define __array(type, item, len)
168+
169+
#undef __array_desc
170+
#define __array_desc(type, container, item, len)
171+
172+
#undef __dynamic_array
173+
#define __dynamic_array(type, item)
174+
94175

95176
#undef TRACE_ZERO_CHAR
96177
#define TRACE_ZERO_CHAR(arg)
@@ -117,16 +198,15 @@ ftrace_format_##call(struct ftrace_event_call *unused, \
117198
#define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
118199
cmd;
119200

120-
#undef TRACE_EVENT_FORMAT
121-
#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
122-
int ftrace_define_fields_##call(struct ftrace_event_call *event_call); \
201+
#undef FTRACE_ENTRY
202+
#define FTRACE_ENTRY(call, struct_name, type, tstruct, print) \
123203
static int ftrace_raw_init_event_##call(void); \
124204
\
125205
struct ftrace_event_call __used \
126206
__attribute__((__aligned__(4))) \
127207
__attribute__((section("_ftrace_events"))) event_##call = { \
128208
.name = #call, \
129-
.id = proto, \
209+
.id = type, \
130210
.system = __stringify(TRACE_SYSTEM), \
131211
.raw_init = ftrace_raw_init_event_##call, \
132212
.show_format = ftrace_format_##call, \
@@ -138,69 +218,4 @@ static int ftrace_raw_init_event_##call(void) \
138218
return 0; \
139219
} \
140220

141-
#undef TRACE_EVENT_FORMAT_NOFILTER
142-
#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
143-
tpfmt) \
144-
\
145-
struct ftrace_event_call __used \
146-
__attribute__((__aligned__(4))) \
147-
__attribute__((section("_ftrace_events"))) event_##call = { \
148-
.name = #call, \
149-
.id = proto, \
150-
.system = __stringify(TRACE_SYSTEM), \
151-
.show_format = ftrace_format_##call, \
152-
};
153-
154-
#include "trace_event_types.h"
155-
156-
#undef TRACE_FIELD
157-
#define TRACE_FIELD(type, item, assign) \
158-
ret = trace_define_field(event_call, #type, #item, \
159-
offsetof(typeof(field), item), \
160-
sizeof(field.item), \
161-
is_signed_type(type), FILTER_OTHER); \
162-
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), \
169-
sizeof(field.item), 0, FILTER_OTHER); \
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, \
178-
FILTER_OTHER); \
179-
if (ret) \
180-
return ret;
181-
182-
#undef TRACE_FIELD_ZERO_CHAR
183-
#define TRACE_FIELD_ZERO_CHAR(item)
184-
185-
#undef TRACE_EVENT_FORMAT
186-
#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
187-
int \
188-
ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
189-
{ \
190-
struct args field; \
191-
int ret; \
192-
\
193-
ret = trace_define_common_fields(event_call); \
194-
if (ret) \
195-
return ret; \
196-
\
197-
tstruct; \
198-
\
199-
return ret; \
200-
}
201-
202-
#undef TRACE_EVENT_FORMAT_NOFILTER
203-
#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
204-
tpfmt)
205-
206-
#include "trace_event_types.h"
221+
#include "trace_entries.h"

0 commit comments

Comments
 (0)