Josh Gao | c0d8686 | 2020-04-20 17:23:32 -0700 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # Copyright (C) 2020 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | set -euxo pipefail |
| 17 | |
| 18 | adb root |
| 19 | adb shell logcat -c -G128M |
| 20 | adb shell setprop persist.adb.trace_mask 1 |
| 21 | adb shell killall adbd |
| 22 | |
| 23 | # TODO: Add `adb transport-id` and wait-for-offline on it. |
| 24 | sleep 5 |
| 25 | |
| 26 | adb wait-for-device shell rm "/data/misc/trace/*" |
| 27 | |
| 28 | ./test_device.py |
| 29 | |
| 30 | # Dump traces from the currently running adbd. |
| 31 | adb shell killall -37 adbd |
| 32 | |
| 33 | echo Waiting for adbd to finish dumping traces |
| 34 | sleep 5 |
| 35 | |
| 36 | TRACEDIR=`mktemp -d` |
| 37 | adb pull /data/misc/trace "$TRACEDIR"/ |
| 38 | echo Pulled traces to $TRACEDIR |
| 39 | |
| 40 | |
| 41 | # Identify which of the trace files are actually adbd, in case something else exited simultaneously. |
| 42 | ADBD_PIDS=$(adb shell "logcat -d -s adbd --format=process | grep 'adbd started' | cut -c 3-7 | tr -d ' ' | sort | uniq") |
| 43 | mkdir "$TRACEDIR"/adbd_traces |
| 44 | |
| 45 | adb shell 'setprop persist.adb.trace_mask 0; killall adbd' |
| 46 | |
| 47 | IFS=$'\n' |
| 48 | for PID in $ADBD_PIDS; do |
| 49 | cp "$TRACEDIR"/trace/clang-$PID-*.profraw "$TRACEDIR"/adbd_traces 2>/dev/null || true |
| 50 | done |
| 51 | |
| 52 | llvm-profdata merge --output="$TRACEDIR"/adbd.profdata "$TRACEDIR"/adbd_traces/* |
| 53 | |
| 54 | cd $ANDROID_BUILD_TOP |
| 55 | llvm-cov report --instr-profile="$TRACEDIR"/adbd.profdata \ |
| 56 | $ANDROID_PRODUCT_OUT/apex/com.android.adbd/bin/adbd \ |
| 57 | --show-region-summary=false \ |
| 58 | /proc/self/cwd/system/core/adb |
| 59 | |
| 60 | llvm-cov show --instr-profile="$TRACEDIR"/adbd.profdata \ |
| 61 | $ANDROID_PRODUCT_OUT/apex/com.android.adbd/bin/adbd \ |
| 62 | --format=html \ |
| 63 | /proc/self/cwd/system/core/adb > $TRACEDIR/report.html |