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>
This commit is contained in:
Ian Rogers
2025-07-10 16:51:15 -07:00
committed by Namhyung Kim
parent 28f5aa8184
commit 679c098cd2
2 changed files with 14 additions and 19 deletions

View File

@@ -135,26 +135,21 @@ const struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = {
},
};
const char *event_type(int type)
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",
};
const char *event_type(size_t type)
{
switch (type) {
case PERF_TYPE_HARDWARE:
return "hardware";
if (type >= PERF_TYPE_MAX)
return "unknown";
case PERF_TYPE_SOFTWARE:
return "software";
case PERF_TYPE_TRACEPOINT:
return "tracepoint";
case PERF_TYPE_HW_CACHE:
return "hardware-cache";
default:
break;
}
return "unknown";
return event_types[type];
}
static char *get_config_str(const struct parse_events_terms *head_terms,

View 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 {