1#!/usr/bin/env python 2 3import codecs, httplib, json, os, urllib, shutil, subprocess, sys, argparse 4 5upstream_git = 'https://github.com/catapult-project/catapult.git' 6 7script_dir = os.path.dirname(os.path.abspath(sys.argv[0])) 8catapult_src_dir = os.path.join(script_dir, 'catapult-upstream') 9 10parser = argparse.ArgumentParser() 11parser.add_argument('trace_file_or_dir', 12 help='Path to trace file or directory of trace files.') 13parser.add_argument('--output_file', dest='outfile', default=os.path.join(os.getcwd(), 'mapper_output.json'), 14 help='Path to output file to store results.') 15parser.add_argument('--mapper_func', dest='func', default='AvgDrawFrame', 16 help='Name of javascript mapper function in systrace_parser.html.') 17args = parser.parse_args() 18 19# Update the source if needed. 20if not os.path.exists(catapult_src_dir): 21 # Pull the latest source from the upstream git. 22 git_args = ['git', 'clone', upstream_git, catapult_src_dir] 23 p = subprocess.Popen(git_args, stdout=subprocess.PIPE, cwd=script_dir) 24 p.communicate() 25 if p.wait() != 0: 26 print 'Failed to checkout source from upstream git.' 27 sys.exit(1) 28 29mapper_func_file = os.path.join(script_dir, 'systrace_parser.html') 30path_to_process_traces = os.path.join(catapult_src_dir, 'trace_processor/bin/process_traces') 31run_command = path_to_process_traces + " --mapper_handle " + mapper_func_file + ":" + args.func + " --output_file " + args.outfile + " " + args.trace_file_or_dir 32print run_command 33sys.exit(os.system(run_command)) 34 35