linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung.kim@lge.com>,
	Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@redhat.com>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Stephane Eranian <eranian@google.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 02/74] perf hists: Link hist entries before inserting to an output tree
Date: Thu, 24 Jan 2013 17:07:11 -0300	[thread overview]
Message-ID: <1359058103-31645-3-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1359058103-31645-1-git-send-email-acme@infradead.org>

From: Namhyung Kim <namhyung.kim@lge.com>

For matching and/or linking hist entries, they need to be sorted by
given sort keys.  However current hists__match/link did this on the
output trees, so that the entries in the output tree need to be resort
before doing it.

This looks not so good since we have trees for collecting or collapsing
entries before passing them to an output tree and they're already sorted
by the given sort keys.  Since we don't need to print anything at the
time of matching/linking, we can use these internal trees directly
instead of bothering with double resort on the output tree.

Its only user - at the time of this writing - perf diff can be easily
converted to use the internal tree and can save some lines too by
getting rid of unnecessary resorting codes.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1355128197-18193-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-diff.c | 65 +++++++++++++----------------------------------
 tools/perf/util/hist.c    | 49 ++++++++++++++++++++++++++---------
 2 files changed, 54 insertions(+), 60 deletions(-)

diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 4dda6f4..8b896f5 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -275,43 +275,6 @@ static struct perf_tool tool = {
 	.ordering_requires_timestamps = true,
 };
 
-static void insert_hist_entry_by_name(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__cmp(iter, he) < 0)
-			p = &(*p)->rb_left;
-		else
-			p = &(*p)->rb_right;
-	}
-
-	rb_link_node(&he->rb_node, parent, p);
-	rb_insert_color(&he->rb_node, root);
-}
-
-static void hists__name_resort(struct hists *self)
-{
-	struct rb_root tmp = RB_ROOT;
-	struct rb_node *next = rb_first(&self->entries);
-
-	while (next != NULL) {
-		struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node);
-
-		next = rb_next(&n->rb_node);
-
-		rb_erase(&n->rb_node, &self->entries);
-		insert_hist_entry_by_name(&tmp, n);
-	}
-
-	self->entries = tmp;
-}
-
 static struct perf_evsel *evsel_match(struct perf_evsel *evsel,
 				      struct perf_evlist *evlist)
 {
@@ -324,30 +287,34 @@ static struct perf_evsel *evsel_match(struct perf_evsel *evsel,
 	return NULL;
 }
 
-static void perf_evlist__resort_hists(struct perf_evlist *evlist, bool name)
+static void perf_evlist__collapse_resort(struct perf_evlist *evlist)
 {
 	struct perf_evsel *evsel;
 
 	list_for_each_entry(evsel, &evlist->entries, node) {
 		struct hists *hists = &evsel->hists;
 
-		hists__output_resort(hists);
-
-		if (name)
-			hists__name_resort(hists);
+		hists__collapse_resort(hists);
 	}
 }
 
 static void hists__baseline_only(struct hists *hists)
 {
-	struct rb_node *next = rb_first(&hists->entries);
+	struct rb_root *root;
+	struct rb_node *next;
+
+	if (sort__need_collapse)
+		root = &hists->entries_collapsed;
+	else
+		root = hists->entries_in;
 
+	next = rb_first(root);
 	while (next != NULL) {
-		struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node);
+		struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node_in);
 
-		next = rb_next(&he->rb_node);
+		next = rb_next(&he->rb_node_in);
 		if (!hist_entry__next_pair(he)) {
-			rb_erase(&he->rb_node, &hists->entries);
+			rb_erase(&he->rb_node_in, root);
 			hist_entry__free(he);
 		}
 	}
@@ -471,6 +438,8 @@ static void hists__process(struct hists *old, struct hists *new)
 	else
 		hists__link(new, old);
 
+	hists__output_resort(new);
+
 	if (sort_compute) {
 		hists__precompute(new);
 		hists__compute_resort(new);
@@ -505,8 +474,8 @@ static int __cmd_diff(void)
 	evlist_old = older->evlist;
 	evlist_new = newer->evlist;
 
-	perf_evlist__resort_hists(evlist_old, true);
-	perf_evlist__resort_hists(evlist_new, false);
+	perf_evlist__collapse_resort(evlist_old);
+	perf_evlist__collapse_resort(evlist_new);
 
 	list_for_each_entry(evsel, &evlist_new->entries, node) {
 		struct perf_evsel *evsel_old;
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 3a9ccd0..8ff3c2f 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -726,16 +726,24 @@ void hists__inc_nr_events(struct hists *hists, u32 type)
 static struct hist_entry *hists__add_dummy_entry(struct hists *hists,
 						 struct hist_entry *pair)
 {
-	struct rb_node **p = &hists->entries.rb_node;
+	struct rb_root *root;
+	struct rb_node **p;
 	struct rb_node *parent = NULL;
 	struct hist_entry *he;
 	int cmp;
 
+	if (sort__need_collapse)
+		root = &hists->entries_collapsed;
+	else
+		root = hists->entries_in;
+
+	p = &root->rb_node;
+
 	while (*p != NULL) {
 		parent = *p;
-		he = rb_entry(parent, struct hist_entry, rb_node);
+		he = rb_entry(parent, struct hist_entry, rb_node_in);
 
-		cmp = hist_entry__cmp(he, pair);
+		cmp = hist_entry__collapse(he, pair);
 
 		if (!cmp)
 			goto out;
@@ -750,8 +758,8 @@ static struct hist_entry *hists__add_dummy_entry(struct hists *hists,
 	if (he) {
 		memset(&he->stat, 0, sizeof(he->stat));
 		he->hists = hists;
-		rb_link_node(&he->rb_node, parent, p);
-		rb_insert_color(&he->rb_node, &hists->entries);
+		rb_link_node(&he->rb_node_in, parent, p);
+		rb_insert_color(&he->rb_node_in, root);
 		hists__inc_nr_entries(hists, he);
 	}
 out:
@@ -761,11 +769,16 @@ out:
 static struct hist_entry *hists__find_entry(struct hists *hists,
 					    struct hist_entry *he)
 {
-	struct rb_node *n = hists->entries.rb_node;
+	struct rb_node *n;
+
+	if (sort__need_collapse)
+		n = hists->entries_collapsed.rb_node;
+	else
+		n = hists->entries_in->rb_node;
 
 	while (n) {
-		struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node);
-		int64_t cmp = hist_entry__cmp(iter, he);
+		struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node_in);
+		int64_t cmp = hist_entry__collapse(iter, he);
 
 		if (cmp < 0)
 			n = n->rb_left;
@@ -783,11 +796,17 @@ static struct hist_entry *hists__find_entry(struct hists *hists,
  */
 void hists__match(struct hists *leader, struct hists *other)
 {
+	struct rb_root *root;
 	struct rb_node *nd;
 	struct hist_entry *pos, *pair;
 
-	for (nd = rb_first(&leader->entries); nd; nd = rb_next(nd)) {
-		pos  = rb_entry(nd, struct hist_entry, rb_node);
+	if (sort__need_collapse)
+		root = &leader->entries_collapsed;
+	else
+		root = leader->entries_in;
+
+	for (nd = rb_first(root); nd; nd = rb_next(nd)) {
+		pos  = rb_entry(nd, struct hist_entry, rb_node_in);
 		pair = hists__find_entry(other, pos);
 
 		if (pair)
@@ -802,11 +821,17 @@ void hists__match(struct hists *leader, struct hists *other)
  */
 int hists__link(struct hists *leader, struct hists *other)
 {
+	struct rb_root *root;
 	struct rb_node *nd;
 	struct hist_entry *pos, *pair;
 
-	for (nd = rb_first(&other->entries); nd; nd = rb_next(nd)) {
-		pos = rb_entry(nd, struct hist_entry, rb_node);
+	if (sort__need_collapse)
+		root = &other->entries_collapsed;
+	else
+		root = other->entries_in;
+
+	for (nd = rb_first(root); nd; nd = rb_next(nd)) {
+		pos = rb_entry(nd, struct hist_entry, rb_node_in);
 
 		if (!hist_entry__has_pairs(pos)) {
 			pair = hists__add_dummy_entry(leader, pos);
-- 
1.8.1.1.361.gec3ae6e


  parent reply	other threads:[~2013-01-24 20:11 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1359058103-31645-1-git-send-email-acme@infradead.org>
2013-01-24 20:07 ` [PATCH 01/74] perf hists: Exchange order of comparing items when collapsing hists Arnaldo Carvalho de Melo
2013-01-24 20:07 ` Arnaldo Carvalho de Melo [this message]
2013-01-24 20:07 ` [PATCH 03/74] perf diff: Use internal rb tree for compute resort Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 04/74] perf test: Add a test case for hists__{match,link} Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 05/74] perf test: Remove leftover temp file left by one of the attr tests Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 06/74] perf tests: Adjust some message log levels to help diagnosing problems in " Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 07/74] perf evsel: Do missing feature fallbacks in just one place Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 08/74] perf evsel: Introduce event fallback method Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 09/74] perf evsel: Introduce perf_evsel__open_strerror method Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 10/74] perf test: Check for linking problems in the python binding Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 11/74] perf python: Fix breakage introduced by the test_attr infrastructure Arnaldo Carvalho de Melo
2013-01-29  4:06   ` Thomas Backlund
2013-01-24 20:07 ` [PATCH 12/74] perf tools: Add missing closedir in multi tracepoint processing Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 13/74] perf tools: Add support for wildcard in tracepoint system name Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 14/74] perf tests: Add event parsing test for '*:*' tracepoints Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 15/74] perf tests: Check python path on attr and binding test Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 16/74] perf header: Ensure read/write finished successfully Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 17/74] perf record: Don't pass host machine to guest synthesizer Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 18/74] perf hists: Rename hists__fprintf_nr_events to events_stats__fprintf Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 19/74] perf session: There is no need for a per session hists instance Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 20/74] perf machine: Introduce struct machines Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 21/74] perf tests: Fix PYTHONPATH for python-use test tracepoints Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 22/74] perf machine: Simplify accessing the host machine Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 23/74] perf kvm: Initialize file_name var to fix segfault Arnaldo Carvalho de Melo
2013-01-25  3:00   ` Xiao Guangrong
2013-01-24 20:07 ` [PATCH 24/74] perf tests: Add return states enum for tests Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 25/74] perf tests: Don't fail if a matching vmlinux isn't found, skip that test Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 26/74] perf tools: remove redundant checks from _sort__sym_cmp Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 27/74] perf kmem: use ARRAY_SIZE instead of reinventing it Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 28/74] perf script: " Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 29/74] uprobes: remove redundant check Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 30/74] perf ui/gtk: Factor out common browser routines Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 31/74] perf ui/gtk: Setup browser window early Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 32/74] tools lib traceevent: test correct variable after allocation Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 33/74] tools lib traceevent: Update FSF postal address to be URL's Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 34/74] tools lib traceevent: Add copyright header Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 35/74] perf tools: Fix GNU make v3.80 compatibility issue Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 36/74] perf tools: Fix possible (unlikely) buffer overflow Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 37/74] perf symbols: Include elf.h header regardless LIBELF_SUPPORT Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 38/74] perf bench: Flush stdout before starting bench suite Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 39/74] perf tools: Add anonymous huge page recognition Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 40/74] perf: Missing field in PERF_RECORD_SAMPLE documentation Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 41/74] perf probe: Allow of casting an array of char to string Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 42/74] perf sort: Move misplaced sort entry functions Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 43/74] perf sort: Get rid of unnecessary __maybe_unused Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 44/74] perf sort: Fix --sort pid output Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 45/74] perf sort: Align cpu column to right Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 46/74] perf sort: Calculate parent column width too Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 47/74] perf sort: Clean up sort__first_dimension setting Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 48/74] perf sort: Separate out branch stack specific sort keys Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 49/74] perf report: Update documentation for " Arnaldo Carvalho de Melo
2013-01-24 20:07 ` [PATCH 50/74] perf symbols: Move name malloc to when needed in dso__load Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 51/74] perf symbols: Mark vmlinux filename as allocated Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 52/74] perf tools: Move get_term_dimensions from top to util.c Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 53/74] perf annotate browser: Fix segfault when drawing out-of-bounds jumps Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 54/74] perf tools: Mark branch_info maps as referenced Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 55/74] perf tools: Remove unused 'unset' parameter from parse_events Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 56/74] tools lib traceevent: Fix warning on '>=' operator Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 57/74] perf tools: Get rid of unused include of config.mak Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 58/74] perf tools: Do not include PERF-VERSION-FILE to Makefile Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 59/74] perf tools: Fix PMU format parsing test failure Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 60/74] perf tools: Move ltrim() to util/string.c Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 61/74] perf tools: Fix usage of __ in parse_events_term struct Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 62/74] perf pmu: Fix usage of __ in struct names Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 63/74] perf ui browsers: " Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 64/74] perf tools: Fix usage of __ in event parsing " Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 65/74] perf tests: Use ARRAY_SIZE() were applicable Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 66/74] perf pmu: Privatize perf_pmu_{format,alias} structs Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 67/74] perf tools: Remove some needless die() calls from the main routine Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 68/74] perf tools: Reinstate 'signed' field flag for tracepoints Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 69/74] perf script: Don't display trace info when invoking scripts Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 70/74] perf script: hook up perf_scripting_context->pevent Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 71/74] perf script: Remove workqueue-stats script Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 72/74] perf tools: Allow passing NULL to intlist__find Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 73/74] perf tools: Allow passing a list to intlist__new Arnaldo Carvalho de Melo
2013-01-24 20:08 ` [PATCH 74/74] perf test: Allow skipping tests Arnaldo Carvalho de Melo

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=1359058103-31645-3-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    /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).