[QUESTION] CPU name logic
See original GitHub issueIs the following code block the entire logic in bpytop determining the CPU name that gets displayed?
I’m just curious at this point because I have a CPU that reports as “Intel® Core™2 Duo CPU” and bpytop just ends up displaying “Duo”, which is not that helpful since it could also refer to a Core Duo CPU.
I’m wondering if anyone out there has already built a function to more reliably return a useful and accurate (but shortened) CPU name that would better suit the bpytop use case. Failing that, maybe I can add to the filtering logic here. For instance, filtering out “Processor” from “ARMv7 Processor rev 3 (v7l)” on the Raspberry Pi.
This function did pretty good with a Ryzen 3600X processor, but maybe that was just because it called itself “Ryzen 3600X”. I didn’t check.
def get_cpu_name() -> str:
'''Fetch a suitable CPU identifier from the CPU model name string'''
name: str = ""
nlist: List = []
command: str = ""
cmd_out: str = ""
rem_line: str = ""
if SYSTEM == "Linux":
command = "cat /proc/cpuinfo"
rem_line = "model name"
elif SYSTEM == "MacOS":
command ="sysctl -n machdep.cpu.brand_string"
elif SYSTEM == "BSD":
command ="sysctl hw.model"
rem_line = "hw.model"
try:
cmd_out = subprocess.check_output("LANG=C " + command, shell=True, universal_newlines=True)
except:
pass
if rem_line:
for line in cmd_out.split("\n"):
if rem_line in line:
name = re.sub( ".*" + rem_line + ".*:", "", line,1).lstrip()
else:
name = cmd_out
nlist = name.split(" ")
if "Xeon" in name and "CPU" in name:
name = nlist[nlist.index("CPU")+1]
elif "Ryzen" in name:
name = " ".join(nlist[nlist.index("Ryzen"):nlist.index("Ryzen")+3])
elif "CPU" in name and not nlist[0] == "CPU":
name = nlist[nlist.index("CPU")-1]
return name
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (9 by maintainers)
Top GitHub Comments
Added more detection logic in v1.0.17
@viv-4 Fixed in v1.0.32