diff options
author | Irina Tirdea <irina.tirdea@intel.com> | 2012-10-15 19:33:38 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-10-24 12:20:11 -0400 |
commit | 68e94f4eb56d92ccb617a98fcac5e575702ec4fd (patch) | |
tree | e032cf52fc4cc66c845a1985bd5c58706e869706 /tools | |
parent | feb8ada4ea5540ee986b23abd95597118729704c (diff) |
perf tools: Try to find cross-built objdump path
As we have architecture information of saved perf.data file, we can try
to find cross-built objdump path.
The triplets include support for Android (arm, x86 and mips
architectures).
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Originally-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1350344020-8071-5-git-send-email-irina.tirdea@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/Makefile | 2 | ||||
-rw-r--r-- | tools/perf/arch/common.c | 178 | ||||
-rw-r--r-- | tools/perf/arch/common.h | 10 | ||||
-rw-r--r-- | tools/perf/builtin-annotate.c | 7 | ||||
-rw-r--r-- | tools/perf/builtin-report.c | 7 | ||||
-rw-r--r-- | tools/perf/util/annotate.h | 1 |
6 files changed, 204 insertions, 1 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 6790cb441a63..78a81eda1272 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -426,6 +426,8 @@ LIB_OBJS += $(OUTPUT)ui/helpline.o | |||
426 | LIB_OBJS += $(OUTPUT)ui/hist.o | 426 | LIB_OBJS += $(OUTPUT)ui/hist.o |
427 | LIB_OBJS += $(OUTPUT)ui/stdio/hist.o | 427 | LIB_OBJS += $(OUTPUT)ui/stdio/hist.o |
428 | 428 | ||
429 | LIB_OBJS += $(OUTPUT)arch/common.o | ||
430 | |||
429 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o | 431 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o |
430 | BUILTIN_OBJS += $(OUTPUT)builtin-bench.o | 432 | BUILTIN_OBJS += $(OUTPUT)builtin-bench.o |
431 | # Benchmark modules | 433 | # Benchmark modules |
diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c new file mode 100644 index 000000000000..2367b253f039 --- /dev/null +++ b/tools/perf/arch/common.c | |||
@@ -0,0 +1,178 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <sys/utsname.h> | ||
3 | #include "common.h" | ||
4 | #include "../util/debug.h" | ||
5 | |||
6 | const char *const arm_triplets[] = { | ||
7 | "arm-eabi-", | ||
8 | "arm-linux-androideabi-", | ||
9 | "arm-unknown-linux-", | ||
10 | "arm-unknown-linux-gnu-", | ||
11 | "arm-unknown-linux-gnueabi-", | ||
12 | NULL | ||
13 | }; | ||
14 | |||
15 | const char *const powerpc_triplets[] = { | ||
16 | "powerpc-unknown-linux-gnu-", | ||
17 | "powerpc64-unknown-linux-gnu-", | ||
18 | NULL | ||
19 | }; | ||
20 | |||
21 | const char *const s390_triplets[] = { | ||
22 | "s390-ibm-linux-", | ||
23 | NULL | ||
24 | }; | ||
25 | |||
26 | const char *const sh_triplets[] = { | ||
27 | "sh-unknown-linux-gnu-", | ||
28 | "sh64-unknown-linux-gnu-", | ||
29 | NULL | ||
30 | }; | ||
31 | |||
32 | const char *const sparc_triplets[] = { | ||
33 | "sparc-unknown-linux-gnu-", | ||
34 | "sparc64-unknown-linux-gnu-", | ||
35 | NULL | ||
36 | }; | ||
37 | |||
38 | const char *const x86_triplets[] = { | ||
39 | "x86_64-pc-linux-gnu-", | ||
40 | "x86_64-unknown-linux-gnu-", | ||
41 | "i686-pc-linux-gnu-", | ||
42 | "i586-pc-linux-gnu-", | ||
43 | "i486-pc-linux-gnu-", | ||
44 | "i386-pc-linux-gnu-", | ||
45 | "i686-linux-android-", | ||
46 | "i686-android-linux-", | ||
47 | NULL | ||
48 | }; | ||
49 | |||
50 | const char *const mips_triplets[] = { | ||
51 | "mips-unknown-linux-gnu-", | ||
52 | "mipsel-linux-android-", | ||
53 | NULL | ||
54 | }; | ||
55 | |||
56 | static bool lookup_path(char *name) | ||
57 | { | ||
58 | bool found = false; | ||
59 | char *path, *tmp; | ||
60 | char buf[PATH_MAX]; | ||
61 | char *env = getenv("PATH"); | ||
62 | |||
63 | if (!env) | ||
64 | return false; | ||
65 | |||
66 | env = strdup(env); | ||
67 | if (!env) | ||
68 | return false; | ||
69 | |||
70 | path = strtok_r(env, ":", &tmp); | ||
71 | while (path) { | ||
72 | scnprintf(buf, sizeof(buf), "%s/%s", path, name); | ||
73 | if (access(buf, F_OK) == 0) { | ||
74 | found = true; | ||
75 | break; | ||
76 | } | ||
77 | path = strtok_r(NULL, ":", &tmp); | ||
78 | } | ||
79 | free(env); | ||
80 | return found; | ||
81 | } | ||
82 | |||
83 | static int lookup_triplets(const char *const *triplets, const char *name) | ||
84 | { | ||
85 | int i; | ||
86 | char buf[PATH_MAX]; | ||
87 | |||
88 | for (i = 0; triplets[i] != NULL; i++) { | ||
89 | scnprintf(buf, sizeof(buf), "%s%s", triplets[i], name); | ||
90 | if (lookup_path(buf)) | ||
91 | return i; | ||
92 | } | ||
93 | return -1; | ||
94 | } | ||
95 | |||
96 | static int perf_session_env__lookup_binutils_path(struct perf_session_env *env, | ||
97 | const char *name, | ||
98 | const char **path) | ||
99 | { | ||
100 | int idx; | ||
101 | char *arch, *cross_env; | ||
102 | struct utsname uts; | ||
103 | const char *const *path_list; | ||
104 | char *buf = NULL; | ||
105 | |||
106 | if (uname(&uts) < 0) | ||
107 | goto out; | ||
108 | |||
109 | /* | ||
110 | * We don't need to try to find objdump path for native system. | ||
111 | * Just use default binutils path (e.g.: "objdump"). | ||
112 | */ | ||
113 | if (!strcmp(uts.machine, env->arch)) | ||
114 | goto out; | ||
115 | |||
116 | cross_env = getenv("CROSS_COMPILE"); | ||
117 | if (cross_env) { | ||
118 | if (asprintf(&buf, "%s%s", cross_env, name) < 0) | ||
119 | goto out_error; | ||
120 | if (buf[0] == '/') { | ||
121 | if (access(buf, F_OK) == 0) | ||
122 | goto out; | ||
123 | goto out_error; | ||
124 | } | ||
125 | if (lookup_path(buf)) | ||
126 | goto out; | ||
127 | free(buf); | ||
128 | } | ||
129 | |||
130 | arch = env->arch; | ||
131 | |||
132 | if (!strcmp(arch, "arm")) | ||
133 | path_list = arm_triplets; | ||
134 | else if (!strcmp(arch, "powerpc")) | ||
135 | path_list = powerpc_triplets; | ||
136 | else if (!strcmp(arch, "sh")) | ||
137 | path_list = sh_triplets; | ||
138 | else if (!strcmp(arch, "s390")) | ||
139 | path_list = s390_triplets; | ||
140 | else if (!strcmp(arch, "sparc")) | ||
141 | path_list = sparc_triplets; | ||
142 | else if (!strcmp(arch, "x86") || !strcmp(arch, "i386") || | ||
143 | !strcmp(arch, "i486") || !strcmp(arch, "i586") || | ||
144 | !strcmp(arch, "i686")) | ||
145 | path_list = x86_triplets; | ||
146 | else if (!strcmp(arch, "mips")) | ||
147 | path_list = mips_triplets; | ||
148 | else { | ||
149 | ui__error("binutils for %s not supported.\n", arch); | ||
150 | goto out_error; | ||
151 | } | ||
152 | |||
153 | idx = lookup_triplets(path_list, name); | ||
154 | if (idx < 0) { | ||
155 | ui__error("Please install %s for %s.\n" | ||
156 | "You can add it to PATH, set CROSS_COMPILE or " | ||
157 | "override the default using --%s.\n", | ||
158 | name, arch, name); | ||
159 | goto out_error; | ||
160 | } | ||
161 | |||
162 | if (asprintf(&buf, "%s%s", path_list[idx], name) < 0) | ||
163 | goto out_error; | ||
164 | |||
165 | out: | ||
166 | *path = buf; | ||
167 | return 0; | ||
168 | out_error: | ||
169 | free(buf); | ||
170 | *path = NULL; | ||
171 | return -1; | ||
172 | } | ||
173 | |||
174 | int perf_session_env__lookup_objdump(struct perf_session_env *env) | ||
175 | { | ||
176 | return perf_session_env__lookup_binutils_path(env, "objdump", | ||
177 | &objdump_path); | ||
178 | } | ||
diff --git a/tools/perf/arch/common.h b/tools/perf/arch/common.h new file mode 100644 index 000000000000..ede246eda9be --- /dev/null +++ b/tools/perf/arch/common.h | |||
@@ -0,0 +1,10 @@ | |||
1 | #ifndef ARCH_PERF_COMMON_H | ||
2 | #define ARCH_PERF_COMMON_H | ||
3 | |||
4 | #include "../util/session.h" | ||
5 | |||
6 | extern const char *objdump_path; | ||
7 | |||
8 | int perf_session_env__lookup_objdump(struct perf_session_env *env); | ||
9 | |||
10 | #endif /* ARCH_PERF_COMMON_H */ | ||
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 690fa9a54657..c4bb6457b19e 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "util/hist.h" | 28 | #include "util/hist.h" |
29 | #include "util/session.h" | 29 | #include "util/session.h" |
30 | #include "util/tool.h" | 30 | #include "util/tool.h" |
31 | #include "arch/common.h" | ||
31 | 32 | ||
32 | #include <linux/bitmap.h> | 33 | #include <linux/bitmap.h> |
33 | 34 | ||
@@ -186,6 +187,12 @@ static int __cmd_annotate(struct perf_annotate *ann) | |||
186 | goto out_delete; | 187 | goto out_delete; |
187 | } | 188 | } |
188 | 189 | ||
190 | if (!objdump_path) { | ||
191 | ret = perf_session_env__lookup_objdump(&session->header.env); | ||
192 | if (ret) | ||
193 | goto out_delete; | ||
194 | } | ||
195 | |||
189 | ret = perf_session__process_events(session, &ann->tool); | 196 | ret = perf_session__process_events(session, &ann->tool); |
190 | if (ret) | 197 | if (ret) |
191 | goto out_delete; | 198 | goto out_delete; |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 5104a40af563..90d1162bb8b8 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include "util/thread.h" | 33 | #include "util/thread.h" |
34 | #include "util/sort.h" | 34 | #include "util/sort.h" |
35 | #include "util/hist.h" | 35 | #include "util/hist.h" |
36 | #include "arch/common.h" | ||
36 | 37 | ||
37 | #include <linux/bitmap.h> | 38 | #include <linux/bitmap.h> |
38 | 39 | ||
@@ -672,6 +673,12 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) | |||
672 | has_br_stack = perf_header__has_feat(&session->header, | 673 | has_br_stack = perf_header__has_feat(&session->header, |
673 | HEADER_BRANCH_STACK); | 674 | HEADER_BRANCH_STACK); |
674 | 675 | ||
676 | if (!objdump_path) { | ||
677 | ret = perf_session_env__lookup_objdump(&session->header.env); | ||
678 | if (ret) | ||
679 | goto error; | ||
680 | } | ||
681 | |||
675 | if (sort__branch_mode == -1 && has_br_stack) | 682 | if (sort__branch_mode == -1 && has_br_stack) |
676 | sort__branch_mode = 1; | 683 | sort__branch_mode = 1; |
677 | 684 | ||
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 39242dcee8f2..a4dd25a61a07 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h | |||
@@ -154,6 +154,5 @@ static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused, | |||
154 | #endif | 154 | #endif |
155 | 155 | ||
156 | extern const char *disassembler_style; | 156 | extern const char *disassembler_style; |
157 | extern const char *objdump_path; | ||
158 | 157 | ||
159 | #endif /* __PERF_ANNOTATE_H */ | 158 | #endif /* __PERF_ANNOTATE_H */ |