blob: 34a5665b3ebe66753a696afd52ca06e802fa3b6c [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 com.android.tools.perflib.heap.Instance;
21import java.util.ArrayList;
22import java.util.Collection;
23import java.util.Collections;
Richard Uhlerb730b782015-07-15 16:01:58 -070024import java.util.List;
Richard Uhlerb730b782015-07-15 16:01:58 -070025
26/**
27 * Class for rendering a list of instances dominated by a single instance in a
28 * pretty way.
29 */
30class DominatedList {
Richard Uhlerb730b782015-07-15 16:01:58 -070031 /**
32 * Render a table to the given HtmlWriter showing a pretty list of
33 * instances.
34 *
Richard Uhler1af86f12015-10-29 14:55:00 -070035 * @param snapshot the snapshot where the instances reside
36 * @param doc the document to render the dominated list to
37 * @param query the current page query
38 * @param id a unique identifier to use for the dominated list in the current page
39 * @param instances the collection of instances to generate a list for
Richard Uhlerb730b782015-07-15 16:01:58 -070040 */
Richard Uhler1af86f12015-10-29 14:55:00 -070041 public static void render(final AhatSnapshot snapshot,
42 Doc doc, Query query, String id, Collection<Instance> instances) {
Richard Uhlerb730b782015-07-15 16:01:58 -070043 List<Instance> insts = new ArrayList<Instance>(instances);
44 Collections.sort(insts, Sort.defaultInstanceCompare(snapshot));
Richard Uhler1af86f12015-10-29 14:55:00 -070045 HeapTable.render(doc, query, id, new TableConfig(snapshot), snapshot, insts);
Richard Uhlerb730b782015-07-15 16:01:58 -070046 }
47
48 private static class TableConfig implements HeapTable.TableConfig<Instance> {
49 AhatSnapshot mSnapshot;
50
Richard Uhler1af86f12015-10-29 14:55:00 -070051 public TableConfig(AhatSnapshot snapshot) {
Richard Uhlerb730b782015-07-15 16:01:58 -070052 mSnapshot = snapshot;
Richard Uhlerb730b782015-07-15 16:01:58 -070053 }
54
55 @Override
56 public String getHeapsDescription() {
57 return "Bytes Retained by Heap";
58 }
59
60 @Override
61 public long getSize(Instance element, Heap heap) {
Richard Uhlerb730b782015-07-15 16:01:58 -070062 int index = mSnapshot.getHeapIndex(heap);
63 return element.getRetainedSize(index);
64 }
65
66 @Override
67 public List<HeapTable.ValueConfig<Instance>> getValueConfigs() {
68 HeapTable.ValueConfig<Instance> value = new HeapTable.ValueConfig<Instance>() {
69 public String getDescription() {
70 return "Object";
71 }
72
73 public DocString render(Instance element) {
Richard Uhler1af86f12015-10-29 14:55:00 -070074 return Value.render(element);
Richard Uhlerb730b782015-07-15 16:01:58 -070075 }
76 };
77 return Collections.singletonList(value);
78 }
79 }
Richard Uhlerb730b782015-07-15 16:01:58 -070080}