如何定位android anr阻塞UI线程的代码


   
  ----- pid 172 at 2012-05-03 11:29:40 -----
  
Cmd line: com.android.systemui

DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
"main" prio=5 tid=1 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x4019f680 self=0x115d8
| sysTid=172 nice=0 sched=0/0 cgrp=default handle=-1342909328
| schedstat=( 47573317000 51093216000 144232 ) utm=3528 stm=1229 core=0
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:119)
at android.os.Looper.loop(Looper.java:116)
at android.app.ActivityThread.main(ActivityThread.java:3997)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)

"Binder Thread #12" prio=5 tid=18 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40ac7b50 self=0x490628
| sysTid=20889 nice=0 sched=0/0 cgrp=default handle=2176152
| schedstat=( 58957000 1918911000 419 ) utm=2 stm=3 core=0
at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #11" prio=5 tid=17 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40ac7a08 self=0x46ffe8
| sysTid=20888 nice=0 sched=0/0 cgrp=default handle=4652968
| schedstat=( 60642000 2376123000 455 ) utm=4 stm=2 core=0
at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #10" prio=5 tid=16 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40b660d8 self=0x375e28
| sysTid=20418 nice=0 sched=0/0 cgrp=default handle=2537248
| schedstat=( 64940000 3974033000 585 ) utm=2 stm=4 core=0
at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #9" prio=5 tid=15 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40a90550 self=0x4f6790
| sysTid=12607 nice=0 sched=0/0 cgrp=default handle=4593776
| schedstat=( 117594000 10506057000 1537 ) utm=3 stm=8 core=0
at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #8" prio=5 tid=14 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40c78970 self=0x34f2c0
| sysTid=11632 nice=0 sched=0/0 cgrp=default handle=3469816
| schedstat=( 140074000 11267279000 1878 ) utm=2 stm=12 core=1
at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #7" prio=5 tid=13 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x407e7d58 self=0x1a3958
| sysTid=10976 nice=0 sched=0/0 cgrp=default handle=4654128
| schedstat=( 147763000 14893146000 2088 ) utm=4 stm=11 core=1
at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #6" prio=5 tid=12 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40ab4d80 self=0x30f310
| sysTid=5922 nice=0 sched=0/0 cgrp=default handle=2920584
| schedstat=( 217090000 23118812000 3369 ) utm=6 stm=15 core=1
at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #5" prio=5 tid=11 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40e26268 self=0x1a31e0
| sysTid=4429 nice=0 sched=0/0 cgrp=default handle=1722072
| schedstat=( 276858000 22065845000 3910 ) utm=8 stm=19 core=1
at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #4" prio=5 tid=10 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40ab2850 self=0x375f70
| sysTid=4253 nice=0 sched=0/0 cgrp=default handle=3360168
| schedstat=( 312554000 25228177000 4060 ) utm=10 stm=21 core=0
at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #3" prio=5 tid=9 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40b33ed0 self=0x462d00
| sysTid=1789 nice=0 sched=0/0 cgrp=default handle=2926192
| schedstat=( 468531000 26894009000 5078 ) utm=15 stm=31 core=1
at dalvik.system.NativeStart.run(Native Method)

"SystemUI StorageNotification" prio=5 tid=8 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x4080fe60 self=0x16c4b0
| sysTid=285 nice=0 sched=0/0 cgrp=default handle=1509992
| schedstat=( 183004000 28409341000 3970 ) utm=6 stm=12 core=1
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:119)
at android.os.Looper.loop(Looper.java:116)
at android.os.HandlerThread.run(HandlerThread.java:60)

"Binder Thread #2" prio=5 tid=7 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x407b3b40 self=0xb5678
| sysTid=179 nice=0 sched=0/0 cgrp=default handle=1282824
| schedstat=( 668392000 27902965000 5761 ) utm=29 stm=37 core=0
at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #1" prio=5 tid=6 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x407b2178 self=0x138728
| sysTid=178 nice=0 sched=0/0 cgrp=default handle=727216
| schedstat=( 781790000 29099266000 5917 ) utm=40 stm=38 core=0
at dalvik.system.NativeStart.run(Native Method)

"Compiler" daemon prio=5 tid=5 VMWAIT
| group="system" sCount=1 dsCount=0 obj=0x407ae088 self=0xb7090
| sysTid=176 nice=0 sched=0/0 cgrp=default handle=723616
| schedstat=( 1113693000 29457938000 9546 ) utm=55 stm=56 core=0
at dalvik.system.NativeStart.run(Native Method)

"Signal Catcher" daemon prio=5 tid=4 RUNNABLE
| group="system" sCount=0 dsCount=0 obj=0x407adfa8 self=0xb08f8
| sysTid=175 nice=0 sched=0/0 cgrp=default handle=742096
| schedstat=( 301757000 28945878000 4107 ) utm=1 stm=29 core=1
at dalvik.system.NativeStart.run(Native Method)

"GC" daemon prio=5 tid=3 VMWAIT
| group="system" sCount=1 dsCount=0 obj=0x407adee0 self=0xb3968
| sysTid=174 nice=0 sched=0/0 cgrp=default handle=1092104
| schedstat=( 2347864000 31518782000 13712 ) utm=207 stm=27 core=0
at dalvik.system.NativeStart.run(Native Method)

"HeapWorker" daemon prio=5 tid=2 VMWAIT
| group="system" sCount=1 dsCount=0 obj=0x407ade08 self=0xb0c98
| sysTid=173 nice=0 sched=0/0 cgrp=default handle=753600
| schedstat=( 1557123000 33218492000 6592 ) utm=112 stm=43 core=1
at dalvik.system.NativeStart.run(Native Method)

----- end 172 -----

请输入图片描述

Android androidanr

Taokaka 12 years, 6 months ago

个人经验,这种东西没什么大的用处,anr大部分原因如问题所示,在UI线程里面做了长时间的操作,所谓5秒时间值,这应该是很直观就能感受的。唯一解决方法就是把长时间的任务放到后台线程去执行,别无他法。
请参考 @android执行长时间操作如何处理,如何避免ANR?
@Android如何避免阻塞主线程

日常必须的 answered 12 years, 6 months ago

Your Answer