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