blob: 0fe4fba716b20f5d72f5fffaf73c1f4bae43e23e [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 Uhlerb730b782015-07-15 16:01:58 -070051
52 DocString menu = new DocString();
Richard Uhler7a16adb2015-11-11 09:13:23 -080053 menu.appendLink(DocString.uri("rooted"), DocString.text("Rooted"));
Richard Uhlerb730b782015-07-15 16:01:58 -070054 menu.append(" - ");
55 menu.appendLink(DocString.uri("site"), DocString.text("Allocations"));
56 menu.append(" - ");
57 menu.appendLink(DocString.uri("help"), DocString.text("Help"));
58 doc.big(menu);
59 }
60
Richard Uhler1af86f12015-10-29 14:55:00 -070061 private void printHeapSizes(Doc doc, Query query) {
Richard Uhlerb730b782015-07-15 16:01:58 -070062 List<Object> dummy = Collections.singletonList(null);
63
64 HeapTable.TableConfig<Object> table = new HeapTable.TableConfig<Object>() {
65 public String getHeapsDescription() {
66 return "Bytes Retained by Heap";
67 }
68
69 public long getSize(Object element, Heap heap) {
70 return mSnapshot.getHeapSize(heap);
71 }
72
73 public List<HeapTable.ValueConfig<Object>> getValueConfigs() {
74 return Collections.emptyList();
75 }
76 };
Richard Uhler1af86f12015-10-29 14:55:00 -070077 HeapTable.render(doc, query, OVERVIEW_ID, table, mSnapshot, dummy);
Richard Uhlerb730b782015-07-15 16:01:58 -070078 }
79}
80