| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import argparse | 6 import argparse |
| 7 import codecs | 7 import codecs |
| 8 import json | 8 import json |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 | 11 |
| 12 sys.path.insert(1, os.path.join(os.path.dirname(__file__), '..')) | 12 sys.path.insert(1, os.path.join(os.path.dirname(__file__), '..')) |
| 13 from tracing import results_renderer | 13 from tracing import results_renderer |
| 14 from tracing.metrics import metric_runner | 14 from tracing.metrics import metric_runner |
| 15 from tracing.metrics import discover | 15 from tracing.metrics import discover |
| 16 | 16 |
| 17 def Main(argv): | 17 def Main(argv): |
| 18 all_metrics = discover.DiscoverMetrics( | 18 all_metrics = discover.DiscoverMetrics( |
| 19 ['/tracing/metrics/all_metrics.html']) | 19 ['/tracing/metrics/all_metrics.html']) |
| 20 parser = argparse.ArgumentParser( | 20 parser = argparse.ArgumentParser( |
| 21 description='Runs metrics on local traces') | 21 description='Runs metrics on local traces') |
| 22 parser.add_argument('trace_file_or_dir', | 22 parser.add_argument('trace_file_or_dir', |
| 23 help='A trace file, or a dir containing trace files') | 23 help='A trace file, or a dir containing trace files') |
| 24 <<<<<<< HEAD | |
| 25 parser.add_argument('metrics', nargs='+', | 24 parser.add_argument('metrics', nargs='+', |
| 26 ======= | |
| 27 parser.add_argument('metrics', nargs=argparse.REMAINDER, | |
| 28 >>>>>>> d779e0a... [polymer] Merge of master into polymer10-migration | |
| 29 help=('Function names of registered metrics ' | 25 help=('Function names of registered metrics ' |
| 30 '(not filenames.) ' | 26 '(not filenames.) ' |
| 31 'Available metrics are: %s' % | 27 'Available metrics are: %s' % |
| 32 ', '.join(all_metrics)), | 28 ', '.join(all_metrics)), |
| 33 choices=all_metrics, metavar='metricName') | 29 choices=all_metrics, metavar='metricName') |
| 34 <<<<<<< HEAD | |
| 35 parser.add_argument('--filename', default='results', type=str, | 30 parser.add_argument('--filename', default='results', type=str, |
| 36 help='Output file name (no extension)') | 31 help='Output file name (no extension)') |
| 37 parser.add_argument('--reset', action='store_true', | 32 parser.add_argument('--reset', action='store_true', |
| 38 help=('Whether to ignore existing results in HTML file ' | 33 help=('Whether to ignore existing results in HTML file ' |
| 39 '(if it exists')) | 34 '(if it exists')) |
| 40 parser.add_argument('--also-output-json', action='store_true', | 35 parser.add_argument('--also-output-json', action='store_true', |
| 41 help=('Also output json file containing values. Note that' | 36 help=('Also output json file containing values. Note that' |
| 42 'this only contains the results of current run')) | 37 'this only contains the results of current run')) |
| 43 ======= | |
| 44 >>>>>>> d779e0a... [polymer] Merge of master into polymer10-migration | |
| 45 | 38 |
| 46 args = parser.parse_args(argv[1:]) | 39 args = parser.parse_args(argv[1:]) |
| 47 trace_file_or_dir = os.path.abspath(args.trace_file_or_dir) | 40 trace_file_or_dir = os.path.abspath(args.trace_file_or_dir) |
| 48 | 41 |
| 49 if os.path.isdir(trace_file_or_dir): | 42 if os.path.isdir(trace_file_or_dir): |
| 50 trace_dir = trace_file_or_dir | 43 trace_dir = trace_file_or_dir |
| 51 traces = [os.path.join(trace_dir, trace) for trace in os.listdir(trace_dir)] | 44 traces = [os.path.join(trace_dir, trace) for trace in os.listdir(trace_dir)] |
| 52 else: | 45 else: |
| 53 traces = [trace_file_or_dir] | 46 traces = [trace_file_or_dir] |
| 54 | 47 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 71 | 64 |
| 72 if args.also_output_json: | 65 if args.also_output_json: |
| 73 output_file = args.filename + '.json' | 66 output_file = args.filename + '.json' |
| 74 with open(output_file, 'w') as f: | 67 with open(output_file, 'w') as f: |
| 75 json.dump(values, f, indent=2, sort_keys=True, separators=(',', ': ')) | 68 json.dump(values, f, indent=2, sort_keys=True, separators=(',', ': ')) |
| 76 print 'JSON result created in file://' + os.path.abspath(output_file) | 69 print 'JSON result created in file://' + os.path.abspath(output_file) |
| 77 | 70 |
| 78 | 71 |
| 79 if __name__ == '__main__': | 72 if __name__ == '__main__': |
| 80 sys.exit(Main(sys.argv)) | 73 sys.exit(Main(sys.argv)) |
| OLD | NEW |