blob: f167a732c18a7371a667a9fa752d72882c35691f [file] [log] [blame]
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001# Copyright (C) 2011 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Nicolas Geoffray70a998c2014-12-04 17:05:22 +000015# This script is used on host and device. It uses a common subset
16# shell dialect that should work on the host (e.g. bash), and
17# Android (e.g. mksh).
18
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +000019function follow_links() {
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010020 if [ z"$BASH_SOURCE" != z ]; then
21 file="$BASH_SOURCE"
22 else
23 file="$0"
24 fi
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +000025 while [ -h "$file" ]; do
26 # On Mac OS, readlink -f doesn't work.
27 file="$(readlink "$file")"
28 done
29 echo "$file"
30}
31
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010032function find_libdir() {
Nicolas Geoffray70a998c2014-12-04 17:05:22 +000033 # Use realpath instead of readlink because Android does not have a readlink.
34 if [ "$(realpath "$ANDROID_ROOT/bin/$DALVIKVM")" = "$(realpath "$ANDROID_ROOT/bin/dalvikvm64")" ]; then
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010035 echo "lib64"
36 else
37 echo "lib"
38 fi
39}
40
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010041invoke_with=
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070042DALVIKVM=dalvikvm
43LIBART=libart.so
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010044
45while true; do
46 if [ "$1" = "--invoke-with" ]; then
47 shift
Andreas Gampec0bbc882015-03-12 09:58:53 -070048 invoke_with="$invoke_with $1"
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010049 shift
50 elif [ "$1" = "-d" ]; then
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070051 LIBART="libartd.so"
52 shift
53 elif [ "$1" = "--32" ]; then
54 DALVIKVM=dalvikvm32
55 shift
56 elif [ "$1" = "--64" ]; then
57 DALVIKVM=dalvikvm64
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010058 shift
Calin Juravleaa980612014-10-20 15:58:57 +010059 elif [ "$1" = "--perf" ]; then
60 PERF="record"
61 shift
62 elif [ "$1" = "--perf-report" ]; then
63 PERF="report"
64 shift
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010065 elif expr "$1" : "--" >/dev/null 2>&1; then
66 echo "unknown option: $1" 1>&2
67 exit 1
68 else
69 break
70 fi
71done
72
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070073PROG_NAME="$(follow_links)"
74PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
75ANDROID_ROOT=$PROG_DIR/..
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070076LIBDIR=$(find_libdir)
77LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR
78
Nicolas Geoffray70a998c2014-12-04 17:05:22 +000079DELETE_ANDROID_DATA=false
80# If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own,
81# and ensure we delete it at the end.
82if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then
83 ANDROID_DATA=$PWD/android-data$$
84 mkdir -p $ANDROID_DATA/dalvik-cache/{arm,arm64,x86,x86_64}
85 DELETE_ANDROID_DATA=true
86fi
87
Nicolas Geoffraye099a612014-12-12 13:52:00 +000088if [ z"$PERF" != z ]; then
89 invoke_with="perf record -o $ANDROID_DATA/perf.data -e cycles:u $invoke_with"
90fi
91
Nicolas Geoffray89c4e282014-03-24 09:33:30 +000092ANDROID_DATA=$ANDROID_DATA \
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010093 ANDROID_ROOT=$ANDROID_ROOT \
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010094 LD_LIBRARY_PATH=$LD_LIBRARY_PATH \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +010095 PATH=$ANDROID_ROOT/bin:$PATH \
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070096 $invoke_with $ANDROID_ROOT/bin/$DALVIKVM $lib \
97 -XXlib:$LIBART \
Nicolas Geoffray6b45fd22015-05-06 18:38:19 +010098 -Xnorelocate \
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010099 -Ximage:$ANDROID_ROOT/framework/core.art \
Calin Juravleaa980612014-10-20 15:58:57 +0100100 -Xcompiler-option --include-debug-symbols \
101 "$@"
102
Nicolas Geoffray89c4e282014-03-24 09:33:30 +0000103EXIT_STATUS=$?
Calin Juravleaa980612014-10-20 15:58:57 +0100104
105if [ z"$PERF" != z ]; then
106 if [ z"$PERF" = zreport ]; then
107 perf report -i $ANDROID_DATA/perf.data
108 fi
109 echo "Perf data saved in: $ANDROID_DATA/perf.data"
110else
Nicolas Geoffray70a998c2014-12-04 17:05:22 +0000111 if [ "$DELETE_ANDROID_DATA" = "true" ]; then
112 rm -rf $ANDROID_DATA
113 fi
Calin Juravleaa980612014-10-20 15:58:57 +0100114fi
115
Nicolas Geoffray89c4e282014-03-24 09:33:30 +0000116exit $EXIT_STATUS