1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/types.h>
6 #include "parse-events.h"
9 #include "thread_map.h"
13 #define CHECK__(x) { \
15 pr_debug(#x " failed!\n"); \
20 #define CHECK_NOT_NULL__(x) { \
21 while ((x) == NULL) { \
22 pr_debug(#x " failed!\n"); \
27 static int find_comm(struct perf_evlist
*evlist
, const char *comm
)
29 union perf_event
*event
;
34 for (i
= 0; i
< evlist
->nr_mmaps
; i
++) {
35 md
= &evlist
->mmap
[i
];
36 if (perf_mmap__read_init(md
) < 0)
38 while ((event
= perf_mmap__read_event(md
)) != NULL
) {
39 if (event
->header
.type
== PERF_RECORD_COMM
&&
40 (pid_t
)event
->comm
.pid
== getpid() &&
41 (pid_t
)event
->comm
.tid
== getpid() &&
42 strcmp(event
->comm
.comm
, comm
) == 0)
44 perf_mmap__consume(md
);
46 perf_mmap__read_done(md
);
52 * test__keep_tracking - test using a dummy software event to keep tracking.
54 * This function implements a test that checks that tracking events continue
55 * when an event is disabled but a dummy software event is not disabled. If the
56 * test passes %0 is returned, otherwise %-1 is returned.
58 int test__keep_tracking(struct test
*test __maybe_unused
, int subtest __maybe_unused
)
60 struct record_opts opts
= {
61 .mmap_pages
= UINT_MAX
,
62 .user_freq
= UINT_MAX
,
63 .user_interval
= ULLONG_MAX
,
68 struct thread_map
*threads
= NULL
;
69 struct cpu_map
*cpus
= NULL
;
70 struct perf_evlist
*evlist
= NULL
;
71 struct perf_evsel
*evsel
= NULL
;
75 threads
= thread_map__new(-1, getpid(), UINT_MAX
);
76 CHECK_NOT_NULL__(threads
);
78 cpus
= cpu_map__new(NULL
);
79 CHECK_NOT_NULL__(cpus
);
81 evlist
= perf_evlist__new();
82 CHECK_NOT_NULL__(evlist
);
84 perf_evlist__set_maps(evlist
, cpus
, threads
);
86 CHECK__(parse_events(evlist
, "dummy:u", NULL
));
87 CHECK__(parse_events(evlist
, "cycles:u", NULL
));
89 perf_evlist__config(evlist
, &opts
, NULL
);
91 evsel
= perf_evlist__first(evlist
);
94 evsel
->attr
.disabled
= 1;
95 evsel
->attr
.enable_on_exec
= 0;
97 if (perf_evlist__open(evlist
) < 0) {
98 pr_debug("Unable to open dummy and cycles event\n");
103 CHECK__(perf_evlist__mmap(evlist
, UINT_MAX
));
106 * First, test that a 'comm' event can be found when the event is
110 perf_evlist__enable(evlist
);
112 comm
= "Test COMM 1";
113 CHECK__(prctl(PR_SET_NAME
, (unsigned long)comm
, 0, 0, 0));
115 perf_evlist__disable(evlist
);
117 found
= find_comm(evlist
, comm
);
119 pr_debug("First time, failed to find tracking event.\n");
124 * Secondly, test that a 'comm' event can be found when the event is
125 * disabled with the dummy event still enabled.
128 perf_evlist__enable(evlist
);
130 evsel
= perf_evlist__last(evlist
);
132 CHECK__(perf_evsel__disable(evsel
));
134 comm
= "Test COMM 2";
135 CHECK__(prctl(PR_SET_NAME
, (unsigned long)comm
, 0, 0, 0));
137 perf_evlist__disable(evlist
);
139 found
= find_comm(evlist
, comm
);
141 pr_debug("Seconf time, failed to find tracking event.\n");
149 perf_evlist__disable(evlist
);
150 perf_evlist__delete(evlist
);
153 thread_map__put(threads
);