参考博客:https://blog.csdn.net/wanglha/article/details/46042147
https://blog.csdn.net/htjx99/article/details/42920641
查看手机是几核的:cat /proc/cpuinfo | grep ^processor | wc -l
计算cpu利用率:
1.adb shell
2.cat /proc/stat
解析:
例:
第一行的数值表示的是CPU总的使用情况,所以我们只要用第一行的数字计算就可以了。下表解析第一行各数值的含义
CPU的即时利用率的计算公式:
CPU在t1到t2时间段总的使用时间 = ( user2+ nice2+ system2+ idle2+ iowait2+ irq2+ softirq2) - ( user1+ nice1+ system1+ idle1+ iowait1+ irq1+ softirq1)
CPU在t1到t2时间段空闲使用时间 = (idle2 - idle1)
CPU在t1到t2时间段即时利用率 = 1 - CPU空闲使用时间 / CPU总的使用时间
查看cpu消耗情况:
1.adb shell dumpsys cpuinfo
筛选出想看的app:adb shell dumpsys cpuinfo |grep packagename
2.实时查看cpu使用率
adb shell
top -m 10 -s cpu