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 6 import argparse 7 import sys 8 import os 9 10 tracing_path = os.path.abspath(os.path.join( 11 os.path.dirname(os.path.realpath(__file__)), '..')) 12 sys.path.append(tracing_path) 13 from tracing_build import html2trace 14 15 16 def main(): 17 parser = argparse.ArgumentParser(description='Extract trace data from an ' 18 'HTML trace.', add_help=False) 19 parser.add_argument('html_path', metavar='HTML_PATH', 20 help='HTML file path (input).') 21 parser.add_argument('trace_path', metavar='TRACE_PATH', 22 help='Trace file path (output). If the HTML file ' 23 'contains more than one trace data block, the first ' 24 'block will be extracted into %(metavar)s and the rest ' 25 'will be extracted into separate files %(metavar)s.1, ' 26 '%(metavar)s.2, etc.') 27 parser.add_argument('--gzipped_output', choices=['true', 'false', 'auto'], 28 default='auto', help='Flag whether the output trace ' 29 'file should be gzipped.') 30 parser.add_argument('-q', '--quiet', action='store_true', 31 help='Don\'t print the saved file name(s).') 32 parser.add_argument('-h', '--help', action='help', 33 help='Show this help message and exit.') 34 args = parser.parse_args() 35 36 if args.gzipped_output == 'true': 37 gzipped_output = True 38 elif args.gzipped_output == 'false': 39 gzipped_output = False 40 else: 41 gzipped_output = args.trace_path.endswith('.gz') 42 43 saved_paths = html2trace.CopyTraceDataFromHTMLFilePath( 44 args.html_path, args.trace_path, gzipped_output) 45 46 if not args.quiet: 47 print '\n'.join(saved_paths) 48 49 50 if __name__ == '__main__': 51 sys.exit(main()) 52