blob: 50ccdf5d634a969899ed5d32b32098fd49fb8f4d [file] [log] [blame]
Josh Gaoc0d86862020-04-20 17:23:32 -07001#!/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
16set -euxo pipefail
17
18adb root
19adb shell logcat -c -G128M
20adb shell setprop persist.adb.trace_mask 1
21adb shell killall adbd
22
23# TODO: Add `adb transport-id` and wait-for-offline on it.
24sleep 5
25
26adb wait-for-device shell rm "/data/misc/trace/*"
27
28./test_device.py
29
30# Dump traces from the currently running adbd.
31adb shell killall -37 adbd
32
33echo Waiting for adbd to finish dumping traces
34sleep 5
35
36TRACEDIR=`mktemp -d`
37adb pull /data/misc/trace "$TRACEDIR"/
38echo Pulled traces to $TRACEDIR
39
40
41# Identify which of the trace files are actually adbd, in case something else exited simultaneously.
42ADBD_PIDS=$(adb shell "logcat -d -s adbd --format=process | grep 'adbd started' | cut -c 3-7 | tr -d ' ' | sort | uniq")
43mkdir "$TRACEDIR"/adbd_traces
44
45adb shell 'setprop persist.adb.trace_mask 0; killall adbd'
46
47IFS=$'\n'
48for PID in $ADBD_PIDS; do
49 cp "$TRACEDIR"/trace/clang-$PID-*.profraw "$TRACEDIR"/adbd_traces 2>/dev/null || true
50done
51
52llvm-profdata merge --output="$TRACEDIR"/adbd.profdata "$TRACEDIR"/adbd_traces/*
53
54cd $ANDROID_BUILD_TOP
55llvm-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
60llvm-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