首先贴一下trace 文件
1Process: com.oppo.reader 2PID: 20358 3Time: 2933175644_1545041895232 4Flags: 0x38d83e44 5Package: com.oppo.reader v62301 (6.2.3.20181030) 6PID: 20358 7Foreground: Yes 8Activity: com.oppo.reader/com.zhangyue.iReader.read.ui.Activity_BookBrowser_TXT 9Subject: Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 2. Wait queue head age: 8825.0ms.) 10Build: OPPO/PBFM00/PBFM00:8.1.0/OPM1.171019.026/1541766248:user/release-keys 11 12CPU usage from 0ms to 6451ms later (2018-12-17 18:18:08.726 to 2018-12-17 18:18:15.177): 13 100% 20358/com.oppo.reader: 97% user + 3.5% kernel / faults: 4111 minor 3 major 14 39% 1895/system_server: 27% user + 11% kernel / faults: 3126 minor 26 major 15 0.2% 1167/media.codec: 0.2% user + 0% kernel / faults: 4081 minor 16 4% 17827/com.android.systemui: 3.2% user + 0.7% kernel / faults: 1640 minor 224 major 17 3.7% 2835/com.android.phone: 3.2% user + 0.4% kernel / faults: 434 minor 18 3.4% 687/surfaceflinger: 2.4% user + 0.9% kernel / faults: 454 minor 19 2.4% 11552/kworker/u16:8: 0% user + 2.4% kernel 20 0% 1155/media.extractor: 0% user + 0% kernel / faults: 2832 minor 21 1.2% 654/android.hardware.graphics.composer@2.1-service: 0.7% user + 0.4% kernel / faults: 11 minor 22 1.2% 17450/com.coloros.floatassistant:float: 1% user + 0.1% kernel / faults: 146 minor 23 1% 451/logd: 0% user + 1% kernel / faults: 10 minor 24 0% 3789/com.coloros.appmanager: 0% user + 0% kernel / faults: 270 minor 25 0.9% 21424/klogd: 0.3% user + 0.6% kernel / faults: 1 minor 26 0.7% 659/android.hardware.sensors@1.0-service: 0.1% user + 0.6% kernel 27 0.7% 10558/kworker/u16:0: 0% user + 0.7% kernel 28 0% 17711/com.oppo.gestureservice: 0% user + 0% kernel / faults: 407 minor 29 0% 17730/com.color.eyeprotect: 0% user + 0% kernel / faults: 592 minor 30 0% 17754/com.oppo.resmonitor: 0% user + 0% kernel / faults: 597 minor 5 major 31 0.7% 21425/xkit_10: 0.7% user + 0% kernel 32 0.6% 86/kcompactd0: 0% user + 0.6% kernel 33 0.6% 11551/kworker/u16:7: 0% user + 0.6% kernel 34 0.6% 21426/xkit_10: 0.3% user + 0.3% kernel / faults: 6 minor 35 0.4% 329/mmc-cmdqd/0: 0% user + 0.4% kernel 36 0.4% 424/ueventd: 0.1% user + 0.3% kernel 37 0.4% 452/servicemanager: 0.3% user + 0.1% kernel 38 0.4% 14513/irq/280-touchpa: 0% user + 0.4% kernel 39 0.3% 1//init: 0% user + 0.3% kernel / faults: 19 minor 40 0.3% 138/kswapd0: 0% user + 0.3% kernel 41 0.3% 245/kgsl_worker_thr: 0% user + 0.3% kernel 42 0.3% 3492/neo: 0.3% user + 0% kernel 43 0.3% 14491/mdss_fb0: 0% user + 0.3% kernel 44 0.3% 17688/com.coloros.exserviceui: 0.1% user + 0.1% kernel / faults: 9 minor 1 major 45 0.1% 7/rcu_preempt: 0% user + 0.1% kernel 46 0.1% 21/rcuop/1: 0% user + 0.1% kernel 47 0% 423/kworker/0:1H: 0% user + 0% kernel 48 0.1% 658/android.hardware.power@1.0-service: 0.1% user + 0% kernel 49 0.1% 740/sensors.qcom: 0.1% user + 0% kernel / faults: 3 minor 50 0.1% 1030/kworker/10:0: 0% user + 0.1% kernel 51 0.1% 1134/cameraserver: 0% user + 0.1% kernel / faults: 26 minor 52 0% 1136/drmserver: 0% user + 0% kernel / faults: 91 minor 3 major 53 0% 1154/mediadrmserver: 0% user + 0% kernel / faults: 181 minor 59 major 54 0% 1159/mediaserver: 0% user + 0% kernel / faults: 34 minor 55 0.1% 1168/rild: 0% user + 0.1% kernel / faults: 2 minor 56 0% 1170/zygote64: 0% user + 0% kernel / faults: 25 minor 57 0.1% 1177/zygote: 0% user + 0.1% kernel / faults: 16 minor 58 0% 1223/tombstoned: 0% user + 0% kernel 59 0.1% 1261/imsdatadaemon: 0% user + 0.1% kernel 60 0.1% 1330/rild: 0.1% user + 0% kernel 61 0.1% 12333/com.tencent.mobileqq:MSF: 0.1% user + 0% kernel / faults: 45 minor 99 major 62 0.1% 12352/com.tencent.mobileqq: 0% user + 0.1% kernel / faults: 45 minor 113 major 63 0.1% 13204/com.tencent.mm: 0.1% user + 0% kernel / faults: 22 minor 69 major 64 0.1% 13717/com.tencent.mm:tools: 0.1% user + 0% kernel / faults: 179 minor 322 major 65 0.1% 14509/logcat: 0.1% user + 0% kernel 66 0.1% 14782/kworker/3:3: 0% user + 0.1% kernel 67 0.1% 19348/com.android.browser: 0.1% user + 0% kernel / faults: 77 minor 129 major 68 0.1% 19469/logcat: 0% user + 0.1% kernel 69 0.1% 19738/kworker/1:2: 0% user + 0.1% kernel 70 0.1% 20519/kworker/2:3: 0% user + 0.1% kernel 71 0.1% 20821/kworker/0:1: 0% user + 0.1% kernel 72 0.1% 20849/diag_mdlog: 0% user + 0.1% kernel 73 0.1% 21334/cat: 0% user + 0.1% kernel 74 0.1% 21428/logcat: 0% user + 0.1% kernel 7526% TOTAL: 20% user + 4.6% kernel + 0.5% iowait + 0.3% irq + 0.1% softirq 76 77----- pid 20358 at 2018-12-17 18:18:09 ----- 78Cmd line: com.oppo.reader 79Build fingerprint: 'OPPO/PBFM00/PBFM00:8.1.0/OPM1.171019.026/1541766248:user/release-keys' 80ABI: 'arm' 81Build type: optimized 82Zygote loaded classes=5110 post zygote classes=3166 83Intern table: 52731 strong; 145 weak 84JNI: CheckJNI is off; globals=727 (plus 79 weak) 85Libraries: /data/app/com.oppo.reader-NTuEuWlogpCo1aD9HtyDhQ==/lib/arm/libUiControl.so /data/app/com.oppo.reader-NTuEuWlogpCo1aD9HtyDhQ==/lib/arm/libtingReader.so /system/app/WebViewGoogleNX/WebViewGoogleNX.apk!/lib/armeabi-v7a/libwebviewchromium.so /system/lib/libandroid.so /system/lib/libcompiler_rt.so /system/lib/libjavacrypto.so /system/lib/libjnigraphics.so /system/lib/libmedia_jni.so /system/lib/libqti_performance.so /system/lib/libsoundpool.so /system/lib/libwebviewchromium_loader.so /system/lib/libwebviewchromium_plat_support.so libjavacore.so libopenjdk.so (14) 86Heap: 24% free, 16MB/22MB; 262809 objects 87Dumping cumulative Gc timings 88Start Dumping histograms for 8 iterations for concurrent copying 89ProcessMarkStack: Sum: 430.463ms 99% C.I. 12.291ms-126.080ms Avg: 53.807ms Max: 127.672ms 90ScanImmuneSpaces: Sum: 94.022ms 99% C.I. 8.543ms-24.656ms Avg: 11.752ms Max: 25.146ms 91VisitConcurrentRoots: Sum: 44.525ms 99% C.I. 4.612ms-8.508ms Avg: 5.565ms Max: 8.527ms 92SweepLargeObjects: Sum: 26.256ms 99% C.I. 1.062ms-8.484ms Avg: 3.282ms Max: 8.507ms 93ClearFromSpace: Sum: 13.381ms 99% C.I. 0.359ms-3.134ms Avg: 1.672ms Max: 3.145ms 94GrayAllDirtyImmuneObjects: Sum: 11.950ms 99% C.I. 0.352ms-8.112ms Avg: 1.493ms Max: 8.351ms 95FlipOtherThreads: Sum: 10.679ms 99% C.I. 0.956ms-2.934ms Avg: 1.334ms Max: 2.969ms 96MarkZygoteLargeObjects: Sum: 7.665ms 99% C.I. 45us-6824us Avg: 958.125us Max: 7023us 97EnqueueFinalizerReferences: Sum: 5.876ms 99% C.I. 95us-2168us Avg: 734.500us Max: 2168us 98ProcessReferences: Sum: 5.800ms 99% C.I. 4us-1463us Avg: 362.500us Max: 1463us 99InitializePhase: Sum: 5.308ms 99% C.I. 220us-3006us Avg: 663.500us Max: 3061us 100ForwardSoftReferences: Sum: 4.183ms 99% C.I. 14us-800us Avg: 522.875us Max: 800us 101SweepSystemWeaks: Sum: 4.176ms 99% C.I. 306us-1172us Avg: 522us Max: 1190us 102RecordFree: Sum: 1.808ms 99% C.I. 145us-671us Avg: 226us Max: 671us 103VisitNonThreadRoots: Sum: 1.565ms 99% C.I. 154us-286us Avg: 195.625us Max: 286us 104MarkingPhase: Sum: 1.317ms 99% C.I. 32us-916us Avg: 164.625us Max: 948us 105ThreadListFlip: Sum: 781us 99% C.I. 57us-239us Avg: 97.625us Max: 239us 106EmptyRBMarkBitStack: Sum: 727us 99% C.I. 13us-282us Avg: 90.875us Max: 282us 107MarkStackAsLive: Sum: 433us 99% C.I. 37us-73us Avg: 54.125us Max: 73us 108(Paused)GrayAllNewlyDirtyImmuneObjects: Sum: 430us 99% C.I. 39us-124us Avg: 53.750us Max: 124us 109ReclaimPhase: Sum: 241us 99% C.I. 17us-78us Avg: 30.125us Max: 78us 110ResumeOtherThreads: Sum: 232us 99% C.I. 6us-145us Avg: 29us Max: 145us 111ResumeRunnableThreads: Sum: 215us 99% C.I. 13us-50us Avg: 26.875us Max: 50us 112ClearRegionSpaceCards: Sum: 198us 99% C.I. 10us-61us Avg: 24.750us Max: 61us 113SweepAllocSpace: Sum: 147us 99% C.I. 6us-32us Avg: 18.375us Max: 32us 114SwapBitmaps: Sum: 124us 99% C.I. 11us-20us Avg: 15.500us Max: 20us 115(Paused)SetFromSpace: Sum: 105us 99% C.I. 3us-42us Avg: 13.125us Max: 42us 116(Paused)ClearCards: Sum: 79us 99% C.I. 250ns-7000ns Avg: 395ns Max: 7000ns 117Sweep: Sum: 71us 99% C.I. 6us-11us Avg: 8.875us Max: 11us 118(Paused)FlipCallback: Sum: 57us 99% C.I. 4us-19us Avg: 7.125us Max: 19us 119FlipThreadRoots: Sum: 35us 99% C.I. 3us-9us Avg: 4.375us Max: 9us 120UnBindBitmaps: Sum: 16us 99% C.I. 2us-2us Avg: 2us Max: 2us 121Done Dumping histograms 122concurrent copying paused: Sum: 1.499ms 99% C.I. 133us-458us Avg: 187.375us Max: 458us 123concurrent copying total time: 672.865ms mean time: 84.108ms 124concurrent copying freed: 558166 objects with total size 84MB 125concurrent copying throughput: 830604/s / 125MB/s 126Cumulative bytes moved 12844720 127Cumulative objects moved 272799 128Total time spent in GC: 672.865ms 129Mean GC size throughput: 65MB/s 130Mean GC object throughput: 827833 objects/s 131Total number of allocations 819829 132Total bytes allocated 60MB 133Total bytes freed 44MB 134Free memory 5MB 135Free memory until GC 5MB 136Free memory until OOME 495MB 137Total memory 22MB 138Max memory 512MB 139Zygote space size 780KB 140Total mutator paused time: 1.499ms 141Total time waiting for GC to complete: 34.535us 142Total GC count: 8 143Total GC time: 672.865ms 144Total blocking GC count: 0 145Total blocking GC time: 0 146Histogram of GC count per 10000 ms: 0:8,1:3,4:1 147Histogram of blocking GC count per 10000 ms: 0:12 148Registered native bytes allocated: 23662650 149/data/app/com.oppo.reader-NTuEuWlogpCo1aD9HtyDhQ==/oat/arm/base.odex: quicken 150/system/app/WebViewGoogleNX/oat/arm/WebViewGoogleNX.odex: quicken 151/data/app/com.oppo.reader-NTuEuWlogpCo1aD9HtyDhQ==/oat/arm/base.odex: quicken 152Current JIT code cache size: 144KB 153Current JIT data cache size: 107KB 154Current JIT capacity: 512KB 155Current number of JIT code cache entries: 124 156Total number of JIT compilations: 147 157Total number of JIT compilations for on stack replacement: 4 158Total number of JIT code cache collections: 4 159Memory used for stack maps: Avg: 565B Max: 6KB Min: 24B 160Memory used for compiled code: Avg: 1277B Max: 9KB Min: 2B 161Memory used for profiling info: Avg: 268B Max: 3KB Min: 16B 162Start Dumping histograms for 151 iterations for JIT timings 163Compiling: Sum: 873.725ms 99% C.I. 0.149ms-48.568ms Avg: 5.943ms Max: 56.411ms 164TrimMaps: Sum: 12.710ms 99% C.I. 8us-689.750us Avg: 86.462us Max: 772us 165Code cache collection: Sum: 5.165ms 99% C.I. 0.877ms-2.372ms Avg: 1.291ms Max: 2.395ms 166Done Dumping histograms 167Memory used for compilation: Avg: 231KB Max: 2MB Min: 15KB 168ProfileSaver total_bytes_written=0 169ProfileSaver total_number_of_writes=0 170ProfileSaver total_number_of_code_cache_queries=2 171ProfileSaver total_number_of_skipped_writes=2 172ProfileSaver total_number_of_failed_writes=0 173ProfileSaver total_ms_of_sleep=101716 174ProfileSaver total_ms_of_work=60 175ProfileSaver max_number_profile_entries_cached=0 176ProfileSaver total_number_of_hot_spikes=2 177ProfileSaver total_number_of_wake_ups=4 178Number of JIT inline cache deoptimizations: 2 179 180suspend all histogram: Sum: 1.234ms 99% C.I. 9us-160.399us Avg: 31.641us Max: 169us 181DALVIK THREADS (70): 182"Signal Catcher" daemon prio=5 tid=3 Runnable 183 | group="system" sCount=0 dsCount=0 flags=0 obj=0x13500280 self=0xe6c0fc00 184 | sysTid=20364 nice=0 cgrp=default sched=0/0 handle=0xdcbfe970 185 | state=R schedstat=( 27239057 2910573 19 ) utm=2 stm=0 core=0 HZ=100 186 | stack=0xdcb04000-0xdcb06000 stackSize=1006KB 187 | held mutexes= "mutator lock"(shared held) 188 native: #00 pc 002e8b57 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, int, BacktraceMap*, char const*, art::ArtMethod*, void*)+130) 189 native: #01 pc 0037b7f9 /system/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool, BacktraceMap*, bool) const+204) 190 native: #02 pc 00377d2b /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool, BacktraceMap*, bool) const+34) 191 native: #03 pc 0038f8fb /system/lib/libart.so (art::DumpCheckpoint::Run(art::Thread*)+698) 192 native: #04 pc 0038947d /system/lib/libart.so (art::ThreadList::RunCheckpoint(art::Closure*, art::Closure*)+320) 193 native: #05 pc 00388f7b /system/lib/libart.so (art::ThreadList::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool)+530) 194 native: #06 pc 00388c9b /system/lib/libart.so (art::ThreadList::DumpForSigQuit(std::__1::basic_ostream<char, std::__1::char_traits<char>>&)+626) 195 native: #07 pc 003652d3 /system/lib/libart.so (art::Runtime::DumpForSigQuit(std::__1::basic_ostream<char, std::__1::char_traits<char>>&)+122) 196 native: #08 pc 0036d9b3 /system/lib/libart.so (art::SignalCatcher::HandleSigQuit()+1282) 197 native: #09 pc 0036c91b /system/lib/libart.so (art::SignalCatcher::Run(void*)+330) 198 native: #10 pc 000473f3 /system/lib/libc.so (__pthread_start(void*)+22) 199 native: #11 pc 0001afb1 /system/lib/libc.so (__start_thread+32) 200 (no managed stack frames) 201 202"main" prio=5 tid=1 Blocked 203 | group="main" sCount=1 dsCount=0 flags=1 obj=0x71ebca68 self=0xe6c0f000 204 | sysTid=20358 nice=-10 cgrp=default sched=0/0 handle=0xea9254a4 205 | state=S schedstat=( 2882074832 469149273 2373 ) utm=241 stm=47 core=1 HZ=100 206 | stack=0xff789000-0xff78b000 stackSize=8MB 207 | held mutexes= 208 at com.zhangyue.iReader.DB.DBAdapter.execSQL(SourceFile:2512) 209 - waiting to lock <0x08d75003> (a com.zhangyue.iReader.DB.DBAdapter) held by thread 66 210 at com.zhangyue.iReader.DB.DBAdapter.queryBookIDWithoutPath(SourceFile:1497) 211 at com.zhangyue.iReader.read.ui.BookBrowserFragment.u(SourceFile:1223) 212 at com.zhangyue.iReader.read.ui.BookBrowserFragment.U(SourceFile:368) 213 at com.zhangyue.iReader.read.ui.cc.run(SourceFile:3098) 214 at android.os.Handler.handleCallback(Handler.java:790) 215 at android.os.Handler.dispatchMessage(Handler.java:99) 216 at android.os.Looper.loop(Looper.java:198) 217 at android.app.ActivityThread.main(ActivityThread.java:7038) 218 at java.lang.reflect.Method.invoke(Native method) 219 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:519) 220 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:836) 221 222"Jit thread pool worker thread 0" daemon prio=5 tid=2 Native 223 | group="main" sCount=1 dsCount=0 flags=1 obj=0x135001f8 self=0xdcd1f000 224 | sysTid=20363 nice=9 cgrp=default sched=0/0 handle=0xdccff970 225 | state=S schedstat=( 803558025 113797923 579 ) utm=76 stm=4 core=6 HZ=100 226 | stack=0xdcc01000-0xdcc03000 stackSize=1022KB 227 | held mutexes= 228 kernel: (couldn't read /proc/self/task/20363/stack) 229 native: #00 pc 00018e20 /system/lib/libc.so (syscall+28) 230 native: #01 pc 000b79d1 /system/lib/libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*)+80) 231 native: #02 pc 00390b81 /system/lib/libart.so (art::ThreadPool::GetTask(art::Thread*)+172) 232 native: #03 pc 003904f7 /system/lib/libart.so (art::ThreadPoolWorker::Run()+62) 233 native: #04 pc 00390115 /system/lib/libart.so (art::ThreadPoolWorker::Callback(void*)+92) 234 native: #05 pc 000473f3 /system/lib/libc.so (__pthread_start(void*)+22) 235 native: #06 pc 0001afb1 /system/lib/libc.so (__start_thread+32) 236 (no managed stack frames) 237 238"ReferenceQueueDaemon" daemon prio=5 tid=4 Waiting 239 | group="system" sCount=1 dsCount=0 flags=1 obj=0x13500308 self=0xdca14600 240 | sysTid=20365 nice=4 cgrp=default sched=0/0 handle=0xc9e29970 241 | state=S schedstat=( 34968799 11582865 55 ) utm=2 stm=1 core=4 HZ=100 242 | stack=0xc9d27000-0xc9d29000 stackSize=1038KB 243 | held mutexes= 244 at java.lang.Object.wait(Native method) 245 - waiting on <0x03602b80> (a java.lang.Class<java.lang.ref.ReferenceQueue>) 246 at java.lang.Daemons$ReferenceQueueDaemon.runInternal(Daemons.java:183) 247 - locked <0x03602b80> (a java.lang.Class<java.lang.ref.ReferenceQueue>) 248 at java.lang.Daemons$Daemon.run(Daemons.java:108) 249 at java.lang.Thread.run(Thread.java:764) 250 251 "OkHttp https://icloud.zhangyue.com/..." prio=5 tid=66 Native 252 | group="main" sCount=1 dsCount=0 flags=1 obj=0x133c0a30 self=0xc4ca9200 253 | sysTid=21822 nice=0 cgrp=default sched=0/0 handle=0xbe396970 254 | state=S schedstat=( 14565089915 55131141 764 ) utm=1423 stm=33 core=2 HZ=100 255 | stack=0xbe294000-0xbe296000 stackSize=1038KB 256 | held mutexes= 257 kernel: (couldn't read /proc/self/task/21822/stack) 258 native: #00 pc 00018e20 /system/lib/libc.so (syscall+28) 259 native: #01 pc 000b79d1 /system/lib/libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*)+80) 260 native: #02 pc 003e2949 /system/lib/libart.so (art::GoToRunnable(art::Thread*)+300) 261 native: #03 pc 003e27ed /system/lib/libart.so (art::JniMethodEnd(unsigned int, art::Thread*)+8) 262 native: #04 pc 00404d45 /system/framework/arm/boot-framework.oat (Java_android_database_sqlite_SQLiteConnection_nativeExecuteForChangedRowCount__JJ+132) 263 at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native method) 264 at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:748) 265 at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754) 266 at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64) 267 at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1658) 268 at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1604) 269 at com.zhangyue.iReader.DB.a.update(SourceFile:129) 270 at com.zhangyue.iReader.DB.DBAdapter.update(SourceFile:4224) 271 at dt.d.b(SourceFile:112) 272 at com.zhangyue.iReader.DB.DBAdapter.updateHighLightByPostion(SourceFile:1657) 273 at df.t.b(SourceFile:269) 274 - locked <0x08d75003> (a com.zhangyue.iReader.DB.DBAdapter) 275 at df.t.a(SourceFile:66) 276 at df.al.a(SourceFile:118) 277 at df.am.onHttpEvent(SourceFile:88) 278 at com.zhangyue.net.p$b.onHttpEvent(SourceFile:138) 279 at com.zhangyue.net.a.a(SourceFile:796) 280 at com.zhangyue.net.a.a(SourceFile:63) 281 at com.zhangyue.net.c.onResponse(SourceFile:698) 282 at okhttp3.RealCall$AsyncCall.execute(SourceFile:153) 283 at okhttp3.internal.NamedRunnable.run(SourceFile:32) 284 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 285 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 286 at java.lang.Thread.run(Thread.java:764)
开头会告诉你,是哪个包ANR 了。所以,以后搜索ANR 可以在log 里面搜索:
Cmd line: com.oppo.reader
后面替换成你的包名。
第一步:查看主线程
1"main" prio=5 tid=1 Blocked 2 | group="main" sCount=1 dsCount=0 flags=1 obj=0x71ebca68 self=0xe6c0f000 3 | sysTid=20358 nice=-10 cgrp=default sched=0/0 handle=0xea9254a4 4 | state=S schedstat=( 2882074832 469149273 2373 ) utm=241 stm=47 core=1 HZ=100 5 | stack=0xff789000-0xff78b000 stackSize=8MB 6 | held mutexes= 7 at com.zhangyue.iReader.DB.DBAdapter.execSQL(SourceFile:2512) 8 - waiting to lock <0x08d75003> (a com.zhangyue.iReader.DB.DBAdapter) held by thread 66 9 at com.zhangyue.iReader.DB.DBAdapter.queryBookIDWithoutPath(SourceFile:1497) 10 at com.zhangyue.iReader.read.ui.BookBrowserFragment.u(SourceFile:1223) 11 at com.zhangyue.iReader.read.ui.BookBrowserFragment.U(SourceFile:368) 12 at com.zhangyue.iReader.read.ui.cc.run(SourceFile:3098) 13 at android.os.Handler.handleCallback(Handler.java:790) 14 at android.os.Handler.dispatchMessage(Handler.java:99) 15 at android.os.Looper.loop(Looper.java:198) 16 at android.app.ActivityThread.main(ActivityThread.java:7038) 17 at java.lang.reflect.Method.invoke(Native method) 18 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:519) 19 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:836)
- waiting to lock <0x08d75003> (a com.zhangyue.iReader.DB.DBAdapter) held by thread 66
他说,在等待一个锁,0x08d75003。 你可以在trace 里面搜索这个字符,或者后面说,held by thread 66,那就搜索线程66
tid=66
第二步:找到线程66
1 "OkHttp https://icloud.zhangyue.com/..." prio=5 tid=66 Native 2 | group="main" sCount=1 dsCount=0 flags=1 obj=0x133c0a30 self=0xc4ca9200 3 | sysTid=21822 nice=0 cgrp=default sched=0/0 handle=0xbe396970 4 | state=S schedstat=( 14565089915 55131141 764 ) utm=1423 stm=33 core=2 HZ=100 5 | stack=0xbe294000-0xbe296000 stackSize=1038KB 6 | held mutexes= 7 kernel: (couldn't read /proc/self/task/21822/stack) 8 native: #00 pc 00018e20 /system/lib/libc.so (syscall+28) 9 native: #01 pc 000b79d1 /system/lib/libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*)+80) 10 native: #02 pc 003e2949 /system/lib/libart.so (art::GoToRunnable(art::Thread*)+300) 11 native: #03 pc 003e27ed /system/lib/libart.so (art::JniMethodEnd(unsigned int, art::Thread*)+8) 12 native: #04 pc 00404d45 /system/framework/arm/boot-framework.oat (Java_android_database_sqlite_SQLiteConnection_nativeExecuteForChangedRowCount__JJ+132) 13 at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native method) 14 at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:748) 15 at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754) 16 at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64) 17 at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1658) 18 at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1604) 19 at com.zhangyue.iReader.DB.a.update(SourceFile:129) 20 at com.zhangyue.iReader.DB.DBAdapter.update(SourceFile:4224) 21 at dt.d.b(SourceFile:112) 22 at com.zhangyue.iReader.DB.DBAdapter.updateHighLightByPostion(SourceFile:1657) 23 at df.t.b(SourceFile:269) 24 - locked <0x08d75003> (a com.zhangyue.iReader.DB.DBAdapter) 25 at df.t.a(SourceFile:66) 26 at df.al.a(SourceFile:118) 27 at df.am.onHttpEvent(SourceFile:88) 28 at com.zhangyue.net.p$b.onHttpEvent(SourceFile:138) 29 at com.zhangyue.net.a.a(SourceFile:796) 30 at com.zhangyue.net.a.a(SourceFile:63) 31 at com.zhangyue.net.c.onResponse(SourceFile:698) 32 at okhttp3.RealCall$AsyncCall.execute(SourceFile:153) 33 at okhttp3.internal.NamedRunnable.run(SourceFile:32) 34 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 35 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 36 at java.lang.Thread.run(Thread.java:764) 37
问下了同事, - locked <0x08d75003> (a com.zhangyue.iReader.DB.DBAdapter) 表示,从这行的堆栈开始,进入synchronized 代码块。(至于是不是,可以自己去获取堆栈,尝试下。)
那么,也就是在这里,子线程执行代码,占用了 - locked <0x08d75003> (a com.zhangyue.iReader.DB.DBAdapter)这个锁。
第三步:处理
怎么处理呢?
- 把没有用的锁,去掉。程序里面不要随意的加锁
- 我们这里是因为一大坨代码,都写在了执行事务里,导致,执行事务的时候,占用了SQLite 链接。导致主线程拿不到SQLite 的锁。
其他技巧
1.如果你觉得是某一块代码执行时间过长导致ANR,那么可以把这一块代码换成下面这个,看看会不会ANR.
1 long begin = System.currentTimeMillis(); 2 3 while(System.currentTimeMillis() - begin < 1000 * 60 * 10){ 4 a = 50; 5 DBAdapter.getInstance().queryALLBook(); 6 } 7
上面这块代码,会执行10分钟。里面不停的执行SQL 操作。