memory usage分析
文摘 无标签 2020-03-24 阅读:152831. Check system overall memory
1-1. adb shell cat /proc/meminfo
1-2. adb shell dumpsys meminfo
total PSS = cached pss + used pss (cached pss : adj >=900 process pss sum , used pss : adj <900 process pss sum)
total kernel = cached kernel + kernel
cached kernel : slab reclaimable + buffers + cached - mapped
kernel : slab unreclaimable + shmem + vmalloc + page tables + kernel stack
查看 kernel slab使用情况
- FAQ21613 [Memory]如何分析slab占用内存细节以及slab leak
- FAQ21615 [Memory]如何查询内核所有 page 的使用情况 (by page owner)
1-3. adb shell procrank
2. Check single process memory
2-1. adb shell dumpsys meminfo $pid
名称 | 算法 |
---|---|
System | total-private Clean 列总和+private dirty列总和 |
Stack | stack private dirty |
PSS total | Pss Total列总和 + SwapPss Dirty列总和 |
Private other | private clean列+private dirty列-java heap-native heap-code-stack-graphic |
Native heap | native private dirty |
Java heap | Dalvik private dirty+.art mmap private clean+.art mmap private dirty |
Graphics | GL mtrack private (clean + dirty) + EGL mtrack private(clean + dirty) |
Code | .so private (clean+dirty) + .jar private (clean+dirty) + .apk private (clean+dirty) + .ttf private (clean+ dirty) + .dex private (clean + dirty) + .oat private (clean + dirty) |
Java heap :
抓取hprof 排查 heap 分布 (FAQ08893 如何抓取app 进程的hprof)
Native heap
Quick Start > 内存泄漏专题分析 > native内存泄漏
或参考/development/scripts/native_heapdump_viewer.py 使用malloc debug + adb shell am dumpheap $pid 查看
1. Collect a native heap dump from the device. For example:
$ adb shell stop
$ adb shell setprop libc.debug.malloc.program app_process
$ adb shell setprop libc.debug.malloc.options backtrace=64
$ adb shell start
(launch and use app)
$ adb shell am dumpheap -n <pid> /[data](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=/data/&project=development)/[local](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=/data/local/&project=development)/[tmp](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=/data/local/tmp/&project=development)/[native_heap.txt](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=/data/local/tmp/native_heap.txt&project=development)
$ adb pull /[data](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=/data/&project=development)/[local](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=/data/local/&project=development)/[tmp](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=/data/local/tmp/&project=development)/[native_heap.txt](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=/data/local/tmp/native_heap.txt&project=development)
2. Run the viewer:
$ python [native_heapdump_viewer.py](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=native_heapdump_viewer.py&project=development) [options] [native_heap.txt](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=native_heap.txt&project=development)
[--verbose]: verbose output
[--html]: interactive html output
[--reverse]: reverse the backtraces (start the tree from the leaves)
[--symbols SYMBOL_DIR] SYMBOL_DIR is the directory containing the .so files with symbols.
Defaults to $[ANDROID_PRODUCT_OUT](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=ANDROID_PRODUCT_OUT/&project=development)/[symbols](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=ANDROID_PRODUCT_OUT/symbols&project=development)
[--app-symbols SYMBOL_DIR] SYMBOL_DIR is the directory containing the app APK and so files.
Defaults to the current directory.
This outputs a file with lines of the form:
5831776 29.09% 100.00% 10532 71b07bc0b0 /[system](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=/system/&project=development)/[lib64](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=/system/lib64/&project=development)/[libandroid_runtime.so](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=/system/lib64/libandroid_runtime.so&project=development) Typeface_createFromArray [frameworks](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=frameworks/&project=development)/[base](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=frameworks/base/&project=development)/[core](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=frameworks/base/core/&project=development)/[jni](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=frameworks/base/core/jni/&project=development)/[android](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=frameworks/base/core/jni/android/&project=development)/[graphics](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=frameworks/base/core/jni/android/graphics/&project=development)/[Typeface.cpp](http://mbjswglx817:8010/alps-mp-q0.mp1/s?path=frameworks/base/core/jni/android/graphics/Typeface.cpp&project=development):68
5831776 is the total number of bytes allocated at this stack frame, which
is 29.09% of the total number of bytes allocated and 100.00% of the parent
frame's bytes allocated. 10532 is the total number of allocations at this
stack frame. 71b07bc0b0 is the address of the stack frame.
Graphics
FAQ22290 [Memory]如何查看ion memory usage
FAQ22281 [Memory]如何查看gpu memory 讯息
Quick Start > 内存泄漏专题分析 > native内存泄漏 > ion内存泄漏
2-2.adb shell system/bin/showmap $pid
list memory detail of a process, the data was collected from smaps
2-3.adb shell cat /proc/$pid/smaps
list memory detail of a process
3. Memory tracking by mlog
3-1 how to get mlog
/d/mlog : cat /d/mlog will update periodically (1s)
/d/dmlog : the last mlog (about last ~30s mlog) (it is also SYS_MEMORY_LOG in SWT/ANR/NE db)
3-2 mlog format
ITEM | 说明 | ITEMs | 说明 |
---|---|---|---|
type> | 表示触发mlog的原因,0表示是timer触发,1表示是LMK,2表示LTK | ion | ion区域的mwmory 总量 |
[time] | 当前的kernel 时间 | swpin | 换入的次数 |
memfr | 空闲的memory | swpout | 换出的次数 |
swpfr | swap区域的free量 | fmflt | 系统发生file page fault的次数 |
cache | 缓存占用的memory的量 | [normal: 0 | normal 区域buddy的情况 |
kernel_stack | 内核栈用的量 | [high: 0 | high区域的buddy情况 |
page_table | page table占用的量 | [pid] | 进程PID |
slab | slab区域使用的memory | adj | adj值 |
gpu | gpu使用的memory | rss | |
gpu_page_cache | gpu部分缓存用的量 | rswp | |
zram | zram区域的mwmory 总量 | pswpin | 进程的文件发生的换入次数 |
active | active区域的mwmory 总量 | pswpout | 进程的文件发生的换出次数 |
inactive | inactive区域的mwmory 总量 | pfmlt | 进程PID文件缺页异常发生的次数 |
shmem | shmem区域的mwmory 总量 |
see also:FAQ21497 mlog 信息查看及其初步的分析
FAQ21888 mlog 信息抓取时间间隔以及其它有用的调整参数
FAQ21889 mlog (SYS_MEMORY_LOG) 的 buffer size 如何修改
3-3 use TfMA tool to parsing mlog (get this tool from submit e-service request)