How to automate the DDMS snapshot mechanism?

后端 未结 4 844
鱼传尺愫
鱼传尺愫 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:15

    I wrote small script, maybe you would find it useful

    heap_dump_location='/data/local/tmp/tmp.hprof'
    
    dump_heap() {
      adb shell rm $heap_dump_location
      pid=`adb shell ps | grep 'com.example.packagename' | grep -v 'packagename\.' | cut -c10-15`
      adb shell am dumpheap $pid $heap_dump_location
      echo "Heap dump started, we have no idea when it's done, so take a look at logs, and when is done use pull_heap_dump"
    }
    
    pull_heap_dump() {
      adb pull $heap_dump_location $1
    }
    

    https://gist.github.com/logcat/8aeca0ee81af6fb0dc10bb0d58940007

提交回复
热议问题