]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
perf sort: Keep output fields in the same level
authorNamhyung Kim <namhyung@kernel.org>
Fri, 7 Mar 2025 08:08:27 +0000 (00:08 -0800)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 20 Mar 2025 16:17:56 +0000 (09:17 -0700)
This is useful for hierarchy output mode where the first level is
considered as output fields.  We want them in the same level so that it
can show only the remaining groups in the hierarchy.

Before:
  $ perf report -s overhead,sample,period,comm,dso -H --stdio
  ...
  #          Overhead  Samples / Period / Command / Shared Object
  # .................  ..........................................
  #
     100.00%           4035
        100.00%           3835883066
           100.00%           perf
               99.37%           perf
                0.50%           ld-linux-x86-64.so.2
                0.06%           [unknown]
                0.04%           libc.so.6
                0.02%           libLLVM-16.so.1

After:
  $ perf report -s overhead,sample,period,comm,dso -H --stdio
  ...
  #    Overhead       Samples        Period  Command / Shared Object
  # .......................................  .......................
  #
     100.00%          4035    3835883066     perf
         99.37%          4005    3811826223     perf
          0.50%            19      19210014     ld-linux-x86-64.so.2
          0.06%             8       2367089     [unknown]
          0.04%             2       1720336     libc.so.6
          0.02%             1        759404     libLLVM-16.so.1

Acked-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20250307080829.354947-1-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/sort.c

index 6f7696b11b97a9f976f41b6a2f7d90f0a9a27a1d..c51049087e4ebb6cf5e4cd12bf73d07bf1a31e7e 100644 (file)
@@ -3657,6 +3657,34 @@ int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
        return -ESRCH;
 }
 
+/* This should match with sort_dimension__add() above */
+static bool is_hpp_sort_key(const char *key)
+{
+       unsigned i;
+
+       for (i = 0; i < ARRAY_SIZE(arch_specific_sort_keys); i++) {
+               if (!strcmp(arch_specific_sort_keys[i], key) &&
+                   !arch_support_sort_key(key)) {
+                       return false;
+               }
+       }
+
+       for (i = 0; i < ARRAY_SIZE(common_sort_dimensions); i++) {
+               struct sort_dimension *sd = &common_sort_dimensions[i];
+
+               if (sd->name && !strncasecmp(key, sd->name, strlen(key)))
+                       return false;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(hpp_sort_dimensions); i++) {
+               struct hpp_dimension *hd = &hpp_sort_dimensions[i];
+
+               if (!strncasecmp(key, hd->name, strlen(key)))
+                       return true;
+       }
+       return false;
+}
+
 static int setup_sort_list(struct perf_hpp_list *list, char *str,
                           struct evlist *evlist)
 {
@@ -3664,7 +3692,9 @@ static int setup_sort_list(struct perf_hpp_list *list, char *str,
        int ret = 0;
        int level = 0;
        int next_level = 1;
+       int prev_level = 0;
        bool in_group = false;
+       bool prev_was_hpp = false;
 
        do {
                tok = str;
@@ -3685,6 +3715,19 @@ static int setup_sort_list(struct perf_hpp_list *list, char *str,
                }
 
                if (*tok) {
+                       if (is_hpp_sort_key(tok)) {
+                               /* keep output (hpp) sort keys in the same level */
+                               if (prev_was_hpp) {
+                                       bool next_same = (level == next_level);
+
+                                       level = prev_level;
+                                       next_level = next_same ? level : level+1;
+                               }
+                               prev_was_hpp = true;
+                       } else {
+                               prev_was_hpp = false;
+                       }
+
                        ret = sort_dimension__add(list, tok, evlist, level);
                        if (ret == -EINVAL) {
                                if (!cacheline_size() && !strncasecmp(tok, "dcacheline", strlen(tok)))
@@ -3696,6 +3739,7 @@ static int setup_sort_list(struct perf_hpp_list *list, char *str,
                                ui__error("Unknown --sort key: `%s'", tok);
                                break;
                        }
+                       prev_level = level;
                }
 
                level = next_level;