1#!/usr/bin/env python 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 4# found in the LICENSE file. 5 6import argparse 7import json 8import os 9import sys 10 11sys.path.insert(1, os.path.join(os.path.dirname(__file__), '..')) 12from tracing.metrics import metric_runner 13 14def Main(argv): 15 parser = argparse.ArgumentParser( 16 description='Runs metrics on local traces') 17 parser.add_argument('metric', 18 help='A metric from tracing/metrics/') 19 parser.add_argument('trace_file_or_dir', 20 help='A trace file, or a dir containing trace files') 21 22 args = parser.parse_args(argv[1:]) 23 metric = args.metric 24 25 if os.path.isdir(args.trace_file_or_dir): 26 trace_dir = args.trace_file_or_dir 27 traces = [os.path.join(trace_dir, trace) for trace in os.listdir(trace_dir)] 28 else: 29 traces = [args.trace_file_or_dir] 30 31 results = {} 32 for trace in traces: 33 results[trace] = metric_runner.RunMetric(trace, metric).AsDict() 34 35 print json.dumps(results, indent=2, sort_keys=True, separators=(',', ': ')) 36 37 38if __name__ == '__main__': 39 sys.exit(Main(sys.argv)) 40