diff options
author | Srikar Dronamraju <srikar@linux.vnet.ibm.com> | 2012-04-16 08:09:25 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-05-11 12:58:53 -0400 |
commit | 73eff9f56e15598c8399c0b86899fd889b97f085 (patch) | |
tree | 66af5bbb7d09dac1ccbf90737f16ffb23f334e2c /tools/perf | |
parent | 225466f1c2d816c33b4341008f45dfdc83a9f0cb (diff) |
perf probe: Detect probe target when m/x options are absent
Options -m and -x explicitly allow tracing of modules / user space
binaries. In absense of these options, check if the first argument can
be used as a target.
perf probe /bin/zsh zfree is equivalent to perf probe -x /bin/zsh zfree.
Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Anton Arapov <anton@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Jim Keniston <jkenisto@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linux-mm <linux-mm@kvack.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20120416120925.30661.40409.sendpatchset@srdronam.in.ibm.com
Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/Documentation/perf-probe.txt | 8 | ||||
-rw-r--r-- | tools/perf/builtin-probe.c | 43 |
2 files changed, 46 insertions, 5 deletions
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt index fb673bef4798..b715cb71592b 100644 --- a/tools/perf/Documentation/perf-probe.txt +++ b/tools/perf/Documentation/perf-probe.txt | |||
@@ -104,6 +104,10 @@ OPTIONS | |||
104 | Specify path to the executable or shared library file for user | 104 | Specify path to the executable or shared library file for user |
105 | space tracing. Can also be used with --funcs option. | 105 | space tracing. Can also be used with --funcs option. |
106 | 106 | ||
107 | In absence of -m/-x options, perf probe checks if the first argument after | ||
108 | the options is an absolute path name. If its an absolute path, perf probe | ||
109 | uses it as a target module/target user space binary to probe. | ||
110 | |||
107 | PROBE SYNTAX | 111 | PROBE SYNTAX |
108 | ------------ | 112 | ------------ |
109 | Probe points are defined by following syntax. | 113 | Probe points are defined by following syntax. |
@@ -190,11 +194,11 @@ Delete all probes on schedule(). | |||
190 | 194 | ||
191 | Add probes at zfree() function on /bin/zsh | 195 | Add probes at zfree() function on /bin/zsh |
192 | 196 | ||
193 | ./perf probe -x /bin/zsh zfree | 197 | ./perf probe -x /bin/zsh zfree or ./perf probe /bin/zsh zfree |
194 | 198 | ||
195 | Add probes at malloc() function on libc | 199 | Add probes at malloc() function on libc |
196 | 200 | ||
197 | ./perf probe -x /lib/libc.so.6 malloc | 201 | ./perf probe -x /lib/libc.so.6 malloc or ./perf probe /lib/libc.so.6 malloc |
198 | 202 | ||
199 | SEE ALSO | 203 | SEE ALSO |
200 | -------- | 204 | -------- |
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index ee3d84a7c895..e215ae61b2ae 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -85,21 +85,58 @@ static int parse_probe_event(const char *str) | |||
85 | return ret; | 85 | return ret; |
86 | } | 86 | } |
87 | 87 | ||
88 | static int set_target(const char *ptr) | ||
89 | { | ||
90 | int found = 0; | ||
91 | const char *buf; | ||
92 | |||
93 | /* | ||
94 | * The first argument after options can be an absolute path | ||
95 | * to an executable / library or kernel module. | ||
96 | * | ||
97 | * TODO: Support relative path, and $PATH, $LD_LIBRARY_PATH, | ||
98 | * short module name. | ||
99 | */ | ||
100 | if (!params.target && ptr && *ptr == '/') { | ||
101 | params.target = ptr; | ||
102 | found = 1; | ||
103 | buf = ptr + (strlen(ptr) - 3); | ||
104 | |||
105 | if (strcmp(buf, ".ko")) | ||
106 | params.uprobes = true; | ||
107 | |||
108 | } | ||
109 | |||
110 | return found; | ||
111 | } | ||
112 | |||
88 | static int parse_probe_event_argv(int argc, const char **argv) | 113 | static int parse_probe_event_argv(int argc, const char **argv) |
89 | { | 114 | { |
90 | int i, len, ret; | 115 | int i, len, ret, found_target; |
91 | char *buf; | 116 | char *buf; |
92 | 117 | ||
118 | found_target = set_target(argv[0]); | ||
119 | if (found_target && argc == 1) | ||
120 | return 0; | ||
121 | |||
93 | /* Bind up rest arguments */ | 122 | /* Bind up rest arguments */ |
94 | len = 0; | 123 | len = 0; |
95 | for (i = 0; i < argc; i++) | 124 | for (i = 0; i < argc; i++) { |
125 | if (i == 0 && found_target) | ||
126 | continue; | ||
127 | |||
96 | len += strlen(argv[i]) + 1; | 128 | len += strlen(argv[i]) + 1; |
129 | } | ||
97 | buf = zalloc(len + 1); | 130 | buf = zalloc(len + 1); |
98 | if (buf == NULL) | 131 | if (buf == NULL) |
99 | return -ENOMEM; | 132 | return -ENOMEM; |
100 | len = 0; | 133 | len = 0; |
101 | for (i = 0; i < argc; i++) | 134 | for (i = 0; i < argc; i++) { |
135 | if (i == 0 && found_target) | ||
136 | continue; | ||
137 | |||
102 | len += sprintf(&buf[len], "%s ", argv[i]); | 138 | len += sprintf(&buf[len], "%s ", argv[i]); |
139 | } | ||
103 | params.mod_events = true; | 140 | params.mod_events = true; |
104 | ret = parse_probe_event(buf); | 141 | ret = parse_probe_event(buf); |
105 | free(buf); | 142 | free(buf); |