perf evlist: Introduce evsel list accessors

To replace the longer list_entry constructs for things that are widely
used:

	perf_evlist__{first,last}(evlist)
	perf_evsel__next(evsel)
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Acked-by: default avatarNamhyung Kim <namhyung@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-ng7azq26wg1jd801qqpcozwp@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 63dab225
...@@ -172,12 +172,12 @@ static bool perf_evlist__equal(struct perf_evlist *evlist, ...@@ -172,12 +172,12 @@ static bool perf_evlist__equal(struct perf_evlist *evlist,
if (evlist->nr_entries != other->nr_entries) if (evlist->nr_entries != other->nr_entries)
return false; return false;
pair = list_entry(other->entries.next, struct perf_evsel, node); pair = perf_evlist__first(other);
list_for_each_entry(pos, &evlist->entries, node) { list_for_each_entry(pos, &evlist->entries, node) {
if (memcmp(&pos->attr, &pair->attr, sizeof(pos->attr) != 0)) if (memcmp(&pos->attr, &pair->attr, sizeof(pos->attr) != 0))
return false; return false;
pair = list_entry(pair->node.next, struct perf_evsel, node); pair = perf_evsel__next(pair);
} }
return true; return true;
......
...@@ -480,7 +480,7 @@ static int run_perf_stat(int argc __used, const char **argv) ...@@ -480,7 +480,7 @@ static int run_perf_stat(int argc __used, const char **argv)
if (group) if (group)
perf_evlist__set_leader(evsel_list); perf_evlist__set_leader(evsel_list);
first = list_entry(evsel_list->entries.next, struct perf_evsel, node); first = perf_evlist__first(evsel_list);
list_for_each_entry(counter, &evsel_list->entries, node) { list_for_each_entry(counter, &evsel_list->entries, node) {
if (create_perf_stat_counter(counter, first) < 0) { if (create_perf_stat_counter(counter, first) < 0) {
......
...@@ -710,7 +710,7 @@ static int test__PERF_RECORD(void) ...@@ -710,7 +710,7 @@ static int test__PERF_RECORD(void)
/* /*
* Config the evsels, setting attr->comm on the first one, etc. * Config the evsels, setting attr->comm on the first one, etc.
*/ */
evsel = list_entry(evlist->entries.next, struct perf_evsel, node); evsel = perf_evlist__first(evlist);
evsel->attr.sample_type |= PERF_SAMPLE_CPU; evsel->attr.sample_type |= PERF_SAMPLE_CPU;
evsel->attr.sample_type |= PERF_SAMPLE_TID; evsel->attr.sample_type |= PERF_SAMPLE_TID;
evsel->attr.sample_type |= PERF_SAMPLE_TIME; evsel->attr.sample_type |= PERF_SAMPLE_TIME;
......
...@@ -509,7 +509,7 @@ static void perf_top__handle_keypress(struct perf_top *top, int c) ...@@ -509,7 +509,7 @@ static void perf_top__handle_keypress(struct perf_top *top, int c)
prompt_integer(&counter, "Enter details event counter"); prompt_integer(&counter, "Enter details event counter");
if (counter >= top->evlist->nr_entries) { if (counter >= top->evlist->nr_entries) {
top->sym_evsel = list_entry(top->evlist->entries.next, struct perf_evsel, node); top->sym_evsel = perf_evlist__first(top->evlist);
fprintf(stderr, "Sorry, no such event, using %s.\n", perf_evsel__name(top->sym_evsel)); fprintf(stderr, "Sorry, no such event, using %s.\n", perf_evsel__name(top->sym_evsel));
sleep(1); sleep(1);
break; break;
...@@ -518,7 +518,7 @@ static void perf_top__handle_keypress(struct perf_top *top, int c) ...@@ -518,7 +518,7 @@ static void perf_top__handle_keypress(struct perf_top *top, int c)
if (top->sym_evsel->idx == counter) if (top->sym_evsel->idx == counter)
break; break;
} else } else
top->sym_evsel = list_entry(top->evlist->entries.next, struct perf_evsel, node); top->sym_evsel = perf_evlist__first(top->evlist);
break; break;
case 'f': case 'f':
prompt_integer(&top->count_filter, "Enter display event count filter"); prompt_integer(&top->count_filter, "Enter display event count filter");
...@@ -1326,7 +1326,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) ...@@ -1326,7 +1326,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
pos->attr.sample_period = top.default_interval; pos->attr.sample_period = top.default_interval;
} }
top.sym_evsel = list_entry(top.evlist->entries.next, struct perf_evsel, node); top.sym_evsel = perf_evlist__first(top.evlist);
symbol_conf.priv_size = sizeof(struct annotation); symbol_conf.priv_size = sizeof(struct annotation);
......
...@@ -57,7 +57,7 @@ void perf_evlist__config_attrs(struct perf_evlist *evlist, ...@@ -57,7 +57,7 @@ void perf_evlist__config_attrs(struct perf_evlist *evlist,
if (evlist->cpus->map[0] < 0) if (evlist->cpus->map[0] < 0)
opts->no_inherit = true; opts->no_inherit = true;
first = list_entry(evlist->entries.next, struct perf_evsel, node); first = perf_evlist__first(evlist);
list_for_each_entry(evsel, &evlist->entries, node) { list_for_each_entry(evsel, &evlist->entries, node) {
perf_evsel__config(evsel, opts, first); perf_evsel__config(evsel, opts, first);
...@@ -376,7 +376,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id) ...@@ -376,7 +376,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
int hash; int hash;
if (evlist->nr_entries == 1) if (evlist->nr_entries == 1)
return list_entry(evlist->entries.next, struct perf_evsel, node); return perf_evlist__first(evlist);
hash = hash_64(id, PERF_EVLIST__HLIST_BITS); hash = hash_64(id, PERF_EVLIST__HLIST_BITS);
head = &evlist->heads[hash]; head = &evlist->heads[hash];
...@@ -386,7 +386,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id) ...@@ -386,7 +386,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
return sid->evsel; return sid->evsel;
if (!perf_evlist__sample_id_all(evlist)) if (!perf_evlist__sample_id_all(evlist))
return list_entry(evlist->entries.next, struct perf_evsel, node); return perf_evlist__first(evlist);
return NULL; return NULL;
} }
...@@ -694,11 +694,9 @@ int perf_evlist__set_filters(struct perf_evlist *evlist) ...@@ -694,11 +694,9 @@ int perf_evlist__set_filters(struct perf_evlist *evlist)
return 0; return 0;
} }
bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist) bool perf_evlist__valid_sample_type(struct perf_evlist *evlist)
{ {
struct perf_evsel *pos, *first; struct perf_evsel *first = perf_evlist__first(evlist), *pos = first;
pos = first = list_entry(evlist->entries.next, struct perf_evsel, node);
list_for_each_entry_continue(pos, &evlist->entries, node) { list_for_each_entry_continue(pos, &evlist->entries, node) {
if (first->attr.sample_type != pos->attr.sample_type) if (first->attr.sample_type != pos->attr.sample_type)
...@@ -708,23 +706,19 @@ bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist) ...@@ -708,23 +706,19 @@ bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist)
return true; return true;
} }
u64 perf_evlist__sample_type(const struct perf_evlist *evlist) u64 perf_evlist__sample_type(struct perf_evlist *evlist)
{ {
struct perf_evsel *first; struct perf_evsel *first = perf_evlist__first(evlist);
first = list_entry(evlist->entries.next, struct perf_evsel, node);
return first->attr.sample_type; return first->attr.sample_type;
} }
u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist) u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist)
{ {
struct perf_evsel *first; struct perf_evsel *first = perf_evlist__first(evlist);
struct perf_sample *data; struct perf_sample *data;
u64 sample_type; u64 sample_type;
u16 size = 0; u16 size = 0;
first = list_entry(evlist->entries.next, struct perf_evsel, node);
if (!first->attr.sample_id_all) if (!first->attr.sample_id_all)
goto out; goto out;
...@@ -748,11 +742,9 @@ u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist) ...@@ -748,11 +742,9 @@ u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist)
return size; return size;
} }
bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist) bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist)
{ {
struct perf_evsel *pos, *first; struct perf_evsel *first = perf_evlist__first(evlist), *pos = first;
pos = first = list_entry(evlist->entries.next, struct perf_evsel, node);
list_for_each_entry_continue(pos, &evlist->entries, node) { list_for_each_entry_continue(pos, &evlist->entries, node) {
if (first->attr.sample_id_all != pos->attr.sample_id_all) if (first->attr.sample_id_all != pos->attr.sample_id_all)
...@@ -762,11 +754,9 @@ bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist) ...@@ -762,11 +754,9 @@ bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist)
return true; return true;
} }
bool perf_evlist__sample_id_all(const struct perf_evlist *evlist) bool perf_evlist__sample_id_all(struct perf_evlist *evlist)
{ {
struct perf_evsel *first; struct perf_evsel *first = perf_evlist__first(evlist);
first = list_entry(evlist->entries.next, struct perf_evsel, node);
return first->attr.sample_id_all; return first->attr.sample_id_all;
} }
...@@ -896,6 +886,6 @@ int perf_evlist__start_workload(struct perf_evlist *evlist) ...@@ -896,6 +886,6 @@ int perf_evlist__start_workload(struct perf_evlist *evlist)
int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event, int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
struct perf_sample *sample, bool swapped) struct perf_sample *sample, bool swapped)
{ {
struct perf_evsel *e = list_entry(evlist->entries.next, struct perf_evsel, node); struct perf_evsel *evsel = perf_evlist__first(evlist);
return perf_evsel__parse_sample(e, event, sample, swapped); return perf_evsel__parse_sample(evsel, event, sample, swapped);
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include "../perf.h" #include "../perf.h"
#include "event.h" #include "event.h"
#include "evsel.h"
#include "util.h" #include "util.h"
#include <unistd.h> #include <unistd.h>
...@@ -41,8 +42,6 @@ struct perf_evsel_str_handler { ...@@ -41,8 +42,6 @@ struct perf_evsel_str_handler {
void *handler; void *handler;
}; };
struct perf_evsel;
struct perf_evlist *perf_evlist__new(struct cpu_map *cpus, struct perf_evlist *perf_evlist__new(struct cpu_map *cpus,
struct thread_map *threads); struct thread_map *threads);
void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
...@@ -121,17 +120,27 @@ int perf_evlist__set_filters(struct perf_evlist *evlist); ...@@ -121,17 +120,27 @@ int perf_evlist__set_filters(struct perf_evlist *evlist);
void __perf_evlist__set_leader(struct list_head *list); void __perf_evlist__set_leader(struct list_head *list);
void perf_evlist__set_leader(struct perf_evlist *evlist); void perf_evlist__set_leader(struct perf_evlist *evlist);
u64 perf_evlist__sample_type(const struct perf_evlist *evlist); u64 perf_evlist__sample_type(struct perf_evlist *evlist);
bool perf_evlist__sample_id_all(const const struct perf_evlist *evlist); bool perf_evlist__sample_id_all(struct perf_evlist *evlist);
u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist); u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist);
int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event, int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
struct perf_sample *sample, bool swapped); struct perf_sample *sample, bool swapped);
bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist); bool perf_evlist__valid_sample_type(struct perf_evlist *evlist);
bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist); bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist);
void perf_evlist__splice_list_tail(struct perf_evlist *evlist, void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
struct list_head *list, struct list_head *list,
int nr_entries); int nr_entries);
static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
{
return list_entry(evlist->entries.next, struct perf_evsel, node);
}
static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist)
{
return list_entry(evlist->entries.prev, struct perf_evsel, node);
}
#endif /* __PERF_EVLIST_H */ #endif /* __PERF_EVLIST_H */
...@@ -184,4 +184,9 @@ void hists__init(struct hists *hists); ...@@ -184,4 +184,9 @@ void hists__init(struct hists *hists);
int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
struct perf_sample *sample, bool swapped); struct perf_sample *sample, bool swapped);
static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
{
return list_entry(evsel->node.next, struct perf_evsel, node);
}
#endif /* __PERF_EVSEL_H */ #endif /* __PERF_EVSEL_H */
...@@ -1689,7 +1689,7 @@ int perf_session__write_header(struct perf_session *session, ...@@ -1689,7 +1689,7 @@ int perf_session__write_header(struct perf_session *session,
lseek(fd, sizeof(f_header), SEEK_SET); lseek(fd, sizeof(f_header), SEEK_SET);
if (session->evlist != evlist) if (session->evlist != evlist)
pair = list_entry(session->evlist->entries.next, struct perf_evsel, node); pair = perf_evlist__first(session->evlist);
list_for_each_entry(attr, &evlist->entries, node) { list_for_each_entry(attr, &evlist->entries, node) {
attr->id_offset = lseek(fd, 0, SEEK_CUR); attr->id_offset = lseek(fd, 0, SEEK_CUR);
...@@ -1704,7 +1704,7 @@ int perf_session__write_header(struct perf_session *session, ...@@ -1704,7 +1704,7 @@ int perf_session__write_header(struct perf_session *session,
if (err < 0) if (err < 0)
goto out_err_write; goto out_err_write;
attr->ids += pair->ids; attr->ids += pair->ids;
pair = list_entry(pair->node.next, struct perf_evsel, node); pair = perf_evsel__next(pair);
} }
} }
......
This diff is collapsed.
...@@ -834,7 +834,7 @@ int parse_filter(const struct option *opt, const char *str, ...@@ -834,7 +834,7 @@ int parse_filter(const struct option *opt, const char *str,
struct perf_evsel *last = NULL; struct perf_evsel *last = NULL;
if (evlist->nr_entries > 0) if (evlist->nr_entries > 0)
last = list_entry(evlist->entries.prev, struct perf_evsel, node); last = perf_evlist__last(evlist);
if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) { if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) {
fprintf(stderr, fprintf(stderr,
......
...@@ -58,8 +58,7 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size) ...@@ -58,8 +58,7 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)
} }
if (top->evlist->nr_entries == 1) { if (top->evlist->nr_entries == 1) {
struct perf_evsel *first; struct perf_evsel *first = perf_evlist__first(top->evlist);
first = list_entry(top->evlist->entries.next, struct perf_evsel, node);
ret += SNPRINTF(bf + ret, size - ret, "%" PRIu64 "%s ", ret += SNPRINTF(bf + ret, size - ret, "%" PRIu64 "%s ",
(uint64_t)first->attr.sample_period, (uint64_t)first->attr.sample_period,
top->freq ? "Hz" : ""); top->freq ? "Hz" : "");
......
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