android stability monkey test

Benpian for application memory leak test, a brief memory leak hazards, a memory leak means that the program has been dynamically allocated heap memory for some reason the program does not release or not release, resulting in a waste of system memory, causing the program to run slowly and even system crashes and other serious consequences. In simple terms it is that if a memory leak, then the application will be more you use the card, and finally cause the application to crash.

Premise preparation conditions:
1, to root your phone, the simulator can also be
2, procrank corresponding to the system, procmem, libpagemap.so file
3, to get the script memory data
4, adb environment
 
Steps:
1, the command line remount about partition
adb root
adb remount
adb logcat -c
 
1.1, in the ddms taken out hprof file
Command line ddms, select the corresponding equipment, click on the download file to obtain hprof
 
2, the procmem, procrank to the push / system / xbin, will be pushed to the libpagemap.so / system / lib
Meanwhile modify three file permissions
adb push procmem / system / xbin
adb push procrank /system/xbin
adb push libpagemap.so /system/lib
adb shell
cd / system / xbin
chmod 777 procrank
chmod 777 procmem
cd ../lib
chmod 777 libpagemap.so
 
3, the start instruction input reference monkey, random start instruction
Reference Instruction
adb shell monkey -p xxx --ignore-timeouts --ignore-crashes --ignore-security-exceptions --monitor-native-crashes --throttle 500 -v -v 36000 > monkey.txt
4, startup scripts, data acquisition procrank, waiting for the end of the monkey
Reference script
Import os, subprocess, Re
 DEF _getDevice ():
     # get all the equipment devices, get a tuple 
    deviceRsp = subprocess.Popen ( " adb Devices " , stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True) .communicate ( ) [0]
     # regular extraction equipment look device, return a List 
    device = the re.findall ( ' (. *) \ tdevice ' , deviceRsp.decode ( ' UTF8 ' ))
     Print (device)
     return device
 DEF _getFileName (to_file, device ):
     # to open the file, the name of the device according to the decision, the default simulator with God night, port 62001 
    __device_list =[]
     For each in Device: 
        STR (each) .replace ( ' : ' , ' _ ' ) .replace ( ' . ' , '' ) # Simulator pit 
        IF  " : "  in each: 
            each = " 62001 " 
        # Analyzing the passed path 
        IF to_file iS None:
              __device_list .append ( ' {0} / {}. 1 .txt ' .format (the os.getcwd (), each))
              #Delete an existing file 
             IF os.path.exists ( __device_list ): 
                 os.remove ( __device_list )
         the else :
             # incoming path is not a suffix, to make up 
            IF os.path.splitext (to_file) [1] == '' :
                 __device_list .append (the os.path.join (to_file, ' {0} .txt ' .format (each)))
             the else :
                 __device_list .append (to_file)
                 BREAK 
    return  __device_list 

DEF Procrank (to_file = None, Package = None, Device = '' , e_num = 1000 ):
    '' ' 
    : Param to_file: write the file path 
    : param pakage: Package name 
    : e_num param: frequency end of the loop 
    : return: 
    ' '' 
    # Check the device id, id if not then get 
    the try :
         IF Device == '' : 
            device = _getDevice ()
         elif  not the isinstance (device, STR):
             The raise TypeError ( ' device device is incorrect, please type string ' )
     the except :
         The raise Exception ( ' acquisition device error _getDevice, or input device error id ' ) 

    # open the file 
    d =_getFileName (to_file, Device)
     the try : 
        F = Open (D [0], ' A + ' , encoding = ' UTF8 ' )
     the except Exception AS E:
         The raise Exception ( ' error:% s \ t file open fails, make sure the file path , and file type, recommended txt file ' % E)
     IF Package IS None: 
        cmd = ' the adb the shell procrank ' 
    elif The os.name == ' POSIX ' : 
        cmd = ' the adb the shell procrank | grep {0} '.format (Package)
     elif The os.name == ' NT ' : 
        cmd = ' the adb the shell procrank | the findstr {0} ' .format (Package) 

    # cycles obtain procrank 
    for n- in Range (e_num):
         # Windows decoding a byte variable became empty, mac decoded into a str, unified with byte 
        d = subprocess.Popen (cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True) .stdout.read ()
         Print (str (d) ) 
        f.write (STR (D)) 
    f.close () 

IF  the __name__ == ' __main__ ' : 
    to_file= '1.txt'
    Procrank(to_file,package='com.android.gallery3d',device='127.0.0.1:62001',e_num=240000)
 
5, the day after the script obtained copy and paste data into the txt document, may be generated by direct observation txt file. Observation of whether the execution error
Contents of the file is approximately
b' 2114  1340816K   56312K   12352K    9912K  com.android.gallery3d\r\n'
b' 2114  1340816K   56312K   12352K    9912K  com.android.gallery3d\r\n'
b' 2114  1340816K   56312K   12352K    9912K  com.android.gallery3d\r\n'
b' 2114  1340816K   56312K   12352K    9912K  com.android.gallery3d\r\n'
b' 2114  1340816K   56312K   12352K    9912K  com.android.gallery3d\r\n'
b' 2114  1340816K   56312K   12352K    9912K  com.android.gallery3d\r\n'
b' 2114  1340816K   56312K   12352K    9912K  com.android.gallery3d\r\n'
b' 2114  1340816K   56312K   12352K    9912K  com.android.gallery3d\r\n'
 
6, the paste data txt file to excel in the uss a screening out all the data, making the use of line chart
uss fourth column of the data, the need to organize data column, remove k, excel finishing not made here.
 
7, if it is found to upper trend line chart, then save it again ddms hprof document, distributed to developers or analytical about their own memory release issue
supplement:
Get the package name, reception open only to test the application, command line, type:
adb shell dumpsys window w |findstr \/ |findstr name=

Guess you like

Origin www.cnblogs.com/dflblog/p/11422419.html