]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf evsel: Assign abbr name for the branch counter events
authorKan Liang <kan.liang@linux.intel.com>
Tue, 13 Aug 2024 16:02:04 +0000 (09:02 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 14 Aug 2024 13:20:40 +0000 (10:20 -0300)
There could be several branch counter events. If perf tool output the
result via the format "event name + a number", the line could be very
long and hard to read.

An abbreviation is introduced to replace the full event name in the
display. The abbreviation starts from 'A' to 'Z9', which can support
up to 286 events. The same abbreviation will be assigned if the same
events are found in the evlist. The next patch will utilize the
abbreviation name to show the branch counter events in the output.

Reviewed-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240813160208.2493643-6-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evlist.c
tools/perf/util/evsel.h

index 68bbd3ea771b482e3e87b4be6d13dc5e9316cf3a..c0379fa1ccfee4e22431819042cdb20e3aa4b568 100644 (file)
@@ -33,6 +33,7 @@
 #include "util/bpf-filter.h"
 #include "util/stat.h"
 #include "util/util.h"
+#include "util/env.h"
 #include "util/intel-tpebs.h"
 #include <signal.h>
 #include <unistd.h>
@@ -1265,15 +1266,67 @@ u64 evlist__combined_branch_type(struct evlist *evlist)
        return branch_type;
 }
 
+static struct evsel *
+evlist__find_dup_event_from_prev(struct evlist *evlist, struct evsel *event)
+{
+       struct evsel *pos;
+
+       evlist__for_each_entry(evlist, pos) {
+               if (event == pos)
+                       break;
+               if ((pos->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS) &&
+                   !strcmp(pos->name, event->name))
+                       return pos;
+       }
+       return NULL;
+}
+
+#define MAX_NR_ABBR_NAME       (26 * 11)
+
+/*
+ * The abbr name is from A to Z9. If the number of event
+ * which requires the branch counter > MAX_NR_ABBR_NAME,
+ * return NA.
+ */
+static void evlist__new_abbr_name(char *name)
+{
+       static int idx;
+       int i = idx / 26;
+
+       if (idx >= MAX_NR_ABBR_NAME) {
+               name[0] = 'N';
+               name[1] = 'A';
+               name[2] = '\0';
+               return;
+       }
+
+       name[0] = 'A' + (idx % 26);
+
+       if (!i)
+               name[1] = '\0';
+       else {
+               name[1] = '0' + i - 1;
+               name[2] = '\0';
+       }
+
+       idx++;
+}
+
 void evlist__update_br_cntr(struct evlist *evlist)
 {
-       struct evsel *evsel;
+       struct evsel *evsel, *dup;
        int i = 0;
 
        evlist__for_each_entry(evlist, evsel) {
                if (evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS) {
                        evsel->br_cntr_idx = i++;
                        evsel__leader(evsel)->br_cntr_nr++;
+
+                       dup = evlist__find_dup_event_from_prev(evlist, evsel);
+                       if (dup)
+                               memcpy(evsel->abbr_name, dup->abbr_name, 3 * sizeof(char));
+                       else
+                               evlist__new_abbr_name(evsel->abbr_name);
                }
        }
        evlist->nr_br_cntr = i;
index a393dae1dc967718243c6f8417da310e784f2d62..4316992f6a693231415f3f87be4e3fd98020f713 100644 (file)
@@ -153,9 +153,15 @@ struct evsel {
         * br_cntr_idx: The idx of the branch counter event in the evlist
         * br_cntr_nr:  The number of the branch counter event in the group
         *              (Only available for the leader event)
+        * abbr_name:   The abbreviation name assigned to an event which is
+        *              logged by the branch counter.
+        *              The abbr name is from A to Z9. NA is applied if out
+        *              of the range.
         */
        int                     br_cntr_idx;
        int                     br_cntr_nr;
+       char                    abbr_name[3];
+
        /*
         * bpf_counter_ops serves two use cases:
         *   1. perf-stat -b          counting events used byBPF programs