1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ahat; 18 19 import com.android.ahat.heapdump.AhatHeap; 20 import com.android.ahat.heapdump.AhatSnapshot; 21 import com.android.ahat.heapdump.Diffable; 22 import java.io.File; 23 import java.io.IOException; 24 import java.util.Collections; 25 import java.util.List; 26 27 class OverviewHandler implements AhatHandler { 28 29 private static final String OVERVIEW_ID = "overview"; 30 31 private AhatSnapshot mSnapshot; 32 private File mHprof; 33 private File mBaseHprof; 34 OverviewHandler(AhatSnapshot snapshot, File hprof, File basehprof)35 public OverviewHandler(AhatSnapshot snapshot, File hprof, File basehprof) { 36 mSnapshot = snapshot; 37 mHprof = hprof; 38 mBaseHprof = basehprof; 39 } 40 41 @Override handle(Doc doc, Query query)42 public void handle(Doc doc, Query query) throws IOException { 43 doc.title("Overview"); 44 45 doc.section("General Information"); 46 doc.descriptions(); 47 doc.description( 48 DocString.text("ahat version"), 49 DocString.format("ahat-%s", OverviewHandler.class.getPackage().getImplementationVersion())); 50 doc.description(DocString.text("hprof file"), DocString.text(mHprof.toString())); 51 if (mBaseHprof != null) { 52 doc.description(DocString.text("baseline hprof file"), DocString.text(mBaseHprof.toString())); 53 } 54 doc.end(); 55 56 doc.section("Heap Sizes"); 57 printHeapSizes(doc, query); 58 59 doc.big(Menu.getMenu()); 60 } 61 62 private static class TableElem implements Diffable<TableElem> { getBaseline()63 @Override public TableElem getBaseline() { 64 return this; 65 } 66 isPlaceHolder()67 @Override public boolean isPlaceHolder() { 68 return false; 69 } 70 } 71 printHeapSizes(Doc doc, Query query)72 private void printHeapSizes(Doc doc, Query query) { 73 List<TableElem> dummy = Collections.singletonList(new TableElem()); 74 75 HeapTable.TableConfig<TableElem> table = new HeapTable.TableConfig<TableElem>() { 76 public String getHeapsDescription() { 77 return "Bytes Retained by Heap"; 78 } 79 80 public long getSize(TableElem element, AhatHeap heap) { 81 return heap.getSize(); 82 } 83 84 public List<HeapTable.ValueConfig<TableElem>> getValueConfigs() { 85 return Collections.emptyList(); 86 } 87 }; 88 HeapTable.render(doc, query, OVERVIEW_ID, table, mSnapshot, dummy); 89 } 90 } 91 92