diff options
author | Namhyung Kim <namhyung@kernel.org> | 2013-03-05 00:53:30 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-03-15 12:06:06 -0400 |
commit | e64aa75bf5559be3ce72e53ae28b76a2f633ca06 (patch) | |
tree | b53c653ae78ae7dd2f038bf39edfec9a84fe1dee | |
parent | ab77df672cdbf7a0235a9de3289c173e2fce68e5 (diff) |
perf annotate browser: Use disasm__calc_percent()
The disasm_line__calc_percent() which was used by annotate browser code
almost duplicates disasm__calc_percent. Let's get rid of the code
duplication.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
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>
Link: http://lkml.kernel.org/r/1362462812-30885-11-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/ui/browsers/annotate.c | 50 | ||||
-rw-r--r-- | tools/perf/util/annotate.c | 4 | ||||
-rw-r--r-- | tools/perf/util/annotate.h | 4 |
3 files changed, 20 insertions, 38 deletions
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 62369f0b6608..8b16926dd56e 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c | |||
@@ -240,40 +240,6 @@ static unsigned int annotate_browser__refresh(struct ui_browser *browser) | |||
240 | return ret; | 240 | return ret; |
241 | } | 241 | } |
242 | 242 | ||
243 | static double disasm_line__calc_percent(struct disasm_line *dl, struct symbol *sym, int evidx) | ||
244 | { | ||
245 | double percent = 0.0; | ||
246 | |||
247 | if (dl->offset != -1) { | ||
248 | int len = sym->end - sym->start; | ||
249 | unsigned int hits = 0; | ||
250 | struct annotation *notes = symbol__annotation(sym); | ||
251 | struct source_line *src_line = notes->src->lines; | ||
252 | struct sym_hist *h = annotation__histogram(notes, evidx); | ||
253 | s64 offset = dl->offset; | ||
254 | struct disasm_line *next; | ||
255 | |||
256 | next = disasm__get_next_ip_line(¬es->src->source, dl); | ||
257 | while (offset < (s64)len && | ||
258 | (next == NULL || offset < next->offset)) { | ||
259 | if (src_line) { | ||
260 | percent += src_line[offset].p[0].percent; | ||
261 | } else | ||
262 | hits += h->addr[offset]; | ||
263 | |||
264 | ++offset; | ||
265 | } | ||
266 | /* | ||
267 | * If the percentage wasn't already calculated in | ||
268 | * symbol__get_source_line, do it now: | ||
269 | */ | ||
270 | if (src_line == NULL && h->sum) | ||
271 | percent = 100.0 * hits / h->sum; | ||
272 | } | ||
273 | |||
274 | return percent; | ||
275 | } | ||
276 | |||
277 | static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_line *bdl) | 243 | static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_line *bdl) |
278 | { | 244 | { |
279 | struct rb_node **p = &root->rb_node; | 245 | struct rb_node **p = &root->rb_node; |
@@ -337,7 +303,8 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, | |||
337 | struct map_symbol *ms = browser->b.priv; | 303 | struct map_symbol *ms = browser->b.priv; |
338 | struct symbol *sym = ms->sym; | 304 | struct symbol *sym = ms->sym; |
339 | struct annotation *notes = symbol__annotation(sym); | 305 | struct annotation *notes = symbol__annotation(sym); |
340 | struct disasm_line *pos; | 306 | struct disasm_line *pos, *next; |
307 | s64 len = symbol__size(sym); | ||
341 | 308 | ||
342 | browser->entries = RB_ROOT; | 309 | browser->entries = RB_ROOT; |
343 | 310 | ||
@@ -345,7 +312,18 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, | |||
345 | 312 | ||
346 | list_for_each_entry(pos, ¬es->src->source, node) { | 313 | list_for_each_entry(pos, ¬es->src->source, node) { |
347 | struct browser_disasm_line *bpos = disasm_line__browser(pos); | 314 | struct browser_disasm_line *bpos = disasm_line__browser(pos); |
348 | bpos->percent[0] = disasm_line__calc_percent(pos, sym, evsel->idx); | 315 | const char *path = NULL; |
316 | |||
317 | if (pos->offset == -1) { | ||
318 | RB_CLEAR_NODE(&bpos->rb_node); | ||
319 | continue; | ||
320 | } | ||
321 | |||
322 | next = disasm__get_next_ip_line(¬es->src->source, pos); | ||
323 | bpos->percent[0] = disasm__calc_percent(notes, evsel->idx, | ||
324 | pos->offset, next ? next->offset : len, | ||
325 | &path); | ||
326 | |||
349 | if (bpos->percent[0] < 0.01) { | 327 | if (bpos->percent[0] < 0.01) { |
350 | RB_CLEAR_NODE(&bpos->rb_node); | 328 | RB_CLEAR_NODE(&bpos->rb_node); |
351 | continue; | 329 | continue; |
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 05e34df5d041..d102716c43a1 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -603,8 +603,8 @@ struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disa | |||
603 | return NULL; | 603 | return NULL; |
604 | } | 604 | } |
605 | 605 | ||
606 | static double disasm__calc_percent(struct annotation *notes, int evidx, | 606 | double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, |
607 | s64 offset, s64 end, const char **path) | 607 | s64 end, const char **path) |
608 | { | 608 | { |
609 | struct source_line *src_line = notes->src->lines; | 609 | struct source_line *src_line = notes->src->lines; |
610 | double percent = 0.0; | 610 | double percent = 0.0; |
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 68f851e6c685..6f3c16f01ab4 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h | |||
@@ -50,6 +50,8 @@ bool ins__is_jump(const struct ins *ins); | |||
50 | bool ins__is_call(const struct ins *ins); | 50 | bool ins__is_call(const struct ins *ins); |
51 | int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops); | 51 | int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops); |
52 | 52 | ||
53 | struct annotation; | ||
54 | |||
53 | struct disasm_line { | 55 | struct disasm_line { |
54 | struct list_head node; | 56 | struct list_head node; |
55 | s64 offset; | 57 | s64 offset; |
@@ -68,6 +70,8 @@ void disasm_line__free(struct disasm_line *dl); | |||
68 | struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos); | 70 | struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos); |
69 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); | 71 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); |
70 | size_t disasm__fprintf(struct list_head *head, FILE *fp); | 72 | size_t disasm__fprintf(struct list_head *head, FILE *fp); |
73 | double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, | ||
74 | s64 end, const char **path); | ||
71 | 75 | ||
72 | struct sym_hist { | 76 | struct sym_hist { |
73 | u64 sum; | 77 | u64 sum; |