]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf report: Update sort key state from -F option
authorNamhyung Kim <namhyung@kernel.org>
Wed, 10 Dec 2025 02:33:27 +0000 (18:33 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 17 Dec 2025 12:30:37 +0000 (09:30 -0300)
Factor out __sort_dimension__update() so that it can be called from -s
and -F option parsing logics.  Otherwise the following command cannot go
into the annotation mode.

  $ perf report -F overhead,type,sym

  Warning: Annotation is only available for symbolic views, include "sym*" in --sort to use it.

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/sort.c

index 3d4b68fd6e44543f3038ada67da90df3db3c8488..f963d61ac166f9b3f16069b07aa4b0dacfb65c02 100644 (file)
@@ -3538,6 +3538,56 @@ out:
        return ret;
 }
 
+static int __sort_dimension__update(struct sort_dimension *sd,
+                                   struct perf_hpp_list *list)
+{
+       if (sd->entry == &sort_parent && parent_pattern) {
+               int ret = regcomp(&parent_regex, parent_pattern, REG_EXTENDED);
+               if (ret) {
+                       char err[BUFSIZ];
+
+                       regerror(ret, &parent_regex, err, sizeof(err));
+                       pr_err("Invalid regex: %s\n%s", parent_pattern, err);
+                       return -EINVAL;
+               }
+               list->parent = 1;
+       } else if (sd->entry == &sort_sym) {
+               list->sym = 1;
+               /*
+                * perf diff displays the performance difference amongst
+                * two or more perf.data files. Those files could come
+                * from different binaries. So we should not compare
+                * their ips, but the name of symbol.
+                */
+               if (sort__mode == SORT_MODE__DIFF)
+                       sd->entry->se_collapse = sort__sym_sort;
+
+       } else if (sd->entry == &sort_sym_offset) {
+               list->sym = 1;
+       } else if (sd->entry == &sort_dso) {
+               list->dso = 1;
+       } else if (sd->entry == &sort_socket) {
+               list->socket = 1;
+       } else if (sd->entry == &sort_thread) {
+               list->thread = 1;
+       } else if (sd->entry == &sort_comm) {
+               list->comm = 1;
+       } else if (sd->entry == &sort_type_offset) {
+               symbol_conf.annotate_data_member = true;
+       } else if (sd->entry == &sort_sym_from || sd->entry == &sort_sym_to) {
+               list->sym = 1;
+       } else if (sd->entry == &sort_mem_dcacheline && cacheline_size() == 0) {
+               return -EINVAL;
+       } else if (sd->entry == &sort_mem_daddr_sym) {
+               list->sym = 1;
+       }
+
+       if (sd->entry->se_collapse)
+               list->need_collapse = 1;
+
+       return 0;
+}
+
 static int __sort_dimension__add(struct sort_dimension *sd,
                                 struct perf_hpp_list *list,
                                 int level)
@@ -3548,8 +3598,8 @@ static int __sort_dimension__add(struct sort_dimension *sd,
        if (__sort_dimension__add_hpp_sort(sd, list, level) < 0)
                return -1;
 
-       if (sd->entry->se_collapse)
-               list->need_collapse = 1;
+       if (__sort_dimension__update(sd, list) < 0)
+               return -1;
 
        sd->taken = 1;
 
@@ -3585,8 +3635,8 @@ static int __sort_dimension__add_output(struct perf_hpp_list *list,
        if (__sort_dimension__add_hpp_output(sd, list, level) < 0)
                return -1;
 
-       if (sd->entry->se_collapse)
-               list->need_collapse = 1;
+       if (__sort_dimension__update(sd, list) < 0)
+               return -1;
 
        sd->taken = 1;
        return 0;
@@ -3651,39 +3701,6 @@ int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
                                sort_dimension_add_dynamic_header(sd, env);
                }
 
-               if (sd->entry == &sort_parent && parent_pattern) {
-                       int ret = regcomp(&parent_regex, parent_pattern, REG_EXTENDED);
-                       if (ret) {
-                               char err[BUFSIZ];
-
-                               regerror(ret, &parent_regex, err, sizeof(err));
-                               pr_err("Invalid regex: %s\n%s", parent_pattern, err);
-                               return -EINVAL;
-                       }
-                       list->parent = 1;
-               } else if (sd->entry == &sort_sym) {
-                       list->sym = 1;
-                       /*
-                        * perf diff displays the performance difference amongst
-                        * two or more perf.data files. Those files could come
-                        * from different binaries. So we should not compare
-                        * their ips, but the name of symbol.
-                        */
-                       if (sort__mode == SORT_MODE__DIFF)
-                               sd->entry->se_collapse = sort__sym_sort;
-
-               } else if (sd->entry == &sort_dso) {
-                       list->dso = 1;
-               } else if (sd->entry == &sort_socket) {
-                       list->socket = 1;
-               } else if (sd->entry == &sort_thread) {
-                       list->thread = 1;
-               } else if (sd->entry == &sort_comm) {
-                       list->comm = 1;
-               } else if (sd->entry == &sort_type_offset) {
-                       symbol_conf.annotate_data_member = true;
-               }
-
                return __sort_dimension__add(sd, list, level);
        }
 
@@ -3702,9 +3719,6 @@ int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
                                    strlen(tok)))
                        return -EINVAL;
 
-               if (sd->entry == &sort_sym_from || sd->entry == &sort_sym_to)
-                       list->sym = 1;
-
                __sort_dimension__add(sd, list, level);
                return 0;
        }
@@ -3718,12 +3732,6 @@ int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
                if (sort__mode != SORT_MODE__MEMORY)
                        return -EINVAL;
 
-               if (sd->entry == &sort_mem_dcacheline && cacheline_size() == 0)
-                       return -EINVAL;
-
-               if (sd->entry == &sort_mem_daddr_sym)
-                       list->sym = 1;
-
                __sort_dimension__add(sd, list, level);
                return 0;
        }