Skip to content

Instantly share code, notes, and snippets.

@martyglaubitz
Created February 12, 2015 12:18
Show Gist options
  • Save martyglaubitz/01dfd5b970e6d6b7bda8 to your computer and use it in GitHub Desktop.
Save martyglaubitz/01dfd5b970e6d6b7bda8 to your computer and use it in GitHub Desktop.
A python script to pull humpdump from an android device/emulat, which can be opened with Eclipse MAT
#!/usr/bin/python -u
import argparse
import subprocess
import time
parser = argparse.ArgumentParser(description='Pull a memory profile of an running process')
parser.add_argument('pid', nargs='+', help='The apps process id')
args = parser.parse_args()
if __name__ == "__main__":
pid = args.pid[0]
hprof_file = "{pid}.hprof".format(pid=pid)
output_path = "/sdcard/Download/" + hprof_file
subprocess.call(["adb","shell","am","dumpheap", pid, output_path])
time.sleep(5) #the shell exits imediatly but the heapdump can take some time
subprocess.call(["adb","pull", output_path])
subprocess.call(["adb","shell","rm", output_path])
subprocess.call(["hprof-conv",hprof_file, "{pid}-conv.hprof".format(pid=pid)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment