1#!/usr/bin/env bash
2#
3# Copyright 2021 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
18usage() {
19  echo "Usage: ./showcompiledclasses.sh -p packagename [-c]"
20  echo "      -p is the packagename to check"
21  echo "      -c just display the counts"
22  echo ""
23  echo "This script greps the odex file for a package and prints the classes have been\
24        compiled by art."
25  exit 1
26}
27
28COUNT=0
29while getopts cp: flag; do
30  case $flag in
31    p)
32      PACKAGE=$OPTARG
33      ;;
34    c)
35      COUNT=1
36      ;;
37    *)
38      usage
39      ;;
40  esac
41done
42
43if [ -z "${PACKAGE}" ]; then
44  usage
45fi
46
47OAT=$(adb shell dumpsys package dexopt | grep -A 1 $PACKAGE | grep status | cut -d":" -f2 |\
48      cut -d "[" -f1 | cut -d " " -f 2)
49RESULTS="$(adb shell oatdump --oat-file="${OAT}" |\
50               grep -E "(OatClassSomeCompiled|OatClassAllCompiled)")"
51if [[ $COUNT -eq 0 ]]; then
52  echo "${RESULTS}"
53else
54  echo -n "OatClassAllCompiled: "
55  echo "${RESULTS}" | grep "OatClassAllCompiled" -c
56  echo -n "OatClassSomeCompiled: "
57  echo "${RESULTS}" | grep "OatClassSomeCompiled" -c
58fi