From 5089d5a9a506a8398665fa3f20cd35468c590483 Mon Sep 17 00:00:00 2001 From: Srikar Dronamraju Date: Mon, 16 Apr 2012 17:39:25 +0530 Subject: [PATCH] --- yaml --- r: 306652 b: refs/heads/master c: 73eff9f56e15598c8399c0b86899fd889b97f085 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/tools/perf/Documentation/perf-probe.txt | 8 +++- trunk/tools/perf/builtin-probe.c | 43 +++++++++++++++++-- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/[refs] b/[refs] index 3e10e57fd4bc..83982a880d52 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 225466f1c2d816c33b4341008f45dfdc83a9f0cb +refs/heads/master: 73eff9f56e15598c8399c0b86899fd889b97f085 diff --git a/trunk/tools/perf/Documentation/perf-probe.txt b/trunk/tools/perf/Documentation/perf-probe.txt index fb673bef4798..b715cb71592b 100644 --- a/trunk/tools/perf/Documentation/perf-probe.txt +++ b/trunk/tools/perf/Documentation/perf-probe.txt @@ -104,6 +104,10 @@ OPTIONS Specify path to the executable or shared library file for user space tracing. Can also be used with --funcs option. +In absence of -m/-x options, perf probe checks if the first argument after +the options is an absolute path name. If its an absolute path, perf probe +uses it as a target module/target user space binary to probe. + PROBE SYNTAX ------------ Probe points are defined by following syntax. @@ -190,11 +194,11 @@ Delete all probes on schedule(). Add probes at zfree() function on /bin/zsh - ./perf probe -x /bin/zsh zfree + ./perf probe -x /bin/zsh zfree or ./perf probe /bin/zsh zfree Add probes at malloc() function on libc - ./perf probe -x /lib/libc.so.6 malloc + ./perf probe -x /lib/libc.so.6 malloc or ./perf probe /lib/libc.so.6 malloc SEE ALSO -------- diff --git a/trunk/tools/perf/builtin-probe.c b/trunk/tools/perf/builtin-probe.c index ee3d84a7c895..e215ae61b2ae 100644 --- a/trunk/tools/perf/builtin-probe.c +++ b/trunk/tools/perf/builtin-probe.c @@ -85,21 +85,58 @@ static int parse_probe_event(const char *str) return ret; } +static int set_target(const char *ptr) +{ + int found = 0; + const char *buf; + + /* + * The first argument after options can be an absolute path + * to an executable / library or kernel module. + * + * TODO: Support relative path, and $PATH, $LD_LIBRARY_PATH, + * short module name. + */ + if (!params.target && ptr && *ptr == '/') { + params.target = ptr; + found = 1; + buf = ptr + (strlen(ptr) - 3); + + if (strcmp(buf, ".ko")) + params.uprobes = true; + + } + + return found; +} + static int parse_probe_event_argv(int argc, const char **argv) { - int i, len, ret; + int i, len, ret, found_target; char *buf; + found_target = set_target(argv[0]); + if (found_target && argc == 1) + return 0; + /* Bind up rest arguments */ len = 0; - for (i = 0; i < argc; i++) + for (i = 0; i < argc; i++) { + if (i == 0 && found_target) + continue; + len += strlen(argv[i]) + 1; + } buf = zalloc(len + 1); if (buf == NULL) return -ENOMEM; len = 0; - for (i = 0; i < argc; i++) + for (i = 0; i < argc; i++) { + if (i == 0 && found_target) + continue; + len += sprintf(&buf[len], "%s ", argv[i]); + } params.mod_events = true; ret = parse_probe_event(buf); free(buf);