How get average CPU usage in Android? [duplicate]

删除回忆录丶 提交于 2020-12-16 07:13:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!