Skip to content

Commit 003495e

Browse files
committed
Make lost_callback type asfe in PerfEventArray
1 parent eebfe61 commit 003495e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/maps/perf_event_array.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
PerfEventArray::PerfEventArray(std::shared_ptr<BpfMap> map, int page_cnt,
88
py::function callback, py::object lost_callback)
99
: map_(map), pb_(nullptr), callback_(std::move(callback)),
10-
lost_callback_(lost_callback) {
10+
lost_callback_(std::move(lost_callback)) {
1111

1212
if (map->get_type() != BPF_MAP_TYPE_PERF_EVENT_ARRAY) {
1313
throw BpfException("Map '" + map->get_name() +
@@ -92,10 +92,12 @@ void PerfEventArray::lost_callback_wrapper(void *ctx, int cpu,
9292
py::gil_scoped_acquire acquire;
9393

9494
try {
95-
if (self->lost_callback_.is_none()) {
96-
return;
95+
if (!self->lost_callback_.is_none()) {
96+
py::function lost_fn = py::cast<py::function>(self->lost_callback_);
97+
lost_fn(cpu, cnt);
98+
} else {
99+
py::print("Lost", cnt, "events on CPU", cpu);
97100
}
98-
self->lost_callback_(cpu, cnt);
99101
} catch (const py::error_already_set &e) {
100102
PyErr_Print();
101103
}

src/maps/perf_event_array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PerfEventArray {
1717
std::shared_ptr<BpfMap> map_;
1818
struct perf_buffer *pb_;
1919
py::function callback_;
20-
py::function lost_callback_;
20+
py::object lost_callback_;
2121

2222
std::shared_ptr<StructParser> parser_;
2323
std::string struct_name_;

0 commit comments

Comments
 (0)