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.Size; 22 import java.io.File; 23 import java.io.IOException; 24 25 class OverviewHandler implements AhatHandler { 26 27 private AhatSnapshot mSnapshot; 28 private File mHprof; 29 private File mBaseHprof; 30 31 public OverviewHandler(AhatSnapshot snapshot, File hprof, File basehprof) { 32 mSnapshot = snapshot; 33 mHprof = hprof; 34 mBaseHprof = basehprof; 35 } 36 37 @Override 38 public void handle(Doc doc, Query query) throws IOException { 39 doc.title("Overview"); 40 41 doc.section("General Information"); 42 doc.descriptions(); 43 doc.description( 44 DocString.text("ahat version"), 45 DocString.format("ahat-%s", OverviewHandler.class.getPackage().getImplementationVersion())); 46 doc.description(DocString.text("hprof file"), DocString.text(mHprof.toString())); 47 if (mBaseHprof != null) { 48 doc.description(DocString.text("baseline hprof file"), DocString.text(mBaseHprof.toString())); 49 } 50 doc.end(); 51 52 doc.section("Bytes Retained by Heap"); 53 printHeapSizes(doc); 54 55 doc.big(Menu.getMenu()); 56 } 57 58 private void printHeapSizes(Doc doc) { 59 SizeTable.table(doc, new Column("Heap"), mSnapshot.isDiffed()); 60 Size totalSize = Size.ZERO; 61 Size totalBase = Size.ZERO; 62 for (AhatHeap heap : mSnapshot.getHeaps()) { 63 Size size = heap.getSize(); 64 Size base = heap.getBaseline().getSize(); 65 if (!size.isZero() || !base.isZero()) { 66 SizeTable.row(doc, DocString.text(heap.getName()), size, base); 67 totalSize = totalSize.plus(size); 68 totalBase = totalBase.plus(base); 69 } 70 } 71 SizeTable.row(doc, DocString.text("Total"), totalSize, totalBase); 72 SizeTable.end(doc); 73 } 74 } 75 76