2

Possible Duplicate:
How to get Memory usage and CPU usage in android?

I'm writing an android application that needs to know how much cpu/battery intensive are some statements.

For example if I call a function, I would like to know how much battery that function used, or at least something like that, for example how many clock cycles have been used.

Do you know everything I can use?

Thanks in advance

Leonardo

Community
  • 1
  • 1
  • See [this question](http://stackoverflow.com/questions/3118234/how-to-get-memory-usage-and-cpu-usage-in-android) – Manoj Kumar Sep 14 '12 at 12:30
  • The best way is , Traceview. Follow this link: http://tools.android.com/recent/traceviewineclipse One more link with brief description : http://android-developers.blogspot.in/2010/10/traceview-war-story.html –  Sep 14 '12 at 12:28
  • Thanks guys but my question is refering a runtime environment (so i can't use traceview) and the cpu usage for a set of statement, the question pointed by Mojo is about "overall" cpu usage. But i really appreciate your effort. – Leonardo De Santis Sep 14 '12 at 13:33

1 Answers1

0

A direct way of arriving at CPU usage may not be available as of now. How ever you can use an indirect approach for calculating CPU usage.

Calculate the diffrence in time stamps before and after you make a function call. This will give you the time duration in milis that a function takes.

Now CPU usage should be directly proportional to time duration unless the function blocks on some IO operation or 'Object.wait()' or context switches.

However the above approach will almost yeild descent results if your functions are only doing in memory calculations.

Community
  • 1
  • 1
sharadendu sinha
  • 827
  • 4
  • 10