aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/annotate.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2016-08-09 14:16:37 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-08-23 14:37:33 -0400
commit3caee094d160b0ef92988099105e9a173a3805b0 (patch)
tree9c2156f70fa229e4a4787b5015eae45072368916 /tools/perf/util/annotate.c
parentc12944f7faa7f76441d83c1413f13e8bc70162b2 (diff)
perf disassemble: Simplify logic for picking the filename to disassemble
Lots of changes to support kcore, compressed modules, build-id files left us with some spaguetti code, simplify it a bit, more to come. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-h70p7x451li3f2fhs44vzmm8@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/annotate.c')
-rw-r--r--tools/perf/util/annotate.c41
1 files changed, 16 insertions, 25 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 9882bc6ac566..8a9949399112 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1166,7 +1166,6 @@ int symbol__disassemble(struct symbol *sym, struct map *map, size_t privsize)
1166{ 1166{
1167 struct dso *dso = map->dso; 1167 struct dso *dso = map->dso;
1168 char *filename; 1168 char *filename;
1169 bool free_filename = true;
1170 char command[PATH_MAX * 2]; 1169 char command[PATH_MAX * 2];
1171 FILE *file; 1170 FILE *file;
1172 char symfs_filename[PATH_MAX]; 1171 char symfs_filename[PATH_MAX];
@@ -1183,31 +1182,30 @@ int symbol__disassemble(struct symbol *sym, struct map *map, size_t privsize)
1183 goto out; 1182 goto out;
1184 1183
1185 filename = dso__build_id_filename(dso, NULL, 0); 1184 filename = dso__build_id_filename(dso, NULL, 0);
1186 if (filename) 1185 if (filename) {
1187 symbol__join_symfs(symfs_filename, filename); 1186 symbol__join_symfs(symfs_filename, filename);
1188 1187 free(filename);
1189 if (filename == NULL) { 1188 } else {
1190 if (dso->has_build_id) 1189 if (dso->has_build_id)
1191 return ENOMEM; 1190 return ENOMEM;
1192 goto fallback; 1191 goto fallback;
1193 } else if (dso__is_kcore(dso) || 1192 }
1194 readlink(symfs_filename, command, sizeof(command)) < 0 || 1193
1195 strstr(command, DSO__NAME_KALLSYMS) || 1194 if (dso__is_kcore(dso) ||
1196 access(symfs_filename, R_OK)) { 1195 readlink(symfs_filename, command, sizeof(command)) < 0 ||
1197 free(filename); 1196 strstr(command, DSO__NAME_KALLSYMS) ||
1197 access(symfs_filename, R_OK)) {
1198fallback: 1198fallback:
1199 /* 1199 /*
1200 * If we don't have build-ids or the build-id file isn't in the 1200 * If we don't have build-ids or the build-id file isn't in the
1201 * cache, or is just a kallsyms file, well, lets hope that this 1201 * cache, or is just a kallsyms file, well, lets hope that this
1202 * DSO is the same as when 'perf record' ran. 1202 * DSO is the same as when 'perf record' ran.
1203 */ 1203 */
1204 filename = (char *)dso->long_name; 1204 symbol__join_symfs(symfs_filename, dso->long_name);
1205 symbol__join_symfs(symfs_filename, filename);
1206 free_filename = false;
1207 } 1205 }
1208 1206
1209 pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__, 1207 pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
1210 filename, sym->name, map->unmap_ip(map, sym->start), 1208 symfs_filename, sym->name, map->unmap_ip(map, sym->start),
1211 map->unmap_ip(map, sym->end)); 1209 map->unmap_ip(map, sym->end));
1212 1210
1213 pr_debug("annotating [%p] %30s : [%p] %30s\n", 1211 pr_debug("annotating [%p] %30s : [%p] %30s\n",
@@ -1222,11 +1220,6 @@ fallback:
1222 delete_extract = true; 1220 delete_extract = true;
1223 strlcpy(symfs_filename, kce.extract_filename, 1221 strlcpy(symfs_filename, kce.extract_filename,
1224 sizeof(symfs_filename)); 1222 sizeof(symfs_filename));
1225 if (free_filename) {
1226 free(filename);
1227 free_filename = false;
1228 }
1229 filename = symfs_filename;
1230 } 1223 }
1231 } else if (dso__needs_decompress(dso)) { 1224 } else if (dso__needs_decompress(dso)) {
1232 char tmp[PATH_MAX]; 1225 char tmp[PATH_MAX];
@@ -1235,14 +1228,14 @@ fallback:
1235 bool ret; 1228 bool ret;
1236 1229
1237 if (kmod_path__parse_ext(&m, symfs_filename)) 1230 if (kmod_path__parse_ext(&m, symfs_filename))
1238 goto out_free_filename; 1231 goto out;
1239 1232
1240 snprintf(tmp, PATH_MAX, "/tmp/perf-kmod-XXXXXX"); 1233 snprintf(tmp, PATH_MAX, "/tmp/perf-kmod-XXXXXX");
1241 1234
1242 fd = mkstemp(tmp); 1235 fd = mkstemp(tmp);
1243 if (fd < 0) { 1236 if (fd < 0) {
1244 free(m.ext); 1237 free(m.ext);
1245 goto out_free_filename; 1238 goto out;
1246 } 1239 }
1247 1240
1248 ret = decompress_to_file(m.ext, symfs_filename, fd); 1241 ret = decompress_to_file(m.ext, symfs_filename, fd);
@@ -1254,7 +1247,7 @@ fallback:
1254 close(fd); 1247 close(fd);
1255 1248
1256 if (!ret) 1249 if (!ret)
1257 goto out_free_filename; 1250 goto out;
1258 1251
1259 strcpy(symfs_filename, tmp); 1252 strcpy(symfs_filename, tmp);
1260 } 1253 }
@@ -1270,7 +1263,7 @@ fallback:
1270 map__rip_2objdump(map, sym->end), 1263 map__rip_2objdump(map, sym->end),
1271 symbol_conf.annotate_asm_raw ? "" : "--no-show-raw", 1264 symbol_conf.annotate_asm_raw ? "" : "--no-show-raw",
1272 symbol_conf.annotate_src ? "-S" : "", 1265 symbol_conf.annotate_src ? "-S" : "",
1273 symfs_filename, filename); 1266 symfs_filename, symfs_filename);
1274 1267
1275 pr_debug("Executing: %s\n", command); 1268 pr_debug("Executing: %s\n", command);
1276 1269
@@ -1332,11 +1325,9 @@ out_remove_tmp:
1332 1325
1333 if (dso__needs_decompress(dso)) 1326 if (dso__needs_decompress(dso))
1334 unlink(symfs_filename); 1327 unlink(symfs_filename);
1335out_free_filename: 1328
1336 if (delete_extract) 1329 if (delete_extract)
1337 kcore_extract__delete(&kce); 1330 kcore_extract__delete(&kce);
1338 if (free_filename)
1339 free(filename);
1340out: 1331out:
1341 return err; 1332 return err;
1342 1333