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

Unified Diff: Tools/Scripts/print-layout-test-times

Issue 23672050: Refactor print-layout-test-times and add unit tests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: tweak a bit to minimize diff Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Tools/Scripts/webkitpy/common/system/systemhost.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Tools/Scripts/print-layout-test-times
diff --git a/Tools/Scripts/print-layout-test-times b/Tools/Scripts/print-layout-test-times
index 6b05d355183e9b474781ac6e8535ea3e8ca7116c..20019957724b7351a696c6c8c5830e881ed649ef 100755
--- a/Tools/Scripts/print-layout-test-times
+++ b/Tools/Scripts/print-layout-test-times
@@ -1,150 +1,36 @@
#!/usr/bin/python
-import json
-import optparse
-import os
-import sys
-
-from webkitpy.common.host import Host
-
-ALL_TEST_TYPES = ['text', 'harness', 'pixel', 'ref', 'unknown']
-
-def main(argv):
- parser = optparse.OptionParser(usage='%prog [times_ms.json]')
- parser.add_option('-f', '--forward', action='store', type='int',
- help='group times by first N directories of test')
- parser.add_option('-b', '--backward', action='store', type='int',
- help='group times by last N directories of test')
- parser.add_option('--fastest', action='store', type='float',
- help='print a list of tests that will take N % of the time')
- parser.add_option('--type', action='append', default=[],
- help='type of tests to filter for (%s)' % ALL_TEST_TYPES)
-
- epilog = """
- You can print out aggregate times per directory using the -f and -b
- flags. The value passed to each flag indicates the "depth" of the flag,
- similar to positive and negative arguments to python arrays.
-
- For example, given fast/forms/week/week-input-type.html, -f 1
- truncates to 'fast', -f 2 and -b 2 truncates to 'fast/forms', and -b 1
- truncates to fast/forms/week . -f 0 truncates to '', which can be used
- to produce a single total time for the run."""
- parser.epilog = '\n'.join(s.lstrip() for s in epilog.splitlines())
-
- options, args = parser.parse_args(argv)
- options.type = options.type or ALL_TEST_TYPES
-
- host = Host()
- port = host.port_factory.get()
- if args and args[0]:
- times_ms_path = args[0]
- else:
- times_ms_path = host.filesystem.join(port.results_directory(), 'times_ms.json')
-
- with open(times_ms_path, 'r') as fp:
- times_trie = json.load(fp)
-
- times = convert_trie_to_flat_paths(times_trie)
-
- if options.fastest:
- print_fastest(port, options, times)
- else:
- print_times(options, times)
-
-
-def print_times(options, times):
- by_key = times_by_key(times, options.forward, options.backward)
- for key in sorted(by_key):
- print "%s %d" % (key, by_key[key])
-
+#
+# Copyright (C) 2013 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-def print_fastest(port, options, times):
- total = times_by_key(times, 0, None)['']
- by_key = times_by_key(times, options.forward, options.backward)
- keys_by_time = sorted(by_key, key=lambda k: by_key[k])
-
- tests_by_key = {}
- for test_name in times:
- key = key_for(test_name, options.forward, options.backward)
- if key in tests_by_key:
- tests_by_key[key].append(test_name)
- else:
- tests_by_key[key] = [test_name]
-
- fast_tests_by_key = {}
- total_so_far = 0
- per_key = total * options.fastest / (len(keys_by_time) * 100.0)
- budget = 0
- while keys_by_time:
- budget += per_key
- key = keys_by_time.pop(0)
- tests_by_time = sorted(tests_by_key[key], key=lambda t: times[t])
- fast_tests_by_key[key] = []
- while tests_by_time and total_so_far < budget:
- test = tests_by_time.pop(0)
- if options.type != ALL_TEST_TYPES and test_type(port, test) not in options.type:
- continue
- test_time = times[test]
- if test_time and total_so_far + test_time < budget: # This test is an optimization to not include tests that are Skipped.
- fast_tests_by_key[key].append(test)
- total_so_far += test_time
-
- for k in sorted(fast_tests_by_key):
- for t in fast_tests_by_key[k]:
- print "%s %d" % (t, times[t])
- return
-
-
-def test_type(port, test_name):
- fs = port.host.filesystem
- if fs.exists(port.expected_filename(test_name, '.png')):
- return 'pixel'
- if port.reference_files(test_name):
- return 'ref'
- txt = port.expected_text(test_name)
- if txt:
- if 'layer at (0,0) size 800x600' in txt:
- return 'pixel'
- for line in txt.splitlines():
- if line.startswith('FAIL') or line.startswith('TIMEOUT') or line.startswith('PASS'):
- return 'harness'
- return 'text'
- return 'unknown'
-
-
-def key_for(path, forward, backward):
- if forward is not None:
- return os.sep.join(path.split(os.sep)[:-1][:forward])
- if backward is not None:
- return os.sep.join(path.split(os.sep)[:-backward])
- return path
-
-
-def times_by_key(times, forward, backward):
- by_key = {}
- for test_name in times:
- key = key_for(test_name, forward, backward)
- if key in by_key:
- by_key[key] += times[test_name]
- else:
- by_key[key] = times[test_name]
- return by_key
-
-
-
-def convert_trie_to_flat_paths(trie, prefix=None):
- # Cloned from webkitpy.layout_tests.layout_package.json_results_generator
- # so that this code can stand alone.
- result = {}
- for name, data in trie.iteritems():
- if prefix:
- name = prefix + "/" + name
- if isinstance(data, int):
- result[name] = data
- else:
- result.update(convert_trie_to_flat_paths(data, name))
-
- return result
+import sys
+from webkitpy.common import host
+from webkitpy.layout_tests import print_layout_test_times
-if __name__ == '__main__':
- sys.exit(main(sys.argv[1:]))
+print_layout_test_times.main(host.Host(), sys.argv[1:])
« no previous file with comments | « no previous file | Tools/Scripts/webkitpy/common/system/systemhost.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698