perf hist: Improve srcline_{from,to} sort key performance

Likewise, modify ->cmp() callback to compare sample address and map
address.  And add ->collapse() and ->sort() to check the actual
srcfile string.  Also add ->init() to make sure it has the srcfile.

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-10-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:17 -08:00 committed by Arnaldo Carvalho de Melo
parent f0cdde28fe
commit ad9ef9eb64
1 changed files with 42 additions and 0 deletions

View File

@ -432,6 +432,12 @@ static char *addr_map_symbol__srcline(struct addr_map_symbol *ams)
static int64_t
sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right)
{
return left->branch_info->from.addr - right->branch_info->from.addr;
}
static int64_t
sort__srcline_from_collapse(struct hist_entry *left, struct hist_entry *right)
{
if (!left->branch_info->srcline_from)
left->branch_info->srcline_from = addr_map_symbol__srcline(&left->branch_info->from);
@ -442,6 +448,18 @@ sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right)
return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from);
}
static int64_t
sort__srcline_from_sort(struct hist_entry *left, struct hist_entry *right)
{
return sort__srcline_from_collapse(left, right);
}
static void sort__srcline_from_init(struct hist_entry *he)
{
if (!he->branch_info->srcline_from)
he->branch_info->srcline_from = addr_map_symbol__srcline(&he->branch_info->from);
}
static int hist_entry__srcline_from_snprintf(struct hist_entry *he, char *bf,
size_t size, unsigned int width)
{
@ -451,6 +469,9 @@ static int hist_entry__srcline_from_snprintf(struct hist_entry *he, char *bf,
struct sort_entry sort_srcline_from = {
.se_header = "From Source:Line",
.se_cmp = sort__srcline_from_cmp,
.se_collapse = sort__srcline_from_collapse,
.se_sort = sort__srcline_from_sort,
.se_init = sort__srcline_from_init,
.se_snprintf = hist_entry__srcline_from_snprintf,
.se_width_idx = HISTC_SRCLINE_FROM,
};
@ -459,6 +480,12 @@ struct sort_entry sort_srcline_from = {
static int64_t
sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right)
{
return left->branch_info->to.addr - right->branch_info->to.addr;
}
static int64_t
sort__srcline_to_collapse(struct hist_entry *left, struct hist_entry *right)
{
if (!left->branch_info->srcline_to)
left->branch_info->srcline_to = addr_map_symbol__srcline(&left->branch_info->to);
@ -469,6 +496,18 @@ sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right)
return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to);
}
static int64_t
sort__srcline_to_sort(struct hist_entry *left, struct hist_entry *right)
{
return sort__srcline_to_collapse(left, right);
}
static void sort__srcline_to_init(struct hist_entry *he)
{
if (!he->branch_info->srcline_to)
he->branch_info->srcline_to = addr_map_symbol__srcline(&he->branch_info->to);
}
static int hist_entry__srcline_to_snprintf(struct hist_entry *he, char *bf,
size_t size, unsigned int width)
{
@ -478,6 +517,9 @@ static int hist_entry__srcline_to_snprintf(struct hist_entry *he, char *bf,
struct sort_entry sort_srcline_to = {
.se_header = "To Source:Line",
.se_cmp = sort__srcline_to_cmp,
.se_collapse = sort__srcline_to_collapse,
.se_sort = sort__srcline_to_sort,
.se_init = sort__srcline_to_init,
.se_snprintf = hist_entry__srcline_to_snprintf,
.se_width_idx = HISTC_SRCLINE_TO,
};