2

I need to profile several functions in my java code for Android.

I do know about traceview. And I actually found which functions to investigate using this tool. But it gives no information that can help in investigations inside specific functions.

So, is there any way I can get per-instruction profiling information for Java code on Android?

Fortyrunner
  • 12,702
  • 4
  • 31
  • 54
inazaruk
  • 74,247
  • 24
  • 188
  • 156
  • I wouldn't worry about instruction-level profiling. What are you doing that needs such fine tuning? If it REALLY does need to be optimized that hard, consider writing it in C++ using the NDK. – Falmarri Nov 10 '10 at 23:01
  • 1
    You most likely need to look at the design of the function, not one particular line. Are you using an n^2 algorithm, or doing lots of unnecessary io? – Cheryl Simon Nov 10 '10 at 23:03
  • @inazaruk: "But it gives no information that can help in investigations inside specific functions" -- there are no "functions" in Java, so I am assuming you are referring to methods. If your method is so long that desk-checking cannot determine where your bottleneck is, then write shorter methods. – CommonsWare Nov 11 '10 at 01:37
  • If there's a debugger available, there's always this method (http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024) – Mike Dunlavey Nov 11 '10 at 02:33
  • @Falmarri, I don't want to invest to C++ code until I prove it is necessary. I just wanted to double check that the time function consumes is mostly in calculations and not in, for example, array access. – inazaruk Nov 11 '10 at 07:48
  • @Mayra, The complexity is linear, and function does I/O but is uses cashing. So I doubt it either of this, and traceviewer shows that 99% function spends inside it, not inside I/O processing. – inazaruk Nov 11 '10 at 07:51
  • @CommonWare, my method is pretty short. I can't make it any shorter. – inazaruk Nov 11 '10 at 07:54
  • @CommonsWare: "functions", "methods", "subroutines", "properties", different names for pretty much the same thing. "Write shorter methods", "desk-check", easy to say. I'm working in a team. There are thousands of files, thousands of classes, countless methods of all sizes. I'm sure that would horrify you (with good reason), but desk-checking ain't gonna take us very far. – Mike Dunlavey Nov 11 '10 at 13:12

1 Answers1

0

I would suggest you can try 'hprof' within your Java code to dump the profiled data to a file and you can analyse that file for more details.

API to use:
dumpHprofData(String fileName)

If you are interested in more granular level profiling then you can try 'readprofile' which works at Kernel level. You would need 'busybox' to use it though. However, I guess you need to map the instructions with your Java statements.

TheCottonSilk
  • 8,662
  • 2
  • 26
  • 37