Use parsed data in cpu count
All checks were successful
buildbot/multibuild_parent Build done.
buildbot/travis_bionic Build done.

This commit is contained in:
Swapnil 2024-06-24 20:06:21 +05:30
parent 1b2769996a
commit 52ecd2dc53
Signed by: swapnil
GPG Key ID: 58029C48BB100574

View File

@ -101,15 +101,11 @@ class ServerData:
def get_cpu_count(self): def get_cpu_count(self):
cpu_count = 0 cpu_count = 0
if os.path.isfile('/usr/sbin/dmidecode'): for section in self.dmidecode_data:
try: if section['DMIType'] == 4: # 4 corresponds to processor
output = subprocess.check_output(['sudo', '/usr/sbin/dmidecode', '-t', 'processor']).decode('utf-8') core_count = int(section.get('Core Count', '0'))
core_match = re.search(r'Core Count: (\d+)', output) thread_count = int(section.get('Thread Count', '0'))
thread_match = re.search(r'Thread Count: (\d+)', output) cpu_count = core_count * thread_count
if core_match and thread_match:
cpu_count = int(core_match.group(1)) * int(thread_match.group(1))
except subprocess.CalledProcessError:
pass
if cpu_count == 0: if cpu_count == 0:
with open('/proc/cpuinfo', 'r') as f: with open('/proc/cpuinfo', 'r') as f:
cpuinfo = f.read() cpuinfo = f.read()