Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/autotest/check_autotest_speedup.py
Views: 1798
#!/usr/bin/env python12'''3Run autotest repeatedly at different speedups to help find best default speedup45AP_FLAKE8_CLEAN6'''78import optparse9import os10import re11import subprocess12import time131415class CheckAutoTestSpeedup(object):16def __init__(17self,18build_target="build.Plane",19test_target="test.QuadPlane",20min_speedup=1,21max_speedup=50,22gdb=False,23debug=False24):25self.build_target = build_target26self.test_target = test_target27self.min_speedup = min_speedup28self.max_speedup = max_speedup29self.gdb = gdb30self.debug = debug3132def progress(self, message):33print("PROGRESS: %s" % (message,))3435def run_program(self, prefix, cmd_list):36'''copied in from build_binaries.py'''37'''run cmd_list, spewing and setting output in self'''38self.progress("Running (%s)" % " ".join(cmd_list))39p = subprocess.Popen(cmd_list,40stdin=None,41close_fds=True,42stdout=subprocess.PIPE,43stderr=subprocess.STDOUT)44self.program_output = ""45while True:46x = p.stdout.readline()47if len(x) == 0:48returncode = os.waitpid(p.pid, 0)49if returncode:50break51# select not available on Windows... probably...52time.sleep(0.1)53continue54if isinstance(x, bytes):55x = x.decode('utf-8')56self.program_output += x57x = x.rstrip()58print("%s: %s" % (prefix, x))59(_, status) = returncode60if status != 0:61self.progress("Process failed (%s)" %62str(returncode))63raise subprocess.CalledProcessError(64returncode, cmd_list)6566def run(self):67build_args = [68"./Tools/autotest/autotest.py",69self.build_target70]71if opts.debug:72build_args.append("--debug")73self.run_program("BUILD", build_args)74results = {75}76f = open(os.path.join("/tmp/speedup.txt"), "w")77for i in range(self.max_speedup, self.min_speedup-1, -1):78self.progress("Checking speedup %u" % i)79run_args = [80"./Tools/autotest/autotest.py",81"--speedup", str(i),82"--show-test-timings",83self.test_target,84]85if opts.gdb:86run_args.append("--gdb")87self.run_program("SPEEDUP-%03u" % i, run_args)88for line in self.program_output.split("\n"):89match = re.match(".*tests_total_time.*?([0-9.]+)s.*", line)90if match is not None:91break92results[i] = float(match.group(1))93prog = "%u %f" % (i, results[i])94self.progress(prog)95print(prog, file=f)96f.flush()9798for (speedup, t) in results.items():99print("%u %f" % (speedup, t))100101102if __name__ == '__main__':103parser = optparse.OptionParser(104"check_autotest_speedup.py",105epilog=""106"e.g. ./Tools/autotest/check_autotest_speedup.py --max-speedup=40 --build-target=build.Sub --test-target=test.Sub"107)108parser.add_option("--debug",109default=False,110help='compile with debugging')111parser.add_option("--gdb",112default=False,113help='run under gdb')114parser.add_option("--max-speedup",115type=int,116default=50,117help='max speedup to test')118parser.add_option("--min-speedup",119type=int,120default=1,121help='min speedup to test')122parser.add_option("--build-target",123type='string',124default='build.Plane',125help='build target (e.g. build.Plane)')126parser.add_option("--test-target",127type='string',128default='test.QuadPlane',129help='test target (e.g. test.QuadPlane)')130131opts, args = parser.parse_args()132133checker = CheckAutoTestSpeedup(134gdb=opts.gdb,135debug=opts.debug,136max_speedup=opts.max_speedup,137min_speedup=opts.min_speedup,138build_target=opts.build_target,139test_target=opts.test_target140)141142checker.run()143144145