Skip to content

Commit

Permalink
update intention
Browse files Browse the repository at this point in the history
  • Loading branch information
CSY-ModelCloud committed Dec 4, 2024
1 parent 12e6059 commit 15d5624
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions device_smi/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ def __init__(self, cls):
command_result = re.sub(r'\n+', '\n', command_result)
result = command_result.split("\n")[1].split(",")
mem_total = int(result[1])
elif platform.system().lower() == "darwin":
model = (
_run(["sysctl", "-n", "machdep.cpu.brand_string"])
.replace("Apple", "")
.strip()
)
elif os.name == 'darwin':
model = (_run(["sysctl", "-n", "machdep.cpu.brand_string"]).replace("Apple", "").strip())
try:
vendor = (_run(["sysctl", "-n", "machdep.cpu.vendor"]))
except BaseException:
Expand All @@ -52,11 +48,10 @@ def __init__(self, cls):
try:
features = sysctl_info["machdep.cpu.features"].splitlines()
except Exception:
# machdep.cpu.features is not available on arm arch
features = []

flags = set(features)
else:
elif os.name == 'posix':
try:
with open("/proc/cpuinfo", "r") as f:
lines = f.readlines()
Expand All @@ -65,27 +60,30 @@ def __init__(self, cls):
flags.update(line.strip().split(":")[1].split())
if line.startswith("model name"):
model = line.split(":")[1].strip()


elif line.startswith("vendor_id"):
vendor = line.split(":")[1].strip()
except FileNotFoundError:
if platform.system().lower() != "darwin":
model = platform.processor()
vendor = platform.uname().system
else:
cpu_info = self.to_dict(_run(['lscpu']))
model = platform.processor()
vendor = platform.uname().system

cpu_count = int(cpu_info["Socket(s)"])
cpu_cores_per_socket = int(cpu_info["Core(s) per socket"])
cpu_cores = cpu_count * cpu_cores_per_socket
cpu_threads = int(cpu_info["CPU(s)"])
cpu_info = self.to_dict(_run(['lscpu']))

with open("/proc/meminfo", "r") as f:
lines = f.readlines()
mem_total = 0
for line in lines:
if line.startswith("MemTotal:"):
mem_total = int(line.split()[1]) * 1024
break
cpu_count = int(cpu_info["Socket(s)"])
cpu_cores_per_socket = int(cpu_info["Core(s) per socket"])
cpu_cores = cpu_count * cpu_cores_per_socket
cpu_threads = int(cpu_info["CPU(s)"])

with open("/proc/meminfo", "r") as f:
lines = f.readlines()
mem_total = 0
for line in lines:
if line.startswith("MemTotal:"):
mem_total = int(line.split()[1]) * 1024
break
else:
print("not support")

model = " ".join(i for i in model.lower().split() if not any(x in i for x in ["ghz", "cpu", "(r)", "(tm)", "intel", "amd", "core", "processor", "@"]))
cls.model = model
Expand Down Expand Up @@ -171,7 +169,7 @@ def metrics(self):

free_pages = int(result["pages free"])

mem_free = free_pages * page_size
mem_free = free_pages * page_size
else:
with open("/proc/meminfo", "r") as f:
lines = f.readlines()
Expand Down

0 comments on commit 15d5624

Please sign in to comment.