Merge "Keep a baseline heap before a test." into tm-qpr-dev am: 68d61e4f51
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20712729 Change-Id: Ia2a675080fc4ebb9e5c36df9ec5789e20a462b08 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -40,24 +40,49 @@ import java.io.IOException;
|
|||||||
public class MemoryTrackingTestCase extends SysuiTestCase {
|
public class MemoryTrackingTestCase extends SysuiTestCase {
|
||||||
private static File sFilesDir = null;
|
private static File sFilesDir = null;
|
||||||
private static String sLatestTestClassName = null;
|
private static String sLatestTestClassName = null;
|
||||||
|
private static int sHeapCount = 0;
|
||||||
|
private static File sLatestBaselineHeapFile = null;
|
||||||
|
|
||||||
@Before public void grabFilesDir() {
|
// Ideally, we would do this in @BeforeClass just once, but we need mContext to get the files
|
||||||
|
// dir, and that does not exist until @Before on each test method.
|
||||||
|
@Before
|
||||||
|
public void grabFilesDir() throws IOException {
|
||||||
|
// This should happen only once per suite
|
||||||
if (sFilesDir == null) {
|
if (sFilesDir == null) {
|
||||||
sFilesDir = mContext.getFilesDir();
|
sFilesDir = mContext.getFilesDir();
|
||||||
}
|
}
|
||||||
sLatestTestClassName = getClass().getName();
|
|
||||||
|
// This will happen before the first test method in each class
|
||||||
|
if (sLatestTestClassName == null) {
|
||||||
|
sLatestTestClassName = getClass().getName();
|
||||||
|
sLatestBaselineHeapFile = dump("baseline" + (++sHeapCount), "before-test");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void dumpHeap() throws IOException {
|
public static void dumpHeap() throws IOException {
|
||||||
|
File afterTestHeap = dump(sLatestTestClassName, "after-test");
|
||||||
|
if (sLatestBaselineHeapFile != null && afterTestHeap != null) {
|
||||||
|
Log.w("MEMORY", "To compare heap to baseline (use go/ahat):");
|
||||||
|
Log.w("MEMORY", " adb pull " + sLatestBaselineHeapFile);
|
||||||
|
Log.w("MEMORY", " adb pull " + afterTestHeap);
|
||||||
|
Log.w("MEMORY",
|
||||||
|
" java -jar ahat.jar --baseline " + sLatestBaselineHeapFile.getName() + " "
|
||||||
|
+ afterTestHeap.getName());
|
||||||
|
}
|
||||||
|
sLatestTestClassName = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File dump(String basename, String heapKind) throws IOException {
|
||||||
if (sFilesDir == null) {
|
if (sFilesDir == null) {
|
||||||
Log.e("MEMORY", "Somehow no test cases??");
|
Log.e("MEMORY", "Somehow no test cases??");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
mockitoTearDown();
|
mockitoTearDown();
|
||||||
Log.w("MEMORY", "about to dump heap");
|
Log.w("MEMORY", "about to dump " + heapKind + " heap");
|
||||||
File path = new File(sFilesDir, sLatestTestClassName + ".ahprof");
|
File path = new File(sFilesDir, basename + ".ahprof");
|
||||||
Debug.dumpHprofData(path.getPath());
|
Debug.dumpHprofData(path.getPath());
|
||||||
Log.w("MEMORY", "did it! Location: " + path);
|
Log.w("MEMORY", "Success! Location: " + path);
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user