From 003495e833f0c129115e0af46d4bc4ad6e30ccdc Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Mon, 20 Oct 2025 05:22:31 +0530 Subject: [PATCH] Make lost_callback type asfe in PerfEventArray --- src/maps/perf_event_array.cpp | 10 ++++++---- src/maps/perf_event_array.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/maps/perf_event_array.cpp b/src/maps/perf_event_array.cpp index cfebb3d..66214e8 100644 --- a/src/maps/perf_event_array.cpp +++ b/src/maps/perf_event_array.cpp @@ -7,7 +7,7 @@ PerfEventArray::PerfEventArray(std::shared_ptr map, int page_cnt, py::function callback, py::object lost_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) { throw BpfException("Map '" + map->get_name() + @@ -92,10 +92,12 @@ void PerfEventArray::lost_callback_wrapper(void *ctx, int cpu, py::gil_scoped_acquire acquire; try { - if (self->lost_callback_.is_none()) { - return; + if (!self->lost_callback_.is_none()) { + py::function lost_fn = py::cast(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) { PyErr_Print(); } diff --git a/src/maps/perf_event_array.h b/src/maps/perf_event_array.h index 9f77454..d35aceb 100644 --- a/src/maps/perf_event_array.h +++ b/src/maps/perf_event_array.h @@ -17,7 +17,7 @@ private: std::shared_ptr map_; struct perf_buffer *pb_; py::function callback_; - py::function lost_callback_; + py::object lost_callback_; std::shared_ptr parser_; std::string struct_name_;