aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@redhat.com>2010-03-16 18:05:37 -0400
committerIngo Molnar <mingo@elte.hu>2010-03-17 06:32:30 -0400
commite0faa8d35845bb1893cf9e608a5a5d92e9390bf0 (patch)
tree4bc641f43f9b572b4ae8f19e8201932a9d611987 /tools/perf
parent31facc5f1ac674fbcc29f212377e589396bb934c (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')
-rw-r--r--tools/perf/builtin-probe.c126
-rw-r--r--tools/perf/util/probe-event.c137
-rw-r--r--tools/perf/util/probe-event.h2
3 files changed, 139 insertions, 126 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 */
118static 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
129static 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
140static int opt_show_lines(const struct option *opt __used, 114static 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 */
208static 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
224int cmd_probe(int argc, const char **argv, const char *prefix __used) 181int 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
336end_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
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 88a3b6d75c7c..1e60a659578b 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -40,6 +40,8 @@
40#include "debug.h" 40#include "debug.h"
41#include "cache.h" 41#include "cache.h"
42#include "color.h" 42#include "color.h"
43#include "symbol.h"
44#include "thread.h"
43#include "parse-events.h" /* For debugfs_path */ 45#include "parse-events.h" /* For debugfs_path */
44#include "probe-event.h" 46#include "probe-event.h"
45 47
@@ -65,6 +67,38 @@ static int e_snprintf(char *str, size_t size, const char *format, ...)
65 return ret; 67 return ret;
66} 68}
67 69
70
71static struct map_groups kmap_groups;
72static struct map *kmaps[MAP__NR_TYPES];
73
74/* Initialize symbol maps for vmlinux */
75static void init_vmlinux(void)
76{
77 symbol_conf.sort_by_name = true;
78 if (symbol_conf.vmlinux_name == NULL)
79 symbol_conf.try_vmlinux_path = true;
80 else
81 pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name);
82 if (symbol__init() < 0)
83 die("Failed to init symbol map.");
84
85 map_groups__init(&kmap_groups);
86 if (map_groups__create_kernel_maps(&kmap_groups, kmaps) < 0)
87 die("Failed to create kernel maps.");
88}
89
90#ifndef NO_DWARF_SUPPORT
91static int open_vmlinux(void)
92{
93 if (map__load(kmaps[MAP__FUNCTION], NULL) < 0) {
94 pr_debug("Failed to load kernel map.\n");
95 return -EINVAL;
96 }
97 pr_debug("Try to open %s\n", kmaps[MAP__FUNCTION]->dso->long_name);
98 return open(kmaps[MAP__FUNCTION]->dso->long_name, O_RDONLY);
99}
100#endif
101
68void parse_line_range_desc(const char *arg, struct line_range *lr) 102void parse_line_range_desc(const char *arg, struct line_range *lr)
69{ 103{
70 const char *ptr; 104 const char *ptr;
@@ -586,8 +620,8 @@ static void get_new_event_name(char *buf, size_t len, const char *base,
586 die("Too many events are on the same function."); 620 die("Too many events are on the same function.");
587} 621}
588 622
589void add_trace_kprobe_events(struct probe_point *probes, int nr_probes, 623static void __add_trace_kprobe_events(struct probe_point *probes,
590 bool force_add) 624 int nr_probes, bool force_add)
591{ 625{
592 int i, j, fd; 626 int i, j, fd;
593 struct probe_point *pp; 627 struct probe_point *pp;
@@ -640,6 +674,92 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
640 close(fd); 674 close(fd);
641} 675}
642 676
677/* Currently just checking function name from symbol map */
678static void evaluate_probe_point(struct probe_point *pp)
679{
680 struct symbol *sym;
681 sym = map__find_symbol_by_name(kmaps[MAP__FUNCTION],
682 pp->function, NULL);
683 if (!sym)
684 die("Kernel symbol \'%s\' not found - probe not added.",
685 pp->function);
686}
687
688void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
689 bool force_add, bool need_dwarf)
690{
691 int i, ret;
692 struct probe_point *pp;
693#ifndef NO_DWARF_SUPPORT
694 int fd;
695#endif
696 /* Add probes */
697 init_vmlinux();
698
699 if (need_dwarf)
700#ifdef NO_DWARF_SUPPORT
701 die("Debuginfo-analysis is not supported");
702#else /* !NO_DWARF_SUPPORT */
703 pr_debug("Some probes require debuginfo.\n");
704
705 fd = open_vmlinux();
706 if (fd < 0) {
707 if (need_dwarf)
708 die("Could not open debuginfo file.");
709
710 pr_debug("Could not open vmlinux/module file."
711 " Try to use symbols.\n");
712 goto end_dwarf;
713 }
714
715 /* Searching probe points */
716 for (i = 0; i < nr_probes; i++) {
717 pp = &probes[i];
718 if (pp->found)
719 continue;
720
721 lseek(fd, SEEK_SET, 0);
722 ret = find_probe_point(fd, pp);
723 if (ret > 0)
724 continue;
725 if (ret == 0) { /* No error but failed to find probe point. */
726 synthesize_perf_probe_point(pp);
727 die("Probe point '%s' not found. - probe not added.",
728 pp->probes[0]);
729 }
730 /* Error path */
731 if (need_dwarf) {
732 if (ret == -ENOENT)
733 pr_warning("No dwarf info found in the vmlinux - please rebuild with CONFIG_DEBUG_INFO=y.\n");
734 die("Could not analyze debuginfo.");
735 }
736 pr_debug("An error occurred in debuginfo analysis."
737 " Try to use symbols.\n");
738 break;
739 }
740 close(fd);
741
742end_dwarf:
743#endif /* !NO_DWARF_SUPPORT */
744
745 /* Synthesize probes without dwarf */
746 for (i = 0; i < nr_probes; i++) {
747 pp = &probes[i];
748 if (pp->found) /* This probe is already found. */
749 continue;
750
751 evaluate_probe_point(pp);
752 ret = synthesize_trace_kprobe_event(pp);
753 if (ret == -E2BIG)
754 die("probe point definition becomes too long.");
755 else if (ret < 0)
756 die("Failed to synthesize a probe point.");
757 }
758
759 /* Settng up probe points */
760 __add_trace_kprobe_events(probes, nr_probes, force_add);
761}
762
643static void __del_trace_kprobe_event(int fd, struct str_node *ent) 763static void __del_trace_kprobe_event(int fd, struct str_node *ent)
644{ 764{
645 char *p; 765 char *p;
@@ -759,6 +879,17 @@ void show_line_range(struct line_range *lr)
759 unsigned int l = 1; 879 unsigned int l = 1;
760 struct line_node *ln; 880 struct line_node *ln;
761 FILE *fp; 881 FILE *fp;
882 int fd, ret;
883
884 /* Search a line range */
885 init_vmlinux();
886 fd = open_vmlinux();
887 if (fd < 0)
888 die("Could not open debuginfo file.");
889 ret = find_line_range(fd, lr);
890 if (ret <= 0)
891 die("Source line is not found.\n");
892 close(fd);
762 893
763 setup_pager(); 894 setup_pager();
764 895
@@ -788,3 +919,5 @@ void show_line_range(struct line_range *lr)
788 919
789 fclose(fp); 920 fclose(fp);
790} 921}
922
923
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 711287d4baea..3865e163bb59 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -13,7 +13,7 @@ extern int synthesize_perf_probe_event(struct probe_point *pp);
13extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp); 13extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp);
14extern int synthesize_trace_kprobe_event(struct probe_point *pp); 14extern int synthesize_trace_kprobe_event(struct probe_point *pp);
15extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes, 15extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
16 bool force_add); 16 bool force_add, bool need_dwarf);
17extern void del_trace_kprobe_events(struct strlist *dellist); 17extern void del_trace_kprobe_events(struct strlist *dellist);
18extern void show_perf_probe_events(void); 18extern void show_perf_probe_events(void);
19extern void show_line_range(struct line_range *lr); 19extern void show_line_range(struct line_range *lr);