blob: d87123ad71bfe05e90a76844d77d77316cf0f07b [file] [log] [blame]
Mathieu Chartier957f8092017-07-11 15:44:45 -07001#!/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
49jar_args=()
50boot_jars=$("$ANDROID_BUILD_TOP"/art/tools/bootjars.sh --target)
51jar_dir=$ANDROID_BUILD_TOP/$(get_build_var TARGET_OUT_JAVA_LIBRARIES)
52for file in $boot_jars; do
53 filename="$jar_dir/$file.jar"
54 jar_args+=("--apk=$filename")
55 jar_args+=("--dex-location=$filename")
56done
57profman_args+=("${jar_args[@]}")
58
59# Generate the profile.
60"$ANDROID_HOST_OUT/bin/profman" --generate-boot-image-profile "--reference-profile-file=$OUT_PROFILE" "${profman_args[@]}"
61
62# Convert it to text.
63echo Dumping profile to $OUT_PROFILE.txt
64"$ANDROID_HOST_OUT/bin/profman" --dump-classes-and-methods "--profile-file=$OUT_PROFILE" "${jar_args[@]}" > "$OUT_PROFILE.txt"
65
66# Generate preloaded classes
67# Filter only classes by using grep -v
68# Remove first and last characters L and ;
69# Replace / with . to make dot format
70grep -v "\\->" "$OUT_PROFILE.txt" | sed 's/.\(.*\)./\1/g' | tr "/" "." > "$OUT_PROFILE.preloaded-classes"
71
72# You may need to filter some classes out since creating threads is not allowed in the zygote.
73# i.e. using: grep -v -E '(android.net.ConnectivityThread\$Singleton)'