您的位置:首页 > 其它

ANR backtrace含义

2016-05-05 15:03 176 查看
在thread_state.h中定义了线程状态,
enum ThreadState {
//                                   Thread.State   JDWP state
kTerminated = 66,                 // TERMINATED     TS_ZOMBIE    Thread.run has returned, but Thread* still around
kRunnable,                        // RUNNABLE       TS_RUNNING   runnable
kTimedWaiting,                    // TIMED_WAITING  TS_WAIT      in Object.wait() with a timeout
kSleeping,                        // TIMED_WAITING  TS_SLEEPING  in Thread.sleep()
kBlocked,                         // BLOCKED        TS_MONITOR   blocked on a monitor
kWaiting,                         // WAITING        TS_WAIT      in Object.wait()
kWaitingForGcToComplete,          // WAITING        TS_WAIT      blocked waiting for GC
kWaitingForCheckPointsToRun,      // WAITING        TS_WAIT      GC waiting for checkpoints to run
kWaitingPerformingGc,             // WAITING        TS_WAIT      performing GC
kWaitingForDebuggerSend,          // WAITING        TS_WAIT      blocked waiting for events to be sent
kWaitingForDebuggerToAttach,      // WAITING        TS_WAIT      blocked waiting for debugger to attach
kWaitingInMainDebuggerLoop,       // WAITING        TS_WAIT      blocking/reading/processing debugger events
kWaitingForDebuggerSuspension,    // WAITING        TS_WAIT      waiting for debugger suspend all
kWaitingForJniOnLoad,             // WAITING        TS_WAIT      waiting for execution of dlopen and JNI on load code
kWaitingForSignalCatcherOutput,   // WAITING        TS_WAIT      waiting for signal catcher IO to complete
kWaitingInMainSignalCatcherLoop,  // WAITING        TS_WAIT      blocking/reading/processing signals
kWaitingForDeoptimization,        // WAITING        TS_WAIT      waiting for deoptimization suspend all
kWaitingForMethodTracingStart,    // WAITING        TS_WAIT      waiting for method tracing to start
kWaitingForVisitObjects,          // WAITING        TS_WAIT      waiting for visiting objects
kWaitingForGetObjectsAllocated,   // WAITING        TS_WAIT      waiting for getting the number of allocated objects
kStarting,                        // NEW            TS_WAIT      native thread started, not yet ready to run managed code
kNative,                          // RUNNABLE       TS_RUNNING   running in a JNI native method
kSuspended,                       // RUNNABLE       TS_RUNNING   suspended by GC or debugger
};

在ANR时,activityManager会发送SIGQUIT给ANR线程杀死该线程。SIGQUIT的处理流程里:

void ThreadList::DumpForSigQuit(std::ostream& os) {
{
ScopedObjectAccess soa(Thread::Current());
// Only print if we have samples.
if (suspend_all_historam_.SampleSize() > 0) {
Histogram<uint64_t>::CumulativeData data;
suspend_all_historam_.CreateHistogram(&data);
suspend_all_historam_.PrintConfidenceIntervals(os, 0.99, data);  // Dump time to suspend.
}
}
Dump(os);
DumpUnattachedThreads(os);
}

会打印出所有线程的状态

"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 obj=0x75062458 self=0x7fadb7ba00
| sysTid=15115 nice=0 cgrp=default sched=0/0 handle=0x7fb10fc158
| state=D schedstat=( 0 0 0 ) utm=1521 stm=548 core=0 HZ=100
| stack=0x7ff8652000-0x7ff8654000 stackSize=8MB
| held mutexes=

其中state是=D是读取proc/self/task/%taskid/state目录得到的结果。

S代表sleeping,D代表suspend且处于uninterruptible状态,R代表runnable状态,Z代表ZOMBIE,T代表stop的状态。

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: