When hierarchy mode is enabled, each entry in a hierarchy level shares
the period. IOW an upper level entry's period is the sum of lower level
entries. Thus perf uses only one of them to calculate the total period
of hists. It was lowest-level (leaf) entries but it has a problem when
it comes to filters.
If a filter is applied, entries in the same level will be filtered or
not. But upper level entries still have period of their sum including
filtered one. So total sum of upper level entries will not be same as
sum of lower level entries.
This resulted in entries having more than 100% of overhead and it can be
produced using perf top with filter(s).
Reported-and-Tested-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1457531222-18130-8-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
hists->stats.total_period += h->stat.period;
}
hists->stats.total_period += h->stat.period;
}
+static void hierarchy_recalc_total_periods(struct hists *hists)
+{
+ struct rb_node *node;
+ struct hist_entry *he;
+
+ node = rb_first(&hists->entries);
+
+ hists->stats.total_period = 0;
+ hists->stats.total_non_filtered_period = 0;
+
+ /*
+ * recalculate total period using top-level entries only
+ * since lower level entries only see non-filtered entries
+ * but upper level entries have sum of both entries.
+ */
+ while (node) {
+ he = rb_entry(node, struct hist_entry, rb_node);
+ node = rb_next(node);
+
+ hists->stats.total_period += he->stat.period;
+ if (!he->filtered)
+ hists->stats.total_non_filtered_period += he->stat.period;
+ }
+}
+
static void hierarchy_insert_output_entry(struct rb_root *root,
struct hist_entry *he)
{
static void hierarchy_insert_output_entry(struct rb_root *root,
struct hist_entry *he)
{
- /* only update stat for leaf entries to avoid duplication */
- hists__inc_stats(hists, he);
- if (!he->filtered)
- hists__calc_col_len(hists, he);
-
if (!use_callchain)
continue;
if (!use_callchain)
continue;
hists__reset_col_len(hists);
if (symbol_conf.report_hierarchy) {
hists__reset_col_len(hists);
if (symbol_conf.report_hierarchy) {
- return hists__hierarchy_output_resort(hists, prog,
- &hists->entries_collapsed,
- &hists->entries,
- min_callchain_hits,
- use_callchain);
+ hists__hierarchy_output_resort(hists, prog,
+ &hists->entries_collapsed,
+ &hists->entries,
+ min_callchain_hits,
+ use_callchain);
+ hierarchy_recalc_total_periods(hists);
+ return;
}
if (sort__need_collapse)
}
if (sort__need_collapse)
+ hierarchy_recalc_total_periods(hists);
+
/*
* resort output after applying a new filter since filter in a lower
* hierarchy can change periods in a upper hierarchy.
/*
* resort output after applying a new filter since filter in a lower
* hierarchy can change periods in a upper hierarchy.