getTotalPrivateDirty()
Return total private dirty memory usage in kB. USS
getTotalPss()
Return total PSS memory usage in kB.
PSS
getTotalSharedDirty()
Return total shared dirty memory usage in kB. RSS
二、直接对Android文件进行解析查询
/proc/cpuinfo系统CPU的类型等多种信息。
/proc/meminfo 系统内存使用信息
如
/proc/meminfo
MemTotal: 16344972 kB
MemFree: 13634064 kB
Buffers: 3656 kB
Cached: 1195708 kB
我们查看机器内存时,会发现MemFree的值很小。这主要是因为,在linux中有这么一种思想,内存不用白不用,因此它尽可能的cache和buffer一些数据,以方便下次使用。但实际上这些内存也是可以立刻拿来使用的。
所以 空闲内存=free+buffers+cached=total-used
通过读取文件/proc/meminfo的信息获取Memory的总量。
ActivityManager. getMemoryInfo(ActivityManager.MemoryInfo)获取当前的可用Memory量。
三、通过Android系统提供的Runtime类,执行adb 命令(top,procrank,ps...等命令)查询
通过对执行结果的标准控制台输出进行解析。这样大大的扩展了Android查询功能.例如:
final Process m_process = Runtime.getRuntime().exec("/system/bin/top -n 1");
final StringBuilder sbread = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(m_process.getInputStream()), 8192);
# procrank
Runtime.getRuntime().exec("/system/xbin/procrank");
内存耗用:VSS/RSS/PSS/USS
Terms
• VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
• RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)
• PSS - Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存)
• USS - Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)
一般来说内存占用大小有如下规律:VSS >= RSS >= PSS >= USS
USS is the total private memory for a process, i.e. that memory that is completely unique to that process.USS is an extremely useful number because it indicates the true incremental cost of running a particular process. When a process is killed, the USS is the total memory that is actually returned to the system. USS is the best number to watch when initially suspicious of memory leaks in a process.
四、dumpsys
dumpsys meminfo
Applications Memory Usage (kB):
Uptime: 1031937 Realtime: 1167591179860
Total PSS by process:
44049 kB: com.skyworth.launchersky_app_home (pid 911)
16839 kB: system (pid 791)
12835 kB: com.skyworth.standardservices (pid 1310)
11233 kB: com.android.wallpaper (pid 881)
9791 kB: com.skyworth.sky_app_atv (pid 1018)
9782 kB: android.process.media (pid 1232)
9622 kB: com.skyworth.hotkey (pid 1666)
9279 kB: com.android.systemui (pid 866)
7400 kB: com.android.email (pid 1265)
7318 kB: com.mstar.tv.service (pid 1246)
6980 kB: com.skyworthdigital.stb.dataprovider (pid 1335)
5808 kB: com.android.exchange (pid 1286)
4923 kB: com.android.inputmethod.pinyin (pid 892)
4351 kB: com.android.providers.calendar (pid 985)
4132 kB: com.android.calendar (pid 961)
3548 kB: com.android.deskclock (pid 1059)
Total PSS by OOM adjustment:
16839 kB: System
16839 kB: system (pid 791)
9279 kB: Persistent
9279 kB: com.android.systemui (pid 866)
44049 kB: Foreground
44049 kB: com.skyworth.launchersky_app_home (pid 911)
11233 kB: Visible
11233 kB: com.android.wallpaper (pid 881)
25076 kB: Perceptible
12835 kB: com.skyworth.standardservices (pid 1310)
7318 kB: com.mstar.tv.service (pid 1246)
4923 kB: com.android.inputmethod.pinyin (pid 892)
6980 kB: A Services
6980 kB: com.skyworthdigital.stb.dataprovider (pid 1335)
9791 kB: Previous
9791 kB: com.skyworth.sky_app_atv (pid 1018)
44643 kB: Background
9782 kB: android.process.media (pid 1232)
9622 kB: com.skyworth.hotkey (pid 1666)
7400 kB: com.android.email (pid 1265)
5808 kB: com.android.exchange (pid 1286)
4351 kB: com.android.providers.calendar (pid 985)
4132 kB: com.android.calendar (pid 961)
3548 kB: com.android.deskclock (pid 1059)
Total PSS by category:
56161 kB: Dalvik
30951 kB: Native
28795 kB: Unknown
24122 kB: .so mmap
18489 kB: .dex mmap
7047 kB: Other mmap
1109 kB: .ttf mmap
1036 kB: .apk mmap
88 kB: Other dev
52 kB: Ashmem
24 kB: .jar mmap
16 kB: Cursor
Total PSS: 167890 kB
转自:http://blog.csdn.net/kieven2008/article/details/6445421