How to automate the DDMS snapshot mechanism?

后端 未结 4 846
鱼传尺愫
鱼传尺愫 2020-12-18 10:20

Does Android DDMS provide APIs ? I need to automate the snapshot mechanism for the native heap. Or is there any post processing tool for analysis DDMS native heap snapshots.

4条回答
  •  一个人的身影
    2020-12-18 11:07

    @laalto's answer is not quite correct

    From a shell you can do the following to get a heap dump for the application using adb.

    Note: Replace 19000 with the process ID of your running application. The filepath must be a filepath which your application has write access to on the Android device.

    Create a heap dump:
    adb shell am dumpheap 19000 /sdcard/Documents/android.hprof
    Pull the file to your machine:
    adb pull /sdcard/Documents/android.hprof
    Convert to a hprof file readable by an analyzer:
    hprof-conv android.hprof mat.hprof

    Tips: Get process ID of your application:

    adb shell ps | grep com.sample.application | cut -c10-15

    Get process ID and dump heap:

    adb shell am dumpheap `adb shell ps | grep com.sample.application | cut -c10-15` /sdcard/Documents/android.hprof

提交回复
热议问题