aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2013-03-05 00:53:24 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-03-15 12:06:05 -0400
commitbd64fcb8805d8e4575f95f0df22f43b74418a4ec (patch)
treec209a8129cfca584037d44be58336c674ccecb26 /tools
parente5ccf9f45d8bff6bfeafa561d2238b0e4beb415e (diff)
perf annotate: Cleanup disasm__calc_percent()
The loop end condition is calculated from next disasm_line or the symbol size if it's the last disasm_line. But it doesn't need to be calculated at every iteration. Moving it out of the function can simplify code a bit. Also the src_line doesn't need to be checked in every time. 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-5-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/annotate.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index a91d7b186081..ae71325d3dc7 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -603,29 +603,28 @@ 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, 606static double disasm__calc_percent(struct annotation *notes, int evidx,
607 struct annotation *notes, int evidx, 607 s64 offset, s64 end, const char **path)
608 s64 offset, u64 len, const char **path)
609{ 608{
610 struct source_line *src_line = notes->src->lines; 609 struct source_line *src_line = notes->src->lines;
611 struct sym_hist *h = annotation__histogram(notes, evidx); 610 struct sym_hist *h = annotation__histogram(notes, evidx);
612 unsigned int hits = 0; 611 unsigned int hits = 0;
613 double percent = 0.0; 612 double percent = 0.0;
614 613
615 while (offset < (s64)len && 614 if (src_line) {
616 (next == NULL || offset < next->offset)) { 615 while (offset < end) {
617 if (src_line) {
618 if (*path == NULL) 616 if (*path == NULL)
619 *path = src_line[offset].path; 617 *path = src_line[offset].path;
620 percent += src_line[offset].percent;
621 } else
622 hits += h->addr[offset];
623 618
624 ++offset; 619 percent += src_line[offset++].percent;
625 } 620 }
621 } else {
622 while (offset < end)
623 hits += h->addr[offset++];
626 624
627 if (src_line == NULL && h->sum) 625 if (h->sum)
628 percent = 100.0 * hits / h->sum; 626 percent = 100.0 * hits / h->sum;
627 }
629 628
630 return percent; 629 return percent;
631} 630}
@@ -648,8 +647,9 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
648 647
649 next = disasm__get_next_ip_line(&notes->src->source, dl); 648 next = disasm__get_next_ip_line(&notes->src->source, dl);
650 649
651 percent = disasm__calc_percent(next, notes, evsel->idx, 650 percent = disasm__calc_percent(notes, evsel->idx, offset,
652 offset, len, &path); 651 next ? next->offset : (s64) len,
652 &path);
653 if (percent < min_pcnt) 653 if (percent < min_pcnt)
654 return -1; 654 return -1;
655 655