Launch ahat server before processing the heap dump.
Change-Id: Ic8f18ad3010cb0937f5ef68228359258ec4793fd
Test: Manually launch ahat on a large heap dump with ahat already
running. Verify that ahat fails immediately.
Test: Manually launch ahat on a large heap dump without ahat already
running. Verify that visiting localhost:7100 immediately
eventually resolves to the overview page rather than say the
site can't be reached.
Bug: 28611294
diff --git a/tools/ahat/src/Main.java b/tools/ahat/src/Main.java
index d784599..fdc5a86 100644
--- a/tools/ahat/src/Main.java
+++ b/tools/ahat/src/Main.java
@@ -67,12 +67,14 @@
return;
}
- System.out.println("Processing hprof file...");
- AhatSnapshot ahat = AhatSnapshot.fromHprof(hprof);
-
+ // Launch the server before parsing the hprof file so we get
+ // BindExceptions quickly.
InetAddress loopback = InetAddress.getLoopbackAddress();
InetSocketAddress addr = new InetSocketAddress(loopback, port);
HttpServer server = HttpServer.create(addr, 0);
+
+ System.out.println("Processing hprof file...");
+ AhatSnapshot ahat = AhatSnapshot.fromHprof(hprof);
server.createContext("/", new AhatHttpHandler(new OverviewHandler(ahat, hprof)));
server.createContext("/rooted", new AhatHttpHandler(new RootedHandler(ahat)));
server.createContext("/object", new AhatHttpHandler(new ObjectHandler(ahat)));