]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - tools/perf/tests/keep-tracking.c
8e2ec5f72042c6ee5d33191855b93a4a6ae9b520
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/types.h>
6 #include <perf/cpumap.h>
7 #include <perf/evlist.h>
10 #include "parse-events.h"
14 #include "thread_map.h"
17 #define CHECK__(x) { \
19 pr_debug(#x " failed!\n"); \
24 #define CHECK_NOT_NULL__(x) { \
25 while ((x) == NULL) { \
26 pr_debug(#x " failed!\n"); \
31 static int find_comm(struct evlist
*evlist
, const char *comm
)
33 union perf_event
*event
;
38 for (i
= 0; i
< evlist
->nr_mmaps
; i
++) {
39 md
= &evlist
->mmap
[i
];
40 if (perf_mmap__read_init(md
) < 0)
42 while ((event
= perf_mmap__read_event(md
)) != NULL
) {
43 if (event
->header
.type
== PERF_RECORD_COMM
&&
44 (pid_t
)event
->comm
.pid
== getpid() &&
45 (pid_t
)event
->comm
.tid
== getpid() &&
46 strcmp(event
->comm
.comm
, comm
) == 0)
48 perf_mmap__consume(md
);
50 perf_mmap__read_done(md
);
56 * test__keep_tracking - test using a dummy software event to keep tracking.
58 * This function implements a test that checks that tracking events continue
59 * when an event is disabled but a dummy software event is not disabled. If the
60 * test passes %0 is returned, otherwise %-1 is returned.
62 int test__keep_tracking(struct test
*test __maybe_unused
, int subtest __maybe_unused
)
64 struct record_opts opts
= {
65 .mmap_pages
= UINT_MAX
,
66 .user_freq
= UINT_MAX
,
67 .user_interval
= ULLONG_MAX
,
72 struct perf_thread_map
*threads
= NULL
;
73 struct perf_cpu_map
*cpus
= NULL
;
74 struct evlist
*evlist
= NULL
;
75 struct evsel
*evsel
= NULL
;
79 threads
= thread_map__new(-1, getpid(), UINT_MAX
);
80 CHECK_NOT_NULL__(threads
);
82 cpus
= perf_cpu_map__new(NULL
);
83 CHECK_NOT_NULL__(cpus
);
85 evlist
= evlist__new();
86 CHECK_NOT_NULL__(evlist
);
88 perf_evlist__set_maps(&evlist
->core
, cpus
, threads
);
90 CHECK__(parse_events(evlist
, "dummy:u", NULL
));
91 CHECK__(parse_events(evlist
, "cycles:u", NULL
));
93 perf_evlist__config(evlist
, &opts
, NULL
);
95 evsel
= perf_evlist__first(evlist
);
97 evsel
->core
.attr
.comm
= 1;
98 evsel
->core
.attr
.disabled
= 1;
99 evsel
->core
.attr
.enable_on_exec
= 0;
101 if (evlist__open(evlist
) < 0) {
102 pr_debug("Unable to open dummy and cycles event\n");
107 CHECK__(evlist__mmap(evlist
, UINT_MAX
));
110 * First, test that a 'comm' event can be found when the event is
114 evlist__enable(evlist
);
116 comm
= "Test COMM 1";
117 CHECK__(prctl(PR_SET_NAME
, (unsigned long)comm
, 0, 0, 0));
119 evlist__disable(evlist
);
121 found
= find_comm(evlist
, comm
);
123 pr_debug("First time, failed to find tracking event.\n");
128 * Secondly, test that a 'comm' event can be found when the event is
129 * disabled with the dummy event still enabled.
132 evlist__enable(evlist
);
134 evsel
= perf_evlist__last(evlist
);
136 CHECK__(evsel__disable(evsel
));
138 comm
= "Test COMM 2";
139 CHECK__(prctl(PR_SET_NAME
, (unsigned long)comm
, 0, 0, 0));
141 evlist__disable(evlist
);
143 found
= find_comm(evlist
, comm
);
145 pr_debug("Second time, failed to find tracking event.\n");
153 evlist__disable(evlist
);
154 evlist__delete(evlist
);
156 perf_cpu_map__put(cpus
);
157 perf_thread_map__put(threads
);