linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	linux-perf-users@vger.kernel.org, Andi Kleen <ak@linux.intel.com>,
	Milian Wolff <milian.wolff@kdab.com>,
	Leo Yan <leo.yan@linaro.org>
Subject: [PATCH 7/9] perf hist: Improve srcline sort key performance
Date: Thu, 15 Dec 2022 11:28:15 -0800	[thread overview]
Message-ID: <20221215192817.2734573-8-namhyung@kernel.org> (raw)
In-Reply-To: <20221215192817.2734573-1-namhyung@kernel.org>

The sort_entry->cmp() will be called for eventy sample data to find a
matching entry.  When it has 'srcline' sort key, that means it needs to
call addr2line or libbfd everytime.

This is not optimal because many samples will have same address and it
just can call addr2line once.  So postpone the actual srcline check to
the sort_entry->collpase() and compare addresses in ->cmp().

Also it needs to add ->init() callback to make sure it has srcline info.
If a sample has a unique data, chances are the entry can be sorted out
by other (previous) keys and callbacks in sort_srcline never called.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/sort.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index f6333b3dca35..913045c5b2b2 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -373,6 +373,18 @@ char *hist_entry__srcline(struct hist_entry *he)
 
 static int64_t
 sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+	int64_t ret;
+
+	ret = _sort__addr_cmp(left->ip, right->ip);
+	if (ret)
+		return ret;
+
+	return sort__dso_cmp(left, right);
+}
+
+static int64_t
+sort__srcline_collapse(struct hist_entry *left, struct hist_entry *right)
 {
 	if (!left->srcline)
 		left->srcline = hist_entry__srcline(left);
@@ -382,18 +394,31 @@ sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right)
 	return strcmp(right->srcline, left->srcline);
 }
 
-static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf,
-					size_t size, unsigned int width)
+static int64_t
+sort__srcline_sort(struct hist_entry *left, struct hist_entry *right)
+{
+	return sort__srcline_collapse(left, right);
+}
+
+static void
+sort__srcline_init(struct hist_entry *he)
 {
 	if (!he->srcline)
 		he->srcline = hist_entry__srcline(he);
+}
 
+static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf,
+					size_t size, unsigned int width)
+{
 	return repsep_snprintf(bf, size, "%-.*s", width, he->srcline);
 }
 
 struct sort_entry sort_srcline = {
 	.se_header	= "Source:Line",
 	.se_cmp		= sort__srcline_cmp,
+	.se_collapse	= sort__srcline_collapse,
+	.se_sort	= sort__srcline_sort,
+	.se_init	= sort__srcline_init,
 	.se_snprintf	= hist_entry__srcline_snprintf,
 	.se_width_idx	= HISTC_SRCLINE,
 };
-- 
2.39.0.314.g84b9a713c41-goog


  parent reply	other threads:[~2022-12-15 19:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-15 19:28 [PATCHSET 0/9] perf report: Improve srcline sort performance (v1) Namhyung Kim
2022-12-15 19:28 ` [PATCH 1/9] perf srcline: Do not return NULL for srcline Namhyung Kim
2022-12-15 19:28 ` [PATCH 2/9] perf report: Ignore SIGPIPE " Namhyung Kim
2022-12-16  7:24   ` Andi Kleen
2022-12-16 18:08     ` Namhyung Kim
2022-12-20 18:38       ` Arnaldo Carvalho de Melo
2022-12-15 19:28 ` [PATCH 3/9] perf symbol: Add filename__has_section() Namhyung Kim
2022-12-15 19:28 ` [PATCH 4/9] perf srcline: Skip srcline if .debug_line is missing Namhyung Kim
2022-12-15 19:28 ` [PATCH 5/9] perf srcline: Conditionally suppress addr2line warnings Namhyung Kim
2022-12-15 19:28 ` [PATCH 6/9] perf hist: Add perf_hpp_fmt->init() callback Namhyung Kim
2022-12-15 19:28 ` Namhyung Kim [this message]
2022-12-15 19:28 ` [PATCH 8/9] perf hist: Improve srcfile sort key performance Namhyung Kim
2022-12-15 19:28 ` [PATCH 9/9] perf hist: Improve srcline_{from,to} " Namhyung Kim
2022-12-15 20:28 ` [PATCHSET 0/9] perf report: Improve srcline sort performance (v1) Ian Rogers

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=20221215192817.2734573-8-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=milian.wolff@kdab.com \
    --cc=mingo@kernel.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).