實(shí)測(cè)App啟動(dòng)時(shí)獲取到的值大于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(" ");
// 進(jìn)程在用戶(hù)態(tài)運(yùn)行的時(shí)間
long uTime = Long.parseLong(res[13]);
......
Android 獲取APP自身的CPU使用率目前 top,dumpsys cpuinfo,/proc/stat這些都被谷歌以安全為由禁止訪(fǎng)問(wèn)了但是性能監(jiān)控(APM)的需求還是有的威沫,這里也只是分享如何獲取自身進(jìn)程的CPU...