Skip to content

Commit

Permalink
perf test: Use perf_evsel__newtp constructor in the tracepoint tests
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Arnaldo Carvalho de Melo committed Dec 10, 2012
1 parent c5d3d50 commit a60d795
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 89 deletions.
1 change: 0 additions & 1 deletion tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ LIB_OBJS += $(OUTPUT)tests/rdpmc.o
LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o
LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o
LIB_OBJS += $(OUTPUT)tests/pmu.o
LIB_OBJS += $(OUTPUT)tests/util.o

BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
Expand Down
37 changes: 11 additions & 26 deletions tools/perf/tests/mmap-basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,16 @@ int test__basic_mmap(void)
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");
Expand Down Expand Up @@ -79,18 +59,20 @@ int test__basic_mmap(void)
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);
char name[64];

snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]);
evsels[i] = perf_evsel__newtp("syscalls", name, i);
if (evsels[i] == NULL) {
pr_debug("perf_evsel__new\n");
goto out_free_evlist;
}

evsels[i]->attr.wakeup_events = 1;
evsels[i]->attr.read_format |= PERF_FORMAT_ID;
perf_evsel__set_sample_bit(evsels[i], ID);

perf_evlist__add(evlist, evsels[i]);

if (perf_evsel__open(evsels[i], cpus, threads) < 0) {
Expand All @@ -99,6 +81,9 @@ int test__basic_mmap(void)
strerror(errno));
goto out_close_fd;
}

nr_events[i] = 0;
expected_nr_events[i] = 1 + rand() % 127;
}

if (perf_evlist__mmap(evlist, 128, true) < 0) {
Expand Down
18 changes: 3 additions & 15 deletions tools/perf/tests/open-syscall-all-cpus.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@
int test__open_syscall_event_on_all_cpus(void)
{
int err = -1, fd, cpu;
struct thread_map *threads;
struct cpu_map *cpus;
struct perf_evsel *evsel;
struct perf_event_attr attr;
unsigned int nr_open_calls = 111, i;
cpu_set_t cpu_set;
int id = trace_event__id("sys_enter_open");
struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);

if (id < 0) {
pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
return -1;
}

threads = thread_map__new(-1, getpid(), UINT_MAX);
if (threads == NULL) {
pr_debug("thread_map__new\n");
return -1;
Expand All @@ -32,15 +24,11 @@ int test__open_syscall_event_on_all_cpus(void)
goto out_thread_map_delete;
}


CPU_ZERO(&cpu_set);

memset(&attr, 0, sizeof(attr));
attr.type = PERF_TYPE_TRACEPOINT;
attr.config = id;
evsel = perf_evsel__new(&attr, 0);
evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0);
if (evsel == NULL) {
pr_debug("perf_evsel__new\n");
pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
goto out_thread_map_delete;
}

Expand Down
17 changes: 3 additions & 14 deletions tools/perf/tests/open-syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,18 @@
int test__open_syscall_event(void)
{
int err = -1, fd;
struct thread_map *threads;
struct perf_evsel *evsel;
struct perf_event_attr attr;
unsigned int nr_open_calls = 111, i;
int id = trace_event__id("sys_enter_open");
struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);

if (id < 0) {
pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
return -1;
}

threads = thread_map__new(-1, getpid(), UINT_MAX);
if (threads == NULL) {
pr_debug("thread_map__new\n");
return -1;
}

memset(&attr, 0, sizeof(attr));
attr.type = PERF_TYPE_TRACEPOINT;
attr.config = id;
evsel = perf_evsel__new(&attr, 0);
evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0);
if (evsel == NULL) {
pr_debug("perf_evsel__new\n");
pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
goto out_thread_map_delete;
}

Expand Down
3 changes: 0 additions & 3 deletions tools/perf/tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@ int test__attr(void);
int test__dso_data(void);
int test__parse_events(void);

/* Util */
int trace_event__id(const char *evname);

#endif /* TESTS_H */
30 changes: 0 additions & 30 deletions tools/perf/tests/util.c

This file was deleted.

0 comments on commit a60d795

Please sign in to comment.