question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] CPU name logic

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
aristocratoscommented, Aug 23, 2020

Added more detection logic in v1.0.17

1reaction
aristocratoscommented, Sep 14, 2020

@viv-4 Fixed in v1.0.32

Read more comments on GitHub >

github_iconTop Results From Across the Web

CPU: Central Processing Unit | AP CSP (article) | Khan Academy
The CPU can process those instructions easily, thanks to a control unit that knows how to interpret program instructions and an Arithmetic Logic...
Read more >
Central Processing Unit (CPU) Parts & Function - Study.com
ALU stands for the arithmatic and logic unit. This unit is responsible for mathematical, logical, and decision operations. This unit is divided ...
Read more >
Types of CPU | Top 6 Processors of CPU With Explanation
Here we discuss an introduction to CPU Types, six processors with explanation, ... It performs fundamental arithmetic logic, input and output operations, ...
Read more >
The central processing unit (CPU): Its components and ...
An introduction to the CPU, what it does, how it works, and how it ... The arithmetic logic unit (ALU) performs the arithmetic...
Read more >
What is this logic component? - cpu - Super User
Does anyone know what the logical component I highlighted does? cpu · computer-architecture · register · logical-processor.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found