Rename BpfPerfBuffer to PerfEventArray, add struct_parser to BpfObject as a shared_ptr

This commit is contained in:
Pragyansh Chaturvedi
2025-10-19 22:34:10 +05:30
parent 05d5bba4f7
commit cbfe6ae95e
7 changed files with 80 additions and 22 deletions

View File

@ -2,11 +2,12 @@
#include "bpf_exception.h"
#include "bpf_map.h"
#include "bpf_program.h"
#include "utils/struct_parser.h"
#include <cerrno>
BpfObject::BpfObject(std::string object_path, py::dict structs)
: obj_(nullptr), object_path_(std::move(object_path)), loaded_(false),
struct_defs_(structs) {}
struct_defs_(structs), struct_parser_(nullptr) {}
BpfObject::~BpfObject() {
// Clear caches first (order matters!)
@ -256,3 +257,11 @@ py::dict BpfObject::get_cached_maps() const {
}
return maps;
}
std::shared_ptr<StructParser> BpfObject::get_struct_parser() const {
if (!struct_parser_ && !struct_defs_.empty()) {
// Create parser on first access
struct_parser_ = std::make_shared<StructParser>(struct_defs_);
}
return struct_parser_;
}