文章目录
1. 抓取Bugreport方法
执行命令adb bugreport就可以生产文件
下面内容是介绍bugreport里面内容
2. MEMINFO内存相关
Item | 全称 | 含义 | 等价 |
---|---|---|---|
USS | Unique Set Size | 物理内存 | 进程独占的内存 |
PSS | Proportional Set Size | 物理内存 | PSS= USS+ 按比例包含共享库 |
RSS | Resident Set Size | 物理内存 | RSS= USS+ 包含共享库 |
VSS | Virtual Set Size | 虚拟内存 | VSS= RSS+ 未分配实际物理内存 |
故内存的大小关系:VSS >= RSS >= PSS >= USS
2.1 dumpsys MEMINFO
命令 dumpsys -t 90 meminfo -a,bugreport其实已经给你列出来
------ DUMPSYS MEMINFO (/system/bin/dumpsys -t 90 meminfo -a,) ------
** MEMINFO in pid 1325 [com.chinatsp.launcher] **
** MEMINFO in pid 1429 [android.process.media] **
** MEMINFO in pid 1813 [com.autonavi.amapauto] **
** MEMINFO in pid 1486 [com.chinatsp.vehicle] **
** MEMINFO in pid 1951 [com.autonavi.amapauto:locationservice] **
** MEMINFO in pid 2128 [com.autonavi.amapauto:push] **
Total RAM: 2,207,184K (status moderate)
Free RAM: 404,556K ( 71,984K cached pss + 239,896K cached kernel + 92,676K free)
Used RAM: 1,253,628K ( 741,308K used pss + 512,320K kernel)
Lost RAM: 546,557K
ZRAM: 2,680K physical used for 11,592K in swap ( 819,196K total swap)
KSM: 5,988K saved from shared 1,800K 21,448K unshared; 14,400K volatile
------ 6.181s was the duration of 'DUMPSYS MEMINFO' ------
内存分析命令
常用的内存调优分析命令:
dumpsys meminfo
procrank
cat /proc/meminfo
free
showmap
vmstat
2.2 cat MEMINFO
//查看总内存,用来看剩余内存和lowmemorykiller情况
------ MEMORY INFO (/proc/meminfo) ------
MemTotal: 2207184 kB
MemFree: 75320 kB
MemAvailable: 220244 kB
Buffers: 12148 kB
Cached: 243884 kB
SwapCached: 116 kB
Active: 604316 kB
Inactive: 379068 kB
Active(anon): 481676 kB
Inactive(anon): 256372 kB
Active(file): 122640 kB
Inactive(file): 122696 kB
Unevictable: 256 kB
Mlocked: 256 kB
SwapTotal: 819196 kB
SwapFree: 805988 kB
Dirty: 2284 kB
Writeback: 0 kB
AnonPages: 727512 kB
Mapped: 133696 kB
Shmem: 10692 kB
Slab: 326776 kB
SReclaimable: 73256 kB
SUnreclaim: 253520 kB
KernelStack: 23344 kB
PageTables: 38372 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 1922788 kB
Committed_AS: 90383252 kB
VmallocTotal: 258867136 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
CmaTotal: 36864 kB
CmaFree: 0 kB
------ 0.011s was the duration of 'MEMORY INFO' ------
2.3 dumpsys PROCRANK
procrank是按照内存占用情况对进程进行排序
------ PROCRANK (/system/xbin/su root procrank) ------
PID Vss Rss Pss Uss Swap PSwap USwap ZSwap cmdline
889 4607636K 161892K 133731K 132884K 1748K 44K 0K 11K com.chinatsp.tdmsservice.TDmsBootService
1325 4439512K 102372K 68696K 66424K 1720K 43K 0K 10K com.chinatsp.launcher
784 4417216K 99640K 65627K 63108K 1684K 42K 0K 10K com.android.systemui
2.4 showmap
------ SHOW MAP 784 (com.android.systemui) (/system/xbin/su root showmap -q 784) ------
virtual shared shared private private
size RSS PSS clean dirty clean dirty swap swapPSS # object
-------- -------- -------- -------- -------- -------- -------- -------- -------- ---- ------------------------------
12 12 4 8 0 0 4 0 0 2 /data/dalvik-cache/arm64/system@framework@boot-QPerformance.art
56 56 44 8 4 0 44 0 0 2 /data/dalvik-cache/arm64/system@framework@boot-android.car.art
12 12 0 4 8 0 0 0 0 2 /data/dalvik-cache/arm64/system@framework@boot-android.hidl.base-V1.0-java.art
16 16 0 8 8 0 0 0 0 2 /data/dalvik-cache/arm64/system@framework@boot-android.hidl.manager-V1.0-java.art
总结
- dumpsys meminfo适用场景: 查看进程的oom adj,或者dalvik/native等区域内存情况,或者某个进程或apk的内存情况,功能非常强大;
- procrank适用场景: 查看进程的VSS/RSS/PSS/USS各个内存指标;
- cat /proc/meminfo适用场景: 查看系统的详尽内存信息,包含内核情况;
- free适用场景: 只查看系统的可用内存;
- showmap适用场景: 查看进程的虚拟地址空间的内存分配情况;
- vmstat适用场景: 周期性地打印出进程运行队列、系统切换、CPU时间占比等情况;
3. CPUINFO
3.1 dumpsys cpuinfo
//dumpsys -t 10 cpuinfo -a -t 10是10秒的timeout时间,默认10
------ DUMPSYS CPUINFO (/system/bin/dumpsys -t 10 cpuinfo -a) ------
Load: 3.26 / 4.94 / 3.04
CPU usage from 9895ms to 1179ms ago (2019-12-10 05:36:34.522 to 2019-12-10 05:36:43.238):
49% 475/system_server: 25% user + 24% kernel / faults: 4311 minor 2 major
...
87% TOTAL: 24% user + 55% kernel + 5.7% iowait + 0.7% irq + 1.2% softirq
3.2 top
top cpuinfo
------ CPU INFO (top -b -n 1 -H -s 6 -o pid,tid,user,pr,ni,%cpu,s,virt,res,pcy,cmd,name) ------
Tasks: 1457 total, 4 running,1453 sleeping, 0 stopped, 0 zombie
Mem: 2207184k total, 2131188k used, 75996k free, 11568k buffers
Swap: 819196k total, 13508k used, 805688k free, 231900k cached
400%cpu 0%user 0%nice 0%sys 400%idle 0%iow 0%irq 0%sirq 0%host
PID TID USER PR NI[%CPU]S VIRT RES PCY CMD NAME
6105 6105 shell 0 -20 61.7 R 11M 3.2M fg top top
1193 1193 mediacodec 20 0 20.7 S 266M 10M fg omx@1.0-service media.codec
4. PROCESSES AND THREADS (进程和线程)
//常用来查,pid对应的包名或者线程名,以及是否有线程泄漏
命令:
ps -A -T -Z -O pri,nice,rtprio,sched,pcy
------ PROCESSES AND THREADS (ps -A -T -Z -O pri,nice,rtprio,sched,pcy) ------
LABEL USER PID TID PPID VSZ RSS WCHAN ADDR S PRI NI RTPRIO SCH PCY CMD
u:r:system_app:s0 system 1840 1877 315 4707172 57828 0 0 S 19 0 - 0 fg android.dvrservice
u:r:system_app:s0 system 1840 1885 315 4707172 57828 0 0 S 19 0 - 0 fg android.dvrservice
u:r:system_app:s0 system 1840 1892 315 4707172 57828 0 0 S 19 0 - 0 fg android.dvrservice
u:r:system_app:s0 system 1840 1893 315 4707172 57828 0 0 S 19 0 - 0 fg android.dvrservice
u:r:system_app:s0 system 1840 1931 315 4707172 57828 0 0 S 19 0 - 0 fg android.dvrservice
u:r:system_app:s0 system 1840 1932 315 4707172 57828 0 0 S 19 0 - 0 fg android.dvrservice
5. PRINTENV环境变量
------ PRINTENV (printenv) ------
PATH=/sbin:/system/sbin:/system/bin:/system/xbin:/vendor/bin:/vendor/xbin
DOWNLOAD_CACHE=/data/cache
ANDROID_BOOTLOGO=1
ANDROID_ROOT=/system
ANDROID_ASSETS=/system/app
ANDROID_DATA=/data
6. Android Log(main system kernel event radio)
6.1 kernel log
------ KERNEL LOG (dmesg) ------
<6>[ 0.000000] Booting Linux on physical CPU 0x0
<6>[ 0.000000] Initializing cgroup subsys cpu
<6>[ 0.000000] Initializing cgroup subsys cpuacct
<5>[ 0.000000] Linux version 4.4.178-g3634edb (test@ubuntu) (gcc version 4.9.x 20150123 (prerelease) (GCC) ) #1 SMP PREEMPT Tue Dec 10 04:39:26 CST 2019
<6>[ 0.000000] Boot CPU: AArch64 Processor [512f2011]
6.2 SYSTEM EVENT RADIO log
------ SYSTEM LOG (logcat -v threadtime -v printable -v uid -d *:v) ------
------ EVENT LOG (logcat -b events -v threadtime -v printable -v uid -d *:v) ------
------ RADIO LOG (logcat -b radio -v threadtime -v printable -v uid -d *:v) ------
7. lsof
lsof命令用于查看进程开打的文件,打开文件的进程,进程打开的端口(TCP、UDP)。lsof必须以root运行。
//因此考虑用来查看fdleak,一般fdleak会单独打印进程的情况
------ LIST OF OPEN FILES (/system/xbin/su root lsof) ------
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
init 1 root cwd DIR 251,0 4096 2 /
init 1 root rtd DIR 251,0 4096 2 /
init 1 root txt REG 251,0 1587064 15 /init
init 1 root mem REG 251,0 1587064 15 /init
init 1 root mem REG 0,18 131072 1379 /dev/__properties__/properties_serial
init 1 root mem REG 0,18 131072 1378 /dev/__properties__/u:object_r:bluetooth_prop:s0
init 1 root mem REG 0,18 131072 1377 /dev/__properties__/u:object_r:config_prop:s0
8. getprop
------ SYSTEM PROPERTIES (getprop) ------
[ro.build.version.release]: [8.1.0]
[ro.build.version.sdk]: [27]
9. binder
//binder调试log主要有
//1
outgoing transaction 623807: edbbfa40 from 30228:1612 to 15625:15635 code 1 flags 10 pri 10 r1 node 222269 size 740:4 data fb600404
//2
1.binder_sample
A.功能说明: 监控每个进程的主线程的binder transaction的耗时情况, 当超过阈值时,则输出相应的目标调用信息,默认1000ms打开。
b.log实例:
2754 2754 I binder_sample: [android.app.IActivityManager,35,2900,android.process.media,5]
从上面的log中可以得出
1.主线程2754;
2.执行android.app.IActivityManager接口
所对应方法code =35(即STOP_SERVICE_TRANSACTION),
所花费时间为2900ms.
该block所在package为 android.process.media,最后一个参数是sample比例(没有太大价值)
------ BINDER FAILED TRANSACTION LOG (/sys/kernel/debug/binder/failed_transaction_log) ------
425547: async from 1534:1534 to 0:0 context binder node 0 handle 10 size 88:0 ret 29189/-22 l=3020
442762: reply from 475:908 to 0:0 context binder node 0 handle -1 size 4:0 ret 29189/0 l=2952
448906: reply from 475:725 to 0:0 context binder node 0 handle -1 size 4:0 ret 29189/0 l=2952
463378: reply from 475:908 to 0:0 context binder node 0 handle -1 size 4:0 ret 29189/0 l=2952
------ 0.009s was the duration of 'BINDER FAILED TRANSACTION LOG' ------
------ BINDER FAILED TRANSACTION LOG (/sys/kernel/debug/binder/failed_transaction_log) ------
425547: async from 1534:1534 to 0:0 context binder node 0 handle 10 size 88:0 ret 29189/-22 l=3020
442762: reply from 475:908 to 0:0 context binder node 0 handle -1 size 4:0 ret 29189/0 l=2952
448906: reply from 475:725 to 0:0 context binder node 0 handle -1 size 4:0 ret 29189/0 l=2952
463378: reply from 475:908 to 0:0 context binder node 0 handle -1 size 4:0 ret 29189/0 l=2952
------ 0.009s was the duration of 'BINDER FAILED TRANSACTION LOG' ------
------ BINDER TRANSACTION LOG (/sys/kernel/debug/binder/transaction_log) ------
498740: reply from 1193:1423 to 1840:2003 context hwbinder node 0 handle -1 size 8:0 ret 0/0 l=0
498741: async from 1193:2024 to 1840:0 context hwbinder node 52563 handle 1 size 208:32 ret 0/0 l=0
498742: call from 1857:2769 to 390:0 context binder node 92563 handle 8 size 104:0 ret 0/0 l=0
498743: reply from 390:1115 to 1857:2769 context binder node 0 handle -1 size 28:0 ret 0/0 l=0
498744: call from 1840:1932 to 1193:0 context hwbinder node 55266 handle 4 size 72:0 ret 0/0 l=0
498745: reply from 1193:1423 to 1840:1932 context hwbinder node 0 handle -1 size 12:0 ret 0/0 l=0
------ 0.009s was the duration of 'BINDER TRANSACTION LOG' ------
------ BINDER TRANSACTIONS (/sys/kernel/debug/binder/transactions) ------
binder transactions:
proc 2128
context binder
buffer 497227: ffffff800e4a2000 size 4:0:0 delivered
proc 1813
context hwbinder
buffer 54396: ffffff800b0e2000 size 44:8:8 delivered
proc 1840
context hwbinder
buffer 498760: ffffff8016eff000 size 8:0:0 delivered
buffer 498779: ffffff8016eff008 size 88:16:72 delivered
10. activity
------ APP ACTIVITIES (/system/bin/dumpsys -t 30 activity -v all) ------
------ APP SERVICES (/system/bin/dumpsys -t 30 activity service all) ------
------ APP PROVIDERS (/system/bin/dumpsys -t 30 activity provider all) ------
//查看进程oom信息
dumpsys activity oom
11. package
dumpsys package
12. crash
12.1 system_server_crash
------ DROPBOX SYSTEM SERVER CRASHES (/system/bin/dumpsys -t 30 dropbox -p system_server_crash) ------
Drop box contents: 242 entries
Max entries: 1000
Searching for: system_server_crash
========================================
2019-12-10 05:25:48 system_server_crash (text, 1631 bytes)
Process: system_server
12.2 system_app_crash
------ DROPBOX SYSTEM APP CRASHES (/system/bin/dumpsys -t 30 dropbox -p system_app_crash) ------
Process: com.example.serviceclient
PID: 1574
Flags: 0x38c8be45
Package: com.example.serviceclient v27 (8.1.0)
Foreground: Yes
Build: Android/jmev_gse/msm8996_gvmq:8.1.0/OPM1.171019.026/wangdo12181429:userdebug/test-keys
java.lang.NoClassDefFoundError: Failed resolution of: Lone/mcuadapter/DpcMcuAdapter$CMMIGestureInfo;
at com.example.serviceclient.MainActivity.createMMIGestureInfo(MainActivity.java:108)
at com.example.serviceclient.MainActivity.testproto(MainActivity.java:102)
at com.example.serviceclient.MainActivity$3.onClick(MainActivity.java:84)
at android.view.View.performClick(View.java:6302)
13. dumpsys -l
查看服务列表
14. trace
dump trace可以搜索Cmd line:,非常有用
Cmd line: /vendor/bin/hw/android.hardware.audio@2.0-service
Cmd line: /vendor/bin/hw/android.hardware.bluetooth@1.0-service-qti
Cmd line: /vendor/bin/hw/android.hardware.graphics.composer@2.1-service
Cmd line: /vendor/bin/hw/android.hardware.sensors@1.0-service
Cmd line: /system/bin/surfaceflinger
Cmd line: system_server
Cmd line: /system/bin/audioserver
Cmd line: com.android.bluetooth
Cmd line: /system/bin/sdcard
Cmd line: com.android.car
Cmd line: com.android.systemui
14.1 dump java trace
//可以通过kill -3 pid来java进程获取trace,如下trace_01
msm8996_gvmq:/data/anr # ls
dumptrace_2IYtOo trace_00 trace_01
14.1 dump native trace
native进程通过debuggerd打印trace
debuggerd -b 18944
来源:CSDN
作者:wd623894174
链接:https://blog.csdn.net/wd229047557/article/details/103730653