diff options
| author | Masami Hiramatsu <mhiramat@redhat.com> | 2009-12-15 10:32:25 -0500 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2009-12-15 14:22:04 -0500 |
| commit | d761b08bff0a9b653f6bd248cea50322e7eccb14 (patch) | |
| tree | ec57220663387ceb65a6e34c78f80c2998ee64e6 /tools | |
| parent | af663d75a64d2cc3f18bdb8a29ff4650b9417c16 (diff) | |
perf probe: Reject second attempt of adding same-name event
Reject second attempt of adding same-name event. This patch
also provides --force option which allows user to add additional
probe events on the same-name event.
e.g.
(the first attempt : success)
./perf probe schedule
Added new event:
probe:schedule (on schedule+0)
(the second attempt : failure)
./perf probe schedule:11
Error: event "schedule" already exists. (Use -f to force duplicates.)
Fatal: Can't add new event.
(the second attempt with -f : successfully added)
./perf probe -f schedule:11
Added new event:
probe:schedule_1 (on schedule+45)
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@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: 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: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153225.17436.15166.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/builtin-probe.c | 6 | ||||
| -rw-r--r-- | tools/perf/util/probe-event.c | 24 | ||||
| -rw-r--r-- | tools/perf/util/probe-event.h | 3 |
3 files changed, 28 insertions, 5 deletions
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index adc0a55acd95..8b4fdaeefa29 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
| @@ -61,6 +61,7 @@ static struct { | |||
| 61 | char *release; | 61 | char *release; |
| 62 | bool need_dwarf; | 62 | bool need_dwarf; |
| 63 | bool list_events; | 63 | bool list_events; |
| 64 | bool force_add; | ||
| 64 | int nr_probe; | 65 | int nr_probe; |
| 65 | struct probe_point probes[MAX_PROBES]; | 66 | struct probe_point probes[MAX_PROBES]; |
| 66 | struct strlist *dellist; | 67 | struct strlist *dellist; |
| @@ -192,6 +193,8 @@ static const struct option options[] = { | |||
| 192 | #endif | 193 | #endif |
| 193 | "\t\t\tkprobe-tracer argument format.)\n", | 194 | "\t\t\tkprobe-tracer argument format.)\n", |
| 194 | opt_add_probe_event), | 195 | opt_add_probe_event), |
| 196 | OPT_BOOLEAN('f', "force", &session.force_add, "forcibly add events" | ||
| 197 | " with existing name"), | ||
| 195 | OPT_END() | 198 | OPT_END() |
| 196 | }; | 199 | }; |
| 197 | 200 | ||
| @@ -294,7 +297,8 @@ end_dwarf: | |||
| 294 | } | 297 | } |
| 295 | 298 | ||
| 296 | /* Settng up probe points */ | 299 | /* Settng up probe points */ |
| 297 | add_trace_kprobe_events(session.probes, session.nr_probe); | 300 | add_trace_kprobe_events(session.probes, session.nr_probe, |
| 301 | session.force_add); | ||
| 298 | return 0; | 302 | return 0; |
| 299 | } | 303 | } |
| 300 | 304 | ||
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 3b4cf456165c..b05d532a4e4c 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
| @@ -482,7 +482,7 @@ static void write_trace_kprobe_event(int fd, const char *buf) | |||
| 482 | } | 482 | } |
| 483 | 483 | ||
| 484 | static void get_new_event_name(char *buf, size_t len, const char *base, | 484 | static void get_new_event_name(char *buf, size_t len, const char *base, |
| 485 | struct strlist *namelist) | 485 | struct strlist *namelist, bool allow_suffix) |
| 486 | { | 486 | { |
| 487 | int i, ret; | 487 | int i, ret; |
| 488 | 488 | ||
| @@ -493,6 +493,12 @@ static void get_new_event_name(char *buf, size_t len, const char *base, | |||
| 493 | if (!strlist__has_entry(namelist, buf)) | 493 | if (!strlist__has_entry(namelist, buf)) |
| 494 | return; | 494 | return; |
| 495 | 495 | ||
| 496 | if (!allow_suffix) { | ||
| 497 | pr_warning("Error: event \"%s\" already exists. " | ||
| 498 | "(Use -f to force duplicates.)\n", base); | ||
| 499 | die("Can't add new event."); | ||
| 500 | } | ||
| 501 | |||
| 496 | /* Try to add suffix */ | 502 | /* Try to add suffix */ |
| 497 | for (i = 1; i < MAX_EVENT_INDEX; i++) { | 503 | for (i = 1; i < MAX_EVENT_INDEX; i++) { |
| 498 | ret = e_snprintf(buf, len, "%s_%d", base, i); | 504 | ret = e_snprintf(buf, len, "%s_%d", base, i); |
| @@ -505,13 +511,15 @@ static void get_new_event_name(char *buf, size_t len, const char *base, | |||
| 505 | die("Too many events are on the same function."); | 511 | die("Too many events are on the same function."); |
| 506 | } | 512 | } |
| 507 | 513 | ||
| 508 | void add_trace_kprobe_events(struct probe_point *probes, int nr_probes) | 514 | void add_trace_kprobe_events(struct probe_point *probes, int nr_probes, |
| 515 | bool force_add) | ||
| 509 | { | 516 | { |
| 510 | int i, j, fd; | 517 | int i, j, fd; |
| 511 | struct probe_point *pp; | 518 | struct probe_point *pp; |
| 512 | char buf[MAX_CMDLEN]; | 519 | char buf[MAX_CMDLEN]; |
| 513 | char event[64]; | 520 | char event[64]; |
| 514 | struct strlist *namelist; | 521 | struct strlist *namelist; |
| 522 | bool allow_suffix; | ||
| 515 | 523 | ||
| 516 | fd = open_kprobe_events(O_RDWR, O_APPEND); | 524 | fd = open_kprobe_events(O_RDWR, O_APPEND); |
| 517 | /* Get current event names */ | 525 | /* Get current event names */ |
| @@ -524,9 +532,12 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes) | |||
| 524 | if (!pp->group) | 532 | if (!pp->group) |
| 525 | pp->group = strdup(PERFPROBE_GROUP); | 533 | pp->group = strdup(PERFPROBE_GROUP); |
| 526 | DIE_IF(!pp->event || !pp->group); | 534 | DIE_IF(!pp->event || !pp->group); |
| 535 | /* If force_add is true, suffix search is allowed */ | ||
| 536 | allow_suffix = force_add; | ||
| 527 | for (i = 0; i < pp->found; i++) { | 537 | for (i = 0; i < pp->found; i++) { |
| 528 | /* Get an unused new event name */ | 538 | /* Get an unused new event name */ |
| 529 | get_new_event_name(event, 64, pp->event, namelist); | 539 | get_new_event_name(event, 64, pp->event, namelist, |
| 540 | allow_suffix); | ||
| 530 | snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s\n", | 541 | snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s\n", |
| 531 | pp->retprobe ? 'r' : 'p', | 542 | pp->retprobe ? 'r' : 'p', |
| 532 | pp->group, event, | 543 | pp->group, event, |
| @@ -538,6 +549,13 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes) | |||
| 538 | show_perf_probe_event(event, buf, pp); | 549 | show_perf_probe_event(event, buf, pp); |
| 539 | /* Add added event name to namelist */ | 550 | /* Add added event name to namelist */ |
| 540 | strlist__add(namelist, event); | 551 | strlist__add(namelist, event); |
| 552 | /* | ||
| 553 | * Probes after the first probe which comes from same | ||
| 554 | * user input are always allowed to add suffix, because | ||
| 555 | * there might be several addresses corresponding to | ||
| 556 | * one code line. | ||
| 557 | */ | ||
| 558 | allow_suffix = true; | ||
| 541 | } | 559 | } |
| 542 | } | 560 | } |
| 543 | /* Show how to use the event. */ | 561 | /* Show how to use the event. */ |
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index 8bb22f5246cc..8fd30525100c 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h | |||
| @@ -10,7 +10,8 @@ extern void parse_perf_probe_event(const char *str, struct probe_point *pp, | |||
| 10 | extern int synthesize_perf_probe_event(struct probe_point *pp); | 10 | extern int synthesize_perf_probe_event(struct probe_point *pp); |
| 11 | extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp); | 11 | extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp); |
| 12 | extern int synthesize_trace_kprobe_event(struct probe_point *pp); | 12 | extern int synthesize_trace_kprobe_event(struct probe_point *pp); |
| 13 | extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes); | 13 | extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes, |
| 14 | bool force_add); | ||
| 14 | extern void del_trace_kprobe_events(struct strlist *dellist); | 15 | extern void del_trace_kprobe_events(struct strlist *dellist); |
| 15 | extern void show_perf_probe_events(void); | 16 | extern void show_perf_probe_events(void); |
| 16 | 17 | ||
