Reputation: 8805
If I run top on my dev android device I can see that when my app in is the background it uses .6% cpu, if I bring it to the foreground it uses 5-6% of the cpu. The problem is, it's not doing anything. There's no services running, there's no background threads, it's just waiting for the user to click a button.
Is there a way in adt or via some other tool to find out which thread is eating the cpu so I can get an idea where to start looking for problems?
Upvotes: 3
Views: 2392
Reputation: 4491
You can use the built-in profiler in Android Studio: https://developer.android.com/studio/profile/cpu-profiler
You can also run adb shell top
but this will only give you CPU and MEM usage per process not thread.
For more info check out this Google I/O presentation: https://www.youtube.com/watch?v=O5V9ZSL0BsM&list=PLOU2XLYxmsIInFRc3M44HUTQc3b_YJ4-Y&index=135
Upvotes: 1
Reputation: 5857
Yes and it's even free. it is called DDMS and is part of the ADT plugin for Eclipse.
Connect your device via USB, start off your app, and then open DDMS view and you will be able quickly find your CPU intensive thread.
Note that it's a good practice to give human readable names to the threads spawned by your program. Your users will never these names, but it will make thread debugging/profiling simpler:
Thread.currentThread().setName("DB-Access-Thread");
Upvotes: 7