Add src/core/bpf_perf_buffer

This commit is contained in:
Pragyansh Chaturvedi
2025-10-17 03:47:31 +05:30
parent 5a3937b7f6
commit 8d27a351e0
2 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,28 @@
#ifndef PYLIBBPF_BPF_PERF_BUFFER_H
#define PYLIBBPF_BPF_PERF_BUFFER_H
#include <libbpf.h>
#include <pybind11/pybind11.h>
#include <pybind11/functional.h>
namespace py = pybind11;
class BpfPerfBuffer {
private:
struct perf_buffer *pb_;
py::function callback_;
py::function lost_callback_;
// Static callback wrappers for C API
static void sample_callback_wrapper(void *ctx, int cpu, void *data, unsigned int size);
static void lost_callback_wrapper(void *ctx, int cpu, unsigned long long cnt);
public:
BpfPerfBuffer(int map_fd, int page_cnt, py::function callback, py::object lost_callback);
~BpfPerfBuffer();
int poll(int timeout_ms);
int consume();
};
#endif // PYLIBBPF_BPF_PERF_BUFFER_H