| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | 2 | #include <errno.h> |
|---|
| 3 | 3 | #include <inttypes.h> |
|---|
| 4 | +#include <limits.h> |
|---|
| 5 | +#include <stdbool.h> |
|---|
| 4 | 6 | #include <stdio.h> |
|---|
| 5 | 7 | #include <unistd.h> |
|---|
| 6 | 8 | #include <linux/types.h> |
|---|
| 7 | 9 | #include <sys/prctl.h> |
|---|
| 10 | +#include <perf/cpumap.h> |
|---|
| 11 | +#include <perf/evlist.h> |
|---|
| 12 | +#include <perf/mmap.h> |
|---|
| 8 | 13 | |
|---|
| 14 | +#include "debug.h" |
|---|
| 9 | 15 | #include "parse-events.h" |
|---|
| 10 | 16 | #include "evlist.h" |
|---|
| 11 | 17 | #include "evsel.h" |
|---|
| 12 | 18 | #include "thread_map.h" |
|---|
| 13 | | -#include "cpumap.h" |
|---|
| 19 | +#include "record.h" |
|---|
| 14 | 20 | #include "tsc.h" |
|---|
| 21 | +#include "util/mmap.h" |
|---|
| 15 | 22 | #include "tests/tests.h" |
|---|
| 16 | 23 | |
|---|
| 17 | 24 | #include "arch-tests.h" |
|---|
| .. | .. |
|---|
| 49 | 56 | }, |
|---|
| 50 | 57 | .sample_time = true, |
|---|
| 51 | 58 | }; |
|---|
| 52 | | - struct thread_map *threads = NULL; |
|---|
| 53 | | - struct cpu_map *cpus = NULL; |
|---|
| 54 | | - struct perf_evlist *evlist = NULL; |
|---|
| 55 | | - struct perf_evsel *evsel = NULL; |
|---|
| 59 | + struct perf_thread_map *threads = NULL; |
|---|
| 60 | + struct perf_cpu_map *cpus = NULL; |
|---|
| 61 | + struct evlist *evlist = NULL; |
|---|
| 62 | + struct evsel *evsel = NULL; |
|---|
| 56 | 63 | int err = -1, ret, i; |
|---|
| 57 | 64 | const char *comm1, *comm2; |
|---|
| 58 | 65 | struct perf_tsc_conversion tc; |
|---|
| .. | .. |
|---|
| 60 | 67 | union perf_event *event; |
|---|
| 61 | 68 | u64 test_tsc, comm1_tsc, comm2_tsc; |
|---|
| 62 | 69 | u64 test_time, comm1_time = 0, comm2_time = 0; |
|---|
| 63 | | - struct perf_mmap *md; |
|---|
| 70 | + struct mmap *md; |
|---|
| 64 | 71 | |
|---|
| 65 | 72 | threads = thread_map__new(-1, getpid(), UINT_MAX); |
|---|
| 66 | 73 | CHECK_NOT_NULL__(threads); |
|---|
| 67 | 74 | |
|---|
| 68 | | - cpus = cpu_map__new(NULL); |
|---|
| 75 | + cpus = perf_cpu_map__new(NULL); |
|---|
| 69 | 76 | CHECK_NOT_NULL__(cpus); |
|---|
| 70 | 77 | |
|---|
| 71 | | - evlist = perf_evlist__new(); |
|---|
| 78 | + evlist = evlist__new(); |
|---|
| 72 | 79 | CHECK_NOT_NULL__(evlist); |
|---|
| 73 | 80 | |
|---|
| 74 | | - perf_evlist__set_maps(evlist, cpus, threads); |
|---|
| 81 | + perf_evlist__set_maps(&evlist->core, cpus, threads); |
|---|
| 75 | 82 | |
|---|
| 76 | 83 | CHECK__(parse_events(evlist, "cycles:u", NULL)); |
|---|
| 77 | 84 | |
|---|
| 78 | 85 | perf_evlist__config(evlist, &opts, NULL); |
|---|
| 79 | 86 | |
|---|
| 80 | | - evsel = perf_evlist__first(evlist); |
|---|
| 87 | + evsel = evlist__first(evlist); |
|---|
| 81 | 88 | |
|---|
| 82 | | - evsel->attr.comm = 1; |
|---|
| 83 | | - evsel->attr.disabled = 1; |
|---|
| 84 | | - evsel->attr.enable_on_exec = 0; |
|---|
| 89 | + evsel->core.attr.comm = 1; |
|---|
| 90 | + evsel->core.attr.disabled = 1; |
|---|
| 91 | + evsel->core.attr.enable_on_exec = 0; |
|---|
| 85 | 92 | |
|---|
| 86 | | - CHECK__(perf_evlist__open(evlist)); |
|---|
| 93 | + CHECK__(evlist__open(evlist)); |
|---|
| 87 | 94 | |
|---|
| 88 | | - CHECK__(perf_evlist__mmap(evlist, UINT_MAX)); |
|---|
| 95 | + CHECK__(evlist__mmap(evlist, UINT_MAX)); |
|---|
| 89 | 96 | |
|---|
| 90 | | - pc = evlist->mmap[0].base; |
|---|
| 97 | + pc = evlist->mmap[0].core.base; |
|---|
| 91 | 98 | ret = perf_read_tsc_conversion(pc, &tc); |
|---|
| 92 | 99 | if (ret) { |
|---|
| 93 | 100 | if (ret == -EOPNOTSUPP) { |
|---|
| .. | .. |
|---|
| 97 | 104 | goto out_err; |
|---|
| 98 | 105 | } |
|---|
| 99 | 106 | |
|---|
| 100 | | - perf_evlist__enable(evlist); |
|---|
| 107 | + evlist__enable(evlist); |
|---|
| 101 | 108 | |
|---|
| 102 | 109 | comm1 = "Test COMM 1"; |
|---|
| 103 | 110 | CHECK__(prctl(PR_SET_NAME, (unsigned long)comm1, 0, 0, 0)); |
|---|
| .. | .. |
|---|
| 107 | 114 | comm2 = "Test COMM 2"; |
|---|
| 108 | 115 | CHECK__(prctl(PR_SET_NAME, (unsigned long)comm2, 0, 0, 0)); |
|---|
| 109 | 116 | |
|---|
| 110 | | - perf_evlist__disable(evlist); |
|---|
| 117 | + evlist__disable(evlist); |
|---|
| 111 | 118 | |
|---|
| 112 | | - for (i = 0; i < evlist->nr_mmaps; i++) { |
|---|
| 119 | + for (i = 0; i < evlist->core.nr_mmaps; i++) { |
|---|
| 113 | 120 | md = &evlist->mmap[i]; |
|---|
| 114 | | - if (perf_mmap__read_init(md) < 0) |
|---|
| 121 | + if (perf_mmap__read_init(&md->core) < 0) |
|---|
| 115 | 122 | continue; |
|---|
| 116 | 123 | |
|---|
| 117 | | - while ((event = perf_mmap__read_event(md)) != NULL) { |
|---|
| 124 | + while ((event = perf_mmap__read_event(&md->core)) != NULL) { |
|---|
| 118 | 125 | struct perf_sample sample; |
|---|
| 119 | 126 | |
|---|
| 120 | 127 | if (event->header.type != PERF_RECORD_COMM || |
|---|
| .. | .. |
|---|
| 123 | 130 | goto next_event; |
|---|
| 124 | 131 | |
|---|
| 125 | 132 | if (strcmp(event->comm.comm, comm1) == 0) { |
|---|
| 126 | | - CHECK__(perf_evsel__parse_sample(evsel, event, |
|---|
| 127 | | - &sample)); |
|---|
| 133 | + CHECK__(evsel__parse_sample(evsel, event, &sample)); |
|---|
| 128 | 134 | comm1_time = sample.time; |
|---|
| 129 | 135 | } |
|---|
| 130 | 136 | if (strcmp(event->comm.comm, comm2) == 0) { |
|---|
| 131 | | - CHECK__(perf_evsel__parse_sample(evsel, event, |
|---|
| 132 | | - &sample)); |
|---|
| 137 | + CHECK__(evsel__parse_sample(evsel, event, &sample)); |
|---|
| 133 | 138 | comm2_time = sample.time; |
|---|
| 134 | 139 | } |
|---|
| 135 | 140 | next_event: |
|---|
| 136 | | - perf_mmap__consume(md); |
|---|
| 141 | + perf_mmap__consume(&md->core); |
|---|
| 137 | 142 | } |
|---|
| 138 | | - perf_mmap__read_done(md); |
|---|
| 143 | + perf_mmap__read_done(&md->core); |
|---|
| 139 | 144 | } |
|---|
| 140 | 145 | |
|---|
| 141 | 146 | if (!comm1_time || !comm2_time) |
|---|
| .. | .. |
|---|
| 163 | 168 | err = 0; |
|---|
| 164 | 169 | |
|---|
| 165 | 170 | out_err: |
|---|
| 166 | | - perf_evlist__delete(evlist); |
|---|
| 171 | + evlist__delete(evlist); |
|---|
| 167 | 172 | return err; |
|---|
| 168 | 173 | } |
|---|