Refactor meminfo (#4698)
This commit is contained in:
parent
d571283d69
commit
f4e0d4cf66
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
from dataclasses import dataclass
|
||||||
from enum import Enum, StrEnum
|
from enum import Enum, StrEnum
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
@ -163,25 +164,6 @@ class _SysInfo:
|
||||||
|
|
||||||
return cpu
|
return cpu
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def mem_info(self) -> dict[str, int]:
|
|
||||||
"""
|
|
||||||
Returns system memory information
|
|
||||||
"""
|
|
||||||
mem_info_path = Path('/proc/meminfo')
|
|
||||||
mem_info: dict[str, int] = {}
|
|
||||||
|
|
||||||
with mem_info_path.open() as file:
|
|
||||||
for line in file:
|
|
||||||
key, value = line.strip().split(':')
|
|
||||||
num = value.split()[0]
|
|
||||||
mem_info[key] = int(num)
|
|
||||||
|
|
||||||
return mem_info
|
|
||||||
|
|
||||||
def mem_info_by_key(self, key: str) -> int:
|
|
||||||
return self.mem_info[key]
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def loaded_modules(self) -> list[str]:
|
def loaded_modules(self) -> list[str]:
|
||||||
"""
|
"""
|
||||||
|
|
@ -273,18 +255,6 @@ class SysInfo:
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def mem_available() -> int:
|
|
||||||
return _sys_info.mem_info_by_key('MemAvailable')
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def mem_free() -> int:
|
|
||||||
return _sys_info.mem_info_by_key('MemFree')
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def mem_total() -> int:
|
|
||||||
return _sys_info.mem_info_by_key('MemTotal')
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def virtualization() -> str | None:
|
def virtualization() -> str | None:
|
||||||
try:
|
try:
|
||||||
|
|
@ -340,3 +310,26 @@ class SysInfo:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class MemInfo:
|
||||||
|
mem_total: int
|
||||||
|
mem_free: int
|
||||||
|
mem_available: int
|
||||||
|
|
||||||
|
|
||||||
|
def read_meminfo() -> MemInfo:
|
||||||
|
data: dict[str, int] = {}
|
||||||
|
|
||||||
|
with Path('/proc/meminfo').open() as file:
|
||||||
|
for line in file:
|
||||||
|
key, _, remainder = line.partition(':')
|
||||||
|
num, _, _ = remainder.strip().partition(' ')
|
||||||
|
data[key] = int(num)
|
||||||
|
|
||||||
|
return MemInfo(
|
||||||
|
mem_total=data['MemTotal'],
|
||||||
|
mem_free=data['MemFree'],
|
||||||
|
mem_available=data['MemAvailable'],
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ from pathlib import Path
|
||||||
|
|
||||||
from archinstall.lib.args import ArchConfigHandler, SubCommand
|
from archinstall.lib.args import ArchConfigHandler, SubCommand
|
||||||
from archinstall.lib.disk.utils import disk_layouts
|
from archinstall.lib.disk.utils import disk_layouts
|
||||||
from archinstall.lib.hardware import SysInfo
|
from archinstall.lib.hardware import MemInfo, SysInfo, read_meminfo
|
||||||
from archinstall.lib.log import debug, error, info, logger, share_install_log, warn
|
from archinstall.lib.log import debug, error, info, logger, share_install_log, warn
|
||||||
from archinstall.lib.menu.helpers import Confirmation
|
from archinstall.lib.menu.helpers import Confirmation
|
||||||
from archinstall.lib.network.wifi_handler import WifiHandler
|
from archinstall.lib.network.wifi_handler import WifiHandler
|
||||||
|
|
@ -23,11 +23,11 @@ from archinstall.tui.components import tui
|
||||||
from archinstall.tui.menu_item import MenuItemGroup
|
from archinstall.tui.menu_item import MenuItemGroup
|
||||||
|
|
||||||
|
|
||||||
def _log_sys_info() -> None:
|
def _log_sys_info(meminfo: MemInfo) -> None:
|
||||||
# Log various information about hardware before starting the installation. This might assist in troubleshooting
|
# Log various information about hardware before starting the installation. This might assist in troubleshooting
|
||||||
debug(f'Hardware model detected: {SysInfo.sys_vendor()} {SysInfo.product_name()}; UEFI mode: {SysInfo.has_uefi()}')
|
debug(f'Hardware model detected: {SysInfo.sys_vendor()} {SysInfo.product_name()}; UEFI mode: {SysInfo.has_uefi()}')
|
||||||
debug(f'Processor model detected: {SysInfo.cpu_model()}')
|
debug(f'Processor model detected: {SysInfo.cpu_model()}')
|
||||||
debug(f'Memory statistics: {SysInfo.mem_available()} available out of {SysInfo.mem_total()} total installed')
|
debug(f'Memory statistics: {meminfo.mem_available} kB available out of {meminfo.mem_total} kB total installed')
|
||||||
debug(f'Virtualization detected: {SysInfo.virtualization()}; is VM: {SysInfo.is_vm()}')
|
debug(f'Virtualization detected: {SysInfo.virtualization()}; is VM: {SysInfo.is_vm()}')
|
||||||
debug(f'Graphics devices detected: {SysInfo._graphics_devices().keys()}')
|
debug(f'Graphics devices detected: {SysInfo._graphics_devices().keys()}')
|
||||||
|
|
||||||
|
|
@ -138,7 +138,7 @@ def run() -> int:
|
||||||
|
|
||||||
translation_handler.save_console_font()
|
translation_handler.save_console_font()
|
||||||
|
|
||||||
_log_sys_info()
|
_log_sys_info(read_meminfo())
|
||||||
|
|
||||||
if not arch_config_handler.args.offline:
|
if not arch_config_handler.args.offline:
|
||||||
if not arch_config_handler.args.skip_wifi_check:
|
if not arch_config_handler.args.skip_wifi_check:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue