Skip to content

Commit

Permalink
perf evlist: Introduce evsel list accessors
Browse files Browse the repository at this point in the history
To replace the longer list_entry constructs for things that are widely
used:

	perf_evlist__{first,last}(evlist)
	perf_evsel__next(evsel)

Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung 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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Aug 15, 2012
1 parent 63dab22 commit 0c21f73
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 125 deletions.
4 changes: 2 additions & 2 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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);

Expand Down
40 changes: 15 additions & 25 deletions tools/perf/util/evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)
Expand All @@ -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;

Expand All @@ -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)
Expand 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;
}

Expand Down Expand Up @@ -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);
}
23 changes: 16 additions & 7 deletions tools/perf/util/evlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdio.h>
#include "../perf.h"
#include "event.h"
#include "evsel.h"
#include "util.h"
#include <unistd.h>

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
5 changes: 5 additions & 0 deletions tools/perf/util/evsel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions tools/perf/util/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down
Loading

0 comments on commit 0c21f73

Please sign in to comment.