From 5faf30a695f7b45711e987df8a82c904a36e581f Mon Sep 17 00:00:00 2001 From: Ronan Dunklau Date: Fri, 14 Apr 2023 11:03:49 +0200 Subject: [PATCH] Make linters happy --- src/pgtracer/ebpf/dwarf.py | 11 +---------- src/pgtracer/model/plan.py | 5 ++--- src/pgtracer/utils.py | 6 ++++-- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/pgtracer/ebpf/dwarf.py b/src/pgtracer/ebpf/dwarf.py index 2c0550c..be738cd 100644 --- a/src/pgtracer/ebpf/dwarf.py +++ b/src/pgtracer/ebpf/dwarf.py @@ -496,7 +496,7 @@ class Struct: fields_defs: Dict[str, StructMemberDefinition] metadata: ProcessMetadata die: DIE - buffer_type: Type + buffer_type: Type[ct._CData] _fully_loaded: bool = False size: int @@ -634,15 +634,6 @@ def as_dict(self, include_all: bool = False) -> Dict[str, Any]: value.as_dict(include_all=True) return values - @classmethod - def size(cls) -> int: - """ - Returns the sizeof() this struct as stored in the DWARF information. - """ - size = cls.die.attributes["DW_AT_byte_size"].value - assert isinstance(size, int) - return size - @classmethod def pointer_type(cls) -> Type[DWARFPointer]: """ diff --git a/src/pgtracer/model/plan.py b/src/pgtracer/model/plan.py index 71bdec0..dcc0b51 100644 --- a/src/pgtracer/model/plan.py +++ b/src/pgtracer/model/plan.py @@ -6,14 +6,13 @@ import ctypes as ct from typing import TYPE_CHECKING, Dict, Optional +from ..ebpf.collector.c_defs import plan_data, planstate_data +from ..ebpf.dwarf import ProcessMetadata, Struct from ..utils import timespec_to_float if TYPE_CHECKING: from enum import IntEnum -from ..ebpf.collector.c_defs import plan_data, planstate_data -from ..ebpf.dwarf import ProcessMetadata, Struct - def explain_dict_to_str(parts: Dict[str, str]) -> str: """ diff --git a/src/pgtracer/utils.py b/src/pgtracer/utils.py index da1d168..a39b8fa 100644 --- a/src/pgtracer/utils.py +++ b/src/pgtracer/utils.py @@ -7,17 +7,19 @@ import re import subprocess from datetime import timedelta -from typing import TYPE_CHECKING, BinaryIO, Optional +from typing import TYPE_CHECKING, BinaryIO, Optional, Union from pypsutil import Process +from pgtracer.ebpf.dwarf import Struct + if TYPE_CHECKING: from ctypes import _CData else: _CData = object -def timespec_to_timedelta(timespec: _CData) -> timedelta: +def timespec_to_timedelta(timespec: Union[_CData, Struct]) -> timedelta: """ Convert a timespec_t or instr_time struct to a timedelta. """