linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Jiri Olsa <jolsa@redhat.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, linux-kernel@vger.kernel.org, paulus@samba.org,
	hpa@zytor.com, mingo@kernel.org, a.p.zijlstra@chello.nl,
	namhyung@kernel.org, jolsa@redhat.com, fweisbec@gmail.com,
	tglx@linutronix.de, cjashfor@linux.vnet.ibm.com, mingo@elte.hu
Subject: [tip:perf/core] perf diff: Change formula methods to work with pair directly
Date: Thu, 24 Jan 2013 10:52:26 -0800	[thread overview]
Message-ID: <tip-f4c8bae1920c459b7b9c12363d11e8a588862e42@git.kernel.org> (raw)
In-Reply-To: <1354110769-2998-7-git-send-email-jolsa@redhat.com>

Commit-ID:  f4c8bae1920c459b7b9c12363d11e8a588862e42
Gitweb:     http://git.kernel.org/tip/f4c8bae1920c459b7b9c12363d11e8a588862e42
Author:     Jiri Olsa <jolsa@redhat.com>
AuthorDate: Wed, 28 Nov 2012 14:52:41 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Sun, 9 Dec 2012 08:46:07 -0300

perf diff: Change formula methods to work with pair directly

Changing formula methods to operate over hist entry and its pair
directly. This makes the code more obvious and readable, instead of all
time checking for pair being != NULL.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1354110769-2998-7-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-diff.c | 35 +++++++++++++----------------------
 tools/perf/ui/hist.c      |  5 ++++-
 tools/perf/util/hist.h    |  3 ++-
 3 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 342085a..d869029 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -184,13 +184,9 @@ s64 perf_diff__compute_wdiff(struct hist_entry *he, struct hist_entry *pair)
 	return he->diff.wdiff;
 }
 
-static int formula_delta(struct hist_entry *he, char *buf, size_t size)
+static int formula_delta(struct hist_entry *he, struct hist_entry *pair,
+			 char *buf, size_t size)
 {
-	struct hist_entry *pair = hist_entry__next_pair(he);
-
-	if (!pair)
-		return -1;
-
 	return scnprintf(buf, size,
 			 "(%" PRIu64 " * 100 / %" PRIu64 ") - "
 			 "(%" PRIu64 " * 100 / %" PRIu64 ")",
@@ -198,41 +194,36 @@ static int formula_delta(struct hist_entry *he, char *buf, size_t size)
 			  pair->stat.period, pair->hists->stats.total_period);
 }
 
-static int formula_ratio(struct hist_entry *he, char *buf, size_t size)
+static int formula_ratio(struct hist_entry *he, struct hist_entry *pair,
+			 char *buf, size_t size)
 {
-	struct hist_entry *pair = hist_entry__next_pair(he);
 	double new_period = he->stat.period;
-	double old_period = pair ? pair->stat.period : 0;
-
-	if (!pair)
-		return -1;
+	double old_period = pair->stat.period;
 
 	return scnprintf(buf, size, "%.0F / %.0F", new_period, old_period);
 }
 
-static int formula_wdiff(struct hist_entry *he, char *buf, size_t size)
+static int formula_wdiff(struct hist_entry *he, struct hist_entry *pair,
+			 char *buf, size_t size)
 {
-	struct hist_entry *pair = hist_entry__next_pair(he);
 	u64 new_period = he->stat.period;
-	u64 old_period = pair ? pair->stat.period : 0;
-
-	if (!pair)
-		return -1;
+	u64 old_period = pair->stat.period;
 
 	return scnprintf(buf, size,
 		  "(%" PRIu64 " * " "%" PRId64 ") - (%" PRIu64 " * " "%" PRId64 ")",
 		  new_period, compute_wdiff_w2, old_period, compute_wdiff_w1);
 }
 
-int perf_diff__formula(char *buf, size_t size, struct hist_entry *he)
+int perf_diff__formula(struct hist_entry *he, struct hist_entry *pair,
+		       char *buf, size_t size)
 {
 	switch (compute) {
 	case COMPUTE_DELTA:
-		return formula_delta(he, buf, size);
+		return formula_delta(he, pair, buf, size);
 	case COMPUTE_RATIO:
-		return formula_ratio(he, buf, size);
+		return formula_ratio(he, pair, buf, size);
 	case COMPUTE_WEIGHTED_DIFF:
-		return formula_wdiff(he, buf, size);
+		return formula_wdiff(he, pair, buf, size);
 	default:
 		BUG_ON(1);
 	}
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 108e5ed..1785bab 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -389,10 +389,13 @@ static int hpp__width_formula(struct perf_hpp *hpp __maybe_unused)
 
 static int hpp__entry_formula(struct perf_hpp *hpp, struct hist_entry *he)
 {
+	struct hist_entry *pair = hist_entry__next_pair(he);
 	const char *fmt = symbol_conf.field_sep ? "%s" : "%-70s";
 	char buf[96] = " ";
 
-	perf_diff__formula(buf, sizeof(buf), he);
+	if (pair)
+		perf_diff__formula(he, pair, buf, sizeof(buf));
+
 	return scnprintf(hpp->buf, hpp->size, fmt, buf);
 }
 
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 235503a..c1b2fad 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -229,6 +229,7 @@ unsigned int hists__sort_list_width(struct hists *self);
 double perf_diff__compute_delta(struct hist_entry *he, struct hist_entry *pair);
 double perf_diff__compute_ratio(struct hist_entry *he, struct hist_entry *pair);
 s64 perf_diff__compute_wdiff(struct hist_entry *he, struct hist_entry *pair);
-int perf_diff__formula(char *buf, size_t size, struct hist_entry *he);
+int perf_diff__formula(struct hist_entry *he, struct hist_entry *pair,
+		       char *buf, size_t size);
 double perf_diff__period_percent(struct hist_entry *he, u64 period);
 #endif	/* __PERF_HIST_H */

  parent reply	other threads:[~2013-01-24 18:52 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-28 13:52 [PATCH/RFC 00/14] perf, tool: Fix endian issues Jiri Olsa
2012-11-28 13:52 ` [PATCH 01/14] perf tool: Introduce perf_hpp__list for period related columns Jiri Olsa
2012-11-29  7:44   ` Namhyung Kim
2012-11-29 10:52     ` Namhyung Kim
2012-11-28 13:52 ` [PATCH 02/14] perf tool: Add struct perf_hpp_fmt into hpp callbacks Jiri Olsa
2012-11-28 13:52 ` [PATCH 03/14] perf tool: Fix period symbol_conf.field_sep display Jiri Olsa
2012-11-29  7:56   ` Namhyung Kim
2012-11-29 11:53     ` Jiri Olsa
2012-11-29 13:40       ` [PATCH] perf hists: Fix period symbol_conf.field_sep display, again Jiri Olsa
2012-11-29 17:35         ` Arnaldo Carvalho de Melo
2012-11-28 13:52 ` [PATCH 04/14] perf diff: Remove displacement from struct hist_entry_diff Jiri Olsa
2012-11-29  8:00   ` Namhyung Kim
2013-01-24 18:50   ` [tip:perf/core] " tip-bot for Jiri Olsa
2012-11-28 13:52 ` [PATCH 05/14] perf diff: Change compute methods to work with pair directly Jiri Olsa
2012-11-29 11:15   ` Namhyung Kim
2013-01-24 18:51   ` [tip:perf/core] " tip-bot for Jiri Olsa
2012-11-28 13:52 ` [PATCH 06/14] perf diff: Change formula " Jiri Olsa
2012-11-29 11:15   ` Namhyung Kim
2013-01-24 18:52   ` tip-bot for Jiri Olsa [this message]
2012-11-28 13:52 ` [PATCH 07/14] perf diff: Add callback to hists__match/hists__link functions Jiri Olsa
2012-11-28 13:52 ` [PATCH 08/14] perf diff: Change diff command to work over multiple data files Jiri Olsa
2012-11-29 11:37   ` Namhyung Kim
2012-11-29 11:53     ` Jiri Olsa
2012-11-28 13:52 ` [PATCH 09/14] perf diff: Update perf diff documentation for multiple data comparison Jiri Olsa
2012-11-29 11:52   ` Namhyung Kim
2012-11-29 12:06     ` Jiri Olsa
2012-11-28 13:52 ` [PATCH 10/14] perf tool: Centralize default columns init in perf_hpp__init Jiri Olsa
2012-11-29 11:55   ` Namhyung Kim
2012-11-29 12:13     ` Jiri Olsa
2012-11-30  5:06       ` Namhyung Kim
2012-11-30 11:56         ` Jiri Olsa
2012-11-28 13:52 ` [PATCH 11/14] perf diff: Making compute functions static Jiri Olsa
2012-11-28 13:52 ` [PATCH 12/14] perf diff: Display data file info ahead of the diff output Jiri Olsa
2012-11-28 13:52 ` [PATCH 13/14] perf diff: Display zero calculation results Jiri Olsa
2012-11-28 13:52 ` [PATCH 14/14] perf diff: Add generic order option for compute sorting Jiri Olsa
2012-11-29 12:02   ` Namhyung Kim
2012-11-29 12:19     ` Jiri Olsa
2012-11-28 13:56 ` [PATCH/RFC 00/14] perf, diff: Support for multiple files Jiri Olsa
2012-11-28 15:57   ` Jiri Olsa

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=tip-f4c8bae1920c459b7b9c12363d11e8a588862e42@git.kernel.org \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    --cc=tglx@linutronix.de \
    /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).