From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>,
Andi Kleen <andi@firstfloor.org>, David Ahern <dsahern@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Stephane Eranian <eranian@google.com>,
Wang Nan <wangnan0@huawei.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 13/19] perf tools: Recalc total periods using top-level entries in hierarchy
Date: Thu, 10 Mar 2016 18:04:34 -0300 [thread overview]
Message-ID: <1457643880-4908-14-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1457643880-4908-1-git-send-email-acme@kernel.org>
From: Namhyung Kim <namhyung@kernel.org>
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>
---
tools/perf/util/hist.c | 44 ++++++++++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 10 deletions(-)
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index a98f9345f686..290b3cbf6877 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1453,6 +1453,31 @@ void hists__inc_stats(struct hists *hists, struct hist_entry *h)
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)
{
@@ -1518,11 +1543,6 @@ static void hists__hierarchy_output_resort(struct hists *hists,
continue;
}
- /* 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;
@@ -1602,11 +1622,13 @@ static void output_resort(struct hists *hists, struct ui_progress *prog,
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)
@@ -1927,6 +1949,8 @@ static void hists__filter_hierarchy(struct hists *hists, int type, const void *a
}
}
+ 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.
--
2.5.0
next prev parent reply other threads:[~2016-03-10 21:05 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-10 21:04 [GIT PULL 00/19] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 01/19] perf jitdump: DWARF is also needed Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 02/19] perf tools: Fix perf script python database export crash Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 03/19] perf tools: Pass perf_hpp_list all the way through setup_sort_list Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 04/19] perf tools: Omit unnecessary cast in perf_pmu__parse_scale Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 05/19] tools lib traceevent: Add '~' operation within arg_num_eval() Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 06/19] perf jitdump: Build only on supported archs Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 07/19] perf tools: Fix hist_entry__filter() for hierarchy Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 08/19] perf tools: Add more sort entry check functions Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 09/19] perf tools: Fix command line filters in hierarchy mode Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 10/19] perf tools: Remove hist_entry->fmt field Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 11/19] perf hists browser: Cleanup hist_browser__fprintf_hierarchy_entry() Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 12/19] perf tools: Remove nr_sort_keys field Arnaldo Carvalho de Melo
2016-03-10 21:04 ` Arnaldo Carvalho de Melo [this message]
2016-03-10 21:04 ` [PATCH 14/19] perf tools: Add sort__has_comm variable Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 15/19] perf hists browser: Allow thread filtering for comm sort key Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 16/19] perf hists browser: Check sort keys before hot key actions Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 17/19] perf stat: Document CSV format in manpage Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 18/19] perf stat: Implement --metric-only mode Arnaldo Carvalho de Melo
2016-03-10 21:04 ` [PATCH 19/19] perf stat: Add --metric-only support for -A Arnaldo Carvalho de Melo
2016-03-11 8:43 ` [GIT PULL 00/19] perf/core improvements and fixes Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457643880-4908-14-git-send-email-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=andi@firstfloor.org \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=wangnan0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).