blob: 2c06b47a2963fc92bd2e53edcc8b79294189b7e4 [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.util.ArrayList;
21import java.util.Collections;
22import java.util.List;
23
24class SitePrinter {
Richard Uhler1af86f12015-10-29 14:55:00 -070025 public static void printSite(AhatSnapshot snapshot, Doc doc, Query query, String id, Site site) {
Richard Uhlerb730b782015-07-15 16:01:58 -070026 List<Site> path = new ArrayList<Site>();
27 for (Site parent = site; parent != null; parent = parent.getParent()) {
28 path.add(parent);
29 }
30 Collections.reverse(path);
31
32
33 HeapTable.TableConfig<Site> table = new HeapTable.TableConfig<Site>() {
34 public String getHeapsDescription() {
35 return "Reachable Bytes Allocated on Heap";
36 }
37
38 public long getSize(Site element, Heap heap) {
39 return element.getSize(heap.getName());
40 }
41
42 public List<HeapTable.ValueConfig<Site>> getValueConfigs() {
43 HeapTable.ValueConfig<Site> value = new HeapTable.ValueConfig<Site>() {
44 public String getDescription() {
45 return "Stack Frame";
46 }
47
48 public DocString render(Site element) {
49 DocString str = new DocString();
50 if (element.getParent() != null) {
51 str.append("→ ");
52 }
53 str.appendLink(
Richard Uhlerc21e4e62015-08-31 16:16:14 -070054 DocString.formattedUri("site?stack=%d&depth=%d",
Richard Uhlerb730b782015-07-15 16:01:58 -070055 element.getStackId(), element.getStackDepth()),
56 DocString.text(element.getName()));
57 return str;
58 }
59 };
60 return Collections.singletonList(value);
61 }
62 };
Richard Uhler1af86f12015-10-29 14:55:00 -070063 HeapTable.render(doc, query, id, table, snapshot, path);
Richard Uhlerb730b782015-07-15 16:01:58 -070064 }
65}