mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Jiri Olsa <jolsa@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
	David Ahern <dsahern@gmail.com>,
	Stephane Eranian <eranian@google.com>,
	Andi Kleen <andi@firstfloor.org>, Wang Nan <wangnan0@huawei.com>
Subject: [PATCH 02/14] perf hists: Resort hist entries with hierarchy
Date: Tue, 26 Jan 2016 01:45:55 +0900	[thread overview]
Message-ID: <1453740367-10901-3-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1453740367-10901-1-git-send-email-namhyung@kernel.org>

For hierarchical output, each entries should be sorted in their
rbtree (hroot) properly.  Add hists__hierarchy_output_resort() to do the
job.  Note that those hierarchy entries share the period counts, it'd be
important to update the hists->stats only once (for leaves).

Acked-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/hist.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 79 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 9b6c68515a51..e9a66b093eaa 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1255,6 +1255,74 @@ void hists__inc_stats(struct hists *hists, struct hist_entry *h)
 	hists->stats.total_period += h->stat.period;
 }
 
+static void hierarchy_insert_output_entry(struct rb_root *root,
+					  struct hist_entry *he)
+{
+	struct rb_node **p = &root->rb_node;
+	struct rb_node *parent = NULL;
+	struct hist_entry *iter;
+
+	while (*p != NULL) {
+		parent = *p;
+		iter = rb_entry(parent, struct hist_entry, rb_node);
+
+		if (hist_entry__sort(he, iter) > 0)
+			p = &parent->rb_left;
+		else
+			p = &parent->rb_right;
+	}
+
+	rb_link_node(&he->rb_node, parent, p);
+	rb_insert_color(&he->rb_node, root);
+}
+
+static void hists__hierarchy_output_resort(struct hists *hists,
+					   struct ui_progress *prog,
+					   struct rb_root *root_in,
+					   struct rb_root *root_out,
+					   u64 min_callchain_hits,
+					   bool use_callchain)
+{
+	struct rb_node *node;
+	struct hist_entry *he;
+
+	*root_out = RB_ROOT;
+	node = rb_first(root_in);
+
+	while (node) {
+		he = rb_entry(node, struct hist_entry, rb_node_in);
+		node = rb_next(node);
+
+		hierarchy_insert_output_entry(root_out, he);
+
+		if (prog)
+			ui_progress__update(prog, 1);
+
+		if (!he->leaf) {
+			hists__hierarchy_output_resort(hists, prog,
+						       &he->hroot_in,
+						       &he->hroot_out,
+						       min_callchain_hits,
+						       use_callchain);
+			hists->nr_entries++;
+			if (!he->filtered)
+				hists->nr_non_filtered_entries++;
+
+			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)
+			callchain_param.sort(&he->sorted_chain, he->callchain,
+					     min_callchain_hits,
+					     &callchain_param);
+	}
+}
+
 static void __hists__insert_output_entry(struct rb_root *entries,
 					 struct hist_entry *he,
 					 u64 min_callchain_hits,
@@ -1298,6 +1366,17 @@ void hists__output_resort(struct hists *hists, struct ui_progress *prog)
 
 	min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100);
 
+	hists__reset_stats(hists);
+	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);
+	}
+
 	if (sort__need_collapse)
 		root = &hists->entries_collapsed;
 	else
@@ -1306,9 +1385,6 @@ void hists__output_resort(struct hists *hists, struct ui_progress *prog)
 	next = rb_first(root);
 	hists->entries = RB_ROOT;
 
-	hists__reset_stats(hists);
-	hists__reset_col_len(hists);
-
 	while (next) {
 		n = rb_entry(next, struct hist_entry, rb_node_in);
 		next = rb_next(&n->rb_node_in);
-- 
2.6.4

  parent reply	other threads:[~2016-01-25 16:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-25 16:45 [PATCHSET 00/14] perf tools: Add support for hierachy view (v3) Namhyung Kim
2016-01-25 16:45 ` [PATCH 01/14] perf hists: Basic support of hierarchical report view Namhyung Kim
2016-01-25 16:45 ` Namhyung Kim [this message]
2016-01-25 16:45 ` [PATCH 03/14] perf hists: Add helper functions for hierarchy mode Namhyung Kim
2016-01-25 16:45 ` [PATCH 04/14] perf hists: Support filtering in " Namhyung Kim
2016-01-25 16:45 ` [PATCH 05/14] perf ui/stdio: Implement hierarchy output mode Namhyung Kim
2016-01-25 16:45 ` [PATCH 06/14] perf ui/stdio: Align column header for hierarchy output Namhyung Kim
2016-01-25 16:46 ` [PATCH 07/14] perf hists browser: Count number of hierarchy entries Namhyung Kim
2016-01-25 16:46 ` [PATCH 08/14] perf hists browser: Support collapsing/expanding whole entries in hierarchy Namhyung Kim
2016-01-25 16:46 ` [PATCH 09/14] perf hists browser: Implement hierarchy output Namhyung Kim
2016-01-25 16:46 ` [PATCH 10/14] perf hists browser: Align column header in hierarchy mode Namhyung Kim
2016-01-25 16:46 ` [PATCH 11/14] perf ui/gtk: Implement hierarchy output mode Namhyung Kim
2016-01-25 16:46 ` [PATCH 12/14] perf report: Add --hierarchy option Namhyung Kim
2016-01-25 16:46 ` [PATCH 13/14] perf hists: Support decaying in hierarchy mode Namhyung Kim
2016-01-25 16:46 ` [PATCH 14/14] perf top: Add --hierarchy option Namhyung Kim

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=1453740367-10901-3-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=andi@firstfloor.org \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@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

all inboxes | Powered by JetHome®