perf hist: Improve srcline sort key performance

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>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20221215192817.2734573-8-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Namhyung Kim 2022-12-15 11:28:15 -08:00 committed by Arnaldo Carvalho de Melo
parent cb6e92c764
commit ec222d7e7c
1 changed files with 27 additions and 2 deletions

View File

@ -373,6 +373,18 @@ char *hist_entry__srcline(struct hist_entry *he)
static int64_t static int64_t
sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right) 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) if (!left->srcline)
left->srcline = hist_entry__srcline(left); 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); return strcmp(right->srcline, left->srcline);
} }
static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf, static int64_t
size_t size, unsigned int width) 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) if (!he->srcline)
he->srcline = hist_entry__srcline(he); 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); return repsep_snprintf(bf, size, "%-.*s", width, he->srcline);
} }
struct sort_entry sort_srcline = { struct sort_entry sort_srcline = {
.se_header = "Source:Line", .se_header = "Source:Line",
.se_cmp = sort__srcline_cmp, .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_snprintf = hist_entry__srcline_snprintf,
.se_width_idx = HISTC_SRCLINE, .se_width_idx = HISTC_SRCLINE,
}; };