]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
perf parse-events: Minor tidy up of event_type helper
authorIan Rogers <irogers@google.com>
Thu, 10 Jul 2025 23:51:15 +0000 (16:51 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 11 Jul 2025 19:36:40 +0000 (12:36 -0700)
Add missing breakpoint and raw types. Avoid a switch, just use a
lookup array. Switch the type to unsigned to avoid checking negative
values.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250710235126.1086011-3-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/parse-events.c
tools/perf/util/parse-events.h

index 4cd64ffa4fcd6fe8c38d4fd68117eb9ad76bced5..a59ae5ca0f894bfc014b4d2782fcdb51e6749dab 100644 (file)
@@ -135,26 +135,21 @@ const struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = {
        },
 };
 
-const char *event_type(int type)
-{
-       switch (type) {
-       case PERF_TYPE_HARDWARE:
-               return "hardware";
-
-       case PERF_TYPE_SOFTWARE:
-               return "software";
-
-       case PERF_TYPE_TRACEPOINT:
-               return "tracepoint";
-
-       case PERF_TYPE_HW_CACHE:
-               return "hardware-cache";
+static const char *const event_types[] = {
+       [PERF_TYPE_HARDWARE]    = "hardware",
+       [PERF_TYPE_SOFTWARE]    = "software",
+       [PERF_TYPE_TRACEPOINT]  = "tracepoint",
+       [PERF_TYPE_HW_CACHE]    = "hardware-cache",
+       [PERF_TYPE_RAW]         = "raw",
+       [PERF_TYPE_BREAKPOINT]  = "breakpoint",
+};
 
-       default:
-               break;
-       }
+const char *event_type(size_t type)
+{
+       if (type >= PERF_TYPE_MAX)
+               return "unknown";
 
-       return "unknown";
+       return event_types[type];
 }
 
 static char *get_config_str(const struct parse_events_terms *head_terms,
index 1c20ed0879aab983a271cab752c1505966ba6cfa..b47bf2810112c4cacc546af529477d1025024b78 100644 (file)
@@ -21,7 +21,7 @@ struct option;
 struct perf_pmu;
 struct strbuf;
 
-const char *event_type(int type);
+const char *event_type(size_t type);
 
 /* Arguments encoded in opt->value. */
 struct parse_events_option_args {