diff options
author | Masami Hiramatsu <mhiramat@redhat.com> | 2009-12-08 17:03:23 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-12-09 01:26:53 -0500 |
commit | fa28244d12337eebcc620b23852ec3cf29582ff9 (patch) | |
tree | ac193550d55be55dba279a57e4ee3a3e41674db0 /tools/perf/util/probe-event.c | |
parent | a7c312bed772c11138409c3a98531e85d690302e (diff) |
perf probe: Support --del option
Support perf probe --del <event> option. Currently,
perf probe can have only one event for each --del option.
If you'd like to delete several probe events, you need
to specify --del for each events.
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
LKML-Reference: <20091208220323.10142.62079.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/probe-event.c')
-rw-r--r-- | tools/perf/util/probe-event.c | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 31beedcf61c1..9480d9941cc0 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -430,10 +430,11 @@ void show_perf_probe_events(void) | |||
430 | } | 430 | } |
431 | 431 | ||
432 | /* Get current perf-probe event names */ | 432 | /* Get current perf-probe event names */ |
433 | static struct strlist *get_perf_event_names(int fd) | 433 | static struct strlist *get_perf_event_names(int fd, bool include_group) |
434 | { | 434 | { |
435 | unsigned int i; | 435 | unsigned int i; |
436 | char *group, *event; | 436 | char *group, *event; |
437 | char buf[128]; | ||
437 | struct strlist *sl, *rawlist; | 438 | struct strlist *sl, *rawlist; |
438 | struct str_node *ent; | 439 | struct str_node *ent; |
439 | 440 | ||
@@ -443,7 +444,12 @@ static struct strlist *get_perf_event_names(int fd) | |||
443 | for (i = 0; i < strlist__nr_entries(rawlist); i++) { | 444 | for (i = 0; i < strlist__nr_entries(rawlist); i++) { |
444 | ent = strlist__entry(rawlist, i); | 445 | ent = strlist__entry(rawlist, i); |
445 | parse_trace_kprobe_event(ent->s, &group, &event, NULL); | 446 | parse_trace_kprobe_event(ent->s, &group, &event, NULL); |
446 | strlist__add(sl, event); | 447 | if (include_group) { |
448 | if (e_snprintf(buf, 128, "%s:%s", group, event) < 0) | ||
449 | die("Failed to copy group:event name."); | ||
450 | strlist__add(sl, buf); | ||
451 | } else | ||
452 | strlist__add(sl, event); | ||
447 | free(group); | 453 | free(group); |
448 | free(event); | 454 | free(event); |
449 | } | 455 | } |
@@ -457,9 +463,10 @@ static void write_trace_kprobe_event(int fd, const char *buf) | |||
457 | { | 463 | { |
458 | int ret; | 464 | int ret; |
459 | 465 | ||
466 | pr_debug("Writing event: %s\n", buf); | ||
460 | ret = write(fd, buf, strlen(buf)); | 467 | ret = write(fd, buf, strlen(buf)); |
461 | if (ret <= 0) | 468 | if (ret <= 0) |
462 | die("Failed to create event."); | 469 | die("Failed to write event: %s", strerror(errno)); |
463 | } | 470 | } |
464 | 471 | ||
465 | static void get_new_event_name(char *buf, size_t len, const char *base, | 472 | static void get_new_event_name(char *buf, size_t len, const char *base, |
@@ -496,7 +503,7 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes) | |||
496 | 503 | ||
497 | fd = open_kprobe_events(O_RDWR, O_APPEND); | 504 | fd = open_kprobe_events(O_RDWR, O_APPEND); |
498 | /* Get current event names */ | 505 | /* Get current event names */ |
499 | namelist = get_perf_event_names(fd); | 506 | namelist = get_perf_event_names(fd, false); |
500 | 507 | ||
501 | for (j = 0; j < nr_probes; j++) { | 508 | for (j = 0; j < nr_probes; j++) { |
502 | pp = probes + j; | 509 | pp = probes + j; |
@@ -524,3 +531,57 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes) | |||
524 | strlist__delete(namelist); | 531 | strlist__delete(namelist); |
525 | close(fd); | 532 | close(fd); |
526 | } | 533 | } |
534 | |||
535 | static void del_trace_kprobe_event(int fd, const char *group, | ||
536 | const char *event, struct strlist *namelist) | ||
537 | { | ||
538 | char buf[128]; | ||
539 | |||
540 | if (e_snprintf(buf, 128, "%s:%s", group, event) < 0) | ||
541 | die("Failed to copy event."); | ||
542 | if (!strlist__has_entry(namelist, buf)) { | ||
543 | pr_warning("Warning: event \"%s\" is not found.\n", buf); | ||
544 | return; | ||
545 | } | ||
546 | /* Convert from perf-probe event to trace-kprobe event */ | ||
547 | if (e_snprintf(buf, 128, "-:%s/%s", group, event) < 0) | ||
548 | die("Failed to copy event."); | ||
549 | |||
550 | write_trace_kprobe_event(fd, buf); | ||
551 | printf("Remove event: %s:%s\n", group, event); | ||
552 | } | ||
553 | |||
554 | void del_trace_kprobe_events(struct strlist *dellist) | ||
555 | { | ||
556 | int fd; | ||
557 | unsigned int i; | ||
558 | const char *group, *event; | ||
559 | char *p, *str; | ||
560 | struct str_node *ent; | ||
561 | struct strlist *namelist; | ||
562 | |||
563 | fd = open_kprobe_events(O_RDWR, O_APPEND); | ||
564 | /* Get current event names */ | ||
565 | namelist = get_perf_event_names(fd, true); | ||
566 | |||
567 | for (i = 0; i < strlist__nr_entries(dellist); i++) { | ||
568 | ent = strlist__entry(dellist, i); | ||
569 | str = strdup(ent->s); | ||
570 | if (!str) | ||
571 | die("Failed to copy event."); | ||
572 | p = strchr(str, ':'); | ||
573 | if (p) { | ||
574 | group = str; | ||
575 | *p = '\0'; | ||
576 | event = p + 1; | ||
577 | } else { | ||
578 | group = PERFPROBE_GROUP; | ||
579 | event = str; | ||
580 | } | ||
581 | del_trace_kprobe_event(fd, group, event, namelist); | ||
582 | free(str); | ||
583 | } | ||
584 | strlist__delete(namelist); | ||
585 | close(fd); | ||
586 | } | ||
587 | |||