First, use the Android API function to view
1.1 Activitymanager View available memory.
Activitymanager.memoryinfo outinfo = new Activitymanager.memoryinfo ();
Am.getmemoryinfo (Outinfo);
Outinfo.availmem is available free memory.
1.2, Android.os.Debug query Pss,vss,uss and other individual processes using memory information
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 GKFX Dirty memory usage in KB.RSS
Second, directly to the Android file parsing query,
/proc/cpuinfo a variety of information such as the type of system CPU.
/proc/meminfo System memory usage information
Such as
/proc/meminfo
memtotal:16344972 KB
memfree:13634064 KB
buffers:3656 KB
cached:1195708 KB
When we look at the machine memory, we find that the value of Memfree is very small. This is mainly because, in Linux there is such a thought, the memory is not white, so it as far as possible cache and buffer some data to facilitate the next use. But in fact, the memory is also available for immediate use.
So free memory =free+buffers+cached=total-used
Get the total amount of memory by reading the file/proc/meminfo information.
Activitymanager. Getmemoryinfo (activitymanager.memoryinfo) Gets the current amount of memory available.
Third, through the runtime class provided by the Android system, execute the ADB command (Top,procrank,ps ... and other commands) query
The standard console output for execution results is parsed. This greatly expands the Android query function. For example:
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");
Memory consumption: Vss/rss/pss/uss
Terms
vss-virtual Set Size Virtual memory consumption (contains memory consumed by shared libraries)
rss-resident Set Size actually uses physical memory (contains memory consumed by shared libraries)
pss-proportional Set Size actual physical memory used (proportional allocation of memory consumed by shared libraries)
Uss-unique The Set Size process consumes the physical memory alone (does not contain the memory occupied by the shared library)
In general, memory footprint has the following rules: VSS >= RSS >= PSS >= USS
USS is the total private memory for a process, i.e. that's memory that's 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 was killed, the USS is actually returned to the system. USS is the best number to watch when initially suspicious of memory leaks in a process.
View Android memory usage and CPU information