aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2013-08-31 14:50:53 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-09-02 13:58:20 -0400
commit395c307089c9f5f0d82c63c11c79227b57bb7ac5 (patch)
treefb0574d23782254c3781a7a21f1f11ab80121e65 /tools
parentd22d1a2a2c224b3b378d873589ced27add7ebde4 (diff)
perf tests: Add 'keep tracking' test
Add a test for the newly added PERF_COUNT_SW_DUMMY event. The test checks that tracking events continue when an event is disabled but a dummy software event is not disabled. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Acked-by: Jiri Olsa <jolsa@redhat.com> Tested-by: Jiri Olsa <jolsa@redhat.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1377975053-3811-4-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/Makefile1
-rw-r--r--tools/perf/tests/builtin-test.c4
-rw-r--r--tools/perf/tests/keep-tracking.c154
-rw-r--r--tools/perf/tests/tests.h1
-rw-r--r--tools/perf/util/evlist.c42
-rw-r--r--tools/perf/util/evlist.h5
6 files changed, 205 insertions, 2 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index ecebfd00295e..c5dc1ad1b8d7 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -465,6 +465,7 @@ endif # NO_LIBELF
465ifndef NO_LIBUNWIND 465ifndef NO_LIBUNWIND
466 LIB_OBJS += $(OUTPUT)util/unwind.o 466 LIB_OBJS += $(OUTPUT)util/unwind.o
467endif 467endif
468LIB_OBJS += $(OUTPUT)tests/keep-tracking.o
468 469
469ifndef NO_LIBAUDIT 470ifndef NO_LIBAUDIT
470 BUILTIN_OBJS += $(OUTPUT)builtin-trace.o 471 BUILTIN_OBJS += $(OUTPUT)builtin-trace.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 8ad9415dd847..8bbeba322df9 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -108,6 +108,10 @@ static struct test {
108 .func = test__sample_parsing, 108 .func = test__sample_parsing,
109 }, 109 },
110 { 110 {
111 .desc = "Test using a dummy software event to keep tracking",
112 .func = test__keep_tracking,
113 },
114 {
111 .func = NULL, 115 .func = NULL,
112 }, 116 },
113}; 117};
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
new file mode 100644
index 000000000000..d444ea2c47d9
--- /dev/null
+++ b/tools/perf/tests/keep-tracking.c
@@ -0,0 +1,154 @@
1#include <sys/types.h>
2#include <unistd.h>
3#include <sys/prctl.h>
4
5#include "parse-events.h"
6#include "evlist.h"
7#include "evsel.h"
8#include "thread_map.h"
9#include "cpumap.h"
10#include "tests.h"
11
12#define CHECK__(x) { \
13 while ((x) < 0) { \
14 pr_debug(#x " failed!\n"); \
15 goto out_err; \
16 } \
17}
18
19#define CHECK_NOT_NULL__(x) { \
20 while ((x) == NULL) { \
21 pr_debug(#x " failed!\n"); \
22 goto out_err; \
23 } \
24}
25
26static int find_comm(struct perf_evlist *evlist, const char *comm)
27{
28 union perf_event *event;
29 int i, found;
30
31 found = 0;
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)
38 found += 1;
39 }
40 }
41 return found;
42}
43
44/**
45 * test__keep_tracking - test using a dummy software event to keep tracking.
46 *
47 * This function implements a test that checks that tracking events continue
48 * when an event is disabled but a dummy software event is not disabled. If the
49 * test passes %0 is returned, otherwise %-1 is returned.
50 */
51int test__keep_tracking(void)
52{
53 struct perf_record_opts opts = {
54 .mmap_pages = UINT_MAX,
55 .user_freq = UINT_MAX,
56 .user_interval = ULLONG_MAX,
57 .freq = 4000,
58 .target = {
59 .uses_mmap = true,
60 },
61 };
62 struct thread_map *threads = NULL;
63 struct cpu_map *cpus = NULL;
64 struct perf_evlist *evlist = NULL;
65 struct perf_evsel *evsel = NULL;
66 int found, err = -1;
67 const char *comm;
68
69 threads = thread_map__new(-1, getpid(), UINT_MAX);
70 CHECK_NOT_NULL__(threads);
71
72 cpus = cpu_map__new(NULL);
73 CHECK_NOT_NULL__(cpus);
74
75 evlist = perf_evlist__new();
76 CHECK_NOT_NULL__(evlist);
77
78 perf_evlist__set_maps(evlist, cpus, threads);
79
80 CHECK__(parse_events(evlist, "dummy:u"));
81 CHECK__(parse_events(evlist, "cycles:u"));
82
83 perf_evlist__config(evlist, &opts);
84
85 evsel = perf_evlist__first(evlist);
86
87 evsel->attr.comm = 1;
88 evsel->attr.disabled = 1;
89 evsel->attr.enable_on_exec = 0;
90
91 if (perf_evlist__open(evlist) < 0) {
92 fprintf(stderr, " (not supported)");
93 err = 0;
94 goto out_err;
95 }
96
97 CHECK__(perf_evlist__mmap(evlist, UINT_MAX, false));
98
99 /*
100 * First, test that a 'comm' event can be found when the event is
101 * enabled.
102 */
103
104 perf_evlist__enable(evlist);
105
106 comm = "Test COMM 1";
107 CHECK__(prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0));
108
109 perf_evlist__disable(evlist);
110
111 found = find_comm(evlist, comm);
112 if (found != 1) {
113 pr_debug("First time, failed to find tracking event.\n");
114 goto out_err;
115 }
116
117 /*
118 * Secondly, test that a 'comm' event can be found when the event is
119 * disabled with the dummy event still enabled.
120 */
121
122 perf_evlist__enable(evlist);
123
124 evsel = perf_evlist__last(evlist);
125
126 CHECK__(perf_evlist__disable_event(evlist, evsel));
127
128 comm = "Test COMM 2";
129 CHECK__(prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0));
130
131 perf_evlist__disable(evlist);
132
133 found = find_comm(evlist, comm);
134 if (found != 1) {
135 pr_debug("Seconf time, failed to find tracking event.\n");
136 goto out_err;
137 }
138
139 err = 0;
140
141out_err:
142 if (evlist) {
143 perf_evlist__disable(evlist);
144 perf_evlist__munmap(evlist);
145 perf_evlist__close(evlist);
146 perf_evlist__delete(evlist);
147 }
148 if (cpus)
149 cpu_map__delete(cpus);
150 if (threads)
151 thread_map__delete(threads);
152
153 return err;
154}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 83d5b71a3ce4..c048b589998a 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -38,5 +38,6 @@ int test__sw_clock_freq(void);
38int test__perf_time_to_tsc(void); 38int test__perf_time_to_tsc(void);
39int test__code_reading(void); 39int test__code_reading(void);
40int test__sample_parsing(void); 40int test__sample_parsing(void);
41int test__keep_tracking(void);
41 42
42#endif /* TESTS_H */ 43#endif /* TESTS_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 5df4ca91bed3..b8727ae45e3b 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -246,7 +246,7 @@ void perf_evlist__disable(struct perf_evlist *evlist)
246 246
247 for (cpu = 0; cpu < nr_cpus; cpu++) { 247 for (cpu = 0; cpu < nr_cpus; cpu++) {
248 list_for_each_entry(pos, &evlist->entries, node) { 248 list_for_each_entry(pos, &evlist->entries, node) {
249 if (!perf_evsel__is_group_leader(pos)) 249 if (!perf_evsel__is_group_leader(pos) || !pos->fd)
250 continue; 250 continue;
251 for (thread = 0; thread < nr_threads; thread++) 251 for (thread = 0; thread < nr_threads; thread++)
252 ioctl(FD(pos, cpu, thread), 252 ioctl(FD(pos, cpu, thread),
@@ -264,7 +264,7 @@ void perf_evlist__enable(struct perf_evlist *evlist)
264 264
265 for (cpu = 0; cpu < nr_cpus; cpu++) { 265 for (cpu = 0; cpu < nr_cpus; cpu++) {
266 list_for_each_entry(pos, &evlist->entries, node) { 266 list_for_each_entry(pos, &evlist->entries, node) {
267 if (!perf_evsel__is_group_leader(pos)) 267 if (!perf_evsel__is_group_leader(pos) || !pos->fd)
268 continue; 268 continue;
269 for (thread = 0; thread < nr_threads; thread++) 269 for (thread = 0; thread < nr_threads; thread++)
270 ioctl(FD(pos, cpu, thread), 270 ioctl(FD(pos, cpu, thread),
@@ -273,6 +273,44 @@ void perf_evlist__enable(struct perf_evlist *evlist)
273 } 273 }
274} 274}
275 275
276int perf_evlist__disable_event(struct perf_evlist *evlist,
277 struct perf_evsel *evsel)
278{
279 int cpu, thread, err;
280
281 if (!evsel->fd)
282 return 0;
283
284 for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
285 for (thread = 0; thread < evlist->threads->nr; thread++) {
286 err = ioctl(FD(evsel, cpu, thread),
287 PERF_EVENT_IOC_DISABLE, 0);
288 if (err)
289 return err;
290 }
291 }
292 return 0;
293}
294
295int perf_evlist__enable_event(struct perf_evlist *evlist,
296 struct perf_evsel *evsel)
297{
298 int cpu, thread, err;
299
300 if (!evsel->fd)
301 return -EINVAL;
302
303 for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
304 for (thread = 0; thread < evlist->threads->nr; thread++) {
305 err = ioctl(FD(evsel, cpu, thread),
306 PERF_EVENT_IOC_ENABLE, 0);
307 if (err)
308 return err;
309 }
310 }
311 return 0;
312}
313
276static int perf_evlist__alloc_pollfd(struct perf_evlist *evlist) 314static int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
277{ 315{
278 int nr_cpus = cpu_map__nr(evlist->cpus); 316 int nr_cpus = cpu_map__nr(evlist->cpus);
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 841a39405f6a..880d7139d2fb 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -110,6 +110,11 @@ void perf_evlist__munmap(struct perf_evlist *evlist);
110void perf_evlist__disable(struct perf_evlist *evlist); 110void perf_evlist__disable(struct perf_evlist *evlist);
111void perf_evlist__enable(struct perf_evlist *evlist); 111void perf_evlist__enable(struct perf_evlist *evlist);
112 112
113int perf_evlist__disable_event(struct perf_evlist *evlist,
114 struct perf_evsel *evsel);
115int perf_evlist__enable_event(struct perf_evlist *evlist,
116 struct perf_evsel *evsel);
117
113void perf_evlist__set_selected(struct perf_evlist *evlist, 118void perf_evlist__set_selected(struct perf_evlist *evlist,
114 struct perf_evsel *evsel); 119 struct perf_evsel *evsel);
115 120