[psutil] Complete BSD (#15090)

This commit is contained in:
Semyon Moroz
2025-11-28 22:11:13 +00:00
committed by GitHub
parent 57b8ed7d6e
commit 349431d92d
2 changed files with 321 additions and 212 deletions
+186 -143
View File
@@ -1,157 +1,83 @@
from _typeshed import Incomplete
from contextlib import AbstractContextManager
from typing import NamedTuple
import sys
from psutil._common import (
FREEBSD as FREEBSD,
NETBSD as NETBSD,
OPENBSD as OPENBSD,
AccessDenied as AccessDenied,
NoSuchProcess as NoSuchProcess,
ZombieProcess as ZombieProcess,
conn_tmap as conn_tmap,
conn_to_ntuple as conn_to_ntuple,
memoize as memoize,
pio,
usage_percent as usage_percent,
)
# sys.platform.startswith(("freebsd", "midnightbsd", "openbsd", "netbsd")):
if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin":
from _typeshed import Incomplete
from collections import defaultdict
from collections.abc import Callable
from contextlib import AbstractContextManager
from typing import Final, NamedTuple, TypeVar, overload
from typing_extensions import ParamSpec
__extra__all__: Incomplete
PROC_STATUSES: Incomplete
TCP_STATUSES: Incomplete
PAGESIZE: Incomplete
AF_LINK: Incomplete
HAS_PROC_NUM_THREADS: Incomplete
kinfo_proc_map: Incomplete
from psutil._common import (
FREEBSD as FREEBSD,
NETBSD as NETBSD,
OPENBSD as OPENBSD,
AccessDenied as AccessDenied,
NoSuchProcess as NoSuchProcess,
ZombieProcess as ZombieProcess,
conn_tmap as conn_tmap,
conn_to_ntuple as conn_to_ntuple,
memoize as memoize,
usage_percent as usage_percent,
)
class svmem(NamedTuple):
total: int
available: int
percent: float
used: int
free: int
active: int
inactive: int
buffers: int
cached: int
shared: int
wired: int
from . import _common, _psposix, _psutil_bsd
class scputimes(NamedTuple):
user: float
nice: float
system: float
idle: float
irq: float
_P = ParamSpec("_P")
_R = TypeVar("_R")
class pmem(NamedTuple):
rss: Incomplete
vms: Incomplete
text: Incomplete
data: Incomplete
stack: Incomplete
__extra__all__: Final[list[str]]
PROC_STATUSES: Final[dict[int, str]]
TCP_STATUSES: Final[dict[int, str]]
PAGESIZE: Final[int]
AF_LINK: Final = _psutil_bsd.AF_LINK
HAS_PROC_NUM_THREADS: Final[bool]
kinfo_proc_map: Final[dict[str, int]]
pfullmem = pmem
class svmem(NamedTuple):
total: int
available: int
percent: float
used: int
free: int
active: int
inactive: int
buffers: int
cached: int
shared: int
wired: int
class pcputimes(NamedTuple):
user: Incomplete
system: Incomplete
children_user: Incomplete
children_system: Incomplete
class scputimes(NamedTuple):
user: float
nice: float
system: float
idle: float
irq: float
class pmmap_grouped(NamedTuple):
path: Incomplete
rss: Incomplete
private: Incomplete
ref_count: Incomplete
shadow_count: Incomplete
class pmem(NamedTuple):
rss: int
vms: int
text: int
data: int
stack: int
class pmmap_ext(NamedTuple):
addr: Incomplete
perms: Incomplete
path: Incomplete
rss: Incomplete
private: Incomplete
ref_count: Incomplete
shadow_count: Incomplete
pfullmem = pmem
class sdiskio(NamedTuple):
read_count: Incomplete
write_count: Incomplete
read_bytes: Incomplete
write_bytes: Incomplete
read_time: Incomplete
write_time: Incomplete
busy_time: Incomplete
class pcputimes(NamedTuple):
user: float
system: float
children_user: float
children_system: float
def virtual_memory() -> svmem: ...
def swap_memory(): ...
def cpu_times(): ...
def per_cpu_times(): ...
def cpu_count_logical(): ...
def cpu_count_cores() -> int | None: ...
def cpu_stats(): ...
def disk_partitions(all: bool = ...): ...
disk_usage: Incomplete
disk_io_counters: Incomplete
net_io_counters: Incomplete
net_if_addrs: Incomplete
def net_if_stats(): ...
def net_connections(kind): ...
def sensors_battery(): ...
def sensors_temperatures(): ...
def cpu_freq(): ...
def boot_time(): ...
def users(): ...
INIT_BOOT_TIME: float
def adjust_proc_create_time(ctime: float) -> float: ...
def pids(): ...
def pid_exists(pid): ...
def wrap_exceptions(fun): ...
def wrap_exceptions_procfs(inst) -> AbstractContextManager[None]: ...
class Process:
pid: Incomplete
def __init__(self, pid) -> None: ...
def oneshot(self): ...
def oneshot_enter(self) -> None: ...
def oneshot_exit(self) -> None: ...
def name(self): ...
def exe(self): ...
def cmdline(self): ...
def environ(self): ...
def terminal(self): ...
def ppid(self): ...
def uids(self): ...
def gids(self): ...
def cpu_times(self): ...
def cpu_num(self): ...
def memory_info(self): ...
memory_full_info: Incomplete
def create_time(self, monotonic: bool = False) -> float: ...
def num_threads(self): ...
def num_ctx_switches(self): ...
def threads(self): ...
def net_connections(self, kind: str = ...): ...
def wait(self, timeout: Incomplete | None = ...): ...
def nice_get(self): ...
def nice_set(self, value): ...
def status(self): ...
def io_counters(self) -> pio: ...
def cwd(self): ...
class nt_mmap_grouped(NamedTuple):
class pmmap_grouped(NamedTuple):
path: Incomplete
rss: Incomplete
private: Incomplete
ref_count: Incomplete
shadow_count: Incomplete
class nt_mmap_ext(NamedTuple):
class pmmap_ext(NamedTuple):
addr: Incomplete
perms: Incomplete
path: Incomplete
@@ -160,9 +86,126 @@ class Process:
ref_count: Incomplete
shadow_count: Incomplete
def open_files(self): ...
def num_fds(self): ...
def cpu_affinity_get(self): ...
def cpu_affinity_set(self, cpus) -> None: ...
def memory_maps(self): ...
def rlimit(self, resource, limits: Incomplete | None = ...): ...
class sdiskio(NamedTuple):
read_count: Incomplete
write_count: Incomplete
read_bytes: Incomplete
write_bytes: Incomplete
read_time: Incomplete
write_time: Incomplete
busy_time: Incomplete
def virtual_memory() -> svmem: ...
def swap_memory() -> _common.sswap: ...
def cpu_times() -> scputimes: ...
def per_cpu_times() -> list[scputimes]: ...
def cpu_count_logical() -> int | None: ...
def cpu_count_cores() -> int | None: ...
def cpu_stats() -> _common.scpustats: ...
def disk_partitions(all: bool = False) -> list[_common.sdiskpart]: ...
disk_usage = _psposix.disk_usage
disk_io_counters = _psutil_bsd.disk_io_counters
net_io_counters = _psutil_bsd.net_io_counters
net_if_addrs = _psutil_bsd.net_if_addrs
def net_if_stats() -> dict[str, _common.snicstats]: ...
def net_connections(kind: str) -> list[_common.sconn]: ...
def sensors_battery() -> _common.sbattery | None: ... # only FreeBSD
def sensors_temperatures() -> defaultdict[str, list[_common.shwtemp]]: ... # only FreeBSD
def cpu_freq() -> list[_common.scpufreq]: ... # only FreeBSD and OpenBSD
def boot_time() -> float: ...
def users() -> list[_common.suser]: ...
INIT_BOOT_TIME: Final[float] # only NetBSD
def adjust_proc_create_time(ctime: float) -> float: ... # only NetBSD
def pids() -> list[int]: ...
def pid_exists(pid: int) -> bool: ...
def wrap_exceptions(fun: Callable[_P, _R]) -> Callable[_P, _R]: ...
def wrap_exceptions_procfs(inst: Process) -> AbstractContextManager[None]: ...
class Process:
__slots__ = ["_cache", "_name", "_ppid", "pid"]
pid: int
def __init__(self, pid: int) -> None: ...
def oneshot(
self,
) -> tuple[
int,
int,
int,
int,
int,
int,
int,
int,
int,
float,
int,
int,
int,
int,
float,
float,
float,
float,
int,
int,
int,
int,
int,
int,
str,
]: ...
def oneshot_enter(self) -> None: ...
def oneshot_exit(self) -> None: ...
def name(self) -> str: ...
def exe(self) -> str: ...
def cmdline(self) -> list[str]: ...
def environ(self) -> dict[str, str]: ...
def terminal(self) -> str | None: ...
def ppid(self) -> int: ...
def uids(self) -> _common.puids: ...
def gids(self) -> _common.pgids: ...
def cpu_times(self) -> _common.pcputimes: ...
def cpu_num(self) -> int: ... # only FreeBSD
def memory_info(self) -> pmem: ...
memory_full_info = memory_info
def create_time(self, monotonic: bool = False) -> float: ...
def num_threads(self) -> int: ...
def num_ctx_switches(self) -> _common.pctxsw: ...
def threads(self) -> list[_common.pthread]: ...
def net_connections(self, kind: str = "inet") -> list[_common.pconn]: ...
def wait(self, timeout: float | None = None): ...
def nice_get(self) -> int: ...
def nice_set(self, value: int) -> None: ...
def status(self) -> str: ...
def io_counters(self) -> _common.pio: ...
def cwd(self) -> str: ...
class nt_mmap_grouped(NamedTuple):
path: Incomplete
rss: Incomplete
private: Incomplete
ref_count: Incomplete
shadow_count: Incomplete
class nt_mmap_ext(NamedTuple):
addr: Incomplete
perms: Incomplete
path: Incomplete
rss: Incomplete
private: Incomplete
ref_count: Incomplete
shadow_count: Incomplete
def open_files(self) -> list[_common.popenfile]: ...
def num_fds(self) -> int: ...
def cpu_affinity_get(self) -> list[int]: ... # only FreeBSD
def cpu_affinity_set(self, cpus: list[int]) -> None: ... # only FreeBSD
def memory_maps(self) -> list[tuple[str, str, str, int, int, int, int]]: ... # only FreeBSD
@overload
def rlimit(self, resource: int, limits: tuple[int, int]) -> None: ... # only FreeBSD
@overload
def rlimit(self, resource: int, limits: None = None) -> tuple[int, int]: ... # only FreeBSD
+135 -69
View File
@@ -1,73 +1,139 @@
from _typeshed import Incomplete
import sys
# TODO: Add POSIX constants and check their aviability (see psutil_posix_add_constants)
AF_LINK: Incomplete
# sys.platform.startswith(("freebsd", "midnightbsd", "openbsd", "netbsd")):
if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin":
from collections.abc import Sequence
from socket import AddressFamily, SocketKind
from typing import Final, overload
def getpagesize() -> int: ...
def net_if_addrs(): ...
def net_if_flags(nic_name: str, /) -> list[str]: ...
def net_if_is_running(nic_name: str, /) -> bool: ...
def net_if_mtu(nic_name: str, /) -> int: ...
def proc_priority_get(pid: int, /) -> int: ...
def proc_priority_set(pid: int, priority: int, /) -> None: ...
def net_if_duplex_speed(nic_name: str, /): ...
def proc_is_zombie(pid: int, /) -> bool: ...
AF_LINK: Final[int]
RLIMIT_AS: Final[int] # only FreeBSD
RLIMIT_CORE: Final[int] # only FreeBSD
RLIMIT_CPU: Final[int] # only FreeBSD
RLIMIT_DATA: Final[int] # only FreeBSD
RLIMIT_FSIZE: Final[int] # only FreeBSD
RLIMIT_MEMLOCK: Final[int] # only FreeBSD
RLIMIT_NOFILE: Final[int] # only FreeBSD
RLIMIT_NPROC: Final[int] # only FreeBSD
RLIMIT_RSS: Final[int] # only FreeBSD
RLIMIT_STACK: Final[int] # only FreeBSD
RLIMIT_SWAP: Final[int] # only FreeBSD
RLIMIT_SBSIZE: Final[int] # only FreeBSD
RLIMIT_NPTS: Final[int] # only FreeBSD
RLIM_INFINITY: Final[int] # only FreeBSD
SIDL: Incomplete
SRUN: Incomplete
SSLEEP: Incomplete
SSTOP: Incomplete
SZOMB: Incomplete
SWAIT: Incomplete # only FreeBSD
SLOCK: Incomplete # only FreeBSD
SDEAD: Incomplete # only OpenBSD and NetBSD
SONPROC: Incomplete # only OpenBSD and NetBSD
SSUSPENDED: Incomplete # only NetBSD
TCPS_CLOSED: Incomplete
TCPS_CLOSING: Incomplete
TCPS_CLOSE_WAIT: Incomplete
TCPS_LISTEN: Incomplete
TCPS_ESTABLISHED: Incomplete
TCPS_SYN_SENT: Incomplete
TCPS_SYN_RECEIVED: Incomplete
TCPS_FIN_WAIT_1: Incomplete
TCPS_FIN_WAIT_2: Incomplete
TCPS_LAST_ACK: Incomplete
TCPS_TIME_WAIT: Incomplete
PSUTIL_CONN_NONE: Incomplete
def getpagesize() -> int: ...
def net_if_addrs(): ...
def net_if_flags(nic_name: str, /) -> list[str]: ...
def net_if_is_running(nic_name: str, /) -> bool: ...
def net_if_mtu(nic_name: str, /) -> int: ...
def proc_priority_get(pid: int, /) -> int: ...
def proc_priority_set(pid: int, priority: int, /) -> None: ...
def net_if_duplex_speed(nic_name: str, /): ...
def proc_is_zombie(pid: int, /) -> bool: ...
def proc_cmdline(*args, **kwargs): ...
def proc_cwd(*args, **kwargs): ...
def proc_environ(*args, **kwargs): ...
def proc_name(*args, **kwargs): ...
def proc_num_fds(*args, **kwargs): ...
def proc_oneshot_info(*args, **kwargs): ...
def proc_open_files(*args, **kwargs): ...
def proc_threads(*args, **kwargs): ...
def proc_num_threads(*args, **kwargs): ... # only FreeBSD and OpenBSD
def proc_cpu_affinity_get(*args, **kwargs): ... # only FreeBSD
def proc_cpu_affinity_set(*args, **kwargs): ... # only FreeBSD
def proc_exe(*args, **kwargs): ... # only FreeBSD
def proc_getrlimit(*args, **kwargs): ... # only FreeBSD
def proc_memory_maps(*args, **kwargs): ... # only FreeBSD
def proc_net_connections(*args, **kwargs): ... # only FreeBSD
def proc_setrlimit(*args, **kwargs): ... # only FreeBSD
def boot_time(*args, **kwargs): ...
def cpu_count_logical(*args, **kwargs): ...
def cpu_stats(*args, **kwargs): ...
def cpu_times(*args, **kwargs): ...
def disk_io_counters(*args, **kwargs): ...
def disk_partitions(*args, **kwargs): ...
def net_connections(*args, **kwargs): ...
def net_io_counters(*args, **kwargs): ...
def per_cpu_times(*args, **kwargs): ...
def pids(*args, **kwargs): ...
def swap_mem(*args, **kwargs): ...
def users(*args, **kwargs): ...
def virtual_mem(*args, **kwargs): ...
def cpu_freq(*args, **kwargs): ... # only FreeBSD and OpenBSD
def cpu_topology(*args, **kwargs): ... # only FreeBSD
def sensors_battery(*args, **kwargs): ... # only FreeBSD
def sensors_cpu_temperature(*args, **kwargs): ... # only FreeBSD
def check_pid_range(*args, **kwargs): ...
def set_debug(*args, **kwargs): ...
version: Final[int]
SIDL: Final[int]
SRUN: Final[int]
SSLEEP: Final[int]
SSTOP: Final[int]
SZOMB: Final[int]
SWAIT: Final[int] # only FreeBSD
SLOCK: Final[int] # only FreeBSD
SDEAD: Final[int] # only OpenBSD and NetBSD
SONPROC: Final[int] # only OpenBSD and NetBSD
SSUSPENDED: Final[int] # only NetBSD
TCPS_CLOSED: Final[int]
TCPS_CLOSING: Final[int]
TCPS_CLOSE_WAIT: Final[int]
TCPS_LISTEN: Final[int]
TCPS_ESTABLISHED: Final[int]
TCPS_SYN_SENT: Final[int]
TCPS_SYN_RECEIVED: Final[int]
TCPS_FIN_WAIT_1: Final[int]
TCPS_FIN_WAIT_2: Final[int]
TCPS_LAST_ACK: Final[int]
TCPS_TIME_WAIT: Final[int]
PSUTIL_CONN_NONE: Final = 128
def proc_cmdline(pid: int, /) -> list[str]: ...
def proc_cwd(pid: int, /) -> str: ...
def proc_environ(pid: int, /) -> dict[str, str]: ...
def proc_name(pid: int, /) -> str: ...
def proc_num_fds(pid: int, /) -> int: ...
def proc_oneshot_info(
pid: int, /
) -> tuple[
int,
int,
int,
int,
int,
int,
int,
int,
int,
float,
int,
int,
int,
int,
float,
float,
float,
float,
int,
int,
int,
int,
int,
int,
str,
]: ...
def proc_open_files(pid: int, /) -> list[tuple[str, int]]: ...
def proc_threads(pid: int, /) -> list[tuple[int, float, float]]: ...
def proc_num_threads(pid: int, /) -> int: ... # only FreeBSD and NetBSD
def proc_cpu_affinity_get(pid: int, /) -> list[int]: ... # only FreeBSD
def proc_cpu_affinity_set(pid: int, cpu_set: Sequence[int], /) -> None: ... # only FreeBSD
def proc_exe(pid: int, /) -> str: ... # only FreeBSD
def proc_getrlimit(pid: int, resource: int, /) -> tuple[int, int]: ... # only FreeBSD
def proc_memory_maps(pid: int, /) -> list[tuple[str, str, str, int, int, int, int]]: ... # only FreeBSD
def proc_net_connections( # only FreeBSD
pid: int, af_filter: Sequence[AddressFamily | int | None], type_filter: Sequence[SocketKind | int | None], /
) -> list[tuple[int, int, int, tuple[str, int], tuple[str, int] | tuple[()], int] | tuple[int, int, int, str, str, int]]: ...
def proc_setrlimit(pid: int, resource: int, soft: int, hard: int, /) -> None: ... # only FreeBSD
def boot_time() -> float: ...
def cpu_count_logical() -> int | None: ...
def cpu_stats() -> tuple[int, ...]: ... # tuple's length depends on OS
def cpu_times() -> tuple[float, float, float, float, float]: ...
def disk_io_counters() -> dict[str, tuple[int, ...]]: ... # tuple's length depends on OS
def disk_partitions() -> list[tuple[str, str, str, str]]: ...
@overload # for FreeBSD
def net_connections(
af_filter: Sequence[AddressFamily | int | None], type_filter: Sequence[SocketKind | int | None], /
) -> list[
tuple[int, int, int, tuple[str, int], tuple[str, int] | tuple[()], int, int] | tuple[int, int, int, str, str, int, int]
]: ...
@overload # for OpenBSD
def net_connections(
pid: int, af_filter: Sequence[AddressFamily | int | None], type_filter: Sequence[SocketKind | int | None], /
) -> list[
tuple[int, int, int, tuple[str, int], tuple[str, int] | tuple[()], int, int] | tuple[int, int, int, str, str, int, int]
]: ...
@overload # for NetBSD
def net_connections(pid: int, kind: str, /) -> list[tuple[int, int, int, str, str, int, int]]: ...
def net_io_counters() -> dict[str, tuple[int, int, int, int, int, int, int, int]]: ...
def per_cpu_times() -> list[tuple[float, float, float, float, float]]: ...
def pids() -> list[int]: ...
def swap_mem() -> tuple[int, int, int, int, int]: ...
def users() -> list[tuple[str, str, str, float, int | None]]: ... # returns None only in OpenBSD
def virtual_mem() -> tuple[int, ...]: ... # tuple's length depends on OS
@overload
def cpu_freq() -> int: ... # only OpenBSD
@overload
def cpu_freq(core: int, /) -> tuple[int, str]: ... # only FreeBSD
def cpu_topology() -> str | None: ... # only FreeBSD
def sensors_battery() -> tuple[int, int, int]: ... # only FreeBSD
def sensors_cpu_temperature(core: int, /) -> tuple[int, int]: ... # only FreeBSD
def check_pid_range(pid: int, /) -> None: ...
def set_debug(value: bool, /) -> None: ...