diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2009-08-12 04:03:49 -0400 |
---|---|---|
committer | Frederic Weisbecker <fweisbec@gmail.com> | 2009-08-12 06:02:38 -0400 |
commit | cd84c2ac6d6425dd4d1b80a2231e534b9b03df18 (patch) | |
tree | 943332327f02f7a056dc87c64e72e340c484ede6 /tools/perf/util | |
parent | 9f8666971185b86615a074bcac67c90fdf8af8bc (diff) |
perf tools: Factorize high level dso helpers
Factorize multiple definitions of high level dso helpers into the
symbol source file.
The side effect is a general export of the verbose and eprintf
debugging helpers into a new file dedicated to debugging purposes.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Brice Goglin <Brice.Goglin@inria.fr>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/debug.c | 22 | ||||
-rw-r--r-- | tools/perf/util/debug.h | 5 | ||||
-rw-r--r-- | tools/perf/util/symbol.c | 97 | ||||
-rw-r--r-- | tools/perf/util/symbol.h | 11 |
4 files changed, 135 insertions, 0 deletions
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c new file mode 100644 index 000000000000..7cb8464abe61 --- /dev/null +++ b/tools/perf/util/debug.c | |||
@@ -0,0 +1,22 @@ | |||
1 | /* For general debugging purposes */ | ||
2 | |||
3 | #include "../perf.h" | ||
4 | #include <string.h> | ||
5 | #include <stdarg.h> | ||
6 | #include <stdio.h> | ||
7 | |||
8 | int verbose = 0; | ||
9 | |||
10 | int eprintf(const char *fmt, ...) | ||
11 | { | ||
12 | va_list args; | ||
13 | int ret = 0; | ||
14 | |||
15 | if (verbose) { | ||
16 | va_start(args, fmt); | ||
17 | ret = vfprintf(stderr, fmt, args); | ||
18 | va_end(args); | ||
19 | } | ||
20 | |||
21 | return ret; | ||
22 | } | ||
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h new file mode 100644 index 000000000000..2ae9090108d3 --- /dev/null +++ b/tools/perf/util/debug.h | |||
@@ -0,0 +1,5 @@ | |||
1 | /* For debugging general purposes */ | ||
2 | |||
3 | extern int verbose; | ||
4 | |||
5 | int eprintf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); | ||
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index f1dcede14307..e9b13b414955 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -937,6 +937,103 @@ int dso__load_kernel(struct dso *self, const char *vmlinux, | |||
937 | return err; | 937 | return err; |
938 | } | 938 | } |
939 | 939 | ||
940 | LIST_HEAD(dsos); | ||
941 | struct dso *kernel_dso; | ||
942 | struct dso *vdso; | ||
943 | struct dso *hypervisor_dso; | ||
944 | |||
945 | char *vmlinux = "vmlinux"; | ||
946 | int modules; | ||
947 | |||
948 | static void dsos__add(struct dso *dso) | ||
949 | { | ||
950 | list_add_tail(&dso->node, &dsos); | ||
951 | } | ||
952 | |||
953 | static struct dso *dsos__find(const char *name) | ||
954 | { | ||
955 | struct dso *pos; | ||
956 | |||
957 | list_for_each_entry(pos, &dsos, node) | ||
958 | if (strcmp(pos->name, name) == 0) | ||
959 | return pos; | ||
960 | return NULL; | ||
961 | } | ||
962 | |||
963 | struct dso *dsos__findnew(const char *name) | ||
964 | { | ||
965 | struct dso *dso = dsos__find(name); | ||
966 | int nr; | ||
967 | |||
968 | if (dso) | ||
969 | return dso; | ||
970 | |||
971 | dso = dso__new(name, 0); | ||
972 | if (!dso) | ||
973 | goto out_delete_dso; | ||
974 | |||
975 | nr = dso__load(dso, NULL, verbose); | ||
976 | if (nr < 0) { | ||
977 | eprintf("Failed to open: %s\n", name); | ||
978 | goto out_delete_dso; | ||
979 | } | ||
980 | if (!nr) | ||
981 | eprintf("No symbols found in: %s, maybe install a debug package?\n", name); | ||
982 | |||
983 | dsos__add(dso); | ||
984 | |||
985 | return dso; | ||
986 | |||
987 | out_delete_dso: | ||
988 | dso__delete(dso); | ||
989 | return NULL; | ||
990 | } | ||
991 | |||
992 | void dsos__fprintf(FILE *fp) | ||
993 | { | ||
994 | struct dso *pos; | ||
995 | |||
996 | list_for_each_entry(pos, &dsos, node) | ||
997 | dso__fprintf(pos, fp); | ||
998 | } | ||
999 | |||
1000 | static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip) | ||
1001 | { | ||
1002 | return dso__find_symbol(dso, ip); | ||
1003 | } | ||
1004 | |||
1005 | int load_kernel(void) | ||
1006 | { | ||
1007 | int err; | ||
1008 | |||
1009 | kernel_dso = dso__new("[kernel]", 0); | ||
1010 | if (!kernel_dso) | ||
1011 | return -1; | ||
1012 | |||
1013 | err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, modules); | ||
1014 | if (err <= 0) { | ||
1015 | dso__delete(kernel_dso); | ||
1016 | kernel_dso = NULL; | ||
1017 | } else | ||
1018 | dsos__add(kernel_dso); | ||
1019 | |||
1020 | vdso = dso__new("[vdso]", 0); | ||
1021 | if (!vdso) | ||
1022 | return -1; | ||
1023 | |||
1024 | vdso->find_symbol = vdso__find_symbol; | ||
1025 | |||
1026 | dsos__add(vdso); | ||
1027 | |||
1028 | hypervisor_dso = dso__new("[hypervisor]", 0); | ||
1029 | if (!hypervisor_dso) | ||
1030 | return -1; | ||
1031 | dsos__add(hypervisor_dso); | ||
1032 | |||
1033 | return err; | ||
1034 | } | ||
1035 | |||
1036 | |||
940 | void symbol__init(void) | 1037 | void symbol__init(void) |
941 | { | 1038 | { |
942 | elf_version(EV_CURRENT); | 1039 | elf_version(EV_CURRENT); |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 1e003ec2f4b1..f3490fcd40ee 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -48,9 +48,20 @@ int dso__load_kernel(struct dso *self, const char *vmlinux, | |||
48 | symbol_filter_t filter, int verbose, int modules); | 48 | symbol_filter_t filter, int verbose, int modules); |
49 | int dso__load_modules(struct dso *self, symbol_filter_t filter, int verbose); | 49 | int dso__load_modules(struct dso *self, symbol_filter_t filter, int verbose); |
50 | int dso__load(struct dso *self, symbol_filter_t filter, int verbose); | 50 | int dso__load(struct dso *self, symbol_filter_t filter, int verbose); |
51 | struct dso *dsos__findnew(const char *name); | ||
52 | void dsos__fprintf(FILE *fp); | ||
51 | 53 | ||
52 | size_t dso__fprintf(struct dso *self, FILE *fp); | 54 | size_t dso__fprintf(struct dso *self, FILE *fp); |
53 | char dso__symtab_origin(const struct dso *self); | 55 | char dso__symtab_origin(const struct dso *self); |
54 | 56 | ||
57 | int load_kernel(void); | ||
58 | |||
55 | void symbol__init(void); | 59 | void symbol__init(void); |
60 | |||
61 | extern struct list_head dsos; | ||
62 | extern struct dso *kernel_dso; | ||
63 | extern struct dso *vdso; | ||
64 | extern struct dso *hypervisor_dso; | ||
65 | extern char *vmlinux; | ||
66 | extern int modules; | ||
56 | #endif /* _PERF_SYMBOL_ */ | 67 | #endif /* _PERF_SYMBOL_ */ |