[PATCH 09/10] perf tests: apply new mmap_read interfaces
From: kan . liang
Date: Tue Oct 10 2017 - 13:24:13 EST
From: Kan Liang <kan.liang@xxxxxxxxx>
no functional change
backward-ring-buffer is the test case for backward mode.
The rest of the test cases are forward mode.
Signed-off-by: Kan Liang <kan.liang@xxxxxxxxx>
---
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 9 ++++++++-
tools/perf/tests/backward-ring-buffer.c | 10 ++++++++--
tools/perf/tests/bpf.c | 10 +++++++++-
tools/perf/tests/code-reading.c | 8 +++++++-
tools/perf/tests/keep-tracking.c | 8 +++++++-
tools/perf/tests/mmap-basic.c | 9 ++++++++-
tools/perf/tests/openat-syscall-tp-fields.c | 9 ++++++++-
tools/perf/tests/perf-record.c | 9 ++++++++-
tools/perf/tests/sw-clock.c | 8 +++++++-
tools/perf/tests/switch-tracking.c | 8 +++++++-
tools/perf/tests/task-exit.c | 8 +++++++-
11 files changed, 84 insertions(+), 12 deletions(-)
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 5dd7efb..e1cdd23 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -57,6 +57,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
struct perf_tsc_conversion tc;
struct perf_event_mmap_page *pc;
union perf_event *event;
+ struct perf_mmap_read read;
u64 test_tsc, comm1_tsc, comm2_tsc;
u64 test_time, comm1_time = 0, comm2_time = 0;
@@ -108,7 +109,12 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
perf_evlist__disable(evlist);
for (i = 0; i < evlist->nr_mmaps; i++) {
- while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
+ if (perf_evlist__mmap_read_init(evlist, i, &read, false)) {
+ pr_err("Can't get mmap information\n");
+ continue;
+ }
+
+ while ((event = perf_mmap__read_event(&read)) != NULL) {
struct perf_sample sample;
if (event->header.type != PERF_RECORD_COMM ||
@@ -129,6 +135,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
next_event:
perf_evlist__mmap_consume(evlist, i);
}
+ perf_mmap__read_done(&read);
}
if (!comm1_time || !comm2_time)
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index d233ad3..4841b7e 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -31,9 +31,14 @@ static int count_samples(struct perf_evlist *evlist, int *sample_count,
for (i = 0; i < evlist->nr_mmaps; i++) {
union perf_event *event;
+ struct perf_mmap_read read;
- perf_mmap__read_catchup(&evlist->backward_mmap[i]);
- while ((event = perf_mmap__read_backward(&evlist->backward_mmap[i])) != NULL) {
+ if (perf_evlist__mmap_read_init(evlist, i, &read, true)) {
+ pr_err("Can't get mmap information\n");
+ continue;
+ }
+
+ while ((event = perf_mmap__read_event(&read)) != NULL) {
const u32 type = event->header.type;
switch (type) {
@@ -48,6 +53,7 @@ static int count_samples(struct perf_evlist *evlist, int *sample_count,
return TEST_FAIL;
}
}
+ perf_mmap__read_done(&read);
}
return TEST_OK;
}
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 34c22cd..0ab7f8f 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -180,13 +180,21 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
for (i = 0; i < evlist->nr_mmaps; i++) {
union perf_event *event;
+ struct perf_mmap_read read;
- while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
+ if (perf_evlist__mmap_read_init(evlist, i, &read, false)) {
+ pr_err("Can't get mmap information\n");
+ continue;
+ }
+
+ while ((event = perf_mmap__read_event(&read)) != NULL) {
const u32 type = event->header.type;
if (type == PERF_RECORD_SAMPLE)
count ++;
+ perf_evlist__mmap_consume(evlist, i);
}
+ perf_mmap__read_done(&read);
}
if (count != expect) {
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 466a462..69cf7fc 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -408,15 +408,21 @@ static int process_events(struct machine *machine, struct perf_evlist *evlist,
struct state *state)
{
union perf_event *event;
+ struct perf_mmap_read read;
int i, ret;
for (i = 0; i < evlist->nr_mmaps; i++) {
- while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
+ if (perf_evlist__mmap_read_init(evlist, i, &read, false)) {
+ pr_err("Can't get mmap information\n");
+ continue;
+ }
+ while ((event = perf_mmap__read_event(&read)) != NULL) {
ret = process_event(machine, evlist, event, state);
perf_evlist__mmap_consume(evlist, i);
if (ret < 0)
return ret;
}
+ perf_mmap__read_done(&read);
}
return 0;
}
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index 7394286..b2beab0 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -26,11 +26,16 @@
static int find_comm(struct perf_evlist *evlist, const char *comm)
{
union perf_event *event;
+ struct perf_mmap_read read;
int i, found;
found = 0;
for (i = 0; i < evlist->nr_mmaps; i++) {
- while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
+ if (perf_evlist__mmap_read_init(evlist, i, &read, false)) {
+ pr_err("Can't get mmap information\n");
+ continue;
+ }
+ while ((event = perf_mmap__read_event(&read)) != NULL) {
if (event->header.type == PERF_RECORD_COMM &&
(pid_t)event->comm.pid == getpid() &&
(pid_t)event->comm.tid == getpid() &&
@@ -38,6 +43,7 @@ static int find_comm(struct perf_evlist *evlist, const char *comm)
found += 1;
perf_evlist__mmap_consume(evlist, i);
}
+ perf_mmap__read_done(&read);
}
return found;
}
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index bc8a70e..529c0c7 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -37,6 +37,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse
expected_nr_events[nsyscalls], i, j;
struct perf_evsel *evsels[nsyscalls], *evsel;
char sbuf[STRERR_BUFSIZE];
+ struct perf_mmap_read read;
threads = thread_map__new(-1, getpid(), UINT_MAX);
if (threads == NULL) {
@@ -105,7 +106,12 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse
++foo;
}
- while ((event = perf_evlist__mmap_read(evlist, 0)) != NULL) {
+ if (perf_evlist__mmap_read_init(evlist, 0, &read, false)) {
+ pr_err("Can't get mmap information\n");
+ goto out_delete_evlist;
+ }
+
+ while ((event = perf_mmap__read_event(&read)) != NULL) {
struct perf_sample sample;
if (event->header.type != PERF_RECORD_SAMPLE) {
@@ -130,6 +136,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse
nr_events[evsel->idx]++;
perf_evlist__mmap_consume(evlist, 0);
}
+ perf_mmap__read_done(&read);
err = 0;
evlist__for_each_entry(evlist, evsel) {
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index b6ee1c4..8431561 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -82,8 +82,14 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest
for (i = 0; i < evlist->nr_mmaps; i++) {
union perf_event *event;
+ struct perf_mmap_read read;
- while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
+ if (perf_evlist__mmap_read_init(evlist, i, &read, false)) {
+ pr_err("Can't get mmap information\n");
+ continue;
+ }
+
+ while ((event = perf_mmap__read_event(&read)) != NULL) {
const u32 type = event->header.type;
int tp_flags;
struct perf_sample sample;
@@ -111,6 +117,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest
goto out_ok;
}
+ perf_mmap__read_done(&read);
}
if (nr_events == before)
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index 19b6500..c5e1f08 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -163,8 +163,14 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
for (i = 0; i < evlist->nr_mmaps; i++) {
union perf_event *event;
+ struct perf_mmap_read read;
- while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
+ if (perf_evlist__mmap_read_init(evlist, i, &read, false)) {
+ pr_err("Can't get mmap information\n");
+ continue;
+ }
+
+ while ((event = perf_mmap__read_event(&read)) != NULL) {
const u32 type = event->header.type;
const char *name = perf_event__name(type);
@@ -267,6 +273,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
perf_evlist__mmap_consume(evlist, i);
}
+ perf_mmap__read_done(&read);
}
/*
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index d88511f..a5dd3e8 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -38,6 +38,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
};
struct cpu_map *cpus;
struct thread_map *threads;
+ struct perf_mmap_read read;
attr.sample_freq = 500;
@@ -92,7 +93,11 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
perf_evlist__disable(evlist);
- while ((event = perf_evlist__mmap_read(evlist, 0)) != NULL) {
+ if (perf_evlist__mmap_read_init(evlist, 0, &read, false)) {
+ pr_err("Can't get mmap information\n");
+ goto out_delete_evlist;
+ }
+ while ((event = perf_mmap__read_event(&read)) != NULL) {
struct perf_sample sample;
if (event->header.type != PERF_RECORD_SAMPLE)
@@ -109,6 +114,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
next_event:
perf_evlist__mmap_consume(evlist, 0);
}
+ perf_mmap__read_done(&read);
if ((u64) nr_samples == total_periods) {
pr_debug("All (%d) samples have period value of 1!\n",
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 2acd785..3b4f2f6 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -257,16 +257,22 @@ static int process_events(struct perf_evlist *evlist,
unsigned pos, cnt = 0;
LIST_HEAD(events);
struct event_node *events_array, *node;
+ struct perf_mmap_read read;
int i, ret;
for (i = 0; i < evlist->nr_mmaps; i++) {
- while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
+ if (perf_evlist__mmap_read_init(evlist, i, &read, false)) {
+ pr_err("Can't get mmap information\n");
+ continue;
+ }
+ while ((event = perf_mmap__read_event(&read)) != NULL) {
cnt += 1;
ret = add_event(evlist, &events, event);
perf_evlist__mmap_consume(evlist, i);
if (ret < 0)
goto out_free_nodes;
}
+ perf_mmap__read_done(&read);
}
events_array = calloc(cnt, sizeof(struct event_node));
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index f0881d0..2529fba 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -46,6 +46,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
char sbuf[STRERR_BUFSIZE];
struct cpu_map *cpus;
struct thread_map *threads;
+ struct perf_mmap_read read;
signal(SIGCHLD, sig_handler);
@@ -105,12 +106,17 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
perf_evlist__start_workload(evlist);
retry:
- while ((event = perf_evlist__mmap_read(evlist, 0)) != NULL) {
+ if (perf_evlist__mmap_read_init(evlist, 0, &read, false)) {
+ pr_err("Can't get mmap information\n");
+ goto out_delete_evlist;
+ }
+ while ((event = perf_mmap__read_event(&read)) != NULL) {
if (event->header.type == PERF_RECORD_EXIT)
nr_exit++;
perf_evlist__mmap_consume(evlist, 0);
}
+ perf_mmap__read_done(&read);
if (!exited || !nr_exit) {
perf_evlist__poll(evlist, -1);
--
2.5.5