aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/util/annotate.c49
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
606static 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
606static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 start, 633static 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(&notes->src->source, dl); 649 next = disasm__get_next_ip_line(&notes->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