1 #include <linux/types.h>
5 #include "parse-events.h"
8 #include "thread_map.h"
12 #define CHECK__(x) { \
14 pr_debug(#x " failed!\n"); \
19 #define CHECK_NOT_NULL__(x) { \
20 while ((x) == NULL) { \
21 pr_debug(#x " failed!\n"); \
26 static int find_comm(struct perf_evlist
*evlist
, const char *comm
)
28 union perf_event
*event
;
32 for (i
= 0; i
< evlist
->nr_mmaps
; i
++) {
33 while ((event
= perf_evlist__mmap_read(evlist
, i
)) != NULL
) {
34 if (event
->header
.type
== PERF_RECORD_COMM
&&
35 (pid_t
)event
->comm
.pid
== getpid() &&
36 (pid_t
)event
->comm
.tid
== getpid() &&
37 strcmp(event
->comm
.comm
, comm
) == 0)
39 perf_evlist__mmap_consume(evlist
, i
);
46 * test__keep_tracking - test using a dummy software event to keep tracking.
48 * This function implements a test that checks that tracking events continue
49 * when an event is disabled but a dummy software event is not disabled. If the
50 * test passes %0 is returned, otherwise %-1 is returned.
52 int test__keep_tracking(void)
54 struct record_opts opts
= {
55 .mmap_pages
= UINT_MAX
,
56 .user_freq
= UINT_MAX
,
57 .user_interval
= ULLONG_MAX
,
63 struct thread_map
*threads
= NULL
;
64 struct cpu_map
*cpus
= NULL
;
65 struct perf_evlist
*evlist
= NULL
;
66 struct perf_evsel
*evsel
= NULL
;
70 threads
= thread_map__new(-1, getpid(), UINT_MAX
);
71 CHECK_NOT_NULL__(threads
);
73 cpus
= cpu_map__new(NULL
);
74 CHECK_NOT_NULL__(cpus
);
76 evlist
= perf_evlist__new();
77 CHECK_NOT_NULL__(evlist
);
79 perf_evlist__set_maps(evlist
, cpus
, threads
);
81 CHECK__(parse_events(evlist
, "dummy:u"));
82 CHECK__(parse_events(evlist
, "cycles:u"));
84 perf_evlist__config(evlist
, &opts
);
86 evsel
= perf_evlist__first(evlist
);
89 evsel
->attr
.disabled
= 1;
90 evsel
->attr
.enable_on_exec
= 0;
92 if (perf_evlist__open(evlist
) < 0) {
93 fprintf(stderr
, " (not supported)");
98 CHECK__(perf_evlist__mmap(evlist
, UINT_MAX
, false));
101 * First, test that a 'comm' event can be found when the event is
105 perf_evlist__enable(evlist
);
107 comm
= "Test COMM 1";
108 CHECK__(prctl(PR_SET_NAME
, (unsigned long)comm
, 0, 0, 0));
110 perf_evlist__disable(evlist
);
112 found
= find_comm(evlist
, comm
);
114 pr_debug("First time, failed to find tracking event.\n");
119 * Secondly, test that a 'comm' event can be found when the event is
120 * disabled with the dummy event still enabled.
123 perf_evlist__enable(evlist
);
125 evsel
= perf_evlist__last(evlist
);
127 CHECK__(perf_evlist__disable_event(evlist
, evsel
));
129 comm
= "Test COMM 2";
130 CHECK__(prctl(PR_SET_NAME
, (unsigned long)comm
, 0, 0, 0));
132 perf_evlist__disable(evlist
);
134 found
= find_comm(evlist
, comm
);
136 pr_debug("Seconf time, failed to find tracking event.\n");
144 perf_evlist__disable(evlist
);
145 perf_evlist__delete(evlist
);
147 cpu_map__delete(cpus
);
148 thread_map__delete(threads
);