1. Use Android API functions to view
1.1 activitymanager view available memory.
Activitymanager. memoryinfo outinfo = new activitymanager. memoryinfo ();
Am. getmemoryinfo (outinfo );
Outinfo. availmem is available idle memory.
1.2. Android. OS. debug queries memory usage information of a single process, such as PSS, VSS, and USS.
Memoryinfo [] memoryinfoarray = aM. getprocessmemoryinfo (PIDS );
Memoryinfo pidmemoryinfo = memoryinfoarray [0];
Pidmemoryinfo. gettotalprivatedirty ();
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
2. parse and query Android files directly
/Proc/cpuinfo system CPU type and other information.
/Proc/meminfo system memory usage information
For example
/Proc/meminfo
Memtotal: 16344972 KB
Memfree: 13634064 KB
Buffers': 3656 KB
Cached: 1195708 KB
When we look at the machine memory, we will find that the memfree value is very small. This is mainly because there is such an idea in Linux, the memory does not need to be white, so it tries its best to cache and buffer some data for the next use. But in fact, these memories can also be used immediately.
So free memory = free + buffers + cached = total-used
Obtain the total amount of memory by reading the/proc/meminfo file.
Activitymanager. getmemoryinfo (activitymanager. memoryinfo) gets the current amount of available memory.
3. Run the ADB command (top, procrank, PS..., and other commands) to query the runtime class provided by the Android system.
Parse the standard console output of the execution result. This greatly extends the android query function. For example:
Final process m_process = runtime.getruntime(cmd.exe C ("/system/bin/top-N 1 ");
Final stringbuilder sbread = new stringbuilder ();
Bufferedreader = new bufferedreader (New inputstreamreader (m_process.getinputstream (), 8192 );
# Procrank
Runtime.getruntime(cmd.exe C ("/system/xbin/procrank ");
Memory consumption: VSS/RSS/PSS/USS
Terms
• VSS-virtual set size virtual memory consumption (including memory occupied by shared libraries)
• RSS-resident set size actually uses physical memory (including memory occupied by shared libraries)
• Pss-proportional set size physical memory actually used (proportional allocation of memory occupied by the Shared Library)
• Uss-unique set size physical memory occupied by the process (excluding the memory occupied by the Shared Library)
Generally, the memory usage is as follows: 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 special 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.
Iv. 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. Taobao clock (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. Taobao clock (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
From: http://blog.csdn.net/kieven2008/article/details/6445421