"Go" Android How to view CPU usage and memory leaks

Source: Internet
Author: User

Original URL: http://www.cnblogs.com/yejiurui/p/3472765.html

In the process of analyzing memory optimization, one of the most important is how we look at the CPU occupancy rate and memory occupancy rate, which is important to a certain extent, after querying the data, studied, temporarily learned about the following several ways, if the master has a better way, or the text described in error, Also hope that the master in the following message, thank you very much!

First, through the Eclipse,adt development tool DDMS to view (HEAP)

In the Devices window, select a program in the emulator that needs to be viewed, choose the "Update heap" button from the toolbar, set the "heap Updates" to the program, and then click Cause in the heap view. The GC can show the memory and CPU usage of the program in real time.

The following interface will then appear:

A) Clicking on the "Cause GC" button is equivalent to requesting a GC operation from the virtual machine;
b) When the memory usage information is displayed for the first time, there is no need to continuously click on "Cause GC", the heap view interface will be refreshed periodically, and the memory usage changes can be seen during the continuous operation of the application.
c) The parameters of the memory usage information can be understood by name, and will not be mentioned here.

The general analysis is as follows:

This is the memory footprint of the current application, allocated is the allocated memory free memory,

Heap size is a virtual machine that is not assigned a fixed value
The maximum value of the heap size is associated with the phone

Some netizens say,

Generally, the majority of 1byte is the image of the occupied

How can you tell if there is a possibility of a memory leak in your application?

How do we know if our program has the possibility of a memory leak? Here's a value to note: In the middle of the heap view, there is a type called data object, which is an object of the class type that exists in our program. In the data object row, there is a column "total size", whose value is the amount of memory for all Java data Objects in the current process, in general, the size of this value determines whether there is a memory leak. It can be judged as follows:
A) continuously operate the current application, while observing the total size value of the data object;
b) The total size value will be stable in a limited range under normal circumstances, that is, because the code in the program is good, no object is not garbage collection, so that although our continuous operation will continue to generate a lot of objects, and in the process of virtual machine continuous GC, These objects are recycled, and the memory footprint will fall to a steady level;
c) Conversely, if there is a case in the code that does not release the object reference, the total size value of the data object will not come down significantly after each GC, and as the number of operations is increased, the value of total size will become larger.
Until an upper limit is reached, the process is killed.
D) The system_process process is here, for example, the total size of the data object that system_process the memory occupied by the process in my test environment will normally stabilize between 2.2~2.8, And when the value exceeds 3.55, the process is killed.

In the following location:

Second, through the Linux command to view

The common commands are

ADB shell

PS is to see the process of

The top command is to see occupancy.

3. How to get maximum memory
Activitymanager am = (activitymanager) getsystemservice (Context.activity_service);
Am.getmemoryclass ();
This is the maximum memory, if more than this memory on the Oom


Memory consumption: Introduction of Vss/rss/pss/uss
    • VSS -Virtual Set Size virtualized 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 Set Size process consumes physical memory alone (does not contain memory consumed by shared libraries)

In general, memory footprint has the following rules: VSS >= RSS >= PSS >= USS


The aim of this post was to provide information that would assist in interpreting memory reports from various tools so the T Rue memory usage for Linux processes and the system can is determined.

Android have a tool called Procrank (/system/xbin/procrank), which lists out the memory usage of Linux processes I n order from highest to lowest usage. The sizes reported per process is VSS, RSS, PSS, and USS.

For the sake of simplicity in this description, memory would be a expressed in terms of pages, rather than bytes. Linux systems like ours manage memory in 4096 bytes pages at the lowest level.

VSS (Reported as VSZ from PS) are the total accessible address space of a process. This is the size also includes memory that May is resident in RAM like Mallocs that has been allocated but not written to. VSS is of very little use for determing real memory usage of a process.

RSS is the total memory actually held in RAM for a process. RSS can be misleading, because it reports the total all of the the the A-Libraries that process uses, even though a share D library is a loaded into memory once regardless of what many processes use it. RSS isn't an accurate representation of the memory usage for a single process.

PSS  differs from RSS in so it reports the proportional size of its shared libraries, i.e. if th REE processes all use a shared libraries that have pages, that library would only contribute pages to the PSS that's re Ported for each of the three processes. PSS is a very useful number because if the PSS for all processes in the system is summed together, which is a good repre Sentation for the total memory usage in the system. When a process was killed, the shared libraries that contributed to its PSS would be proportionally distributed to the PSS T Otals for the remaining processes still using that library. In this-a-slightly misleading, because when a process is killed, PSS does not accurately represent the memory Returned to the overall system.

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.

For systems that has Python available, there is also a nice tool called Smem that would report memory statistics including All of these categories.

# Procrank
PID Vss Rss Pss Uss cmdline
481 31536K 30936K 14337K 9956K system_server
475 26128K 26128K 10046K 5992K zygote
526 25108K 25108K 9225K 5384K android.process.acore
523 22388K 22388K 7166K 3432K com.android.phone
574 21632K 21632K 6109K 2468K com.android.settings
521 20816K 20816K 6050K 2776K jp.co.omronsoft.openwnn
474 3304K 3304K 1097K 624k/system/bin/mediaserver
PNS 304K 304K 289K 288k/sbin/adbd
720K 720K 261K 212k/system/bin/rild
601 412K 412K 225K 216K Procrank
1 204K 204K 185K 184k/init
388K 388K 182K 172k/system/bin/qemud
284 384K 384K 160K 148K Top
376K 376K 148K 136k/system/bin/vold
261 332K 332K 123K 112K logcat
396K 396K 105K 80k/system/bin/keystore
316K 316K 100K 88k/system/bin/installd
269 328K 328K 95K 72k/system/bin/sh
280K 280K 93K 84k/system/bin/servicemanager
304K 304K 91K 80k/system/bin/qemu-props
324K 324K 91K 68k/system/bin/sh
260 324K 324K 91K 68k/system/bin/sh
324K 324K 91K 68k/system/bin/sh
308K 308K 88K 68k/system/bin/sh
232K 232K 67K 60k/system/bin/debuggerd

Use ADB tools under Windows to view the CPU and memory consumption of Android programs

Original URL: Http://www.tuicool.com/articles/aEVzAzF

1. Open the terminal and enter the above directory as shown in:

2. Enter the ADB shell and open the ADB command line as shown in:

3. View CPU Usage:

Input command: top-m 10-s CPU (-m displays the maximum number,-S is sorted by the specified line), as shown in:

Parameter meaning: PID  : Progress identification, Application IDs    : The state of the process, where s indicates hibernation, R is running, Z represents a zombie state, n indicates that the process precedence value is negative #thr: The number of threads currently used by the program VSS    size virtual memory consumption (contains memory consumed by shared libraries) RSS  Size actual use of physical memory (contains memory consumed by shared libraries) PCY  : Foreground (FG) and background (BG) process UID  user identification, Identity idname: application name  

Note the PID of the first column, which uses the PID value to view the current program's memory usage.

4. View the memory usage of the specified program:

Input command: Dumpsys meminfo 3253, as shown in:
Parameter meaning: Memory used by Dalvik:dalvik   3.0 after bitmap is put here)  other: Except for Dalvik and native memory, including c\c++ non-heap memory ... PSS    : This memory is a proportional allocation of shared memory to a process using shared memory allocated: Used memory      free: idle memory private dirty: unshared, The memory that cannot be paged out (such as a small object that is buffered by a Linux system in order to increase the allocated memory speed, and the memory will not be freed even if your process has exited) share dirty   : Shared, but there is memory that cannot be paged out  

5. Use CTRL + C to exit the ADB command line.

View CPU consumption

1. Enter adb shell

2. Enter the top-m 10-s CPU to see the top 10 CPU consuming programs (-t displays the process name,-s is sorted by the specified row,-n is refreshed several times before exiting,-D refresh interval,-m Maximum number of displays)

Parameter meaning:

PID:Progress identification, application ID

S: The state of the process, where s indicates hibernation,R is running,Z represents a zombie state, andn indicates that the process precedence value is negative.

#THR: The number of threads currently used by the program

VSS:virtual Set size virtualized memory consumption (contains memory consumed by shared libraries)

RSS: resident Set size actually uses physical memory (contains memory consumed by shared libraries)

PCY: I don't know what that means, look for answers.

UID: user identification, identity ID

Name: Application names

View memory consumption

1. Enter adb shell;

2. Input Dumpsys meminfo (PID or package name ), appear as;

Parameter meaning:

Memory used by Dalvik:dalvik

Native:native heap memory, refers to c\c++ heap of memory (Android 3.0 after bitmap is put here)

Other: Except for Dalvik and native memory, contains c\c++ non-heap memory ...

PSS: This memory is a prorated allocation of shared memory to a process that uses shared memory

Allocated: Used Memory

Free: Idle memory

Private dirty: Memory that is unshared and cannot be paged out (such as small objects that are buffered by the Linux system in order to increase the allocated memory speed, even if your process has exited, the memory will not be freed)

Share dirty: Shared, but there is no memory to be paged out

Analyze memory

1. Through DDMS, select the program process you want to view and click Update heap;

2. view memory consumption in the heap interface

3. For further analysis, you need to use the MAT plugin;

4. Select the program process click the Dump HPROF file icon, pop-up, such as, the general choice of the first can be;


5. appear as, click leak Suspect,mat will list the largest number of objects in memory;

View Android process information Original URL: http://www.2cto.com/kf/201408/324134.html

Open adb shell, direct PS command

If you look at a particular process, such as "Torch Hero", filter with grep

The meaning of each column parameter:

user process current users;

PID Process ID, progress ID;

PPID The process parent ID, which is the ID of the procedure;

vsize Virtual size, the size of the virtualized memory of the process;

RSS Resident Set size, which actually resides "in memory" memory size;

Wchan The address of the hibernation process in the kernel;

PC Program Counter;

name Process name;

If you want to kill the process, kill the PID

You can also see which libraries the process has loaded based on the process ID, cat/proc/pid/maps

# Cat/proc/9562/maps
7429b000-74cd4000 R-xp 00000000 103:0d 390977/data/app-lib/com.vega.one-1/libcocos2djs.so
40891000-40892000 rw-p 00005000 103:0c 1501/system/lib/libglesv2.so
40347000-4035d000 R-xp 00000000 103:0c 2003/system/lib/libz.so

"Go" Android How to view CPU usage and memory leaks

Related Article

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.