androidshellunixcpu-usagedumpsys

TOP command vs dumpsys cpuinfo: Which one is more accurate?


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.


Solution

  • 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.)