Skip to content

Commit 02d4292

Browse files
authored
bpo-30263: regrtest: add system load average (#3165)
Add the CPU count in the header.
1 parent ec4ab09 commit 02d4292

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

Lib/test/regrtest.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,24 @@ def format_test_result(test_name, result):
295295
return fmt % test_name
296296

297297

298+
def cpu_count():
299+
# first try os.sysconf() to prevent loading the big multiprocessing module
300+
try:
301+
return os.sysconf('SC_NPROCESSORS_ONLN')
302+
except (AttributeError, ValueError):
303+
pass
304+
305+
# try multiprocessing.cpu_count()
306+
try:
307+
import multiprocessing
308+
except ImportError:
309+
pass
310+
else:
311+
return multiprocessing.cpu_count()
312+
313+
return None
314+
315+
298316
def unload_test_modules(save_modules):
299317
# Unload the newly imported modules (best effort finalization)
300318
for module in sys.modules.keys():
@@ -617,15 +635,24 @@ def test_forever(tests=list(selected)):
617635

618636
def display_progress(test_index, test):
619637
# "[ 51/405/1] test_tcl"
620-
fmt = "[{1:{0}}{2}/{3}] {4}" if bad else "[{1:{0}}{2}] {4}"
621-
line = fmt.format(test_count_width, test_index, test_count,
622-
len(bad), test)
638+
line = "{1:{0}}{2}".format(test_count_width, test_index, test_count)
639+
if bad and not pgo:
640+
line = '{}/{}'.format(line, len(bad))
641+
line = '[{}]'.format(line)
642+
643+
# add the system load prefix: "load avg: 1.80 "
644+
if hasattr(os, 'getloadavg'):
645+
load_avg_1min = os.getloadavg()[0]
646+
line = "load avg: {:.2f} {}".format(load_avg_1min, line)
623647

624648
# add the timestamp prefix: "0:01:05 "
625649
test_time = time.time() - regrtest_start_time
626650
test_time = datetime.timedelta(seconds=int(test_time))
627651
line = "%s %s" % (test_time, line)
628652

653+
# add the test name
654+
line = "{} {}".format(line, test)
655+
629656
print(line)
630657
sys.stdout.flush()
631658

@@ -638,6 +665,9 @@ def display_progress(test_index, test):
638665
print "== ", platform.platform(aliased=True), \
639666
"%s-endian" % sys.byteorder
640667
print "== ", os.getcwd()
668+
ncpu = cpu_count()
669+
if ncpu:
670+
print "== CPU count:", ncpu
641671
print "Testing with flags:", sys.flags
642672

643673
if randomize:

Lib/test/test_regrtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def check_line(self, output, regex):
8585
self.assertRegexpMatches(output, regex)
8686

8787
def parse_executed_tests(self, output):
88-
regex = (r'^[0-9]+:[0-9]+:[0-9]+ \[ *[0-9]+(?:/ *[0-9]+)*\] (%s)'
88+
regex = (r'^[0-9]+:[0-9]+:[0-9]+ (?:load avg: [0-9]+\.[0-9]{2} )?\[ *[0-9]+(?:/ *[0-9]+)*\] (%s)'
8989
% self.TESTNAME_REGEX)
9090
parser = re.finditer(regex, output, re.MULTILINE)
9191
return list(match.group(1) for match in parser)

0 commit comments

Comments
 (0)