实测App启动时获取到的值大于100,下面是我的核心代码:
private static float getCpuDataAboveO() {
FileInputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
try {
if (CLK_TCK_INITED.compareAndSet(false, true)) {
configClkTck();
}
inputStream = new FileInputStream(PID_STAT_FILE);
inputStreamReader = new InputStreamReader(inputStream);
bufferedReader = new BufferedReader(inputStreamReader);
String line = bufferedReader.readLine();
String[] res = line.split(" ");
// 进程在用户态运行的时间
long uTime = Long.parseLong(res[13]);
......
Android 获取APP自身的CPU使用率目前 top,dumpsys cpuinfo,/proc/stat这些都被谷歌以安全为由禁止访问了但是性能监控(APM)的需求还是有的,这里也只是分享如何获取自身进程的CPU...