blob: 0dbad7e00cb46d1b903d7e33c5f7b8a3f2fa624b [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 Uhler1a5baaa2015-12-21 12:47:26 -080051
52 List<InstanceUtils.NativeAllocation> allocs = mSnapshot.getNativeAllocations();
53 if (!allocs.isEmpty()) {
54 doc.section("Registered Native Allocations");
55 long totalSize = 0;
56 for (InstanceUtils.NativeAllocation alloc : allocs) {
57 totalSize += alloc.size;
58 }
59 doc.descriptions();
60 doc.description(DocString.text("Number of Registered Native Allocations"),
61 DocString.format("%,14d", allocs.size()));
62 doc.description(DocString.text("Total Size of Registered Native Allocations"),
63 DocString.format("%,14d", totalSize));
64 doc.end();
65 }
66
Richard Uhlera7f46cb2015-12-21 14:34:59 -080067 doc.big(Menu.getMenu());
Richard Uhlerb730b782015-07-15 16:01:58 -070068 }
69
Richard Uhler1af86f12015-10-29 14:55:00 -070070 private void printHeapSizes(Doc doc, Query query) {
Richard Uhlerb730b782015-07-15 16:01:58 -070071 List<Object> dummy = Collections.singletonList(null);
72
73 HeapTable.TableConfig<Object> table = new HeapTable.TableConfig<Object>() {
74 public String getHeapsDescription() {
75 return "Bytes Retained by Heap";
76 }
77
78 public long getSize(Object element, Heap heap) {
79 return mSnapshot.getHeapSize(heap);
80 }
81
82 public List<HeapTable.ValueConfig<Object>> getValueConfigs() {
83 return Collections.emptyList();
84 }
85 };
Richard Uhler1af86f12015-10-29 14:55:00 -070086 HeapTable.render(doc, query, OVERVIEW_ID, table, mSnapshot, dummy);
Richard Uhlerb730b782015-07-15 16:01:58 -070087 }
88}
89