mirror of
https://github.com/varun-r-mallya/pylibbpf.git
synced 2026-02-12 16:11:00 +00:00
Rename BpfPerfBuffer to PerfEventArray, add struct_parser to BpfObject as a shared_ptr
This commit is contained in:
@ -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_;
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ namespace py = pybind11;
|
||||
|
||||
class BpfProgram;
|
||||
class BpfMap;
|
||||
class StructParser;
|
||||
|
||||
/**
|
||||
* BpfObject - Represents a loaded BPF object file.
|
||||
@ -29,6 +30,7 @@ private:
|
||||
mutable std::unordered_map<std::string, std::shared_ptr<BpfProgram>>
|
||||
prog_cache_;
|
||||
py::dict struct_defs_;
|
||||
mutable std::shared_ptr<StructParser> struct_parser_;
|
||||
|
||||
std::shared_ptr<BpfProgram> _get_or_create_program(struct bpf_program *prog);
|
||||
std::shared_ptr<BpfMap> _get_or_create_map(struct bpf_map *map);
|
||||
@ -78,6 +80,10 @@ public:
|
||||
[[nodiscard]] std::shared_ptr<BpfMap> get_map(const std::string &name);
|
||||
[[nodiscard]] struct bpf_map *find_map_by_name(const std::string &name) const;
|
||||
[[nodiscard]] py::dict get_cached_maps() const;
|
||||
|
||||
// Struct parsing
|
||||
[[nodiscard]] py::dict get_struct_defs() const { return struct_defs_; }
|
||||
[[nodiscard]] std::shared_ptr<StructParser> get_struct_parser() const;
|
||||
};
|
||||
|
||||
#endif // PYLIBBPF_BPF_OBJECT_H
|
||||
|
||||
Reference in New Issue
Block a user