diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2013-09-11 01:09:28 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-10-09 14:59:39 -0400 |
commit | f048d548f803b57ee1dbf66702f398ba69657450 (patch) | |
tree | ce21648b7d6886588dbcee3a045d96d9972321b7 /tools/perf/util/annotate.c | |
parent | 909b143162de7af310d2a9351220030260ebe728 (diff) |
perf annotate: Factor out get/free_srcline()
Currently external addr2line tool is used for srcline sort key and
annotate with srcline info. Separate the common code to prepare
upcoming enhancements.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1378876173-13363-5-git-send-email-namhyung@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.c | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index c6fd1870f278..d48297d77e19 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -1070,7 +1070,7 @@ static void symbol__free_source_line(struct symbol *sym, int len) | |||
1070 | (sizeof(src_line->p) * (src_line->nr_pcnt - 1)); | 1070 | (sizeof(src_line->p) * (src_line->nr_pcnt - 1)); |
1071 | 1071 | ||
1072 | for (i = 0; i < len; i++) { | 1072 | for (i = 0; i < len; i++) { |
1073 | free(src_line->path); | 1073 | free_srcline(src_line->path); |
1074 | src_line = (void *)src_line + sizeof_src_line; | 1074 | src_line = (void *)src_line + sizeof_src_line; |
1075 | } | 1075 | } |
1076 | 1076 | ||
@@ -1087,7 +1087,6 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map, | |||
1087 | u64 start; | 1087 | u64 start; |
1088 | int i, k; | 1088 | int i, k; |
1089 | int evidx = evsel->idx; | 1089 | int evidx = evsel->idx; |
1090 | char cmd[PATH_MAX * 2]; | ||
1091 | struct source_line *src_line; | 1090 | struct source_line *src_line; |
1092 | struct annotation *notes = symbol__annotation(sym); | 1091 | struct annotation *notes = symbol__annotation(sym); |
1093 | struct sym_hist *h = annotation__histogram(notes, evidx); | 1092 | struct sym_hist *h = annotation__histogram(notes, evidx); |
@@ -1115,10 +1114,7 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map, | |||
1115 | start = map__rip_2objdump(map, sym->start); | 1114 | start = map__rip_2objdump(map, sym->start); |
1116 | 1115 | ||
1117 | for (i = 0; i < len; i++) { | 1116 | for (i = 0; i < len; i++) { |
1118 | char *path = NULL; | ||
1119 | size_t line_len; | ||
1120 | u64 offset; | 1117 | u64 offset; |
1121 | FILE *fp; | ||
1122 | double percent_max = 0.0; | 1118 | double percent_max = 0.0; |
1123 | 1119 | ||
1124 | src_line->nr_pcnt = nr_pcnt; | 1120 | src_line->nr_pcnt = nr_pcnt; |
@@ -1135,19 +1131,9 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map, | |||
1135 | goto next; | 1131 | goto next; |
1136 | 1132 | ||
1137 | offset = start + i; | 1133 | offset = start + i; |
1138 | sprintf(cmd, "addr2line -e %s %016" PRIx64, filename, offset); | 1134 | src_line->path = get_srcline(filename, offset); |
1139 | fp = popen(cmd, "r"); | ||
1140 | if (!fp) | ||
1141 | goto next; | ||
1142 | |||
1143 | if (getline(&path, &line_len, fp) < 0 || !line_len) | ||
1144 | goto next_close; | ||
1145 | |||
1146 | src_line->path = path; | ||
1147 | insert_source_line(&tmp_root, src_line); | 1135 | insert_source_line(&tmp_root, src_line); |
1148 | 1136 | ||
1149 | next_close: | ||
1150 | pclose(fp); | ||
1151 | next: | 1137 | next: |
1152 | src_line = (void *)src_line + sizeof_src_line; | 1138 | src_line = (void *)src_line + sizeof_src_line; |
1153 | } | 1139 | } |
@@ -1188,7 +1174,7 @@ static void print_summary(struct rb_root *root, const char *filename) | |||
1188 | 1174 | ||
1189 | path = src_line->path; | 1175 | path = src_line->path; |
1190 | color = get_percent_color(percent_max); | 1176 | color = get_percent_color(percent_max); |
1191 | color_fprintf(stdout, color, " %s", path); | 1177 | color_fprintf(stdout, color, " %s\n", path); |
1192 | 1178 | ||
1193 | node = rb_next(node); | 1179 | node = rb_next(node); |
1194 | } | 1180 | } |