]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
perf hist: Improve srcfile sort key performance
authorNamhyung Kim <namhyung@kernel.org>
Thu, 15 Dec 2022 19:28:16 +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-9-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/sort.c

index 913045c5b2b28b461fdd35d81c27d936391b5ca7..c290539dcf437d0311285f3dc6c6c10f6663bc0f 100644 (file)
@@ -569,18 +569,41 @@ sort__srcfile_cmp(struct hist_entry *left, struct hist_entry *right)
        return strcmp(right->srcfile, left->srcfile);
 }
 
-static int hist_entry__srcfile_snprintf(struct hist_entry *he, char *bf,
-                                       size_t size, unsigned int width)
+static int64_t
+sort__srcfile_collapse(struct hist_entry *left, struct hist_entry *right)
+{
+       if (!left->srcfile)
+               left->srcfile = hist_entry__get_srcfile(left);
+       if (!right->srcfile)
+               right->srcfile = hist_entry__get_srcfile(right);
+
+       return strcmp(right->srcfile, left->srcfile);
+}
+
+static int64_t
+sort__srcfile_sort(struct hist_entry *left, struct hist_entry *right)
+{
+       return sort__srcfile_collapse(left, right);
+}
+
+static void sort__srcfile_init(struct hist_entry *he)
 {
        if (!he->srcfile)
                he->srcfile = hist_entry__get_srcfile(he);
+}
 
+static int hist_entry__srcfile_snprintf(struct hist_entry *he, char *bf,
+                                       size_t size, unsigned int width)
+{
        return repsep_snprintf(bf, size, "%-.*s", width, he->srcfile);
 }
 
 struct sort_entry sort_srcfile = {
        .se_header      = "Source File",
        .se_cmp         = sort__srcfile_cmp,
+       .se_collapse    = sort__srcfile_collapse,
+       .se_sort        = sort__srcfile_sort,
+       .se_init        = sort__srcfile_init,
        .se_snprintf    = hist_entry__srcfile_snprintf,
        .se_width_idx   = HISTC_SRCFILE,
 };