mirror of
https://github.com/varun-r-mallya/pylibbpf.git
synced 2026-02-12 16:11:00 +00:00
Fix pre-commit conditions
This commit is contained in:
@ -10,7 +10,6 @@ include_directories(${CMAKE_SOURCE_DIR}/src)
|
|||||||
add_subdirectory(pybind11)
|
add_subdirectory(pybind11)
|
||||||
pybind11_add_module(
|
pybind11_add_module(
|
||||||
pylibbpf
|
pylibbpf
|
||||||
|
|
||||||
# Core
|
# Core
|
||||||
src/core/bpf_program.h
|
src/core/bpf_program.h
|
||||||
src/core/bpf_exception.h
|
src/core/bpf_exception.h
|
||||||
@ -19,15 +18,12 @@ pybind11_add_module(
|
|||||||
src/core/bpf_program.cpp
|
src/core/bpf_program.cpp
|
||||||
src/core/bpf_map.cpp
|
src/core/bpf_map.cpp
|
||||||
src/core/bpf_object.cpp
|
src/core/bpf_object.cpp
|
||||||
|
|
||||||
# Maps
|
# Maps
|
||||||
src/maps/perf_event_array.h
|
src/maps/perf_event_array.h
|
||||||
src/maps/perf_event_array.cpp
|
src/maps/perf_event_array.cpp
|
||||||
|
|
||||||
# Utils
|
# Utils
|
||||||
src/utils/struct_parser.h
|
src/utils/struct_parser.h
|
||||||
src/utils/struct_parser.cpp
|
src/utils/struct_parser.cpp
|
||||||
|
|
||||||
# Bindings
|
# Bindings
|
||||||
src/bindings/main.cpp)
|
src/bindings/main.cpp)
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import time
|
import time
|
||||||
from ctypes import c_int32, c_int64, c_uint64, c_void_p
|
from ctypes import c_int32, c_int64, c_uint64, c_void_p
|
||||||
|
|
||||||
from pylibbpf import BpfMap
|
|
||||||
from pythonbpf import BPF, bpf, bpfglobal, map, section
|
from pythonbpf import BPF, bpf, bpfglobal, map, section
|
||||||
from pythonbpf.maps import HashMap
|
from pythonbpf.maps import HashMap
|
||||||
|
|
||||||
|
from pylibbpf import BpfMap
|
||||||
|
|
||||||
|
|
||||||
@bpf
|
@bpf
|
||||||
@map
|
@map
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from .ir_to_ctypes import convert_structs_to_ctypes, is_pythonbpf_structs
|
||||||
from .pylibbpf import (
|
from .pylibbpf import (
|
||||||
BpfObject as _BpfObject, # C++ object (internal)
|
BpfException,
|
||||||
BpfProgram,
|
|
||||||
BpfMap,
|
BpfMap,
|
||||||
|
BpfProgram,
|
||||||
PerfEventArray,
|
PerfEventArray,
|
||||||
StructParser,
|
StructParser,
|
||||||
BpfException,
|
)
|
||||||
|
from .pylibbpf import (
|
||||||
|
BpfObject as _BpfObject, # C++ object (internal)
|
||||||
)
|
)
|
||||||
from .wrappers import BpfObjectWrapper
|
from .wrappers import BpfObjectWrapper
|
||||||
from .ir_to_ctypes import convert_structs_to_ctypes, is_pythonbpf_structs
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import ctypes
|
import ctypes
|
||||||
from typing import Dict, Type
|
|
||||||
from llvmlite import ir
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Dict, Type
|
||||||
|
|
||||||
|
from llvmlite import ir
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -54,12 +55,18 @@ def convert_structs_to_ctypes(structs_sym_tab) -> Dict[str, Type[ctypes.Structur
|
|||||||
struct_class = type(
|
struct_class = type(
|
||||||
struct_name,
|
struct_name,
|
||||||
(ctypes.Structure,),
|
(ctypes.Structure,),
|
||||||
{'_fields_': fields, '__module__': 'pylibbpf.ir_to_ctypes', '__doc__': f'Auto-generated ctypes structure for {struct_name}',
|
{
|
||||||
'__repr__': lambda self: (
|
"_fields_": fields,
|
||||||
f"<{struct_name} " +
|
"__module__": "pylibbpf.ir_to_ctypes",
|
||||||
" ".join(f"{name}={getattr(self, name)}" for name, _ in fields) +
|
"__doc__": f"Auto-generated ctypes structure for {struct_name}",
|
||||||
">"
|
"__repr__": lambda self: (
|
||||||
)}
|
f"<{struct_name} "
|
||||||
|
+ " ".join(
|
||||||
|
f"{name}={getattr(self, name)}" for name, _ in fields
|
||||||
|
)
|
||||||
|
+ ">"
|
||||||
|
),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
ctypes_structs[struct_name] = struct_class
|
ctypes_structs[struct_name] = struct_class
|
||||||
@ -80,9 +87,9 @@ def is_pythonbpf_structs(structs) -> bool:
|
|||||||
|
|
||||||
first_value = next(iter(structs.values()))
|
first_value = next(iter(structs.values()))
|
||||||
return (
|
return (
|
||||||
hasattr(first_value, 'ir_type') and
|
hasattr(first_value, "ir_type")
|
||||||
hasattr(first_value, 'fields') and
|
and hasattr(first_value, "fields")
|
||||||
hasattr(first_value, 'size')
|
and hasattr(first_value, "size")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ class PerfEventArrayHelper:
|
|||||||
callback: Callable,
|
callback: Callable,
|
||||||
struct_name: str = "",
|
struct_name: str = "",
|
||||||
page_cnt: int = 8,
|
page_cnt: int = 8,
|
||||||
lost_callback: Optional[Callable] = None
|
lost_callback: Optional[Callable] = None,
|
||||||
):
|
):
|
||||||
"""Open perf buffer with auto-deserialization."""
|
"""Open perf buffer with auto-deserialization."""
|
||||||
from .pylibbpf import PerfEventArray
|
from .pylibbpf import PerfEventArray
|
||||||
@ -24,14 +24,11 @@ class PerfEventArrayHelper:
|
|||||||
page_cnt,
|
page_cnt,
|
||||||
callback,
|
callback,
|
||||||
struct_name,
|
struct_name,
|
||||||
lost_callback or (lambda cpu, cnt: None)
|
lost_callback or (lambda cpu, cnt: None),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self._perf_buffer = PerfEventArray(
|
self._perf_buffer = PerfEventArray(
|
||||||
self._map,
|
self._map, page_cnt, callback, lost_callback or (lambda cpu, cnt: None)
|
||||||
page_cnt,
|
|
||||||
callback,
|
|
||||||
lost_callback or (lambda cpu, cnt: None)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|||||||
2
setup.py
2
setup.py
@ -3,7 +3,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from setuptools import Extension, setup, find_packages
|
from setuptools import Extension, find_packages, setup
|
||||||
from setuptools.command.build_ext import build_ext
|
from setuptools.command.build_ext import build_ext
|
||||||
|
|
||||||
# Convert distutils Windows platform specifiers to CMake -A arguments
|
# Convert distutils Windows platform specifiers to CMake -A arguments
|
||||||
|
|||||||
Reference in New Issue
Block a user