0

I want to look at the cpu usage of my app in Android. For which, I used both top and dumpsys cpuinfo. I calculated the average of 5 minutes for top command (1 second interval between cpu measurements). For example, once I got 19% for my app over 5 minutes but next time I got 17% over 5 minutes. I did the same with dumpsys. Their results are slightly different.

The main question is: Is one more accurate than the other one ?

I need high precision for the CPU usage.

Moreover, can I change the timespan for dumpsys cpuinfo such that it gives the average over last 5 minutes ?

Update: Its not a duplicate question like this one.

Community
  • 1
  • 1
utengr
  • 3,225
  • 3
  • 29
  • 68
  • Possible duplicate of [How to get higher precision of "CPU%" than that from TOP command?](http://stackoverflow.com/questions/15148193/how-to-get-higher-precision-of-cpu-than-that-from-top-command) – Alex P. Nov 10 '16 at 11:31
  • @Alex P: Its not a duplicate of that question as I have posted it after reading that thread thoroughly. – utengr Nov 10 '16 at 11:56

1 Answers1

1

I suggest going with dumpsys. In my experience, TOP gets its information from a variety of sources, some direct and some estimates. The estimates were necessary in earlier architectures because there weren't any means to directly measure certain statistics. Now days, many of these measurements are available from the lowest level. The main problem with TOP is figuring out if it has been updated to obtaining these measurements directly or is it still estimating them.

In contrast, dumpsys gets its info from /proc. These measurements are at the lowest level or very nearly so. As such, as the architecture changes, /proc is more likely to be updated.

The second part of your question brings up one of /proc's deficiencies. /proc is generally very poorly documented, including sampling rates, etc. I haven't seen a case where a sampling rate for /proc (and so dumpsys) could be set, but that doesn't mean such capability doesn't exist. (Often, the sampling rate is actually dumped along with the data.)

Community
  • 1
  • 1
Taylor Kidd
  • 1,463
  • 1
  • 9
  • 11
  • Thanks for your explanation. I think dumpsys cpuinfo displays the information for the last 5-6 seconds. Could it be that I run this command through a script at 1 second interval and then average the results over 5 or any specific time period? The other question: How can I get the dumpsys cpuinfo in decimals ? For top, I used busybox. – utengr Nov 09 '16 at 12:28