ADB Fetch memory command

Source: Internet
Author: User
Tags cpu usage

1. View the log information in the IDE
When the program runs garbage collection, a log message is printed with the following format:
D/DALVIKVM: <GC_Reason> <amount_freed>,
Gc_reason represents the cause of garbage collection and the current collection type, including the following categories:
Gc_concurrent: Garbage collection that is triggered when the number of objects in the heap reaches a certain level
Gc_for_malloc: Allocates memory when memory is full and the system pauses the program and reclaims memory
Gc_hprof_dump_heap: Creating a fpfor file to analyze garbage collection caused by HEAP
GC_EXPLICIT: The program called the garbage collection function System.GC

Gc_external_alloc: A garbage collection that appears in API 10 and below, for external allocation of memory (native memory or NIO buffer), and the high version is all allocated in the Dalvik heap.

Amount_freed indicates that the recovered memory

Heap_stats indicates the percentage of free memory and the total size of the surviving object/heap

External_memory_stats represents API 10 and below for externally allocated memory, allocated memory/boundary that causes garbage collection

Pause_time pause time, one representing the start of garbage collection time, the other represents the end of the recovery of the pause time

D/DALVIKVM (9050): Gc_concurrent freed 2049K, 65% free 3571k/9991k, external 4703k/5261k, paused 2ms+2ms
Note the "3571k/9991k" value in this message, which represents the heap size used by the program.

2. Using DDMS
Ddms in Eclipse provides a GUI that looks at memory usage, and when we repeatedly click Cause GC, we see the heap of the current program, which is convenient to use and can be used for Google.

3. Use the ADB dumpsys command
ADB is a very powerful tool for viewing application memory usage using ADB to view memory usage on the command line in the following format:
adb shell Dumpsys meminfo <package_name>
Among them, package_name can also be replaced by program Pid,pid can be through the adb shell top | grep app_name to find, is the memory usage of a program:

Here are a few fields to focus on:
(1) Heap information for Native/dalvik
Specifically in the first and second lines above, it gives the JNI layer and the Java layer of memory allocation, if it is found that the value has been increasing, the representative of the program may have a memory leak.

(2) PSS information for total
This value is the amount of memory your app really occupies, and with this information, you can easily identify which programs in your phone are more memory-heavy.

4. Using adb shell Procrank
The SH in the phone is streamlined, some phones may not have Procrank commands, can use the Genymotion simulator, or install Procrank commands themselves. When using Procrank, the output of the command line is entered:

As you can see, there are four different representations of memory consumption under Linux:
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)


Vss:vss represents the size of all memory address space that a process can access. This size includes memory space that the process has requested but not yet used. In practice, it is seldom used in this way to indicate that a process consumes memory, and it is used to indicate that the memory usage of a single process is inaccurate.
RSS: Represents the amount of space that a process actually uses in RAM, including the memory that is consumed by all shared libraries, which is also inaccurate for the process that is consuming memory.
PSS: Represents the space address size that a process actually uses in RAM, which proportionally contains the memory occupied by the shared library. If there are 3 processes using the same shared library, the PSS for each process includes a 1/3 size shared library memory. This means that the memory usage of the process is more accurate, but when only one process uses the shared library, the situation is exactly the same as RSS.
USS: Represents the amount of memory space that a process itself occupies and does not contain any other components, which is the best way to represent the size of the process memory!
can see: Vss>=rss>=pss>=uss

5. Other common command commands:
adb shell kill Pidnumber The background process you want to kill to simulate the recurrence condition of a bug.
adb shell PS View process information in the current terminal

So how do you determine how much RAM the current hardware system has in your code? The following code is available in the Framework Processlist.java:
Processlist () {
Meminforeader minfo = new Meminforeader ();
Minfo.readmeminfo ();
MTOTALMEMMB = Minfo.gettotalsize ()/(1024*1024);
}

To view the CPU usage of a process: adb shell top-n 1-d 0.5 | grep proc_ ID

ADB Fetch memory command

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.