"main"prio=5tid=1Blocked | group="main"sCount=1dsCount=0obj=0x74f9bbe8self=0xe7084400 | sysTid=28210nice=0cgrp=defaultsched=0/0handle=0xe9dcd534 | state=S schedstat=(13454428309928953492) utm=121stm=13core=3HZ=100 | stack=0xff3b6000-0xff3b8000stackSize=8MB | held mutexes= at com.ss.android.common.applog.LogReaper.insertCrashLog(SourceFile:98) - waiting to lock <0x0d3fbd00> (a com.ss.android.common.applog.LogReaper) held by thread34 at com.ss.android.common.applog.AppLog.uncaughtException(SourceFile:1408 at u.aly.n.uncaughtException(SourceFile:34) at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068) at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
等待对象:
1
waiting to lock <0x0d3fbd00> (a com.ss.android.common.applog.LogReaper) held by thread34
held by thread 34 是 ART tid,要在同一次 dump 找 tid=34;不是去找 Linux TID 34。这里对应的 Linux TID 是 28274。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
"LogReaper"prio=5tid=34TimedWaiting | group="main"sCount=1dsCount=0obj=0x12fcaba0self=0xcb226e00 | sysTid=28274nice=0cgrp=defaultsched=0/0handle=0xc9f9b920 | state=S schedstat=(77341565269270880) utm=7stm=0core=5HZ=100 | stack=0xc9e99000-0xc9e9b000stackSize=1038KB | held mutexes= at java.lang.Object.wait!(Native method) - waiting on <0x00fc7065> (a java.util.concurrent.atomic.AtomicInteger) at java.lang.Object.wait(Object.java:407) at com.ss.android.action.b.d.a(SourceFile:216) at com.ss.android.newmedia.b.onLogSessionBatchEvent(SourceFile:468) at com.ss.android.common.applog.DBHelper.batchSession(SourceFile:616) - locked <0x0d4ff1c4> (a com.ss.android.common.applog.DBHelper) at com.ss.android.common.applog.LogReaper.switchSession(SourceFile:175) at com.ss.android.common.applog.LogReaper.switchSession(SourceFile:153) at com.ss.android.common.applog.LogReaper.processItem(SourceFile:122) - locked <0x0d3fbd00> (a com.ss.android.common.applog.LogReaper) at com.ss.android.common.applog.LogReaper.run(SourceFile:632)
下一层等待:
1
waiting on <0x00fc7065> (a java.util.concurrent.atomic.AtomicInteger)
05-0100:51:39.594 1449 5234I am_anr : [0,2169,com.xxx.weather2,820526660,Input dispatching timed out (Waiting to send key event because the focused window has not finished processing all of the input events that were previously delivered to it. Outbound queue length: 0. Wait queue length: 1.)]
再看 ANR in 的 CPU 记录:
1 2 3 4 5 6 7 8 9
05-0100:51:53.974 1449 5234E ActivityManager: ANR in com.xxx.weather2 (com.xxx.weather2/com.xxx.weather.xxxMainActivity) 05-0100:51:53.974 1449 5234E ActivityManager: PID:2169 05-0100:51:53.974 1449 5234E ActivityManager: Reason:Input dispatching timed out (Waiting to send key event because the focused window has not finished processing all of the input events that were previously delivered to it. Outbound queue length: 0. Wait queue length: 1.) 05-01 00:51:53.974 1449 5234 E ActivityManager: Parent: com.xxx.weather2/com.xxx.weather.xxxMainActivity 05-01 00:51:53.974 1449 5234 E ActivityManager: Load: 29.89 / 31.82 / 32.27 05-01 00:51:53.974 1449 5234 E ActivityManager: CPU usage from 4583ms to 12043ms later (2020-05-01 00:51:44.177 to 2020-05-01 00:51:51.637): 05-01 00:51:53.974 1449 5234 E ActivityManager: 18% 1449/system_server: 9.1% user + 9.3% kernel / faults: 7819 minor 1 major 05-01 00:51:53.974 1449 5234 E ActivityManager: 10% 720/surfaceflinger: 6.2% user + 4.4% kernel / faults: 734 minor 26 major 05-01 00:51:53.974 1449 5234 E ActivityManager: 10% 651/android.hardware.audio@5.0-service-mediatek: 9.5% user + 0.8% kernel / faults: 1 minor 4 major
CPU 摘录的采样窗口是 00:51:44.177–51.637,已经晚于 00:51:39.594 的 am_anr。只列三个进程,Load 又在 30 左右,因此不能据此认定“CPU 不忙,排除系统负载”。应找超时前的调度、I/O/内存压力及冻结状态。
ANR 后的 unfreeze reason: Signal 是一个线索:既然这里在解冻,那么之前是不是被冻结了,才没能响应输入?沿着这个疑问往前搜,可以找到 00:51:04.000 的 freeze 记录。先把原始行时间排在一起,再检查这个猜想能否成立:
时间
片段实际记录的内容
00:51:04.000
厂商 Hans 对 UID 10182 / weather2 记录 freeze,原因 LcdOff
00:51:04.471–04.477
系统输入策略记录 BACK DOWN 入队前/分发前拦截;不是应用已处理的证据
00:51:34.478
分发前策略记录 BACK UP;距 DOWN 约 30 秒,且两者 downTime 不同,不能补成普通成对按键
00:51:39.484 / 39.594
Input dispatch 超时日志 / am_anr
00:51:40.868–40.870
Signal Catcher 响应、Hans unfreeze reason: Signal、应用丢弃/取消事件和长输入耗时日志
// 约 5 秒后记录超时:窗口仍有此前投递的事件未完成 05-01 00:51:39.484 1449 1620 I WindowManager: Input event dispatching timed out sending to com.xxx.weather2/com.xxx.weather.xxxMainActivity. Reason: Waiting to send key event because the focused window has not finished processing all of the input events that were previously delivered to it. Outbound queue length: 0. Wait queue length: 1. 05-01 00:51:39.484 2256 5518 I QUALITY-TOTAL: exp: anr 05-01 00:51:39.594 1449 5234 I am_anr : [0,2169,com.xxx.weather2,820526660,Input dispatching timed out (Waiting to send key event because the focused window has not finished processing all of the input events that were previously delivered to it. Outbound queue length: 0. Wait queue length: 1.)] 05-01 00:51:39.593 1449 1620 D ActivityManager: ANR post Runnable for ProcessRecord{ae0c833 2169:com.xxx.weather2/u0a182} to deal with anr happend at 38847248@#@2169 05-01 00:51:39.593 1449 1620 D ActivityManager: ANR caller(2) = com.android.server.am.ActivityManagerService$LocalService.inputDispatchingTimedOut:19872 com.android.server.wm.ActivityRecord.keyDispatchingTimedOut:2641 com.android.server.wm.AppWindowToken.keyDispatchingTimedOut:2007 com.android.server.wm.InputManagerCallback.notifyANR:111 com.android.server.input.InputManagerService.notifyANR:1822 <bottom of call stack> <bottom of call stack> <bottom of call stack>
// Signal Catcher 有响应;此残缺行未给出信号号或发送端 05-01 00:51:40.868 2169 2202 I oloros.weather: Thread[7,tid=2202,WaitingInMainSignalCatcherLoop,Thread*=0xd9878400,peer=0x138c0250,"Signal Catcher"]: reacting to signal
// Hans 记录以 Signal 为原因的解冻,具体触发逻辑需厂商源码 05-01 00:51:40.869 1449 9811 I xxxHansManager : unfreeze uid: 10182 package: com.xxx.weather2 reason: Signal 05-01 00:51:40.869 2169 2202 I oloros.weather: 05-01 00:51:40.869 2169 2169 W ViewRootImpl[xxxMainActivity]: Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x8, repeatCount=0, eventTime=38812125, downTime=38812125, deviceId=-1, source=0x101, displayId=0 }, hasFocus:true, mStopped:true, mPausedForTransition:false 05-01 00:51:40.869 2169 2169 W ViewRootImpl[xxxMainActivity]: Cancelling event due to no window focus: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x28, repeatCount=0, eventTime=38847249, downTime=38812125, deviceId=-1, source=0x101, displayId=0 }, hasFocus:true, mStopped:true, mPausedForTransition:false
// InputDispatcher 报告上一个输入事件耗时 36391.9 ms,不是 CPU 时间 05-01 00:51:40.869 1449 1620 I InputDispatcher: Window '1b36ae8 com.xxx.weather2/com.xxx.weather.xxxMainActivity (server)' spent 36391.9ms processing the last input event: KeyEvent 05-01 00:51:40.869 2169 2169 V ViewRootImpl[xxxMainActivity]: Sending input event to IME: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x28, repeatCount=0, eventTime=38847249, downTime=38812125, deviceId=-1, source=0x101, displayId=0 } 05-01 00:51:40.870 2169 2169 I Choreographer: Skipped 2212 frames! The application may be doing too much work on its main thread.
这些记录支持“冻结期间输入迟迟未完成,解冻后继续处理”的调查方向,但还缺实际 freezer 状态、完整输入序号及厂商解冻逻辑,不能仅凭日志相邻就确认因果关系。ANR 抓栈通常涉及 SIGQUIT(3),这里的残缺 Signal Catcher 行没有直接列出信号号;也不能把跨线程的毫秒级打印顺序当成执行因果顺序。
36391.9 ms 是 InputDispatcher 的耗时值。墙钟 04.471→40.869 相差约 36398 ms,不能逐位视作相同计时口径;分发前 04.477 更接近,但仍需单调时钟/事件记录确认。Skipped 2212 frames 也不证明主线程一直在做 CPU 运算。这个案例应提交系统冻结/输入团队继续核对,不把 2020 年 Hans 行为推广为现代 AOSP freezer 的固定流程。
19:44:56.815 2515 25056 I am_anr : [0,3365,com.xxx.launcher,819478085,Input dispatching timed out (Waiting to send key event because the focused window has not finished processing all of the input events that were previously delivered to it. Outbound queue length: 0. Wait queue length: 9.)]
"main"prio=5tid=1Native | group="main"sCount=1dsCount=0flags=1obj=0x72a50cd0self=0x6f7ae10800 | sysTid=3365nice=-10cgrp=defaultsched=0/0handle=0x700123bed8 | state=S schedstat=(37451337214473599138010494263) utm=26967stm=10484core=0HZ=100 |stack=0x7fc0270000-0x7fc0272000stackSize=8192KB | held mutexes= kernel: (couldn't read /proc/self/task/3365/stack) native: #00pc0000000000071a8c /apex/com.android.runtime/lib64/bionic/libc.so (syscall+28) native: #01pc0000000000075710 /apex/com.android.runtime/lib64/bionic/libc.so (__futex_wait_ex(voidvolatile*,bool,int,bool, timespecconst*)+140) native: #02pc00000000000d9744 /apex/com.android.runtime/lib64/bionic/libc.so (pthread_cond_wait+60) native: #03pc00000000002bf5e8 /system/lib64/libhwui.so (android::uirenderer::renderthread::DrawFrameTask::postAndWait()+168) native: #04pc00000000002bf510 /system/lib64/libhwui.so (android::uirenderer::renderthread::DrawFrameTask::drawFrame()+44)12 at android.graphics.HardwareRenderer.nSyncAndDrawFrame(Native method) at android.graphics.HardwareRenderer.syncAndDrawFrame(HardwareRenderer.java:422) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:671) at android.view.ViewRootImpl.draw(ViewRootImpl.java:3983) - locked <0x030694da> (a java.lang.Object) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3782) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3085) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1994) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8201) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1085) at android.view.Choreographer.doCallbacks(Choreographer.java:908) at android.view.Choreographer.doFrame(Choreographer.java:835) at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:1013) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:238) at android.app.ActivityThread.main(ActivityThread.java:7798) at java.lang.reflect.Method.invoke(Native method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
"main" prio=5 tid=1 Native held mutexes= kernel: (couldn't read /proc/self/task/11003/stack) native: #00 pc 000492a4 /system/lib/libc.so (nanosleep+12) native: #01 pc 0002dc21 /system/lib/libc.so (usleep+52) native: #02 pc 00009cab /system/lib/libsqlite.so (???) native: #03 pc 00011119 /system/lib/libsqlite.so (???) native: #04 pc 00016455 /system/lib/libsqlite.so (???) native: #16 pc 0000fa29 /system/lib/libsqlite.so (???) native: #17 pc 0000fad7 /system/lib/libsqlite.so (sqlite3_prepare16_v2+14) native: #18 pc 0007f671 /system/lib/libandroid_runtime.so (???) native: #19 pc 002b4721 /system/framework/arm/boot-framework.oat (Java_android_database_sqlite_SQLiteConnection_nativePrepareStatement__JLjava_lang_String_2+116) at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:294) at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215) at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193) at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463) at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185) at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177) at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:808) locked <0x0db193bf> (a java.lang.Object) at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793) at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696) at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:690) at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:299) at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223) at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163) locked <0x045a4a8c> (a com.xxxx.video.common.data.DataBaseHelper) at com.xxxx.video.common.data.DataBaseORM.<init>(DataBaseORM.java:46) at com.xxxx.video.common.data.DataBaseORM.getInstance(DataBaseORM.java:53) locked <0x017095d5> (a java.lang.Class<com.xxxx.video.common.data.DataBaseORM>)