1*288bf522SAndroid Build Coastguard Worker#!/usr/bin/env python 2*288bf522SAndroid Build Coastguard Worker# 3*288bf522SAndroid Build Coastguard Worker# Copyright (C) 2015 The Android Open Source Project 4*288bf522SAndroid Build Coastguard Worker# 5*288bf522SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*288bf522SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*288bf522SAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*288bf522SAndroid Build Coastguard Worker# 9*288bf522SAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*288bf522SAndroid Build Coastguard Worker# 11*288bf522SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*288bf522SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*288bf522SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*288bf522SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*288bf522SAndroid Build Coastguard Worker# limitations under the License. 16*288bf522SAndroid Build Coastguard Worker# 17*288bf522SAndroid Build Coastguard Worker 18*288bf522SAndroid Build Coastguard Workerimport argparse 19*288bf522SAndroid Build Coastguard Workerimport os 20*288bf522SAndroid Build Coastguard Workerimport subprocess 21*288bf522SAndroid Build Coastguard Workerimport sys 22*288bf522SAndroid Build Coastguard Worker 23*288bf522SAndroid Build Coastguard Workerdef main(): 24*288bf522SAndroid Build Coastguard Worker # Create argument parser 25*288bf522SAndroid Build Coastguard Worker parser = argparse.ArgumentParser() 26*288bf522SAndroid Build Coastguard Worker parser.add_argument('systrace_file', metavar='SYSTRACE_FILE', help='systrace file to analyze') 27*288bf522SAndroid Build Coastguard Worker parser.add_argument('-e', metavar='EVENT_LOG', help='android event log file') 28*288bf522SAndroid Build Coastguard Worker args = parser.parse_args() 29*288bf522SAndroid Build Coastguard Worker 30*288bf522SAndroid Build Coastguard Worker this_script_path = os.path.dirname(os.path.realpath(__file__)) 31*288bf522SAndroid Build Coastguard Worker 32*288bf522SAndroid Build Coastguard Worker # Find chromium-trace directory and vinn binary as offset from this script 33*288bf522SAndroid Build Coastguard Worker chromium_trace_path = os.path.normpath(this_script_path + '/../../../external/chromium-trace') 34*288bf522SAndroid Build Coastguard Worker if not os.path.exists(chromium_trace_path): 35*288bf522SAndroid Build Coastguard Worker sys.exit('Can\'t find chromium-trace in your source tree') 36*288bf522SAndroid Build Coastguard Worker 37*288bf522SAndroid Build Coastguard Worker vinn_path = chromium_trace_path + '/catapult/third_party/vinn/' 38*288bf522SAndroid Build Coastguard Worker if not os.path.exists(vinn_path): 39*288bf522SAndroid Build Coastguard Worker sys.exit('Can\'t find vinn in your source tree') 40*288bf522SAndroid Build Coastguard Worker 41*288bf522SAndroid Build Coastguard Worker sys.path.append(vinn_path) 42*288bf522SAndroid Build Coastguard Worker import vinn 43*288bf522SAndroid Build Coastguard Worker 44*288bf522SAndroid Build Coastguard Worker # Find source paths and construct vinn launch arguments 45*288bf522SAndroid Build Coastguard Worker tracing_path = chromium_trace_path + '/catapult/tracing/' 46*288bf522SAndroid Build Coastguard Worker gldist_path = chromium_trace_path + '/catapult/tracing/third_party/gl-matrix/dist/' 47*288bf522SAndroid Build Coastguard Worker source_paths_arg = [tracing_path, gldist_path] 48*288bf522SAndroid Build Coastguard Worker js_args_arg = [args.systrace_file] 49*288bf522SAndroid Build Coastguard Worker if args.e is not None: 50*288bf522SAndroid Build Coastguard Worker js_args_arg += [args.e] 51*288bf522SAndroid Build Coastguard Worker res = vinn.RunFile(this_script_path + '/analysis.html', source_paths=source_paths_arg, 52*288bf522SAndroid Build Coastguard Worker js_args=js_args_arg, stdout=sys.stdout, stdin=sys.stdin); 53*288bf522SAndroid Build Coastguard Worker return res.returncode 54*288bf522SAndroid Build Coastguard Worker 55*288bf522SAndroid Build Coastguard Workerif __name__ == '__main__': 56*288bf522SAndroid Build Coastguard Worker main() 57