Skip to content

Commit

Permalink
use lower case to check platform
Browse files Browse the repository at this point in the history
  • Loading branch information
CSY-ModelCloud committed Dec 4, 2024
1 parent fbb2831 commit be084a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions device_smi/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, cls):
elif line.startswith("vendor_id"):
vendor = line.split(":")[1].strip()
except FileNotFoundError:
if platform.system() == "Darwin":
if platform.system().lower() == "darwin":
model = (
_run(["sysctl", "-n", "machdep.cpu.brand_string"])
.replace("Apple", "")
Expand All @@ -44,7 +44,7 @@ def __init__(self, cls):
else:
model = platform.processor()
vendor = platform.uname().system
if platform.system() == "Darwin":
if platform.system().lower() == "darwin":
sysctl_info = self.to_dict(_run(["sysctl", "-a"]))
cpu_count = 1
cpu_cores = int(sysctl_info["hw.physicalcpu"])
Expand Down Expand Up @@ -107,7 +107,7 @@ def __init__(self, cls):

def _utilization(self):
# check if is macOS
if platform.system() == "Darwin":
if platform.system().lower() == "darwin":
output = _run(["top", "-l", "1", "-stats", "cpu"])

# CPU usage: 7.61% user, 15.23% sys, 77.15% idle
Expand Down Expand Up @@ -159,12 +159,12 @@ def metrics(self):
if total_diff <= 0:
utilization = 0
else:
if platform.system() == "Darwin":
if platform.system().lower() == "darwin":
utilization = idle_time_2 - idle_time_1
else:
utilization = (1 - (idle_diff / total_diff)) * 100

if platform.system() == "Darwin":
if platform.system().lower() == "darwin":
available_mem = _run(["vm_stat"]).replace(".", "").lower()

result = self.to_dict(available_mem)
Expand All @@ -187,7 +187,7 @@ def metrics(self):
memory_used = self.memory_total - mem_free

process_id = os.getpid()
if platform.system() == "Darwin":
if platform.system().lower() == "darwin":
result = _run(["ps", "-p", str(process_id), "-o", "rss="])
memory_current_process = int(result) * 1024
else:
Expand Down
2 changes: 1 addition & 1 deletion device_smi/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, device):
or device_type == "xpu"
or re.match(r"(gpu|cuda|xpu):\d+", device_type)
):
if platform.system() == "Darwin":
if platform.system().lower() == "darwin":
if platform.machine() == 'x86_64':
raise Exception("Not supported for macOS on Intel chips.")

Expand Down

0 comments on commit be084a7

Please sign in to comment.