aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/probe-event.c
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/util/probe-event.c
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/util/probe-event.c')
-rw-r--r--tools/perf/util/probe-event.c137
1 files changed, 135 insertions, 2 deletions
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