Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf streams: Calculate the sum of total streams hits

We have used callchain_node->hit to measure the hot level of one stream.
This patch calculates the sum of hits of total streams.

Thus in next patch, we can use following formula to report hot percent
for one stream.

hot percent = callchain_node->hit / sum of total hits

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20201009022845.13141-6-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jin Yao and committed by
Arnaldo Carvalho de Melo
28904f4d fa79aa64

+38
+32
tools/perf/util/callchain.c
··· 1667 1667 1668 1668 return match; 1669 1669 } 1670 + 1671 + static u64 count_callchain_hits(struct hist_entry *he) 1672 + { 1673 + struct rb_root *root = &he->sorted_chain; 1674 + struct rb_node *rb_node = rb_first(root); 1675 + struct callchain_node *node; 1676 + u64 chain_hits = 0; 1677 + 1678 + while (rb_node) { 1679 + node = rb_entry(rb_node, struct callchain_node, rb_node); 1680 + chain_hits += node->hit; 1681 + rb_node = rb_next(rb_node); 1682 + } 1683 + 1684 + return chain_hits; 1685 + } 1686 + 1687 + u64 callchain_total_hits(struct hists *hists) 1688 + { 1689 + struct rb_node *next = rb_first_cached(&hists->entries); 1690 + u64 chain_hits = 0; 1691 + 1692 + while (next) { 1693 + struct hist_entry *he = rb_entry(next, struct hist_entry, 1694 + rb_node); 1695 + 1696 + chain_hits += count_callchain_hits(he); 1697 + next = rb_next(&he->rb_node); 1698 + } 1699 + 1700 + return chain_hits; 1701 + }
+3
tools/perf/util/callchain.h
··· 13 13 struct map; 14 14 struct perf_sample; 15 15 struct thread; 16 + struct hists; 16 17 17 18 #define HELP_PAD "\t\t\t\t" 18 19 ··· 302 301 303 302 bool callchain_cnode_matched(struct callchain_node *base_cnode, 304 303 struct callchain_node *pair_cnode); 304 + 305 + u64 callchain_total_hits(struct hists *hists); 305 306 306 307 #endif /* __PERF_CALLCHAIN_H */
+2
tools/perf/util/stream.c
··· 121 121 update_hot_callchain(he, es); 122 122 next = rb_next(&he->rb_node); 123 123 } 124 + 125 + es->streams_hits = callchain_total_hits(hists); 124 126 } 125 127 126 128 static int evlist__init_callchain_streams(struct evlist *evlist,
+1
tools/perf/util/stream.h
··· 14 14 int nr_streams_max; 15 15 int nr_streams; 16 16 int evsel_idx; 17 + u64 streams_hits; 17 18 }; 18 19 19 20 struct evlist_streams {