Android generates a heap dump file(. hprof)
A heap dump is a snapshot of the program heap that tells you which parts of the program are using most of the memory.
It is stored in a binary format called Hprof. For files generated after Android executes the Android.os.Debug.dumpHprofData (Hprofpath) method, the. hprof file needs to be converted from the Dalvik format to the J2SE hprof format. The conversion operation is performed using the Hprof-conv tool provided by ANDROIDSDK.
Hprof-conv dump.hprof Converted-dump.hprof
This article belongs to Sodino original, posted in Blog:Http://blog.csdn.net/sodino, reprint please indicate the source.
The relevant code can be downloaded from the group file in QQ Group Code2share (363267446).
The Android code generates a 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 the sdcard exists and is available if (Android.os.Environment.MEDIA_MOUNTED.equals (state)) {filefile = new File (Enviro Nment.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; }
Don't forget to declare sdcard Write permissions in Androidmanifest.xml:
<uses-permissionandroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>