Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: tools/skpbench/skpbench.py

Issue 2410373002: skpbench: add warmup run (Closed)
Patch Set: skpbench: add warmup run Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/skpbench/skpbench.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright 2016 Google Inc. 3 # Copyright 2016 Google Inc.
4 # 4 #
5 # Use of this source code is governed by a BSD-style license that can be 5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file. 6 # found in the LICENSE file.
7 7
8 from __future__ import print_function 8 from __future__ import print_function
9 from _adb import Adb 9 from _adb import Adb
10 from _benchresult import BenchResult 10 from _benchresult import BenchResult
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 nargs='+', 60 nargs='+',
61 help=".skp files or directories to expand for .skp files") 61 help=".skp files or directories to expand for .skp files")
62 62
63 FLAGS = __argparse.parse_args() 63 FLAGS = __argparse.parse_args()
64 if FLAGS.adb: 64 if FLAGS.adb:
65 import _adb_path as _path 65 import _adb_path as _path
66 _path.init(FLAGS.device_serial) 66 _path.init(FLAGS.device_serial)
67 else: 67 else:
68 import _os_path as _path 68 import _os_path as _path
69 69
70 def dump_commandline_if_verbose(commandline):
71 if FLAGS.verbosity >= 4:
72 quoted = ['\'%s\'' % re.sub(r'([\\\'])', r'\\\1', x) for x in commandline]
73 print(' '.join(quoted), file=sys.stderr)
74
70 75
71 class StddevException(Exception): 76 class StddevException(Exception):
72 pass 77 pass
73 78
74 class Message: 79 class Message:
75 READLINE = 0, 80 READLINE = 0,
76 POLL_HARDWARE = 1, 81 POLL_HARDWARE = 1,
77 EXIT = 2 82 EXIT = 2
78 def __init__(self, message, value=None): 83 def __init__(self, message, value=None):
79 self.message = message 84 self.message = message
(...skipping 24 matching lines...) Expand all
104 if FLAGS.path: 109 if FLAGS.path:
105 ARGV[0] = _path.join(FLAGS.path, ARGV[0]) 110 ARGV[0] = _path.join(FLAGS.path, ARGV[0])
106 if FLAGS.adb: 111 if FLAGS.adb:
107 if FLAGS.device_serial is None: 112 if FLAGS.device_serial is None:
108 ARGV = ['adb', 'shell'] + ARGV 113 ARGV = ['adb', 'shell'] + ARGV
109 else: 114 else:
110 ARGV = ['adb', '-s', FLAGS.device_serial, 'shell'] + ARGV 115 ARGV = ['adb', '-s', FLAGS.device_serial, 'shell'] + ARGV
111 116
112 @classmethod 117 @classmethod
113 def print_header(cls): 118 def print_header(cls):
114 subprocess.call(cls.ARGV + ['--duration', '0']) 119 commandline = cls.ARGV + ['--duration', '0']
120 dump_commandline_if_verbose(commandline)
121 subprocess.call(commandline)
122
123 @classmethod
124 def run_warmup(cls, warmup_time):
125 if not warmup_time:
126 return
127 print('running %i second warmup...' % warmup_time)
128 commandline = cls.ARGV + ['--duration', str(warmup_time * 1000),
129 '--config', 'gpu',
130 '--skp', 'warmup']
131 dump_commandline_if_verbose(commandline)
132 output = subprocess.check_output(commandline).decode('utf-8')
133 # validate the warmup run output.
134 for line in output.split('\n'):
135 match = BenchResult.match(line.rstrip())
136 if match and match.bench == 'warmup':
137 return
138 raise Exception('Invalid warmup output:\n%s' % output)
115 139
116 def __init__(self, skp, config, max_stddev, best_result=None): 140 def __init__(self, skp, config, max_stddev, best_result=None):
117 self.skp = skp 141 self.skp = skp
118 self.config = config 142 self.config = config
119 self.max_stddev = max_stddev 143 self.max_stddev = max_stddev
120 self.best_result = best_result 144 self.best_result = best_result
121 self._queue = Queue() 145 self._queue = Queue()
122 self._proc = None 146 self._proc = None
123 self._monitor = None 147 self._monitor = None
124 self._hw_poll_timer = None 148 self._hw_poll_timer = None
(...skipping 11 matching lines...) Expand all
136 hardware.sanity_check() 160 hardware.sanity_check()
137 self._schedule_hardware_poll() 161 self._schedule_hardware_poll()
138 162
139 commandline = self.ARGV + ['--config', self.config, 163 commandline = self.ARGV + ['--config', self.config,
140 '--skp', self.skp, 164 '--skp', self.skp,
141 '--suppressHeader', 'true'] 165 '--suppressHeader', 'true']
142 if FLAGS.write_path: 166 if FLAGS.write_path:
143 pngfile = _path.join(FLAGS.write_path, self.config, 167 pngfile = _path.join(FLAGS.write_path, self.config,
144 _path.basename(self.skp) + '.png') 168 _path.basename(self.skp) + '.png')
145 commandline.extend(['--png', pngfile]) 169 commandline.extend(['--png', pngfile])
146 if (FLAGS.verbosity >= 4): 170 dump_commandline_if_verbose(commandline)
147 quoted = ['\'%s\'' % re.sub(r'([\\\'])', r'\\\1', x) for x in commandline]
148 print(' '.join(quoted), file=sys.stderr)
149 self._proc = subprocess.Popen(commandline, stdout=subprocess.PIPE) 171 self._proc = subprocess.Popen(commandline, stdout=subprocess.PIPE)
150 self._monitor = SubprocessMonitor(self._queue, self._proc) 172 self._monitor = SubprocessMonitor(self._queue, self._proc)
151 self._monitor.start() 173 self._monitor.start()
152 174
153 while True: 175 while True:
154 message = self._queue.get() 176 message = self._queue.get()
155 if message.message == Message.READLINE: 177 if message.message == Message.READLINE:
156 result = BenchResult.match(message.value) 178 result = BenchResult.match(message.value)
157 if result: 179 if result:
158 hardware.sanity_check() 180 hardware.sanity_check()
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 skpbench.best_result.stddev, skpbench.max_stddev, 248 skpbench.best_result.stddev, skpbench.max_stddev,
227 retry_max_stddev), 249 retry_max_stddev),
228 file=sys.stderr) 250 file=sys.stderr)
229 benches.append((skpbench.skp, skpbench.config, retry_max_stddev, 251 benches.append((skpbench.skp, skpbench.config, retry_max_stddev,
230 skpbench.best_result)) 252 skpbench.best_result))
231 253
232 except HardwareException as exception: 254 except HardwareException as exception:
233 if FLAGS.verbosity >= 5: 255 if FLAGS.verbosity >= 5:
234 hardware.print_debug_diagnostics() 256 hardware.print_debug_diagnostics()
235 skpbench.terminate() 257 skpbench.terminate()
236 naptime = max(hardware.kick_in_time, exception.sleeptime)
237 if FLAGS.verbosity >= 1: 258 if FLAGS.verbosity >= 1:
238 print("%s; taking a %i second nap..." % 259 print("%s; taking a %i second nap..." %
239 (exception.message, naptime), file=sys.stderr) 260 (exception.message, exception.sleeptime), file=sys.stderr)
240 benches.appendleft(benchargs) # retry the same bench next time. 261 benches.appendleft(benchargs) # retry the same bench next time.
241 hardware.sleep(naptime - hardware.kick_in_time) 262 hardware.sleep(exception.sleeptime)
242 time.sleep(hardware.kick_in_time) 263 SKPBench.run_warmup(hardware.warmup_time)
243 264
244 265
245 def main(): 266 def main():
246 # Delimiter is ',' or ' ', skip if nested inside parens (e.g. gpu(a=b,c=d)). 267 # Delimiter is ',' or ' ', skip if nested inside parens (e.g. gpu(a=b,c=d)).
247 DELIMITER = r'[, ](?!(?:[^(]*\([^)]*\))*[^()]*\))' 268 DELIMITER = r'[, ](?!(?:[^(]*\([^)]*\))*[^()]*\))'
248 configs = re.split(DELIMITER, FLAGS.config) 269 configs = re.split(DELIMITER, FLAGS.config)
249 skps = _path.find_skps(FLAGS.skps) 270 skps = _path.find_skps(FLAGS.skps)
250 271
251 if FLAGS.adb: 272 if FLAGS.adb:
252 adb = Adb(FLAGS.device_serial) 273 adb = Adb(FLAGS.device_serial)
253 model = adb.get_device_model() 274 model = adb.get_device_model()
254 if model == 'Pixel C': 275 if model == 'Pixel C':
255 from _hardware_pixel_c import HardwarePixelC 276 from _hardware_pixel_c import HardwarePixelC
256 hardware = HardwarePixelC(adb) 277 hardware = HardwarePixelC(adb)
257 else: 278 else:
258 from _hardware_android import HardwareAndroid 279 from _hardware_android import HardwareAndroid
259 print("WARNING: %s: don't know how to monitor this hardware; results " 280 print("WARNING: %s: don't know how to monitor this hardware; results "
260 "may be unreliable." % model, file=sys.stderr) 281 "may be unreliable." % model, file=sys.stderr)
261 hardware = HardwareAndroid(adb) 282 hardware = HardwareAndroid(adb)
262 else: 283 else:
263 hardware = Hardware() 284 hardware = Hardware()
264 285
265 with hardware: 286 with hardware:
266 if hardware.kick_in_time: 287 SKPBench.run_warmup(hardware.warmup_time)
267 print("sleeping %i seconds to allow hardware settings to kick in..." %
268 hardware.kick_in_time, file=sys.stderr)
269 time.sleep(hardware.kick_in_time)
270 run_benchmarks(configs, skps, hardware) 288 run_benchmarks(configs, skps, hardware)
271 289
272 290
273 if __name__ == '__main__': 291 if __name__ == '__main__':
274 main() 292 main()
OLDNEW
« no previous file with comments | « tools/skpbench/skpbench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698