Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 import json | 2 # |
| 3 import optparse | 3 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 import os | 4 # |
| 5 # Redistribution and use in source and binary forms, with or without | |
| 6 # modification, are permitted provided that the following conditions are | |
| 7 # met: | |
| 8 # | |
| 9 # * Redistributions of source code must retain the above copyright | |
| 10 # notice, this list of conditions and the following disclaimer. | |
| 11 # * Redistributions in binary form must reproduce the above | |
| 12 # copyright notice, this list of conditions and the following disclaimer | |
| 13 # in the documentation and/or other materials provided with the | |
| 14 # distribution. | |
| 15 # * Neither the name of Google Inc. nor the names of its | |
| 16 # contributors may be used to endorse or promote products derived from | |
| 17 # this software without specific prior written permission. | |
| 18 # | |
| 19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
|
Dirk Pranke
2013/09/19 23:50:56
The files didn't have proper copyright disclaimers
| |
| 30 | |
| 5 import sys | 31 import sys |
| 6 | 32 |
| 7 from webkitpy.common.host import Host | 33 from webkitpy.common import host |
| 34 from webkitpy.layout_tests import print_layout_test_times | |
| 8 | 35 |
| 9 ALL_TEST_TYPES = ['text', 'harness', 'pixel', 'ref', 'unknown'] | 36 print_layout_test_times.main(host.Host(), sys.argv[1:]) |
| 10 | |
| 11 def main(argv): | |
| 12 parser = optparse.OptionParser(usage='%prog [times_ms.json]') | |
| 13 parser.add_option('-f', '--forward', action='store', type='int', | |
| 14 help='group times by first N directories of test') | |
| 15 parser.add_option('-b', '--backward', action='store', type='int', | |
| 16 help='group times by last N directories of test') | |
| 17 parser.add_option('--fastest', action='store', type='float', | |
| 18 help='print a list of tests that will take N % of the time ') | |
| 19 parser.add_option('--type', action='append', default=[], | |
| 20 help='type of tests to filter for (%s)' % ALL_TEST_TYPES) | |
| 21 | |
| 22 epilog = """ | |
| 23 You can print out aggregate times per directory using the -f and -b | |
| 24 flags. The value passed to each flag indicates the "depth" of the flag, | |
| 25 similar to positive and negative arguments to python arrays. | |
| 26 | |
| 27 For example, given fast/forms/week/week-input-type.html, -f 1 | |
| 28 truncates to 'fast', -f 2 and -b 2 truncates to 'fast/forms', and -b 1 | |
| 29 truncates to fast/forms/week . -f 0 truncates to '', which can be used | |
| 30 to produce a single total time for the run.""" | |
| 31 parser.epilog = '\n'.join(s.lstrip() for s in epilog.splitlines()) | |
| 32 | |
| 33 options, args = parser.parse_args(argv) | |
| 34 options.type = options.type or ALL_TEST_TYPES | |
| 35 | |
| 36 host = Host() | |
| 37 port = host.port_factory.get() | |
| 38 if args and args[0]: | |
| 39 times_ms_path = args[0] | |
| 40 else: | |
| 41 times_ms_path = host.filesystem.join(port.results_directory(), 'times_ms .json') | |
| 42 | |
| 43 with open(times_ms_path, 'r') as fp: | |
| 44 times_trie = json.load(fp) | |
| 45 | |
| 46 times = convert_trie_to_flat_paths(times_trie) | |
| 47 | |
| 48 if options.fastest: | |
| 49 print_fastest(port, options, times) | |
| 50 else: | |
| 51 print_times(options, times) | |
| 52 | |
| 53 | |
| 54 def print_times(options, times): | |
| 55 by_key = times_by_key(times, options.forward, options.backward) | |
| 56 for key in sorted(by_key): | |
| 57 print "%s %d" % (key, by_key[key]) | |
| 58 | |
| 59 | |
| 60 def print_fastest(port, options, times): | |
| 61 total = times_by_key(times, 0, None)[''] | |
| 62 by_key = times_by_key(times, options.forward, options.backward) | |
| 63 keys_by_time = sorted(by_key, key=lambda k: by_key[k]) | |
| 64 | |
| 65 tests_by_key = {} | |
| 66 for test_name in times: | |
| 67 key = key_for(test_name, options.forward, options.backward) | |
| 68 if key in tests_by_key: | |
| 69 tests_by_key[key].append(test_name) | |
| 70 else: | |
| 71 tests_by_key[key] = [test_name] | |
| 72 | |
| 73 fast_tests_by_key = {} | |
| 74 total_so_far = 0 | |
| 75 per_key = total * options.fastest / (len(keys_by_time) * 100.0) | |
| 76 budget = 0 | |
| 77 while keys_by_time: | |
| 78 budget += per_key | |
| 79 key = keys_by_time.pop(0) | |
| 80 tests_by_time = sorted(tests_by_key[key], key=lambda t: times[t]) | |
| 81 fast_tests_by_key[key] = [] | |
| 82 while tests_by_time and total_so_far < budget: | |
| 83 test = tests_by_time.pop(0) | |
| 84 if options.type != ALL_TEST_TYPES and test_type(port, test) not in o ptions.type: | |
| 85 continue | |
| 86 test_time = times[test] | |
| 87 if test_time and total_so_far + test_time < budget: # This test is a n optimization to not include tests that are Skipped. | |
| 88 fast_tests_by_key[key].append(test) | |
| 89 total_so_far += test_time | |
| 90 | |
| 91 for k in sorted(fast_tests_by_key): | |
| 92 for t in fast_tests_by_key[k]: | |
| 93 print "%s %d" % (t, times[t]) | |
| 94 return | |
| 95 | |
| 96 | |
| 97 def test_type(port, test_name): | |
| 98 fs = port.host.filesystem | |
| 99 if fs.exists(port.expected_filename(test_name, '.png')): | |
| 100 return 'pixel' | |
| 101 if port.reference_files(test_name): | |
| 102 return 'ref' | |
| 103 txt = port.expected_text(test_name) | |
| 104 if txt: | |
| 105 if 'layer at (0,0) size 800x600' in txt: | |
| 106 return 'pixel' | |
| 107 for line in txt.splitlines(): | |
| 108 if line.startswith('FAIL') or line.startswith('TIMEOUT') or line.sta rtswith('PASS'): | |
| 109 return 'harness' | |
| 110 return 'text' | |
| 111 return 'unknown' | |
| 112 | |
| 113 | |
| 114 def key_for(path, forward, backward): | |
| 115 if forward is not None: | |
| 116 return os.sep.join(path.split(os.sep)[:-1][:forward]) | |
| 117 if backward is not None: | |
| 118 return os.sep.join(path.split(os.sep)[:-backward]) | |
| 119 return path | |
| 120 | |
| 121 | |
| 122 def times_by_key(times, forward, backward): | |
| 123 by_key = {} | |
| 124 for test_name in times: | |
| 125 key = key_for(test_name, forward, backward) | |
| 126 if key in by_key: | |
| 127 by_key[key] += times[test_name] | |
| 128 else: | |
| 129 by_key[key] = times[test_name] | |
| 130 return by_key | |
| 131 | |
| 132 | |
| 133 | |
| 134 def convert_trie_to_flat_paths(trie, prefix=None): | |
| 135 # Cloned from webkitpy.layout_tests.layout_package.json_results_generator | |
| 136 # so that this code can stand alone. | |
| 137 result = {} | |
| 138 for name, data in trie.iteritems(): | |
| 139 if prefix: | |
| 140 name = prefix + "/" + name | |
| 141 if isinstance(data, int): | |
| 142 result[name] = data | |
| 143 else: | |
| 144 result.update(convert_trie_to_flat_paths(data, name)) | |
| 145 | |
| 146 return result | |
| 147 | |
| 148 | |
| 149 if __name__ == '__main__': | |
| 150 sys.exit(main(sys.argv[1:])) | |
| OLD | NEW |