Android Client Performance test-memory (i)

Source: Internet
Author: User
Tags memory usage stringbuffer

Preface:

1. This content for the app application client performance test, not involved in the background, so not for the API or data interface

2. Target items for testing: Resource consumption, memory leak, power consumption, response time

3. Client performance metrics: memory, CPU, traffic

4. This series is mainly about how to obtain Android app application performance metrics, and simple analysis, positioning problems


first, view memory indicators:

preparatory work:

(1). Enter the developer option with the test app handset and turn on "USB debug Mode"

(2). Use the data line to connect the handset device with the computer equipment, can install the PP assistant to access

(3). Mobile phone open to test app, that is, open the process


1. View memory data at command line:

(1). Open cmd


(2). Get device list: Enter ADB devices (pre-installed ADB driver, if error, unplug reconnect phone)


(3). Enter the shell environment of the device: input: adb-s c7r6t16722004661 shell (if only one device, can direct adb shell, multiple units must add device serial number c7r6t16722004661)


(4). Lookup Process: input PS (Fuzzy Lookup) to find the corresponding application package name, and record its PID (process ID): 30017,

If you know the exact package name, you can find the PS |grep directly and accurately com.hundsun.stockwinner.grzq



(5). Query Memory Information:

There are two ways to get:

A. Obtained by "Dumpsys Meminfo package name/pid", enter: Dumpsys meminfo 30017

PSS total: Physical memory that is actually used

Private dirty: Privately resident memory

Heap Size: Consumes total memory (Heap heap) (extended: The process memory space is virtual memory, differentiated from physical memory, and the process cannot directly manipulate physical memory ram.) When necessary, the operating system maps it so that the process can be applied to physical memory.

Heap Alloc: Allocating memory

HEAP Free: Idle memory

Native process and Java process occupy the size of memory (extended: the memory requested by C + + is the memory requested by the native Process,java: Java process)

Memory size: Native process:13004

Dalvik process:10448

Note: Because the Android system imposes a hard limit on Dalvik vm HeapSize, when the Java process requests a Java space that exceeds the threshold, it throws a Oom exception (this threshold can be 48M, 24M, 16M, etc., depending on the model)

To view a single application maximum memory limit, enter the command: Getprop|grep heapgrowthlimit Results The model is 192M. Dalvik process is over, it throws oom anomaly.


B. Can be passed directly: Procrank.

The SH on the phone is streamlined, some phones may not have procrank commands, you can use the Genymotion simulator, or install Procrank commands yourself.

(I do not have this command, not installed, this part of the content is not operational, direct access to the network)


Vss-virtual Set Size Virtual consumption memory (containing memory occupied by shared libraries)--is an accessible address space for a single process

Rss-resident Set Size actually uses physical memory, which contains the memory occupied by shared libraries--the amount of memory that a single process actually consumes, not the exact description

Pss-proportional Set Size actually uses physical memory (proportional allocation of memory occupied by shared libraries)--a good description of the overall memory usage in the system

Uss-unique the physical memory occupied by the Set Size process alone (without the memory occupied by shared libraries)--The total private memory size of a single process, which is the total amount of memory exclusive to the process.

Generally speaking, the memory footprint has the following regularity: VSS >= RSS >= PSS >= USS.


USS is the best number to detect if a process starts with a suspicious memory leak


2. Code gets memory data:

Java calls the ADB shell Dumpsys Meminfo to retrieve the memory by means of string interception, which can be used to print the data back and realize monitoring.

The incoming parameter is: Application package name, this is immutable.

Package com.hss.performanceTest;
/** * FROM HSS * DATA:2017/9/8 * project:getmemory/import Java.io.BufferedReader;
Import java.io.IOException;

Import Java.io.InputStreamReader; public class GetMemory {public static string GetMemory (String packagename) throws IOException, Interruptedexception
          {String str3=null;
          Runtime Runtime = Runtime.getruntime ();
          Process proc = runtime.exec ("adb shell Dumpsys meminfo" +packagename);
              try {if (proc.waitfor ()!= 0) {System.err.println ("exit value =" + Proc.exitvalue ()); } BufferedReader in = new BufferedReader (New InputStreamReader (proc.get
              InputStream ()));
              StringBuffer StringBuffer = new StringBuffer ();
              String line = null;

              while (line = In.readline ())!= null) {Stringbuffer.append (line+ ""); } String Str1=stringbuffer.tostriNg ();     
              String str2=str1.substring (Str1.indexof ("Objects") -60,str1.indexof ("Objects"));
              Str3=str2.substring (0,10);
          Str3.trim ();
          catch (Interruptedexception e) {System.err.println (e);
              }finally{try {Proc.destroy ();
    The catch (Exception E2) {}} return STR3;
        public static void Main (String args[]) {System.out.println ("start ...");
			try {String Resurt = getmemory.getmemory ("Com.hundsun.stockwinner.sxzq");
		System.out.println ("The Memory of Shanxi Securities:" +resurt);
		catch (IOException e) {//TODO auto-generated catch block E.printstacktrace ();
		catch (Interruptedexception e) {//TODO auto-generated catch block E.printstacktrace ();

 }             
    } 
    
}

Run Screenshots:






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.