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,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Mike Galbraith <efault@gmx.de>,
	Namhyung Kim <namhyung@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Stephane Eranian <eranian@google.com>
Subject: [PATCH 08/21] perf diff: Start moving to support matching more than two hists
Date: Fri,  9 Nov 2012 18:42:57 -0300	[thread overview]
Message-ID: <1352497390-17716-9-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1352497390-17716-1-git-send-email-acme@infradead.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

We want to match more than two hists, so that we can match more than two
perf.data files and moreover, match hist_entries (buckets) in multiple
events in a group.

So the "baseline"/"leader" will instead of a ->pair pointer, use a
list_head, that will link to the pairs and hists__match use it.

Following that perf_evlist__link will link the hists in its evsel
groups.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-2kbmzepoi544ygj9godseqpv@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-diff.c |   21 ++++++++++++---------
 tools/perf/ui/hist.c      |   10 +++++-----
 tools/perf/util/hist.c    |    2 ++
 tools/perf/util/sort.h    |   27 +++++++++++++++++++++++----
 4 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 380683d..8a9db38 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -154,7 +154,7 @@ static double get_period_percent(struct hist_entry *he, u64 period)
 
 double perf_diff__compute_delta(struct hist_entry *he)
 {
-	struct hist_entry *pair = he->pair;
+	struct hist_entry *pair = hist_entry__next_pair(he);
 	double new_percent = get_period_percent(he, he->stat.period);
 	double old_percent = pair ? get_period_percent(pair, pair->stat.period) : 0.0;
 
@@ -165,7 +165,7 @@ double perf_diff__compute_delta(struct hist_entry *he)
 
 double perf_diff__compute_ratio(struct hist_entry *he)
 {
-	struct hist_entry *pair = he->pair;
+	struct hist_entry *pair = hist_entry__next_pair(he);
 	double new_period = he->stat.period;
 	double old_period = pair ? pair->stat.period : 0;
 
@@ -176,7 +176,7 @@ double perf_diff__compute_ratio(struct hist_entry *he)
 
 s64 perf_diff__compute_wdiff(struct hist_entry *he)
 {
-	struct hist_entry *pair = he->pair;
+	struct hist_entry *pair = hist_entry__next_pair(he);
 	u64 new_period = he->stat.period;
 	u64 old_period = pair ? pair->stat.period : 0;
 
@@ -193,7 +193,7 @@ s64 perf_diff__compute_wdiff(struct hist_entry *he)
 
 static int formula_delta(struct hist_entry *he, char *buf, size_t size)
 {
-	struct hist_entry *pair = he->pair;
+	struct hist_entry *pair = hist_entry__next_pair(he);
 
 	if (!pair)
 		return -1;
@@ -207,7 +207,7 @@ static int formula_delta(struct hist_entry *he, char *buf, size_t size)
 
 static int formula_ratio(struct hist_entry *he, char *buf, size_t size)
 {
-	struct hist_entry *pair = he->pair;
+	struct hist_entry *pair = hist_entry__next_pair(he);
 	double new_period = he->stat.period;
 	double old_period = pair ? pair->stat.period : 0;
 
@@ -219,7 +219,7 @@ static int formula_ratio(struct hist_entry *he, char *buf, size_t size)
 
 static int formula_wdiff(struct hist_entry *he, char *buf, size_t size)
 {
-	struct hist_entry *pair = he->pair;
+	struct hist_entry *pair = hist_entry__next_pair(he);
 	u64 new_period = he->stat.period;
 	u64 old_period = pair ? pair->stat.period : 0;
 
@@ -359,8 +359,11 @@ static void hists__match(struct hists *older, struct hists *newer)
 	struct rb_node *nd;
 
 	for (nd = rb_first(&newer->entries); nd; nd = rb_next(nd)) {
-		struct hist_entry *pos = rb_entry(nd, struct hist_entry, rb_node);
-		pos->pair = hists__find_entry(older, pos);
+		struct hist_entry *pos = rb_entry(nd, struct hist_entry, rb_node),
+				  *pair = hists__find_entry(older, pos);
+
+		if (pair)
+			hist__entry_add_pair(pos, pair);
 	}
 }
 
@@ -402,7 +405,7 @@ static void hists__baseline_only(struct hists *hists)
 		struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node);
 
 		next = rb_next(&he->rb_node);
-		if (!he->pair) {
+		if (!hist_entry__next_pair(he)) {
 			rb_erase(&he->rb_node, &hists->entries);
 			hist_entry__free(he);
 		}
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 4f5f475..aa84130 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -161,7 +161,7 @@ static int hpp__width_baseline(struct perf_hpp *hpp __maybe_unused)
 
 static double baseline_percent(struct hist_entry *he)
 {
-	struct hist_entry *pair = he->pair;
+	struct hist_entry *pair = hist_entry__next_pair(he);
 	struct hists *pair_hists = pair ? pair->hists : NULL;
 	double percent = 0.0;
 
@@ -179,7 +179,7 @@ static int hpp__color_baseline(struct perf_hpp *hpp, struct hist_entry *he)
 {
 	double percent = baseline_percent(he);
 
-	if (he->pair)
+	if (hist_entry__has_pairs(he))
 		return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);
 	else
 		return scnprintf(hpp->buf, hpp->size, "        ");
@@ -190,7 +190,7 @@ static int hpp__entry_baseline(struct perf_hpp *hpp, struct hist_entry *he)
 	double percent = baseline_percent(he);
 	const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%";
 
-	if (he->pair || symbol_conf.field_sep)
+	if (hist_entry__has_pairs(he) || symbol_conf.field_sep)
 		return scnprintf(hpp->buf, hpp->size, fmt, percent);
 	else
 		return scnprintf(hpp->buf, hpp->size, "            ");
@@ -248,7 +248,7 @@ static int hpp__width_period_baseline(struct perf_hpp *hpp __maybe_unused)
 
 static int hpp__entry_period_baseline(struct perf_hpp *hpp, struct hist_entry *he)
 {
-	struct hist_entry *pair = he->pair;
+	struct hist_entry *pair = hist_entry__next_pair(he);
 	u64 period = pair ? pair->stat.period : 0;
 	const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64;
 
@@ -354,7 +354,7 @@ static int hpp__width_displ(struct perf_hpp *hpp __maybe_unused)
 static int hpp__entry_displ(struct perf_hpp *hpp,
 			    struct hist_entry *he)
 {
-	struct hist_entry *pair = he->pair;
+	struct hist_entry *pair = hist_entry__next_pair(he);
 	long displacement = pair ? pair->position - he->position : 0;
 	const char *fmt = symbol_conf.field_sep ? "%s" : "%6.6s";
 	char buf[32] = " ";
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index a1b823f..f42de79 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -244,6 +244,8 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template)
 			he->ms.map->referenced = true;
 		if (symbol_conf.use_callchain)
 			callchain_init(he->callchain);
+
+		INIT_LIST_HEAD(&he->pairs.node);
 	}
 
 	return he;
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 13761d8..b4e8c3b 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -77,6 +77,10 @@ struct hist_entry_diff {
 struct hist_entry {
 	struct rb_node		rb_node_in;
 	struct rb_node		rb_node;
+	union {
+		struct list_head node;
+		struct list_head head;
+	} pairs;
 	struct he_stat		stat;
 	struct map_symbol	ms;
 	struct thread		*thread;
@@ -96,15 +100,30 @@ struct hist_entry {
 	char			*srcline;
 	struct symbol		*parent;
 	unsigned long		position;
-	union {
-		struct hist_entry *pair;
-		struct rb_root	  sorted_chain;
-	};
+	struct rb_root		sorted_chain;
 	struct branch_info	*branch_info;
 	struct hists		*hists;
 	struct callchain_root	callchain[0];
 };
 
+static inline bool hist_entry__has_pairs(struct hist_entry *he)
+{
+	return !list_empty(&he->pairs.node);
+}
+
+static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
+{
+	if (hist_entry__has_pairs(he))
+		return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
+	return NULL;
+}
+
+static inline void hist__entry_add_pair(struct hist_entry *he,
+					struct hist_entry *pair)
+{
+	list_add_tail(&he->pairs.head, &pair->pairs.node);
+}
+
 enum sort_type {
 	SORT_PID,
 	SORT_COMM,
-- 
1.7.9.2.358.g22243


  parent reply	other threads:[~2012-11-09 21:47 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-09 21:42 [GIT PULL 00/21] perf/core improvements and fixes Arnaldo Carvalho de Melo
2012-11-09 21:42 ` [PATCH 01/21] perf machine: Set kernel data mapping length Arnaldo Carvalho de Melo
2012-11-09 21:42 ` [PATCH 02/21] perf tools: Fix detection of stack area Arnaldo Carvalho de Melo
2012-11-09 21:42 ` [PATCH 03/21] perf hists: Free branch_info when freeing hist_entry Arnaldo Carvalho de Melo
2012-11-09 21:42 ` [PATCH 04/21] perf tests: Move attr.py temp dir cleanup into finally section Arnaldo Carvalho de Melo
2012-11-09 21:42 ` [PATCH 05/21] perf tools: Add LIBDW_DIR Makefile variable to for alternate libdw Arnaldo Carvalho de Melo
2012-11-09 21:42 ` [PATCH 06/21] perf tools: Add arbitary aliases and support names with - Arnaldo Carvalho de Melo
2012-11-09 21:42 ` [PATCH 07/21] perf tools: Don't try to lookup objdump for live mode Arnaldo Carvalho de Melo
2012-11-09 21:42 ` Arnaldo Carvalho de Melo [this message]
2012-11-09 21:42 ` [PATCH 09/21] perf diff: Move hists__match to the hists lib Arnaldo Carvalho de Melo
2012-11-09 21:42 ` [PATCH 10/21] perf hists: Introduce hists__link Arnaldo Carvalho de Melo
2012-11-12  2:40   ` Namhyung Kim
2012-11-12 16:04     ` Arnaldo Carvalho de Melo
2012-11-09 21:43 ` [PATCH 11/21] perf diff: Use hists__link when not pairing just with baseline Arnaldo Carvalho de Melo
2012-11-09 21:43 ` [PATCH 12/21] perf machine: Move more methods to machine.[ch] Arnaldo Carvalho de Melo
2012-11-09 21:43 ` [PATCH 13/21] perf test: fix a build error on builtin-test Arnaldo Carvalho de Melo
2012-11-09 21:43 ` [PATCH 14/21] perf annotate: Whitespace fixups Arnaldo Carvalho de Melo
2012-11-09 21:43 ` [PATCH 15/21] perf annotate: Don't try to follow jump target on PLT symbols Arnaldo Carvalho de Melo
2012-11-09 21:43 ` [PATCH 16/21] perf annotate: Merge same lines in summary view Arnaldo Carvalho de Melo
2012-11-09 21:43 ` [PATCH 17/21] tools lib traceevent: Add __maybe_unused to unused parameters Arnaldo Carvalho de Melo
2012-11-09 21:43 ` [PATCH 18/21] tools lib traceevent: Avoid comparisions between signed/unsigned Arnaldo Carvalho de Melo
2012-11-09 21:43 ` [PATCH 19/21] tools lib traceevent: No need to check for < 0 on an unsigned enum Arnaldo Carvalho de Melo
2012-11-09 21:43 ` [PATCH 20/21] tools lib traceevent: Handle INVALID_ARG_TYPE errno in pevent_strerror Arnaldo Carvalho de Melo
2012-11-09 21:43 ` [PATCH 21/21] tools lib traceevent: Use 'const' in variables pointing to const strings Arnaldo Carvalho de Melo
2012-11-12  2:10 ` [GIT PULL 00/21] perf/core improvements and fixes Namhyung Kim
2012-11-12 13:55   ` Jiri Olsa
2012-11-12 16:01     ` Arnaldo Carvalho de Melo
2012-11-13  1:20       ` Namhyung Kim
2012-11-13 18:11 ` 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=1352497390-17716-9-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=efault@gmx.de \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@gmail.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.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).