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 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 19 | # Globals |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 20 | ART_BINARY=dalvikvm |
| 21 | DELETE_ANDROID_DATA="no" |
| 22 | LAUNCH_WRAPPER= |
| 23 | LIBART=libart.so |
| 24 | JIT_PROFILE="no" |
| 25 | VERBOSE="no" |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame^] | 26 | CLEAN_OAT_FILES="yes" |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 27 | EXTRA_OPTIONS=() |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 28 | |
Calin Juravle | 64f45cb | 2017-03-16 19:58:26 -0700 | [diff] [blame] | 29 | # Follow all sym links to get the program name. |
| 30 | if [ z"$BASH_SOURCE" != z ]; then |
| 31 | PROG_NAME="$BASH_SOURCE" |
| 32 | else |
| 33 | PROG_NAME="$0" |
| 34 | fi |
| 35 | while [ -h "$PROG_NAME" ]; do |
| 36 | # On Mac OS, readlink -f doesn't work. |
| 37 | PROG_NAME="$(readlink "$PROG_NAME")" |
| 38 | done |
Nicolas Geoffray | 9583fbc | 2014-02-28 15:21:07 +0000 | [diff] [blame] | 39 | |
Nicolas Geoffray | fc3c67a | 2014-07-02 14:57:53 +0100 | [diff] [blame] | 40 | function find_libdir() { |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 41 | # Get the actual file, $1 is the ART_BINARY_PATH and may be a symbolic link. |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 42 | # Use realpath instead of readlink because Android does not have a readlink. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 43 | if [[ "$(realpath "$1")" == *dalvikvm64 ]]; then |
Nicolas Geoffray | fc3c67a | 2014-07-02 14:57:53 +0100 | [diff] [blame] | 44 | echo "lib64" |
| 45 | else |
| 46 | echo "lib" |
| 47 | fi |
| 48 | } |
| 49 | |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 50 | function replace_compiler_filter_with_quicken() { |
| 51 | ARGS_WITH_QUICKEN=("$@") |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 52 | |
| 53 | found="false" |
| 54 | ((index=0)) |
| 55 | while ((index <= $#)); do |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 56 | what="${ARGS_WITH_QUICKEN[$index]}" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 57 | |
| 58 | case "$what" in |
| 59 | --compiler-filter=*) |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 60 | ARGS_WITH_QUICKEN[$index]="--compiler-filter=quicken" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 61 | found="true" |
| 62 | ;; |
| 63 | esac |
| 64 | |
| 65 | ((index++)) |
| 66 | shift |
| 67 | done |
| 68 | if [ "$found" != "true" ]; then |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 69 | ARGS_WITH_QUICKEN=(-Xcompiler-option --compiler-filter=quicken "${ARGS_WITH_QUICKEN[@]}") |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 70 | fi |
| 71 | } |
| 72 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 73 | function usage() { |
| 74 | cat 1>&2 <<EOF |
| 75 | Usage: art [OPTIONS] [--] [ART_OPTIONS] CLASS |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 76 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 77 | Supported OPTIONS include: |
| 78 | --32 Use the 32-bit Android Runtime. |
| 79 | --64 Use the 64-bit Android Runtime. |
| 80 | --callgrind Launch the Android Runtime in callgrind. |
| 81 | -d Use the debug ART library (libartd.so). |
| 82 | --debug Equivalent to -d. |
| 83 | --gdb Launch the Android Runtime in gdb. |
| 84 | --help Display usage message. |
| 85 | --invoke-with <program> Launch the Android Runtime in <program>. |
| 86 | --perf Launch the Android Runtime with perf recording. |
| 87 | --perf-report Launch the Android Runtime with perf recording with |
| 88 | report upon completion. |
| 89 | --profile Run with profiling, then run using profile data. |
| 90 | --verbose Run script verbosely. |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame^] | 91 | --no-clean Don't cleanup oat directories. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 92 | |
| 93 | The ART_OPTIONS are passed directly to the Android Runtime. |
| 94 | |
| 95 | Example: |
| 96 | art --32 -cp my_classes.dex MainClass |
| 97 | |
| 98 | Common errors: |
| 99 | 1) Not having core.art available (see $ANDROID_BUILD_TOP/art/Android.mk). |
| 100 | eg m -j32 build-art-host |
| 101 | 2) Not having boot.art available (see $ANDROID_BUILD_TOP/build/make/core/dex_preopt_libart_boot.mk) |
| 102 | eg m -j32 out/target/product/generic_x86_64/dex_bootjars/system/framework/x86_64/boot.art |
| 103 | EOF |
| 104 | } |
| 105 | |
| 106 | function clean_android_data() { |
| 107 | if [ "$DELETE_ANDROID_DATA" = "yes" ]; then |
| 108 | rm -rf $ANDROID_DATA |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 109 | fi |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 112 | # Given 'VAR1=VAL VAR2=VAL2 ... cmd arg1 arg2 ... argN' run the 'cmd' with the args |
| 113 | # with the modified environment {VAR1=VAL,VAL2=,...}. |
| 114 | # |
| 115 | # Also prints the command to be run if verbose mode is enabled. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 116 | function verbose_run() { |
| 117 | if [ "$VERBOSE" = "yes" ]; then |
| 118 | echo "$@" |
| 119 | fi |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 120 | |
| 121 | env "$@" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 122 | } |
| 123 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 124 | # Parse a colon-separated list into an array (e.g. "foo.dex:bar.dex" -> (foo.dex bar.dex)) |
| 125 | PARSE_CLASSPATH_RESULT=() # Return value will be here due to shell limitations. |
| 126 | parse_classpath() { |
| 127 | local cp="$1" |
| 128 | local oldifs=$IFS |
| 129 | |
| 130 | local cp_array |
| 131 | cp_array=() |
| 132 | |
| 133 | IFS=":" |
| 134 | for part in $cp; do |
| 135 | cp_array+=("$part") |
| 136 | done |
| 137 | IFS=$oldifs |
| 138 | |
| 139 | PARSE_CLASSPATH_RESULT=("${cp_array[@]}") |
| 140 | } |
| 141 | |
| 142 | # Sets 'PARSE_CLASSPATH_RESULT' to an array of class path dex files. |
| 143 | # e.g. (-cp foo/classes.dex:bar/classes.dex) -> (foo/classes.dex bar/classes.dex) |
| 144 | find_cp_in_args() { |
| 145 | local found="false" |
| 146 | local index=0 |
| 147 | local what |
| 148 | |
| 149 | while [[ $# -gt 0 ]]; do |
| 150 | case "$1" in |
| 151 | -cp|-classpath) |
| 152 | parse_classpath "$2" |
| 153 | # Sets 'PARSE_CLASSPATH_RESULT' to an array of class path dex files. |
| 154 | # Subsequent parses will overwrite the preceding. |
| 155 | shift |
| 156 | ;; |
| 157 | esac |
| 158 | shift |
| 159 | done |
| 160 | } |
| 161 | |
| 162 | # Delete the 'oat' directories relative to the classpath's dex files. |
| 163 | # e.g. (foo/classes.dex bar/classes.dex) would delete (foo/oat bar/oat) directories. |
| 164 | cleanup_oat_directory() { |
| 165 | local classpath |
| 166 | classpath=("$@") |
| 167 | |
| 168 | local dirpath |
| 169 | |
| 170 | for path in "${classpath[@]}"; do |
| 171 | dirpath="$(dirname "$path")" |
| 172 | [[ -d "$dirpath" ]] && verbose_run rm -rf "$dirpath/oat" |
| 173 | done |
| 174 | } |
| 175 | |
| 176 | # Parse -cp <CP>, -classpath <CP>, and $CLASSPATH to find the dex files. |
| 177 | # Each dex file's directory will have an 'oat' file directory, delete it. |
| 178 | # Input: Command line arguments to the art script. |
| 179 | # e.g. -cp foo/classes.dex:bar/classes.dex would delete (foo/oat bar/oat) directories. |
| 180 | cleanup_oat_directory_for_classpath() { |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame^] | 181 | if [ "$CLEAN_OAT_FILES" = "yes" ]; then |
| 182 | # First try: Use $CLASSPATH environment variable. |
| 183 | parse_classpath "$CLASSPATH" |
| 184 | # Second try: Look for latest -cp or -classpath arg which will take precedence. |
| 185 | find_cp_in_args "$@" |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 186 | |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame^] | 187 | cleanup_oat_directory "${PARSE_CLASSPATH_RESULT[@]}" |
| 188 | fi |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 191 | # Attempt to find $ANDROID_ROOT/framework/<isa>/core.art' without knowing what <isa> is. |
| 192 | function check_if_boot_image_file_exists() { |
| 193 | local image_location_dir="$1" |
| 194 | local image_location_name="$2" |
| 195 | |
| 196 | # Expand image_files to a list of existing image files on the disk. |
| 197 | # If no such files exist, it expands to single element 'dir/*/file' with a literal '*'. |
| 198 | local image_files |
| 199 | image_files=("$image_location_dir"/*/"$image_location_name") # avoid treating "*" as literal. |
| 200 | |
| 201 | # Array always has at least 1 element. Test explicitly whether the file exists. |
| 202 | [[ -e "${image_files[0]}" ]] |
| 203 | } |
| 204 | |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 205 | # Automatically find the boot image location. It uses core.art by default. |
| 206 | # On a real device, it might only have a boot.art, so use that instead when core.art does not exist. |
| 207 | function detect_boot_image_location() { |
| 208 | local image_location_dir="$ANDROID_ROOT/framework" |
| 209 | local image_location_name="core.art" |
| 210 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 211 | # If there are no existing core.art, try to find boot.art. |
| 212 | # If there is no boot.art then leave it as-is, assumes -Ximage is explicitly used. |
| 213 | # Otherwise let dalvikvm give the error message about an invalid image file. |
| 214 | if ! check_if_boot_image_file_exists "$image_location_dir" "core.art" && \ |
| 215 | check_if_boot_image_file_exists "$image_location_dir" "boot.art"; then |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 216 | image_location_name="boot.art" |
| 217 | fi |
| 218 | |
| 219 | local image_location="$image_location_dir/$image_location_name" |
| 220 | echo "$image_location" |
| 221 | } |
| 222 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 223 | # Runs dalvikvm, returns its exit code. |
| 224 | # (Oat directories are cleaned up in between runs) |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 225 | function run_art() { |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 226 | local image_location="$(detect_boot_image_location)" |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 227 | local ret |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 228 | |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 229 | # First cleanup any left-over 'oat' files from the last time dalvikvm was run. |
| 230 | cleanup_oat_directory_for_classpath "$@" |
| 231 | # Run dalvikvm. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 232 | verbose_run ANDROID_DATA=$ANDROID_DATA \ |
| 233 | ANDROID_ROOT=$ANDROID_ROOT \ |
| 234 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH \ |
| 235 | PATH=$ANDROID_ROOT/bin:$PATH \ |
| 236 | LD_USE_LOAD_BIAS=1 \ |
| 237 | $LAUNCH_WRAPPER $ART_BINARY_PATH $lib \ |
| 238 | -XXlib:$LIBART \ |
| 239 | -Xnorelocate \ |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 240 | -Ximage:"$image_location" \ |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 241 | "$@" |
Nicolas Geoffray | 162a570 | 2017-08-04 09:28:32 +0000 | [diff] [blame] | 242 | ret=$? |
| 243 | |
| 244 | # Avoid polluting disk with 'oat' files after dalvikvm has finished. |
| 245 | cleanup_oat_directory_for_classpath "$@" |
| 246 | |
| 247 | # Forward exit code of dalvikvm. |
| 248 | return $ret |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | while [[ "$1" = "-"* ]]; do |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 252 | case "$1" in |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 253 | --) |
| 254 | # No more arguments for this script. |
| 255 | shift |
| 256 | break |
| 257 | ;; |
| 258 | --32) |
| 259 | ART_BINARY=dalvikvm32 |
| 260 | ;; |
| 261 | --64) |
| 262 | ART_BINARY=dalvikvm64 |
| 263 | ;; |
| 264 | --callgrind) |
| 265 | LAUNCH_WRAPPER="valgrind --tool=callgrind" |
| 266 | ;; |
| 267 | -d) |
| 268 | ;& # Fallthrough |
| 269 | --debug) |
| 270 | LIBART="libartd.so" |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 271 | # Expect that debug mode wants all checks. |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 272 | EXTRA_OPTIONS+=(-XX:SlowDebug=true) |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 273 | ;; |
| 274 | --gdb) |
| 275 | LIBART="libartd.so" |
| 276 | LAUNCH_WRAPPER="gdb --args" |
| 277 | ;; |
| 278 | --help) |
| 279 | usage |
| 280 | exit 0 |
| 281 | ;; |
| 282 | --invoke-with) |
| 283 | LAUNCH_WRAPPER=$2 |
| 284 | shift |
| 285 | ;; |
| 286 | --perf) |
| 287 | PERF="record" |
| 288 | ;; |
| 289 | --perf-report) |
| 290 | PERF="report" |
| 291 | ;; |
| 292 | --profile) |
| 293 | JIT_PROFILE="yes" |
| 294 | ;; |
| 295 | --verbose) |
| 296 | VERBOSE="yes" |
| 297 | ;; |
Nicolas Geoffray | c0c0785 | 2017-08-08 09:44:15 +0100 | [diff] [blame^] | 298 | --no-clean) |
| 299 | CLEAN_OAT_FILES="no" |
| 300 | ;; |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 301 | --*) |
| 302 | echo "unknown option: $1" 1>&2 |
| 303 | usage |
| 304 | exit 1 |
| 305 | ;; |
| 306 | *) |
| 307 | break |
| 308 | ;; |
| 309 | esac |
| 310 | shift |
Nicolas Geoffray | f63a0a5 | 2014-09-02 15:24:25 +0100 | [diff] [blame] | 311 | done |
| 312 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 313 | if [ $# -eq 0 ]; then |
| 314 | usage |
| 315 | exit 1 |
| 316 | fi |
| 317 | |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 318 | PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" |
| 319 | ANDROID_ROOT=$PROG_DIR/.. |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 320 | ART_BINARY_PATH=$ANDROID_ROOT/bin/$ART_BINARY |
Brian Carlstrom | 87bb26f | 2014-09-08 11:13:47 -0700 | [diff] [blame] | 321 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 322 | if [ ! -x "$ART_BINARY_PATH" ]; then |
| 323 | cat 1>&2 <<EOF |
| 324 | Android Runtime not found: $ART_BINARY_PATH |
| 325 | This script should be in the same directory as the Android Runtime ($ART_BINARY). |
| 326 | EOF |
| 327 | exit 1 |
| 328 | fi |
| 329 | |
| 330 | LIBDIR="$(find_libdir $ART_BINARY_PATH)" |
| 331 | LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 332 | |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 333 | # If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own, |
| 334 | # and ensure we delete it at the end. |
| 335 | if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then |
Igor Murashkin | 7fef4eb | 2017-07-14 15:45:47 -0700 | [diff] [blame] | 336 | if [[ $PWD != / ]]; then |
| 337 | ANDROID_DATA="$PWD/android-data$$" |
| 338 | else |
| 339 | # Use /data/local/tmp when running this from adb shell, since it starts out in / |
| 340 | # by default. |
| 341 | ANDROID_DATA="$ANDROID_DATA/local/tmp/android-data$$" |
| 342 | fi |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 343 | mkdir -p "$ANDROID_DATA" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 344 | DELETE_ANDROID_DATA="yes" |
Nicolas Geoffray | 70a998c | 2014-12-04 17:05:22 +0000 | [diff] [blame] | 345 | fi |
| 346 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 347 | if [ "$PERF" != "" ]; then |
| 348 | LAUNCH_WRAPPER="perf record -g -o $ANDROID_DATA/perf.data -e cycles:u $LAUNCH_WRAPPER" |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 349 | EXTRA_OPTIONS+=(-Xcompiler-option --generate-debug-info) |
Nicolas Geoffray | e099a61 | 2014-12-12 13:52:00 +0000 | [diff] [blame] | 350 | fi |
| 351 | |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 352 | if [ "$JIT_PROFILE" = "yes" ]; then |
| 353 | # Create the profile. The runtime expects profiles to be created before |
| 354 | # execution. |
| 355 | PROFILE_PATH="$ANDROID_DATA/primary.prof" |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 356 | touch "$PROFILE_PATH" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 357 | |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 358 | # Replace the compiler filter with quicken so that we |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 359 | # can capture the profile. |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 360 | ARGS_WITH_QUICKEN= |
| 361 | replace_compiler_filter_with_quicken "$@" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 362 | |
| 363 | run_art -Xjitsaveprofilinginfo \ |
| 364 | -Xps-min-methods-to-save:1 \ |
| 365 | -Xps-min-classes-to-save:1 \ |
| 366 | -Xps-min-notification-before-wake:10 \ |
| 367 | -Xps-profile-path:$PROFILE_PATH \ |
| 368 | -Xusejit:true \ |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 369 | "${ARGS_WITH_QUICKEN[@]}" \ |
Igor Murashkin | 1194244 | 2017-07-20 11:08:34 -0700 | [diff] [blame] | 370 | &> "$ANDROID_DATA/profile_gen.log" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 371 | EXIT_STATUS=$? |
| 372 | |
| 373 | if [ $EXIT_STATUS != 0 ]; then |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 374 | echo "Profile run failed: " >&2 |
| 375 | cat "$ANDROID_DATA/profile_gen.log" >&2 |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 376 | clean_android_data |
| 377 | exit $EXIT_STATUS |
| 378 | fi |
| 379 | |
Igor Murashkin | d54ac26 | 2017-07-26 11:16:23 -0700 | [diff] [blame] | 380 | # Wipe dalvik-cache so that a subsequent run_art must regenerate it. |
| 381 | # Leave $ANDROID_DATA intact since it contains our profile file. |
| 382 | rm -rf "$ANDROID_DATA/dalvik-cache" |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 383 | |
| 384 | # Append arguments so next invocation of run_art uses the profile. |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 385 | EXTRA_OPTIONS+=(-Xcompiler-option --profile-file="$PROFILE_PATH") |
Nicolas Geoffray | 9d7baf4 | 2017-04-19 09:01:29 +0000 | [diff] [blame] | 386 | fi |
| 387 | |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 388 | # Protect additional arguments in quotes to preserve whitespaces (used by |
| 389 | # run-jdwp-test.sh when running on device), '$' (may be used as part of |
| 390 | # classpath) and other special characters when evaluated. |
| 391 | EXTRA_OPTIONS+=("$@") |
Calin Juravle | 64f45cb | 2017-03-16 19:58:26 -0700 | [diff] [blame] | 392 | |
Vladimir Marko | afd44ea | 2017-07-14 13:52:02 +0100 | [diff] [blame] | 393 | run_art "${EXTRA_OPTIONS[@]}" |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 394 | EXIT_STATUS=$? |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 395 | |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 396 | if [ "$PERF" != "" ]; then |
| 397 | if [ "$PERF" = report ]; then |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 398 | perf report -i $ANDROID_DATA/perf.data |
| 399 | fi |
| 400 | echo "Perf data saved in: $ANDROID_DATA/perf.data" |
| 401 | else |
Orion Hodson | 9763f2e | 2017-03-28 08:27:23 +0100 | [diff] [blame] | 402 | # Perf output is placed under $ANDROID_DATA so not cleaned when perf options used. |
| 403 | clean_android_data |
Calin Juravle | aa98061 | 2014-10-20 15:58:57 +0100 | [diff] [blame] | 404 | fi |
| 405 | |
Nicolas Geoffray | 89c4e28 | 2014-03-24 09:33:30 +0000 | [diff] [blame] | 406 | exit $EXIT_STATUS |