Calin Juravle | c7bcda8 | 2020-06-17 19:40:47 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2020 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 | |
| 17 | # |
| 18 | # This script creates the final boot image profile (suitable to include in the platform build). |
| 19 | # The input to the script are: |
| 20 | # 1) the boot.zip file which contains the boot classpath and system server jars. |
| 21 | # This file can be obtained from running `m dist` or by configuring the device with |
| 22 | # the `art/tools/boot-image-profile-configure-device.sh` script. |
Orion Hodson | 3e8caeb | 2020-08-07 15:41:24 +0100 | [diff] [blame] | 23 | # 2) the preloaded classes denylist which specify what clases should not be preloaded |
| 24 | # in Zygote. Usually located in usually in frameworks/base/config/preloaded-classes-denylist |
Calin Juravle | c7bcda8 | 2020-06-17 19:40:47 -0700 | [diff] [blame] | 25 | # 3) a list of raw boot image profiles extracted from devices. An example how to do that is |
| 26 | # by running `art/tools/boot-image-profile-extract-profile.sh` script. |
| 27 | # |
| 28 | # It is strongly recommended that you make use of extensive critical user journeys flows in order |
| 29 | # to capture the raw boot image profiles described in #3. |
| 30 | # |
| 31 | # NOTE: by default, the script uses default arguments for producing the boot image profiles. |
| 32 | # You might want to adjust the default generation arguments based on the shape of profile |
| 33 | # and based on the metrics that matter for each product. |
| 34 | # |
| 35 | |
| 36 | if [[ -z "$ANDROID_BUILD_TOP" ]]; then |
| 37 | echo "You must run on this after running envsetup.sh and launch target" |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | if [[ "$#" -lt 4 ]]; then |
Orion Hodson | 3e8caeb | 2020-08-07 15:41:24 +0100 | [diff] [blame] | 42 | echo "Usage $0 <output-dir> <boot.zip-location> <preloaded-denylist-location> <profile-input1> <profile-input2> ... <profman args>" |
Calin Juravle | c7bcda8 | 2020-06-17 19:40:47 -0700 | [diff] [blame] | 43 | echo "Without any profman args the script will use defaults." |
Orion Hodson | 3e8caeb | 2020-08-07 15:41:24 +0100 | [diff] [blame] | 44 | echo "Example: $0 output-dir boot.zip frameworks/base/config/preloaded-classes-denylist android1.prof android2.prof" |
| 45 | echo " $0 output-dir boot.zip frameworks/base/config/preloaded-classes-denylist android.prof --profman-arg --upgrade-startup-to-hot=true" |
| 46 | echo "preloaded-deny-list-location is usually frameworks/base/config/preloaded-classes-denylist" |
Calin Juravle | c7bcda8 | 2020-06-17 19:40:47 -0700 | [diff] [blame] | 47 | exit 1 |
| 48 | fi |
| 49 | |
| 50 | echo "Creating work dir" |
| 51 | WORK_DIR=/tmp/android-bcp |
| 52 | mkdir -p "$WORK_DIR" |
| 53 | |
| 54 | OUT_DIR="$1" |
| 55 | BOOT_ZIP="$2" |
Orion Hodson | 3e8caeb | 2020-08-07 15:41:24 +0100 | [diff] [blame] | 56 | PRELOADED_DENYLIST="$3" |
Calin Juravle | c7bcda8 | 2020-06-17 19:40:47 -0700 | [diff] [blame] | 57 | shift 3 |
| 58 | |
Calin Juravle | c7bcda8 | 2020-06-17 19:40:47 -0700 | [diff] [blame] | 59 | # Read the profile input args. |
| 60 | profman_profile_input_args=() |
| 61 | while [[ "$#" -ge 1 ]] && [[ ! "$1" = '--profman-arg' ]]; do |
| 62 | profman_profile_input_args+=("--profile-file=$1") |
| 63 | shift |
| 64 | done |
| 65 | |
| 66 | # Read the profman args. |
| 67 | profman_args=() |
| 68 | while [[ "$#" -ge 2 ]] && [[ "$1" = '--profman-arg' ]]; do |
| 69 | profman_args+=("$2") |
| 70 | shift 2 |
| 71 | done |
| 72 | |
| 73 | OUT_BOOT_PROFILE="$OUT_DIR"/boot-image-profile.txt |
| 74 | OUT_PRELOADED_CLASSES="$OUT_DIR"/preloaded-classes |
| 75 | OUT_SYSTEM_SERVER="$OUT_DIR"/art-profile |
| 76 | |
| 77 | echo "Changing dirs to the build top" |
| 78 | cd "$ANDROID_BUILD_TOP" |
| 79 | |
| 80 | echo "Unziping boot.zip" |
| 81 | BOOT_UNZIP_DIR="$WORK_DIR"/boot-dex |
| 82 | ART_JARS="$BOOT_UNZIP_DIR"/dex_artjars_input |
| 83 | BOOT_JARS="$BOOT_UNZIP_DIR"/dex_bootjars_input |
| 84 | SYSTEM_SERVER_JAR="$BOOT_UNZIP_DIR"/system/framework/services.jar |
| 85 | |
| 86 | unzip -o "$BOOT_ZIP" -d "$BOOT_UNZIP_DIR" |
| 87 | |
| 88 | echo "Processing boot image jar files" |
| 89 | jar_args=() |
| 90 | for entry in "$ART_JARS"/* |
| 91 | do |
| 92 | jar_args+=("--apk=$entry") |
| 93 | done |
| 94 | for entry in "$BOOT_JARS"/* |
| 95 | do |
| 96 | jar_args+=("--apk=$entry") |
| 97 | done |
| 98 | profman_args+=("${jar_args[@]}") |
| 99 | |
| 100 | echo "Running profman for boot image profiles" |
| 101 | # NOTE: |
| 102 | # You might want to adjust the default generation arguments based on the data |
| 103 | # For example, to update the selection thresholds you could specify: |
| 104 | # --method-threshold=10 \ |
| 105 | # --class-threshold=10 \ |
| 106 | # --preloaded-class-threshold=10 \ |
| 107 | # --special-package=android:1 \ |
| 108 | # --special-package=com.android.systemui:1 \ |
| 109 | # The threshold is percentage of total aggregation, that is, a method/class is |
| 110 | # included in the profile only if it's used by at least x% of the packages. |
| 111 | # (from 0% - include everything to 100% - include only the items that |
| 112 | # are used by all packages on device). |
| 113 | # The --special-package allows you to give a prioriority to certain packages, |
| 114 | # meaning, if the methods is used by that package then the algorithm will use a |
| 115 | # different selection thresholds. |
| 116 | # (system server is identified as the "android" package) |
| 117 | profman \ |
| 118 | --generate-boot-image-profile \ |
| 119 | "${profman_profile_input_args[@]}" \ |
| 120 | --out-profile-path="$OUT_BOOT_PROFILE" \ |
| 121 | --out-preloaded-classes-path="$OUT_PRELOADED_CLASSES" \ |
Orion Hodson | 3e8caeb | 2020-08-07 15:41:24 +0100 | [diff] [blame] | 122 | --preloaded-classes-denylist="$PRELOADED_DENYLIST" \ |
Calin Juravle | c7bcda8 | 2020-06-17 19:40:47 -0700 | [diff] [blame] | 123 | --special-package=android:1 \ |
| 124 | --special-package=com.android.systemui:1 \ |
| 125 | "${profman_args[@]}" |
| 126 | |
| 127 | echo "Done boot image profile" |
| 128 | |
| 129 | echo "Running profman for system server" |
| 130 | # For system server profile we want to include everything usually |
| 131 | # We also don't have a preloaded-classes file for it, so we ignore the argument. |
| 132 | profman \ |
| 133 | --generate-boot-image-profile \ |
| 134 | "${profman_profile_input_args[@]}" \ |
| 135 | --out-profile-path="$OUT_SYSTEM_SERVER" \ |
| 136 | --apk="$SYSTEM_SERVER_JAR" \ |
| 137 | --method-threshold=0 \ |
| 138 | --class-threshold=0 |
| 139 | |
| 140 | echo "Done system server" |
| 141 | |
| 142 | echo "" |
| 143 | echo "Boot profile methods+classes count: $(wc -l $OUT_BOOT_PROFILE)" |
| 144 | echo "Preloaded classes count: $(wc -l $OUT_PRELOADED_CLASSES)" |
| 145 | echo "System server profile methods+classes count: $(wc -l $OUT_SYSTEM_SERVER)" |
| 146 | |
| 147 | CLEAN_UP="${CLEAN_UP:-true}" |
| 148 | if [[ "$CLEAN_UP" = "true" ]]; then |
| 149 | rm -rf "$WORK_DIR" |
Orion Hodson | 3e8caeb | 2020-08-07 15:41:24 +0100 | [diff] [blame] | 150 | fi |