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

Side by Side Diff: tracing/bin/run_metric

Issue 2162963002: [polymer] Merge of master into polymer10-migration (Closed) Base URL: git@github.com:catapult-project/catapult.git@polymer10-migration
Patch Set: Merge polymer10-migration int polymer10-merge Created 4 years, 5 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
« no previous file with comments | « tracing/app.yaml ('k') | tracing/third_party/mannwhitneyu/README.chromium » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 json 7 import json
8 import os 8 import os
9 import sys 9 import sys
10 10
11 sys.path.insert(1, os.path.join(os.path.dirname(__file__), '..')) 11 sys.path.insert(1, os.path.join(os.path.dirname(__file__), '..'))
12 from tracing.metrics import metric_runner 12 from tracing.metrics import metric_runner
13 from tracing.metrics import discover 13 from tracing.metrics import discover
14 14
15 def Main(argv): 15 def Main(argv):
16 all_metrics = discover.DiscoverMetrics( 16 all_metrics = discover.DiscoverMetrics(
17 ['/tracing/metrics/all_metrics.html']) 17 ['/tracing/metrics/all_metrics.html'])
18 parser = argparse.ArgumentParser( 18 parser = argparse.ArgumentParser(
19 description='Runs metrics on local traces') 19 description='Runs metrics on local traces')
20 parser.add_argument('metric_name',
21 help=('The function name of a registered metric, NOT '
22 'filename. Available metrics are: %s' %
23 ', '.join(all_metrics)),
24 choices=all_metrics, metavar='metricName')
25 parser.add_argument('trace_file_or_dir', 20 parser.add_argument('trace_file_or_dir',
26 help='A trace file, or a dir containing trace files') 21 help='A trace file, or a dir containing trace files')
22 parser.add_argument('metrics', nargs=argparse.REMAINDER,
23 help=('Function names of registered metrics '
24 '(not filenames.) '
25 'Available metrics are: %s' %
26 ', '.join(all_metrics)),
27 choices=all_metrics, metavar='metricName')
27 28
28 args = parser.parse_args(argv[1:]) 29 args = parser.parse_args(argv[1:])
29 metric = args.metric_name 30 trace_file_or_dir = os.path.abspath(args.trace_file_or_dir)
30 31
31 if os.path.isdir(args.trace_file_or_dir): 32 if os.path.isdir(trace_file_or_dir):
32 trace_dir = args.trace_file_or_dir 33 trace_dir = trace_file_or_dir
33 traces = [os.path.join(trace_dir, trace) for trace in os.listdir(trace_dir)] 34 traces = [os.path.join(trace_dir, trace) for trace in os.listdir(trace_dir)]
34 else: 35 else:
35 traces = [args.trace_file_or_dir] 36 traces = [trace_file_or_dir]
36 37
37 results = {k: v.AsDict() 38 results = {k: v.AsDict() for k, v in
38 for k, v in metric_runner.RunMetricOnTraces(traces, metric).iteritems()} 39 metric_runner.RunMetricOnTraces(traces, args.metrics).iteritems()}
39 40
40 failures = [] 41 failures = []
41 for trace in traces: 42 for trace in traces:
42 failures.extend(results[trace].get('failures', [])) 43 failures.extend(results[trace].get('failures', []))
43 if failures: 44 if failures:
44 print 'Running metric failed:' 45 print 'Running metric failed:'
45 for failure in failures: 46 for failure in failures:
46 print failure['stack'] 47 print failure['stack']
47 else: 48 else:
48 print json.dumps(results, indent=2, sort_keys=True, separators=(',', ': ')) 49 print json.dumps(results, indent=2, sort_keys=True, separators=(',', ': '))
49 50
50 51
51 if __name__ == '__main__': 52 if __name__ == '__main__':
52 sys.exit(Main(sys.argv)) 53 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « tracing/app.yaml ('k') | tracing/third_party/mannwhitneyu/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698