Mathieu Chartier | 957f809 | 2017-07-11 15:44:45 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2017 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 a boot image profile based on input profiles. |
| 19 | # |
| 20 | |
| 21 | if [[ "$#" -lt 2 ]]; then |
| 22 | echo "Usage $0 <output> <profman args> <profiles>+" |
| 23 | echo "Also outputs <output>.txt and <output>.preloaded-classes" |
| 24 | echo 'Example: generate-boot-image-profile.sh boot.prof --profman-arg --boot-image-sampled-method-threshold=1 profiles/0/*/primary.prof' |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 29 | TOP="$DIR/../.." |
| 30 | source "${TOP}/build/envsetup.sh" >&/dev/null # import get_build_var |
| 31 | |
| 32 | OUT_PROFILE=$1 |
| 33 | shift |
| 34 | |
| 35 | # Read the profman args. |
| 36 | profman_args=() |
| 37 | while [[ "$#" -ge 2 ]] && [[ "$1" = '--profman-arg' ]]; do |
| 38 | profman_args+=("$2") |
| 39 | shift 2 |
| 40 | done |
| 41 | |
| 42 | # Remaining args are all the profiles. |
| 43 | for file in "$@"; do |
| 44 | if [[ -s $file ]]; then |
| 45 | profman_args+=("--profile-file=$file") |
| 46 | fi |
| 47 | done |
| 48 | |
David Brazdil | f13ac7c | 2018-01-30 10:09:08 +0000 | [diff] [blame] | 49 | # Boot jars have hidden API access flags which do not pass dex file |
| 50 | # verification. Skip it. |
Calin Juravle | 1bfe4bd | 2018-04-26 16:00:11 -0700 | [diff] [blame] | 51 | jar_args=() |
Mathieu Chartier | 957f809 | 2017-07-11 15:44:45 -0700 | [diff] [blame] | 52 | boot_jars=$("$ANDROID_BUILD_TOP"/art/tools/bootjars.sh --target) |
| 53 | jar_dir=$ANDROID_BUILD_TOP/$(get_build_var TARGET_OUT_JAVA_LIBRARIES) |
| 54 | for file in $boot_jars; do |
| 55 | filename="$jar_dir/$file.jar" |
| 56 | jar_args+=("--apk=$filename") |
| 57 | jar_args+=("--dex-location=$filename") |
| 58 | done |
| 59 | profman_args+=("${jar_args[@]}") |
| 60 | |
| 61 | # Generate the profile. |
| 62 | "$ANDROID_HOST_OUT/bin/profman" --generate-boot-image-profile "--reference-profile-file=$OUT_PROFILE" "${profman_args[@]}" |
| 63 | |
| 64 | # Convert it to text. |
| 65 | echo Dumping profile to $OUT_PROFILE.txt |
| 66 | "$ANDROID_HOST_OUT/bin/profman" --dump-classes-and-methods "--profile-file=$OUT_PROFILE" "${jar_args[@]}" > "$OUT_PROFILE.txt" |
| 67 | |
| 68 | # Generate preloaded classes |
| 69 | # Filter only classes by using grep -v |
| 70 | # Remove first and last characters L and ; |
| 71 | # Replace / with . to make dot format |
| 72 | grep -v "\\->" "$OUT_PROFILE.txt" | sed 's/.\(.*\)./\1/g' | tr "/" "." > "$OUT_PROFILE.preloaded-classes" |
| 73 | |
| 74 | # You may need to filter some classes out since creating threads is not allowed in the zygote. |
| 75 | # i.e. using: grep -v -E '(android.net.ConnectivityThread\$Singleton)' |