- 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
64 lines
1.7 KiB
Bash
Executable File
64 lines
1.7 KiB
Bash
Executable File
#!/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" |