]>
Commit | Line | Data |
---|---|---|
b77e38aa SR |
1 | /* |
2 | * event tracer | |
3 | * | |
4 | * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> | |
5 | * | |
981d081e SR |
6 | * - Added format output of fields of the trace point. |
7 | * This was based off of work by Tom Zanussi <tzanussi@gmail.com>. | |
8 | * | |
b77e38aa SR |
9 | */ |
10 | ||
11 | #include <linux/debugfs.h> | |
12 | #include <linux/uaccess.h> | |
13 | #include <linux/module.h> | |
14 | #include <linux/ctype.h> | |
15 | ||
91729ef9 | 16 | #include "trace_output.h" |
b77e38aa | 17 | |
b628b3e6 SR |
18 | #define TRACE_SYSTEM "TRACE_SYSTEM" |
19 | ||
11a241a3 SR |
20 | static DEFINE_MUTEX(event_mutex); |
21 | ||
cf027f64 TZ |
22 | int trace_define_field(struct ftrace_event_call *call, char *type, |
23 | char *name, int offset, int size) | |
24 | { | |
25 | struct ftrace_event_field *field; | |
26 | ||
fe9f57f2 | 27 | field = kzalloc(sizeof(*field), GFP_KERNEL); |
cf027f64 TZ |
28 | if (!field) |
29 | goto err; | |
fe9f57f2 | 30 | |
cf027f64 TZ |
31 | field->name = kstrdup(name, GFP_KERNEL); |
32 | if (!field->name) | |
33 | goto err; | |
fe9f57f2 | 34 | |
cf027f64 TZ |
35 | field->type = kstrdup(type, GFP_KERNEL); |
36 | if (!field->type) | |
37 | goto err; | |
fe9f57f2 | 38 | |
cf027f64 TZ |
39 | field->offset = offset; |
40 | field->size = size; | |
41 | list_add(&field->link, &call->fields); | |
42 | ||
43 | return 0; | |
fe9f57f2 | 44 | |
cf027f64 TZ |
45 | err: |
46 | if (field) { | |
47 | kfree(field->name); | |
48 | kfree(field->type); | |
49 | } | |
50 | kfree(field); | |
fe9f57f2 | 51 | |
cf027f64 TZ |
52 | return -ENOMEM; |
53 | } | |
54 | ||
b77e38aa SR |
55 | static void ftrace_clear_events(void) |
56 | { | |
57 | struct ftrace_event_call *call = (void *)__start_ftrace_events; | |
58 | ||
59 | ||
60 | while ((unsigned long)call < (unsigned long)__stop_ftrace_events) { | |
61 | ||
62 | if (call->enabled) { | |
63 | call->enabled = 0; | |
64 | call->unregfunc(); | |
65 | } | |
66 | call++; | |
67 | } | |
68 | } | |
69 | ||
fd994989 SR |
70 | static void ftrace_event_enable_disable(struct ftrace_event_call *call, |
71 | int enable) | |
72 | { | |
73 | ||
74 | switch (enable) { | |
75 | case 0: | |
76 | if (call->enabled) { | |
77 | call->enabled = 0; | |
78 | call->unregfunc(); | |
79 | } | |
fd994989 SR |
80 | break; |
81 | case 1: | |
da4d0302 | 82 | if (!call->enabled) { |
fd994989 SR |
83 | call->enabled = 1; |
84 | call->regfunc(); | |
85 | } | |
fd994989 SR |
86 | break; |
87 | } | |
88 | } | |
89 | ||
b77e38aa SR |
90 | static int ftrace_set_clr_event(char *buf, int set) |
91 | { | |
1473e441 | 92 | struct ftrace_event_call *call = __start_ftrace_events; |
b628b3e6 SR |
93 | char *event = NULL, *sub = NULL, *match; |
94 | int ret = -EINVAL; | |
95 | ||
96 | /* | |
97 | * The buf format can be <subsystem>:<event-name> | |
98 | * *:<event-name> means any event by that name. | |
99 | * :<event-name> is the same. | |
100 | * | |
101 | * <subsystem>:* means all events in that subsystem | |
102 | * <subsystem>: means the same. | |
103 | * | |
104 | * <name> (no ':') means all events in a subsystem with | |
105 | * the name <name> or any event that matches <name> | |
106 | */ | |
107 | ||
108 | match = strsep(&buf, ":"); | |
109 | if (buf) { | |
110 | sub = match; | |
111 | event = buf; | |
112 | match = NULL; | |
113 | ||
114 | if (!strlen(sub) || strcmp(sub, "*") == 0) | |
115 | sub = NULL; | |
116 | if (!strlen(event) || strcmp(event, "*") == 0) | |
117 | event = NULL; | |
118 | } | |
b77e38aa | 119 | |
11a241a3 | 120 | mutex_lock(&event_mutex); |
ac199db0 | 121 | for_each_event(call) { |
b77e38aa | 122 | |
40e26815 | 123 | if (!call->name || !call->regfunc) |
1473e441 SR |
124 | continue; |
125 | ||
b628b3e6 SR |
126 | if (match && |
127 | strcmp(match, call->name) != 0 && | |
128 | strcmp(match, call->system) != 0) | |
129 | continue; | |
130 | ||
131 | if (sub && strcmp(sub, call->system) != 0) | |
132 | continue; | |
133 | ||
134 | if (event && strcmp(event, call->name) != 0) | |
b77e38aa | 135 | continue; |
b77e38aa | 136 | |
fd994989 SR |
137 | ftrace_event_enable_disable(call, set); |
138 | ||
b628b3e6 | 139 | ret = 0; |
b77e38aa | 140 | } |
11a241a3 SR |
141 | mutex_unlock(&event_mutex); |
142 | ||
b628b3e6 | 143 | return ret; |
b77e38aa SR |
144 | } |
145 | ||
146 | /* 128 should be much more than enough */ | |
147 | #define EVENT_BUF_SIZE 127 | |
148 | ||
149 | static ssize_t | |
150 | ftrace_event_write(struct file *file, const char __user *ubuf, | |
151 | size_t cnt, loff_t *ppos) | |
152 | { | |
153 | size_t read = 0; | |
154 | int i, set = 1; | |
155 | ssize_t ret; | |
156 | char *buf; | |
157 | char ch; | |
158 | ||
159 | if (!cnt || cnt < 0) | |
160 | return 0; | |
161 | ||
1852fcce SR |
162 | ret = tracing_update_buffers(); |
163 | if (ret < 0) | |
164 | return ret; | |
165 | ||
b77e38aa SR |
166 | ret = get_user(ch, ubuf++); |
167 | if (ret) | |
168 | return ret; | |
169 | read++; | |
170 | cnt--; | |
171 | ||
172 | /* skip white space */ | |
173 | while (cnt && isspace(ch)) { | |
174 | ret = get_user(ch, ubuf++); | |
175 | if (ret) | |
176 | return ret; | |
177 | read++; | |
178 | cnt--; | |
179 | } | |
180 | ||
181 | /* Only white space found? */ | |
182 | if (isspace(ch)) { | |
183 | file->f_pos += read; | |
184 | ret = read; | |
185 | return ret; | |
186 | } | |
187 | ||
188 | buf = kmalloc(EVENT_BUF_SIZE+1, GFP_KERNEL); | |
189 | if (!buf) | |
190 | return -ENOMEM; | |
191 | ||
192 | if (cnt > EVENT_BUF_SIZE) | |
193 | cnt = EVENT_BUF_SIZE; | |
194 | ||
195 | i = 0; | |
196 | while (cnt && !isspace(ch)) { | |
197 | if (!i && ch == '!') | |
198 | set = 0; | |
199 | else | |
200 | buf[i++] = ch; | |
201 | ||
202 | ret = get_user(ch, ubuf++); | |
203 | if (ret) | |
204 | goto out_free; | |
205 | read++; | |
206 | cnt--; | |
207 | } | |
208 | buf[i] = 0; | |
209 | ||
210 | file->f_pos += read; | |
211 | ||
212 | ret = ftrace_set_clr_event(buf, set); | |
213 | if (ret) | |
214 | goto out_free; | |
215 | ||
216 | ret = read; | |
217 | ||
218 | out_free: | |
219 | kfree(buf); | |
220 | ||
221 | return ret; | |
222 | } | |
223 | ||
224 | static void * | |
225 | t_next(struct seq_file *m, void *v, loff_t *pos) | |
226 | { | |
227 | struct ftrace_event_call *call = m->private; | |
228 | struct ftrace_event_call *next = call; | |
229 | ||
230 | (*pos)++; | |
231 | ||
40e26815 SR |
232 | for (;;) { |
233 | if ((unsigned long)call >= (unsigned long)__stop_ftrace_events) | |
234 | return NULL; | |
235 | ||
236 | /* | |
237 | * The ftrace subsystem is for showing formats only. | |
238 | * They can not be enabled or disabled via the event files. | |
239 | */ | |
240 | if (call->regfunc) | |
241 | break; | |
242 | ||
243 | call++; | |
244 | next = call; | |
245 | } | |
b77e38aa SR |
246 | |
247 | m->private = ++next; | |
248 | ||
249 | return call; | |
250 | } | |
251 | ||
252 | static void *t_start(struct seq_file *m, loff_t *pos) | |
253 | { | |
254 | return t_next(m, NULL, pos); | |
255 | } | |
256 | ||
257 | static void * | |
258 | s_next(struct seq_file *m, void *v, loff_t *pos) | |
259 | { | |
260 | struct ftrace_event_call *call = m->private; | |
261 | struct ftrace_event_call *next; | |
262 | ||
263 | (*pos)++; | |
264 | ||
265 | retry: | |
266 | if ((unsigned long)call >= (unsigned long)__stop_ftrace_events) | |
267 | return NULL; | |
268 | ||
269 | if (!call->enabled) { | |
270 | call++; | |
271 | goto retry; | |
272 | } | |
273 | ||
274 | next = call; | |
275 | m->private = ++next; | |
276 | ||
277 | return call; | |
278 | } | |
279 | ||
280 | static void *s_start(struct seq_file *m, loff_t *pos) | |
281 | { | |
282 | return s_next(m, NULL, pos); | |
283 | } | |
284 | ||
285 | static int t_show(struct seq_file *m, void *v) | |
286 | { | |
287 | struct ftrace_event_call *call = v; | |
288 | ||
b628b3e6 SR |
289 | if (strcmp(call->system, TRACE_SYSTEM) != 0) |
290 | seq_printf(m, "%s:", call->system); | |
b77e38aa SR |
291 | seq_printf(m, "%s\n", call->name); |
292 | ||
293 | return 0; | |
294 | } | |
295 | ||
296 | static void t_stop(struct seq_file *m, void *p) | |
297 | { | |
298 | } | |
299 | ||
300 | static int | |
301 | ftrace_event_seq_open(struct inode *inode, struct file *file) | |
302 | { | |
303 | int ret; | |
304 | const struct seq_operations *seq_ops; | |
305 | ||
306 | if ((file->f_mode & FMODE_WRITE) && | |
307 | !(file->f_flags & O_APPEND)) | |
308 | ftrace_clear_events(); | |
309 | ||
310 | seq_ops = inode->i_private; | |
311 | ret = seq_open(file, seq_ops); | |
312 | if (!ret) { | |
313 | struct seq_file *m = file->private_data; | |
314 | ||
315 | m->private = __start_ftrace_events; | |
316 | } | |
317 | return ret; | |
318 | } | |
319 | ||
1473e441 SR |
320 | static ssize_t |
321 | event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, | |
322 | loff_t *ppos) | |
323 | { | |
324 | struct ftrace_event_call *call = filp->private_data; | |
325 | char *buf; | |
326 | ||
da4d0302 | 327 | if (call->enabled) |
1473e441 SR |
328 | buf = "1\n"; |
329 | else | |
330 | buf = "0\n"; | |
331 | ||
332 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); | |
333 | } | |
334 | ||
335 | static ssize_t | |
336 | event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
337 | loff_t *ppos) | |
338 | { | |
339 | struct ftrace_event_call *call = filp->private_data; | |
340 | char buf[64]; | |
341 | unsigned long val; | |
342 | int ret; | |
343 | ||
344 | if (cnt >= sizeof(buf)) | |
345 | return -EINVAL; | |
346 | ||
347 | if (copy_from_user(&buf, ubuf, cnt)) | |
348 | return -EFAULT; | |
349 | ||
350 | buf[cnt] = 0; | |
351 | ||
352 | ret = strict_strtoul(buf, 10, &val); | |
353 | if (ret < 0) | |
354 | return ret; | |
355 | ||
1852fcce SR |
356 | ret = tracing_update_buffers(); |
357 | if (ret < 0) | |
358 | return ret; | |
359 | ||
1473e441 SR |
360 | switch (val) { |
361 | case 0: | |
1473e441 | 362 | case 1: |
11a241a3 | 363 | mutex_lock(&event_mutex); |
fd994989 | 364 | ftrace_event_enable_disable(call, val); |
11a241a3 | 365 | mutex_unlock(&event_mutex); |
1473e441 SR |
366 | break; |
367 | ||
368 | default: | |
369 | return -EINVAL; | |
370 | } | |
371 | ||
372 | *ppos += cnt; | |
373 | ||
374 | return cnt; | |
375 | } | |
376 | ||
91729ef9 | 377 | #undef FIELD |
156b5f17 | 378 | #define FIELD(type, name) \ |
cf027f64 TZ |
379 | #type, "common_" #name, offsetof(typeof(field), name), \ |
380 | sizeof(field.name) | |
91729ef9 SR |
381 | |
382 | static int trace_write_header(struct trace_seq *s) | |
383 | { | |
384 | struct trace_entry field; | |
385 | ||
386 | /* struct trace_entry */ | |
387 | return trace_seq_printf(s, | |
ce8eb2bf SR |
388 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" |
389 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" | |
390 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" | |
391 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" | |
392 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" | |
91729ef9 SR |
393 | "\n", |
394 | FIELD(unsigned char, type), | |
395 | FIELD(unsigned char, flags), | |
396 | FIELD(unsigned char, preempt_count), | |
397 | FIELD(int, pid), | |
398 | FIELD(int, tgid)); | |
399 | } | |
da4d0302 | 400 | |
981d081e SR |
401 | static ssize_t |
402 | event_format_read(struct file *filp, char __user *ubuf, size_t cnt, | |
403 | loff_t *ppos) | |
404 | { | |
405 | struct ftrace_event_call *call = filp->private_data; | |
406 | struct trace_seq *s; | |
407 | char *buf; | |
408 | int r; | |
409 | ||
c269fc8c TZ |
410 | if (*ppos) |
411 | return 0; | |
412 | ||
981d081e SR |
413 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
414 | if (!s) | |
415 | return -ENOMEM; | |
416 | ||
417 | trace_seq_init(s); | |
418 | ||
c5e4e192 SR |
419 | /* If any of the first writes fail, so will the show_format. */ |
420 | ||
421 | trace_seq_printf(s, "name: %s\n", call->name); | |
422 | trace_seq_printf(s, "ID: %d\n", call->id); | |
423 | trace_seq_printf(s, "format:\n"); | |
91729ef9 SR |
424 | trace_write_header(s); |
425 | ||
981d081e SR |
426 | r = call->show_format(s); |
427 | if (!r) { | |
428 | /* | |
429 | * ug! The format output is bigger than a PAGE!! | |
430 | */ | |
431 | buf = "FORMAT TOO BIG\n"; | |
432 | r = simple_read_from_buffer(ubuf, cnt, ppos, | |
433 | buf, strlen(buf)); | |
434 | goto out; | |
435 | } | |
436 | ||
437 | r = simple_read_from_buffer(ubuf, cnt, ppos, | |
438 | s->buffer, s->len); | |
439 | out: | |
440 | kfree(s); | |
441 | return r; | |
442 | } | |
443 | ||
23725aee PZ |
444 | static ssize_t |
445 | event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) | |
446 | { | |
447 | struct ftrace_event_call *call = filp->private_data; | |
448 | struct trace_seq *s; | |
449 | int r; | |
450 | ||
451 | if (*ppos) | |
452 | return 0; | |
453 | ||
454 | s = kmalloc(sizeof(*s), GFP_KERNEL); | |
455 | if (!s) | |
456 | return -ENOMEM; | |
457 | ||
458 | trace_seq_init(s); | |
459 | trace_seq_printf(s, "%d\n", call->id); | |
460 | ||
461 | r = simple_read_from_buffer(ubuf, cnt, ppos, | |
462 | s->buffer, s->len); | |
463 | kfree(s); | |
464 | return r; | |
465 | } | |
466 | ||
7ce7e424 TZ |
467 | static ssize_t |
468 | event_filter_read(struct file *filp, char __user *ubuf, size_t cnt, | |
469 | loff_t *ppos) | |
470 | { | |
471 | struct ftrace_event_call *call = filp->private_data; | |
472 | struct trace_seq *s; | |
473 | int r; | |
474 | ||
475 | if (*ppos) | |
476 | return 0; | |
477 | ||
478 | s = kmalloc(sizeof(*s), GFP_KERNEL); | |
479 | if (!s) | |
480 | return -ENOMEM; | |
481 | ||
482 | trace_seq_init(s); | |
483 | ||
4bda2d51 TZ |
484 | filter_print_preds(call->preds, s); |
485 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); | |
7ce7e424 TZ |
486 | |
487 | kfree(s); | |
488 | ||
489 | return r; | |
490 | } | |
491 | ||
492 | static ssize_t | |
493 | event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
494 | loff_t *ppos) | |
495 | { | |
496 | struct ftrace_event_call *call = filp->private_data; | |
497 | char buf[64], *pbuf = buf; | |
498 | struct filter_pred *pred; | |
499 | int err; | |
500 | ||
501 | if (cnt >= sizeof(buf)) | |
502 | return -EINVAL; | |
503 | ||
504 | if (copy_from_user(&buf, ubuf, cnt)) | |
505 | return -EFAULT; | |
8433a40e | 506 | buf[cnt] = '\0'; |
7ce7e424 TZ |
507 | |
508 | pred = kzalloc(sizeof(*pred), GFP_KERNEL); | |
509 | if (!pred) | |
510 | return -ENOMEM; | |
511 | ||
512 | err = filter_parse(&pbuf, pred); | |
513 | if (err < 0) { | |
514 | filter_free_pred(pred); | |
515 | return err; | |
516 | } | |
517 | ||
518 | if (pred->clear) { | |
519 | filter_free_preds(call); | |
09f1f245 | 520 | filter_free_pred(pred); |
7ce7e424 TZ |
521 | return cnt; |
522 | } | |
523 | ||
524 | if (filter_add_pred(call, pred)) { | |
525 | filter_free_pred(pred); | |
526 | return -EINVAL; | |
527 | } | |
528 | ||
529 | *ppos += cnt; | |
530 | ||
531 | return cnt; | |
532 | } | |
533 | ||
cfb180f3 TZ |
534 | static ssize_t |
535 | subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt, | |
536 | loff_t *ppos) | |
537 | { | |
538 | struct event_subsystem *system = filp->private_data; | |
539 | struct trace_seq *s; | |
540 | int r; | |
541 | ||
542 | if (*ppos) | |
543 | return 0; | |
544 | ||
545 | s = kmalloc(sizeof(*s), GFP_KERNEL); | |
546 | if (!s) | |
547 | return -ENOMEM; | |
548 | ||
549 | trace_seq_init(s); | |
550 | ||
4bda2d51 TZ |
551 | filter_print_preds(system->preds, s); |
552 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); | |
cfb180f3 TZ |
553 | |
554 | kfree(s); | |
555 | ||
556 | return r; | |
557 | } | |
558 | ||
559 | static ssize_t | |
560 | subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
561 | loff_t *ppos) | |
562 | { | |
563 | struct event_subsystem *system = filp->private_data; | |
564 | char buf[64], *pbuf = buf; | |
565 | struct filter_pred *pred; | |
566 | int err; | |
567 | ||
568 | if (cnt >= sizeof(buf)) | |
569 | return -EINVAL; | |
570 | ||
571 | if (copy_from_user(&buf, ubuf, cnt)) | |
572 | return -EFAULT; | |
8433a40e | 573 | buf[cnt] = '\0'; |
cfb180f3 TZ |
574 | |
575 | pred = kzalloc(sizeof(*pred), GFP_KERNEL); | |
576 | if (!pred) | |
577 | return -ENOMEM; | |
578 | ||
579 | err = filter_parse(&pbuf, pred); | |
580 | if (err < 0) { | |
581 | filter_free_pred(pred); | |
582 | return err; | |
583 | } | |
584 | ||
585 | if (pred->clear) { | |
586 | filter_free_subsystem_preds(system); | |
09f1f245 | 587 | filter_free_pred(pred); |
cfb180f3 TZ |
588 | return cnt; |
589 | } | |
590 | ||
591 | if (filter_add_subsystem_pred(system, pred)) { | |
c4cff064 | 592 | filter_free_subsystem_preds(system); |
cfb180f3 TZ |
593 | filter_free_pred(pred); |
594 | return -EINVAL; | |
595 | } | |
596 | ||
597 | *ppos += cnt; | |
598 | ||
599 | return cnt; | |
600 | } | |
601 | ||
b77e38aa SR |
602 | static const struct seq_operations show_event_seq_ops = { |
603 | .start = t_start, | |
604 | .next = t_next, | |
605 | .show = t_show, | |
606 | .stop = t_stop, | |
607 | }; | |
608 | ||
609 | static const struct seq_operations show_set_event_seq_ops = { | |
610 | .start = s_start, | |
611 | .next = s_next, | |
612 | .show = t_show, | |
613 | .stop = t_stop, | |
614 | }; | |
615 | ||
2314c4ae SR |
616 | static const struct file_operations ftrace_avail_fops = { |
617 | .open = ftrace_event_seq_open, | |
618 | .read = seq_read, | |
619 | .llseek = seq_lseek, | |
620 | .release = seq_release, | |
621 | }; | |
622 | ||
b77e38aa SR |
623 | static const struct file_operations ftrace_set_event_fops = { |
624 | .open = ftrace_event_seq_open, | |
625 | .read = seq_read, | |
626 | .write = ftrace_event_write, | |
627 | .llseek = seq_lseek, | |
628 | .release = seq_release, | |
629 | }; | |
630 | ||
1473e441 SR |
631 | static const struct file_operations ftrace_enable_fops = { |
632 | .open = tracing_open_generic, | |
633 | .read = event_enable_read, | |
634 | .write = event_enable_write, | |
635 | }; | |
636 | ||
981d081e SR |
637 | static const struct file_operations ftrace_event_format_fops = { |
638 | .open = tracing_open_generic, | |
639 | .read = event_format_read, | |
640 | }; | |
641 | ||
23725aee PZ |
642 | static const struct file_operations ftrace_event_id_fops = { |
643 | .open = tracing_open_generic, | |
644 | .read = event_id_read, | |
645 | }; | |
646 | ||
7ce7e424 TZ |
647 | static const struct file_operations ftrace_event_filter_fops = { |
648 | .open = tracing_open_generic, | |
649 | .read = event_filter_read, | |
650 | .write = event_filter_write, | |
651 | }; | |
652 | ||
cfb180f3 TZ |
653 | static const struct file_operations ftrace_subsystem_filter_fops = { |
654 | .open = tracing_open_generic, | |
655 | .read = subsystem_filter_read, | |
656 | .write = subsystem_filter_write, | |
657 | }; | |
658 | ||
1473e441 SR |
659 | static struct dentry *event_trace_events_dir(void) |
660 | { | |
661 | static struct dentry *d_tracer; | |
662 | static struct dentry *d_events; | |
663 | ||
664 | if (d_events) | |
665 | return d_events; | |
666 | ||
667 | d_tracer = tracing_init_dentry(); | |
668 | if (!d_tracer) | |
669 | return NULL; | |
670 | ||
671 | d_events = debugfs_create_dir("events", d_tracer); | |
672 | if (!d_events) | |
673 | pr_warning("Could not create debugfs " | |
674 | "'events' directory\n"); | |
675 | ||
676 | return d_events; | |
677 | } | |
678 | ||
6ecc2d1c SR |
679 | static LIST_HEAD(event_subsystems); |
680 | ||
681 | static struct dentry * | |
682 | event_subsystem_dir(const char *name, struct dentry *d_events) | |
683 | { | |
684 | struct event_subsystem *system; | |
685 | ||
686 | /* First see if we did not already create this dir */ | |
687 | list_for_each_entry(system, &event_subsystems, list) { | |
688 | if (strcmp(system->name, name) == 0) | |
689 | return system->entry; | |
690 | } | |
691 | ||
692 | /* need to create new entry */ | |
693 | system = kmalloc(sizeof(*system), GFP_KERNEL); | |
694 | if (!system) { | |
695 | pr_warning("No memory to create event subsystem %s\n", | |
696 | name); | |
697 | return d_events; | |
698 | } | |
699 | ||
700 | system->entry = debugfs_create_dir(name, d_events); | |
701 | if (!system->entry) { | |
702 | pr_warning("Could not create event subsystem %s\n", | |
703 | name); | |
704 | kfree(system); | |
705 | return d_events; | |
706 | } | |
707 | ||
708 | system->name = name; | |
709 | list_add(&system->list, &event_subsystems); | |
710 | ||
cfb180f3 TZ |
711 | system->preds = NULL; |
712 | ||
6ecc2d1c SR |
713 | return system->entry; |
714 | } | |
715 | ||
1473e441 SR |
716 | static int |
717 | event_create_dir(struct ftrace_event_call *call, struct dentry *d_events) | |
718 | { | |
719 | struct dentry *entry; | |
fd994989 | 720 | int ret; |
1473e441 | 721 | |
6ecc2d1c SR |
722 | /* |
723 | * If the trace point header did not define TRACE_SYSTEM | |
724 | * then the system would be called "TRACE_SYSTEM". | |
725 | */ | |
726 | if (strcmp(call->system, "TRACE_SYSTEM") != 0) | |
727 | d_events = event_subsystem_dir(call->system, d_events); | |
728 | ||
fd994989 SR |
729 | if (call->raw_init) { |
730 | ret = call->raw_init(); | |
731 | if (ret < 0) { | |
732 | pr_warning("Could not initialize trace point" | |
733 | " events/%s\n", call->name); | |
734 | return ret; | |
735 | } | |
736 | } | |
737 | ||
1473e441 SR |
738 | call->dir = debugfs_create_dir(call->name, d_events); |
739 | if (!call->dir) { | |
740 | pr_warning("Could not create debugfs " | |
741 | "'%s' directory\n", call->name); | |
742 | return -1; | |
743 | } | |
744 | ||
770cb243 SR |
745 | if (call->regfunc) { |
746 | entry = debugfs_create_file("enable", 0644, call->dir, call, | |
747 | &ftrace_enable_fops); | |
748 | if (!entry) | |
749 | pr_warning("Could not create debugfs " | |
750 | "'%s/enable' entry\n", call->name); | |
751 | } | |
1473e441 | 752 | |
23725aee PZ |
753 | if (call->id) { |
754 | entry = debugfs_create_file("id", 0444, call->dir, call, | |
755 | &ftrace_event_id_fops); | |
756 | if (!entry) | |
757 | pr_warning("Could not create debugfs '%s/id' entry\n", | |
758 | call->name); | |
759 | } | |
760 | ||
cf027f64 TZ |
761 | if (call->define_fields) { |
762 | ret = call->define_fields(); | |
763 | if (ret < 0) { | |
764 | pr_warning("Could not initialize trace point" | |
765 | " events/%s\n", call->name); | |
766 | return ret; | |
767 | } | |
9a8118ba TZ |
768 | entry = debugfs_create_file("filter", 0644, call->dir, call, |
769 | &ftrace_event_filter_fops); | |
770 | if (!entry) | |
771 | pr_warning("Could not create debugfs " | |
772 | "'%s/filter' entry\n", call->name); | |
cf027f64 TZ |
773 | } |
774 | ||
981d081e SR |
775 | /* A trace may not want to export its format */ |
776 | if (!call->show_format) | |
777 | return 0; | |
778 | ||
779 | entry = debugfs_create_file("format", 0444, call->dir, call, | |
780 | &ftrace_event_format_fops); | |
781 | if (!entry) | |
782 | pr_warning("Could not create debugfs " | |
783 | "'%s/format' entry\n", call->name); | |
fd994989 | 784 | |
1473e441 SR |
785 | return 0; |
786 | } | |
787 | ||
b77e38aa SR |
788 | static __init int event_trace_init(void) |
789 | { | |
1473e441 | 790 | struct ftrace_event_call *call = __start_ftrace_events; |
b77e38aa SR |
791 | struct dentry *d_tracer; |
792 | struct dentry *entry; | |
1473e441 | 793 | struct dentry *d_events; |
b77e38aa SR |
794 | |
795 | d_tracer = tracing_init_dentry(); | |
796 | if (!d_tracer) | |
797 | return 0; | |
798 | ||
2314c4ae SR |
799 | entry = debugfs_create_file("available_events", 0444, d_tracer, |
800 | (void *)&show_event_seq_ops, | |
801 | &ftrace_avail_fops); | |
802 | if (!entry) | |
803 | pr_warning("Could not create debugfs " | |
804 | "'available_events' entry\n"); | |
805 | ||
b77e38aa SR |
806 | entry = debugfs_create_file("set_event", 0644, d_tracer, |
807 | (void *)&show_set_event_seq_ops, | |
808 | &ftrace_set_event_fops); | |
809 | if (!entry) | |
810 | pr_warning("Could not create debugfs " | |
811 | "'set_event' entry\n"); | |
812 | ||
1473e441 SR |
813 | d_events = event_trace_events_dir(); |
814 | if (!d_events) | |
815 | return 0; | |
816 | ||
ac199db0 | 817 | for_each_event(call) { |
1473e441 SR |
818 | /* The linker may leave blanks */ |
819 | if (!call->name) | |
820 | continue; | |
821 | event_create_dir(call, d_events); | |
822 | } | |
823 | ||
b77e38aa SR |
824 | return 0; |
825 | } | |
826 | fs_initcall(event_trace_init); |