mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									dbaf746b6d
								
							
						
					
					
						commit
						3d0056842c
					
				
					 3 changed files with 39 additions and 25 deletions
				
			
		| 
						 | 
					@ -343,5 +343,7 @@ def _parse_args(args, **kwargs):
 | 
				
			||||||
                    ns.use_resources.append(r)
 | 
					                    ns.use_resources.append(r)
 | 
				
			||||||
    if ns.random_seed is not None:
 | 
					    if ns.random_seed is not None:
 | 
				
			||||||
        ns.randomize = True
 | 
					        ns.randomize = True
 | 
				
			||||||
 | 
					    if ns.verbose:
 | 
				
			||||||
 | 
					        ns.header = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return ns
 | 
					    return ns
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -120,18 +120,22 @@ class Regrtest:
 | 
				
			||||||
    def display_progress(self, test_index, test):
 | 
					    def display_progress(self, test_index, test):
 | 
				
			||||||
        if self.ns.quiet:
 | 
					        if self.ns.quiet:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # "[ 51/405/1] test_tcl passed"
 | 
				
			||||||
 | 
					        line = f"{test_index:{self.test_count_width}}{self.test_count}"
 | 
				
			||||||
        if self.bad and not self.ns.pgo:
 | 
					        if self.bad and not self.ns.pgo:
 | 
				
			||||||
            fmt = "{time} [{test_index:{count_width}}{test_count}/{nbad}] {test_name}"
 | 
					            line = f"{line}/{len(self.bad)}"
 | 
				
			||||||
        else:
 | 
					        line = f"[{line}] {test}"
 | 
				
			||||||
            fmt = "{time} [{test_index:{count_width}}{test_count}] {test_name}"
 | 
					
 | 
				
			||||||
 | 
					        # add the system load prefix: "load avg: 1.80 "
 | 
				
			||||||
 | 
					        if hasattr(os, 'getloadavg'):
 | 
				
			||||||
 | 
					            load_avg_1min = os.getloadavg()[0]
 | 
				
			||||||
 | 
					            line = f"load avg: {load_avg_1min:.2f} {line}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # add the timestamp prefix:  "0:01:05 "
 | 
				
			||||||
        test_time = time.monotonic() - self.start_time
 | 
					        test_time = time.monotonic() - self.start_time
 | 
				
			||||||
        test_time = datetime.timedelta(seconds=int(test_time))
 | 
					        test_time = datetime.timedelta(seconds=int(test_time))
 | 
				
			||||||
        line = fmt.format(count_width=self.test_count_width,
 | 
					        line = f"{test_time} {line}"
 | 
				
			||||||
                          test_index=test_index,
 | 
					 | 
				
			||||||
                          test_count=self.test_count,
 | 
					 | 
				
			||||||
                          nbad=len(self.bad),
 | 
					 | 
				
			||||||
                          test_name=test,
 | 
					 | 
				
			||||||
                          time=test_time)
 | 
					 | 
				
			||||||
        print(line, flush=True)
 | 
					        print(line, flush=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def parse_args(self, kwargs):
 | 
					    def parse_args(self, kwargs):
 | 
				
			||||||
| 
						 | 
					@ -376,24 +380,29 @@ class Regrtest:
 | 
				
			||||||
                if self.bad:
 | 
					                if self.bad:
 | 
				
			||||||
                    return
 | 
					                    return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def run_tests(self):
 | 
					    def display_header(self):
 | 
				
			||||||
        # For a partial run, we do not need to clutter the output.
 | 
					 | 
				
			||||||
        if (self.ns.verbose
 | 
					 | 
				
			||||||
            or self.ns.header
 | 
					 | 
				
			||||||
            or not (self.ns.pgo or self.ns.quiet or self.ns.single
 | 
					 | 
				
			||||||
                    or self.tests or self.ns.args)):
 | 
					 | 
				
			||||||
        # Print basic platform information
 | 
					        # Print basic platform information
 | 
				
			||||||
        print("==", platform.python_implementation(), *sys.version.split())
 | 
					        print("==", platform.python_implementation(), *sys.version.split())
 | 
				
			||||||
            print("==  ", platform.platform(aliased=True),
 | 
					        print("==", platform.platform(aliased=True),
 | 
				
			||||||
                      "%s-endian" % sys.byteorder)
 | 
					                      "%s-endian" % sys.byteorder)
 | 
				
			||||||
            print("==  ", "hash algorithm:", sys.hash_info.algorithm,
 | 
					        print("== hash algorithm:", sys.hash_info.algorithm,
 | 
				
			||||||
              "64bit" if sys.maxsize > 2**32 else "32bit")
 | 
					              "64bit" if sys.maxsize > 2**32 else "32bit")
 | 
				
			||||||
        print("== cwd:", os.getcwd())
 | 
					        print("== cwd:", os.getcwd())
 | 
				
			||||||
 | 
					        cpu_count = os.cpu_count()
 | 
				
			||||||
 | 
					        if cpu_count:
 | 
				
			||||||
 | 
					            print("== CPU count:", cpu_count)
 | 
				
			||||||
        print("== encodings: locale=%s, FS=%s"
 | 
					        print("== encodings: locale=%s, FS=%s"
 | 
				
			||||||
              % (locale.getpreferredencoding(False),
 | 
					              % (locale.getpreferredencoding(False),
 | 
				
			||||||
                 sys.getfilesystemencoding()))
 | 
					                 sys.getfilesystemencoding()))
 | 
				
			||||||
        print("Testing with flags:", sys.flags)
 | 
					        print("Testing with flags:", sys.flags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def run_tests(self):
 | 
				
			||||||
 | 
					        # For a partial run, we do not need to clutter the output.
 | 
				
			||||||
 | 
					        if (self.ns.header
 | 
				
			||||||
 | 
					            or not(self.ns.pgo or self.ns.quiet or self.ns.single
 | 
				
			||||||
 | 
					                   or self.tests or self.ns.args)):
 | 
				
			||||||
 | 
					            self.display_header()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if self.ns.randomize:
 | 
					        if self.ns.randomize:
 | 
				
			||||||
            print("Using random seed", self.ns.random_seed)
 | 
					            print("Using random seed", self.ns.random_seed)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -118,6 +118,9 @@ class ParseArgsTestCase(unittest.TestCase):
 | 
				
			||||||
        ns = libregrtest._parse_args(['--header'])
 | 
					        ns = libregrtest._parse_args(['--header'])
 | 
				
			||||||
        self.assertTrue(ns.header)
 | 
					        self.assertTrue(ns.header)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ns = libregrtest._parse_args(['--verbose'])
 | 
				
			||||||
 | 
					        self.assertTrue(ns.header)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_randomize(self):
 | 
					    def test_randomize(self):
 | 
				
			||||||
        for opt in '-r', '--randomize':
 | 
					        for opt in '-r', '--randomize':
 | 
				
			||||||
            with self.subTest(opt=opt):
 | 
					            with self.subTest(opt=opt):
 | 
				
			||||||
| 
						 | 
					@ -354,7 +357,7 @@ class BaseTestCase(unittest.TestCase):
 | 
				
			||||||
        self.assertRegex(output, regex)
 | 
					        self.assertRegex(output, regex)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def parse_executed_tests(self, output):
 | 
					    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)
 | 
					                 % self.TESTNAME_REGEX)
 | 
				
			||||||
        parser = re.finditer(regex, output, re.MULTILINE)
 | 
					        parser = re.finditer(regex, output, re.MULTILINE)
 | 
				
			||||||
        return list(match.group(1) for match in parser)
 | 
					        return list(match.group(1) for match in parser)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue