All of lore.kernel.org
 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, Jiri Olsa <jolsa@redhat.com>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 62/76] perf diff: Add generic order option for compute sorting
Date: Thu, 18 Jul 2013 16:49:49 -0300	[thread overview]
Message-ID: <1374177003-3706-63-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1374177003-3706-1-git-send-email-acme@infradead.org>

From: Jiri Olsa <jolsa@redhat.com>

Adding option 'o' to allow sorting based on the input file number. By
default (without -o option) the output is sorted on baseline.

Also removing '+' sorting support from -c option, because it's not
needed anymore.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
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/n/tip-l7dvhgt0azm7yiqg3fbn4dxw@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-diff.txt |  6 ++-
 tools/perf/builtin-diff.c              | 95 +++++++++++++++++++++++-----------
 2 files changed, 70 insertions(+), 31 deletions(-)

diff --git a/tools/perf/Documentation/perf-diff.txt b/tools/perf/Documentation/perf-diff.txt
index 2d134f3..fdfceee 100644
--- a/tools/perf/Documentation/perf-diff.txt
+++ b/tools/perf/Documentation/perf-diff.txt
@@ -75,8 +75,6 @@ OPTIONS
 -c::
 --compute::
         Differential computation selection - delta,ratio,wdiff (default is delta).
-        If '+' is specified as a first character, the output is sorted based
-        on the computation results.
         See COMPARISON METHODS section for more info.
 
 -p::
@@ -87,6 +85,10 @@ OPTIONS
 --formula::
         Show formula for given computation.
 
+-o::
+--order::
+       Specify compute sorting column number.
+
 COMPARISON
 ----------
 The comparison is governed by the baseline file. The baseline perf.data
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index f2fbf69..93de3ac 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -64,7 +64,7 @@ static bool force;
 static bool show_period;
 static bool show_formula;
 static bool show_baseline_only;
-static bool sort_compute;
+static unsigned int sort_compute;
 
 static s64 compute_wdiff_w1;
 static s64 compute_wdiff_w2;
@@ -188,13 +188,6 @@ static int setup_compute(const struct option *opt, const char *str,
 		return 0;
 	}
 
-	if (*str == '+') {
-		sort_compute = true;
-		cstr = (char *) ++str;
-		if (!*str)
-			return 0;
-	}
-
 	option = strchr(str, ':');
 	if (option) {
 		unsigned len = option++ - str;
@@ -378,6 +371,29 @@ static void perf_evlist__collapse_resort(struct perf_evlist *evlist)
 	}
 }
 
+static struct hist_entry*
+get_pair_data(struct hist_entry *he, struct data__file *d)
+{
+	if (hist_entry__has_pairs(he)) {
+		struct hist_entry *pair;
+
+		list_for_each_entry(pair, &he->pairs.head, pairs.node)
+			if (pair->hists == d->hists)
+				return pair;
+	}
+
+	return NULL;
+}
+
+static struct hist_entry*
+get_pair_fmt(struct hist_entry *he, struct diff_hpp_fmt *dfmt)
+{
+	void *ptr = dfmt - dfmt->idx;
+	struct data__file *d = container_of(ptr, struct data__file, fmt);
+
+	return get_pair_data(he, d);
+}
+
 static void hists__baseline_only(struct hists *hists)
 {
 	struct rb_root *root;
@@ -412,10 +428,12 @@ static void hists__precompute(struct hists *hists)
 
 	next = rb_first(root);
 	while (next != NULL) {
-		struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node_in);
-		struct hist_entry *pair = hist_entry__next_pair(he);
+		struct hist_entry *he, *pair;
 
+		he   = rb_entry(next, struct hist_entry, rb_node_in);
 		next = rb_next(&he->rb_node_in);
+
+		pair = get_pair_data(he, &data__files[sort_compute]);
 		if (!pair)
 			continue;
 
@@ -446,7 +464,7 @@ static int64_t cmp_doubles(double l, double r)
 }
 
 static int64_t
-hist_entry__cmp_compute(struct hist_entry *left, struct hist_entry *right,
+__hist_entry__cmp_compute(struct hist_entry *left, struct hist_entry *right,
 			int c)
 {
 	switch (c) {
@@ -478,6 +496,36 @@ hist_entry__cmp_compute(struct hist_entry *left, struct hist_entry *right,
 	return 0;
 }
 
+static int64_t
+hist_entry__cmp_compute(struct hist_entry *left, struct hist_entry *right,
+			int c)
+{
+	bool pairs_left  = hist_entry__has_pairs(left);
+	bool pairs_right = hist_entry__has_pairs(right);
+	struct hist_entry *p_right, *p_left;
+
+	if (!pairs_left && !pairs_right)
+		return 0;
+
+	if (!pairs_left || !pairs_right)
+		return pairs_left ? -1 : 1;
+
+	p_left  = get_pair_data(left,  &data__files[sort_compute]);
+	p_right = get_pair_data(right, &data__files[sort_compute]);
+
+	if (!p_left && !p_right)
+		return 0;
+
+	if (!p_left || !p_right)
+		return p_left ? -1 : 1;
+
+	/*
+	 * We have 2 entries of same kind, let's
+	 * make the data comparison.
+	 */
+	return __hist_entry__cmp_compute(p_left, p_right, c);
+}
+
 static void insert_hist_entry_by_compute(struct rb_root *root,
 					 struct hist_entry *he,
 					 int c)
@@ -680,6 +728,7 @@ static const struct option options[] = {
 		   "columns '.' is reserved."),
 	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
 		    "Look for files with symbols relative to this directory"),
+	OPT_UINTEGER('o', "order", &sort_compute, "Specify compute sorting."),
 	OPT_END()
 };
 
@@ -791,28 +840,11 @@ hpp__entry_pair(struct hist_entry *he, struct hist_entry *pair,
 	};
 }
 
-static struct hist_entry *get_pair(struct hist_entry *he,
-				   struct diff_hpp_fmt *dfmt)
-{
-	void *ptr = dfmt - dfmt->idx;
-	struct data__file *d = container_of(ptr, struct data__file, fmt);
-
-	if (hist_entry__has_pairs(he)) {
-		struct hist_entry *pair;
-
-		list_for_each_entry(pair, &he->pairs.head, pairs.node)
-			if (pair->hists == d->hists)
-				return pair;
-	}
-
-	return NULL;
-}
-
 static void
 __hpp__entry_global(struct hist_entry *he, struct diff_hpp_fmt *dfmt,
 		    char *buf, size_t size)
 {
-	struct hist_entry *pair = get_pair(he, dfmt);
+	struct hist_entry *pair = get_pair_fmt(he, dfmt);
 	int idx = dfmt->idx;
 
 	/* baseline is special */
@@ -972,6 +1004,11 @@ static int data_init(int argc, const char **argv)
 		defaults[1] = "perf.data.guest";
 	}
 
+	if (sort_compute >= (unsigned int) data__files_cnt) {
+		pr_err("Order option out of limit.\n");
+		return -EINVAL;
+	}
+
 	data__files = zalloc(sizeof(*data__files) * data__files_cnt);
 	if (!data__files)
 		return -ENOMEM;
-- 
1.8.1.4


  parent reply	other threads:[~2013-07-18 19:50 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-18 19:48 [GIT PULL 00/76] perf/core improvements and fixes Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 01/76] perf tools: Rename cpu_map__all() to cpu_map__empty() Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 02/76] perf top: Add --objdump option Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 03/76] perf tools: Remove cwd from perf_session struct Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 04/76] perf tests: Omit end of the symbol check failure for test 1 Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 05/76] perf tests: Make TEST_ASSERT_VAL global Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 06/76] perf tools: Use default include path notation for libtraceevent headers Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 07/76] perf tools: Add methods for setting/retrieving priv element of thread struct Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 08/76] perf tools: Remove callchain_cursor_reset call Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 09/76] perf util: Move debugfs/tracing helper functions to util.c Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 10/76] perf util: Use evsel->name to get tracepoint_paths Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 11/76] perf tools: Do not elide parent symbol column Arnaldo Carvalho de Melo
2013-07-18 19:48 ` [PATCH 12/76] perf report: Fix perf_session__delete removal Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 13/76] perf tools: Make Power7 events available for perf Arnaldo Carvalho de Melo
2013-07-18 19:49   ` Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 14/76] perf evlist: Fix use of uninitialized variable Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 15/76] perf tools: Don't free list head in parse_events__free_terms Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 16/76] perf tests: Make terms a stack variable in test_term Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 17/76] perf parse events: Demystify memory allocations Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 18/76] tools lib traceevent: Remove unused install targets Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 19/76] tools lib traceevent: Get rid of unused gui target Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 20/76] tools lib traceevent: Add const qualifier to string arguments Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 21/76] tools lib traceevent: Add trace_seq_reset() Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 22/76] tools lib traceevent: Add page_size field to pevent Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 23/76] tools lib traceevent: Port kbuffer parser routines Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 24/76] perf util: Save page size in a trace file to pevent Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 25/76] perf util: Save long size of traced system Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 26/76] perf util: Make file/host_bigendian variable local Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 27/76] perf util: Skip reading header_event file Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 28/76] perf util: Parse header_page to get proper long size Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 29/76] perf util: Get rid of unused header_page_* variables Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 30/76] perf script: Adopt latency_format variable Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 31/76] perf util: Rename read_*() functions in trace-event-info.c Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 32/76] perf util: No need to call read_trace_init() in tracing_data_header() Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 33/76] perf util: Remove unused enum and macro in trace-event.h Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 34/76] perf sched: Move struct perf_sched definition out of cmd_sched() Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 35/76] perf gtk/hists: Use GtkTreeStore instead of GtkListStore Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 36/76] perf gtk/hists: Add support for callchains Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 37/76] perf gtk/hists: Display callchain overhead also Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 38/76] perf gtk/hists: Make column headers resizable Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 39/76] perf gtk/hists: Add a double-click handler for callchains Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 40/76] perf gtk/hists: Set rules hint for the hist browser Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 41/76] perf inject: Remove unused parameter Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 42/76] perf tools: Fix missing tool parameter Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 43/76] perf inject: Add missing 'finished_round' Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 44/76] perf tools: Add const specifier to perf_pmu__find name parameter Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 45/76] perf evlist: Tidy duplicated munmap code Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 46/76] perf tools: Validate perf event header size Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 47/76] perf tools: struct thread has a tid not a pid Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 48/76] perf tools: Default to cpu// for events v5 Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 49/76] perf list: List kernel supplied event aliases Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 50/76] perf report/top: Add option to collapse undesired parts of call graph Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 51/76] perf tools: Add struct perf_hpp_fmt into hpp callbacks Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 52/76] perf tools: Centralize default columns init in perf_hpp__init Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 53/76] perf diff: Introducing diff_data object to hold files Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 54/76] perf diff: Switching the base hists to be pairs head Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 55/76] perf hists: Marking dummy hists entries Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 56/76] perf diff: Display data file info ahead of the diff output Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 57/76] perf diff: Move diff related columns into diff command Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 58/76] perf diff: Move columns into struct data__file Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 59/76] perf diff: Change diff command to work over multiple data files Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 60/76] perf diff: Update perf diff documentation for multiple data comparison Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 61/76] perf diff: Making compute functions static Arnaldo Carvalho de Melo
2013-07-18 19:49 ` Arnaldo Carvalho de Melo [this message]
2013-07-18 19:49 ` [PATCH 63/76] perf tools: Move hist_entry__period_snprintf into stdio code Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 64/76] perf timechart: Use traceevent lib event-parse.h include Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 65/76] perf timechart: Remove event types framework only user Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 66/76] perf tools: Remove event types from perf data file Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 67/76] perf record: Remove event types pushing Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 68/76] perf tools: Remove event types framework completely Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 69/76] perf tools: Fix 'make tools/perf' Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 70/76] perf symbols: Do not apply symfs for an absolute vmlinux path Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 71/76] perf tests: Check proper prev_state size for sched_switch tp Arnaldo Carvalho de Melo
2013-07-18 19:49 ` [PATCH 72/76] perf session: Use session->fd instead of passing fd as argument Arnaldo Carvalho de Melo
2013-07-18 19:50 ` [PATCH 73/76] perf header: Remove data_offset seek as it's not needed Arnaldo Carvalho de Melo
2013-07-18 19:50 ` [PATCH 74/76] perf header: Remove attr_offset from perf_header Arnaldo Carvalho de Melo
2013-07-18 19:50 ` [PATCH 75/76] perf header: Introduce feat_offset into perf_header Arnaldo Carvalho de Melo
2013-07-18 19:50 ` [PATCH 76/76] perf header: Recognize version number for perf data file Arnaldo Carvalho de Melo
2013-07-19  7:40 ` [GIT PULL 00/76] perf/core improvements and fixes 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=1374177003-3706-63-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.