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