Skip to content

Commit 28904f4

Browse files
Jin Yaoacmel
authored andcommitted
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>
1 parent fa79aa6 commit 28904f4

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

tools/perf/util/callchain.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,3 +1667,35 @@ bool callchain_cnode_matched(struct callchain_node *base_cnode,
16671667

16681668
return match;
16691669
}
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+
}

tools/perf/util/callchain.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct ip_callchain;
1313
struct map;
1414
struct perf_sample;
1515
struct thread;
16+
struct hists;
1617

1718
#define HELP_PAD "\t\t\t\t"
1819

@@ -302,4 +303,6 @@ void callchain_param_setup(u64 sample_type);
302303
bool callchain_cnode_matched(struct callchain_node *base_cnode,
303304
struct callchain_node *pair_cnode);
304305

306+
u64 callchain_total_hits(struct hists *hists);
307+
305308
#endif /* __PERF_CALLCHAIN_H */

tools/perf/util/stream.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ static void init_hot_callchain(struct hists *hists, struct evsel_streams *es)
121121
update_hot_callchain(he, es);
122122
next = rb_next(&he->rb_node);
123123
}
124+
125+
es->streams_hits = callchain_total_hits(hists);
124126
}
125127

126128
static int evlist__init_callchain_streams(struct evlist *evlist,

tools/perf/util/stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct evsel_streams {
1414
int nr_streams_max;
1515
int nr_streams;
1616
int evsel_idx;
17+
u64 streams_hits;
1718
};
1819

1920
struct evlist_streams {

0 commit comments

Comments
 (0)