如何使Java线程转储在Android中?线程、Java、Android

2023-09-05 09:23:48 作者:把你从记忆中删除

我只是想从java虚拟机线程转储全部,看看什么线程锁,什么等待着解开一些资源的线程。喜欢的东西描述这里。 我trye​​d杀死受精卵的过程,但没有结果。

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.

推荐答案

最简单的方法是用DDMS,或ADT插件在Eclipse中。请参阅http://developer.android.com/tools/debugging/ddms.html基本说明。总之,进入设备视图中,选择你感兴趣的应用程序,请启用确保线程更新,并切换到主题视图。您将获得在这个过程中线程的实时更新列表。在一个线程双击将抓住当前的堆栈状态的快照。

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.

如果你有一个开发者/ root权限的设备,你可以问Dalvik虚拟机通过发送 SIGQUIT 的应用过程中,你有兴趣来转储线程堆栈。对于例如,如果你想看到日历应用程序堆栈的所有线程,你可以做这样的事情:

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 kill -3 2596

在logcat的输出会这样说:

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 .

您的信号处理每一次,日志被追加到该文件。可能还有其他的东西在里面,所以你需要搜索 PID 2596

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:
...

这样在DDMS螺纹视图的优点在于,如果线程粘贴在监视器上,堆栈转储会给你什么对象被锁定,并且其中线程当前持有锁的指示。

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.

受精卵的过程是不是与此有关;根据定义,它没有运行的应用程序。因为它没有一个JDWP线程,并且不听SIGQUIT,你不能得到一个堆栈跟踪信息也无妨。

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.