From 46e476bab4788231395a17564f364636132f91e2 Mon Sep 17 00:00:00 2001 From: Richard Uhler Date: Thu, 21 Jul 2016 13:52:48 -0700 Subject: [PATCH] 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 --- tools/ahat/src/Main.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/ahat/src/Main.java b/tools/ahat/src/Main.java index d7845996b..fdc5a860e 100644 --- a/tools/ahat/src/Main.java +++ b/tools/ahat/src/Main.java @@ -67,12 +67,14 @@ public class Main { 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))); -- 2.11.0