I just want to get all dumps from java virtual machine threads, to look at what the threads lock and what threads waiting to unlock some resources. Something like is described here. I've tryed to kill Zygote process but with no results.
The easiest way is with DDMS, or the ADT plugin in Eclipse. See http://developer.android.com/tools/debugging/ddms.html for basic instructions. In short, go into the Device view, select the application you're interested in, make sure thread updates are enabled, and switch to the Threads view. You will get a live-updated list of threads in that process. Double-clicking on a thread will grab a snapshot of the current stack state.
You can use select-all and copy in the thread dump to copy & paste the stack trace.
If you have a developer / rooted device, you can ask the Dalvik VM to dump thread stacks by sending a SIGQUIT
to the app process you're interested in. For example, if you wanted to see the stacks for all threads in the Calendar app, you could do something like this:
% adb shell ps | grep android.calendar
u0_a6 2596 127 912804 48296 ffffffff b6f62c10 S com.google.android.calendar
# 2596 is the process ID
% adb shell run-as com.google.android.colendar kill -3 2596
The logcat output will say something like:
I/dalvikvm( 2596): Wrote stack traces to '/data/anr/traces.txt'
So, pull that:
% adb pull /data/anr/traces.txt .
Every time you signal a process, the logs are appended to that file. There may be other stuff in there, so you need to search for pid 2596
:
----- pid 2596 at 2012-11-27 12:48:38 -----
Cmd line: com.google.android.calendar
DALVIK THREADS:
...
The advantage of doing this over the DDMS thread view is that, if the thread is stuck on a monitor, the stack dump will give you an indication of what object is locked and which thread currently holds the lock.
The zygote process isn't relevant here; by definition it isn't running an app. Since it doesn't have a JDWP thread, and doesn't listen for SIGQUIT, you can't get a stack trace out of it anyway.
Just debug your app on your phone in Android Studio; then in the "Debug view" Alt+5
just press the "Camera" button at the bottom left corner, to obtain a dump of all stacktraces, including locks they are holding.
Taking the commands from the answer, and putting it all up together, here is the following script. Putting it into the dump.sh file and executing, it will find the needed PID, create a new file with current timestamp and next it will fetch the Thread-Dump into it.
This command can be useful when one has a very short period of time to fetch the dump.
Before using it, make sure that traces are put into the file /data/anr/traces.txt
or replace this value in the script.
#!/bin/sh
pid=`./adb shell ps | grep android.calendar | awk '{print $2}'`
echo $pid
f=$(date +%s%N)
echo $f
./adb shell run-as com.google.android.calendar kill -3 $pid
./adb pull /data/anr/traces.txt $f
As an alternative file name, one can use f=$(date +"%T.%6N")
to get human readable timestamp. It would be easier to find the needed file.
If you don't have a rooted device and your app isn't a debug build, you can still generate a bug report from developer options to get the thread dump. The dumps are under the VM TRACES JUST NOW section of the bugreport*.txt file.
It's quicker if you know the ID of the thread you're suspecting. You can get the PID of the app by calling:
adb shell ps -A | grep com.example.myapp
and the thread ID with:
adb shell ps -T | grep <pid>
If you switch to the DDMS view in Eclipse you have some tools to look at threads. Is that what you're looking for?
I'm guessing you need the threads within an app. For this, you can use the DDMS view on the ADT eclipse plugin. Here's the doc http://developer.android.com/tools/debugging/ddms.html#thread
© 2022 - 2024 — McMap. All rights reserved.