perf evlist: Introduce evlist__for_each() & friends

For the common evsel list traversal, so that it becomes more compact.

Use the opportunity to start ditching the 'perf_' from 'perf_evlist__',
as discussed, as the whole conversion touches a lot of places, lets do
it piecemeal when we have the chance due to other work, like in this
case.

Cc: Adrian Hunter <adrian.hunter@intel.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@kernel.org>
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-qnkx7dzm2h6m6uptkfk03ni6@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2014-01-10 10:37:27 -03:00
Родитель f6d8b0571c
Коммит 0050f7aa18
24 изменённых файлов: 151 добавлений и 86 удалений

Просмотреть файл

@ -232,7 +232,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
perf_session__fprintf_dsos(session, stdout); perf_session__fprintf_dsos(session, stdout);
total_nr_samples = 0; total_nr_samples = 0;
list_for_each_entry(pos, &session->evlist->entries, node) { evlist__for_each(session->evlist, pos) {
struct hists *hists = &pos->hists; struct hists *hists = &pos->hists;
u32 nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE]; u32 nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];

Просмотреть файл

@ -356,9 +356,10 @@ static struct perf_evsel *evsel_match(struct perf_evsel *evsel,
{ {
struct perf_evsel *e; struct perf_evsel *e;
list_for_each_entry(e, &evlist->entries, node) evlist__for_each(evlist, e) {
if (perf_evsel__match2(evsel, e)) if (perf_evsel__match2(evsel, e))
return e; return e;
}
return NULL; return NULL;
} }
@ -367,7 +368,7 @@ static void perf_evlist__collapse_resort(struct perf_evlist *evlist)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
struct hists *hists = &evsel->hists; struct hists *hists = &evsel->hists;
hists__collapse_resort(hists, NULL); hists__collapse_resort(hists, NULL);
@ -614,7 +615,7 @@ static void data_process(void)
struct perf_evsel *evsel_base; struct perf_evsel *evsel_base;
bool first = true; bool first = true;
list_for_each_entry(evsel_base, &evlist_base->entries, node) { evlist__for_each(evlist_base, evsel_base) {
struct data__file *d; struct data__file *d;
int i; int i;

Просмотреть файл

@ -29,7 +29,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
if (session == NULL) if (session == NULL)
return -ENOMEM; return -ENOMEM;
list_for_each_entry(pos, &session->evlist->entries, node) evlist__for_each(session->evlist, pos)
perf_evsel__fprintf(pos, details, stdout); perf_evsel__fprintf(pos, details, stdout);
perf_session__delete(session); perf_session__delete(session);

Просмотреть файл

@ -369,7 +369,7 @@ static int __cmd_inject(struct perf_inject *inject)
inject->tool.ordered_samples = true; inject->tool.ordered_samples = true;
list_for_each_entry(evsel, &session->evlist->entries, node) { evlist__for_each(session->evlist, evsel) {
const char *name = perf_evsel__name(evsel); const char *name = perf_evsel__name(evsel);
if (!strcmp(name, "sched:sched_switch")) { if (!strcmp(name, "sched:sched_switch")) {

Просмотреть файл

@ -1174,7 +1174,7 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)
* Note: exclude_{guest,host} do not apply here. * Note: exclude_{guest,host} do not apply here.
* This command processes KVM tracepoints from host only * This command processes KVM tracepoints from host only
*/ */
list_for_each_entry(pos, &evlist->entries, node) { evlist__for_each(evlist, pos) {
struct perf_event_attr *attr = &pos->attr; struct perf_event_attr *attr = &pos->attr;
/* make sure these *are* set */ /* make sure these *are* set */

Просмотреть файл

@ -183,7 +183,7 @@ static int record__open(struct record *rec)
perf_evlist__config(evlist, opts); perf_evlist__config(evlist, opts);
list_for_each_entry(pos, &evlist->entries, node) { evlist__for_each(evlist, pos) {
try_again: try_again:
if (perf_evsel__open(pos, evlist->cpus, evlist->threads) < 0) { if (perf_evsel__open(pos, evlist->cpus, evlist->threads) < 0) {
if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) { if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) {

Просмотреть файл

@ -384,7 +384,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
{ {
struct perf_evsel *pos; struct perf_evsel *pos;
list_for_each_entry(pos, &evlist->entries, node) { evlist__for_each(evlist, pos) {
struct hists *hists = &pos->hists; struct hists *hists = &pos->hists;
const char *evname = perf_evsel__name(pos); const char *evname = perf_evsel__name(pos);
@ -495,7 +495,7 @@ static u64 report__collapse_hists(struct report *rep)
* Count number of histogram entries to use when showing progress, * Count number of histogram entries to use when showing progress,
* reusing nr_samples variable. * reusing nr_samples variable.
*/ */
list_for_each_entry(pos, &rep->session->evlist->entries, node) evlist__for_each(rep->session->evlist, pos)
nr_samples += pos->hists.nr_entries; nr_samples += pos->hists.nr_entries;
ui_progress__init(&prog, nr_samples, "Merging related events..."); ui_progress__init(&prog, nr_samples, "Merging related events...");
@ -505,7 +505,7 @@ static u64 report__collapse_hists(struct report *rep)
*/ */
nr_samples = 0; nr_samples = 0;
list_for_each_entry(pos, &rep->session->evlist->entries, node) { evlist__for_each(rep->session->evlist, pos) {
struct hists *hists = &pos->hists; struct hists *hists = &pos->hists;
if (pos->idx == 0) if (pos->idx == 0)
@ -582,7 +582,7 @@ static int __cmd_report(struct report *rep)
return 0; return 0;
} }
list_for_each_entry(pos, &session->evlist->entries, node) evlist__for_each(session->evlist, pos)
hists__output_resort(&pos->hists); hists__output_resort(&pos->hists);
return report__browse_hists(rep); return report__browse_hists(rep);

Просмотреть файл

@ -603,7 +603,7 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
if (evsel->attr.type >= PERF_TYPE_MAX) if (evsel->attr.type >= PERF_TYPE_MAX)
return 0; return 0;
list_for_each_entry(pos, &evlist->entries, node) { evlist__for_each(evlist, pos) {
if (pos->attr.type == evsel->attr.type && pos != evsel) if (pos->attr.type == evsel->attr.type && pos != evsel)
return 0; return 0;
} }
@ -1309,8 +1309,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
snprintf(evname, len + 1, "%s", p); snprintf(evname, len + 1, "%s", p);
match = 0; match = 0;
list_for_each_entry(pos, evlist__for_each(session->evlist, pos) {
&session->evlist->entries, node) {
if (!strcmp(perf_evsel__name(pos), evname)) { if (!strcmp(perf_evsel__name(pos), evname)) {
match = 1; match = 1;
break; break;

Просмотреть файл

@ -214,7 +214,7 @@ static void perf_evlist__free_stats(struct perf_evlist *evlist)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
perf_evsel__free_stat_priv(evsel); perf_evsel__free_stat_priv(evsel);
perf_evsel__free_counts(evsel); perf_evsel__free_counts(evsel);
perf_evsel__free_prev_raw_counts(evsel); perf_evsel__free_prev_raw_counts(evsel);
@ -225,7 +225,7 @@ static int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
if (perf_evsel__alloc_stat_priv(evsel) < 0 || if (perf_evsel__alloc_stat_priv(evsel) < 0 ||
perf_evsel__alloc_counts(evsel, perf_evsel__nr_cpus(evsel)) < 0 || perf_evsel__alloc_counts(evsel, perf_evsel__nr_cpus(evsel)) < 0 ||
(alloc_raw && perf_evsel__alloc_prev_raw_counts(evsel) < 0)) (alloc_raw && perf_evsel__alloc_prev_raw_counts(evsel) < 0))
@ -259,7 +259,7 @@ static void perf_stat__reset_stats(struct perf_evlist *evlist)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
perf_evsel__reset_stat_priv(evsel); perf_evsel__reset_stat_priv(evsel);
perf_evsel__reset_counts(evsel, perf_evsel__nr_cpus(evsel)); perf_evsel__reset_counts(evsel, perf_evsel__nr_cpus(evsel));
} }
@ -326,13 +326,13 @@ static struct perf_evsel *nth_evsel(int n)
/* Assumes this only called when evsel_list does not change anymore. */ /* Assumes this only called when evsel_list does not change anymore. */
if (!array) { if (!array) {
list_for_each_entry(ev, &evsel_list->entries, node) evlist__for_each(evsel_list, ev)
array_len++; array_len++;
array = malloc(array_len * sizeof(void *)); array = malloc(array_len * sizeof(void *));
if (!array) if (!array)
exit(ENOMEM); exit(ENOMEM);
j = 0; j = 0;
list_for_each_entry(ev, &evsel_list->entries, node) evlist__for_each(evsel_list, ev)
array[j++] = ev; array[j++] = ev;
} }
if (n < array_len) if (n < array_len)
@ -440,13 +440,13 @@ static void print_interval(void)
char prefix[64]; char prefix[64];
if (aggr_mode == AGGR_GLOBAL) { if (aggr_mode == AGGR_GLOBAL) {
list_for_each_entry(counter, &evsel_list->entries, node) { evlist__for_each(evsel_list, counter) {
ps = counter->priv; ps = counter->priv;
memset(ps->res_stats, 0, sizeof(ps->res_stats)); memset(ps->res_stats, 0, sizeof(ps->res_stats));
read_counter_aggr(counter); read_counter_aggr(counter);
} }
} else { } else {
list_for_each_entry(counter, &evsel_list->entries, node) { evlist__for_each(evsel_list, counter) {
ps = counter->priv; ps = counter->priv;
memset(ps->res_stats, 0, sizeof(ps->res_stats)); memset(ps->res_stats, 0, sizeof(ps->res_stats));
read_counter(counter); read_counter(counter);
@ -483,12 +483,12 @@ static void print_interval(void)
print_aggr(prefix); print_aggr(prefix);
break; break;
case AGGR_NONE: case AGGR_NONE:
list_for_each_entry(counter, &evsel_list->entries, node) evlist__for_each(evsel_list, counter)
print_counter(counter, prefix); print_counter(counter, prefix);
break; break;
case AGGR_GLOBAL: case AGGR_GLOBAL:
default: default:
list_for_each_entry(counter, &evsel_list->entries, node) evlist__for_each(evsel_list, counter)
print_counter_aggr(counter, prefix); print_counter_aggr(counter, prefix);
} }
@ -504,7 +504,7 @@ static void handle_initial_delay(void)
nthreads = thread_map__nr(evsel_list->threads); nthreads = thread_map__nr(evsel_list->threads);
usleep(initial_delay * 1000); usleep(initial_delay * 1000);
list_for_each_entry(counter, &evsel_list->entries, node) evlist__for_each(evsel_list, counter)
perf_evsel__enable(counter, ncpus, nthreads); perf_evsel__enable(counter, ncpus, nthreads);
} }
} }
@ -552,7 +552,7 @@ static int __run_perf_stat(int argc, const char **argv)
if (group) if (group)
perf_evlist__set_leader(evsel_list); perf_evlist__set_leader(evsel_list);
list_for_each_entry(counter, &evsel_list->entries, node) { evlist__for_each(evsel_list, counter) {
if (create_perf_stat_counter(counter) < 0) { if (create_perf_stat_counter(counter) < 0) {
/* /*
* PPC returns ENXIO for HW counters until 2.6.37 * PPC returns ENXIO for HW counters until 2.6.37
@ -630,13 +630,13 @@ static int __run_perf_stat(int argc, const char **argv)
update_stats(&walltime_nsecs_stats, t1 - t0); update_stats(&walltime_nsecs_stats, t1 - t0);
if (aggr_mode == AGGR_GLOBAL) { if (aggr_mode == AGGR_GLOBAL) {
list_for_each_entry(counter, &evsel_list->entries, node) { evlist__for_each(evsel_list, counter) {
read_counter_aggr(counter); read_counter_aggr(counter);
perf_evsel__close_fd(counter, perf_evsel__nr_cpus(counter), perf_evsel__close_fd(counter, perf_evsel__nr_cpus(counter),
thread_map__nr(evsel_list->threads)); thread_map__nr(evsel_list->threads));
} }
} else { } else {
list_for_each_entry(counter, &evsel_list->entries, node) { evlist__for_each(evsel_list, counter) {
read_counter(counter); read_counter(counter);
perf_evsel__close_fd(counter, perf_evsel__nr_cpus(counter), 1); perf_evsel__close_fd(counter, perf_evsel__nr_cpus(counter), 1);
} }
@ -1117,7 +1117,7 @@ static void print_aggr(char *prefix)
for (s = 0; s < aggr_map->nr; s++) { for (s = 0; s < aggr_map->nr; s++) {
id = aggr_map->map[s]; id = aggr_map->map[s];
list_for_each_entry(counter, &evsel_list->entries, node) { evlist__for_each(evsel_list, counter) {
val = ena = run = 0; val = ena = run = 0;
nr = 0; nr = 0;
for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) { for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
@ -1328,11 +1328,11 @@ static void print_stat(int argc, const char **argv)
print_aggr(NULL); print_aggr(NULL);
break; break;
case AGGR_GLOBAL: case AGGR_GLOBAL:
list_for_each_entry(counter, &evsel_list->entries, node) evlist__for_each(evsel_list, counter)
print_counter_aggr(counter, NULL); print_counter_aggr(counter, NULL);
break; break;
case AGGR_NONE: case AGGR_NONE:
list_for_each_entry(counter, &evsel_list->entries, node) evlist__for_each(evsel_list, counter)
print_counter(counter, NULL); print_counter(counter, NULL);
break; break;
default: default:

Просмотреть файл

@ -482,7 +482,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
fprintf(stderr, "\nAvailable events:"); fprintf(stderr, "\nAvailable events:");
list_for_each_entry(top->sym_evsel, &top->evlist->entries, node) evlist__for_each(top->evlist, top->sym_evsel)
fprintf(stderr, "\n\t%d %s", top->sym_evsel->idx, perf_evsel__name(top->sym_evsel)); fprintf(stderr, "\n\t%d %s", top->sym_evsel->idx, perf_evsel__name(top->sym_evsel));
prompt_integer(&counter, "Enter details event counter"); prompt_integer(&counter, "Enter details event counter");
@ -493,7 +493,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
sleep(1); sleep(1);
break; break;
} }
list_for_each_entry(top->sym_evsel, &top->evlist->entries, node) evlist__for_each(top->evlist, top->sym_evsel)
if (top->sym_evsel->idx == counter) if (top->sym_evsel->idx == counter)
break; break;
} else } else
@ -575,7 +575,7 @@ static void *display_thread_tui(void *arg)
* Zooming in/out UIDs. For now juse use whatever the user passed * Zooming in/out UIDs. For now juse use whatever the user passed
* via --uid. * via --uid.
*/ */
list_for_each_entry(pos, &top->evlist->entries, node) evlist__for_each(top->evlist, pos)
pos->hists.uid_filter_str = top->record_opts.target.uid_str; pos->hists.uid_filter_str = top->record_opts.target.uid_str;
perf_evlist__tui_browse_hists(top->evlist, help, &hbt, top->min_percent, perf_evlist__tui_browse_hists(top->evlist, help, &hbt, top->min_percent,
@ -858,7 +858,7 @@ static int perf_top__start_counters(struct perf_top *top)
perf_evlist__config(evlist, opts); perf_evlist__config(evlist, opts);
list_for_each_entry(counter, &evlist->entries, node) { evlist__for_each(evlist, counter) {
try_again: try_again:
if (perf_evsel__open(counter, top->evlist->cpus, if (perf_evsel__open(counter, top->evlist->cpus,
top->evlist->threads) < 0) { top->evlist->threads) < 0) {

Просмотреть файл

@ -79,7 +79,7 @@ static int __perf_evsel__name_array_test(const char *names[], int nr_names)
} }
err = 0; err = 0;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
if (strcmp(perf_evsel__name(evsel), names[evsel->idx])) { if (strcmp(perf_evsel__name(evsel), names[evsel->idx])) {
--err; --err;
pr_debug("%s != %s\n", perf_evsel__name(evsel), names[evsel->idx]); pr_debug("%s != %s\n", perf_evsel__name(evsel), names[evsel->idx]);

Просмотреть файл

@ -208,7 +208,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine)
* However the second evsel also has a collapsed entry for * However the second evsel also has a collapsed entry for
* "bash [libc] malloc" so total 9 entries will be in the tree. * "bash [libc] malloc" so total 9 entries will be in the tree.
*/ */
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
for (k = 0; k < ARRAY_SIZE(fake_common_samples); k++) { for (k = 0; k < ARRAY_SIZE(fake_common_samples); k++) {
const union perf_event event = { const union perf_event event = {
.header = { .header = {
@ -466,7 +466,7 @@ int test__hists_link(void)
if (err < 0) if (err < 0)
goto out; goto out;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
hists__collapse_resort(&evsel->hists, NULL); hists__collapse_resort(&evsel->hists, NULL);
if (verbose > 2) if (verbose > 2)

Просмотреть файл

@ -126,7 +126,7 @@ int test__basic_mmap(void)
} }
err = 0; err = 0;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
if (nr_events[evsel->idx] != expected_nr_events[evsel->idx]) { if (nr_events[evsel->idx] != expected_nr_events[evsel->idx]) {
pr_debug("expected %d %s events, got %d\n", pr_debug("expected %d %s events, got %d\n",
expected_nr_events[evsel->idx], expected_nr_events[evsel->idx],

Просмотреть файл

@ -30,7 +30,7 @@ static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups); TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
TEST_ASSERT_VAL("wrong type", TEST_ASSERT_VAL("wrong type",
PERF_TYPE_TRACEPOINT == evsel->attr.type); PERF_TYPE_TRACEPOINT == evsel->attr.type);
TEST_ASSERT_VAL("wrong sample_type", TEST_ASSERT_VAL("wrong sample_type",
@ -201,7 +201,7 @@ test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
TEST_ASSERT_VAL("wrong exclude_user", TEST_ASSERT_VAL("wrong exclude_user",
!evsel->attr.exclude_user); !evsel->attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", TEST_ASSERT_VAL("wrong exclude_kernel",

Просмотреть файл

@ -1938,7 +1938,7 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
ui_helpline__push("Press ESC to exit"); ui_helpline__push("Press ESC to exit");
list_for_each_entry(pos, &evlist->entries, node) { evlist__for_each(evlist, pos) {
const char *ev_name = perf_evsel__name(pos); const char *ev_name = perf_evsel__name(pos);
size_t line_len = strlen(ev_name) + 7; size_t line_len = strlen(ev_name) + 7;
@ -1970,9 +1970,10 @@ single_entry:
struct perf_evsel *pos; struct perf_evsel *pos;
nr_entries = 0; nr_entries = 0;
list_for_each_entry(pos, &evlist->entries, node) evlist__for_each(evlist, pos) {
if (perf_evsel__is_group_leader(pos)) if (perf_evsel__is_group_leader(pos))
nr_entries++; nr_entries++;
}
if (nr_entries == 1) if (nr_entries == 1)
goto single_entry; goto single_entry;

Просмотреть файл

@ -375,7 +375,7 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
gtk_container_add(GTK_CONTAINER(window), vbox); gtk_container_add(GTK_CONTAINER(window), vbox);
list_for_each_entry(pos, &evlist->entries, node) { evlist__for_each(evlist, pos) {
struct hists *hists = &pos->hists; struct hists *hists = &pos->hists;
const char *evname = perf_evsel__name(pos); const char *evname = perf_evsel__name(pos);
GtkWidget *scrolled_window; GtkWidget *scrolled_window;

Просмотреть файл

@ -81,7 +81,7 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
/* /*
* check if cgrp is already defined, if so we reuse it * check if cgrp is already defined, if so we reuse it
*/ */
list_for_each_entry(counter, &evlist->entries, node) { evlist__for_each(evlist, counter) {
cgrp = counter->cgrp; cgrp = counter->cgrp;
if (!cgrp) if (!cgrp)
continue; continue;
@ -110,7 +110,7 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
* if add cgroup N, then need to find event N * if add cgroup N, then need to find event N
*/ */
n = 0; n = 0;
list_for_each_entry(counter, &evlist->entries, node) { evlist__for_each(evlist, counter) {
if (n == nr_cgroups) if (n == nr_cgroups)
goto found; goto found;
n++; n++;

Просмотреть файл

@ -81,7 +81,7 @@ static void perf_evlist__update_id_pos(struct perf_evlist *evlist)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
list_for_each_entry(evsel, &evlist->entries, node) evlist__for_each(evlist, evsel)
perf_evsel__calc_id_pos(evsel); perf_evsel__calc_id_pos(evsel);
perf_evlist__set_id_pos(evlist); perf_evlist__set_id_pos(evlist);
@ -91,7 +91,7 @@ static void perf_evlist__purge(struct perf_evlist *evlist)
{ {
struct perf_evsel *pos, *n; struct perf_evsel *pos, *n;
list_for_each_entry_safe(pos, n, &evlist->entries, node) { evlist__for_each_safe(evlist, n, pos) {
list_del_init(&pos->node); list_del_init(&pos->node);
perf_evsel__delete(pos); perf_evsel__delete(pos);
} }
@ -148,7 +148,7 @@ void __perf_evlist__set_leader(struct list_head *list)
leader->nr_members = evsel->idx - leader->idx + 1; leader->nr_members = evsel->idx - leader->idx + 1;
list_for_each_entry(evsel, list, node) { __evlist__for_each(list, evsel) {
evsel->leader = leader; evsel->leader = leader;
} }
} }
@ -207,7 +207,7 @@ static int perf_evlist__add_attrs(struct perf_evlist *evlist,
return 0; return 0;
out_delete_partial_list: out_delete_partial_list:
list_for_each_entry_safe(evsel, n, &head, node) __evlist__for_each_safe(&head, n, evsel)
perf_evsel__delete(evsel); perf_evsel__delete(evsel);
return -1; return -1;
} }
@ -228,7 +228,7 @@ perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
if (evsel->attr.type == PERF_TYPE_TRACEPOINT && if (evsel->attr.type == PERF_TYPE_TRACEPOINT &&
(int)evsel->attr.config == id) (int)evsel->attr.config == id)
return evsel; return evsel;
@ -243,7 +243,7 @@ perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
if ((evsel->attr.type == PERF_TYPE_TRACEPOINT) && if ((evsel->attr.type == PERF_TYPE_TRACEPOINT) &&
(strcmp(evsel->name, name) == 0)) (strcmp(evsel->name, name) == 0))
return evsel; return evsel;
@ -273,7 +273,7 @@ void perf_evlist__disable(struct perf_evlist *evlist)
int nr_threads = thread_map__nr(evlist->threads); int nr_threads = thread_map__nr(evlist->threads);
for (cpu = 0; cpu < nr_cpus; cpu++) { for (cpu = 0; cpu < nr_cpus; cpu++) {
list_for_each_entry(pos, &evlist->entries, node) { evlist__for_each(evlist, pos) {
if (!perf_evsel__is_group_leader(pos) || !pos->fd) if (!perf_evsel__is_group_leader(pos) || !pos->fd)
continue; continue;
for (thread = 0; thread < nr_threads; thread++) for (thread = 0; thread < nr_threads; thread++)
@ -291,7 +291,7 @@ void perf_evlist__enable(struct perf_evlist *evlist)
int nr_threads = thread_map__nr(evlist->threads); int nr_threads = thread_map__nr(evlist->threads);
for (cpu = 0; cpu < nr_cpus; cpu++) { for (cpu = 0; cpu < nr_cpus; cpu++) {
list_for_each_entry(pos, &evlist->entries, node) { evlist__for_each(evlist, pos) {
if (!perf_evsel__is_group_leader(pos) || !pos->fd) if (!perf_evsel__is_group_leader(pos) || !pos->fd)
continue; continue;
for (thread = 0; thread < nr_threads; thread++) for (thread = 0; thread < nr_threads; thread++)
@ -630,7 +630,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
int fd = FD(evsel, cpu, thread); int fd = FD(evsel, cpu, thread);
if (*output == -1) { if (*output == -1) {
@ -806,7 +806,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
pr_debug("mmap size %zuB\n", evlist->mmap_len); pr_debug("mmap size %zuB\n", evlist->mmap_len);
mask = evlist->mmap_len - page_size - 1; mask = evlist->mmap_len - page_size - 1;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
if ((evsel->attr.read_format & PERF_FORMAT_ID) && if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
evsel->sample_id == NULL && evsel->sample_id == NULL &&
perf_evsel__alloc_id(evsel, cpu_map__nr(cpus), threads->nr) < 0) perf_evsel__alloc_id(evsel, cpu_map__nr(cpus), threads->nr) < 0)
@ -849,7 +849,7 @@ int perf_evlist__apply_filters(struct perf_evlist *evlist)
const int ncpus = cpu_map__nr(evlist->cpus), const int ncpus = cpu_map__nr(evlist->cpus),
nthreads = thread_map__nr(evlist->threads); nthreads = thread_map__nr(evlist->threads);
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
if (evsel->filter == NULL) if (evsel->filter == NULL)
continue; continue;
@ -868,7 +868,7 @@ int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter)
const int ncpus = cpu_map__nr(evlist->cpus), const int ncpus = cpu_map__nr(evlist->cpus),
nthreads = thread_map__nr(evlist->threads); nthreads = thread_map__nr(evlist->threads);
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
err = perf_evsel__set_filter(evsel, ncpus, nthreads, filter); err = perf_evsel__set_filter(evsel, ncpus, nthreads, filter);
if (err) if (err)
break; break;
@ -887,7 +887,7 @@ bool perf_evlist__valid_sample_type(struct perf_evlist *evlist)
if (evlist->id_pos < 0 || evlist->is_pos < 0) if (evlist->id_pos < 0 || evlist->is_pos < 0)
return false; return false;
list_for_each_entry(pos, &evlist->entries, node) { evlist__for_each(evlist, pos) {
if (pos->id_pos != evlist->id_pos || if (pos->id_pos != evlist->id_pos ||
pos->is_pos != evlist->is_pos) pos->is_pos != evlist->is_pos)
return false; return false;
@ -903,7 +903,7 @@ u64 __perf_evlist__combined_sample_type(struct perf_evlist *evlist)
if (evlist->combined_sample_type) if (evlist->combined_sample_type)
return evlist->combined_sample_type; return evlist->combined_sample_type;
list_for_each_entry(evsel, &evlist->entries, node) evlist__for_each(evlist, evsel)
evlist->combined_sample_type |= evsel->attr.sample_type; evlist->combined_sample_type |= evsel->attr.sample_type;
return evlist->combined_sample_type; return evlist->combined_sample_type;
@ -921,7 +921,7 @@ bool perf_evlist__valid_read_format(struct perf_evlist *evlist)
u64 read_format = first->attr.read_format; u64 read_format = first->attr.read_format;
u64 sample_type = first->attr.sample_type; u64 sample_type = first->attr.sample_type;
list_for_each_entry_continue(pos, &evlist->entries, node) { evlist__for_each(evlist, pos) {
if (read_format != pos->attr.read_format) if (read_format != pos->attr.read_format)
return false; return false;
} }
@ -978,7 +978,7 @@ bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist)
{ {
struct perf_evsel *first = perf_evlist__first(evlist), *pos = first; struct perf_evsel *first = perf_evlist__first(evlist), *pos = first;
list_for_each_entry_continue(pos, &evlist->entries, node) { evlist__for_each_continue(evlist, pos) {
if (first->attr.sample_id_all != pos->attr.sample_id_all) if (first->attr.sample_id_all != pos->attr.sample_id_all)
return false; return false;
} }
@ -1004,7 +1004,7 @@ void perf_evlist__close(struct perf_evlist *evlist)
int ncpus = cpu_map__nr(evlist->cpus); int ncpus = cpu_map__nr(evlist->cpus);
int nthreads = thread_map__nr(evlist->threads); int nthreads = thread_map__nr(evlist->threads);
list_for_each_entry_reverse(evsel, &evlist->entries, node) evlist__for_each_reverse(evlist, evsel)
perf_evsel__close(evsel, ncpus, nthreads); perf_evsel__close(evsel, ncpus, nthreads);
} }
@ -1015,7 +1015,7 @@ int perf_evlist__open(struct perf_evlist *evlist)
perf_evlist__update_id_pos(evlist); perf_evlist__update_id_pos(evlist);
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
err = perf_evsel__open(evsel, evlist->cpus, evlist->threads); err = perf_evsel__open(evsel, evlist->cpus, evlist->threads);
if (err < 0) if (err < 0)
goto out_err; goto out_err;
@ -1154,7 +1154,7 @@ size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp)
struct perf_evsel *evsel; struct perf_evsel *evsel;
size_t printed = 0; size_t printed = 0;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
printed += fprintf(fp, "%s%s", evsel->idx ? ", " : "", printed += fprintf(fp, "%s%s", evsel->idx ? ", " : "",
perf_evsel__name(evsel)); perf_evsel__name(evsel));
} }
@ -1233,7 +1233,7 @@ void perf_evlist__to_front(struct perf_evlist *evlist,
if (move_evsel == perf_evlist__first(evlist)) if (move_evsel == perf_evlist__first(evlist))
return; return;
list_for_each_entry_safe(evsel, n, &evlist->entries, node) { evlist__for_each_safe(evlist, n, evsel) {
if (evsel->leader == move_evsel->leader) if (evsel->leader == move_evsel->leader)
list_move_tail(&evsel->node, &move); list_move_tail(&evsel->node, &move);
} }

Просмотреть файл

@ -196,5 +196,70 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str);
void perf_evlist__to_front(struct perf_evlist *evlist, void perf_evlist__to_front(struct perf_evlist *evlist,
struct perf_evsel *move_evsel); struct perf_evsel *move_evsel);
/**
* __evlist__for_each - iterate thru all the evsels
* @list: list_head instance to iterate
* @evsel: struct evsel iterator
*/
#define __evlist__for_each(list, evsel) \
list_for_each_entry(evsel, list, node)
/**
* evlist__for_each - iterate thru all the evsels
* @evlist: evlist instance to iterate
* @evsel: struct evsel iterator
*/
#define evlist__for_each(evlist, evsel) \
__evlist__for_each(&(evlist)->entries, evsel)
/**
* __evlist__for_each_continue - continue iteration thru all the evsels
* @list: list_head instance to iterate
* @evsel: struct evsel iterator
*/
#define __evlist__for_each_continue(list, evsel) \
list_for_each_entry_continue(evsel, list, node)
/**
* evlist__for_each_continue - continue iteration thru all the evsels
* @evlist: evlist instance to iterate
* @evsel: struct evsel iterator
*/
#define evlist__for_each_continue(evlist, evsel) \
__evlist__for_each_continue(&(evlist)->entries, evsel)
/**
* __evlist__for_each_reverse - iterate thru all the evsels in reverse order
* @list: list_head instance to iterate
* @evsel: struct evsel iterator
*/
#define __evlist__for_each_reverse(list, evsel) \
list_for_each_entry_reverse(evsel, list, node)
/**
* evlist__for_each_reverse - iterate thru all the evsels in reverse order
* @evlist: evlist instance to iterate
* @evsel: struct evsel iterator
*/
#define evlist__for_each_reverse(evlist, evsel) \
__evlist__for_each_reverse(&(evlist)->entries, evsel)
/**
* __evlist__for_each_safe - safely iterate thru all the evsels
* @list: list_head instance to iterate
* @tmp: struct evsel temp iterator
* @evsel: struct evsel iterator
*/
#define __evlist__for_each_safe(list, tmp, evsel) \
list_for_each_entry_safe(evsel, tmp, list, node)
/**
* evlist__for_each_safe - safely iterate thru all the evsels
* @evlist: evlist instance to iterate
* @evsel: struct evsel iterator
* @tmp: struct evsel temp iterator
*/
#define evlist__for_each_safe(evlist, tmp, evsel) \
__evlist__for_each_safe(&(evlist)->entries, tmp, evsel)
#endif /* __PERF_EVLIST_H */ #endif /* __PERF_EVLIST_H */

Просмотреть файл

@ -643,8 +643,7 @@ static int write_event_desc(int fd, struct perf_header *h __maybe_unused,
if (ret < 0) if (ret < 0)
return ret; return ret;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
ret = do_write(fd, &evsel->attr, sz); ret = do_write(fd, &evsel->attr, sz);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -1092,7 +1091,7 @@ static int write_group_desc(int fd, struct perf_header *h __maybe_unused,
if (ret < 0) if (ret < 0)
return ret; return ret;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
if (perf_evsel__is_group_leader(evsel) && if (perf_evsel__is_group_leader(evsel) &&
evsel->nr_members > 1) { evsel->nr_members > 1) {
const char *name = evsel->group_name ?: "{anon_group}"; const char *name = evsel->group_name ?: "{anon_group}";
@ -1487,7 +1486,7 @@ static void print_group_desc(struct perf_header *ph, int fd __maybe_unused,
session = container_of(ph, struct perf_session, header); session = container_of(ph, struct perf_session, header);
list_for_each_entry(evsel, &session->evlist->entries, node) { evlist__for_each(session->evlist, evsel) {
if (perf_evsel__is_group_leader(evsel) && if (perf_evsel__is_group_leader(evsel) &&
evsel->nr_members > 1) { evsel->nr_members > 1) {
fprintf(fp, "# group: %s{%s", evsel->group_name ?: "", fprintf(fp, "# group: %s{%s", evsel->group_name ?: "",
@ -1768,7 +1767,7 @@ perf_evlist__find_by_index(struct perf_evlist *evlist, int idx)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
if (evsel->idx == idx) if (evsel->idx == idx)
return evsel; return evsel;
} }
@ -2071,7 +2070,7 @@ static int process_group_desc(struct perf_file_section *section __maybe_unused,
session->evlist->nr_groups = nr_groups; session->evlist->nr_groups = nr_groups;
i = nr = 0; i = nr = 0;
list_for_each_entry(evsel, &session->evlist->entries, node) { evlist__for_each(session->evlist, evsel) {
if (evsel->idx == (int) desc[i].leader_idx) { if (evsel->idx == (int) desc[i].leader_idx) {
evsel->leader = evsel; evsel->leader = evsel;
/* {anon_group} is a dummy name */ /* {anon_group} is a dummy name */
@ -2298,7 +2297,7 @@ int perf_session__write_header(struct perf_session *session,
lseek(fd, sizeof(f_header), SEEK_SET); lseek(fd, sizeof(f_header), SEEK_SET);
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(session->evlist, evsel) {
evsel->id_offset = lseek(fd, 0, SEEK_CUR); evsel->id_offset = lseek(fd, 0, SEEK_CUR);
err = do_write(fd, evsel->id, evsel->ids * sizeof(u64)); err = do_write(fd, evsel->id, evsel->ids * sizeof(u64));
if (err < 0) { if (err < 0) {
@ -2309,7 +2308,7 @@ int perf_session__write_header(struct perf_session *session,
attr_offset = lseek(fd, 0, SEEK_CUR); attr_offset = lseek(fd, 0, SEEK_CUR);
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
f_attr = (struct perf_file_attr){ f_attr = (struct perf_file_attr){
.attr = evsel->attr, .attr = evsel->attr,
.ids = { .ids = {
@ -2742,7 +2741,7 @@ static int perf_evlist__prepare_tracepoint_events(struct perf_evlist *evlist,
{ {
struct perf_evsel *pos; struct perf_evsel *pos;
list_for_each_entry(pos, &evlist->entries, node) { evlist__for_each(evlist, pos) {
if (pos->attr.type == PERF_TYPE_TRACEPOINT && if (pos->attr.type == PERF_TYPE_TRACEPOINT &&
perf_evsel__prepare_tracepoint_event(pos, pevent)) perf_evsel__prepare_tracepoint_event(pos, pevent))
return -1; return -1;
@ -2890,7 +2889,7 @@ int perf_event__synthesize_attrs(struct perf_tool *tool,
struct perf_evsel *evsel; struct perf_evsel *evsel;
int err = 0; int err = 0;
list_for_each_entry(evsel, &session->evlist->entries, node) { evlist__for_each(session->evlist, evsel) {
err = perf_event__synthesize_attr(tool, &evsel->attr, evsel->ids, err = perf_event__synthesize_attr(tool, &evsel->attr, evsel->ids,
evsel->id, process); evsel->id, process);
if (err) { if (err) {

Просмотреть файл

@ -820,8 +820,7 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add)
if (!add && get_event_modifier(&mod, str, NULL)) if (!add && get_event_modifier(&mod, str, NULL))
return -EINVAL; return -EINVAL;
list_for_each_entry(evsel, list, node) { __evlist__for_each(list, evsel) {
if (add && get_event_modifier(&mod, str, evsel)) if (add && get_event_modifier(&mod, str, evsel))
return -EINVAL; return -EINVAL;
@ -845,7 +844,7 @@ int parse_events_name(struct list_head *list, char *name)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
list_for_each_entry(evsel, list, node) { __evlist__for_each(list, evsel) {
if (!evsel->name) if (!evsel->name)
evsel->name = strdup(name); evsel->name = strdup(name);
} }

Просмотреть файл

@ -908,9 +908,10 @@ static PyObject *pyrf_evlist__item(PyObject *obj, Py_ssize_t i)
if (i >= pevlist->evlist.nr_entries) if (i >= pevlist->evlist.nr_entries)
return NULL; return NULL;
list_for_each_entry(pos, &pevlist->evlist.entries, node) evlist__for_each(&pevlist->evlist, pos) {
if (i-- == 0) if (i-- == 0)
break; break;
}
return Py_BuildValue("O", container_of(pos, struct pyrf_evsel, evsel)); return Py_BuildValue("O", container_of(pos, struct pyrf_evsel, evsel));
} }

Просмотреть файл

@ -89,19 +89,19 @@ void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts)
if (evlist->cpus->map[0] < 0) if (evlist->cpus->map[0] < 0)
opts->no_inherit = true; opts->no_inherit = true;
list_for_each_entry(evsel, &evlist->entries, node) evlist__for_each(evlist, evsel)
perf_evsel__config(evsel, opts); perf_evsel__config(evsel, opts);
if (evlist->nr_entries > 1) { if (evlist->nr_entries > 1) {
struct perf_evsel *first = perf_evlist__first(evlist); struct perf_evsel *first = perf_evlist__first(evlist);
list_for_each_entry(evsel, &evlist->entries, node) { evlist__for_each(evlist, evsel) {
if (evsel->attr.sample_type == first->attr.sample_type) if (evsel->attr.sample_type == first->attr.sample_type)
continue; continue;
use_sample_identifier = perf_can_sample_identifier(); use_sample_identifier = perf_can_sample_identifier();
break; break;
} }
list_for_each_entry(evsel, &evlist->entries, node) evlist__for_each(evlist, evsel)
perf_evsel__set_sample_id(evsel, use_sample_identifier); perf_evsel__set_sample_id(evsel, use_sample_identifier);
} }

Просмотреть файл

@ -1384,7 +1384,7 @@ bool perf_session__has_traces(struct perf_session *session, const char *msg)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
list_for_each_entry(evsel, &session->evlist->entries, node) { evlist__for_each(session->evlist, evsel) {
if (evsel->attr.type == PERF_TYPE_TRACEPOINT) if (evsel->attr.type == PERF_TYPE_TRACEPOINT)
return true; return true;
} }
@ -1442,7 +1442,7 @@ size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp)
ret += events_stats__fprintf(&session->stats, fp); ret += events_stats__fprintf(&session->stats, fp);
list_for_each_entry(pos, &session->evlist->entries, node) { evlist__for_each(session->evlist, pos) {
ret += fprintf(fp, "%s stats:\n", perf_evsel__name(pos)); ret += fprintf(fp, "%s stats:\n", perf_evsel__name(pos));
ret += events_stats__fprintf(&pos->hists.stats, fp); ret += events_stats__fprintf(&pos->hists.stats, fp);
} }
@ -1464,7 +1464,7 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
{ {
struct perf_evsel *pos; struct perf_evsel *pos;
list_for_each_entry(pos, &session->evlist->entries, node) { evlist__for_each(session->evlist, pos) {
if (pos->attr.type == type) if (pos->attr.type == type)
return pos; return pos;
} }