Skip to content

Commit 3438fde

Browse files
authored
Fix emrun --system-info. NFC (#23826)
On my local machine `/proc/cpuinfo` contains `min` and `max` Mhz lines.
1 parent 8af2200 commit 3438fde

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

emrun.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import argparse
1818
import atexit
1919
import json
20+
import math
2021
import os
2122
import platform
2223
import re
@@ -769,12 +770,11 @@ def get_cpu_info():
769770
logical_cores = int(check_output(['sysctl', '-n', 'machdep.cpu.thread_count']).strip())
770771
frequency = int(check_output(['sysctl', '-n', 'hw.cpufrequency']).strip()) // 1000000
771772
elif LINUX:
772-
all_info = check_output(['cat', '/proc/cpuinfo']).strip()
773-
for line in all_info.split("\n"):
773+
for line in open('/proc/cpuinfo').readlines():
774774
if 'model name' in line:
775775
cpu_name = re.sub('.*model name.*:', '', line, count=1).strip()
776776
lscpu = check_output(['lscpu'])
777-
frequency = int(float(re.search('CPU MHz: (.*)', lscpu).group(1).strip()) + 0.5)
777+
frequency = math.ceil(float(re.search('CPU (max )?MHz: (.*)', lscpu).group(2).strip()))
778778
sockets = int(re.search(r'Socket\(s\): (.*)', lscpu).group(1).strip())
779779
physical_cores = sockets * int(re.search(r'Core\(s\) per socket: (.*)', lscpu).group(1).strip())
780780
logical_cores = physical_cores * int(re.search(r'Thread\(s\) per core: (.*)', lscpu).group(1).strip())
@@ -1391,7 +1391,8 @@ def get_system_info(format_json):
13911391
else:
13921392
cpu = get_cpu_info()
13931393
gpus = get_gpu_info()
1394-
info = 'Computer name: ' + socket.gethostname() + '\n' # http://stackoverflow.com/questions/799767/getting-name-of-windows-computer-running-python-script
1394+
# http://stackoverflow.com/questions/799767/getting-name-of-windows-computer-running-python-script
1395+
info = 'Computer name: ' + socket.gethostname() + '\n'
13951396
info += 'Model: ' + get_computer_model() + '\n'
13961397
info += 'OS: ' + get_os_version() + ' with ' + str(get_system_memory() // 1024 // 1024) + ' MB of System RAM\n'
13971398
info += 'CPU: ' + cpu['model'] + ', ' + str(cpu['frequency']) + ' MHz, ' + str(cpu['physicalCores']) + ' physical cores, ' + str(cpu['logicalCores']) + ' logical cores\n'

0 commit comments

Comments
 (0)