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

Side by Side Diff: Tools/Scripts/webkitpy/layout_tests/print_layout_test_times.py

Issue 546133003: Reformat webkitpy.layout_tests w/ format-webkitpy. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 19 matching lines...) Expand all
30 import optparse 30 import optparse
31 31
32 from webkitpy.layout_tests.port import Port 32 from webkitpy.layout_tests.port import Port
33 33
34 34
35 def main(host, argv): 35 def main(host, argv):
36 parser = optparse.OptionParser(usage='%prog [times_ms.json]') 36 parser = optparse.OptionParser(usage='%prog [times_ms.json]')
37 parser.add_option('-f', '--forward', action='store', type='int', 37 parser.add_option('-f', '--forward', action='store', type='int',
38 help='group times by first N directories of test') 38 help='group times by first N directories of test')
39 parser.add_option('-b', '--backward', action='store', type='int', 39 parser.add_option('-b', '--backward', action='store', type='int',
40 help='group times by last N directories of test') 40 help='group times by last N directories of test')
41 parser.add_option('--fastest', action='store', type='float', 41 parser.add_option('--fastest', action='store', type='float',
42 help='print a list of tests that will take N % of the time ') 42 help='print a list of tests that will take N % of the time ')
43 43
44 epilog = """ 44 epilog = """
45 You can print out aggregate times per directory using the -f and -b 45 You can print out aggregate times per directory using the -f and -b
46 flags. The value passed to each flag indicates the "depth" of the flag, 46 flags. The value passed to each flag indicates the "depth" of the flag,
47 similar to positive and negative arguments to python arrays. 47 similar to positive and negative arguments to python arrays.
48 48
49 For example, given fast/forms/week/week-input-type.html, -f 1 49 For example, given fast/forms/week/week-input-type.html, -f 1
50 truncates to 'fast', -f 2 and -b 2 truncates to 'fast/forms', and -b 1 50 truncates to 'fast', -f 2 and -b 2 truncates to 'fast/forms', and -b 1
(...skipping 18 matching lines...) Expand all
69 options.forward = 0 69 options.forward = 0
70 print_fastest(host, port, options, times) 70 print_fastest(host, port, options, times)
71 else: 71 else:
72 print_times(host, options, times) 72 print_times(host, options, times)
73 73
74 74
75 def print_times(host, options, times): 75 def print_times(host, options, times):
76 by_key = times_by_key(times, options.forward, options.backward) 76 by_key = times_by_key(times, options.forward, options.backward)
77 for key in sorted(by_key): 77 for key in sorted(by_key):
78 if key: 78 if key:
79 host.print_("%s %d" % (key, by_key[key])) 79 host.print_('%s %d' % (key, by_key[key]))
80 else: 80 else:
81 host.print_("%d" % by_key[key]) 81 host.print_('%d' % by_key[key])
82 82
83 83
84 def print_fastest(host, port, options, times): 84 def print_fastest(host, port, options, times):
85 total = times_by_key(times, 0, None)[''] 85 total = times_by_key(times, 0, None)['']
86 by_key = times_by_key(times, options.forward, options.backward) 86 by_key = times_by_key(times, options.forward, options.backward)
87 keys_by_time = sorted(by_key, key=lambda k: (by_key[k], k)) 87 keys_by_time = sorted(by_key, key=lambda k: (by_key[k], k))
88 88
89 tests_by_key = {} 89 tests_by_key = {}
90 for test_name in sorted(times): 90 for test_name in sorted(times):
91 key = key_for(test_name, options.forward, options.backward) 91 key = key_for(test_name, options.forward, options.backward)
92 if key in sorted(tests_by_key): 92 if key in sorted(tests_by_key):
93 tests_by_key[key].append(test_name) 93 tests_by_key[key].append(test_name)
94 else: 94 else:
95 tests_by_key[key] = [test_name] 95 tests_by_key[key] = [test_name]
96 96
97 fast_tests_by_key = {} 97 fast_tests_by_key = {}
98 total_so_far = 0 98 total_so_far = 0
99 per_key = total * options.fastest / (len(keys_by_time) * 100.0) 99 per_key = total * options.fastest / (len(keys_by_time) * 100.0)
100 budget = 0 100 budget = 0
101 while keys_by_time: 101 while keys_by_time:
102 budget += per_key 102 budget += per_key
103 key = keys_by_time.pop(0) 103 key = keys_by_time.pop(0)
104 tests_by_time = sorted(tests_by_key[key], key=lambda t: (times[t], t)) 104 tests_by_time = sorted(tests_by_key[key], key=lambda t: (times[t], t))
105 fast_tests_by_key[key] = [] 105 fast_tests_by_key[key] = []
106 while tests_by_time and total_so_far <= budget: 106 while tests_by_time and total_so_far <= budget:
107 test = tests_by_time.pop(0) 107 test = tests_by_time.pop(0)
108 test_time = times[test] 108 test_time = times[test]
109 # Make sure test time > 0 so we don't include tests that are skippe d. 109 # Make sure test time > 0 so we don't include tests that are skipped .
110 if test_time and total_so_far + test_time <= budget: 110 if test_time and total_so_far + test_time <= budget:
111 fast_tests_by_key[key].append(test) 111 fast_tests_by_key[key].append(test)
112 total_so_far += test_time 112 total_so_far += test_time
113 113
114 for k in sorted(fast_tests_by_key): 114 for k in sorted(fast_tests_by_key):
115 for t in fast_tests_by_key[k]: 115 for t in fast_tests_by_key[k]:
116 host.print_("%s %d" % (t, times[t])) 116 host.print_('%s %d' % (t, times[t]))
117 return 117 return
118 118
119 119
120 def key_for(path, forward, backward): 120 def key_for(path, forward, backward):
121 sep = Port.TEST_PATH_SEPARATOR 121 sep = Port.TEST_PATH_SEPARATOR
122 if forward is not None: 122 if forward is not None:
123 return sep.join(path.split(sep)[:-1][:forward]) 123 return sep.join(path.split(sep)[:-1][:forward])
124 if backward is not None: 124 if backward is not None:
125 return sep.join(path.split(sep)[:-backward]) 125 return sep.join(path.split(sep)[:-backward])
126 return path 126 return path
127 127
128 128
129 def times_by_key(times, forward, backward): 129 def times_by_key(times, forward, backward):
130 by_key = {} 130 by_key = {}
131 for test_name in times: 131 for test_name in times:
132 key = key_for(test_name, forward, backward) 132 key = key_for(test_name, forward, backward)
133 if key in by_key: 133 if key in by_key:
134 by_key[key] += times[test_name] 134 by_key[key] += times[test_name]
135 else: 135 else:
136 by_key[key] = times[test_name] 136 by_key[key] = times[test_name]
137 return by_key 137 return by_key
138 138
139 139
140 def convert_trie_to_flat_paths(trie, prefix=None): 140 def convert_trie_to_flat_paths(trie, prefix=None):
141 result = {} 141 result = {}
142 for name, data in trie.iteritems(): 142 for name, data in trie.iteritems():
143 if prefix: 143 if prefix:
144 name = prefix + "/" + name 144 name = prefix + '/' + name
145 if isinstance(data, int): 145 if isinstance(data, int):
146 result[name] = data 146 result[name] = data
147 else: 147 else:
148 result.update(convert_trie_to_flat_paths(data, name)) 148 result.update(convert_trie_to_flat_paths(data, name))
149 149
150 return result 150 return result
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698