Add some hostside scripts to make life easier

- Take a heapdump and open it with ahat on the browser:
runhat2 PID_OR_PROCESS_NAME

- Take thread stacktrace dump
stacktrace PID_OR_PROCESS_NAME

TODO: Remove runhat? Is there anyone still using it?

Bug: 110088132
Test: stacktrace system_server
Test: stacktrace $(pid system_server)
Test: stacktrace com.android.systemui
Test: runhat2 system_server
Change-Id: I8ee4b51ac9097d5342d2d4209407a4b8ac4d5945
This commit is contained in:
Makoto Onuki
2018-06-13 17:46:37 -07:00
parent d588b42f64
commit 5cd3d2c9f0
3 changed files with 217 additions and 0 deletions

64
scripts/stacktrace Executable file
View File

@@ -0,0 +1,64 @@
#!/bin/bash
# Copyright (C) 2018 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
. "${0%/*}"/bash_util.bash
function usage() {
cat 1>&2 <<"EOF"
$script_name: print stacktrace of an android process.
Usage: $script_name PID_OR_PROCESS_NAME
EOF
exit 1
}
pid="$(resolve_pid "$1" || usage)"
info "Dumping stacktrace from pid $pid ..."
# Send sigquit to initiate stacktrace.
ts="$(get_last_logcat_timestamp)"
do_adb shell kill -s sigquit "$pid"
# Watch logcat to catch finish, and then obtain the filename.
# First, set up a timer for timeout.
(
sleep 10
warn "Timed out waiting for tombstoned. (wrong PID?)"
kill -s usr1 $$
) &
timer_pid=$!
trap 'exit 0' USR1
# --------- beginning of main
# 06-14 00:12:57.384 1058 925 925 E /system/bin/tombstoned: Traces for pid 1204 written to: /data/anr/trace_01
info "Waiting for tombstoned to finish writing..."
log="$(do_adb logcat -T "$ts" -e "Traces for pid $pid written to" -m 1 | sed -e 1d)" # Remoe the header
file="${log## }" # Remove everything until the last space.
do_adb shell cat "$file" || true # Somehow this returns 1?
# Success, kill the timer process.
kill "$timer_pid"