perf hist: Improve srcline_{from,to} sort key performance
authorNamhyung Kim <namhyung@kernel.org>
Thu, 15 Dec 2022 19:28:17 +0000 (11:28 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 21 Dec 2022 17:52:40 +0000 (14:52 -0300)
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>
tools/perf/util/sort.c

index c290539..e188f74 100644 (file)
@@ -433,6 +433,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,
 };
@@ -460,6 +481,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,
 };