Elliott Hughes | 40ef99e | 2011-08-11 17:44:34 -0700 | [diff] [blame] | 1 | # 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 Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 15 | # 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 Geoffray | 9583fbc | 2014-02-28 15:21:07 +0000 | [diff] [blame] | 19 | function follow_links() { |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 20 | if [ z"$BASH_SOURCE" != z ]; then |
| 21 | file="$BASH_SOURCE" |
| 22 | else |
| 23 | file="$0" |
| 24 | fi |
Nicolas Geoffray | 9583fbc | 2014-02-28 15:21:07 +0000 | [diff] [blame] | 25 | 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 Geoffray | fc3c67a | 2014-07-02 14:57:53 +0100 | [diff] [blame] | 32 | function find_libdir() { |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 33 | # 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 Geoffray | fc3c67a | 2014-07-02 14:57:53 +0100 | [diff] [blame] | 35 | echo "lib64" |
| 36 | else |
| 37 | echo "lib" |
| 38 | fi |
| 39 | } |
| 40 | |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 41 | invoke_with= |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 42 | DALVIKVM=dalvikvm |
| 43 | LIBART=libart.so |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 44 | |
| 45 | while true; do |
| 46 | if [ "$1" = "--invoke-with" ]; then |
| 47 | shift |
Andreas Gampe | c0bbc88 | 2015-03-12 09:58:53 -0700 | [diff] [blame] | 48 | invoke_with="$invoke_with $1" |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 49 | shift |
| 50 | elif [ "$1" = "-d" ]; then |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 51 | LIBART="libartd.so" |
| 52 | shift |
| 53 | elif [ "$1" = "--32" ]; then |
| 54 | DALVIKVM=dalvikvm32 |
| 55 | shift |
| 56 | elif [ "$1" = "--64" ]; then |
| 57 | DALVIKVM=dalvikvm64 |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 58 | shift |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 59 | elif [ "$1" = "--perf" ]; then |
| 60 | PERF="record" |
| 61 | shift |
| 62 | elif [ "$1" = "--perf-report" ]; then |
| 63 | PERF="report" |
| 64 | shift |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 65 | elif expr "$1" : "--" >/dev/null 2>&1; then |
| 66 | echo "unknown option: $1" 1>&2 |
| 67 | exit 1 |
| 68 | else |
| 69 | break |
| 70 | fi |
| 71 | done |
| 72 | |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 73 | PROG_NAME="$(follow_links)" |
| 74 | PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" |
| 75 | ANDROID_ROOT=$PROG_DIR/.. |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 76 | LIBDIR=$(find_libdir) |
| 77 | LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR |
| 78 | |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 79 | DELETE_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. |
| 82 | if [ "$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 |
| 86 | fi |
| 87 | |
Nicolas Geoffray | e099a61 | 2014-12-12 13:52:00 +0000 | [diff] [blame] | 88 | if [ z"$PERF" != z ]; then |
| 89 | invoke_with="perf record -o $ANDROID_DATA/perf.data -e cycles:u $invoke_with" |
| 90 | fi |
| 91 | |
Nicolas Geoffray | 89c4e28 | 2014-03-24 09:33:30 +0000 | [diff] [blame] | 92 | ANDROID_DATA=$ANDROID_DATA \ |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 93 | ANDROID_ROOT=$ANDROID_ROOT \ |
Nicolas Geoffray | fc3c67a | 2014-07-02 14:57:53 +0100 | [diff] [blame] | 94 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH \ |
Nicolas Geoffray | 4f7fdd2 | 2015-04-24 11:57:37 +0100 | [diff] [blame] | 95 | PATH=$ANDROID_ROOT/bin:$PATH \ |
Nicolas Geoffray | fdaeee1 | 2015-06-25 15:53:54 +0100 | [diff] [blame] | 96 | LD_USE_LOAD_BIAS=1 \ |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 97 | $invoke_with $ANDROID_ROOT/bin/$DALVIKVM $lib \ |
| 98 | -XXlib:$LIBART \ |
Nicolas Geoffray | 6b45fd2 | 2015-05-06 18:38:19 +0100 | [diff] [blame] | 99 | -Xnorelocate \ |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 100 | -Ximage:$ANDROID_ROOT/framework/core.art \ |
David Srbecky | 8363c77 | 2015-05-28 16:12:43 +0100 | [diff] [blame] | 101 | -Xcompiler-option --generate-debug-info \ |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 102 | "$@" |
| 103 | |
Nicolas Geoffray | 89c4e28 | 2014-03-24 09:33:30 +0000 | [diff] [blame] | 104 | EXIT_STATUS=$? |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 105 | |
| 106 | if [ z"$PERF" != z ]; then |
| 107 | if [ z"$PERF" = zreport ]; then |
| 108 | perf report -i $ANDROID_DATA/perf.data |
| 109 | fi |
| 110 | echo "Perf data saved in: $ANDROID_DATA/perf.data" |
| 111 | else |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 112 | if [ "$DELETE_ANDROID_DATA" = "true" ]; then |
| 113 | rm -rf $ANDROID_DATA |
| 114 | fi |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 115 | fi |
| 116 | |
Nicolas Geoffray | 89c4e28 | 2014-03-24 09:33:30 +0000 | [diff] [blame] | 117 | exit $EXIT_STATUS |