Android Client performance test-memory "pre-code"

Source: Internet
Author: User
Tags stringbuffer

Objective:

1. This content is the performance test of the app client, does not involve the background, so it is not for the API or data interface

2. Target items for testing: resource consumption, memory leaks, power consumption, response time

3. Client performance metrics: memory, CPU, traffic

4. This series is mainly about how to get the performance index of Android app, and simple analysis, positioning problems

First, view memory metrics:

Preparatory work:

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

(2). Use the data cable to connect the mobile device to the computer equipment, can install the PP assistant to access

(3). The phone opens the app to be tested, which opens the process

1. Command line view memory data:

(1). Open cmd

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

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

(4). Find process: Enter PS (Fuzzy Lookup) to find the corresponding application package name, and record its PID (process ID): 20852,

If you know the exact package name, you can directly find PS |grep Com.quncao.lark

(5). Query Memory Information:

There are two ways to get:

A. Obtained through the "Dumpsys Meminfo package name/pid" command, Input: Dumpsys meminfo 20852

PSS Total: actual physical memory used

Private dirty: Privately resident memory

Heap Size: Occupies total memory (heap heap) (expansion: The process memory space is virtual memory, which is distinguished from physical memory, and the process cannot directly manipulate the physical memory ram. If necessary, the operating system maps it so that processes can be applied to physical memory)

Heap Alloc: Allocating memory

HEAP Free: Idle memory

Native process and Java process occupy the size of memory (extension: C + + request memory for native Process,java requested memory: Java process)

Memory size: Native process:13004

Dalvik process:10448

Note: Since the Android system imposes a hard limit on Dalvik vm heapsize, an Oom exception is thrown when the Java process requests more Java space than the threshold value (this threshold can be 48M, 24M, 16M, depending on the model)

To view the maximum memory limit for a single app, enter the command: Getprop|grep heapgrowthlimit Results The model is 192M. Dalvik process over will throw an Oom exception

B. Can be directly passed: 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.

(I do not have this command, not installed, this part of the content is not operational, for the network to obtain directly)

Vss-virtual Set Size Virtual memory consumption (contains memory consumed by shared libraries)--is an address space accessible to a single process

Rss-resident Set size actually uses physical memory (contains memory consumed by shared libraries)--the amount of memory that a single process actually consumes, not the exact description

Pss-proportional Set Size Actual physical memory used (proportional allocation of memory consumed by shared libraries)--a good description of the overall memory usage in the system

Uss-unique the Set size process consumes only the physical memory (not the memory consumed by the shared library)-the total amount of private memory for a single process, that is, the total amount of memory that is exclusive to the process.

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

USS is the best number to detect when a process begins to have a suspected memory leak

2. The code gets the memory data:

Java calls the ADB shell Dumpsys Meminfo and then uses the string interception method to obtain the memory, can return the data to print, realizes the monitoring.

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

1  Packagecom.hss.performanceTest;2 /**3 * from HSS4 * DATA:2017/9/85 * Project:getmemory6  */7 ImportJava.io.BufferedReader;8 Importjava.io.IOException;9 ImportJava.io.InputStreamReader;Ten   One  Public classGetMemory { A   -      Public StaticString GetMemory (String packagename)throwsIOException, interruptedexception { -   theString 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 ()); A               } atBufferedReader in =NewBufferedReader (NewInputStreamReader ( - Proc.getinputstream ())); -StringBuffer StringBuffer =NewStringBuffer (); -String line =NULL; -                while(line = In.readline ())! =NULL) { -Stringbuffer.append (line+ ""); in   -               } toString str1=stringbuffer.tostring (); +String str2=str1.substring (Str1.indexof ("Objects") -60,str1.indexof ("Objects"));  -Str3=str2.substring (0,10); the Str3.trim (); *}Catch(interruptedexception e) { $ System.err.println (e);Panax Notoginseng}finally{ -               Try { the Proc.destroy (); +}Catch(Exception E2) { A               } the           } +         returnSTR3; -     } $      Public Static voidMain (String args[]) { $          -System.out.println ("Start running ..."); -         Try { theString Resurt = getmemory.getmemory ("Com.hundsun.stockwinner.sxzq"); -SYSTEM.OUT.PRINTLN ("Shanxi Securities ' memory:" +Resurt);Wuyi}Catch(IOException e) { the             //TODO auto-generated Catch block - e.printstacktrace (); Wu}Catch(interruptedexception e) { -             //TODO auto-generated Catch block About e.printstacktrace (); $         }              -     }  -      -}

Run:

Android Client performance test-memory "pre-code"

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.