android--Memory Debugging

Source: Internet
Author: User

Because of debugging a major problem, suspected memory, specifically wrote a test script. Record it.



Writing is not easy, reproduced please specify the source: http://blog.csdn.net/jscese/article/details/37928823

I. Preparation for commissioning

The first thing you need to do is turn on the ADB feature. Start ADBD

PC-side adb connect IP ADDRESS

Suppose an ADB exception is available to try the adb kill-server . adb start-server



Two. adb shell Directive 1. View Overall memory

After the ADB is connected to the ADB shell Procrank to see the current memory situation!

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvannjzxnl/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70 /gravity/southeast ">


    • VSS -Virtual Set Size virtualized memory consumption (including memory consumed by shared libraries)
    • RSS -resident Set Size actually uses physical memory (including 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 (excluding memory consumed by shared libraries)


2. View the memory of the specified process

adb shell Dumpsys meminfo (package name or PID)


Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvannjzxnl/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70 /gravity/southeast ">



3. Most memory-intensive processes or threads

adb shell Top

Shows the 10 processes currently occupying the highest memory,adb shell top-m:



View threads:adb shell top-t-M


Three. Shell scripts

For real-time monitoring of memory usage. and save the log, my shell script:

    #!/bin/bash       echo "begain test Memory" >memeory_recode.txt      i=0      while true; do            adb shell Procrank | grep ' RAM: ' | Tee-a memeory_record.txt             memoryinfo=$ (tail memeory_record.txt-n 1)       #freememory = $memoryinfo | cut-d "-F 4
   
    freememory= ' echo ' $memoryinfo ' |awk-f ' {print $4} '            free=${freememory%?
    

if [$free-lt 8000];then echo-e "\033[31mfree Memory is $free KB less than 8m\033[0m" | tee-a memeory_recode . txt adb shell top-m 10-n 1 | tee-a memeory_recode.txt Else echo "freememory = $free KB" fi I =$ (($i + 1)) sleep 1 var=$ (date) echo "Jscese display memory at $var the $i times" Echo Done



Save the RAM information to Memeory_record.txt. And parse the value of the freememory, assuming that less than 8000K will take up the memory of the top 10 process information is also saved into the record.


Four. Dalvik settings in Build.prop

dalvik.vm.heapstartsize=8mdalvik.vm.heapgrowthlimit=96mdalvik.vm.heapsize=256mdalvik.vm.heaptargetutilization= 0.75dalvik.vm.heapminfree=512kdalvik.vm.heapmaxfree=8mdalvik.vm.lockprof.threshold=500dalvik.vm.dexopt-flags=m =y

These properties represent some of the property settings for Dalvik, which can be found in the prototype under/dalvik/vm/alloc/heapsource.cpp:

struct Heapsource {/* Target ideal heap utilization ratio; Range 1..heap_utilization_max */size_t Targetutiliz    ation     /* The starting heap size.    */size_t Startsize;     /* The largest that the heap source as a whole are allowed to grow.    */size_t MaximumSize;  /* * The largest size we permit the heap to grow.  This value allows * the user to limit the heap growth below the maximum size.     This * was a work around until we can dynamically set the maximum size. * This value can range between the starting size and the maximum * size but should never is set below the current foot     Print of the * heap.    */size_t Growthlimit;     /* The desired max size of the heap source as a whole.    */size_t Idealsize;  /* The maximum number of bytes allowed to being allocated from the * active heap before a GC is forced.     This was used to "shrink" the * heap in lieu of actual compaction.    */size_t Softlimit; /* Minimum Number of Free bytes. Used with the target utilization when * setting the Softlimit.     Never allows less bytes than this to being free * when the heap size is below the maximum size or growth limit.    */size_t MinFree; /* Maximum number of free bytes. Used with the target utilization when * setting the Softlimit.     Never allows more bytes than this to being free * While the heap size is below the maximum size or growth limit. */size_t MaxFree;


The roughly corresponding meanings are for example the following:

1.heapstartsize--heap Initial allocation size, the amount of memory allocated when an app is started

2.heapgrowthlimit--allocates the largest growth value of a heap, the maximum amount of memory allocated by an app, which should be reported in excess of outofmemory

3.heapsize--the maximum value that the entire heap can achieve. Which is the sum of memory that the application can use.

Utilization ratio of 4.heaptargetutilization--representative heap, actual use and maximum utilization control

5.heapminfree--heap size limiting factor, minimum spare value if heap size does not exceed the limit value

6.heapmaxfree--and minimum, the maximum size of the heap can be spare

7.lockprof.threshold--Debug Logger threshold for internal lock resource contention, default value is 500

8.dexopt-flags--program code verification and optimization, the following from the encyclopedia:

Dalvik.vm.dexopt-flags: This parameter controls the program code checksum optimization of the Dalvik virtual machine. The available values are M, V, and O. M is the standard option. can be m=y or m=n. If m=y, enable validation of unsafe code and optimization of managed code. Best compatibility and security, recommended. V is the CHECK option and can coexist with O. can be v=a or v=n. If v=a means to validate all the code, v=n turns off the checksum of the code.

O is an optimization option that can coexist with V. can be o=v or o=a. If O=v is optimized to validate the code, o=a means to optimize all the code. For example: dalvik.vm.dexopt-flags=m=y dalvik.vm.dexopt-flags=v=n,o=v Note that this parameter only affects when the Dex file is generated after the APK is installed or when the APK is first used. If the entire system (including the application) is Odex, it is meaningless.







android--Memory Debugging

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.