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 17readme() { 18 echo ' 19Analyze boot-time 20e.g. 21ANDROID_BUILD_TOP="$PWD" \ 22CONFIG_YMAL="$ANDROID_BUILD_TOP/system/extras/boottime_tools/bootanalyze/config.yaml" \ 23 LOOPS=3 \ 24 RESULTS_DIR="$PWD/bootAnalyzeResults" \ 25 $ANDROID_BUILD_TOP/system/extras/boottime_tools/bootanalyze/bootanalyze.sh 26 27Flags: 28-a : Uses "adb reboot" (instead of "adb shell su root svc power reboot") command to reboot 29-b : If set grabs bootchart 30-w : If set grabs carwatchdog perf stats 31-s : Set the device serial for adb 32' 33 exit 34} 35 36 37if [[ -z $ANDROID_BUILD_TOP ]]; then 38 echo 'Error: you need to specify ANDROID_BUILD_TOP' 39 readme 40fi 41echo "ANDROID_BUILD_TOP=$ANDROID_BUILD_TOP" 42SCRIPT_DIR="$ANDROID_BUILD_TOP/system/extras/boottime_tools/bootanalyze" 43 44 45if [[ -z $CONFIG_YMAL ]]; then 46 CONFIG_YMAL="$SCRIPT_DIR/config.yaml" 47fi 48echo "CONFIG_YMAL=$CONFIG_YMAL" 49 50 51if [[ -z $RESULTS_DIR ]]; then 52 RESULTS_DIR="$PWD/bootAnalyzeResults" 53fi 54echo "RESULTS_DIR=$RESULTS_DIR" 55mkdir -p $RESULTS_DIR 56 57REBOOT_FLAG="" 58BOOTCHART_FLAG="" 59CARWATCHDOG_FLAG="" 60PY_SERIAL_FLAG="" 61ADB_SERIAL_FLAG="" 62 63while getopts 'abws:' OPTION; do 64 case "$OPTION" in 65 a) 66 REBOOT_FLAG="-a" 67 ;; 68 b) 69 BOOTCHART_FLAG="-b" 70 ;; 71 w) 72 CARWATCHDOG_FLAG="-W" 73 ;; 74 s) 75 PY_SERIAL_FLAG="--serial ${OPTARG}" 76 ADB_SERIAL_FLAG="-s ${OPTARG}" 77 ;; 78 ?) 79 echo 'Error: Invalid flag set' 80 readme 81 ;; 82 esac 83done 84shift "$(($OPTIND -1))" 85 86 87adb $ADB_SERIAL_FLAG shell 'touch /data/bootchart/enabled' 88 89if [[ -z $LOOPS ]]; then 90 LOOPS=1 91fi 92echo "Analyzing boot-time for LOOPS=$LOOPS" 93BOOTCHART_TGZ="/tmp/android-bootchart/bootchart.tgz" 94START=1 95 96SLEEP_SEC=20 97for (( l=$START; l<=$LOOPS; l++ )); do 98 echo "Loop: $l" 99 SECONDS=0 100 mkdir $RESULTS_DIR/$l 101 $SCRIPT_DIR/bootanalyze.py -c $CONFIG_YMAL -G 4M -r \ 102 $PY_SERIAL_FLAG $REBOOT_FLAG $BOOTCHART_FLAG $CARWATCHDOG_FLAG \ 103 -o "$RESULTS_DIR/$l" 1> "$RESULTS_DIR/$l/boot.txt" 104 if [[ $? -ne 0 ]]; then 105 echo "bootanalyze.py failed" 106 exit 1 107 fi 108 echo "$SECONDS sec." 109 if [ -f "$BOOTCHART_TGZ" ]; then 110 cp $BOOTCHART_TGZ "$RESULTS_DIR/$l/bootchart.tgz" 111 fi 112 echo "Sleep for $SLEEP_SEC sec." 113 sleep $SLEEP_SEC 114done 115 116echo 117echo "Complete $LOOPS" 118