赞
踩
文章出处:https://blog.csdn.net/shift_wwx/article/details/42555135
根据android 中的dumpsys和android 查看内存使用情况不做过多的source code解析。
根据:
ServiceManager.addService("cpuinfo", new CpuBinder(m));
找到CpuBinder:
- @Override
- protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
- if (mActivityManagerService.checkCallingPermission(android.Manifest.permission.DUMP)
- != PackageManager.PERMISSION_GRANTED) {
- pw.println("Permission Denial: can't dump cpuinfo from from pid="
- + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
- + " without permission " + android.Manifest.permission.DUMP);
- return;
- }
-
- synchronized (mActivityManagerService.mProcessCpuThread) {
- pw.print(mActivityManagerService.mProcessCpuTracker.printCurrentLoad());
- pw.print(mActivityManagerService.mProcessCpuTracker.printCurrentState(
- SystemClock.uptimeMillis()));
- }
- }
最终就可以获取cpu使用情况了:
- 130|root@h15:/ # dumpsys cpuinfo
- Load: 0.44 / 0.49 / 0.5
- CPU usage from 79896ms to 19892ms ago:
- 48% 3803/kdvb-ad-0-fe-0: 0% user + 48% kernel
- 0.5% 6221/kworker/1:0: 0% user + 0.5% kernel
- 0.5% 6336/kworker/0:1: 0% user + 0.5% kernel
- 0.2% 2586/tvserver: 0% user + 0.2% kernel
- 0.1% 1549/kthread_di: 0% user + 0.1% kernel
- 0% 3749/system_server: 0% user + 0% kernel / faults: 1 minor
- 0% 2591/surfaceflinger: 0% user + 0% kernel
- 0% 3887/com.android.systemui: 0% user + 0% kernel / faults: 4 minor
- 0% 4034/com.qiyi.video: 0% user + 0% kernel / faults: 2 minor
- 25% TOTAL: 0% user + 25% kernel
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。