问题
I want to get the average CPU usage in Android per 100ms or 500ms. I have tried to use top
and dumpsys cpuinfo
, but neither of them tell me the average usage or the timestamp. So how can I get the average usage?
I notice that there is some CPU usage information in /proc/stat
, can I calculate average CPU usage using /proc/stat
?
回答1:
I've tested the solution by Krypton, and got wrong numbers (about 22% while getting about 48 via adb shell top). So maybe the answer is not running ok on android 7, or there is some bug.
I found a working solution at this question ,and code provided by Souch is already doing the job for us. Just use his CpuInfo class to get the average load each time you need it.
来源:https://stackoverflow.com/questions/23261306/how-get-average-cpu-usage-in-android