diff options
Diffstat (limited to 'src/com/android/tradefed/device/TestDevice.java')
-rw-r--r-- | src/com/android/tradefed/device/TestDevice.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/com/android/tradefed/device/TestDevice.java b/src/com/android/tradefed/device/TestDevice.java index 66285f4ec..e5ab1d43e 100644 --- a/src/com/android/tradefed/device/TestDevice.java +++ b/src/com/android/tradefed/device/TestDevice.java @@ -30,6 +30,7 @@ import com.android.tradefed.util.RunUtil; import com.android.tradefed.util.StreamUtil; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Strings; import java.awt.Image; import java.awt.image.BufferedImage; @@ -89,6 +90,11 @@ public class TestDevice extends NativeDevice { /** Timeout to wait for a screenshot before giving up to avoid hanging forever */ private static final long MAX_SCREENSHOT_TIMEOUT = 5 * 60 * 1000; // 5 min + /** adb shell am dumpheap <service pid> <dump file path> */ + private static final String DUMPHEAP_CMD = "am dumpheap %s %s"; + /** Time given to a file to be dumped on device side */ + private static final long DUMPHEAP_TIME = 5000l; + /** * @param device * @param stateMonitor @@ -1215,4 +1221,33 @@ public class TestDevice extends NativeDevice { + "Must be API %d.", feature, getSerialNumber(), strictMinLevel)); } } + + @Override + public File dumpHeap(String process, String devicePath) throws DeviceNotAvailableException { + if (Strings.isNullOrEmpty(devicePath) || Strings.isNullOrEmpty(process)) { + throw new IllegalArgumentException("devicePath or process cannot be null or empty."); + } + String pid = getProcessPid(process); + if (pid == null) { + return null; + } + File dump = dumpAndPullHeap(pid, devicePath); + // Clean the device. + executeShellCommand(String.format("rm %s", devicePath)); + return dump; + } + + /** Dump the heap file and pull it from the device. */ + private File dumpAndPullHeap(String pid, String devicePath) throws DeviceNotAvailableException { + executeShellCommand(String.format(DUMPHEAP_CMD, pid, devicePath)); + // Allow a little bit of time for the file to populate on device side. + int attempt = 0; + // TODO: add an API to check device file size + while (!doesFileExist(devicePath) && attempt < 3) { + getRunUtil().sleep(DUMPHEAP_TIME); + attempt++; + } + File dumpFile = pullFile(devicePath); + return dumpFile; + } } |