Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 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 com.android.tools.perflib.heap.Instance; |
| 21 | import java.util.ArrayList; |
| 22 | import java.util.Collection; |
| 23 | import java.util.Collections; |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 24 | import java.util.List; |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Class for rendering a list of instances dominated by a single instance in a |
| 28 | * pretty way. |
| 29 | */ |
| 30 | class DominatedList { |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Render a table to the given HtmlWriter showing a pretty list of |
| 33 | * instances. |
| 34 | * |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 35 | * @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 Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 40 | */ |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 41 | public static void render(final AhatSnapshot snapshot, |
| 42 | Doc doc, Query query, String id, Collection<Instance> instances) { |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 43 | List<Instance> insts = new ArrayList<Instance>(instances); |
| 44 | Collections.sort(insts, Sort.defaultInstanceCompare(snapshot)); |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 45 | HeapTable.render(doc, query, id, new TableConfig(snapshot), snapshot, insts); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | private static class TableConfig implements HeapTable.TableConfig<Instance> { |
| 49 | AhatSnapshot mSnapshot; |
| 50 | |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 51 | public TableConfig(AhatSnapshot snapshot) { |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 52 | mSnapshot = snapshot; |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 53 | } |
| 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 Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 62 | 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 Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 74 | return Value.render(element); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 75 | } |
| 76 | }; |
| 77 | return Collections.singletonList(value); |
| 78 | } |
| 79 | } |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 80 | } |