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: NJiri Olsa <jolsa@redhat.com>
Acked-by: NNamhyung 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: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 63dab225
......@@ -172,12 +172,12 @@ static bool perf_evlist__equal(struct perf_evlist *evlist,
if (evlist->nr_entries != other->nr_entries)
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) {
if (memcmp(&pos->attr, &pair->attr, sizeof(pos->attr) != 0))
return false;
pair = list_entry(pair->node.next, struct perf_evsel, node);
pair = perf_evsel__next(pair);
}
return true;
......
......@@ -480,7 +480,7 @@ static int run_perf_stat(int argc __used, const char **argv)
if (group)
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) {
if (create_perf_stat_counter(counter, first) < 0) {
......
......@@ -710,7 +710,7 @@ static int test__PERF_RECORD(void)
/*
* 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_TID;
evsel->attr.sample_type |= PERF_SAMPLE_TIME;
......
......@@ -509,7 +509,7 @@ static void perf_top__handle_keypress(struct perf_top *top, int c)
prompt_integer(&counter, "Enter details event counter");
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));
sleep(1);
break;
......@@ -518,7 +518,7 @@ static void perf_top__handle_keypress(struct perf_top *top, int c)
if (top->sym_evsel->idx == counter)
break;
} else
top->sym_evsel = list_entry(top->evlist->entries.next, struct perf_evsel, node);
top->sym_evsel = perf_evlist__first(top->evlist);
break;
case 'f':
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)
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);
......
......@@ -57,7 +57,7 @@ void perf_evlist__config_attrs(struct perf_evlist *evlist,
if (evlist->cpus->map[0] < 0)
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) {
perf_evsel__config(evsel, opts, first);
......@@ -376,7 +376,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
int hash;
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);
head = &evlist->heads[hash];
......@@ -386,7 +386,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
return sid->evsel;
if (!perf_evlist__sample_id_all(evlist))
return list_entry(evlist->entries.next, struct perf_evsel, node);
return perf_evlist__first(evlist);
return NULL;
}
......@@ -694,11 +694,9 @@ int perf_evlist__set_filters(struct perf_evlist *evlist)
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;
pos = first = list_entry(evlist->entries.next, struct perf_evsel, node);
struct perf_evsel *first = perf_evlist__first(evlist), *pos = first;
list_for_each_entry_continue(pos, &evlist->entries, node) {
if (first->attr.sample_type != pos->attr.sample_type)
......@@ -708,23 +706,19 @@ bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist)
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;
first = list_entry(evlist->entries.next, struct perf_evsel, node);
struct perf_evsel *first = perf_evlist__first(evlist);
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;
u64 sample_type;
u16 size = 0;
first = list_entry(evlist->entries.next, struct perf_evsel, node);
if (!first->attr.sample_id_all)
goto out;
......@@ -748,11 +742,9 @@ u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist)
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;
pos = first = list_entry(evlist->entries.next, struct perf_evsel, node);
struct perf_evsel *first = perf_evlist__first(evlist), *pos = first;
list_for_each_entry_continue(pos, &evlist->entries, node) {
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)
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;
first = list_entry(evlist->entries.next, struct perf_evsel, node);
struct perf_evsel *first = perf_evlist__first(evlist);
return first->attr.sample_id_all;
}
......@@ -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,
struct perf_sample *sample, bool swapped)
{
struct perf_evsel *e = list_entry(evlist->entries.next, struct perf_evsel, node);
return perf_evsel__parse_sample(e, event, sample, swapped);
struct perf_evsel *evsel = perf_evlist__first(evlist);
return perf_evsel__parse_sample(evsel, event, sample, swapped);
}
......@@ -5,6 +5,7 @@
#include <stdio.h>
#include "../perf.h"
#include "event.h"
#include "evsel.h"
#include "util.h"
#include <unistd.h>
......@@ -41,8 +42,6 @@ struct perf_evsel_str_handler {
void *handler;
};
struct perf_evsel;
struct perf_evlist *perf_evlist__new(struct cpu_map *cpus,
struct thread_map *threads);
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);
void __perf_evlist__set_leader(struct list_head *list);
void perf_evlist__set_leader(struct perf_evlist *evlist);
u64 perf_evlist__sample_type(const struct perf_evlist *evlist);
bool perf_evlist__sample_id_all(const const struct perf_evlist *evlist);
u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist);
u64 perf_evlist__sample_type(struct perf_evlist *evlist);
bool perf_evlist__sample_id_all(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,
struct perf_sample *sample, bool swapped);
bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist);
bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist);
bool perf_evlist__valid_sample_type(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,
struct list_head *list,
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 */
......@@ -184,4 +184,9 @@ void hists__init(struct hists *hists);
int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
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 */
......@@ -1689,7 +1689,7 @@ int perf_session__write_header(struct perf_session *session,
lseek(fd, sizeof(f_header), SEEK_SET);
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) {
attr->id_offset = lseek(fd, 0, SEEK_CUR);
......@@ -1704,7 +1704,7 @@ int perf_session__write_header(struct perf_session *session,
if (err < 0)
goto out_err_write;
attr->ids += pair->ids;
pair = list_entry(pair->node.next, struct perf_evsel, node);
pair = perf_evsel__next(pair);
}
}
......
此差异已折叠。
......@@ -834,7 +834,7 @@ int parse_filter(const struct option *opt, const char *str,
struct perf_evsel *last = NULL;
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) {
fprintf(stderr,
......
......@@ -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) {
struct perf_evsel *first;
first = list_entry(top->evlist->entries.next, struct perf_evsel, node);
struct perf_evsel *first = perf_evlist__first(top->evlist);
ret += SNPRINTF(bf + ret, size - ret, "%" PRIu64 "%s ",
(uint64_t)first->attr.sample_period,
top->freq ? "Hz" : "");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册