Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1335432

[PATCH v6 18/25] perf hists browser: Count number of hierarchy entries

Path csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Namhyung Kim <namhyung@kernel.org>
Newsgroups linux.kernel
Subject [PATCH v6 18/25] perf hists browser: Count number of hierarchy entries
Date Tue, 16 Feb 2016 15:20:02 +0100
Message-ID <r2ODU-vy-29@gated-at.bofh.it> (permalink)
References <r2ODT-vy-3@gated-at.bofh.it>
X-Original-To Arnaldo Carvalho de Melo <acme@kernel.org>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=72HBRvoz75MG1zonxXvGddtNJSd2Pj8pNx3kOpikU8c=; b=B6QEEj7yNQq4ICJGSIhRwL4WQoj7Bin1MHa0rLOD+meDN+pdTEkHMv6BR0+oiRPXFa QowArgFrA/3vj4mePWlcLylvfGuKOeWI0H63OIu1KtSQZa1jyqw0qNh7UW8E4Qf0duqL P22g85q4j/8/ZLSRBxKab0oB6J1zIL6gLRupTxutiDYbxbHdkeGeonXaELFJoXc2+QnJ gRu+V8u0WJy8lloYTS2ldXO3KUsYB6QsAqXgJ0vnNqWbDwadjcH50fHIt7EHgvAPEVUZ Kl1NtAvi9d3jcdS15P1QmPEuOw2Sw6Xgm3KPqWflax6B8x3WAqevtsioHQBKhtEOEcc/ hvKQ==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=72HBRvoz75MG1zonxXvGddtNJSd2Pj8pNx3kOpikU8c=; b=Uj5jkBnpG1N8aBf1sj7JQUAKp5MEcSubHB1BvvuaGuqN78WaG9ZqIqNc4E6rycTn3t imIQkjAej/9mHxNkrQA5ROc/A0Xse5pXoe5DkPh5CHB8Xh9s0bBlYivb7i5u5J8/29QD wje7ZE8G/XQgh/C6r+RtDZdObGTMO9cPZ9KPwPKcriKjvfhC2Q7mDvJ1yAZLcrOoLBDN DOVAYoKCF2V7AN3+KTTYnGets3K2dWNtM7V5pRqxbh5Moexj7aNVxI8hBMjaJgy2TpPf uLD9th6hcIvSoF3aANkp9uQuOjjsLQZVZF8kQJ0NpLKTnkRDohFqtvDFQhb7BMXtIbQm vqbA==
X-Gm-Message-State AG10YORzGdsDkmFifjaulRHcDhBMJleVlmvWUGcjQ2dlAqkpGNsSwC4vllpDbSIHMdDs9g==
X-Received by 10.98.9.92 with SMTP id e89mr31440388pfd.34.1455631862529; Tue, 16 Feb 2016 06:11:02 -0800 (PST)
X-Mailer git-send-email 2.7.1
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 174
Organization linux.* mail to news gateway
X-Original-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>, Andi Kleen <andi@firstfloor.org>, Stephane Eranian <eranian@google.com>, Wang Nan <wangnan0@huawei.com>
X-Original-Date Tue, 16 Feb 2016 23:08:36 +0900
X-Original-Message-ID <1455631723-17345-19-git-send-email-namhyung@kernel.org>
X-Original-References <1455631723-17345-1-git-send-email-namhyung@kernel.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1335432

Show key headers only | View raw


Add nr_hierarchy_entries field to keep current number of (unfolded) hist
entries.  And the hist_entry->nr_rows carries number of direct children.
But in the hierarchy mode, entry can have grand children and callchains.
So update the number properly using hierarchy_count_rows() when toggling
the folded state (by pressing ENTER key).

Acked-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/ui/browsers/hists.c | 85 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 74 insertions(+), 11 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 1819771243f9..de1d6f0df8a7 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -32,6 +32,7 @@ struct hist_browser {
 	bool		     show_headers;
 	float		     min_pcnt;
 	u64		     nr_non_filtered_entries;
+	u64		     nr_hierarchy_entries;
 	u64		     nr_callchain_rows;
 };
 
@@ -58,11 +59,11 @@ static int hist_browser__get_folding(struct hist_browser *browser)
 
 	for (nd = rb_first(&hists->entries);
 	     (nd = hists__filter_entries(nd, browser->min_pcnt)) != NULL;
-	     nd = rb_next(nd)) {
+	     nd = rb_hierarchy_next(nd)) {
 		struct hist_entry *he =
 			rb_entry(nd, struct hist_entry, rb_node);
 
-		if (he->unfolded)
+		if (he->leaf && he->unfolded)
 			unfolded_rows += he->nr_rows;
 	}
 	return unfolded_rows;
@@ -72,7 +73,9 @@ static u32 hist_browser__nr_entries(struct hist_browser *hb)
 {
 	u32 nr_entries;
 
-	if (hist_browser__has_filter(hb))
+	if (symbol_conf.report_hierarchy)
+		nr_entries = hb->nr_hierarchy_entries;
+	else if (hist_browser__has_filter(hb))
 		nr_entries = hb->nr_non_filtered_entries;
 	else
 		nr_entries = hb->hists->nr_entries;
@@ -247,6 +250,35 @@ static int callchain__count_rows(struct rb_root *chain)
 	return n;
 }
 
+static int hierarchy_count_rows(struct hist_browser *hb, struct hist_entry *he,
+				bool include_children)
+{
+	int count = 0;
+	struct rb_node *node;
+	struct hist_entry *child;
+
+	if (he->leaf)
+		return callchain__count_rows(&he->sorted_chain);
+
+	node = rb_first(&he->hroot_out);
+	while (node) {
+		float percent;
+
+		child = rb_entry(node, struct hist_entry, rb_node);
+		percent = hist_entry__get_percent_limit(child);
+
+		if (!child->filtered && percent >= hb->min_pcnt) {
+			count++;
+
+			if (include_children && child->unfolded)
+				count += hierarchy_count_rows(hb, child, true);
+		}
+
+		node = rb_next(node);
+	}
+	return count;
+}
+
 static bool hist_entry__toggle_fold(struct hist_entry *he)
 {
 	if (!he)
@@ -326,11 +358,17 @@ static void callchain__init_have_children(struct rb_root *root)
 
 static void hist_entry__init_have_children(struct hist_entry *he)
 {
-	if (!he->init_have_children) {
+	if (he->init_have_children)
+		return;
+
+	if (he->leaf) {
 		he->has_children = !RB_EMPTY_ROOT(&he->sorted_chain);
 		callchain__init_have_children(&he->sorted_chain);
-		he->init_have_children = true;
+	} else {
+		he->has_children = !RB_EMPTY_ROOT(&he->hroot_out);
 	}
+
+	he->init_have_children = true;
 }
 
 static bool hist_browser__toggle_fold(struct hist_browser *browser)
@@ -349,17 +387,41 @@ static bool hist_browser__toggle_fold(struct hist_browser *browser)
 		has_children = callchain_list__toggle_fold(cl);
 
 	if (has_children) {
+		int child_rows = 0;
+
 		hist_entry__init_have_children(he);
 		browser->b.nr_entries -= he->nr_rows;
-		browser->nr_callchain_rows -= he->nr_rows;
 
-		if (he->unfolded)
-			he->nr_rows = callchain__count_rows(&he->sorted_chain);
+		if (he->leaf)
+			browser->nr_callchain_rows -= he->nr_rows;
 		else
+			browser->nr_hierarchy_entries -= he->nr_rows;
+
+		if (symbol_conf.report_hierarchy)
+			child_rows = hierarchy_count_rows(browser, he, true);
+
+		if (he->unfolded) {
+			if (he->leaf)
+				he->nr_rows = callchain__count_rows(&he->sorted_chain);
+			else
+				he->nr_rows = hierarchy_count_rows(browser, he, false);
+
+			/* account grand children */
+			if (symbol_conf.report_hierarchy)
+				browser->b.nr_entries += child_rows - he->nr_rows;
+		} else {
+			if (symbol_conf.report_hierarchy)
+				browser->b.nr_entries -= child_rows - he->nr_rows;
+
 			he->nr_rows = 0;
+		}
 
 		browser->b.nr_entries += he->nr_rows;
-		browser->nr_callchain_rows += he->nr_rows;
+
+		if (he->leaf)
+			browser->nr_callchain_rows += he->nr_rows;
+		else
+			browser->nr_hierarchy_entries += he->nr_rows;
 
 		return true;
 	}
@@ -2025,17 +2087,18 @@ static void hist_browser__update_nr_entries(struct hist_browser *hb)
 	u64 nr_entries = 0;
 	struct rb_node *nd = rb_first(&hb->hists->entries);
 
-	if (hb->min_pcnt == 0) {
+	if (hb->min_pcnt == 0 && !symbol_conf.report_hierarchy) {
 		hb->nr_non_filtered_entries = hb->hists->nr_non_filtered_entries;
 		return;
 	}
 
 	while ((nd = hists__filter_entries(nd, hb->min_pcnt)) != NULL) {
 		nr_entries++;
-		nd = rb_next(nd);
+		nd = rb_hierarchy_next(nd);
 	}
 
 	hb->nr_non_filtered_entries = nr_entries;
+	hb->nr_hierarchy_entries = nr_entries;
 }
 
 static void hist_browser__update_percent_limit(struct hist_browser *hb,
-- 
2.7.1

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH v6 18/25] perf hists browser: Count number of hierarchy entries Namhyung Kim <namhyung@kernel.org> - 2016-02-16 15:20 +0100

csiph-web