blob: af96b47fad04f323f07e43ca6a685cb64ff43f04 [file] [log] [blame]
Nicolas Geoffrayd2f6f772014-03-17 18:26:00 +00001#!/bin/bash
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002#
3# Copyright (C) 2011 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
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +000017function follow_links() {
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010018 if [ z"$BASH_SOURCE" != z ]; then
19 file="$BASH_SOURCE"
20 else
21 file="$0"
22 fi
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +000023 while [ -h "$file" ]; do
24 # On Mac OS, readlink -f doesn't work.
25 file="$(readlink "$file")"
26 done
27 echo "$file"
28}
29
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010030function find_libdir() {
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070031 if [ "$(readlink "$ANDROID_ROOT/bin/$DALVIKVM")" = "dalvikvm64" ]; then
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010032 echo "lib64"
33 else
34 echo "lib"
35 fi
36}
37
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010038invoke_with=
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070039DALVIKVM=dalvikvm
40LIBART=libart.so
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010041
42while true; do
43 if [ "$1" = "--invoke-with" ]; then
44 shift
45 invoke_with="$1"
46 shift
47 elif [ "$1" = "-d" ]; then
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070048 LIBART="libartd.so"
49 shift
50 elif [ "$1" = "--32" ]; then
51 DALVIKVM=dalvikvm32
52 shift
53 elif [ "$1" = "--64" ]; then
54 DALVIKVM=dalvikvm64
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010055 shift
Calin Juravleaa980612014-10-20 15:58:57 +010056 elif [ "$1" = "--perf" ]; then
57 PERF="record"
58 shift
59 elif [ "$1" = "--perf-report" ]; then
60 PERF="report"
61 shift
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010062 elif expr "$1" : "--" >/dev/null 2>&1; then
63 echo "unknown option: $1" 1>&2
64 exit 1
65 else
66 break
67 fi
68done
69
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070070PROG_NAME="$(follow_links)"
71PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
72ANDROID_ROOT=$PROG_DIR/..
73ANDROID_DATA=$PWD/android-data$$
74LIBDIR=$(find_libdir)
75LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR
76
Calin Juravleaa980612014-10-20 15:58:57 +010077
78if [ z"$PERF" != z ]; then
79 invoke_with="perf record -o $ANDROID_DATA/perf.data -e cycles:u $invoke_with"
80fi
81
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010082mkdir -p $ANDROID_DATA/dalvik-cache/{arm,arm64,x86,x86_64}
Nicolas Geoffray89c4e282014-03-24 09:33:30 +000083ANDROID_DATA=$ANDROID_DATA \
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010084 ANDROID_ROOT=$ANDROID_ROOT \
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010085 LD_LIBRARY_PATH=$LD_LIBRARY_PATH \
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070086 $invoke_with $ANDROID_ROOT/bin/$DALVIKVM $lib \
87 -XXlib:$LIBART \
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010088 -Ximage:$ANDROID_ROOT/framework/core.art \
Calin Juravleaa980612014-10-20 15:58:57 +010089 -Xcompiler-option --include-debug-symbols \
90 "$@"
91
Nicolas Geoffray89c4e282014-03-24 09:33:30 +000092EXIT_STATUS=$?
Calin Juravleaa980612014-10-20 15:58:57 +010093
94if [ z"$PERF" != z ]; then
95 if [ z"$PERF" = zreport ]; then
96 perf report -i $ANDROID_DATA/perf.data
97 fi
98 echo "Perf data saved in: $ANDROID_DATA/perf.data"
99else
100 rm -rf $ANDROID_DATA
101fi
102
Nicolas Geoffray89c4e282014-03-24 09:33:30 +0000103exit $EXIT_STATUS