public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Jiri Olsa <jolsa@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
	David Ahern <dsahern@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Andi Kleen <andi@firstfloor.org>, Wang Nan <wangnan0@huawei.com>
Subject: [PATCH v4 3/5] perf tools: Fix dynamic sort keys to sort properly
Date: Thu,  7 Jan 2016 09:12:27 +0900	[thread overview]
Message-ID: <1452125549-1511-3-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1452125549-1511-1-git-send-email-namhyung@kernel.org>

Currently, the dynamic sort keys compares trace data using memcmp().
But for output sorting, it should check data size and compare by word.
Also it sorted strings in reverse order, fix it.

Before)

  $ perf report -F overhead -s prev_pid,next_pid
  ...
  # Overhead    prev_pid    next_pid
  # ........  ..........  ..........
  #
       0.39%         490           0
       9.12%         225           0
       0.04%         224           0
       0.51%         731         189
       0.08%         731           3
       0.12%         731           0
       4.82%         729           0
       0.08%        1229           0
       0.20%         715           0
       4.78%         189         225
  ...

After)

  $ perf report -F overhead -s prev_pid,next_pid
  ...
  # Overhead    prev_pid    next_pid
  # ........  ..........  ..........
  #
       0.43%           0           7
       0.04%           0          11
       0.04%           0          12
       0.08%           0          14
       0.04%           0          17
       0.08%           0          19
       0.04%           0          22
       0.04%           0          27
       0.04%           0          37
       0.04%           0          42
  ...

Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/sort.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index e8a5cdee3f0d..4d05b13aeac8 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1804,6 +1804,9 @@ static int64_t __sort__hde_sort(struct perf_hpp_fmt *fmt,
 	struct hpp_dynamic_entry *hde;
 	struct format_field *field;
 	unsigned offset, size;
+	int64_t *a64, *b64;
+	int32_t *a32, *b32;
+	int16_t *a16, *b16;
 
 	hde = container_of(fmt, struct hpp_dynamic_entry, hpp);
 
@@ -1819,7 +1822,25 @@ static int64_t __sort__hde_sort(struct perf_hpp_fmt *fmt,
 		size = field->size;
 	}
 
-	return memcmp(b->raw_data + offset, a->raw_data + offset, size);
+	if (field->flags & FIELD_IS_STRING)
+		return strcmp(b->raw_data + offset, a->raw_data + offset);
+
+	switch (size) {
+	case 8:
+		a64 = a->raw_data + offset;
+		b64 = b->raw_data + offset;
+		return *b64 - *a64;
+	case 4:
+		a32 = a->raw_data + offset;
+		b32 = b->raw_data + offset;
+		return *b32 - *a32;
+	case 2:
+		a16 = a->raw_data + offset;
+		b16 = b->raw_data + offset;
+		return *b16 - *a16;
+	default:
+		return memcmp(b->raw_data + offset, a->raw_data + offset, size);
+	}
 }
 
 bool perf_hpp__is_dynamic_entry(struct perf_hpp_fmt *fmt)
-- 
2.6.4


  parent reply	other threads:[~2016-01-07  0:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-07  0:12 [PATCH v4 1/5] perf tools: Fix sorting of dynamic sort keys Namhyung Kim
2016-01-07  0:12 ` [PATCH v4 2/5] perf tools: Separate hpp->sort callback for " Namhyung Kim
2016-01-07  0:12 ` Namhyung Kim [this message]
2016-01-07  0:12 ` [PATCH v4 4/5] perf tools: Support dynamic sort keys for -F/--fields Namhyung Kim
2016-01-07  9:24   ` Jiri Olsa
2016-01-07 10:54     ` Namhyung Kim
2016-01-07  0:12 ` [PATCH v4 5/5] perf evlist: Add --trace-fields option to show trace fields Namhyung Kim
2016-01-08 17:22   ` Arnaldo Carvalho de Melo
2016-01-09 16:42   ` [tip:perf/core] " tip-bot for Namhyung Kim

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=1452125549-1511-3-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=andi@firstfloor.org \
    --cc=dsahern@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=wangnan0@huawei.com \
    /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