Android App memory footprint test (print procrank information every second)

Source: Internet
Author: User



1. Memory consumption



For smartphones, the memory size is fixed, so if the memory footprint of a single app is smaller, the more apps you can install on your phone, or the smaller your app's memory footprint, the smoother it will run on your phone. So, the size of the memory footprint is an important indicator of app performance.






2. Explanation of the principle



For an app, we can focus on its memory footprint in 3 different states:



The empty load ———— app is already running in the background, but the user is not using it;



The load ———— app runs in the foreground and the user does a small amount of operation;



Full-load ———— users continue to operate frequently, and the app is running close to saturation.



However, apart from the first case, the other two kinds of subjectivity are very strong, not very easy to distinguish. Normal product testing, as long as the background to verify the operation (5-10 minutes appropriate) and the user continued to frequent a large number of operations (10-15 minutes appropriate) in both cases.



In this way, it becomes the question of how to continuously count and record the memory that the app occupies. The Procrank tool can implement this function.






Installation of 3.procrank



1) Download Procrank compression package,: http://download.csdn.net/download/yincheng886337/9433538



2) Unzip, push the Procrank file to the/system/xbin directory of the mobile phone;



Command: ADB push Procrank/system/xbin



Push the Procmem file to the/system/xbin directory of your phone;



Command: ADB push Procmem/system/xbin



Push the libpagemap.so file to the/system/lib directory of your phone;



Command: ADB push libpagemap.so/system/lib



3) Enter the ADB shell, get root permissions, respectively to Procrank, Procmem, libpagemap.so three files 777 permissions, as follows:



chmod 777/system/xbin/procrank



chmod 777/system/xbin/procmem



chmod 777/system/xbin/libpagemap.so



If the push does not enter three files or modify the permissions of three files, then re-mount the system, and then modify the permissions of three files, as follows:



Mount-o Remount,rw/system






4. Procrank Value Analysis



Enter the adb shell, get root permissions, enter the command: Procrank, such as:






vss--is an all-accessible address space for a single process, and its size includes parts that may not yet reside in memory. For example, the address space has been allocated by malloc, but is not actually written, and for determining the actual memory usage size of a single process, VSS is of little use.



rss--is the amount of memory that a single process actually consumes, and the reason RSS is easy to mislead is that it includes the full memory size of all shared libraries used by the process. For a single shared library, although no matter how many processes are used, the actual shared library will only be loaded in memory once, so RSS is not an accurate description of the memory usage size of a single process.



pss--Unlike RSS, PSS includes the shared library size that it uses, for example, three processes use the same shared library that consumes 30 pages of memory. For any one of the three processes, PSS will include only 10 of these memory pages. PSS is a very useful number because all processes in the system are counted as a whole and are a good description of the overall memory usage in the system. If a process is terminated, the shared library size used in its PSS will be prorated back to the rest of the process that is still using the shared library.



uss--is the total private memory size of a single process, which is the total amount of memory that is exclusive to the process;



USS is a very useful number because it reveals the actual amount of memory increment that runs a particular process, and if the process is terminated, USS is the amount of memory actually returned to the system. USS is the best number to detect when a process begins to have a suspected memory leak.






5. Write scripts to automatically print Procrank information every second



1) First create a cmd.txt file that writes the ADB shell commands that need to be executed, such as:









2) Write the Python script as follows:


import os, sys, time
for i in range (500):
     os.popen ("adb shell <cmd.txt") #Run the command in cmd.txt
     step1 = os.popen ("adb pull /data/test/t1.txt F: /100python/log102101.txt") #Download the generated t1.txt file to the local
     fo = open ("log102101.txt", ‘r +‘)
     input = fo.read ()
     fo2 = open ("mem.txt", ‘r +‘)
     fo2.seek (0, os.SEEK_END) #locate to the end of the mem.txt file
     fo2.write (input) #Write the content of t1.txt
     fo.close ()
     fo2.close ()
     time.sleep (1) # Take a rest for one second, and then enter the next cycle, that is, print the information of procrank every one second
print "ok" #flag completed 


Note: cmd.txt files, python scripts, mem.txt are stored in the same directory






3) Run the Monkey and execute the written script



The resulting mem.txt file is as follows:






Attached Monkey command:



adb shell monkey-p com.waboon.test--ignore-crashes--ignore-timeouts--ignore-native-crashes--pct-touch 30-v-v-v--t Hrottle 200 1000






4) The value of the fifth column in the Mem.txt file is USS, the Mem.txt file is opened with Notepad, and the value of the fifth column is copied into Excel to generate the chart, as follows:






5) Analysis Value






Android App memory footprint test (print procrank information every second)


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.