diff options
| -rw-r--r-- | tools/perf/Documentation/perf-probe.txt | 15 | ||||
| -rw-r--r-- | tools/perf/builtin-probe.c | 43 | ||||
| -rw-r--r-- | tools/perf/util/probe-event.c | 422 | ||||
| -rw-r--r-- | tools/perf/util/probe-event.h | 12 | ||||
| -rw-r--r-- | tools/perf/util/symbol.c | 8 | ||||
| -rw-r--r-- | tools/perf/util/symbol.h | 1 |
6 files changed, 403 insertions, 98 deletions
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt index 2780d9ce48bf..fb673bef4798 100644 --- a/tools/perf/Documentation/perf-probe.txt +++ b/tools/perf/Documentation/perf-probe.txt | |||
| @@ -77,7 +77,8 @@ OPTIONS | |||
| 77 | 77 | ||
| 78 | -F:: | 78 | -F:: |
| 79 | --funcs:: | 79 | --funcs:: |
| 80 | Show available functions in given module or kernel. | 80 | Show available functions in given module or kernel. With -x/--exec, |
| 81 | can also list functions in a user space executable / shared library. | ||
| 81 | 82 | ||
| 82 | --filter=FILTER:: | 83 | --filter=FILTER:: |
| 83 | (Only for --vars and --funcs) Set filter. FILTER is a combination of glob | 84 | (Only for --vars and --funcs) Set filter. FILTER is a combination of glob |
| @@ -98,6 +99,11 @@ OPTIONS | |||
| 98 | --max-probes:: | 99 | --max-probes:: |
| 99 | Set the maximum number of probe points for an event. Default is 128. | 100 | Set the maximum number of probe points for an event. Default is 128. |
| 100 | 101 | ||
| 102 | -x:: | ||
| 103 | --exec=PATH:: | ||
| 104 | Specify path to the executable or shared library file for user | ||
| 105 | space tracing. Can also be used with --funcs option. | ||
| 106 | |||
| 101 | PROBE SYNTAX | 107 | PROBE SYNTAX |
| 102 | ------------ | 108 | ------------ |
| 103 | Probe points are defined by following syntax. | 109 | Probe points are defined by following syntax. |
| @@ -182,6 +188,13 @@ Delete all probes on schedule(). | |||
| 182 | 188 | ||
| 183 | ./perf probe --del='schedule*' | 189 | ./perf probe --del='schedule*' |
| 184 | 190 | ||
| 191 | Add probes at zfree() function on /bin/zsh | ||
| 192 | |||
| 193 | ./perf probe -x /bin/zsh zfree | ||
| 194 | |||
| 195 | Add probes at malloc() function on libc | ||
| 196 | |||
| 197 | ./perf probe -x /lib/libc.so.6 malloc | ||
| 185 | 198 | ||
| 186 | SEE ALSO | 199 | SEE ALSO |
| 187 | -------- | 200 | -------- |
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 4935c09dd5b5..ee3d84a7c895 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
| @@ -54,6 +54,7 @@ static struct { | |||
| 54 | bool show_ext_vars; | 54 | bool show_ext_vars; |
| 55 | bool show_funcs; | 55 | bool show_funcs; |
| 56 | bool mod_events; | 56 | bool mod_events; |
| 57 | bool uprobes; | ||
| 57 | int nevents; | 58 | int nevents; |
| 58 | struct perf_probe_event events[MAX_PROBES]; | 59 | struct perf_probe_event events[MAX_PROBES]; |
| 59 | struct strlist *dellist; | 60 | struct strlist *dellist; |
| @@ -75,6 +76,8 @@ static int parse_probe_event(const char *str) | |||
| 75 | return -1; | 76 | return -1; |
| 76 | } | 77 | } |
| 77 | 78 | ||
| 79 | pev->uprobes = params.uprobes; | ||
| 80 | |||
| 78 | /* Parse a perf-probe command into event */ | 81 | /* Parse a perf-probe command into event */ |
| 79 | ret = parse_perf_probe_command(str, pev); | 82 | ret = parse_perf_probe_command(str, pev); |
| 80 | pr_debug("%d arguments\n", pev->nargs); | 83 | pr_debug("%d arguments\n", pev->nargs); |
| @@ -125,6 +128,28 @@ static int opt_del_probe_event(const struct option *opt __used, | |||
| 125 | return 0; | 128 | return 0; |
| 126 | } | 129 | } |
| 127 | 130 | ||
| 131 | static int opt_set_target(const struct option *opt, const char *str, | ||
| 132 | int unset __used) | ||
| 133 | { | ||
| 134 | int ret = -ENOENT; | ||
| 135 | |||
| 136 | if (str && !params.target) { | ||
| 137 | if (!strcmp(opt->long_name, "exec")) | ||
| 138 | params.uprobes = true; | ||
| 139 | #ifdef DWARF_SUPPORT | ||
| 140 | else if (!strcmp(opt->long_name, "module")) | ||
| 141 | params.uprobes = false; | ||
| 142 | #endif | ||
| 143 | else | ||
| 144 | return ret; | ||
| 145 | |||
| 146 | params.target = str; | ||
| 147 | ret = 0; | ||
| 148 | } | ||
| 149 | |||
| 150 | return ret; | ||
| 151 | } | ||
| 152 | |||
| 128 | #ifdef DWARF_SUPPORT | 153 | #ifdef DWARF_SUPPORT |
| 129 | static int opt_show_lines(const struct option *opt __used, | 154 | static int opt_show_lines(const struct option *opt __used, |
| 130 | const char *str, int unset __used) | 155 | const char *str, int unset __used) |
| @@ -246,9 +271,9 @@ static const struct option options[] = { | |||
| 246 | "file", "vmlinux pathname"), | 271 | "file", "vmlinux pathname"), |
| 247 | OPT_STRING('s', "source", &symbol_conf.source_prefix, | 272 | OPT_STRING('s', "source", &symbol_conf.source_prefix, |
| 248 | "directory", "path to kernel source"), | 273 | "directory", "path to kernel source"), |
| 249 | OPT_STRING('m', "module", ¶ms.target, | 274 | OPT_CALLBACK('m', "module", NULL, "modname|path", |
| 250 | "modname|path", | 275 | "target module name (for online) or path (for offline)", |
| 251 | "target module name (for online) or path (for offline)"), | 276 | opt_set_target), |
| 252 | #endif | 277 | #endif |
| 253 | OPT__DRY_RUN(&probe_event_dry_run), | 278 | OPT__DRY_RUN(&probe_event_dry_run), |
| 254 | OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points, | 279 | OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points, |
| @@ -260,6 +285,8 @@ static const struct option options[] = { | |||
| 260 | "\t\t\t(default: \"" DEFAULT_VAR_FILTER "\" for --vars,\n" | 285 | "\t\t\t(default: \"" DEFAULT_VAR_FILTER "\" for --vars,\n" |
| 261 | "\t\t\t \"" DEFAULT_FUNC_FILTER "\" for --funcs)", | 286 | "\t\t\t \"" DEFAULT_FUNC_FILTER "\" for --funcs)", |
| 262 | opt_set_filter), | 287 | opt_set_filter), |
| 288 | OPT_CALLBACK('x', "exec", NULL, "executable|path", | ||
| 289 | "target executable name or path", opt_set_target), | ||
| 263 | OPT_END() | 290 | OPT_END() |
| 264 | }; | 291 | }; |
| 265 | 292 | ||
| @@ -310,6 +337,10 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
| 310 | pr_err(" Error: Don't use --list with --funcs.\n"); | 337 | pr_err(" Error: Don't use --list with --funcs.\n"); |
| 311 | usage_with_options(probe_usage, options); | 338 | usage_with_options(probe_usage, options); |
| 312 | } | 339 | } |
| 340 | if (params.uprobes) { | ||
| 341 | pr_warning(" Error: Don't use --list with --exec.\n"); | ||
| 342 | usage_with_options(probe_usage, options); | ||
| 343 | } | ||
| 313 | ret = show_perf_probe_events(); | 344 | ret = show_perf_probe_events(); |
| 314 | if (ret < 0) | 345 | if (ret < 0) |
| 315 | pr_err(" Error: Failed to show event list. (%d)\n", | 346 | pr_err(" Error: Failed to show event list. (%d)\n", |
| @@ -333,8 +364,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
| 333 | if (!params.filter) | 364 | if (!params.filter) |
| 334 | params.filter = strfilter__new(DEFAULT_FUNC_FILTER, | 365 | params.filter = strfilter__new(DEFAULT_FUNC_FILTER, |
| 335 | NULL); | 366 | NULL); |
| 336 | ret = show_available_funcs(params.target, | 367 | ret = show_available_funcs(params.target, params.filter, |
| 337 | params.filter); | 368 | params.uprobes); |
| 338 | strfilter__delete(params.filter); | 369 | strfilter__delete(params.filter); |
| 339 | if (ret < 0) | 370 | if (ret < 0) |
| 340 | pr_err(" Error: Failed to show functions." | 371 | pr_err(" Error: Failed to show functions." |
| @@ -343,7 +374,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
| 343 | } | 374 | } |
| 344 | 375 | ||
| 345 | #ifdef DWARF_SUPPORT | 376 | #ifdef DWARF_SUPPORT |
| 346 | if (params.show_lines) { | 377 | if (params.show_lines && !params.uprobes) { |
| 347 | if (params.mod_events) { | 378 | if (params.mod_events) { |
| 348 | pr_err(" Error: Don't use --line with" | 379 | pr_err(" Error: Don't use --line with" |
| 349 | " --add/--del.\n"); | 380 | " --add/--del.\n"); |
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 8a8ee64e72d1..59dccc98b554 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
| @@ -44,6 +44,7 @@ | |||
| 44 | #include "trace-event.h" /* For __unused */ | 44 | #include "trace-event.h" /* For __unused */ |
| 45 | #include "probe-event.h" | 45 | #include "probe-event.h" |
| 46 | #include "probe-finder.h" | 46 | #include "probe-finder.h" |
| 47 | #include "session.h" | ||
| 47 | 48 | ||
| 48 | #define MAX_CMDLEN 256 | 49 | #define MAX_CMDLEN 256 |
| 49 | #define MAX_PROBE_ARGS 128 | 50 | #define MAX_PROBE_ARGS 128 |
| @@ -70,6 +71,8 @@ static int e_snprintf(char *str, size_t size, const char *format, ...) | |||
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); | 73 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); |
| 74 | static int convert_name_to_addr(struct perf_probe_event *pev, | ||
| 75 | const char *exec); | ||
| 73 | static struct machine machine; | 76 | static struct machine machine; |
| 74 | 77 | ||
| 75 | /* Initialize symbol maps and path of vmlinux/modules */ | 78 | /* Initialize symbol maps and path of vmlinux/modules */ |
| @@ -170,6 +173,34 @@ const char *kernel_get_module_path(const char *module) | |||
| 170 | return (dso) ? dso->long_name : NULL; | 173 | return (dso) ? dso->long_name : NULL; |
| 171 | } | 174 | } |
| 172 | 175 | ||
| 176 | static int init_user_exec(void) | ||
| 177 | { | ||
| 178 | int ret = 0; | ||
| 179 | |||
| 180 | symbol_conf.try_vmlinux_path = false; | ||
| 181 | symbol_conf.sort_by_name = true; | ||
| 182 | ret = symbol__init(); | ||
| 183 | |||
| 184 | if (ret < 0) | ||
