diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2009-08-19 03:54:51 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-08-19 09:02:24 -0400 |
commit | 540b7b8d65575c80162f2a0f38e1d313c92a6042 (patch) | |
tree | 664bdd01ce8fce990e634a304f9b3ab51e50970c | |
parent | e647d6b314266adb904d4b84973eda0afa856946 (diff) |
tracing/syscalls: Add filtering support
Add filtering support for syscall events:
# echo 'mode == 0666' > events/syscalls/sys_enter_open
# echo 'ret == 0' > events/syscalls/sys_exit_open
# echo 1 > events/syscalls/sys_enter_open
# echo 1 > events/syscalls/sys_exit_open
# cat trace
...
modprobe-3084 [001] 117.463140: sys_open(filename: 917d3e8, flags: 0, mode: 1b6)
modprobe-3084 [001] 117.463176: sys_open -> 0x0
less-3086 [001] 117.510455: sys_open(filename: 9c6bdb8, flags: 8000, mode: 1b6)
sendmail-2574 [001] 122.145840: sys_open(filename: b807a365, flags: 0, mode: 1b6)
...
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <4A8BAFCB.1040006@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | include/linux/ftrace_event.h | 5 | ||||
-rw-r--r-- | include/linux/syscalls.h | 16 | ||||
-rw-r--r-- | include/trace/syscall.h | 7 | ||||
-rw-r--r-- | kernel/trace/trace_events.c | 5 | ||||
-rw-r--r-- | kernel/trace/trace_syscalls.c | 51 |
5 files changed, 71 insertions, 13 deletions
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h index 427cbae47f84..df5b085c4150 100644 --- a/include/linux/ftrace_event.h +++ b/include/linux/ftrace_event.h | |||
@@ -140,8 +140,9 @@ extern int filter_current_check_discard(struct ftrace_event_call *call, | |||
140 | void *rec, | 140 | void *rec, |
141 | struct ring_buffer_event *event); | 141 | struct ring_buffer_event *event); |
142 | 142 | ||
143 | extern int trace_define_field(struct ftrace_event_call *call, char *type, | 143 | extern int trace_define_field(struct ftrace_event_call *call, |
144 | char *name, int offset, int size, int is_signed); | 144 | const char *type, const char *name, |
145 | int offset, int size, int is_signed); | ||
145 | extern int trace_define_common_fields(struct ftrace_event_call *call); | 146 | extern int trace_define_common_fields(struct ftrace_event_call *call); |
146 | 147 | ||
147 | #define is_signed_type(type) (((type)(-1)) < 0) | 148 | #define is_signed_type(type) (((type)(-1)) < 0) |
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 8d57f77794ee..f124c8995555 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h | |||
@@ -190,6 +190,7 @@ static void prof_sysexit_disable_##sname(struct ftrace_event_call *event_call) \ | |||
190 | .event = &event_syscall_enter, \ | 190 | .event = &event_syscall_enter, \ |
191 | .raw_init = init_enter_##sname, \ | 191 | .raw_init = init_enter_##sname, \ |
192 | .show_format = syscall_enter_format, \ | 192 | .show_format = syscall_enter_format, \ |
193 | .define_fields = syscall_enter_define_fields, \ | ||
193 | .regfunc = reg_event_syscall_enter, \ | 194 | .regfunc = reg_event_syscall_enter, \ |
194 | .unregfunc = unreg_event_syscall_enter, \ | 195 | .unregfunc = unreg_event_syscall_enter, \ |
195 | .data = "sys"#sname, \ | 196 | .data = "sys"#sname, \ |
@@ -226,6 +227,7 @@ static void prof_sysexit_disable_##sname(struct ftrace_event_call *event_call) \ | |||
226 | .event = &event_syscall_exit, \ | 227 | .event = &event_syscall_exit, \ |
227 | .raw_init = init_exit_##sname, \ | 228 | .raw_init = init_exit_##sname, \ |
228 | .show_format = syscall_exit_format, \ | 229 | .show_format = syscall_exit_format, \ |
230 | .define_fields = syscall_exit_define_fields, \ | ||
229 | .regfunc = reg_event_syscall_exit, \ | 231 | .regfunc = reg_event_syscall_exit, \ |
230 | .unregfunc = unreg_event_syscall_exit, \ | 232 | .unregfunc = unreg_event_syscall_exit, \ |
231 | .data = "sys"#sname, \ | 233 | .data = "sys"#sname, \ |
@@ -233,6 +235,8 @@ static void prof_sysexit_disable_##sname(struct ftrace_event_call *event_call) \ | |||
233 | } | 235 | } |
234 | 236 | ||
235 | #define SYSCALL_METADATA(sname, nb) \ | 237 | #define SYSCALL_METADATA(sname, nb) \ |
238 | SYSCALL_TRACE_ENTER_EVENT(sname); \ | ||
239 | SYSCALL_TRACE_EXIT_EVENT(sname); \ | ||
236 | static const struct syscall_metadata __used \ | 240 | static const struct syscall_metadata __used \ |
237 | __attribute__((__aligned__(4))) \ | 241 | __attribute__((__aligned__(4))) \ |
238 | __attribute__((section("__syscalls_metadata"))) \ | 242 | __attribute__((section("__syscalls_metadata"))) \ |
@@ -241,20 +245,22 @@ static void prof_sysexit_disable_##sname(struct ftrace_event_call *event_call) \ | |||
241 | .nb_args = nb, \ | 245 | .nb_args = nb, \ |
242 | .types = types_##sname, \ | 246 | .types = types_##sname, \ |
243 | .args = args_##sname, \ | 247 | .args = args_##sname, \ |
244 | }; \ | 248 | .enter_event = &event_enter_##sname, \ |
245 | SYSCALL_TRACE_ENTER_EVENT(sname); \ | 249 | .exit_event = &event_exit_##sname, \ |
246 | SYSCALL_TRACE_EXIT_EVENT(sname); | 250 | }; |
247 | 251 | ||
248 | #define SYSCALL_DEFINE0(sname) \ | 252 | #define SYSCALL_DEFINE0(sname) \ |
253 | SYSCALL_TRACE_ENTER_EVENT(_##sname); \ | ||
254 | SYSCALL_TRACE_EXIT_EVENT(_##sname); \ | ||
249 | static const struct syscall_metadata __used \ | 255 | static const struct syscall_metadata __used \ |
250 | __attribute__((__aligned__(4))) \ | 256 | __attribute__((__aligned__(4))) \ |
251 | __attribute__((section("__syscalls_metadata"))) \ | 257 | __attribute__((section("__syscalls_metadata"))) \ |
252 | __syscall_meta_##sname = { \ | 258 | __syscall_meta_##sname = { \ |
253 | .name = "sys_"#sname, \ | 259 | .name = "sys_"#sname, \ |
254 | .nb_args = 0, \ | 260 | .nb_args = 0, \ |
261 | .enter_event = &event_enter__##sname, \ | ||
262 | .exit_event = &event_exit__##sname, \ | ||
255 | }; \ | 263 | }; \ |
256 | SYSCALL_TRACE_ENTER_EVENT(_##sname); \ | ||
257 | SYSCALL_TRACE_EXIT_EVENT(_##sname); \ | ||
258 | asmlinkage long sys_##sname(void) | 264 | asmlinkage long sys_##sname(void) |
259 | #else | 265 | #else |
260 | #define SYSCALL_DEFINE0(name) asmlinkage long sys_##name(void) | 266 | #define SYSCALL_DEFINE0(name) asmlinkage long sys_##name(void) |
diff --git a/include/trace/syscall.h b/include/trace/syscall.h index 5ce85d75d31b..9661dd406b93 100644 --- a/include/trace/syscall.h +++ b/include/trace/syscall.h | |||
@@ -34,6 +34,8 @@ DECLARE_TRACE_WITH_CALLBACK(syscall_exit, | |||
34 | * @args: list of args as strings (args[i] matches types[i]) | 34 | * @args: list of args as strings (args[i] matches types[i]) |
35 | * @enter_id: associated ftrace enter event id | 35 | * @enter_id: associated ftrace enter event id |
36 | * @exit_id: associated ftrace exit event id | 36 | * @exit_id: associated ftrace exit event id |
37 | * @enter_event: associated syscall_enter trace event | ||
38 | * @exit_event: associated syscall_exit trace event | ||
37 | */ | 39 | */ |
38 | struct syscall_metadata { | 40 | struct syscall_metadata { |
39 | const char *name; | 41 | const char *name; |
@@ -42,6 +44,9 @@ struct syscall_metadata { | |||
42 | const char **args; | 44 | const char **args; |
43 | int enter_id; | 45 | int enter_id; |
44 | int exit_id; | 46 | int exit_id; |
47 | |||
48 | struct ftrace_event_call *enter_event; | ||
49 | struct ftrace_event_call *exit_event; | ||
45 | }; | 50 | }; |
46 | 51 | ||
47 | #ifdef CONFIG_FTRACE_SYSCALLS | 52 | #ifdef CONFIG_FTRACE_SYSCALLS |
@@ -59,6 +64,8 @@ extern int syscall_enter_format(struct ftrace_event_call *call, | |||
59 | struct trace_seq *s); | 64 | struct trace_seq *s); |
60 | extern int syscall_exit_format(struct ftrace_event_call *call, | 65 | extern int syscall_exit_format(struct ftrace_event_call *call, |
61 | struct trace_seq *s); | 66 | struct trace_seq *s); |
67 | extern int syscall_enter_define_fields(struct ftrace_event_call *call); | ||
68 | extern int syscall_exit_define_fields(struct ftrace_event_call *call); | ||
62 | enum print_line_t print_syscall_enter(struct trace_iterator *iter, int flags); | 69 | enum print_line_t print_syscall_enter(struct trace_iterator *iter, int flags); |
63 | enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags); | 70 | enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags); |
64 | #endif | 71 | #endif |
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 9c7ecfb3416f..79d352027a61 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c | |||
@@ -27,8 +27,8 @@ DEFINE_MUTEX(event_mutex); | |||
27 | 27 | ||
28 | LIST_HEAD(ftrace_events); | 28 | LIST_HEAD(ftrace_events); |
29 | 29 | ||
30 | int trace_define_field(struct ftrace_event_call *call, char *type, | 30 | int trace_define_field(struct ftrace_event_call *call, const char *type, |
31 | char *name, int offset, int size, int is_signed) | 31 | const char *name, int offset, int size, int is_signed) |
32 | { | 32 | { |
33 | struct ftrace_event_field *field; | 33 | struct ftrace_event_field *field; |
34 | 34 | ||
@@ -83,6 +83,7 @@ int trace_define_common_fields(struct ftrace_event_call *call) | |||
83 | 83 | ||
84 | return ret; | 84 | return ret; |
85 | } | 85 | } |
86 | EXPORT_SYMBOL_GPL(trace_define_common_fields); | ||
86 | 87 | ||
87 | #ifdef CONFIG_MODULES | 88 | #ifdef CONFIG_MODULES |
88 | 89 | ||
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index 7336b6c265d7..28e4dae4af21 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c | |||
@@ -165,6 +165,49 @@ int syscall_exit_format(struct ftrace_event_call *call, struct trace_seq *s) | |||
165 | return trace_seq_printf(s, "\nprint fmt: \"0x%%lx\", REC->ret\n"); | 165 | return trace_seq_printf(s, "\nprint fmt: \"0x%%lx\", REC->ret\n"); |
166 | } | 166 | } |
167 | 167 | ||
168 | int syscall_enter_define_fields(struct ftrace_event_call *call) | ||
169 | { | ||
170 | struct syscall_trace_enter trace; | ||
171 | struct syscall_metadata *meta; | ||
172 | int ret; | ||
173 | int nr; | ||
174 | int i; | ||
175 | int offset = offsetof(typeof(trace), args); | ||
176 | |||
177 | nr = syscall_name_to_nr(call->data); | ||
178 | meta = syscall_nr_to_meta(nr); | ||
179 | |||
180 | if (!meta) | ||
181 | return 0; | ||
182 | |||
183 | ret = trace_define_common_fields(call); | ||
184 | if (ret) | ||
185 | return ret; | ||
186 | |||
187 | for (i = 0; i < meta->nb_args; i++) { | ||
188 | ret = trace_define_field(call, meta->types[i], | ||
189 | meta->args[i], offset, | ||
190 | sizeof(unsigned long), 0); | ||
191 | offset += sizeof(unsigned long); | ||
192 | } | ||
193 | |||
194 | return ret; | ||
195 | } | ||
196 | |||
197 | int syscall_exit_define_fields(struct ftrace_event_call *call) | ||
198 | { | ||
199 | struct syscall_trace_exit trace; | ||
200 | int ret; | ||
201 | |||
202 | ret = trace_define_common_fields(call); | ||
203 | if (ret) | ||
204 | return ret; | ||
205 | |||
206 | ret = trace_define_field(call, SYSCALL_FIELD(unsigned long, ret), 0); | ||
207 | |||
208 | return ret; | ||
209 | } | ||
210 | |||
168 | void ftrace_syscall_enter(struct pt_regs *regs, long id) | 211 | void ftrace_syscall_enter(struct pt_regs *regs, long id) |
169 | { | 212 | { |
170 | struct syscall_trace_enter *entry; | 213 | struct syscall_trace_enter *entry; |
@@ -192,8 +235,8 @@ void ftrace_syscall_enter(struct pt_regs *regs, long id) | |||
192 | entry->nr = syscall_nr; | 235 | entry->nr = syscall_nr; |
193 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, entry->args); | 236 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, entry->args); |
194 | 237 | ||
195 | trace_current_buffer_unlock_commit(event, 0, 0); | 238 | if (!filter_current_check_discard(sys_data->enter_event, entry, event)) |
196 | trace_wake_up(); | 239 | trace_current_buffer_unlock_commit(event, 0, 0); |
197 | } | 240 | } |
198 | 241 | ||
199 | void ftrace_syscall_exit(struct pt_regs *regs, long ret) | 242 | void ftrace_syscall_exit(struct pt_regs *regs, long ret) |
@@ -220,8 +263,8 @@ void ftrace_syscall_exit(struct pt_regs *regs, long ret) | |||
220 | entry->nr = syscall_nr; | 263 | entry->nr = syscall_nr; |
221 | entry->ret = syscall_get_return_value(current, regs); | 264 | entry->ret = syscall_get_return_value(current, regs); |
222 | 265 | ||
223 | trace_current_buffer_unlock_commit(event, 0, 0); | 266 | if (!filter_current_check_discard(sys_data->exit_event, entry, event)) |
224 | trace_wake_up(); | 267 | trace_current_buffer_unlock_commit(event, 0, 0); |
225 | } | 268 | } |
226 | 269 | ||
227 | int reg_event_syscall_enter(void *ptr) | 270 | int reg_event_syscall_enter(void *ptr) |