简体   繁体   中英

Android - Debug slow running code

Is there a good way (proper way, or effective way) to debug slow running code?

I have a thread which runs multiple loops and then recurses and my code is running very slow.

Is there a good way to debug different loops or sections of code to find out which is running slowest?

If the debugger already does this, can someone please explain how,

Many thanks

What you need is not a debugger, but a profiler. Check this tool from Android's SDK: traceview

One of the most primitive ways to determine slow points is to litter the code with print statements. Bottlenecks then show up as delays between prints. This can be improved by printing the system time as you move from one loop to another, making it trivial to determine the slowest loops.

A solution that is potentially easier and more thorough is to use a performance profiler. Most mainstream languages will have standalone profilers or debuggers with performance profiling built-in. A good profiler will determine the percentage of execution time spent on each area of your code and offer useful information for optimizing performance bottlenecks.

If you need more specific information it would be helpful to post the language you are using as well as relevant sections of the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM