From 4e96b1de65143bac77420ed8610b5df8a7237cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Hajdan=2C=20Jr?= Date: Mon, 16 Nov 2015 16:16:11 +0100 Subject: sizes.py: implement individual failures, at least for Linux BUG=553425 R=akuegel@chromium.org Review URL: https://codereview.chromium.org/1428833006 . Cr-Commit-Position: refs/heads/master@{#359839} --- .../scripts/legacy/scripts/slave/chromium/sizes.py | 48 +++++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'infra') diff --git a/infra/scripts/legacy/scripts/slave/chromium/sizes.py b/infra/scripts/legacy/scripts/slave/chromium/sizes.py index 9875826..77331d1 100755 --- a/infra/scripts/legacy/scripts/slave/chromium/sizes.py +++ b/infra/scripts/legacy/scripts/slave/chromium/sizes.py @@ -12,6 +12,7 @@ """ import errno +import json import platform import optparse import os @@ -28,6 +29,22 @@ SRC_DIR = os.path.abspath( os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..', '..')) +class ResultsCollector(object): + def __init__(self): + self.results = {} + + def add_result(self, name, identifier, value, units): + assert name not in self.results + self.results[name] = { + 'identifier': identifier, + 'value': int(value), + 'units': units + } + + # Legacy printing, previously used for parsing the text logs. + print 'RESULT %s: %s= %s %s' % (name, identifier, value, units) + + def get_size(filename): return os.stat(filename)[stat.ST_SIZE] @@ -67,7 +84,7 @@ def print_si_fail_hint(path_to_tool): print '# HINT: diff against the log from the last run to see what changed' -def main_mac(options, args): +def main_mac(options, args, results_collector): """Print appropriate size information about built Mac targets. Returns the first non-zero exit status of any command it executes, @@ -271,7 +288,7 @@ def check_linux_binary(target_dir, binary_name, options): return result, sizes -def main_linux(options, args): +def main_linux(options, args, results_collector): """Print appropriate size information about built Linux targets. Returns the first non-zero exit status of any command it executes, @@ -298,7 +315,7 @@ def main_linux(options, args): if result == 0: result = this_result for name, identifier, totals_id, value, units in this_sizes: - print 'RESULT %s: %s= %s %s' % (name, identifier, value, units) + results_collector.add_result(name, identifier, value, units) totals_id = totals_id or identifier, units totals[totals_id] = totals.get(totals_id, 0) + int(value) @@ -315,15 +332,15 @@ def main_linux(options, args): if e.errno == errno.ENOENT: continue # Don't print anything for missing files. raise - print 'RESULT %s: %s= %s bytes' % (filename, filename, size) + results_collector.add_result(filename, filename, size, 'bytes') totals['size', 'bytes'] += size # TODO(mcgrathr): This should all be refactored so the mac and win flavors # also deliver data structures rather than printing, and the logic for # the printing and the summing totals is shared across all three flavors. for (identifier, units), value in sorted(totals.iteritems()): - print 'RESULT totals-%s: %s= %s %s' % (identifier, identifier, - value, units) + results_collector.add_result( + 'totals-%s' % identifier, identifier, value, units) return result @@ -344,7 +361,7 @@ def check_android_binaries(binaries, target_dir, options): return result -def main_android(options, args): +def main_android(options, args, results_collector): """Print appropriate size information about built Android targets. Returns the first non-zero exit status of any command it executes, @@ -361,7 +378,7 @@ def main_android(options, args): return check_android_binaries(binaries, target_dir, options) -def main_android_webview(options, args): +def main_android_webview(options, args, results_collector): """Print appropriate size information about Android WebViewChromium targets. Returns the first non-zero exit status of any command it executes, @@ -375,7 +392,7 @@ def main_android_webview(options, args): return check_android_binaries(binaries, target_dir, options) -def main_android_cronet(options, args): +def main_android_cronet(options, args, results_collector): """Print appropriate size information about Android Cronet targets. Returns the first non-zero exit status of any command it executes, @@ -394,7 +411,7 @@ def main_android_cronet(options, args): return check_android_binaries(binaries, target_dir, options) -def main_win(options, args): +def main_win(options, args, results_collector): """Print appropriate size information about built Windows targets. Returns the first non-zero exit status of any command it executes, @@ -459,6 +476,7 @@ def main(): default=default_platform, help='specify platform (%s) [default: %%default]' % ', '.join(platforms)) + option_parser.add_option('--json', help='Path to JSON output file') options, args = option_parser.parse_args() @@ -471,7 +489,15 @@ def main(): msg = 'Use the --platform= option to specify a supported platform:\n' sys.stderr.write(msg + ' ' + ' '.join(platforms) + '\n') return 2 - return real_main(options, args) + + results_collector = ResultsCollector() + rc = real_main(options, args, results_collector) + + if options.json: + with open(options.json, 'w') as f: + json.dump(results_collector.results, f) + + return rc if '__main__' == __name__: -- cgit v1.1