diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-12-10 13:11:43 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-12-10 13:11:43 -0500 |
commit | a60d79535c21dca4e24d08abf8ab56e2f860af71 (patch) | |
tree | 4887c99890bc49809cf02c8ac7fd75d7b9b942e5 /tools/perf/tests | |
parent | c5d3d50da2e32441d65d63ac27a67197998668c5 (diff) |
perf test: Use perf_evsel__newtp constructor in the tracepoint tests
Removing one trace_event__id function, not used anymore.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.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 <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-13p2ov2rg166y73j9uazukma@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests')
-rw-r--r-- | tools/perf/tests/mmap-basic.c | 37 | ||||
-rw-r--r-- | tools/perf/tests/open-syscall-all-cpus.c | 18 | ||||
-rw-r--r-- | tools/perf/tests/open-syscall.c | 17 | ||||
-rw-r--r-- | tools/perf/tests/tests.h | 3 | ||||
-rw-r--r-- | tools/perf/tests/util.c | 30 |
5 files changed, 17 insertions, 88 deletions
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 8682ecfb4f66..4743b6d7a09a 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c | |||
@@ -22,36 +22,16 @@ int test__basic_mmap(void) | |||
22 | struct thread_map *threads; | 22 | struct thread_map *threads; |
23 | struct cpu_map *cpus; | 23 | struct cpu_map *cpus; |
24 | struct perf_evlist *evlist; | 24 | struct perf_evlist *evlist; |
25 | struct perf_event_attr attr = { | ||
26 | .type = PERF_TYPE_TRACEPOINT, | ||
27 | .read_format = PERF_FORMAT_ID, | ||
28 | .sample_type = PERF_SAMPLE_ID, | ||
29 | .watermark = 0, | ||
30 | }; | ||
31 | cpu_set_t cpu_set; | 25 | cpu_set_t cpu_set; |
32 | const char *syscall_names[] = { "getsid", "getppid", "getpgrp", | 26 | const char *syscall_names[] = { "getsid", "getppid", "getpgrp", |
33 | "getpgid", }; | 27 | "getpgid", }; |
34 | pid_t (*syscalls[])(void) = { (void *)getsid, getppid, getpgrp, | 28 | pid_t (*syscalls[])(void) = { (void *)getsid, getppid, getpgrp, |
35 | (void*)getpgid }; | 29 | (void*)getpgid }; |
36 | #define nsyscalls ARRAY_SIZE(syscall_names) | 30 | #define nsyscalls ARRAY_SIZE(syscall_names) |
37 | int ids[nsyscalls]; | ||
38 | unsigned int nr_events[nsyscalls], | 31 | unsigned int nr_events[nsyscalls], |
39 | expected_nr_events[nsyscalls], i, j; | 32 | expected_nr_events[nsyscalls], i, j; |
40 | struct perf_evsel *evsels[nsyscalls], *evsel; | 33 | struct perf_evsel *evsels[nsyscalls], *evsel; |
41 | 34 | ||
42 | for (i = 0; i < nsyscalls; ++i) { | ||
43 | char name[64]; | ||
44 | |||
45 | snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]); | ||
46 | ids[i] = trace_event__id(name); | ||
47 | if (ids[i] < 0) { | ||
48 | pr_debug("Is debugfs mounted on /sys/kernel/debug?\n"); | ||
49 | return -1; | ||
50 | } | ||
51 | nr_events[i] = 0; | ||
52 | expected_nr_events[i] = random() % 257; | ||
53 | } | ||
54 | |||
55 | threads = thread_map__new(-1, getpid(), UINT_MAX); | 35 | threads = thread_map__new(-1, getpid(), UINT_MAX); |
56 | if (threads == NULL) { | 36 | if (threads == NULL) { |
57 | pr_debug("thread_map__new\n"); | 37 | pr_debug("thread_map__new\n"); |
@@ -79,18 +59,20 @@ int test__basic_mmap(void) | |||
79 | goto out_free_cpus; | 59 | goto out_free_cpus; |
80 | } | 60 | } |
81 | 61 | ||
82 | /* anonymous union fields, can't be initialized above */ | ||
83 | attr.wakeup_events = 1; | ||
84 | attr.sample_period = 1; | ||
85 | |||
86 | for (i = 0; i < nsyscalls; ++i) { | 62 | for (i = 0; i < nsyscalls; ++i) { |
87 | attr.config = ids[i]; | 63 | char name[64]; |
88 | evsels[i] = perf_evsel__new(&attr, i); | 64 | |
65 | snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]); | ||
66 | evsels[i] = perf_evsel__newtp("syscalls", name, i); | ||
89 | if (evsels[i] == NULL) { | 67 | if (evsels[i] == NULL) { |
90 | pr_debug("perf_evsel__new\n"); | 68 | pr_debug("perf_evsel__new\n"); |
91 | goto out_free_evlist; | 69 | goto out_free_evlist; |
92 | } | 70 | } |
93 | 71 | ||
72 | evsels[i]->attr.wakeup_events = 1; | ||
73 | evsels[i]->attr.read_format |= PERF_FORMAT_ID; | ||
74 | perf_evsel__set_sample_bit(evsels[i], ID); | ||
75 | |||
94 | perf_evlist__add(evlist, evsels[i]); | 76 | perf_evlist__add(evlist, evsels[i]); |
95 | 77 | ||
96 | if (perf_evsel__open(evsels[i], cpus, threads) < 0) { | 78 | if (perf_evsel__open(evsels[i], cpus, threads) < 0) { |
@@ -99,6 +81,9 @@ int test__basic_mmap(void) | |||
99 | strerror(errno)); | 81 | strerror(errno)); |
100 | goto out_close_fd; | 82 | goto out_close_fd; |
101 | } | 83 | } |
84 | |||
85 | nr_events[i] = 0; | ||
86 | expected_nr_events[i] = 1 + rand() % 127; | ||
102 | } | 87 | } |
103 | 88 | ||
104 | if (perf_evlist__mmap(evlist, 128, true) < 0) { | 89 | if (perf_evlist__mmap(evlist, 128, true) < 0) { |
diff --git a/tools/perf/tests/open-syscall-all-cpus.c b/tools/perf/tests/open-syscall-all-cpus.c index 31072aba0d54..9b920a0cce79 100644 --- a/tools/perf/tests/open-syscall-all-cpus.c +++ b/tools/perf/tests/open-syscall-all-cpus.c | |||
@@ -7,20 +7,12 @@ | |||
7 | int test__open_syscall_event_on_all_cpus(void) | 7 | int test__open_syscall_event_on_all_cpus(void) |
8 | { | 8 | { |
9 | int err = -1, fd, cpu; | 9 | int err = -1, fd, cpu; |
10 | struct thread_map *threads; | ||
11 | struct cpu_map *cpus; | 10 | struct cpu_map *cpus; |
12 | struct perf_evsel *evsel; | 11 | struct perf_evsel *evsel; |
13 | struct perf_event_attr attr; | ||
14 | unsigned int nr_open_calls = 111, i; | 12 | unsigned int nr_open_calls = 111, i; |
15 | cpu_set_t cpu_set; | 13 | cpu_set_t cpu_set; |
16 | int id = trace_event__id("sys_enter_open"); | 14 | struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX); |
17 | 15 | ||
18 | if (id < 0) { | ||
19 | pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); | ||
20 | return -1; | ||
21 | } | ||
22 | |||
23 | threads = thread_map__new(-1, getpid(), UINT_MAX); | ||
24 | if (threads == NULL) { | 16 | if (threads == NULL) { |
25 | pr_debug("thread_map__new\n"); | 17 | pr_debug("thread_map__new\n"); |
26 | return -1; | 18 | return -1; |
@@ -32,15 +24,11 @@ int test__open_syscall_event_on_all_cpus(void) | |||
32 | goto out_thread_map_delete; | 24 | goto out_thread_map_delete; |
33 | } | 25 | } |
34 | 26 | ||
35 | |||
36 | CPU_ZERO(&cpu_set); | 27 | CPU_ZERO(&cpu_set); |
37 | 28 | ||
38 | memset(&attr, 0, sizeof(attr)); | 29 | evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0); |
39 | attr.type = PERF_TYPE_TRACEPOINT; | ||
40 | attr.config = id; | ||
41 | evsel = perf_evsel__new(&attr, 0); | ||
42 | if (evsel == NULL) { | 30 | if (evsel == NULL) { |
43 | pr_debug("perf_evsel__new\n"); | 31 | pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); |
44 | goto out_thread_map_delete; | 32 | goto out_thread_map_delete; |
45 | } | 33 | } |
46 | 34 | ||
diff --git a/tools/perf/tests/open-syscall.c b/tools/perf/tests/open-syscall.c index 98be8b518b4f..befc0671f95d 100644 --- a/tools/perf/tests/open-syscall.c +++ b/tools/perf/tests/open-syscall.c | |||
@@ -6,29 +6,18 @@ | |||
6 | int test__open_syscall_event(void) | 6 | int test__open_syscall_event(void) |
7 | { | 7 | { |
8 | int err = -1, fd; | 8 | int err = -1, fd; |
9 | struct thread_map *threads; | ||
10 | struct perf_evsel *evsel; | 9 | struct perf_evsel *evsel; |
11 | struct perf_event_attr attr; | ||
12 | unsigned int nr_open_calls = 111, i; | 10 | unsigned int nr_open_calls = 111, i; |
13 | int id = trace_event__id("sys_enter_open"); | 11 | struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX); |
14 | 12 | ||
15 | if (id < 0) { | ||
16 | pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); | ||
17 | return -1; | ||
18 | } | ||
19 | |||
20 | threads = thread_map__new(-1, getpid(), UINT_MAX); | ||
21 | if (threads == NULL) { | 13 | if (threads == NULL) { |
22 | pr_debug("thread_map__new\n"); | 14 | pr_debug("thread_map__new\n"); |
23 | return -1; | 15 | return -1; |
24 | } | 16 | } |
25 | 17 | ||
26 | memset(&attr, 0, sizeof(attr)); | 18 | evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0); |
27 | attr.type = PERF_TYPE_TRACEPOINT; | ||
28 | attr.config = id; | ||
29 | evsel = perf_evsel__new(&attr, 0); | ||
30 | if (evsel == NULL) { | 19 | if (evsel == NULL) { |
31 | pr_debug("perf_evsel__new\n"); | 20 | pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); |
32 | goto out_thread_map_delete; | 21 | goto out_thread_map_delete; |
33 | } | 22 | } |
34 | 23 | ||
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index fc121edab016..0fd94657960e 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h | |||
@@ -16,7 +16,4 @@ int test__attr(void); | |||
16 | int test__dso_data(void); | 16 | int test__dso_data(void); |
17 | int test__parse_events(void); | 17 | int test__parse_events(void); |
18 | 18 | ||
19 | /* Util */ | ||
20 | int trace_event__id(const char *evname); | ||
21 | |||
22 | #endif /* TESTS_H */ | 19 | #endif /* TESTS_H */ |
diff --git a/tools/perf/tests/util.c b/tools/perf/tests/util.c deleted file mode 100644 index 748f2e8f6961..000000000000 --- a/tools/perf/tests/util.c +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <unistd.h> | ||
3 | #include <stdlib.h> | ||
4 | #include <sys/types.h> | ||
5 | #include <sys/stat.h> | ||
6 | #include <fcntl.h> | ||
7 | #include "tests.h" | ||
8 | #include "debugfs.h" | ||
9 | |||
10 | int trace_event__id(const char *evname) | ||
11 | { | ||
12 | char *filename; | ||
13 | int err = -1, fd; | ||
14 | |||
15 | if (asprintf(&filename, | ||
16 | "%s/syscalls/%s/id", | ||
17 | tracing_events_path, evname) < 0) | ||
18 | return -1; | ||
19 | |||
20 | fd = open(filename, O_RDONLY); | ||
21 | if (fd >= 0) { | ||
22 | char id[16]; | ||
23 | if (read(fd, id, sizeof(id)) > 0) | ||
24 | err = atoi(id); | ||
25 | close(fd); | ||
26 | } | ||
27 | |||
28 | free(filename); | ||
29 | return err; | ||
30 | } | ||