Debian Codegraph @

testsuite/systemtap.syscall/perf_event.c

raw
1 /* COVERAGE: perf_event_open */
2
3 #define _GNU_SOURCE
4 #include <unistd.h>
5 #include <string.h>
6 #include <sys/syscall.h>
7 #include <sys/ioctl.h>
8
9 #ifdef __NR_perf_event_open
10 #include <linux/perf_event.h>
11 // Note that the man page says you need to include the following
12 // file. However, if you aren't using hardware breakpoint events
13 // (which this testcase doesn't), you don't really need it. Some
14 // kernels, like 2.6.32-504.el6.s390x, don't have the header.
15 //
16 // #include <linux/hw_breakpoint.h>
17
18 static inline int
19 perf_event_open(struct perf_event_attr *attr, pid_t pid,
20 int cpu, int group_fd, unsigned long flags)
21 {
22 return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags);
23 }
24 #endif
25
26 int main()
27 {
28 #ifdef __NR_perf_event_open
29 struct perf_event_attr pe;
30 int fd;
31 long long count;
32
33 memset(&pe, 0, sizeof(struct perf_event_attr));
34 pe.type = PERF_TYPE_SOFTWARE;
35 pe.size = sizeof(struct perf_event_attr);
36 pe.config = PERF_COUNT_SW_CPU_CLOCK;
37 pe.disabled = 0;
38 pe.exclude_kernel = 1;
39 pe.exclude_hv = 1;
40
41 fd = perf_event_open(&pe, 0, -1, -1, 0);
42 //staptest// perf_event_open (XXXX, 0, -1, -1, 0x0) = NNNN
43
44 sleep(1);
45
46 ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
47 read(fd, &count, sizeof(count));
48
49 // Limit testing.
50
51 fd = perf_event_open((struct perf_event_attr*)-1, 0, -1, -1, 0);
52 #ifdef __s390__
53 //staptest// perf_event_open (0x[7]?[f]+, 0, -1, -1, 0x0) = -NNNN
54 #else
55 //staptest// perf_event_open (0x[f]+, 0, -1, -1, 0x0) = -NNNN
56 #endif
57
58 fd = perf_event_open(&pe, -1, -1, -1, 0);
59 //staptest// perf_event_open (XXXX, -1, -1, -1, 0x0) = -NNNN
60
61 fd = perf_event_open(&pe, 0, -1, -1, -1);
62 //staptest// perf_event_open (XXXX, 0, -1, -1, PERF_FLAG_[^ ]+|XXXX) = -NNNN
63
64 close(fd);
65 #endif
66 return 0;
67 }