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 21if [[ "$#" -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 26fi 27 28DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 29TOP="$DIR/../.." 30source "${TOP}/build/envsetup.sh" >&/dev/null # import get_build_var 31 32OUT_PROFILE=$1 33shift 34 35# Read the profman args. 36profman_args=() 37while [[ "$#" -ge 2 ]] && [[ "$1" = '--profman-arg' ]]; do 38 profman_args+=("$2") 39 shift 2 40done 41 42# Remaining args are all the profiles. 43for file in "$@"; do 44 if [[ -s $file ]]; then 45 profman_args+=("--profile-file=$file") 46 fi 47done 48 49# Boot jars have hidden API access flags which do not pass dex file 50# verification. Skip it. 51jar_args=() 52boot_jars=$("$ANDROID_BUILD_TOP"/art/tools/bootjars.sh --target) 53jar_dir=$ANDROID_BUILD_TOP/$(get_build_var TARGET_OUT_JAVA_LIBRARIES) 54for file in $boot_jars; do 55 filename="$jar_dir/$file.jar" 56 jar_args+=("--apk=$filename") 57 jar_args+=("--dex-location=$filename") 58done 59profman_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. 65echo 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 72grep -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)' 76