From cda4f2e72f569e0a0d6119c1c75284fd44df79ab Mon Sep 17 00:00:00 2001 From: Richard Uhler Date: Fri, 9 Sep 2016 09:56:20 +0100 Subject: Refactor ahat's perflib api. This change substantially refactors how ahat accesses heap dump data. Rather than use the perflib API directly with some additional information accessed on the side via AhatSnapshot, we introduce an entirely new API for accessing all the information we need from a heap dump. Perflib is used when processing the heap dump to populate the information initially, but afterwards all views and handlers go through the new com.android.ahat.heapdump API. The primary motivation for this change is to facilitate adding support for diffing two heap dumps to ahat. The new API provides flexibility that will make it easier to form links between objects in different snapshots and introduce place holder objects to show when there is an object in another snapshot that has no corresponding object in this snapshot. A large number of test cases were added to cover missing cases discovered in the process of refactoring ahat's perflib API. The external user-facing UI may have minor cosmetic changes, but otherwise is unchanged. Test: m ahat-test, with many new tests added. Bug: 33770653 Change-Id: I1a6b05ea469ebbbac67d99129dd9faa457b4d17e --- tools/ahat/test/ObjectHandlerTest.java | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tools/ahat/test/ObjectHandlerTest.java (limited to 'tools/ahat/test/ObjectHandlerTest.java') diff --git a/tools/ahat/test/ObjectHandlerTest.java b/tools/ahat/test/ObjectHandlerTest.java new file mode 100644 index 0000000000..cd0ba23013 --- /dev/null +++ b/tools/ahat/test/ObjectHandlerTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ahat; + +import com.android.ahat.heapdump.AhatInstance; +import com.android.ahat.heapdump.AhatSnapshot; +import java.io.IOException; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class ObjectHandlerTest { + @Test + public void noCrashClassInstance() throws IOException { + TestDump dump = TestDump.getTestDump(); + + AhatInstance object = dump.getDumpedAhatInstance("aPhantomReference"); + assertNotNull(object); + + AhatHandler handler = new ObjectHandler(dump.getAhatSnapshot()); + TestHandler.testNoCrash(handler, "http://localhost:7100/object?id=" + object.getId()); + } + + @Test + public void noCrashClassObj() throws IOException { + TestDump dump = TestDump.getTestDump(); + + AhatSnapshot snapshot = dump.getAhatSnapshot(); + AhatHandler handler = new ObjectHandler(snapshot); + + AhatInstance object = snapshot.findClass("Main"); + assertNotNull(object); + + TestHandler.testNoCrash(handler, "http://localhost:7100/object?id=" + object.getId()); + } + + @Test + public void noCrashSystemClassObj() throws IOException { + TestDump dump = TestDump.getTestDump(); + + AhatSnapshot snapshot = dump.getAhatSnapshot(); + AhatHandler handler = new ObjectHandler(snapshot); + + AhatInstance object = snapshot.findClass("java.lang.String"); + assertNotNull(object); + + TestHandler.testNoCrash(handler, "http://localhost:7100/object?id=" + object.getId()); + } + + @Test + public void noCrashArrayInstance() throws IOException { + TestDump dump = TestDump.getTestDump(); + + AhatInstance object = dump.getDumpedAhatInstance("gcPathArray"); + assertNotNull(object); + + AhatHandler handler = new ObjectHandler(dump.getAhatSnapshot()); + TestHandler.testNoCrash(handler, "http://localhost:7100/object?id=" + object.getId()); + } +} -- cgit v1.2.3-59-g8ed1b