Skip to content

Commit

Permalink
Include memory information
Browse files Browse the repository at this point in the history
  • Loading branch information
vsivanandharao_expedia committed Jan 1, 2025
1 parent e8d9bb0 commit 875372d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pyarchitecture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
from typing import Any, Dict

from pyarchitecture import cpu, disks, gpu
from pyarchitecture import cpu, disks, gpu, memory

version = "0.0.0-a0"

Expand All @@ -20,6 +20,7 @@ def all_components() -> Dict[str, Any]:
"Disks": disks.get_all_disks(),
"CPU": cpu.get_cpu_info(),
"GPU": gpu.get_gpu_names(),
"Memory": memory.get_memory_info(),
}


Expand Down Expand Up @@ -107,10 +108,9 @@ def commandline() -> None:
data["GPU"] = gpu.get_gpu_names()
if disk_info:
data["Disks"] = disks.get_all_disks()
import io

with open(filename, "w") as json_file:
json.dump(data, json_file, indent=2) # type: io.TextIOBase
json.dump(data, json_file, indent=2)
print(f"Architecture information has been stored in {filename!r}")
sys.exit(0)
else:
Expand Down
7 changes: 4 additions & 3 deletions pyarchitecture/cpu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
from typing import Dict

import psutil

from pyarchitecture import models
from pyarchitecture.cpu import main

Expand Down Expand Up @@ -35,9 +37,8 @@ def get_cpu_info(cpu_lib: str | os.PathLike = None) -> Dict[str, int | str]:
Returns CPU name.
"""
cpu_name = main.get_name(_get_cpu_lib(cpu_lib))
cpu_count = os.cpu_count()
return {
"name": cpu_name,
"logical_cores": cpu_count,
"physical_cores": int(cpu_count / 2) if cpu_count >= 2 else 1,
"logical_cores": psutil.cpu_count(logical=True),
"physical_cores": psutil.cpu_count(logical=False),
}
2 changes: 1 addition & 1 deletion pyarchitecture/disks/macOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import defaultdict
from typing import Dict, List

from pyarchitecture.disks import squire
from pyarchitecture import squire

LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion pyarchitecture/disks/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess
from typing import Dict, List, Tuple

from pyarchitecture.disks import squire
from pyarchitecture import squire

LOGGER = logging.getLogger(__name__)

Expand Down
25 changes: 25 additions & 0 deletions pyarchitecture/memory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import psutil

from pyarchitecture import squire


def get_memory_info(raw: bool = False) -> dict[str, int | str]:
"""Get memory information for the host system.
Returns:
Dict[str, str]:
Returns memory information.
"""
if raw:
return {
"total": psutil.virtual_memory().total,
"available": psutil.virtual_memory().available,
"used": psutil.virtual_memory().used,
"free": psutil.virtual_memory().free,
}
return {
"total": squire.size_converter(psutil.virtual_memory().total),
"available": squire.size_converter(psutil.virtual_memory().available),
"used": squire.size_converter(psutil.virtual_memory().used),
"free": squire.size_converter(psutil.virtual_memory().free),
}
File renamed without changes.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ classifiers = [
]
keywords = ["physical-drives", "PyArchitecture"]
requires-python = ">=3.10"
dependencies = [
"psutil>=6.1.1"
]

[tool.setuptools]
packages = [
Expand Down

0 comments on commit 875372d

Please sign in to comment.