Commit f8eb5453 authored by SunKyu's avatar SunKyu

perf_reader : add timeout argument to perf_reader_poll

parent c9b920bb
...@@ -205,11 +205,11 @@ static void event_read(struct perf_reader *reader) { ...@@ -205,11 +205,11 @@ static void event_read(struct perf_reader *reader) {
} }
} }
int perf_reader_poll(int num_readers, struct perf_reader **readers) { int perf_reader_poll(int num_readers, struct perf_reader **readers, int timeout) {
struct pollfd pfds[] = { struct pollfd pfds[] = {
{readers[0]->fd, POLLIN}, {readers[0]->fd, POLLIN},
}; };
if (poll(pfds, num_readers, -1) > 0) { if (poll(pfds, num_readers, timeout) > 0) {
int i; int i;
for (i = 0; i < num_readers; ++i) { for (i = 0; i < num_readers; ++i) {
if (pfds[i].revents & POLLIN) if (pfds[i].revents & POLLIN)
......
...@@ -19,4 +19,4 @@ struct perf_reader; ...@@ -19,4 +19,4 @@ struct perf_reader;
struct perf_reader * perf_reader_new(int fd, int page_cnt, perf_reader_cb cb, void *cb_cookie); struct perf_reader * perf_reader_new(int fd, int page_cnt, perf_reader_cb cb, void *cb_cookie);
void perf_reader_free(void *ptr); void perf_reader_free(void *ptr);
int perf_reader_mmap(struct perf_reader *reader, int fd, unsigned long sample_type); int perf_reader_mmap(struct perf_reader *reader, int fd, unsigned long sample_type);
int perf_reader_poll(int num_readers, struct perf_reader **readers); int perf_reader_poll(int num_readers, struct perf_reader **readers, int timeout);
...@@ -94,7 +94,7 @@ lib.bpf_attach_kprobe.argtypes = [ct.c_int, ct.c_char_p, ct.c_char_p, ct.c_int, ...@@ -94,7 +94,7 @@ lib.bpf_attach_kprobe.argtypes = [ct.c_int, ct.c_char_p, ct.c_char_p, ct.c_int,
lib.bpf_detach_kprobe.restype = ct.c_int lib.bpf_detach_kprobe.restype = ct.c_int
lib.bpf_detach_kprobe.argtypes = [ct.c_char_p] lib.bpf_detach_kprobe.argtypes = [ct.c_char_p]
lib.perf_reader_poll.restype = ct.c_int lib.perf_reader_poll.restype = ct.c_int
lib.perf_reader_poll.argtypes = [ct.c_int, ct.POINTER(ct.c_void_p)] lib.perf_reader_poll.argtypes = [ct.c_int, ct.POINTER(ct.c_void_p), ct.c_int]
lib.perf_reader_free.restype = None lib.perf_reader_free.restype = None
lib.perf_reader_free.argtypes = [ct.c_void_p] lib.perf_reader_free.argtypes = [ct.c_void_p]
...@@ -780,7 +780,7 @@ class BPF(object): ...@@ -780,7 +780,7 @@ class BPF(object):
""" """
return len(open_kprobes) return len(open_kprobes)
def kprobe_poll(self): def kprobe_poll(self, timeout = -1):
"""kprobe_poll(self) """kprobe_poll(self)
Poll from the ring buffers for all of the open kprobes, calling the Poll from the ring buffers for all of the open kprobes, calling the
...@@ -790,7 +790,7 @@ class BPF(object): ...@@ -790,7 +790,7 @@ class BPF(object):
for i, v in enumerate(open_kprobes.values()): for i, v in enumerate(open_kprobes.values()):
readers[i] = v readers[i] = v
try: try:
lib.perf_reader_poll(len(open_kprobes), readers) lib.perf_reader_poll(len(open_kprobes), readers, timeout)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment