aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/annotate.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2017-10-11 11:01:40 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-11-16 12:37:49 -0500
commit073ae601edc211383b62618effaaedaa8b1d22db (patch)
tree2a4187da8332b9fb549bf5b927a3f7ddd6f286b6 /tools/perf/util/annotate.c
parent7e304557ead5b309d59807b2f05ed47f2c0076c6 (diff)
perf annotate: Add symbol__calc_percent function
Add symbol__calc_percent function, that calculates annotation data for symbol and put the data in the struct annotation_line::samples array. Committer notes: Made symbol__calc_percent non static to be used in the next two patches, which will get some fixups from jolsa, doing it this way to keep this bisectable. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Andi Kleen <andi@firstfloor.org> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20171011150158.11895-18-jolsa@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.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 313fb2e90dba..ff1036096347 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1628,6 +1628,62 @@ out_close_stdout:
1628 goto out_remove_tmp; 1628 goto out_remove_tmp;
1629} 1629}
1630 1630
1631static void calc_percent(struct sym_hist *hist,
1632 struct annotation_data *sample,
1633 s64 offset, s64 end)
1634{
1635 unsigned int hits = 0;
1636 u64 period = 0;
1637
1638 while (offset < end) {
1639 hits += hist->addr[offset].nr_samples;
1640 period += hist->addr[offset].period;
1641 ++offset;
1642 }
1643
1644 if (hist->nr_samples) {
1645 sample->he.period = period;
1646 sample->he.nr_samples = hits;
1647 sample->percent = 100.0 * hits / hist->nr_samples;
1648 }
1649}
1650
1651static int annotation__calc_percent(struct annotation *notes,
1652 struct perf_evsel *evsel, s64 len)
1653{
1654 struct annotation_line *al, *next;
1655
1656 list_for_each_entry(al, &notes->src->source, node) {
1657 s64 end;
1658 int i;
1659
1660 if (al->offset == -1)
1661 continue;
1662
1663 next = annotation_line__next(al, &notes->src->source);
1664 end = next ? next->offset : len;
1665
1666 for (i = 0; i < al->samples_nr; i++) {
1667 struct annotation_data *sample;
1668 struct sym_hist *hist;
1669
1670 hist = annotation__histogram(notes, evsel->idx + i);
1671 sample = &al->samples[i];
1672
1673 calc_percent(hist, sample, al->offset, end);
1674 }
1675 }
1676
1677 return 0;
1678}
1679
1680int symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel)
1681{
1682 struct annotation *notes = symbol__annotation(sym);
1683
1684 return annotation__calc_percent(notes, evsel, symbol__size(sym));
1685}
1686
1631int symbol__annotate(struct symbol *sym, struct map *map, 1687int symbol__annotate(struct symbol *sym, struct map *map,
1632 struct perf_evsel *evsel, size_t privsize, 1688 struct perf_evsel *evsel, size_t privsize,
1633 struct arch **parch, char *cpuid) 1689 struct arch **parch, char *cpuid)
@@ -1663,7 +1719,11 @@ int symbol__annotate(struct symbol *sym, struct map *map,
1663 } 1719 }
1664 } 1720 }
1665 1721
1666 return symbol__disassemble(sym, &args); 1722 err = symbol__disassemble(sym, &args);
1723 if (err)
1724 return err;
1725
1726 return symbol__calc_percent(sym, evsel);
1667} 1727}
1668 1728
1669static void insert_source_line(struct rb_root *root, struct source_line *src_line) 1729static void insert_source_line(struct rb_root *root, struct source_line *src_line)