Commit b02137cc authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf probe: Move print logic into cmd_probe()

Showing actual trace event when adding perf events is only needed in
perf probe command.  But the add functionality itself can be used by
other places.  So move the printing code into the cmd_probe().

Also it combines the output if more than one event is added.

Before:
  $ sudo perf probe -a do_fork -a do_exit
  Added new event:
  probe:do_fork        (on do_fork)

  You can now use it in all perf tools, such as:

      perf record -e probe:do_fork -aR sleep 1

  Added new events:
  probe:do_exit        (on do_exit)
  probe:do_exit_1      (on do_exit)

  You can now use it in all perf tools, such as:

      perf record -e probe:do_exit_1 -aR sleep 1

After:
  $ sudo perf probe -a do_fork -a do_exit
  Added new events:
  probe:do_fork        (on do_fork)
  probe:do_exit        (on do_exit)
  probe:do_exit_1      (on do_exit)

  You can now use it in all perf tools, such as:

      perf record -e probe:do_exit_1 -aR sleep 1
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1441368963-11565-3-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 12fae5ef
...@@ -311,6 +311,52 @@ static void pr_err_with_code(const char *msg, int err) ...@@ -311,6 +311,52 @@ static void pr_err_with_code(const char *msg, int err)
pr_err("\n"); pr_err("\n");
} }
static int perf_add_probe_events(struct perf_probe_event *pevs, int npevs)
{
int ret;
int i, k;
const char *event = NULL, *group = NULL;
ret = convert_perf_probe_events(pevs, npevs);
if (ret < 0)
goto out_cleanup;
ret = apply_perf_probe_events(pevs, npevs);
if (ret < 0)
goto out_cleanup;
for (i = k = 0; i < npevs; i++)
k += pevs[i].ntevs;
pr_info("Added new event%s\n", (k > 1) ? "s:" : ":");
for (i = 0; i < npevs; i++) {
struct perf_probe_event *pev = &pevs[i];
for (k = 0; k < pev->ntevs; k++) {
struct probe_trace_event *tev = &pev->tevs[k];
/* We use tev's name for showing new events */
show_perf_probe_event(tev->group, tev->event, pev,
tev->point.module, false);
/* Save the last valid name */
event = tev->event;
group = tev->group;
}
}
/* Note that it is possible to skip all events because of blacklist */
if (event) {
/* Show how to use the event. */
pr_info("\nYou can now use it in all perf tools, such as:\n\n");
pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", group, event);
}
out_cleanup:
cleanup_perf_probe_events(pevs, npevs);
return ret;
}
static int static int
__cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
...@@ -496,7 +542,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) ...@@ -496,7 +542,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
usage_with_options(probe_usage, options); usage_with_options(probe_usage, options);
} }
ret = add_perf_probe_events(params.events, params.nevents); ret = perf_add_probe_events(params.events, params.nevents);
if (ret < 0) { if (ret < 0) {
pr_err_with_code(" Error: Failed to add events.", ret); pr_err_with_code(" Error: Failed to add events.", ret);
return ret; return ret;
......
...@@ -2180,9 +2180,9 @@ static int perf_probe_event__sprintf(const char *group, const char *event, ...@@ -2180,9 +2180,9 @@ static int perf_probe_event__sprintf(const char *group, const char *event,
} }
/* Show an event */ /* Show an event */
static int show_perf_probe_event(const char *group, const char *event, int show_perf_probe_event(const char *group, const char *event,
struct perf_probe_event *pev, struct perf_probe_event *pev,
const char *module, bool use_stdout) const char *module, bool use_stdout)
{ {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
int ret; int ret;
...@@ -2399,7 +2399,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, ...@@ -2399,7 +2399,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
{ {
int i, fd, ret; int i, fd, ret;
struct probe_trace_event *tev = NULL; struct probe_trace_event *tev = NULL;
const char *event = NULL, *group = NULL;
struct strlist *namelist; struct strlist *namelist;
fd = probe_file__open(PF_FL_RW | (pev->uprobes ? PF_FL_UPROBE : 0)); fd = probe_file__open(PF_FL_RW | (pev->uprobes ? PF_FL_UPROBE : 0));
...@@ -2415,7 +2414,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, ...@@ -2415,7 +2414,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
} }
ret = 0; ret = 0;
pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
for (i = 0; i < ntevs; i++) { for (i = 0; i < ntevs; i++) {
tev = &tevs[i]; tev = &tevs[i];
/* Skip if the symbol is out of .text or blacklisted */ /* Skip if the symbol is out of .text or blacklisted */
...@@ -2432,13 +2430,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, ...@@ -2432,13 +2430,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
if (ret < 0) if (ret < 0)
break; break;
/* We use tev's name for showing new events */
show_perf_probe_event(tev->group, tev->event, pev,
tev->point.module, false);
/* Save the last valid name */
event = tev->event;
group = tev->group;
/* /*
* Probes after the first probe which comes from same * Probes after the first probe which comes from same
* user input are always allowed to add suffix, because * user input are always allowed to add suffix, because
...@@ -2450,13 +2441,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, ...@@ -2450,13 +2441,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
if (ret == -EINVAL && pev->uprobes) if (ret == -EINVAL && pev->uprobes)
warn_uprobe_event_compat(tev); warn_uprobe_event_compat(tev);
/* Note that it is possible to skip all events because of blacklist */
if (ret >= 0 && event) {
/* Show how to use the event. */
pr_info("\nYou can now use it in all perf tools, such as:\n\n");
pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", group, event);
}
strlist__delete(namelist); strlist__delete(namelist);
close_out: close_out:
close(fd); close(fd);
......
...@@ -144,6 +144,9 @@ extern int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs); ...@@ -144,6 +144,9 @@ extern int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);
extern int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs); extern int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs);
extern void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs); extern void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs);
extern int del_perf_probe_events(struct strfilter *filter); extern int del_perf_probe_events(struct strfilter *filter);
extern int show_perf_probe_event(const char *group, const char *event,
struct perf_probe_event *pev,
const char *module, bool use_stdout);
extern int show_perf_probe_events(struct strfilter *filter); extern int show_perf_probe_events(struct strfilter *filter);
extern int show_line_range(struct line_range *lr, const char *module, extern int show_line_range(struct line_range *lr, const char *module,
bool user); bool user);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment