xref: /aosp_15_r20/system/extras/boottime_tools/bootanalyze/bootanalyze.sh (revision 288bf5226967eb3dac5cce6c939ccc2a7f2b4fe5)
1*288bf522SAndroid Build Coastguard Worker#!/bin/bash
2*288bf522SAndroid Build Coastguard Worker
3*288bf522SAndroid Build Coastguard Worker# Copyright (C) 2020 The Android Open Source Project
4*288bf522SAndroid Build Coastguard Worker#
5*288bf522SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*288bf522SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*288bf522SAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*288bf522SAndroid Build Coastguard Worker#
9*288bf522SAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
10*288bf522SAndroid Build Coastguard Worker#
11*288bf522SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*288bf522SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*288bf522SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*288bf522SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*288bf522SAndroid Build Coastguard Worker# limitations under the License.
16*288bf522SAndroid Build Coastguard Worker
17*288bf522SAndroid Build Coastguard Workerreadme() {
18*288bf522SAndroid Build Coastguard Worker    echo '
19*288bf522SAndroid Build Coastguard WorkerAnalyze boot-time
20*288bf522SAndroid Build Coastguard Workere.g.
21*288bf522SAndroid Build Coastguard WorkerANDROID_BUILD_TOP="$PWD" \
22*288bf522SAndroid Build Coastguard WorkerCONFIG_YMAL="$ANDROID_BUILD_TOP/system/extras/boottime_tools/bootanalyze/config.yaml" \
23*288bf522SAndroid Build Coastguard Worker    LOOPS=3 \
24*288bf522SAndroid Build Coastguard Worker    RESULTS_DIR="$PWD/bootAnalyzeResults" \
25*288bf522SAndroid Build Coastguard Worker    $ANDROID_BUILD_TOP/system/extras/boottime_tools/bootanalyze/bootanalyze.sh
26*288bf522SAndroid Build Coastguard Worker
27*288bf522SAndroid Build Coastguard WorkerFlags:
28*288bf522SAndroid Build Coastguard Worker-a : Uses "adb reboot" (instead of "adb shell su root svc power reboot") command to reboot
29*288bf522SAndroid Build Coastguard Worker-b : If set grabs bootchart
30*288bf522SAndroid Build Coastguard Worker-w : If set grabs carwatchdog perf stats
31*288bf522SAndroid Build Coastguard Worker-s : Set the device serial for adb
32*288bf522SAndroid Build Coastguard Worker'
33*288bf522SAndroid Build Coastguard Worker    exit
34*288bf522SAndroid Build Coastguard Worker}
35*288bf522SAndroid Build Coastguard Worker
36*288bf522SAndroid Build Coastguard Worker
37*288bf522SAndroid Build Coastguard Workerif [[ -z $ANDROID_BUILD_TOP ]]; then
38*288bf522SAndroid Build Coastguard Worker    echo 'Error: you need to specify ANDROID_BUILD_TOP'
39*288bf522SAndroid Build Coastguard Worker    readme
40*288bf522SAndroid Build Coastguard Workerfi
41*288bf522SAndroid Build Coastguard Workerecho "ANDROID_BUILD_TOP=$ANDROID_BUILD_TOP"
42*288bf522SAndroid Build Coastguard WorkerSCRIPT_DIR="$ANDROID_BUILD_TOP/system/extras/boottime_tools/bootanalyze"
43*288bf522SAndroid Build Coastguard Worker
44*288bf522SAndroid Build Coastguard Worker
45*288bf522SAndroid Build Coastguard Workerif [[ -z $CONFIG_YMAL ]]; then
46*288bf522SAndroid Build Coastguard Worker	CONFIG_YMAL="$SCRIPT_DIR/config.yaml"
47*288bf522SAndroid Build Coastguard Workerfi
48*288bf522SAndroid Build Coastguard Workerecho "CONFIG_YMAL=$CONFIG_YMAL"
49*288bf522SAndroid Build Coastguard Worker
50*288bf522SAndroid Build Coastguard Worker
51*288bf522SAndroid Build Coastguard Workerif [[ -z $RESULTS_DIR ]]; then
52*288bf522SAndroid Build Coastguard Worker	RESULTS_DIR="$PWD/bootAnalyzeResults"
53*288bf522SAndroid Build Coastguard Workerfi
54*288bf522SAndroid Build Coastguard Workerecho "RESULTS_DIR=$RESULTS_DIR"
55*288bf522SAndroid Build Coastguard Workermkdir -p $RESULTS_DIR
56*288bf522SAndroid Build Coastguard Worker
57*288bf522SAndroid Build Coastguard WorkerREBOOT_FLAG=""
58*288bf522SAndroid Build Coastguard WorkerBOOTCHART_FLAG=""
59*288bf522SAndroid Build Coastguard WorkerCARWATCHDOG_FLAG=""
60*288bf522SAndroid Build Coastguard WorkerPY_SERIAL_FLAG=""
61*288bf522SAndroid Build Coastguard WorkerADB_SERIAL_FLAG=""
62*288bf522SAndroid Build Coastguard Worker
63*288bf522SAndroid Build Coastguard Workerwhile getopts 'abws:' OPTION; do
64*288bf522SAndroid Build Coastguard Worker  case "$OPTION" in
65*288bf522SAndroid Build Coastguard Worker    a)
66*288bf522SAndroid Build Coastguard Worker      REBOOT_FLAG="-a"
67*288bf522SAndroid Build Coastguard Worker      ;;
68*288bf522SAndroid Build Coastguard Worker    b)
69*288bf522SAndroid Build Coastguard Worker      BOOTCHART_FLAG="-b"
70*288bf522SAndroid Build Coastguard Worker      ;;
71*288bf522SAndroid Build Coastguard Worker    w)
72*288bf522SAndroid Build Coastguard Worker      CARWATCHDOG_FLAG="-W"
73*288bf522SAndroid Build Coastguard Worker      ;;
74*288bf522SAndroid Build Coastguard Worker    s)
75*288bf522SAndroid Build Coastguard Worker      PY_SERIAL_FLAG="--serial ${OPTARG}"
76*288bf522SAndroid Build Coastguard Worker      ADB_SERIAL_FLAG="-s ${OPTARG}"
77*288bf522SAndroid Build Coastguard Worker      ;;
78*288bf522SAndroid Build Coastguard Worker    ?)
79*288bf522SAndroid Build Coastguard Worker      echo 'Error: Invalid flag set'
80*288bf522SAndroid Build Coastguard Worker      readme
81*288bf522SAndroid Build Coastguard Worker      ;;
82*288bf522SAndroid Build Coastguard Worker  esac
83*288bf522SAndroid Build Coastguard Workerdone
84*288bf522SAndroid Build Coastguard Workershift "$(($OPTIND -1))"
85*288bf522SAndroid Build Coastguard Worker
86*288bf522SAndroid Build Coastguard Worker
87*288bf522SAndroid Build Coastguard Workeradb $ADB_SERIAL_FLAG shell 'touch /data/bootchart/enabled'
88*288bf522SAndroid Build Coastguard Worker
89*288bf522SAndroid Build Coastguard Workerif [[ -z $LOOPS ]]; then
90*288bf522SAndroid Build Coastguard Worker	LOOPS=1
91*288bf522SAndroid Build Coastguard Workerfi
92*288bf522SAndroid Build Coastguard Workerecho "Analyzing boot-time for LOOPS=$LOOPS"
93*288bf522SAndroid Build Coastguard WorkerBOOTCHART_TGZ="/tmp/android-bootchart/bootchart.tgz"
94*288bf522SAndroid Build Coastguard WorkerSTART=1
95*288bf522SAndroid Build Coastguard Worker
96*288bf522SAndroid Build Coastguard WorkerSLEEP_SEC=20
97*288bf522SAndroid Build Coastguard Workerfor (( l=$START; l<=$LOOPS; l++ )); do
98*288bf522SAndroid Build Coastguard Worker    echo "Loop: $l"
99*288bf522SAndroid Build Coastguard Worker    SECONDS=0
100*288bf522SAndroid Build Coastguard Worker    mkdir $RESULTS_DIR/$l
101*288bf522SAndroid Build Coastguard Worker    $SCRIPT_DIR/bootanalyze.py -c $CONFIG_YMAL -G 4M -r \
102*288bf522SAndroid Build Coastguard Worker        $PY_SERIAL_FLAG $REBOOT_FLAG $BOOTCHART_FLAG $CARWATCHDOG_FLAG \
103*288bf522SAndroid Build Coastguard Worker        -o "$RESULTS_DIR/$l" 1> "$RESULTS_DIR/$l/boot.txt"
104*288bf522SAndroid Build Coastguard Worker    if [[ $? -ne 0 ]]; then
105*288bf522SAndroid Build Coastguard Worker        echo "bootanalyze.py failed"
106*288bf522SAndroid Build Coastguard Worker        exit 1
107*288bf522SAndroid Build Coastguard Worker    fi
108*288bf522SAndroid Build Coastguard Worker    echo "$SECONDS sec."
109*288bf522SAndroid Build Coastguard Worker    if [ -f "$BOOTCHART_TGZ" ]; then
110*288bf522SAndroid Build Coastguard Worker        cp $BOOTCHART_TGZ "$RESULTS_DIR/$l/bootchart.tgz"
111*288bf522SAndroid Build Coastguard Worker    fi
112*288bf522SAndroid Build Coastguard Worker    echo "Sleep for $SLEEP_SEC sec."
113*288bf522SAndroid Build Coastguard Worker    sleep $SLEEP_SEC
114*288bf522SAndroid Build Coastguard Workerdone
115*288bf522SAndroid Build Coastguard Worker
116*288bf522SAndroid Build Coastguard Workerecho
117*288bf522SAndroid Build Coastguard Workerecho "Complete $LOOPS"
118