Commit 860dbb08 authored by Paul Chaignon's avatar Paul Chaignon

Exit on EPIPE

parent 5b08d385
...@@ -17,6 +17,7 @@ import ctypes as ct ...@@ -17,6 +17,7 @@ import ctypes as ct
from functools import reduce from functools import reduce
import multiprocessing import multiprocessing
import os import os
import errno
from .libbcc import lib, _RAW_CB_TYPE, _LOST_CB_TYPE from .libbcc import lib, _RAW_CB_TYPE, _LOST_CB_TYPE
from .perf import Perf from .perf import Perf
...@@ -523,8 +524,24 @@ class PerfEventArray(ArrayBase): ...@@ -523,8 +524,24 @@ class PerfEventArray(ArrayBase):
self._open_perf_buffer(i, callback, page_cnt, lost_cb) self._open_perf_buffer(i, callback, page_cnt, lost_cb)
def _open_perf_buffer(self, cpu, callback, page_cnt, lost_cb): def _open_perf_buffer(self, cpu, callback, page_cnt, lost_cb):
fn = _RAW_CB_TYPE(lambda _, data, size: callback(cpu, data, size)) def raw_cb_(_, data, size):
lost_fn = _LOST_CB_TYPE(lambda lost: lost_cb(lost)) if lost_cb else ct.cast(None, _LOST_CB_TYPE) try:
callback(cpu, data, size)
except IOError, e:
if e.errno == errno.EPIPE:
exit()
else:
raise e
def lost_cb_(lost):
try:
lost_cb(lost)
except IOError, e:
if e.errno == errno.EPIPE:
exit()
else:
raise e
fn = _RAW_CB_TYPE(raw_cb_)
lost_fn = _LOST_CB_TYPE(lost_cb_) if lost_cb else ct.cast(None, _LOST_CB_TYPE)
reader = lib.bpf_open_perf_buffer(fn, lost_fn, None, -1, cpu, page_cnt) reader = lib.bpf_open_perf_buffer(fn, lost_fn, None, -1, cpu, page_cnt)
if not reader: if not reader:
raise Exception("Could not open perf buffer") raise Exception("Could not open perf buffer")
......
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