diff options
author | Ian Rogers <irogers@google.com> | 2025-07-10 16:51:15 -0700 |
---|---|---|
committer | Namhyung Kim <namhyung@kernel.org> | 2025-07-11 12:36:40 -0700 |
commit | 679c098cd2db458b1899e4410150d41a550ec6d6 (patch) | |
tree | 91ec38288e814eb7e424965c772925e2a45e0d2f | |
parent | 28f5aa8184c9c9b8eab35fa3884c416fe75e88e4 (diff) |
perf parse-events: Minor tidy up of event_type helper
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>
-rw-r--r-- | tools/perf/util/parse-events.c | 31 | ||||
-rw-r--r-- | tools/perf/util/parse-events.h | 2 |
2 files changed, 14 insertions, 19 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 4cd64ffa4fcd..a59ae5ca0f89 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -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, diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 1c20ed0879aa..b47bf2810112 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -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 { |