Commit 7afb3fab authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Arnaldo Carvalho de Melo

perf probe: Support multiple probes on different binaries

Support multiple probes on different binaries with just
one command.

In the result, this example sets up the probes on icmp_rcv in
kernel, on main and set_target in perf, and on pcspkr_event
in pcspker.ko driver.
  -----
  # perf probe -a icmp_rcv -x ./perf -a main -a set_target \
   -m /lib/modules/4.0.0-rc5+/kernel/drivers/input/misc/pcspkr.ko \
   -a pcspkr_event
  Added new event:
    probe:icmp_rcv       (on icmp_rcv)

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

          perf record -e probe:icmp_rcv -aR sleep 1

  Added new event:
    probe_perf:main      (on main in /home/mhiramat/ksrc/linux-3/tools/perf/perf)

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

          perf record -e probe_perf:main -aR sleep 1

  Added new event:
    probe_perf:set_target (on set_target in /home/mhiramat/ksrc/linux-3/tools/perf/perf)

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

          perf record -e probe_perf:set_target -aR sleep 1

  Added new event:
    probe:pcspkr_event   (on pcspkr_event in pcspkr)

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

          perf record -e probe:pcspkr_event -aR sleep 1
  -----
Reported-by: default avatarArnaldo Carvalho de Melo <acme@infradead.org>
Signed-off-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20150401102539.17137.46454.stgit@localhost.localdomainSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 5e78c69b
...@@ -78,6 +78,11 @@ static int parse_probe_event(const char *str) ...@@ -78,6 +78,11 @@ static int parse_probe_event(const char *str)
} }
pev->uprobes = params.uprobes; pev->uprobes = params.uprobes;
if (params.target) {
pev->target = strdup(params.target);
if (!pev->target)
return -ENOMEM;
}
/* Parse a perf-probe command into event */ /* Parse a perf-probe command into event */
ret = parse_perf_probe_command(str, pev); ret = parse_perf_probe_command(str, pev);
...@@ -178,7 +183,7 @@ static int opt_set_target(const struct option *opt, const char *str, ...@@ -178,7 +183,7 @@ static int opt_set_target(const struct option *opt, const char *str,
int ret = -ENOENT; int ret = -ENOENT;
char *tmp; char *tmp;
if (str && !params.target) { if (str) {
if (!strcmp(opt->long_name, "exec")) if (!strcmp(opt->long_name, "exec"))
params.uprobes = true; params.uprobes = true;
#ifdef HAVE_DWARF_SUPPORT #ifdef HAVE_DWARF_SUPPORT
...@@ -200,6 +205,7 @@ static int opt_set_target(const struct option *opt, const char *str, ...@@ -200,6 +205,7 @@ static int opt_set_target(const struct option *opt, const char *str,
if (!tmp) if (!tmp)
return -ENOMEM; return -ENOMEM;
} }
free(params.target);
params.target = tmp; params.target = tmp;
ret = 0; ret = 0;
} }
...@@ -487,7 +493,6 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) ...@@ -487,7 +493,6 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
if (params.nevents) { if (params.nevents) {
ret = add_perf_probe_events(params.events, params.nevents, ret = add_perf_probe_events(params.events, params.nevents,
params.max_probe_points, params.max_probe_points,
params.target,
params.force_add); params.force_add);
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);
......
...@@ -1906,6 +1906,7 @@ void clear_perf_probe_event(struct perf_probe_event *pev) ...@@ -1906,6 +1906,7 @@ void clear_perf_probe_event(struct perf_probe_event *pev)
free(pev->event); free(pev->event);
free(pev->group); free(pev->group);
free(pev->target);
clear_perf_probe_point(&pev->point); clear_perf_probe_point(&pev->point);
for (i = 0; i < pev->nargs; i++) { for (i = 0; i < pev->nargs; i++) {
...@@ -2654,7 +2655,7 @@ struct __event_package { ...@@ -2654,7 +2655,7 @@ struct __event_package {
}; };
int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
int max_tevs, const char *target, bool force_add) int max_tevs, bool force_add)
{ {
int i, j, ret; int i, j, ret;
struct __event_package *pkgs; struct __event_package *pkgs;
...@@ -2678,7 +2679,7 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, ...@@ -2678,7 +2679,7 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
ret = convert_to_probe_trace_events(pkgs[i].pev, ret = convert_to_probe_trace_events(pkgs[i].pev,
&pkgs[i].tevs, &pkgs[i].tevs,
max_tevs, max_tevs,
target); pkgs[i].pev->target);
if (ret < 0) if (ret < 0)
goto end; goto end;
pkgs[i].ntevs = ret; pkgs[i].ntevs = ret;
......
...@@ -73,7 +73,8 @@ struct perf_probe_event { ...@@ -73,7 +73,8 @@ struct perf_probe_event {
char *group; /* Group name */ char *group; /* Group name */
struct perf_probe_point point; /* Probe point */ struct perf_probe_point point; /* Probe point */
int nargs; /* Number of arguments */ int nargs; /* Number of arguments */
bool uprobes; bool uprobes; /* Uprobe event flag */
char *target; /* Target binary */
struct perf_probe_arg *args; /* Arguments */ struct perf_probe_arg *args; /* Arguments */
}; };
...@@ -124,8 +125,7 @@ extern int line_range__init(struct line_range *lr); ...@@ -124,8 +125,7 @@ extern int line_range__init(struct line_range *lr);
extern const char *kernel_get_module_path(const char *module); extern const char *kernel_get_module_path(const char *module);
extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
int max_probe_points, const char *module, int max_probe_points, bool force_add);
bool force_add);
extern int del_perf_probe_events(struct strlist *dellist); extern int del_perf_probe_events(struct strlist *dellist);
extern int show_perf_probe_events(void); extern int show_perf_probe_events(void);
extern int show_line_range(struct line_range *lr, const char *module, extern int show_line_range(struct line_range *lr, const char *module,
......
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