mirror of
https://github.com/varun-r-mallya/pylibbpf.git
synced 2026-02-12 16:11:00 +00:00
Make lost_callback type asfe in PerfEventArray
This commit is contained in:
@ -7,7 +7,7 @@
|
|||||||
PerfEventArray::PerfEventArray(std::shared_ptr<BpfMap> map, int page_cnt,
|
PerfEventArray::PerfEventArray(std::shared_ptr<BpfMap> map, int page_cnt,
|
||||||
py::function callback, py::object lost_callback)
|
py::function callback, py::object lost_callback)
|
||||||
: map_(map), pb_(nullptr), callback_(std::move(callback)),
|
: map_(map), pb_(nullptr), callback_(std::move(callback)),
|
||||||
lost_callback_(lost_callback) {
|
lost_callback_(std::move(lost_callback)) {
|
||||||
|
|
||||||
if (map->get_type() != BPF_MAP_TYPE_PERF_EVENT_ARRAY) {
|
if (map->get_type() != BPF_MAP_TYPE_PERF_EVENT_ARRAY) {
|
||||||
throw BpfException("Map '" + map->get_name() +
|
throw BpfException("Map '" + map->get_name() +
|
||||||
@ -92,10 +92,12 @@ void PerfEventArray::lost_callback_wrapper(void *ctx, int cpu,
|
|||||||
py::gil_scoped_acquire acquire;
|
py::gil_scoped_acquire acquire;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (self->lost_callback_.is_none()) {
|
if (!self->lost_callback_.is_none()) {
|
||||||
return;
|
py::function lost_fn = py::cast<py::function>(self->lost_callback_);
|
||||||
|
lost_fn(cpu, cnt);
|
||||||
|
} else {
|
||||||
|
py::print("Lost", cnt, "events on CPU", cpu);
|
||||||
}
|
}
|
||||||
self->lost_callback_(cpu, cnt);
|
|
||||||
} catch (const py::error_already_set &e) {
|
} catch (const py::error_already_set &e) {
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ private:
|
|||||||
std::shared_ptr<BpfMap> map_;
|
std::shared_ptr<BpfMap> map_;
|
||||||
struct perf_buffer *pb_;
|
struct perf_buffer *pb_;
|
||||||
py::function callback_;
|
py::function callback_;
|
||||||
py::function lost_callback_;
|
py::object lost_callback_;
|
||||||
|
|
||||||
std::shared_ptr<StructParser> parser_;
|
std::shared_ptr<StructParser> parser_;
|
||||||
std::string struct_name_;
|
std::string struct_name_;
|
||||||
|
|||||||
Reference in New Issue
Block a user