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 | |
Richard Uhler | cda4f2e | 2016-09-09 09:56:20 +0100 | [diff] [blame] | 19 | import com.android.ahat.heapdump.AhatHeap; |
| 20 | import com.android.ahat.heapdump.AhatInstance; |
| 21 | import com.android.ahat.heapdump.AhatSnapshot; |
Richard Uhler | f629cfd | 2016-12-12 13:11:26 +0000 | [diff] [blame] | 22 | import com.android.ahat.heapdump.Sort; |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 23 | import java.util.ArrayList; |
| 24 | import java.util.Collection; |
| 25 | import java.util.Collections; |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 26 | import java.util.List; |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Class for rendering a list of instances dominated by a single instance in a |
| 30 | * pretty way. |
| 31 | */ |
| 32 | class DominatedList { |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Render a table to the given HtmlWriter showing a pretty list of |
| 35 | * instances. |
| 36 | * |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 37 | * @param snapshot the snapshot where the instances reside |
| 38 | * @param doc the document to render the dominated list to |
| 39 | * @param query the current page query |
| 40 | * @param id a unique identifier to use for the dominated list in the current page |
| 41 | * @param instances the collection of instances to generate a list for |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 42 | */ |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 43 | public static void render(final AhatSnapshot snapshot, |
Richard Uhler | cda4f2e | 2016-09-09 09:56:20 +0100 | [diff] [blame] | 44 | Doc doc, Query query, String id, Collection<AhatInstance> instances) { |
| 45 | List<AhatInstance> insts = new ArrayList<AhatInstance>(instances); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 46 | Collections.sort(insts, Sort.defaultInstanceCompare(snapshot)); |
Richard Uhler | cda4f2e | 2016-09-09 09:56:20 +0100 | [diff] [blame] | 47 | HeapTable.render(doc, query, id, new TableConfig(), snapshot, insts); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Richard Uhler | cda4f2e | 2016-09-09 09:56:20 +0100 | [diff] [blame] | 50 | private static class TableConfig implements HeapTable.TableConfig<AhatInstance> { |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 51 | @Override |
| 52 | public String getHeapsDescription() { |
| 53 | return "Bytes Retained by Heap"; |
| 54 | } |
| 55 | |
| 56 | @Override |
Richard Uhler | cda4f2e | 2016-09-09 09:56:20 +0100 | [diff] [blame] | 57 | public long getSize(AhatInstance element, AhatHeap heap) { |
| 58 | return element.getRetainedSize(heap); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
Richard Uhler | cda4f2e | 2016-09-09 09:56:20 +0100 | [diff] [blame] | 62 | public List<HeapTable.ValueConfig<AhatInstance>> getValueConfigs() { |
| 63 | HeapTable.ValueConfig<AhatInstance> value = new HeapTable.ValueConfig<AhatInstance>() { |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 64 | public String getDescription() { |
| 65 | return "Object"; |
| 66 | } |
| 67 | |
Richard Uhler | cda4f2e | 2016-09-09 09:56:20 +0100 | [diff] [blame] | 68 | public DocString render(AhatInstance element) { |
| 69 | return Summarizer.summarize(element); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 70 | } |
| 71 | }; |
| 72 | return Collections.singletonList(value); |
| 73 | } |
| 74 | } |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 75 | } |