Android - 有时应用程序挂起而没有ui线程

时间:2016-04-27 12:40:13

标签: android android-ndk

有时(因此很难重现和调试)我的应用程序在启动后就会挂起。它只显示布局(有两个片段和一个NDK组件),这就是它!

我认为代码中有无限循环,但没有类似的东西。当我尝试使用ADB监视器找到它时,甚至没有UI线程:

Android app hangs without UI thread

唯一打印到日志的是:

04-27 15:21:58.956 769-793/? E/ActivityManager: ANR in com.test.test (com.test.test/.ui.package.SomeActivity_)
    PID: 7338
    Reason: 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: 31.  Wait queue head age: 5774.1ms.)
    Load: 9.48 / 9.59 / 9.48
    CPU usage from 0ms to 6185ms later:
      57% 769/system_server: 24% user + 32% kernel / faults: 5390 minor 1 major
      15% 949/com.android.systemui: 7.4% user + 7.9% kernel / faults: 2163 minor
      0% 202/debuggerd: 0% user + 0% kernel / faults: 5828 minor
      9.5% 7338/com.test.test: 5% user + 4.5% kernel / faults: 1151 minor 2 major
      9.2% 1623/com.android.phone: 4.3% user + 4.8% kernel / faults: 1714 minor
      2.1% 1595/com.android.nfc: 0.9% user + 1.1% kernel / faults: 742 minor
      0% 1606/com.redbend.vdmc: 0% user + 0% kernel / faults: 911 minor
      1.2% 3187/mpdecision: 0% user + 1.2% kernel
      0.9% 132/ueventd: 0.4% user + 0.4% kernel
      0.8% 16415/kworker/u:5: 0% user + 0.8% kernel
      0.6% 24060/kworker/u:1: 0% user + 0.6% kernel
      0.4% 3/ksoftirqd/0: 0% user + 0.4% kernel
      0.3% 148/logd: 0.3% user + 0% kernel
      0.3% 198/surfaceflinger: 0.1% user + 0.1% kernel
      0.3% 212/sensors.qcom: 0.1% user + 0.1% kernel / faults: 5 minor
      0.3% 221/adbd: 0% user + 0.3% kernel / faults: 20 minor
      0.1% 121/mmcqd/1: 0% user + 0.1% kernel
      0.1% 125/dhd_dpc: 0% user + 0.1% kernel
      0.1% 205/mediaserver: 0% user + 0.1% kernel
      0.1% 1821/com.google.android.gms: 0% user + 0.1% kernel
      0.1% 7711/ru.yandex.yandexbus:yandexplib: 0.1% user + 0% kernel
      0.1% 17799/com.hsv.freeadblockerbrowser: 0% user + 0.1% kernel
      0.1% 28853/kworker/0:2: 0% user + 0.1% kernel
     +0% 8118/migration/1: 0% user + 0% kernel
     +0% 8119/kworker/1:0: 0% user + 0% kernel
     +0% 8120/kworker/1:0H: 0% user + 0% kernel
     +0% 8121/ksoftirqd/1: 0% user + 0% kernel
     +0% 8122/kworker/1:1: 0% user + 0% kernel
     +0% 8123/kworker/1:1H: 0% user + 0% kernel
    50% TOTAL: 20% user + 28% kernel + 0.4% iowait
    CPU usage from 5613ms to 6150ms later:
      7.4% 769/system_server: 1.8% user + 5.6% kernel
        3.7% 793/ActivityManager: 0% user + 3.7% kernel
      3.7% 7338/com.test.test: 3.7% user + 0% kernel
        3.7% 7525/Thread-4705: 3.7% user + 0% kernel
      1.1% 3/ksoftirqd/0: 0% user + 1.1% kernel
      1.4% 3187/mpdecision: 0% user + 1.4% kernel
      1.6% 16415/kworker/u:5: 0% user + 1.6% kernel
    8.3% TOTAL: 5.5% user + 2.7% kernel
04-27 15:21:58.977 769-793/? I/ActivityManager: Skipping duplicate ANR: ProcessRecord{3c1a91d 7338:com.test.test/u0a268} 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: 31.  Wait queue head age: 10865.4ms.)
04-27 15:21:58.992 769-8124/? W/DropBoxManagerService: Dropping: data_app_anr (10 > 0 bytes)

1 个答案:

答案 0 :(得分:0)

描述您的代码。有一些不错的工具,我会从Systrace和Traceview(谷歌的官方工具)开始。我的赌注是本机代码需要花费很多时间的问题,但你自己检查一下。

Systrace analyze

NDK perf