blob: 91d6e27b9f04cf1110ec6360fcd32a29ac571e37 [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 Geoffrayf7694612016-11-29 22:06:50 +000033 # Get the actual file, $DALVIKVM may be a symbolic link.
Nicolas Geoffray70a998c2014-12-04 17:05:22 +000034 # Use realpath instead of readlink because Android does not have a readlink.
Nicolas Geoffrayf7694612016-11-29 22:06:50 +000035 if [[ "$(realpath "$ANDROID_ROOT/bin/$DALVIKVM")" == *dalvikvm64 ]]; then
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010036 echo "lib64"
37 else
38 echo "lib"
39 fi
40}
41
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010042invoke_with=
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070043DALVIKVM=dalvikvm
44LIBART=libart.so
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010045
46while true; do
47 if [ "$1" = "--invoke-with" ]; then
48 shift
Andreas Gampec0bbc882015-03-12 09:58:53 -070049 invoke_with="$invoke_with $1"
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010050 shift
51 elif [ "$1" = "-d" ]; then
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070052 LIBART="libartd.so"
53 shift
54 elif [ "$1" = "--32" ]; then
55 DALVIKVM=dalvikvm32
56 shift
57 elif [ "$1" = "--64" ]; then
58 DALVIKVM=dalvikvm64
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010059 shift
Calin Juravleaa980612014-10-20 15:58:57 +010060 elif [ "$1" = "--perf" ]; then
61 PERF="record"
62 shift
63 elif [ "$1" = "--perf-report" ]; then
64 PERF="report"
65 shift
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010066 elif expr "$1" : "--" >/dev/null 2>&1; then
67 echo "unknown option: $1" 1>&2
68 exit 1
69 else
70 break
71 fi
72done
73
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070074PROG_NAME="$(follow_links)"
75PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
76ANDROID_ROOT=$PROG_DIR/..
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070077LIBDIR=$(find_libdir)
78LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR
Nicolas Geoffraydba4fe72016-01-18 16:57:06 +000079DEBUG_OPTION=""
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070080
Nicolas Geoffray70a998c2014-12-04 17:05:22 +000081DELETE_ANDROID_DATA=false
82# If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own,
83# and ensure we delete it at the end.
84if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then
85 ANDROID_DATA=$PWD/android-data$$
86 mkdir -p $ANDROID_DATA/dalvik-cache/{arm,arm64,x86,x86_64}
87 DELETE_ANDROID_DATA=true
88fi
89
Nicolas Geoffraye099a612014-12-12 13:52:00 +000090if [ z"$PERF" != z ]; then
Mathieu Chartier8da49772016-09-02 11:44:11 -070091 invoke_with="perf record -g -o $ANDROID_DATA/perf.data -e cycles:u $invoke_with"
Nicolas Geoffraydba4fe72016-01-18 16:57:06 +000092 DEBUG_OPTION="-Xcompiler-option --generate-debug-info"
Nicolas Geoffraye099a612014-12-12 13:52:00 +000093fi
94
Nicolas Geoffray1e085f02015-10-06 12:00:47 +010095# We use the PIC core image to work with perf.
Nicolas Geoffray89c4e282014-03-24 09:33:30 +000096ANDROID_DATA=$ANDROID_DATA \
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010097 ANDROID_ROOT=$ANDROID_ROOT \
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010098 LD_LIBRARY_PATH=$LD_LIBRARY_PATH \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +010099 PATH=$ANDROID_ROOT/bin:$PATH \
Nicolas Geoffrayfdaeee12015-06-25 15:53:54 +0100100 LD_USE_LOAD_BIAS=1 \
Brian Carlstrom87bb26f2014-09-08 11:13:47 -0700101 $invoke_with $ANDROID_ROOT/bin/$DALVIKVM $lib \
102 -XXlib:$LIBART \
Nicolas Geoffray6b45fd22015-05-06 18:38:19 +0100103 -Xnorelocate \
Nicolas Geoffrayb76bc782016-09-14 12:33:34 +0000104 -Ximage:$ANDROID_ROOT/framework/core.art \
Nicolas Geoffraydba4fe72016-01-18 16:57:06 +0000105 $DEBUG_OPTION \
Calin Juravleaa980612014-10-20 15:58:57 +0100106 "$@"
107
Nicolas Geoffray89c4e282014-03-24 09:33:30 +0000108EXIT_STATUS=$?
Calin Juravleaa980612014-10-20 15:58:57 +0100109
110if [ z"$PERF" != z ]; then
111 if [ z"$PERF" = zreport ]; then
112 perf report -i $ANDROID_DATA/perf.data
113 fi
114 echo "Perf data saved in: $ANDROID_DATA/perf.data"
115else
Nicolas Geoffray70a998c2014-12-04 17:05:22 +0000116 if [ "$DELETE_ANDROID_DATA" = "true" ]; then
117 rm -rf $ANDROID_DATA
118 fi
Calin Juravleaa980612014-10-20 15:58:57 +0100119fi
120
Nicolas Geoffray89c4e282014-03-24 09:33:30 +0000121exit $EXIT_STATUS