Commit 696f27c9 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

libperf: Introduce perf_evlist__purge()

Add a static perf_evlist__purge() function to purge evsels from a evlist.

Add also perf_evlist__for_each_entry_safe() which is used by
perf_evlist__purge().
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20191007125344.14268-26-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 93dd6e28
...@@ -109,6 +109,18 @@ perf_evlist__next(struct perf_evlist *evlist, struct perf_evsel *prev) ...@@ -109,6 +109,18 @@ perf_evlist__next(struct perf_evlist *evlist, struct perf_evsel *prev)
return next; return next;
} }
static void perf_evlist__purge(struct perf_evlist *evlist)
{
struct perf_evsel *pos, *n;
perf_evlist__for_each_entry_safe(evlist, n, pos) {
list_del_init(&pos->node);
perf_evsel__delete(pos);
}
evlist->nr_entries = 0;
}
void perf_evlist__exit(struct perf_evlist *evlist) void perf_evlist__exit(struct perf_evlist *evlist)
{ {
perf_cpu_map__put(evlist->cpus); perf_cpu_map__put(evlist->cpus);
...@@ -125,6 +137,7 @@ void perf_evlist__delete(struct perf_evlist *evlist) ...@@ -125,6 +137,7 @@ void perf_evlist__delete(struct perf_evlist *evlist)
perf_evlist__munmap(evlist); perf_evlist__munmap(evlist);
perf_evlist__close(evlist); perf_evlist__close(evlist);
perf_evlist__purge(evlist);
perf_evlist__exit(evlist); perf_evlist__exit(evlist);
free(evlist); free(evlist);
} }
......
...@@ -82,6 +82,24 @@ void perf_evlist__exit(struct perf_evlist *evlist); ...@@ -82,6 +82,24 @@ void perf_evlist__exit(struct perf_evlist *evlist);
#define perf_evlist__for_each_entry_reverse(evlist, evsel) \ #define perf_evlist__for_each_entry_reverse(evlist, evsel) \
__perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel) __perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel)
/**
* __perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
* @list: list_head instance to iterate
* @tmp: struct evsel temp iterator
* @evsel: struct evsel iterator
*/
#define __perf_evlist__for_each_entry_safe(list, tmp, evsel) \
list_for_each_entry_safe(evsel, tmp, list, node)
/**
* perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
* @evlist: evlist instance to iterate
* @evsel: struct evsel iterator
* @tmp: struct evsel temp iterator
*/
#define perf_evlist__for_each_entry_safe(evlist, tmp, evsel) \
__perf_evlist__for_each_entry_safe(&(evlist)->entries, tmp, evsel)
static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist) static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
{ {
return list_entry(evlist->entries.next, struct perf_evsel, node); return list_entry(evlist->entries.next, struct perf_evsel, node);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment