07 Oct 2018, 20:21

Poor Man's Profiler

If you’re having issues regarding performance, i.e. application is slow, a quick and dirty solution can be to

  1. trigger slow code (from UI, etc.) and then
  2. press pause button in the IDE Image of pause button in Android studio

Chances are that two out of three times call stack will be stuck in the expensive method call.

Image of call stack

Then, you can simply have a glance at what each method does:

fun innocentMethod1() {
    innocentMethod2()
}

fun innocentMethod2() {
    innocentLookingMethod()
}

Nothing suspicious here.

But, move on and you might see something like:

fun innocentLookingMethod() {
    for (i in 1..1000000) {
        innocentMethod3(i)
    }
}

which should be a good enough starting point for further work.

Credits

Credits for the idea, however it may seem simple, are due to a blog or forum post somewhere, sometime.