[PATCH 04/12] perf tests: Move test__basic_mmap into separate object
Separating test__basic_mmap test from the builtin-test into mmap-basic object. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 1 + tools/perf/tests/builtin-test.c | 157 -- tools/perf/tests/mmap-basic.c | 162 tools/perf/tests/tests.h| 1 + 4 files changed, 164 insertions(+), 157 deletions(-) create mode 100644 tools/perf/tests/mmap-basic.c diff --git a/tools/perf/Makefile b/tools/perf/Makefile index d413e89..337489e 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -434,6 +434,7 @@ LIB_OBJS += $(OUTPUT)tests/attr.o LIB_OBJS += $(OUTPUT)tests/vmlinux-kallsyms.o LIB_OBJS += $(OUTPUT)tests/open-syscall.o LIB_OBJS += $(OUTPUT)tests/open-syscall-all-cpus.o +LIB_OBJS += $(OUTPUT)tests/mmap-basic.o LIB_OBJS += $(OUTPUT)tests/util.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 98e883b..609f592 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -30,163 +30,6 @@ #include -/* - * This test will generate random numbers of calls to some getpid syscalls, - * then establish an mmap for a group of events that are created to monitor - * the syscalls. - * - * It will receive the events, using mmap, use its PERF_SAMPLE_ID generated - * sample.id field to map back to its respective perf_evsel instance. - * - * Then it checks if the number of syscalls reported as perf events by - * the kernel corresponds to the number of syscalls made. - */ -static int test__basic_mmap(void) -{ - int err = -1; - union perf_event *event; - struct thread_map *threads; - struct cpu_map *cpus; - struct perf_evlist *evlist; - struct perf_event_attr attr = { - .type = PERF_TYPE_TRACEPOINT, - .read_format= PERF_FORMAT_ID, - .sample_type= PERF_SAMPLE_ID, - .watermark = 0, - }; - cpu_set_t cpu_set; - const char *syscall_names[] = { "getsid", "getppid", "getpgrp", - "getpgid", }; - pid_t (*syscalls[])(void) = { (void *)getsid, getppid, getpgrp, - (void*)getpgid }; -#define nsyscalls ARRAY_SIZE(syscall_names) - int ids[nsyscalls]; - unsigned int nr_events[nsyscalls], -expected_nr_events[nsyscalls], i, j; - struct perf_evsel *evsels[nsyscalls], *evsel; - - for (i = 0; i < nsyscalls; ++i) { - char name[64]; - - snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]); - ids[i] = trace_event__id(name); - if (ids[i] < 0) { - pr_debug("Is debugfs mounted on /sys/kernel/debug?\n"); - return -1; - } - nr_events[i] = 0; - expected_nr_events[i] = random() % 257; - } - - threads = thread_map__new(-1, getpid(), UINT_MAX); - if (threads == NULL) { - pr_debug("thread_map__new\n"); - return -1; - } - - cpus = cpu_map__new(NULL); - if (cpus == NULL) { - pr_debug("cpu_map__new\n"); - goto out_free_threads; - } - - CPU_ZERO(_set); - CPU_SET(cpus->map[0], _set); - sched_setaffinity(0, sizeof(cpu_set), _set); - if (sched_setaffinity(0, sizeof(cpu_set), _set) < 0) { - pr_debug("sched_setaffinity() failed on CPU %d: %s ", -cpus->map[0], strerror(errno)); - goto out_free_cpus; - } - - evlist = perf_evlist__new(cpus, threads); - if (evlist == NULL) { - pr_debug("perf_evlist__new\n"); - goto out_free_cpus; - } - - /* anonymous union fields, can't be initialized above */ - attr.wakeup_events = 1; - attr.sample_period = 1; - - for (i = 0; i < nsyscalls; ++i) { - attr.config = ids[i]; - evsels[i] = perf_evsel__new(, i); - if (evsels[i] == NULL) { - pr_debug("perf_evsel__new\n"); - goto out_free_evlist; - } - - perf_evlist__add(evlist, evsels[i]); - - if (perf_evsel__open(evsels[i], cpus, threads) < 0) { - pr_debug("failed to open counter: %s, " -"tweak /proc/sys/kernel/perf_event_paranoid?\n", -strerror(errno)); - goto out_close_fd; - } - } - - if (perf_evlist__mmap(evlist, 128, true) < 0) { - pr_debug("failed to mmap events: %d (%s)\n", errno, -
[PATCH 04/12] perf tests: Move test__basic_mmap into separate object
Separating test__basic_mmap test from the builtin-test into mmap-basic object. Signed-off-by: Jiri Olsa jo...@redhat.com Cc: Corey Ashford cjash...@linux.vnet.ibm.com Cc: Frederic Weisbecker fweis...@gmail.com Cc: Ingo Molnar mi...@elte.hu Cc: Paul Mackerras pau...@samba.org Cc: Peter Zijlstra a.p.zijls...@chello.nl Cc: Arnaldo Carvalho de Melo a...@redhat.com --- tools/perf/Makefile | 1 + tools/perf/tests/builtin-test.c | 157 -- tools/perf/tests/mmap-basic.c | 162 tools/perf/tests/tests.h| 1 + 4 files changed, 164 insertions(+), 157 deletions(-) create mode 100644 tools/perf/tests/mmap-basic.c diff --git a/tools/perf/Makefile b/tools/perf/Makefile index d413e89..337489e 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -434,6 +434,7 @@ LIB_OBJS += $(OUTPUT)tests/attr.o LIB_OBJS += $(OUTPUT)tests/vmlinux-kallsyms.o LIB_OBJS += $(OUTPUT)tests/open-syscall.o LIB_OBJS += $(OUTPUT)tests/open-syscall-all-cpus.o +LIB_OBJS += $(OUTPUT)tests/mmap-basic.o LIB_OBJS += $(OUTPUT)tests/util.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 98e883b..609f592 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -30,163 +30,6 @@ #include sched.h -/* - * This test will generate random numbers of calls to some getpid syscalls, - * then establish an mmap for a group of events that are created to monitor - * the syscalls. - * - * It will receive the events, using mmap, use its PERF_SAMPLE_ID generated - * sample.id field to map back to its respective perf_evsel instance. - * - * Then it checks if the number of syscalls reported as perf events by - * the kernel corresponds to the number of syscalls made. - */ -static int test__basic_mmap(void) -{ - int err = -1; - union perf_event *event; - struct thread_map *threads; - struct cpu_map *cpus; - struct perf_evlist *evlist; - struct perf_event_attr attr = { - .type = PERF_TYPE_TRACEPOINT, - .read_format= PERF_FORMAT_ID, - .sample_type= PERF_SAMPLE_ID, - .watermark = 0, - }; - cpu_set_t cpu_set; - const char *syscall_names[] = { getsid, getppid, getpgrp, - getpgid, }; - pid_t (*syscalls[])(void) = { (void *)getsid, getppid, getpgrp, - (void*)getpgid }; -#define nsyscalls ARRAY_SIZE(syscall_names) - int ids[nsyscalls]; - unsigned int nr_events[nsyscalls], -expected_nr_events[nsyscalls], i, j; - struct perf_evsel *evsels[nsyscalls], *evsel; - - for (i = 0; i nsyscalls; ++i) { - char name[64]; - - snprintf(name, sizeof(name), sys_enter_%s, syscall_names[i]); - ids[i] = trace_event__id(name); - if (ids[i] 0) { - pr_debug(Is debugfs mounted on /sys/kernel/debug?\n); - return -1; - } - nr_events[i] = 0; - expected_nr_events[i] = random() % 257; - } - - threads = thread_map__new(-1, getpid(), UINT_MAX); - if (threads == NULL) { - pr_debug(thread_map__new\n); - return -1; - } - - cpus = cpu_map__new(NULL); - if (cpus == NULL) { - pr_debug(cpu_map__new\n); - goto out_free_threads; - } - - CPU_ZERO(cpu_set); - CPU_SET(cpus-map[0], cpu_set); - sched_setaffinity(0, sizeof(cpu_set), cpu_set); - if (sched_setaffinity(0, sizeof(cpu_set), cpu_set) 0) { - pr_debug(sched_setaffinity() failed on CPU %d: %s , -cpus-map[0], strerror(errno)); - goto out_free_cpus; - } - - evlist = perf_evlist__new(cpus, threads); - if (evlist == NULL) { - pr_debug(perf_evlist__new\n); - goto out_free_cpus; - } - - /* anonymous union fields, can't be initialized above */ - attr.wakeup_events = 1; - attr.sample_period = 1; - - for (i = 0; i nsyscalls; ++i) { - attr.config = ids[i]; - evsels[i] = perf_evsel__new(attr, i); - if (evsels[i] == NULL) { - pr_debug(perf_evsel__new\n); - goto out_free_evlist; - } - - perf_evlist__add(evlist, evsels[i]); - - if (perf_evsel__open(evsels[i], cpus, threads) 0) { - pr_debug(failed to open counter: %s, -tweak /proc/sys/kernel/perf_event_paranoid?\n, -strerror(errno)); - goto out_close_fd; - } - } - - if (perf_evlist__mmap(evlist, 128, true)