diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2013-03-05 00:53:23 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-03-15 12:06:04 -0400 |
commit | e5ccf9f45d8bff6bfeafa561d2238b0e4beb415e (patch) | |
tree | 7c08a9eb1014a8ab56abd30ceecccc2de935772c /tools/perf/util | |
parent | 3aec150af3de6c00570bdacf45bf5a999ab9cf1d (diff) |
perf annotate: Factor out disasm__calc_percent()
Factor out calculation of histogram of a symbol into
disasm__calc_percent. It'll be used for later changes.
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: 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-4-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/annotate.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index fa347b169e27..a91d7b186081 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -603,6 +603,33 @@ 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 disasm_line *next, | ||
607 | struct annotation *notes, int evidx, | ||
608 | s64 offset, u64 len, const char **path) | ||
609 | { | ||
610 | struct source_line *src_line = notes->src->lines; | ||
611 | struct sym_hist *h = annotation__histogram(notes, evidx); | ||
612 | unsigned int hits = 0; | ||
613 | double percent = 0.0; | ||
614 | |||
615 | while (offset < (s64)len && | ||
616 | (next == NULL || offset < next->offset)) { | ||
617 | if (src_line) { | ||
618 | if (*path == NULL) | ||
619 | *path = src_line[offset].path; | ||
620 | percent += src_line[offset].percent; | ||
621 | } else | ||
622 | hits += h->addr[offset]; | ||
623 | |||
624 | ++offset; | ||
625 | } | ||
626 | |||
627 | if (src_line == NULL && h->sum) | ||
628 | percent = 100.0 * hits / h->sum; | ||
629 | |||
630 | return percent; | ||
631 | } | ||
632 | |||
606 | static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 start, | 633 | static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 start, |
607 | struct perf_evsel *evsel, u64 len, int min_pcnt, int printed, | 634 | struct perf_evsel *evsel, u64 len, int min_pcnt, int printed, |
608 | int max_lines, struct disasm_line *queue) | 635 | int max_lines, struct disasm_line *queue) |
@@ -612,33 +639,17 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st | |||
612 | 639 | ||
613 | if (dl->offset != -1) { | 640 | if (dl->offset != -1) { |
614 | const char *path = NULL; | 641 | const char *path = NULL; |
615 | unsigned int hits = 0; | 642 | double percent; |
616 | double percent = 0.0; | ||
617 | const char *color; | 643 | const char *color; |
618 | struct annotation *notes = symbol__annotation(sym); | 644 | struct annotation *notes = symbol__annotation(sym); |
619 | struct source_line *src_line = notes->src->lines; | ||
620 | struct sym_hist *h = annotation__histogram(notes, evsel->idx); | ||
621 | s64 offset = dl->offset; | 645 | s64 offset = dl->offset; |
622 | const u64 addr = start + offset; | 646 | const u64 addr = start + offset; |
623 | struct disasm_line *next; | 647 | struct disasm_line *next; |
624 | 648 | ||
625 | next = disasm__get_next_ip_line(¬es->src->source, dl); | 649 | next = disasm__get_next_ip_line(¬es->src->source, dl); |
626 | 650 | ||
627 | while (offset < (s64)len && | 651 | percent = disasm__calc_percent(next, notes, evsel->idx, |
628 | (next == NULL || offset < next->offset)) { | 652 | offset, len, &path); |
629 | if (src_line) { | ||
630 | if (path == NULL) | ||
631 | path = src_line[offset].path; | ||
632 | percent += src_line[offset].percent; | ||
633 | } else | ||
634 | hits += h->addr[offset]; | ||
635 | |||
636 | ++offset; | ||
637 | } | ||
638 | |||
639 | if (src_line == NULL && h->sum) | ||
640 | percent = 100.0 * hits / h->sum; | ||
641 | |||
642 | if (percent < min_pcnt) | 653 | if (percent < min_pcnt) |
643 | return -1; | 654 | return -1; |
644 | 655 | ||