CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/autotest/check_autotest_speedup.py
Views: 1798
1
#!/usr/bin/env python
2
3
'''
4
Run autotest repeatedly at different speedups to help find best default speedup
5
6
AP_FLAKE8_CLEAN
7
'''
8
9
import optparse
10
import os
11
import re
12
import subprocess
13
import time
14
15
16
class CheckAutoTestSpeedup(object):
17
def __init__(
18
self,
19
build_target="build.Plane",
20
test_target="test.QuadPlane",
21
min_speedup=1,
22
max_speedup=50,
23
gdb=False,
24
debug=False
25
):
26
self.build_target = build_target
27
self.test_target = test_target
28
self.min_speedup = min_speedup
29
self.max_speedup = max_speedup
30
self.gdb = gdb
31
self.debug = debug
32
33
def progress(self, message):
34
print("PROGRESS: %s" % (message,))
35
36
def run_program(self, prefix, cmd_list):
37
'''copied in from build_binaries.py'''
38
'''run cmd_list, spewing and setting output in self'''
39
self.progress("Running (%s)" % " ".join(cmd_list))
40
p = subprocess.Popen(cmd_list,
41
stdin=None,
42
close_fds=True,
43
stdout=subprocess.PIPE,
44
stderr=subprocess.STDOUT)
45
self.program_output = ""
46
while True:
47
x = p.stdout.readline()
48
if len(x) == 0:
49
returncode = os.waitpid(p.pid, 0)
50
if returncode:
51
break
52
# select not available on Windows... probably...
53
time.sleep(0.1)
54
continue
55
if isinstance(x, bytes):
56
x = x.decode('utf-8')
57
self.program_output += x
58
x = x.rstrip()
59
print("%s: %s" % (prefix, x))
60
(_, status) = returncode
61
if status != 0:
62
self.progress("Process failed (%s)" %
63
str(returncode))
64
raise subprocess.CalledProcessError(
65
returncode, cmd_list)
66
67
def run(self):
68
build_args = [
69
"./Tools/autotest/autotest.py",
70
self.build_target
71
]
72
if opts.debug:
73
build_args.append("--debug")
74
self.run_program("BUILD", build_args)
75
results = {
76
}
77
f = open(os.path.join("/tmp/speedup.txt"), "w")
78
for i in range(self.max_speedup, self.min_speedup-1, -1):
79
self.progress("Checking speedup %u" % i)
80
run_args = [
81
"./Tools/autotest/autotest.py",
82
"--speedup", str(i),
83
"--show-test-timings",
84
self.test_target,
85
]
86
if opts.gdb:
87
run_args.append("--gdb")
88
self.run_program("SPEEDUP-%03u" % i, run_args)
89
for line in self.program_output.split("\n"):
90
match = re.match(".*tests_total_time.*?([0-9.]+)s.*", line)
91
if match is not None:
92
break
93
results[i] = float(match.group(1))
94
prog = "%u %f" % (i, results[i])
95
self.progress(prog)
96
print(prog, file=f)
97
f.flush()
98
99
for (speedup, t) in results.items():
100
print("%u %f" % (speedup, t))
101
102
103
if __name__ == '__main__':
104
parser = optparse.OptionParser(
105
"check_autotest_speedup.py",
106
epilog=""
107
"e.g. ./Tools/autotest/check_autotest_speedup.py --max-speedup=40 --build-target=build.Sub --test-target=test.Sub"
108
)
109
parser.add_option("--debug",
110
default=False,
111
help='compile with debugging')
112
parser.add_option("--gdb",
113
default=False,
114
help='run under gdb')
115
parser.add_option("--max-speedup",
116
type=int,
117
default=50,
118
help='max speedup to test')
119
parser.add_option("--min-speedup",
120
type=int,
121
default=1,
122
help='min speedup to test')
123
parser.add_option("--build-target",
124
type='string',
125
default='build.Plane',
126
help='build target (e.g. build.Plane)')
127
parser.add_option("--test-target",
128
type='string',
129
default='test.QuadPlane',
130
help='test target (e.g. test.QuadPlane)')
131
132
opts, args = parser.parse_args()
133
134
checker = CheckAutoTestSpeedup(
135
gdb=opts.gdb,
136
debug=opts.debug,
137
max_speedup=opts.max_speedup,
138
min_speedup=opts.min_speedup,
139
build_target=opts.build_target,
140
test_target=opts.test_target
141
)
142
143
checker.run()
144
145