男儿欲遂平生志,五经勤向窗前读。这篇文章主要讲述Android N 7.1.1 ActivityManagerService 获取cpu状态相关的知识,希望能为你提供帮助。
void updateCpuStatsNow() { synchronized (mProcessCpuTracker) { mProcessCpuMutexFree.set(false); final long now = SystemClock.uptimeMillis(); boolean haveNewCpuStats = false; if (MONITOR_CPU_USAGE & & mLastCpuTime.get() < (now-MONITOR_CPU_MIN_TIME)) { mLastCpuTime.set(now); mProcessCpuTracker.update(); if (mProcessCpuTracker.hasGoodLastStats()) { haveNewCpuStats = true; //Slog.i(TAG, mProcessCpu.printCurrentState()); //Slog.i(TAG, "Total CPU usage: " //+ mProcessCpu.getTotalCpuPercent() + "%"); // Slog the cpu usage if the property is set. if ("true".equals(SystemProperties.get("events.cpu"))) { int user = mProcessCpuTracker.getLastUserTime(); int system = mProcessCpuTracker.getLastSystemTime(); int iowait = mProcessCpuTracker.getLastIoWaitTime(); int irq = mProcessCpuTracker.getLastIrqTime(); int softIrq = mProcessCpuTracker.getLastSoftIrqTime(); int idle = mProcessCpuTracker.getLastIdleTime(); int total = user + system + iowait + irq + softIrq + idle; if (total == 0) total = 1; EventLog.writeEvent(EventLogTags.CPU, ((user+system+iowait+irq+softIrq) * 100) / total, (user * 100) / total, (system * 100) / total, (iowait * 100) / total, (irq * 100) / total, (softIrq * 100) / total); } } }final BatteryStatsImpl bstats = mBatteryStatsService.getActiveStatistics(); synchronized(bstats) { synchronized(mPidsSelfLocked) { if (haveNewCpuStats) { if (bstats.startAddingCpuLocked()) { int totalUTime = 0; int totalSTime = 0; final int N = mProcessCpuTracker.countStats(); for (int i=0; i< N; i++) { ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i); if (!st.working) { continue; } ProcessRecord pr = mPidsSelfLocked.get(st.pid); totalUTime += st.rel_utime; totalSTime += st.rel_stime; if (pr != null) { BatteryStatsImpl.Uid.Proc ps = pr.curProcBatteryStats; if (ps == null || !ps.isActive()) { pr.curProcBatteryStats = ps = bstats.getProcessStatsLocked( pr.info.uid, pr.processName); } ps.addCpuTimeLocked(st.rel_utime, st.rel_stime); pr.curCpuTime += st.rel_utime + st.rel_stime; } else { BatteryStatsImpl.Uid.Proc ps = st.batteryStats; if (ps == null || !ps.isActive()) { st.batteryStats = ps = bstats.getProcessStatsLocked( bstats.mapUid(st.uid), st.name); } ps.addCpuTimeLocked(st.rel_utime, st.rel_stime); } } final int userTime = mProcessCpuTracker.getLastUserTime(); final int systemTime = mProcessCpuTracker.getLastSystemTime(); final int iowaitTime = mProcessCpuTracker.getLastIoWaitTime(); final int irqTime = mProcessCpuTracker.getLastIrqTime(); final int softIrqTime = mProcessCpuTracker.getLastSoftIrqTime(); final int idleTime = mProcessCpuTracker.getLastIdleTime(); bstats.finishAddingCpuLocked(totalUTime, totalSTime, userTime, systemTime, iowaitTime, irqTime, softIrqTime, idleTime); } } }if (mLastWriteTime < (now-BATTERY_STATS_TIME)) { mLastWriteTime = now; mBatteryStatsService.scheduleWriteToDisk(); } } } }
【Android N 7.1.1 ActivityManagerService 获取cpu状态】
推荐阅读
- 我的Android进阶之旅------&gt;怎样将Activity变为半透明的对话框()
- Android语音播报后台播报语音识别
- Hybrid App开发之jQuery选择器
- [转]App架构设计经验谈(接口的设计)
- Android RecyclerView嵌套RecyclerView
- Android测试读写sd卡文件与写sd卡文件耗时
- Android-CheckBox 实现计算器
- exchange2010安卓手机无法配置exchange邮件
- 基于我们3组的网易云APP制作,找的APlayer H5音乐播放器