1

perf parse-events: Tidy the setting of the default event name

Add comments. Pass ownership of the event name to save on a strdup.

Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Tested-by: Atish Patra <atishp@rivosinc.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Beeman Strong <beeman@rivosinc.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240416061533.921723-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Ian Rogers 2024-04-15 23:15:32 -07:00 committed by Arnaldo Carvalho de Melo
parent afd876bbdc
commit bb65ff7810
4 changed files with 19 additions and 7 deletions

View File

@ -1836,18 +1836,21 @@ int parse_events__modifier_event(struct parse_events_state *parse_state, void *l
return parse_events__modifier_list(parse_state, loc, list, mod, /*group=*/false); return parse_events__modifier_list(parse_state, loc, list, mod, /*group=*/false);
} }
int parse_events_name(struct list_head *list, const char *name) int parse_events__set_default_name(struct list_head *list, char *name)
{ {
struct evsel *evsel; struct evsel *evsel;
bool used_name = false;
__evlist__for_each_entry(list, evsel) { __evlist__for_each_entry(list, evsel) {
if (!evsel->name) { if (!evsel->name) {
evsel->name = strdup(name); evsel->name = used_name ? strdup(name) : name;
used_name = true;
if (!evsel->name) if (!evsel->name)
return -ENOMEM; return -ENOMEM;
} }
} }
if (!used_name)
free(name);
return 0; return 0;
} }

View File

@ -207,7 +207,7 @@ int parse_events__modifier_event(struct parse_events_state *parse_state, void *l
struct list_head *list, struct parse_events_modifier mod); struct list_head *list, struct parse_events_modifier mod);
int parse_events__modifier_group(struct parse_events_state *parse_state, void *loc, int parse_events__modifier_group(struct parse_events_state *parse_state, void *loc,
struct list_head *list, struct parse_events_modifier mod); struct list_head *list, struct parse_events_modifier mod);
int parse_events_name(struct list_head *list, const char *name); int parse_events__set_default_name(struct list_head *list, char *name);
int parse_events_add_tracepoint(struct list_head *list, int *idx, int parse_events_add_tracepoint(struct list_head *list, int *idx,
const char *sys, const char *event, const char *sys, const char *event,
struct parse_events_error *error, struct parse_events_error *error,

View File

@ -96,6 +96,11 @@ static int drv_str(yyscan_t scanner, int token)
return token; return token;
} }
/*
* Use yyless to return all the characaters to the input. Update the column for
* location debugging. If __alloc is non-zero set yylval to the text for the
* returned token's value.
*/
#define REWIND(__alloc) \ #define REWIND(__alloc) \
do { \ do { \
YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \ YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \

View File

@ -247,10 +247,14 @@ event_name
event_name: event_name:
PE_EVENT_NAME event_def PE_EVENT_NAME event_def
{ {
int err; /*
* When an event is parsed the text is rewound and the entire text of
* the event is set to the str of PE_EVENT_NAME token matched here. If
* no name was on an event via a term, set the name to the entire text
* taking ownership of the allocation.
*/
int err = parse_events__set_default_name($2, $1);
err = parse_events_name($2, $1);
free($1);
if (err) { if (err) {
free_list_evsel($2); free_list_evsel($2);
YYNOMEM; YYNOMEM;