14

I am developing a rather large software on Android with a log native code, it's working now but having some performance issues.

I am hoping I can profile each module(function call) of the software for CPU cycles, memory usage, etc, on several real android phones. Is there a simple c library to do that?

I see people using oprofile, It seems to be a overkill for my case since that it is a system wild profiler, and it requires rebuild the kernel and system image.

As I have the full source code of my app, all I really need is a simple c library that I can embed in my code to do some profiling while the app runs several test cases.

BTW, what is the Linux way of doing this?

lennydizzy
  • 141
  • 1
  • 3
  • Can you run the app under a debugger? That you can manually interrupt of pause? Then you can use the random-pause method to find the performance problems. http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024 – Mike Dunlavey Dec 01 '10 at 20:55
  • NDK debugger support only available in froyo, plus I could use a systemic way if I wanna run the profiling on several different phones. – lennydizzy Dec 01 '10 at 21:01
  • 1
    **ndk-gdb** is available, and should be able to give you a stack trace when you ctrl-C it. This is not intended to measure performance. It is intended to find the code to optimize in order to improve performance. Measuring does not find problems, but finding and fixing problems does improve the measurement, regardless of platform. (I know that's not how people typically think about this, but that's how to make code run fast.) – Mike Dunlavey Dec 02 '10 at 16:37
  • I believe in Linux you need to compile and link with `-p` or `-pg` to enable profiling. – Chef Pharaoh Jan 09 '18 at 19:22

1 Answers1

4

I've had pretty decent results with android-ndk-profiler.

http://code.google.com/p/android-ndk-profiler/

Outputs /mnt/sdcard/gmon.out

dwerner
  • 6,462
  • 4
  • 30
  • 44
  • Unfortunately it's about as useless as it can get. In addition to being rather fragile (only works with some versions of gprof and gcc etc.), without full stack sampling [the information isn't representative anyway](http://stackoverflow.com/a/1779343/201725). – Jan Hudec Oct 04 '12 at 09:11