From f48097f2702a4102bffe31a58384a9e9def10652 Mon Sep 17 00:00:00 2001 From: vadimt Date: Thu, 14 Jan 2021 19:43:28 -0800 Subject: [PATCH] Correctly generating heap dumps for OOP tests Not trying to dump the test process :) Still using Debug.dumpHprofData for inproc because using shell command for inproc can deadlock. Test: manual Bug: 177065099 Change-Id: I4b581954a01ecc8a1427409baa030aaa3b70d6b5 --- .../android/launcher3/ui/AbstractLauncherUiTest.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index 37dd4d27c0..1854fc7e94 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -100,6 +100,7 @@ public abstract class AbstractLauncherUiTest { private static final String TAG = "AbstractLauncherUiTest"; private static String sStrictmodeDetectedActivityLeak; + private static boolean sDumpWasGenerated = false; private static boolean sActivityLeakReported; private static final String SYSTEMUI_PACKAGE = "com.android.systemui"; protected static final ActivityLeakTracker ACTIVITY_LEAK_TRACKER = new ActivityLeakTracker(); @@ -151,10 +152,18 @@ public abstract class AbstractLauncherUiTest { } public static String dumpHprofData() { + if (sDumpWasGenerated) return "dump has already been generated by another test"; try { final String fileName = getInstrumentation().getTargetContext().getFilesDir().getPath() + "/ActivityLeakHeapDump.hprof"; - Debug.dumpHprofData(fileName); + if (TestHelpers.isInLauncherProcess()) { + Debug.dumpHprofData(fileName); + } else { + final UiDevice device = UiDevice.getInstance(getInstrumentation()); + device.executeShellCommand( + "am dumpheap " + device.getLauncherPackageName() + " " + fileName); + } + sDumpWasGenerated = true; return "memory dump filename: " + fileName; } catch (Throwable e) { Log.e(TAG, "dumpHprofData failed", e);