First, you didn't mention if the code is only java or jni.
In any case, my following comment is a partial reply, since it's not about finding the longest running functions, but rather about debugging ANRs in general.
When debugging ANRs, I would handle it like a deadlock. When seeing the app is stuck, try to dump the current stack traces. It might work better than the regular ANR traces.
Another thing you can do, is attach the debugger and pause the app when you see it stuck.
The final thing to try, would be to add logs around your code when going in and out of function calls, and see the last one that went in but didn't go out. You can also try following this.