通过adb shell dumpsys meminfo pid,我们可以获得如下内容
Applications Memory Usage (in Kilobytes): Uptime: 543447125 Realtime: 543469686 ** MEMINFO in pid 23178 [com.huawei.browser:sandboxed_process0:com.huawei.browser.sandbox.SandboxedProcessService0:6] ** Pss Private Private SwapPss Heap Heap Heap Total Dirty Clean Dirty Size Alloc Free ------ ------ ------ ------ ------ ------ ------ Native Heap 99 96 0 2028 6656 4327 2328 Dalvik Heap 4 0 0 754 3078 1030 2048 Dalvik Other 4 4 0 366 Stack 8 8 0 26 Other dev 4 0 4 0 .so mmap 535 4 0 319 .jar mmap 114 0 0 0 .apk mmap 2 0 0 0 .dex mmap 622 0 4 2617 .oat mmap 409 0 0 0 .art mmap 259 16 0 2183 Other mmap 14 0 0 6 Unknown 28 28 0 455 TOTAL 10856 156 8 8754 9734 5357 4376 App Summary Pss(KB) ------ Java Heap: 16 Native Heap: 96 Code: 8 Stack: 8 Graphics: 0 Private Other: 36 System: 10692 TOTAL: 10856 TOTAL SWAP PSS: 8754在 Android 10 以下的设备中,我们可以通过activityManager.getProcessMemoryInfo(pids) 获取进程相关的内存信息,Android 10之后的系统对这个接口加了一些限制,数据更新时间为5分钟,需要直接调用meminfo service 来dump获取这部分内容。
2.2 CPU 指标说明ProcessCpu:测试进程CPU使用率
SystemCpu:整机CPU使用率
通过读取/proc/stat文件,我们可以看到下面的内容
cpu 2490696 175785 2873834 17973539 12823 680472 230184 0 0 0 cpu0 621631 33199 739364 12893642 10736 365458 86720 0 0 0 cpu1 623944 30576 688904 677748 609 145744 93230 0 0 0 cpu2 519768 33948 650022 685194 703 78117 23873 0 0 0 cpu3 499978 33082 547153 687802 650 81072 21360 0 0 0 cpu4 32586 4853 41910 774975 36 2097 1025 0 0 0 cpu5 30950 5003 40730 776693 19 2060 999 0 0 0 cpu6 99227 22708 109219 722048 23 3970 2140 0 0 0 cpu7 62610 12414 56531 755434 44 1952 836 0 0 0 intr 209333749 0 0 0 0 35952688 0 11796562 7 5 5 17537 80 2431 0 0 0 1069962 0 35 1334360 0 0 0 0 0 11 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 34984538 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 505 50695 1174791 345 0 0 0 11301652 24660 0 111 0 0 0 0 0 0 0 0 0 0 0 86153 54 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1099230 0 18 1814 0 0 23 514624 1300943 248469 0 0 0 0 0 97168 60709 1641967 609754 38618 0 0 0 0 0 0 0 0 0 0 0 0 0 0