Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 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.tools.perflib.heap.Heap; |
| 20 | import java.io.IOException; |
| 21 | import java.io.File; |
| 22 | import java.util.Collections; |
| 23 | import java.util.List; |
| 24 | |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 25 | class OverviewHandler implements AhatHandler { |
| 26 | |
| 27 | private static final String OVERVIEW_ID = "overview"; |
| 28 | |
| 29 | private AhatSnapshot mSnapshot; |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 30 | private File mHprof; |
| 31 | |
| 32 | public OverviewHandler(AhatSnapshot snapshot, File hprof) { |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 33 | mSnapshot = snapshot; |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 34 | mHprof = hprof; |
| 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"), |
Richard Uhler | c21e4e6 | 2015-08-31 16:16:14 -0700 | [diff] [blame] | 45 | DocString.format("ahat-%s", OverviewHandler.class.getPackage().getImplementationVersion())); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 46 | doc.description(DocString.text("hprof file"), DocString.text(mHprof.toString())); |
| 47 | doc.end(); |
| 48 | |
| 49 | doc.section("Heap Sizes"); |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 50 | printHeapSizes(doc, query); |
Richard Uhler | a7f46cb | 2015-12-21 14:34:59 -0800 | [diff] [blame] | 51 | doc.big(Menu.getMenu()); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 54 | private void printHeapSizes(Doc doc, Query query) { |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 55 | List<Object> dummy = Collections.singletonList(null); |
| 56 | |
| 57 | HeapTable.TableConfig<Object> table = new HeapTable.TableConfig<Object>() { |
| 58 | public String getHeapsDescription() { |
| 59 | return "Bytes Retained by Heap"; |
| 60 | } |
| 61 | |
| 62 | public long getSize(Object element, Heap heap) { |
| 63 | return mSnapshot.getHeapSize(heap); |
| 64 | } |
| 65 | |
| 66 | public List<HeapTable.ValueConfig<Object>> getValueConfigs() { |
| 67 | return Collections.emptyList(); |
| 68 | } |
| 69 | }; |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 70 | HeapTable.render(doc, query, OVERVIEW_ID, table, mSnapshot, dummy); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |