1

Sometimes (so it's very hard to reproduce and debug) my application just hangs after it starts. It only shows layout (with two fragments and one NDK-component) and that's it!

I thought that there's something like infinite loop in code, but there's no anything like that. There's no even UI thread, when I tried to find it with ADB monitor:

Android app hangs without UI thread

The only it prints to log is:

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)
Slava
  • 1,314
  • 14
  • 28
  • Introduce AsyncTask for the code that takes long to execute – PEHLAJ Apr 27 '16 at 12:47
  • How to recognise where I should go to Async task? It's not just doing something slowly. It completely blocks app and I can't even see UI thread. – Slava Apr 27 '16 at 12:49
  • Nope, I work with native android, difficult to work with NDK. Btw share the code first :) – PEHLAJ Apr 27 '16 at 12:50
  • What nope? :-) Sorry, I can't share code because the project is commercial and I can't reproduce error to leave only necessary part of code :-/ – Slava Apr 27 '16 at 12:53
  • I've answered to 3mpty, check it, please :-) – Slava Apr 27 '16 at 13:21

1 Answers1

0

Profile your code. There is few nice tools for that, I would start with Systrace and Traceview (official tools from Google). My bet would be problem with native code that takes to much time, but you've to check it yourself.

Systrace analyze

NDK perf

3mpty
  • 1,354
  • 8
  • 16
  • It's hard to use, but I've found that main thread is still exists and hangs in core of AndroidAsync library (I use websockets). Don't you know this error? It's exactly the same error as mine: http://stackoverflow.com/questions/23632587/thread-automatically-going-to-wait-state-in-android – Slava Apr 27 '16 at 13:20