blob: 0a9381ef24ac656b4e6a47626e43890398e54961 [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.util.Collections;
22import java.util.Comparator;
23import java.util.List;
24
25class SiteHandler extends AhatHandler {
26 public SiteHandler(AhatSnapshot snapshot) {
27 super(snapshot);
28 }
29
30 @Override
31 public void handle(Doc doc, Query query) throws IOException {
32 int stackId = query.getInt("stack", 0);
33 int depth = query.getInt("depth", -1);
34 Site site = mSnapshot.getSite(stackId, depth);
35
36 doc.title("Site %s", site.getName());
37 doc.section("Allocation Site");
38 SitePrinter.printSite(doc, mSnapshot, site);
39
40 doc.section("Sites Called from Here");
41 List<Site> children = site.getChildren();
42 if (children.isEmpty()) {
43 doc.println(DocString.text("(none)"));
44 } else {
45 Collections.sort(children, new Sort.SiteBySize("app"));
46
47 HeapTable.TableConfig<Site> table = new HeapTable.TableConfig<Site>() {
48 public String getHeapsDescription() {
49 return "Reachable Bytes Allocated on Heap";
50 }
51
52 public long getSize(Site element, Heap heap) {
53 return element.getSize(heap.getName());
54 }
55
56 public List<HeapTable.ValueConfig<Site>> getValueConfigs() {
57 HeapTable.ValueConfig<Site> value = new HeapTable.ValueConfig<Site>() {
58 public String getDescription() {
59 return "Child Site";
60 }
61
62 public DocString render(Site element) {
63 return DocString.link(
Richard Uhlerc21e4e62015-08-31 16:16:14 -070064 DocString.formattedUri("site?stack=%d&depth=%d",
Richard Uhlerb730b782015-07-15 16:01:58 -070065 element.getStackId(), element.getStackDepth()),
66 DocString.text(element.getName()));
67 }
68 };
69 return Collections.singletonList(value);
70 }
71 };
72 HeapTable.render(doc, table, mSnapshot, children);
73 }
74
75 doc.section("Objects Allocated");
76 doc.table(
77 new Column("Reachable Bytes Allocated", Column.Align.RIGHT),
78 new Column("Instances", Column.Align.RIGHT),
79 new Column("Heap"),
80 new Column("Class"));
81 List<Site.ObjectsInfo> infos = site.getObjectsInfos();
82 Comparator<Site.ObjectsInfo> compare = new Sort.WithPriority<Site.ObjectsInfo>(
83 new Sort.ObjectsInfoByHeapName(),
84 new Sort.ObjectsInfoBySize(),
85 new Sort.ObjectsInfoByClassName());
86 Collections.sort(infos, compare);
87 for (Site.ObjectsInfo info : infos) {
88 String className = AhatSnapshot.getClassName(info.classObj);
89 doc.row(
Richard Uhlerc21e4e62015-08-31 16:16:14 -070090 DocString.format("%,14d", info.numBytes),
Richard Uhlerb730b782015-07-15 16:01:58 -070091 DocString.link(
Richard Uhlerc21e4e62015-08-31 16:16:14 -070092 DocString.formattedUri("objects?stack=%d&depth=%d&heap=%s&class=%s",
Richard Uhlerb730b782015-07-15 16:01:58 -070093 site.getStackId(), site.getStackDepth(), info.heap.getName(), className),
Richard Uhlerc21e4e62015-08-31 16:16:14 -070094 DocString.format("%,14d", info.numInstances)),
Richard Uhlerb730b782015-07-15 16:01:58 -070095 DocString.text(info.heap.getName()),
96 Value.render(info.classObj));
97 }
98 doc.end();
99 }
100}
101