Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Ian Rogers and committed by
Namhyung Kim
679c098c 28f5aa81

+14 -19
+13 -18
tools/perf/util/parse-events.c
··· 135 135 }, 136 136 }; 137 137 138 - const char *event_type(int type) 138 + static const char *const event_types[] = { 139 + [PERF_TYPE_HARDWARE] = "hardware", 140 + [PERF_TYPE_SOFTWARE] = "software", 141 + [PERF_TYPE_TRACEPOINT] = "tracepoint", 142 + [PERF_TYPE_HW_CACHE] = "hardware-cache", 143 + [PERF_TYPE_RAW] = "raw", 144 + [PERF_TYPE_BREAKPOINT] = "breakpoint", 145 + }; 146 + 147 + const char *event_type(size_t type) 139 148 { 140 - switch (type) { 141 - case PERF_TYPE_HARDWARE: 142 - return "hardware"; 149 + if (type >= PERF_TYPE_MAX) 150 + return "unknown"; 143 151 144 - case PERF_TYPE_SOFTWARE: 145 - return "software"; 146 - 147 - case PERF_TYPE_TRACEPOINT: 148 - return "tracepoint"; 149 - 150 - case PERF_TYPE_HW_CACHE: 151 - return "hardware-cache"; 152 - 153 - default: 154 - break; 155 - } 156 - 157 - return "unknown"; 152 + return event_types[type]; 158 153 } 159 154 160 155 static char *get_config_str(const struct parse_events_terms *head_terms,
+1 -1
tools/perf/util/parse-events.h
··· 21 21 struct perf_pmu; 22 22 struct strbuf; 23 23 24 - const char *event_type(int type); 24 + const char *event_type(size_t type); 25 25 26 26 /* Arguments encoded in opt->value. */ 27 27 struct parse_events_option_args {