blob: 720fcb42ff6e907ad50918eecb4effd1c983af71 [file] [log] [blame]
Richard Uhlerb730b782015-07-15 16:01:58 -07001/*
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
17package com.android.ahat;
18
19import com.android.tools.perflib.heap.Heap;
20import java.io.IOException;
21import java.io.File;
22import java.util.Collections;
23import java.util.List;
24
Richard Uhler1af86f12015-10-29 14:55:00 -070025class OverviewHandler implements AhatHandler {
26
27 private static final String OVERVIEW_ID = "overview";
28
29 private AhatSnapshot mSnapshot;
Richard Uhlerb730b782015-07-15 16:01:58 -070030 private File mHprof;
31
32 public OverviewHandler(AhatSnapshot snapshot, File hprof) {
Richard Uhler1af86f12015-10-29 14:55:00 -070033 mSnapshot = snapshot;
Richard Uhlerb730b782015-07-15 16:01:58 -070034 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 Uhlerc21e4e62015-08-31 16:16:14 -070045 DocString.format("ahat-%s", OverviewHandler.class.getPackage().getImplementationVersion()));
Richard Uhlerb730b782015-07-15 16:01:58 -070046 doc.description(DocString.text("hprof file"), DocString.text(mHprof.toString()));
47 doc.end();
48
49 doc.section("Heap Sizes");
Richard Uhler1af86f12015-10-29 14:55:00 -070050 printHeapSizes(doc, query);
Richard Uhlera7f46cb2015-12-21 14:34:59 -080051 doc.big(Menu.getMenu());
Richard Uhlerb730b782015-07-15 16:01:58 -070052 }
53
Richard Uhler1af86f12015-10-29 14:55:00 -070054 private void printHeapSizes(Doc doc, Query query) {
Richard Uhlerb730b782015-07-15 16:01:58 -070055 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 Uhler1af86f12015-10-29 14:55:00 -070070 HeapTable.render(doc, query, OVERVIEW_ID, table, mSnapshot, dummy);
Richard Uhlerb730b782015-07-15 16:01:58 -070071 }
72}
73