转自:http://blog.csdn.net/sodino/article/details/38512473

一个heap dump就是一个程序heap的快照,可以获知程序的哪些部分正在使用大部分的内存。
它保存为一种叫做HPROF的二进制格式。对于Android执行android.os.Debug.dumpHprofData(hprofPath)方法后所生成的文件,需要把.hprof文件从Dalvik格式转换成J2SE HPROF格式。使用AndroidSDK提供的hprof-conv工具可执行该转换操作。

hprof-conv dump.hprof converted-dump.hprof  

Android代码生成dump文件如下:

    public static boolean createDumpFile(Context context) {        String LOG_PATH = "/dump.gc/";        boolean bool = false;        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ssss", Locale.getDefault());        String createTime = sdf.format(new Date(System.currentTimeMillis()));        String state = android.os.Environment.getExternalStorageState();                // 判断SdCard是否存在并且是可用的        if (android.os.Environment.MEDIA_MOUNTED.equals(state)) {            File file = new File(Environment.getExternalStorageDirectory().getPath() + LOG_PATH);            if (!file.exists()) {                file.mkdirs();            }                        String hprofPath = file.getAbsolutePath();            if (!hprofPath.endsWith("/")) {                hprofPath += "/";            }            hprofPath += createTime + ".hprof";            try {                android.os.Debug.dumpHprofData(hprofPath);                bool = true;                Log.d("nsz", "create dumpfile done!");            } catch (IOException e) {                e.printStackTrace();            }        } else {            bool = false;            Log.d("nsz", "no sdcard!");        }        return bool;    }

不要忘记了在AndroidManifest.xml中声明SDCard写权限:

  

更多相关文章

  1. sdcard相关的adb命令
  2. android 编译出来的执行文件 not executable: magic 7F45
  3. Android课程---Android(安卓)Studio的一些小技巧
  4. Android(安卓)java.lang.StackOverflowError at android.view.Vi
  5. android 解压缩zip包
  6. Android(安卓)线刷小白教程
  7. 高级组件之选项卡
  8. Android(安卓)Studio发布到Jcenter
  9. 在s5pv210开发板的android平台上添加busybox的支持[基于x210开发

随机推荐

  1. Use adb on Mac OS
  2. Android(安卓)SharedPreferences的使用案
  3. Android布局属性大全
  4. android音频架构
  5. android调用系统发短信界面功能
  6. android学习资料
  7. Android百度地图知识汇总
  8. ubuntu共享文件夹设置
  9. android studio 报编码 GBK 的不可映射字
  10. Switch自定义