Skip to content

Commit 3d00568

Browse files
authored
bpo-30263: regrtest: log system load (#1452)
* bpo-30263: regrtest: log system load * regrtest: log the number of CPUs Log the number of CPUs in the header. --verbose now imply --header.
1 parent dbaf746 commit 3d00568

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

‎Lib/test/libregrtest/cmdline.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,5 +343,7 @@ def _parse_args(args, **kwargs):
343343
ns.use_resources.append(r)
344344
if ns.random_seed is not None:
345345
ns.randomize = True
346+
if ns.verbose:
347+
ns.header = True
346348

347349
return ns

‎Lib/test/libregrtest/main.py‎

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,22 @@ def accumulate_result(self, test, result):
120120
def display_progress(self, test_index, test):
121121
if self.ns.quiet:
122122
return
123+
124+
# "[ 51/405/1] test_tcl passed"
125+
line = f"{test_index:{self.test_count_width}}{self.test_count}"
123126
if self.bad and not self.ns.pgo:
124-
fmt = "{time} [{test_index:{count_width}}{test_count}/{nbad}] {test_name}"
125-
else:
126-
fmt = "{time} [{test_index:{count_width}}{test_count}] {test_name}"
127+
line = f"{line}/{len(self.bad)}"
128+
line = f"[{line}] {test}"
129+
130+
# add the system load prefix: "load avg: 1.80 "
131+
if hasattr(os, 'getloadavg'):
132+
load_avg_1min = os.getloadavg()[0]
133+
line = f"load avg: {load_avg_1min:.2f} {line}"
134+
135+
# add the timestamp prefix: "0:01:05 "
127136
test_time = time.monotonic() - self.start_time
128137
test_time = datetime.timedelta(seconds=int(test_time))
129-
line = fmt.format(count_width=self.test_count_width,
130-
test_index=test_index,
131-
test_count=self.test_count,
132-
nbad=len(self.bad),
133-
test_name=test,
134-
time=test_time)
138+
line = f"{test_time} {line}"
135139
print(line, flush=True)
136140

137141
def parse_args(self, kwargs):
@@ -376,23 +380,28 @@ def _test_forever(self, tests):
376380
if self.bad:
377381
return
378382

383+
def display_header(self):
384+
# Print basic platform information
385+
print("==", platform.python_implementation(), *sys.version.split())
386+
print("==", platform.platform(aliased=True),
387+
"%s-endian" % sys.byteorder)
388+
print("== hash algorithm:", sys.hash_info.algorithm,
389+
"64bit" if sys.maxsize > 2**32 else "32bit")
390+
print("== cwd:", os.getcwd())
391+
cpu_count = os.cpu_count()
392+
if cpu_count:
393+
print("== CPU count:", cpu_count)
394+
print("== encodings: locale=%s, FS=%s"
395+
% (locale.getpreferredencoding(False),
396+
sys.getfilesystemencoding()))
397+
print("Testing with flags:", sys.flags)
398+
379399
def run_tests(self):
380400
# For a partial run, we do not need to clutter the output.
381-
if (self.ns.verbose
382-
or self.ns.header
383-
or not (self.ns.pgo or self.ns.quiet or self.ns.single
384-
or self.tests or self.ns.args)):
385-
# Print basic platform information
386-
print("==", platform.python_implementation(), *sys.version.split())
387-
print("== ", platform.platform(aliased=True),
388-
"%s-endian" % sys.byteorder)
389-
print("== ", "hash algorithm:", sys.hash_info.algorithm,
390-
"64bit" if sys.maxsize > 2**32 else "32bit")
391-
print("== cwd:", os.getcwd())
392-
print("== encodings: locale=%s, FS=%s"
393-
% (locale.getpreferredencoding(False),
394-
sys.getfilesystemencoding()))
395-
print("Testing with flags:", sys.flags)
401+
if (self.ns.header
402+
or not(self.ns.pgo or self.ns.quiet or self.ns.single
403+
or self.tests or self.ns.args)):
404+
self.display_header()
396405

397406
if self.ns.randomize:
398407
print("Using random seed", self.ns.random_seed)

‎Lib/test/test_regrtest.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ def test_header(self):
118118
ns = libregrtest._parse_args(['--header'])
119119
self.assertTrue(ns.header)
120120

121+
ns = libregrtest._parse_args(['--verbose'])
122+
self.assertTrue(ns.header)
123+
121124
def test_randomize(self):
122125
for opt in '-r', '--randomize':
123126
with self.subTest(opt=opt):
@@ -354,7 +357,7 @@ def check_line(self, output, regex):
354357
self.assertRegex(output, regex)
355358

356359
def parse_executed_tests(self, output):
357-
regex = (r'^[0-9]+:[0-9]+:[0-9]+ \[ *[0-9]+(?:/ *[0-9]+)*\] (%s)'
360+
regex = (r'^[0-9]+:[0-9]+:[0-9]+ (?:load avg: [0-9]+\.[0-9]{2} )?\[ *[0-9]+(?:/ *[0-9]+)*\] (%s)'
358361
% self.TESTNAME_REGEX)
359362
parser = re.finditer(regex, output, re.MULTILINE)
360363
return list(match.group(1) for match in parser)

0 commit comments

Comments
 (0)