diff options
author | Masami Hiramatsu <mhiramat@redhat.com> | 2010-03-16 18:05:37 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-03-17 06:32:30 -0400 |
commit | e0faa8d35845bb1893cf9e608a5a5d92e9390bf0 (patch) | |
tree | 4bc641f43f9b572b4ae8f19e8201932a9d611987 /tools/perf/builtin-probe.c | |
parent | 31facc5f1ac674fbcc29f212377e589396bb934c (diff) |
perf probe: Move add-probe routine to util/
Move add-probe routine to util/probe_event.c. This simplifies
main routine for reducing maintenance cost.
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <20100316220537.32050.72214.stgit@localhost6.localdomain6>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/builtin-probe.c')
-rw-r--r-- | tools/perf/builtin-probe.c | 126 |
1 files changed, 3 insertions, 123 deletions
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index b6afe7b344dd..2087034782ff 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -36,11 +36,9 @@ | |||
36 | #include "builtin.h" | 36 | #include "builtin.h" |
37 | #include "util/util.h" | 37 | #include "util/util.h" |
38 | #include "util/strlist.h" | 38 | #include "util/strlist.h" |
39 | #include "util/event.h" | 39 | #include "util/symbol.h" |
40 | #include "util/debug.h" | 40 | #include "util/debug.h" |
41 | #include "util/debugfs.h" | 41 | #include "util/debugfs.h" |
42 | #include "util/symbol.h" | ||
43 | #include "util/thread.h" | ||
44 | #include "util/parse-options.h" | 42 | #include "util/parse-options.h" |
45 | #include "util/parse-events.h" /* For debugfs_path */ | 43 | #include "util/parse-events.h" /* For debugfs_path */ |
46 | #include "util/probe-finder.h" | 44 | #include "util/probe-finder.h" |
@@ -57,8 +55,6 @@ static struct { | |||
57 | int nr_probe; | 55 | int nr_probe; |
58 | struct probe_point probes[MAX_PROBES]; | 56 | struct probe_point probes[MAX_PROBES]; |
59 | struct strlist *dellist; | 57 | struct strlist *dellist; |
60 | struct map_groups kmap_groups; | ||
61 | struct map *kmaps[MAP__NR_TYPES]; | ||
62 | struct line_range line_range; | 58 | struct line_range line_range; |
63 | } session; | 59 | } session; |
64 | 60 | ||
@@ -114,29 +110,7 @@ static int opt_del_probe_event(const struct option *opt __used, | |||
114 | return 0; | 110 | return 0; |
115 | } | 111 | } |
116 | 112 | ||
117 | /* Currently just checking function name from symbol map */ | ||
118 | static void evaluate_probe_point(struct probe_point *pp) | ||
119 | { | ||
120 | struct symbol *sym; | ||
121 | sym = map__find_symbol_by_name(session.kmaps[MAP__FUNCTION], | ||
122 | pp->function, NULL); | ||
123 | if (!sym) | ||
124 | die("Kernel symbol \'%s\' not found - probe not added.", | ||
125 | pp->function); | ||
126 | } | ||
127 | |||
128 | #ifndef NO_DWARF_SUPPORT | 113 | #ifndef NO_DWARF_SUPPORT |
129 | static int open_vmlinux(void) | ||
130 | { | ||
131 | if (map__load(session.kmaps[MAP__FUNCTION], NULL) < 0) { | ||
132 | pr_debug("Failed to load kernel map.\n"); | ||
133 | return -EINVAL; | ||
134 | } | ||
135 | pr_debug("Try to open %s\n", | ||
136 | session.kmaps[MAP__FUNCTION]->dso->long_name); | ||
137 | return open(session.kmaps[MAP__FUNCTION]->dso->long_name, O_RDONLY); | ||
138 | } | ||
139 | |||
140 | static int opt_show_lines(const struct option *opt __used, | 114 | static int opt_show_lines(const struct option *opt __used, |
141 | const char *str, int unset __used) | 115 | const char *str, int unset __used) |
142 | { | 116 | { |
@@ -204,31 +178,8 @@ static const struct option options[] = { | |||
204 | OPT_END() | 178 | OPT_END() |
205 | }; | 179 | }; |
206 | 180 | ||
207 | /* Initialize symbol maps for vmlinux */ | ||
208 | static void init_vmlinux(void) | ||
209 | { | ||
210 | symbol_conf.sort_by_name = true; | ||
211 | if (symbol_conf.vmlinux_name == NULL) | ||
212 | symbol_conf.try_vmlinux_path = true; | ||
213 | else | ||
214 | pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name); | ||
215 | if (symbol__init() < 0) | ||
216 | die("Failed to init symbol map."); | ||
217 | |||
218 | map_groups__init(&session.kmap_groups); | ||
219 | if (map_groups__create_kernel_maps(&session.kmap_groups, | ||
220 | session.kmaps) < 0) | ||
221 | die("Failed to create kernel maps."); | ||
222 | } | ||
223 | |||
224 | int cmd_probe(int argc, const char **argv, const char *prefix __used) | 181 | int cmd_probe(int argc, const char **argv, const char *prefix __used) |
225 | { | 182 | { |
226 | int i, ret; | ||
227 | #ifndef NO_DWARF_SUPPORT | ||
228 | int fd; | ||
229 | #endif | ||
230 | struct probe_point *pp; | ||
231 | |||
232 | argc = parse_options(argc, argv, options, probe_usage, | 183 | argc = parse_options(argc, argv, options, probe_usage, |
233 | PARSE_OPT_STOP_AT_NON_OPTION); | 184 | PARSE_OPT_STOP_AT_NON_OPTION); |
234 | if (argc > 0) { | 185 | if (argc > 0) { |
@@ -267,14 +218,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
267 | " --add/--del.\n"); | 218 | " --add/--del.\n"); |
268 | usage_with_options(probe_usage, options); | 219 | usage_with_options(probe_usage, options); |
269 | } | 220 | } |
270 | init_vmlinux(); | 221 | |
271 | fd = open_vmlinux(); | ||
272 | if (fd < 0) | ||
273 | die("Could not open debuginfo file."); | ||
274 | ret = find_line_range(fd, &session.line_range); | ||
275 | if (ret <= 0) | ||
276 | die("Source line is not found.\n"); | ||
277 | close(fd); | ||
278 | show_line_range(&session.line_range); | 222 | show_line_range(&session.line_range); |
279 | return 0; | 223 | return 0; |
280 | } | 224 | } |
@@ -287,72 +231,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
287 | return 0; | 231 | return 0; |
288 | } | 232 | } |
289 | 233 | ||
290 | /* Add probes */ | ||
291 | init_vmlinux(); | ||
292 | |||
293 | if (session.need_dwarf) | ||
294 | #ifdef NO_DWARF_SUPPORT | ||
295 | die("Debuginfo-analysis is not supported"); | ||
296 | #else /* !NO_DWARF_SUPPORT */ | ||
297 | pr_debug("Some probes require debuginfo.\n"); | ||
298 | |||
299 | fd = open_vmlinux(); | ||
300 | if (fd < 0) { | ||
301 | if (session.need_dwarf) | ||
302 | die("Could not open debuginfo file."); | ||
303 | |||
304 | pr_debug("Could not open vmlinux/module file." | ||
305 | " Try to use symbols.\n"); | ||
306 | goto end_dwarf; | ||
307 | } | ||
308 | |||
309 | /* Searching probe points */ | ||
310 | for (i = 0; i < session.nr_probe; i++) { | ||
311 | pp = &session.probes[i]; | ||
312 | if (pp->found) | ||
313 | continue; | ||
314 | |||
315 | lseek(fd, SEEK_SET, 0); | ||
316 | ret = find_probe_point(fd, pp); | ||
317 | if (ret > 0) | ||
318 | continue; | ||
319 | if (ret == 0) { /* No error but failed to find probe point. */ | ||
320 | synthesize_perf_probe_point(pp); | ||
321 | die("Probe point '%s' not found. - probe not added.", | ||
322 | pp->probes[0]); | ||
323 | } | ||
324 | /* Error path */ | ||
325 | if (session.need_dwarf) { | ||
326 | if (ret == -ENOENT) | ||
327 | pr_warning("No dwarf info found in the vmlinux - please rebuild with CONFIG_DEBUG_INFO=y.\n"); | ||
328 | die("Could not analyze debuginfo."); | ||
329 | } | ||
330 | pr_debug("An error occurred in debuginfo analysis." | ||
331 | " Try to use symbols.\n"); | ||
332 | break; | ||
333 | } | ||
334 | close(fd); | ||
335 | |||
336 | end_dwarf: | ||
337 | #endif /* !NO_DWARF_SUPPORT */ | ||
338 | |||
339 | /* Synthesize probes without dwarf */ | ||
340 | for (i = 0; i < session.nr_probe; i++) { | ||
341 | pp = &session.probes[i]; | ||
342 | if (pp->found) /* This probe is already found. */ | ||
343 | continue; | ||
344 | |||
345 | evaluate_probe_point(pp); | ||
346 | ret = synthesize_trace_kprobe_event(pp); | ||
347 | if (ret == -E2BIG) | ||
348 | die("probe point definition becomes too long."); | ||
349 | else if (ret < 0) | ||
350 | die("Failed to synthesize a probe point."); | ||
351 | } | ||
352 | |||
353 | /* Settng up probe points */ | ||
354 | add_trace_kprobe_events(session.probes, session.nr_probe, | 234 | add_trace_kprobe_events(session.probes, session.nr_probe, |
355 | session.force_add); | 235 | session.force_add, session.need_dwarf); |
356 | return 0; | 236 | return 0; |
357 | } | 237 | } |
358 | 238 | ||