aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/annotate.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-04-02 11:59:01 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-04-07 15:09:05 -0400
commit058b4cc9af574c072988a38a7a5ee93df881e5aa (patch)
treeb43317d17d667aa54b20e0b363f1d2fb288e07e7 /tools/perf/util/annotate.c
parent087091652bf8b351432a3f3fb50996ee3582d5e4 (diff)
perf annotate: Allow printing objdump line addr in different color
And by default use "magenta" for it. Both the --stdio and --tui routines follow the same semantics. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-ede5zkaf7oorwvbqjezb4yg4@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.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 08c6d138a655..9fc4126e54db 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -84,10 +84,15 @@ static struct objdump_line *objdump_line__new(s64 offset, char *line, size_t pri
84 84
85 if (self != NULL) { 85 if (self != NULL) {
86 self->offset = offset; 86 self->offset = offset;
87 self->line = line; 87 self->line = strdup(line);
88 if (self->line == NULL)
89 goto out_delete;
88 } 90 }
89 91
90 return self; 92 return self;
93out_delete:
94 free(self);
95 return NULL;
91} 96}
92 97
93void objdump_line__free(struct objdump_line *self) 98void objdump_line__free(struct objdump_line *self)
@@ -112,7 +117,7 @@ struct objdump_line *objdump__get_next_ip_line(struct list_head *head,
112} 117}
113 118
114static int objdump_line__print(struct objdump_line *oline, struct symbol *sym, 119static int objdump_line__print(struct objdump_line *oline, struct symbol *sym,
115 int evidx, u64 len, int min_pcnt, 120 u64 start, int evidx, u64 len, int min_pcnt,
116 int printed, int max_lines, 121 int printed, int max_lines,
117 struct objdump_line *queue) 122 struct objdump_line *queue)
118{ 123{
@@ -128,6 +133,7 @@ static int objdump_line__print(struct objdump_line *oline, struct symbol *sym,
128 struct source_line *src_line = notes->src->lines; 133 struct source_line *src_line = notes->src->lines;
129 struct sym_hist *h = annotation__histogram(notes, evidx); 134 struct sym_hist *h = annotation__histogram(notes, evidx);
130 s64 offset = oline->offset; 135 s64 offset = oline->offset;
136 const u64 addr = start + offset;
131 struct objdump_line *next; 137 struct objdump_line *next;
132 138
133 next = objdump__get_next_ip_line(&notes->src->source, oline); 139 next = objdump__get_next_ip_line(&notes->src->source, oline);
@@ -157,7 +163,7 @@ static int objdump_line__print(struct objdump_line *oline, struct symbol *sym,
157 list_for_each_entry_from(queue, &notes->src->source, node) { 163 list_for_each_entry_from(queue, &notes->src->source, node) {
158 if (queue == oline) 164 if (queue == oline)
159 break; 165 break;
160 objdump_line__print(queue, sym, evidx, len, 166 objdump_line__print(queue, sym, start, evidx, len,
161 0, 0, 1, NULL); 167 0, 0, 1, NULL);
162 } 168 }
163 } 169 }
@@ -180,6 +186,7 @@ static int objdump_line__print(struct objdump_line *oline, struct symbol *sym,
180 186
181 color_fprintf(stdout, color, " %7.2f", percent); 187 color_fprintf(stdout, color, " %7.2f", percent);
182 printf(" : "); 188 printf(" : ");
189 color_fprintf(stdout, PERF_COLOR_MAGENTA, " %" PRIx64 ":", addr);
183 color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", oline->line); 190 color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", oline->line);
184 } else if (max_lines && printed >= max_lines) 191 } else if (max_lines && printed >= max_lines)
185 return 1; 192 return 1;
@@ -201,7 +208,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
201{ 208{
202 struct annotation *notes = symbol__annotation(sym); 209 struct annotation *notes = symbol__annotation(sym);
203 struct objdump_line *objdump_line; 210 struct objdump_line *objdump_line;
204 char *line = NULL, *tmp, *tmp2, *c; 211 char *line = NULL, *parsed_line, *tmp, *tmp2, *c;
205 size_t line_len; 212 size_t line_len;
206 s64 line_ip, offset = -1; 213 s64 line_ip, offset = -1;
207 214
@@ -246,13 +253,17 @@ static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
246 offset = line_ip - start; 253 offset = line_ip - start;
247 if (offset < 0 || (u64)line_ip > end) 254 if (offset < 0 || (u64)line_ip > end)
248 offset = -1; 255 offset = -1;
249 } 256 else
257 parsed_line = tmp2 + 1;
258 } else
259 parsed_line = line;
250 260
251 objdump_line = objdump_line__new(offset, line, privsize); 261 objdump_line = objdump_line__new(offset, parsed_line, privsize);
252 if (objdump_line == NULL) { 262 free(line);
253 free(line); 263
264 if (objdump_line == NULL)
254 return -1; 265 return -1;
255 } 266
256 objdump__add_line(&notes->src->source, objdump_line); 267 objdump__add_line(&notes->src->source, objdump_line);
257 268
258 return 0; 269 return 0;
@@ -493,6 +504,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,
493 const char *filename = dso->long_name, *d_filename; 504 const char *filename = dso->long_name, *d_filename;
494 struct annotation *notes = symbol__annotation(sym); 505 struct annotation *notes = symbol__annotation(sym);
495 struct objdump_line *pos, *queue = NULL; 506 struct objdump_line *pos, *queue = NULL;
507 u64 start = map__rip_2objdump(map, sym->start);
496 int printed = 2, queue_len = 0; 508 int printed = 2, queue_len = 0;
497 int more = 0; 509 int more = 0;
498 u64 len; 510 u64 len;
@@ -516,8 +528,9 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,
516 queue_len = 0; 528 queue_len = 0;
517 } 529 }
518 530
519 switch (objdump_line__print(pos, sym, evidx, len, min_pcnt, 531 switch (objdump_line__print(pos, sym, start, evidx, len,
520 printed, max_lines, queue)) { 532 min_pcnt, printed, max_lines,
533 queue)) {
521 case 0: 534 case 0:
522 ++printed; 535 ++printed;
523 if (context) { 536 if (context) {