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

Side by Side Diff: tracing/bin/run_metric

Issue 2110683010: Allow benchmarks to specify running multiple metrics. (Closed) Base URL: git@github.com:catapult-project/catapult@master
Patch Set: code review changes 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
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', 20 parser.add_argument('metric', action='append', dest='metric_names',
21 help=('The function name of a registered metric, NOT ' 21 default=[],
22 'filename. Available metrics are: %s' % 22 help=('Comma separated list of function names '
23 'of registered metrics (not filenames.) '
petrcermak 2016/07/06 08:19:47 nit: Lines 23-25 should be vertically aligned with
24 'Available metrics are: %s' %
23 ', '.join(all_metrics)), 25 ', '.join(all_metrics)),
24 choices=all_metrics, metavar='metricName') 26 choices=all_metrics, metavar='metricName')
25 parser.add_argument('trace_file_or_dir', 27 parser.add_argument('trace_file_or_dir',
26 help='A trace file, or a dir containing trace files') 28 help='A trace file, or a dir containing trace files')
27 29
28 args = parser.parse_args(argv[1:]) 30 args = parser.parse_args(argv[1:])
29 metric = args.metric_name 31 metrics = args.metric_names.split(',')
30 32
31 if os.path.isdir(args.trace_file_or_dir): 33 if os.path.isdir(args.trace_file_or_dir):
32 trace_dir = args.trace_file_or_dir 34 trace_dir = args.trace_file_or_dir
33 traces = [os.path.join(trace_dir, trace) for trace in os.listdir(trace_dir)] 35 traces = [os.path.join(trace_dir, trace) for trace in os.listdir(trace_dir)]
34 else: 36 else:
35 traces = [args.trace_file_or_dir] 37 traces = [args.trace_file_or_dir]
36 38
37 results = {k: v.AsDict() 39 results = {k: v.AsDict()
38 for k, v in metric_runner.RunMetricOnTraces(traces, metric).iteritems()} 40 for k, v in metric_runner.RunMetricOnTraces(traces, metrics).iteritems()}
petrcermak 2016/07/06 08:19:47 nit: I think that "for" should be vertically align
39 41
40 failures = [] 42 failures = []
41 for trace in traces: 43 for trace in traces:
42 failures.extend(results[trace].get('failures', [])) 44 failures.extend(results[trace].get('failures', []))
43 if failures: 45 if failures:
44 print 'Running metric failed:' 46 print 'Running metric failed:'
45 for failure in failures: 47 for failure in failures:
46 print failure['stack'] 48 print failure['stack']
47 else: 49 else:
48 print json.dumps(results, indent=2, sort_keys=True, separators=(',', ': ')) 50 print json.dumps(results, indent=2, sort_keys=True, separators=(',', ': '))
49 51
50 52
51 if __name__ == '__main__': 53 if __name__ == '__main__':
52 sys.exit(Main(sys.argv)) 54 sys.exit(Main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698