Several ways to view the memory and CPU usage of a single process on an Android system

Source: Internet
Author: User

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.

Several ways to view a single process memory and CPU usage on an Android system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.