Skip to content

Commit

Permalink
perf tools: Factor out copy_config_terms() and free_config_terms()
Browse files Browse the repository at this point in the history
Factor out copy_config_terms() and free_config_terms() so that they can
be reused.

Signed-off-by: Adrian Hunter <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: Jin Yao <[email protected]>
Cc: Kan Liang <[email protected]>
Link: https //lore.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
ahunter6 authored and acmel committed Sep 11, 2021
1 parent eb34363 commit a7d212f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
20 changes: 15 additions & 5 deletions tools/perf/util/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@ struct evsel *evsel__new_cycles(bool precise, __u32 type, __u64 config)
goto out;
}

static int evsel__copy_config_terms(struct evsel *dst, struct evsel *src)
int copy_config_terms(struct list_head *dst, struct list_head *src)
{
struct evsel_config_term *pos, *tmp;

list_for_each_entry(pos, &src->config_terms, list) {
list_for_each_entry(pos, src, list) {
tmp = malloc(sizeof(*tmp));
if (tmp == NULL)
return -ENOMEM;
Expand All @@ -350,11 +350,16 @@ static int evsel__copy_config_terms(struct evsel *dst, struct evsel *src)
return -ENOMEM;
}
}
list_add_tail(&tmp->list, &dst->config_terms);
list_add_tail(&tmp->list, dst);
}
return 0;
}

static int evsel__copy_config_terms(struct evsel *dst, struct evsel *src)
{
return copy_config_terms(&dst->config_terms, &src->config_terms);
}

/**
* evsel__clone - create a new evsel copied from @orig
* @orig: original evsel
Expand Down Expand Up @@ -1385,18 +1390,23 @@ int evsel__disable(struct evsel *evsel)
return err;
}

static void evsel__free_config_terms(struct evsel *evsel)
void free_config_terms(struct list_head *config_terms)
{
struct evsel_config_term *term, *h;

list_for_each_entry_safe(term, h, &evsel->config_terms, list) {
list_for_each_entry_safe(term, h, config_terms, list) {
list_del_init(&term->list);
if (term->free_str)
zfree(&term->val.str);
free(term);
}
}

static void evsel__free_config_terms(struct evsel *evsel)
{
free_config_terms(&evsel->config_terms);
}

void evsel__exit(struct evsel *evsel)
{
assert(list_empty(&evsel->core.node));
Expand Down
3 changes: 3 additions & 0 deletions tools/perf/util/evsel.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ static inline struct evsel *evsel__new(struct perf_event_attr *attr)
struct evsel *evsel__clone(struct evsel *orig);
struct evsel *evsel__newtp_idx(const char *sys, const char *name, int idx);

int copy_config_terms(struct list_head *dst, struct list_head *src);
void free_config_terms(struct list_head *config_terms);

/*
* Returns pointer with encoded error via <linux/err.h> interface.
*/
Expand Down
9 changes: 1 addition & 8 deletions tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,14 +1608,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
}

if (!parse_state->fake_pmu && perf_pmu__config(pmu, &attr, head_config, parse_state->error)) {
struct evsel_config_term *pos, *tmp;

list_for_each_entry_safe(pos, tmp, &config_terms, list) {
list_del_init(&pos->list);
if (pos->free_str)
zfree(&pos->val.str);
free(pos);
}
free_config_terms(&config_terms);
return -EINVAL;
}

Expand Down

0 comments on commit a7d212f

Please sign in to comment.