Skip to content

Commit 4da2140

Browse files
committed
use lscpu instead of /proc/cpuinfo
1 parent c268f2a commit 4da2140

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

scripts/generate_multiple_tables.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,24 @@
2929

3030

3131
def get_cpu_model():
32-
if platform.system() == "Windows":
32+
system = platform.system()
33+
if system == "Windows":
3334
return platform.processor()
34-
elif platform.system() == "Darwin":
35+
elif system == "Darwin":
3536
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + '/usr/sbin'
36-
command = "sysctl -n machdep.cpu.brand_string"
37-
return subprocess.check_output(command).strip()
38-
elif platform.system() == "Linux":
39-
command = "cat /proc/cpuinfo"
40-
output = subprocess.check_output(command, shell=True).decode().strip()
41-
for line in output.split("\n"):
42-
if line.startswith("model name"):
43-
return line.split(':', 1)[1].strip()
37+
command = ["sysctl", "-n", "machdep.cpu.brand_string"]
38+
return subprocess.check_output(command, text=True).strip()
39+
elif system == "Linux":
40+
output = subprocess.check_output(["lscpu"], text=True)
41+
model_name = None
42+
architecture = None
43+
for line in output.splitlines():
44+
if "Model name:" in line:
45+
model_name = line.split(":", 1)[1].strip()
46+
elif "Architecture:" in line:
47+
architecture = line.split(":", 1)[1].strip()
48+
# Prefer model_name if available; fallback to architecture
49+
return model_name or architecture or "unknown_cpu"
4450
return "unknown_cpu"
4551

4652

0 commit comments

Comments
 (0)