Linux,Android中如何查看内存

http://blog.youkuaiyun.com/hudashi/article/details/7050897

查看kernel和app,framework等内存使用情况的步骤如下:

1) 在kernel log中,可以看到被从内核中挖出去的CMA区域大小

<6>[    0.000000] Machine: Qualcomm Technologies, Inc. MSM 8916 MTP 
<6>[    0.000000] cma: Found external_image__region@0, memory base 
0x0000000086000000, size  8 MiB, limit 0xffffffffffffffff 
<6>[    0.000000] cma: Found modem_adsp_region@0, memory base 
0x0000000086800000, size 85 MiB,  limit 0xffffffffffffffff 
<6>[    0.000000] cma: Found pheripheral_region@0, memory base 
0x000000008bd00000, size 6 MiB,  limit 0xffffffffff ffffff  
<6>[    0.000000] cma: Found secure_region@0, memory base 
0x0000000000000000, size 109 MiB, limit 0xffffffffffffffff  
<6>[    0.000000] cma: Found venus_qseecom_region@0, memory base 
0x0000000000000000, size 18 MiB, limit 0x0000000090000000 
 <6>[     0.000000] cma: Found audio_region@0, memory base 
0x0000000000000000, size 3 MiB, limit 0xffffffffffffffff 

2) 打印/proc/meminfo的内容,以下是一个打印的例子
 MemTotal − 921600 kB
 MemFree − 138728 kB
 Buffers − 4616 kB
 Cached − 362008 kB

3) 被挖出去的Non-HLOS的内存大小是
Non-HLOS memory = 8 MB + 85 MB + 6 MB = 99 MB
这个大小就是上面挖出去的CMA区域中,被固定从内存中挖出去的几个区域的综合。

4) HLOS也可以说是Android Memory的大小 = MemTotal = 900MB

5) kernel占据的大小 = Total Ram - Non-HLOS 内存大小 - HLOS或者Android Memory大小 - (被另外Carveout的内存,上面的内容里边是不存在这种被另外Carveout的内存)
所以kernel占据的大小 = 1025MB - 99MB - 900MB - 0MB = 25MB

6) Free memory计算
Free memory = MemFree(/pro/meminfo打印出来的) + Cached(/pro/meminfo打印出来的) = 138728 kB + 362008 kB ~=489MB

7) 计算APP + Framework和APPs + framework 内存大小 = HLOS或者Android memory大小 - free memory = 900MB -489MB = 411MB

还有一些Android内存使用状况的adb命令
  • To get overall memory footprint , use the following commands:
    adb shell cat /proc/meminfo
    adb shell /proc/iomem
    adb shell procrank
    adb shell procrank – C
    adb shell cat /proc/zoneinfo
    adb shell dumpsys meminfo
    adb shell dumpsys SurfaceFlinger
    (Run the above command after collecting the above, as the dumpsys is known to trigger GC,
    which can cause some variation in the data).

  • Use the following command to get the details of zram configuration and copy t he zram folder
    to logs location:
    adb shell cat /proc/swaps
    adb pull /sys/block/zram0/ zram

  • If there are multiple zram devices (zram1, zram2, and so on ), get all such information. To
    know KSM savings, use the following set of commands and share the ksm folder :
    mount –t debugfs none /sys/kernel/debug
    adb pull /sys/kernel/mm/ksm/ ksm

  • To get process specific memory footprint, use the following commands
    adb shell procmem process_pid
    adb shell dumpsys meminfo process_pid
    adb shell cat /proc/ process_pid/smaps
    adb shell dumpsys procstat process_pid

  • To know all the vm settings, use the following command:
    adb shell cat /proc/sys/vm/*

  • To get LMK parameters , use the following commands:
    adb shell cat /sys/module/lowmemorykiller/parameters/adj
    adb shell cat /sys/module/lowmemorykiller/parameters/minfree

  • To understand buffer allocations in kernel , use the following command:
    nm - t d -l - r –size- sort - S vmlinux | head -50

  • To know KGSL allocations, use the following set of commands and share kgsl folder :
    mount –t debugfs none /sys/kernel/debug
    adb pull /sys/class/kgsl/kgsl/ kgsl

  • Share the build.prop file from your device :
    adb pull /system/build.prop

Memory footprint of an application

Every application has the following included as part of its memory consumption
 Uncached memory
 Cached memory
 KGSL memory
 ION memory
All QC provided process memory numbers using “dumpsys meminfo” include all the above.
Other vendors may not include KGSL and ION memory. Our representation to include kgsl and
ion is per Google’s recommendation. It is implemented in the memtrack hardware module
(/system/lib/hw/memtrack.msm8916.so) as part of our solution and exposed to upper layers (like
dumpsys, meminfo , an d so on).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值