Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Linux,Android中如何查看內存

Linux,Android中如何查看內存

編輯:關於Android編程

查看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).

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved