memory usage分析

文摘 无标签 2020-03-24 阅读:15283

1. Check system overall memory

1-1. adb shell cat /proc/meminfo 
meminfo1.png

1-2. adb shell dumpsys meminfo

meminfo2.png
meminfo3.png

      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 

procrank1.png

2. Check single process memory

2-1. adb shell dumpsys meminfo $pid

dumpsysmeminfo1.png

名称算法
Systemtotal-private Clean 列总和+private dirty列总和
Stack stack private dirty 
PSS totalPss Total列总和 + SwapPss Dirty列总和
Private otherprivate clean列+private dirty列-java heap-native heap-code-stack-graphic
Native heapnative private dirty
Java heapDalvik 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

showmap2.png

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表示LTKionion区域的mwmory 总量
[time]当前的kernel 时间swpin换入的次数
memfr空闲的memoryswpout换出的次数
swpfrswap区域的free量fmflt系统发生file page fault的次数
cache缓存占用的memory的量[normal: 0normal 区域buddy的情况
kernel_stack内核栈用的量[high: 0high区域的buddy情况
page_tablepage table占用的量[pid]进程PID
slabslab区域使用的memoryadjadj值
gpugpu使用的memoryrss
gpu_page_cachegpu部分缓存用的量rswp
zramzram区域的mwmory 总量pswpin进程的文件发生的换入次数
activeactive区域的mwmory 总量pswpout进程的文件发生的换出次数
inactiveinactive区域的mwmory 总量pfmlt进程PID文件缺页异常发生的次数
shmemshmem区域的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)

tfma1.png

tfma2.png

tfma3.png

tfma4.png

tfma5.png

0条评论

© 2024 芯缘异码. Powered by Typecho