[Android] generate the heap dump file (. hprof ),

Source: Internet
Author: User

[Android] generate the heap dump file (. hprof ),

Android generates the heap dump file (. hprof)

A heap dump is a heap snapshot of the program. You can know which parts of the program are using most of the memory.

It is saved as a binary format called HPROF. For files generated by running the Android. OS. Debug. dumpHprofData (hprofPath) method on android, You need to convert the. hprof file from Dalvik format to J2SE HPROF format. Use the hprof-conv tool provided by AndroidSDK to perform the conversion.

 

hprof-conv dump.hprof converted-dump.hprof

This article is originally written by sodino and published on the blog:Http://blog.csdn.net/sodino, Reprinted, please indicate the source.

The related code can be downloaded from the group file in the QQ Group Code2Share (363267446.

Android code generates the dump file as follows:

Public static boolean createDumpFile (Contextcontext) {StringLOG_PATH = "/dump. gc/"; boolean bool = false; SimpleDateFormatsdf = new SimpleDateFormat (" yyyy-MM-dd_HH.mm.ssss "); StringcreateTime = sdf. format (new Date (System. currentTimeMillis (); Stringstate = android. OS. environment. getExternalStorageState (); // determines whether an SdCard exists and is available if (android. OS. environment. MEDIA_MOUNTED.equals (state) {Filefile = new File (Environment. getExternalStorageDirectory (). getPath () + LOG_PATH); if (! File. exists () {file. mkdirs ();} StringhprofPath = file. getAbsolutePath (); if (! HprofPath. endsWith ("/") {hprofPath + = "/";} hprofPath + = createTime + ". hprof "; try {android. OS. debug. dumpHprofData (hprofPath); bool = true; Log. d ("ANDROID_LAB", "create dumpfile done! ");} Catch (IOException e) {e. printStackTrace () ;}} else {bool = false; Log. d (" ANDROID_LAB "," nosdcard! ");} Return bool ;}

Do not forget to declare the SDCard write permission in AndroidManifest. xml:

<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />






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.