[Python-checkins] bpo-30263: regrtest: add system load average (#3165)

Victor Stinner webhook-mailer at python.org
Mon Aug 21 12:01:15 EDT 2017


https://github.com/python/cpython/commit/02d4292df4bbd7a2cbf2716c9e6c22cae76e2093
commit: 02d4292df4bbd7a2cbf2716c9e6c22cae76e2093
branch: 2.7
author: Victor Stinner <victor.stinner at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-08-21T18:01:11+02:00
summary:

bpo-30263: regrtest: add system load average (#3165)

Add the CPU count in the header.

files:
M Lib/test/regrtest.py
M Lib/test/test_regrtest.py

diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 7096de8469a..cd8cc159364 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -295,6 +295,24 @@ def format_test_result(test_name, result):
     return fmt % test_name
 
 
+def cpu_count():
+    # first try os.sysconf() to prevent loading the big multiprocessing module
+    try:
+        return os.sysconf('SC_NPROCESSORS_ONLN')
+    except (AttributeError, ValueError):
+        pass
+
+    # try multiprocessing.cpu_count()
+    try:
+        import multiprocessing
+    except ImportError:
+        pass
+    else:
+        return multiprocessing.cpu_count()
+
+    return None
+
+
 def unload_test_modules(save_modules):
     # Unload the newly imported modules (best effort finalization)
     for module in sys.modules.keys():
@@ -617,15 +635,24 @@ def test_forever(tests=list(selected)):
 
     def display_progress(test_index, test):
         # "[ 51/405/1] test_tcl"
-        fmt = "[{1:{0}}{2}/{3}] {4}" if bad else "[{1:{0}}{2}] {4}"
-        line = fmt.format(test_count_width, test_index, test_count,
-                          len(bad), test)
+        line = "{1:{0}}{2}".format(test_count_width, test_index, test_count)
+        if bad and not pgo:
+            line = '{}/{}'.format(line, len(bad))
+        line = '[{}]'.format(line)
+
+        # add the system load prefix: "load avg: 1.80 "
+        if hasattr(os, 'getloadavg'):
+            load_avg_1min = os.getloadavg()[0]
+            line = "load avg: {:.2f} {}".format(load_avg_1min, line)
 
         # add the timestamp prefix:  "0:01:05 "
         test_time = time.time() - regrtest_start_time
         test_time = datetime.timedelta(seconds=int(test_time))
         line = "%s %s" % (test_time, line)
 
+        # add the test name
+        line = "{} {}".format(line, test)
+
         print(line)
         sys.stdout.flush()
 
@@ -638,6 +665,9 @@ def display_progress(test_index, test):
             print "==  ", platform.platform(aliased=True), \
                           "%s-endian" % sys.byteorder
             print "==  ", os.getcwd()
+            ncpu = cpu_count()
+            if ncpu:
+                print "== CPU count:", ncpu
             print "Testing with flags:", sys.flags
 
     if randomize:
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index 400463c4263..264c74d22ba 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -85,7 +85,7 @@ def check_line(self, output, regex):
         self.assertRegexpMatches(output, regex)
 
     def parse_executed_tests(self, output):
-        regex = (r'^[0-9]+:[0-9]+:[0-9]+ \[ *[0-9]+(?:/ *[0-9]+)*\] (%s)'
+        regex = (r'^[0-9]+:[0-9]+:[0-9]+ (?:load avg: [0-9]+\.[0-9]{2} )?\[ *[0-9]+(?:/ *[0-9]+)*\] (%s)'
                  % self.TESTNAME_REGEX)
         parser = re.finditer(regex, output, re.MULTILINE)
         return list(match.group(1) for match in parser)



More information about the Python-checkins mailing list