hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/tools/perf/tests/keep-tracking.c
....@@ -1,14 +1,20 @@
11 // SPDX-License-Identifier: GPL-2.0
22 #include <linux/types.h>
3
+#include <limits.h>
34 #include <unistd.h>
45 #include <sys/prctl.h>
6
+#include <perf/cpumap.h>
7
+#include <perf/evlist.h>
8
+#include <perf/mmap.h>
59
10
+#include "debug.h"
611 #include "parse-events.h"
712 #include "evlist.h"
813 #include "evsel.h"
14
+#include "record.h"
915 #include "thread_map.h"
10
-#include "cpumap.h"
1116 #include "tests.h"
17
+#include "util/mmap.h"
1218
1319 #define CHECK__(x) { \
1420 while ((x) < 0) { \
....@@ -24,26 +30,26 @@
2430 } \
2531 }
2632
27
-static int find_comm(struct perf_evlist *evlist, const char *comm)
33
+static int find_comm(struct evlist *evlist, const char *comm)
2834 {
2935 union perf_event *event;
30
- struct perf_mmap *md;
36
+ struct mmap *md;
3137 int i, found;
3238
3339 found = 0;
34
- for (i = 0; i < evlist->nr_mmaps; i++) {
40
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
3541 md = &evlist->mmap[i];
36
- if (perf_mmap__read_init(md) < 0)
42
+ if (perf_mmap__read_init(&md->core) < 0)
3743 continue;
38
- while ((event = perf_mmap__read_event(md)) != NULL) {
44
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
3945 if (event->header.type == PERF_RECORD_COMM &&
4046 (pid_t)event->comm.pid == getpid() &&
4147 (pid_t)event->comm.tid == getpid() &&
4248 strcmp(event->comm.comm, comm) == 0)
4349 found += 1;
44
- perf_mmap__consume(md);
50
+ perf_mmap__consume(&md->core);
4551 }
46
- perf_mmap__read_done(md);
52
+ perf_mmap__read_done(&md->core);
4753 }
4854 return found;
4955 }
....@@ -65,54 +71,54 @@
6571 .uses_mmap = true,
6672 },
6773 };
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;
7278 int found, err = -1;
7379 const char *comm;
7480
7581 threads = thread_map__new(-1, getpid(), UINT_MAX);
7682 CHECK_NOT_NULL__(threads);
7783
78
- cpus = cpu_map__new(NULL);
84
+ cpus = perf_cpu_map__new(NULL);
7985 CHECK_NOT_NULL__(cpus);
8086
81
- evlist = perf_evlist__new();
87
+ evlist = evlist__new();
8288 CHECK_NOT_NULL__(evlist);
8389
84
- perf_evlist__set_maps(evlist, cpus, threads);
90
+ perf_evlist__set_maps(&evlist->core, cpus, threads);
8591
8692 CHECK__(parse_events(evlist, "dummy:u", NULL));
8793 CHECK__(parse_events(evlist, "cycles:u", NULL));
8894
8995 perf_evlist__config(evlist, &opts, NULL);
9096
91
- evsel = perf_evlist__first(evlist);
97
+ evsel = evlist__first(evlist);
9298
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;
96102
97
- if (perf_evlist__open(evlist) < 0) {
103
+ if (evlist__open(evlist) < 0) {
98104 pr_debug("Unable to open dummy and cycles event\n");
99105 err = TEST_SKIP;
100106 goto out_err;
101107 }
102108
103
- CHECK__(perf_evlist__mmap(evlist, UINT_MAX));
109
+ CHECK__(evlist__mmap(evlist, UINT_MAX));
104110
105111 /*
106112 * First, test that a 'comm' event can be found when the event is
107113 * enabled.
108114 */
109115
110
- perf_evlist__enable(evlist);
116
+ evlist__enable(evlist);
111117
112118 comm = "Test COMM 1";
113119 CHECK__(prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0));
114120
115
- perf_evlist__disable(evlist);
121
+ evlist__disable(evlist);
116122
117123 found = find_comm(evlist, comm);
118124 if (found != 1) {
....@@ -125,20 +131,20 @@
125131 * disabled with the dummy event still enabled.
126132 */
127133
128
- perf_evlist__enable(evlist);
134
+ evlist__enable(evlist);
129135
130
- evsel = perf_evlist__last(evlist);
136
+ evsel = evlist__last(evlist);
131137
132
- CHECK__(perf_evsel__disable(evsel));
138
+ CHECK__(evsel__disable(evsel));
133139
134140 comm = "Test COMM 2";
135141 CHECK__(prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0));
136142
137
- perf_evlist__disable(evlist);
143
+ evlist__disable(evlist);
138144
139145 found = find_comm(evlist, comm);
140146 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");
142148 goto out_err;
143149 }
144150
....@@ -146,11 +152,11 @@
146152
147153 out_err:
148154 if (evlist) {
149
- perf_evlist__disable(evlist);
150
- perf_evlist__delete(evlist);
155
+ evlist__disable(evlist);
156
+ evlist__delete(evlist);
151157 } else {
152
- cpu_map__put(cpus);
153
- thread_map__put(threads);
158
+ perf_cpu_map__put(cpus);
159
+ perf_thread_map__put(threads);
154160 }
155161
156162 return err;