.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
---|
2 | 2 | #include <linux/types.h> |
---|
| 3 | +#include <limits.h> |
---|
3 | 4 | #include <unistd.h> |
---|
4 | 5 | #include <sys/prctl.h> |
---|
| 6 | +#include <perf/cpumap.h> |
---|
| 7 | +#include <perf/evlist.h> |
---|
| 8 | +#include <perf/mmap.h> |
---|
5 | 9 | |
---|
| 10 | +#include "debug.h" |
---|
6 | 11 | #include "parse-events.h" |
---|
7 | 12 | #include "evlist.h" |
---|
8 | 13 | #include "evsel.h" |
---|
| 14 | +#include "record.h" |
---|
9 | 15 | #include "thread_map.h" |
---|
10 | | -#include "cpumap.h" |
---|
11 | 16 | #include "tests.h" |
---|
| 17 | +#include "util/mmap.h" |
---|
12 | 18 | |
---|
13 | 19 | #define CHECK__(x) { \ |
---|
14 | 20 | while ((x) < 0) { \ |
---|
.. | .. |
---|
24 | 30 | } \ |
---|
25 | 31 | } |
---|
26 | 32 | |
---|
27 | | -static int find_comm(struct perf_evlist *evlist, const char *comm) |
---|
| 33 | +static int find_comm(struct evlist *evlist, const char *comm) |
---|
28 | 34 | { |
---|
29 | 35 | union perf_event *event; |
---|
30 | | - struct perf_mmap *md; |
---|
| 36 | + struct mmap *md; |
---|
31 | 37 | int i, found; |
---|
32 | 38 | |
---|
33 | 39 | found = 0; |
---|
34 | | - for (i = 0; i < evlist->nr_mmaps; i++) { |
---|
| 40 | + for (i = 0; i < evlist->core.nr_mmaps; i++) { |
---|
35 | 41 | md = &evlist->mmap[i]; |
---|
36 | | - if (perf_mmap__read_init(md) < 0) |
---|
| 42 | + if (perf_mmap__read_init(&md->core) < 0) |
---|
37 | 43 | continue; |
---|
38 | | - while ((event = perf_mmap__read_event(md)) != NULL) { |
---|
| 44 | + while ((event = perf_mmap__read_event(&md->core)) != NULL) { |
---|
39 | 45 | if (event->header.type == PERF_RECORD_COMM && |
---|
40 | 46 | (pid_t)event->comm.pid == getpid() && |
---|
41 | 47 | (pid_t)event->comm.tid == getpid() && |
---|
42 | 48 | strcmp(event->comm.comm, comm) == 0) |
---|
43 | 49 | found += 1; |
---|
44 | | - perf_mmap__consume(md); |
---|
| 50 | + perf_mmap__consume(&md->core); |
---|
45 | 51 | } |
---|
46 | | - perf_mmap__read_done(md); |
---|
| 52 | + perf_mmap__read_done(&md->core); |
---|
47 | 53 | } |
---|
48 | 54 | return found; |
---|
49 | 55 | } |
---|
.. | .. |
---|
65 | 71 | .uses_mmap = true, |
---|
66 | 72 | }, |
---|
67 | 73 | }; |
---|
68 | | - struct thread_map *threads = NULL; |
---|
69 | | - struct cpu_map *cpus = NULL; |
---|
70 | | - struct perf_evlist *evlist = NULL; |
---|
71 | | - struct perf_evsel *evsel = NULL; |
---|
| 74 | + struct perf_thread_map *threads = NULL; |
---|
| 75 | + struct perf_cpu_map *cpus = NULL; |
---|
| 76 | + struct evlist *evlist = NULL; |
---|
| 77 | + struct evsel *evsel = NULL; |
---|
72 | 78 | int found, err = -1; |
---|
73 | 79 | const char *comm; |
---|
74 | 80 | |
---|
75 | 81 | threads = thread_map__new(-1, getpid(), UINT_MAX); |
---|
76 | 82 | CHECK_NOT_NULL__(threads); |
---|
77 | 83 | |
---|
78 | | - cpus = cpu_map__new(NULL); |
---|
| 84 | + cpus = perf_cpu_map__new(NULL); |
---|
79 | 85 | CHECK_NOT_NULL__(cpus); |
---|
80 | 86 | |
---|
81 | | - evlist = perf_evlist__new(); |
---|
| 87 | + evlist = evlist__new(); |
---|
82 | 88 | CHECK_NOT_NULL__(evlist); |
---|
83 | 89 | |
---|
84 | | - perf_evlist__set_maps(evlist, cpus, threads); |
---|
| 90 | + perf_evlist__set_maps(&evlist->core, cpus, threads); |
---|
85 | 91 | |
---|
86 | 92 | CHECK__(parse_events(evlist, "dummy:u", NULL)); |
---|
87 | 93 | CHECK__(parse_events(evlist, "cycles:u", NULL)); |
---|
88 | 94 | |
---|
89 | 95 | perf_evlist__config(evlist, &opts, NULL); |
---|
90 | 96 | |
---|
91 | | - evsel = perf_evlist__first(evlist); |
---|
| 97 | + evsel = evlist__first(evlist); |
---|
92 | 98 | |
---|
93 | | - evsel->attr.comm = 1; |
---|
94 | | - evsel->attr.disabled = 1; |
---|
95 | | - evsel->attr.enable_on_exec = 0; |
---|
| 99 | + evsel->core.attr.comm = 1; |
---|
| 100 | + evsel->core.attr.disabled = 1; |
---|
| 101 | + evsel->core.attr.enable_on_exec = 0; |
---|
96 | 102 | |
---|
97 | | - if (perf_evlist__open(evlist) < 0) { |
---|
| 103 | + if (evlist__open(evlist) < 0) { |
---|
98 | 104 | pr_debug("Unable to open dummy and cycles event\n"); |
---|
99 | 105 | err = TEST_SKIP; |
---|
100 | 106 | goto out_err; |
---|
101 | 107 | } |
---|
102 | 108 | |
---|
103 | | - CHECK__(perf_evlist__mmap(evlist, UINT_MAX)); |
---|
| 109 | + CHECK__(evlist__mmap(evlist, UINT_MAX)); |
---|
104 | 110 | |
---|
105 | 111 | /* |
---|
106 | 112 | * First, test that a 'comm' event can be found when the event is |
---|
107 | 113 | * enabled. |
---|
108 | 114 | */ |
---|
109 | 115 | |
---|
110 | | - perf_evlist__enable(evlist); |
---|
| 116 | + evlist__enable(evlist); |
---|
111 | 117 | |
---|
112 | 118 | comm = "Test COMM 1"; |
---|
113 | 119 | CHECK__(prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0)); |
---|
114 | 120 | |
---|
115 | | - perf_evlist__disable(evlist); |
---|
| 121 | + evlist__disable(evlist); |
---|
116 | 122 | |
---|
117 | 123 | found = find_comm(evlist, comm); |
---|
118 | 124 | if (found != 1) { |
---|
.. | .. |
---|
125 | 131 | * disabled with the dummy event still enabled. |
---|
126 | 132 | */ |
---|
127 | 133 | |
---|
128 | | - perf_evlist__enable(evlist); |
---|
| 134 | + evlist__enable(evlist); |
---|
129 | 135 | |
---|
130 | | - evsel = perf_evlist__last(evlist); |
---|
| 136 | + evsel = evlist__last(evlist); |
---|
131 | 137 | |
---|
132 | | - CHECK__(perf_evsel__disable(evsel)); |
---|
| 138 | + CHECK__(evsel__disable(evsel)); |
---|
133 | 139 | |
---|
134 | 140 | comm = "Test COMM 2"; |
---|
135 | 141 | CHECK__(prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0)); |
---|
136 | 142 | |
---|
137 | | - perf_evlist__disable(evlist); |
---|
| 143 | + evlist__disable(evlist); |
---|
138 | 144 | |
---|
139 | 145 | found = find_comm(evlist, comm); |
---|
140 | 146 | if (found != 1) { |
---|
141 | | - pr_debug("Seconf time, failed to find tracking event.\n"); |
---|
| 147 | + pr_debug("Second time, failed to find tracking event.\n"); |
---|
142 | 148 | goto out_err; |
---|
143 | 149 | } |
---|
144 | 150 | |
---|
.. | .. |
---|
146 | 152 | |
---|
147 | 153 | out_err: |
---|
148 | 154 | if (evlist) { |
---|
149 | | - perf_evlist__disable(evlist); |
---|
150 | | - perf_evlist__delete(evlist); |
---|
| 155 | + evlist__disable(evlist); |
---|
| 156 | + evlist__delete(evlist); |
---|
151 | 157 | } else { |
---|
152 | | - cpu_map__put(cpus); |
---|
153 | | - thread_map__put(threads); |
---|
| 158 | + perf_cpu_map__put(cpus); |
---|
| 159 | + perf_thread_map__put(threads); |
---|
154 | 160 | } |
---|
155 | 161 | |
---|
156 | 162 | return err; |
---|