• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 class OverviewHandler implements AhatHandler {
26 
27   private static final String OVERVIEW_ID = "overview";
28 
29   private AhatSnapshot mSnapshot;
30   private File mHprof;
31 
OverviewHandler(AhatSnapshot snapshot, File hprof)32   public OverviewHandler(AhatSnapshot snapshot, File hprof) {
33     mSnapshot = snapshot;
34     mHprof = hprof;
35   }
36 
37   @Override
handle(Doc doc, Query query)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     doc.end();
48 
49     doc.section("Heap Sizes");
50     printHeapSizes(doc, query);
51 
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 
67     doc.big(Menu.getMenu());
68   }
69 
printHeapSizes(Doc doc, Query query)70   private void printHeapSizes(Doc doc, Query query) {
71     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     };
86     HeapTable.render(doc, query, OVERVIEW_ID, table, mSnapshot, dummy);
87   }
88 }
89 
90