diff options
author | Jiri Olsa <jolsa@kernel.org> | 2019-07-21 13:24:34 +0200 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-07-29 23:34:45 +0200 |
commit | 651bf38ce10a65ef8efb901fc33187127c023e97 (patch) | |
tree | 0ed001cfe2255f31e97c423198d0b9406bf1466d /tools/perf/lib/evlist.c | |
parent | libperf: Add perf_evsel__new() function (diff) | |
download | linux-651bf38ce10a65ef8efb901fc33187127c023e97.tar.xz linux-651bf38ce10a65ef8efb901fc33187127c023e97.zip |
libperf: Add perf_evlist__for_each_evsel() iterator
Add a perf_evlist__for_each_evsel() macro to iterate perf_evsel objects
in evlist.
Introduce the perf_evlist__next() function to do that without exposing
'struct perf_evlist' internals.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20190721112506.12306-48-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/lib/evlist.c')
-rw-r--r-- | tools/perf/lib/evlist.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c index 0517deb4cb1c..979ee423490f 100644 --- a/tools/perf/lib/evlist.c +++ b/tools/perf/lib/evlist.c @@ -34,3 +34,23 @@ struct perf_evlist *perf_evlist__new(void) return evlist; } + +struct perf_evsel * +perf_evlist__next(struct perf_evlist *evlist, struct perf_evsel *prev) +{ + struct perf_evsel *next; + + if (!prev) { + next = list_first_entry(&evlist->entries, + struct perf_evsel, + node); + } else { + next = list_next_entry(prev, node); + } + + /* Empty list is noticed here so don't need checking on entry. */ + if (&next->node == &evlist->entries) + return NULL; + + return next; +} |