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

Unified Diff: Tools/Scripts/webkitpy/layout_tests/print_layout_test_times.py

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
Index: Tools/Scripts/webkitpy/layout_tests/print_layout_test_times.py
diff --git a/Tools/Scripts/print-layout-test-times b/Tools/Scripts/webkitpy/layout_tests/print_layout_test_times.py
old mode 100755
new mode 100644
similarity index 54%
copy from Tools/Scripts/print-layout-test-times
copy to Tools/Scripts/webkitpy/layout_tests/print_layout_test_times.py
index 6b05d355183e9b474781ac6e8535ea3e8ca7116c..15bc1f00e330810515c8ce20cd2a1849fd5c65ad
--- a/Tools/Scripts/print-layout-test-times
+++ b/Tools/Scripts/webkitpy/layout_tests/print_layout_test_times.py
@@ -1,14 +1,38 @@
-#!/usr/bin/python
+# 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.
+
import json
import optparse
-import os
-import sys
-from webkitpy.common.host import Host
+from webkitpy.layout_tests.port import Port
-ALL_TEST_TYPES = ['text', 'harness', 'pixel', 'ref', 'unknown']
-def main(argv):
+def main(host, 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')
@@ -16,8 +40,6 @@ def main(argv):
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
@@ -31,41 +53,43 @@ def main(argv):
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_trie = json.loads(host.filesystem.read_text_file(times_ms_path))
times = convert_trie_to_flat_paths(times_trie)
if options.fastest:
- print_fastest(port, options, times)
+ if options.forward is None and options.backward is None:
+ options.forward = 0
+ print_fastest(host, port, options, times)
else:
- print_times(options, times)
+ print_times(host, options, times)
-def print_times(options, times):
+def print_times(host, 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])
+ if key:
+ host.print_("%s %d" % (key, by_key[key]))
+ else:
+ host.print_("%d" % by_key[key])
-def print_fastest(port, options, times):
+def print_fastest(host, 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])
+ keys_by_time = sorted(by_key, key=lambda k: (by_key[k], k))
tests_by_key = {}
- for test_name in times:
+ for test_name in sorted(times):
key = key_for(test_name, options.forward, options.backward)
- if key in tests_by_key:
+ if key in sorted(tests_by_key):
tests_by_key[key].append(test_name)
else:
tests_by_key[key] = [test_name]
@@ -77,45 +101,28 @@ def print_fastest(port, options, times):
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])
+ tests_by_time = sorted(tests_by_key[key], key=lambda t: (times[t], t))
fast_tests_by_key[key] = []
- while tests_by_time and total_so_far < budget:
+ 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.
+ # Make sure test time > 0 so we don't include tests that are skipped.
+ if test_time and total_so_far + test_time <= budget:
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])
+ host.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):
+ sep = Port.TEST_PATH_SEPARATOR
if forward is not None:
- return os.sep.join(path.split(os.sep)[:-1][:forward])
+ return sep.join(path.split(sep)[:-1][:forward])
if backward is not None:
- return os.sep.join(path.split(os.sep)[:-backward])
+ return sep.join(path.split(sep)[:-backward])
return path
@@ -130,10 +137,7 @@ def times_by_key(times, forward, backward):
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:
@@ -144,7 +148,3 @@ def convert_trie_to_flat_paths(trie, prefix=None):
result.update(convert_trie_to_flat_paths(data, name))
return result
-
-
-if __name__ == '__main__':
- sys.exit(main(sys.argv[1:]))

Powered by Google App Engine
This is Rietveld 408576698