OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 import csv | |
6 import logging | |
7 import os | |
8 import sys | |
9 | |
10 from chrome_remote_control import browser_finder | |
11 from chrome_remote_control import browser_options | |
12 from chrome_remote_control import multi_page_benchmark | |
13 from chrome_remote_control import page_runner | |
14 from chrome_remote_control import page_set | |
15 | |
16 import perf_tools.first_paint_time_benchmark | |
17 import perf_tools.scrolling_benchmark | |
18 import perf_tools.skpicture_printer | |
19 import perf_tools.texture_upload_benchmark | |
20 | |
21 # TODO(tonyg/nduca): Discover benchmarks automagically. | |
22 _BENCHMARKS = { | |
23 'first_paint_time_benchmark': | |
24 perf_tools.first_paint_time_benchmark.FirstPaintTimeBenchmark, | |
25 'scrolling_benchmark': | |
26 perf_tools.scrolling_benchmark.ScrollingBenchmark, | |
27 'skpicture_printer': | |
28 perf_tools.skpicture_printer.SkPicturePrinter, | |
29 'texture_upload_benchmark': | |
30 perf_tools.texture_upload_benchmark.TextureUploadBenchmark | |
31 } | |
32 | |
33 | |
34 def Main(): | |
35 """Turns a MultiPageBenchmark into a command-line program. | |
36 | |
37 If args is not specified, sys.argv[1:] is used. | |
38 """ | |
39 options = browser_options.BrowserOptions() | |
40 parser = options.CreateParser('%prog [options] <benchmark> <page_set>') | |
41 _, args = parser.parse_args() | |
42 | |
43 if len(args) != 2 or args[0] not in _BENCHMARKS: | |
44 parser.print_usage() | |
45 import page_sets # pylint: disable=F0401 | |
46 sys.stderr.write('Available benchmarks:\n%s\n\n' % ',\n'.join( | |
dtu
2012/10/16 23:53:44
print >> sys.stderr, 'Available bench...'
tonyg
2012/10/17 00:13:44
Done.
| |
47 _BENCHMARKS.keys())) | |
48 sys.stderr.write('Available page_sets:\n%s\n\n' % ',\n'.join( | |
49 [os.path.relpath(f) for f in page_sets.GetAllPageSetFilenames()])) | |
50 sys.exit(1) | |
51 | |
52 benchmark = _BENCHMARKS[args[0]]() | |
53 ps = page_set.PageSet.FromFile(args[1]) | |
54 | |
55 benchmark.AddOptions(parser) | |
56 _, args = parser.parse_args() | |
57 | |
58 benchmark.CustomizeBrowserOptions(options) | |
59 possible_browser = browser_finder.FindBrowser(options) | |
60 if possible_browser == None: | |
dtu
2012/10/16 23:53:44
if not possible_browser:
tonyg
2012/10/17 00:13:44
Done.
| |
61 sys.stderr.write( | |
62 'No browser found.\n' + | |
63 'Use --browser=list to figure out which are available.\n') | |
64 sys.exit(1) | |
65 | |
66 results = multi_page_benchmark.CsvBenchmarkResults(csv.writer(sys.stdout)) | |
67 with page_runner.PageRunner(ps) as runner: | |
68 runner.Run(options, possible_browser, benchmark, results) | |
69 # When using an exact executable, assume it is a reference build for the | |
70 # purpose of outputting the perf results. | |
dtu
2012/10/16 23:53:44
Not sure about the validity of this assumption. Wh
tonyg
2012/10/17 00:13:44
It just changes the string that is printed in the
| |
71 results.PrintSummary(options.browser_executable and '_ref' or '') | |
72 | |
73 if len(results.page_failures): | |
74 logging.warning('Failed pages: %s', '\n'.join( | |
75 [failure['page'].url for failure in results.page_failures])) | |
76 return max(255, len(results.page_failures)) | |
OLD | NEW |