Commit ad9ef9eb authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo
Browse files

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: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarIan 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent f0cdde28
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -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,
};