From be469c4da4efab73250f1c5bd520777978975da2 Mon Sep 17 00:00:00 2001 From: CSY-ModelCloud Date: Tue, 3 Dec 2024 13:28:05 +0800 Subject: [PATCH 1/4] check cpu virtualized --- device_smi/cpu.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/device_smi/cpu.py b/device_smi/cpu.py index 007c02c..a3f95ef 100644 --- a/device_smi/cpu.py +++ b/device_smi/cpu.py @@ -18,6 +18,8 @@ def __init__(self, cls): flags = set() if os.name == 'posix': + if "virtualization" in _run(["lscpu"]).lower(): + cls.virtualized = True try: with open("/proc/cpuinfo", "r") as f: lines = f.readlines() @@ -76,7 +78,7 @@ def __init__(self, cls): break else: if platform.system().lower() == "windows": - command_result = _run(["wmic", "cpu", "get", "manufacturer,name,numberofcores,numberoflogicalprocessors", "/format:csv"]).strip() + command_result = _run(["wmic", "cpu", "get", "manufacturer,name,numberofcores,numberoflogicalprocessors,VirtualizationFirmwareEnabled", "/format:csv"]).strip() command_result = re.sub(r'\n+', '\n', command_result) # windows uses \n\n result = command_result.split("\n")[1].split(",") cpu_count = command_result.count('\n') @@ -84,6 +86,7 @@ def __init__(self, cls): cpu_cores = int(result[3]) cpu_threads = int(result[4]) vendor = result[1].strip() + cls.virtualized = result[5].strip().lower() == "true" command_result = _run(["wmic", "os", "get", "TotalVisibleMemorySize", "/Value", "/format:csv"]).strip() command_result = re.sub(r'\n+', '\n', command_result) From 922a9edb71875d6d04495294a0f1988a1b694f48 Mon Sep 17 00:00:00 2001 From: CSY-ModelCloud Date: Tue, 3 Dec 2024 13:37:57 +0800 Subject: [PATCH 2/4] convert wmic to dict --- device_smi/cpu.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/device_smi/cpu.py b/device_smi/cpu.py index a3f95ef..461f4b7 100644 --- a/device_smi/cpu.py +++ b/device_smi/cpu.py @@ -78,20 +78,23 @@ def __init__(self, cls): break else: if platform.system().lower() == "windows": - command_result = _run(["wmic", "cpu", "get", "manufacturer,name,numberofcores,numberoflogicalprocessors,VirtualizationFirmwareEnabled", "/format:csv"]).strip() - command_result = re.sub(r'\n+', '\n', command_result) # windows uses \n\n - result = command_result.split("\n")[1].split(",") + command_result = _run(["wmic", "cpu", "get", "manufacturer,name,numberofcores,numberoflogicalprocessors,VirtualizationFirmwareEnabled", "/value"]).strip().lower() + result = self.to_dict(command_result, "=") + command_result = re.sub(r'\n+', '\n', command_result) + cpu_count = command_result.count('\n') - model = result[2].strip() - cpu_cores = int(result[3]) - cpu_threads = int(result[4]) - vendor = result[1].strip() - cls.virtualized = result[5].strip().lower() == "true" - command_result = _run(["wmic", "os", "get", "TotalVisibleMemorySize", "/Value", "/format:csv"]).strip() - command_result = re.sub(r'\n+', '\n', command_result) - result = command_result.split("\n")[1].split(",") - mem_total = int(result[1]) + model = result['name'] + cpu_cores = result['numberofcores'] + cpu_threads = result['numberoflogicalprocessors'] + + vendor = result['manufacturer'] + + cls.virtualized = result['virtualizationfirmwareenabled'] == "true" + + result = self.to_dict(_run(["wmic", "os", "get", "TotalVisibleMemorySize", "/Value"]).strip().strip().lower(), "=") + + mem_total = int(result['totalvisiblememorysize']) model = model.lower() if "amd" in model: From 8538a867cb546b7c2f52da924249b3857c868120 Mon Sep 17 00:00:00 2001 From: CSY-ModelCloud Date: Tue, 3 Dec 2024 13:48:51 +0800 Subject: [PATCH 3/4] print features on ci --- device_smi/cpu.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/device_smi/cpu.py b/device_smi/cpu.py index 461f4b7..8754198 100644 --- a/device_smi/cpu.py +++ b/device_smi/cpu.py @@ -18,7 +18,11 @@ def __init__(self, cls): flags = set() if os.name == 'posix': - if "virtualization" in _run(["lscpu"]).lower(): + if platform.system() == "darwin": + print("eeeeeeeeeee") + print(_run(['sysctl', 'machdep.cpu.features'])) + print("eeeeeeeeeee") + elif "virtualization" in _run(["lscpu"]).lower(): cls.virtualized = True try: with open("/proc/cpuinfo", "r") as f: From 0e55e3b244239861adc157ed7b7cf8e02ba34ea4 Mon Sep 17 00:00:00 2001 From: CSY-ModelCloud Date: Tue, 3 Dec 2024 13:56:18 +0800 Subject: [PATCH 4/4] lower name --- device_smi/cpu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device_smi/cpu.py b/device_smi/cpu.py index 8754198..ee1d3fd 100644 --- a/device_smi/cpu.py +++ b/device_smi/cpu.py @@ -18,7 +18,7 @@ def __init__(self, cls): flags = set() if os.name == 'posix': - if platform.system() == "darwin": + if platform.system().lower() == "darwin": print("eeeeeeeeeee") print(_run(['sysctl', 'machdep.cpu.features'])) print("eeeeeeeeeee")