Nicolas Geoffray | d2f6f77 | 2014-03-17 18:26:00 +0000 | [diff] [blame] | 1 | #!/bin/bash |
Elliott Hughes | 40ef99e | 2011-08-11 17:44:34 -0700 | [diff] [blame] | 2 | # |
| 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 Geoffray | 9583fbc | 2014-02-28 15:21:07 +0000 | [diff] [blame] | 17 | function follow_links() { |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 18 | if [ z"$BASH_SOURCE" != z ]; then |
| 19 | file="$BASH_SOURCE" |
| 20 | else |
| 21 | file="$0" |
| 22 | fi |
Nicolas Geoffray | 9583fbc | 2014-02-28 15:21:07 +0000 | [diff] [blame] | 23 | 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 Geoffray | fc3c67a | 2014-07-02 14:57:53 +0100 | [diff] [blame] | 30 | function find_libdir() { |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 31 | if [ "$(readlink "$ANDROID_ROOT/bin/$DALVIKVM")" = "dalvikvm64" ]; then |
Nicolas Geoffray | fc3c67a | 2014-07-02 14:57:53 +0100 | [diff] [blame] | 32 | echo "lib64" |
| 33 | else |
| 34 | echo "lib" |
| 35 | fi |
| 36 | } |
| 37 | |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 38 | invoke_with= |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 39 | DALVIKVM=dalvikvm |
| 40 | LIBART=libart.so |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 41 | |
| 42 | while true; do |
| 43 | if [ "$1" = "--invoke-with" ]; then |
| 44 | shift |
| 45 | invoke_with="$1" |
| 46 | shift |
| 47 | elif [ "$1" = "-d" ]; then |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 48 | LIBART="libartd.so" |
| 49 | shift |
| 50 | elif [ "$1" = "--32" ]; then |
| 51 | DALVIKVM=dalvikvm32 |
| 52 | shift |
| 53 | elif [ "$1" = "--64" ]; then |
| 54 | DALVIKVM=dalvikvm64 |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 55 | shift |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame^] | 56 | elif [ "$1" = "--perf" ]; then |
| 57 | PERF="record" |
| 58 | shift |
| 59 | elif [ "$1" = "--perf-report" ]; then |
| 60 | PERF="report" |
| 61 | shift |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 62 | elif expr "$1" : "--" >/dev/null 2>&1; then |
| 63 | echo "unknown option: $1" 1>&2 |
| 64 | exit 1 |
| 65 | else |
| 66 | break |
| 67 | fi |
| 68 | done |
| 69 | |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 70 | PROG_NAME="$(follow_links)" |
| 71 | PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" |
| 72 | ANDROID_ROOT=$PROG_DIR/.. |
| 73 | ANDROID_DATA=$PWD/android-data$$ |
| 74 | LIBDIR=$(find_libdir) |
| 75 | LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR |
| 76 | |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame^] | 77 | |
| 78 | if [ z"$PERF" != z ]; then |
| 79 | invoke_with="perf record -o $ANDROID_DATA/perf.data -e cycles:u $invoke_with" |
| 80 | fi |
| 81 | |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 82 | mkdir -p $ANDROID_DATA/dalvik-cache/{arm,arm64,x86,x86_64} |
Nicolas Geoffray | 89c4e28 | 2014-03-24 09:33:30 +0000 | [diff] [blame] | 83 | ANDROID_DATA=$ANDROID_DATA \ |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 84 | ANDROID_ROOT=$ANDROID_ROOT \ |
Nicolas Geoffray | fc3c67a | 2014-07-02 14:57:53 +0100 | [diff] [blame] | 85 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH \ |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 86 | $invoke_with $ANDROID_ROOT/bin/$DALVIKVM $lib \ |
| 87 | -XXlib:$LIBART \ |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 88 | -Ximage:$ANDROID_ROOT/framework/core.art \ |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame^] | 89 | -Xcompiler-option --include-debug-symbols \ |
| 90 | "$@" |
| 91 | |
Nicolas Geoffray | 89c4e28 | 2014-03-24 09:33:30 +0000 | [diff] [blame] | 92 | EXIT_STATUS=$? |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame^] | 93 | |
| 94 | if [ 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" |
| 99 | else |
| 100 | rm -rf $ANDROID_DATA |
| 101 | fi |
| 102 | |
Nicolas Geoffray | 89c4e28 | 2014-03-24 09:33:30 +0000 | [diff] [blame] | 103 | exit $EXIT_STATUS |