Commit fbbe6d6e authored by 4ast's avatar 4ast Committed by GitHub

Merge pull request #1393 from pchaigno/handle-epipe

Exit on EPIPE
parents 1e7dc399 860dbb08
......@@ -17,6 +17,7 @@ import ctypes as ct
from functools import reduce
import multiprocessing
import os
import errno
from .libbcc import lib, _RAW_CB_TYPE, _LOST_CB_TYPE
from .perf import Perf
......@@ -523,8 +524,24 @@ class PerfEventArray(ArrayBase):
self._open_perf_buffer(i, 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))
lost_fn = _LOST_CB_TYPE(lambda lost: lost_cb(lost)) if lost_cb else ct.cast(None, _LOST_CB_TYPE)
def raw_cb_(_, data, size):
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)
if not reader:
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