blob: f73e3ca0272d4a1bc89ddfe197c7c9eba8f43f9b [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
Richard Uhlercda4f2e2016-09-09 09:56:20 +010019import com.android.ahat.heapdump.AhatHeap;
20import com.android.ahat.heapdump.AhatInstance;
21import com.android.ahat.heapdump.AhatSnapshot;
Richard Uhlerf629cfd2016-12-12 13:11:26 +000022import com.android.ahat.heapdump.Sort;
Richard Uhlerb730b782015-07-15 16:01:58 -070023import java.util.ArrayList;
24import java.util.Collection;
25import java.util.Collections;
Richard Uhlerb730b782015-07-15 16:01:58 -070026import java.util.List;
Richard Uhlerb730b782015-07-15 16:01:58 -070027
28/**
29 * Class for rendering a list of instances dominated by a single instance in a
30 * pretty way.
31 */
32class DominatedList {
Richard Uhlerb730b782015-07-15 16:01:58 -070033 /**
34 * Render a table to the given HtmlWriter showing a pretty list of
35 * instances.
36 *
Richard Uhler1af86f12015-10-29 14:55:00 -070037 * @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 Uhlerb730b782015-07-15 16:01:58 -070042 */
Richard Uhler1af86f12015-10-29 14:55:00 -070043 public static void render(final AhatSnapshot snapshot,
Richard Uhlercda4f2e2016-09-09 09:56:20 +010044 Doc doc, Query query, String id, Collection<AhatInstance> instances) {
45 List<AhatInstance> insts = new ArrayList<AhatInstance>(instances);
Richard Uhlerb730b782015-07-15 16:01:58 -070046 Collections.sort(insts, Sort.defaultInstanceCompare(snapshot));
Richard Uhlercda4f2e2016-09-09 09:56:20 +010047 HeapTable.render(doc, query, id, new TableConfig(), snapshot, insts);
Richard Uhlerb730b782015-07-15 16:01:58 -070048 }
49
Richard Uhlercda4f2e2016-09-09 09:56:20 +010050 private static class TableConfig implements HeapTable.TableConfig<AhatInstance> {
Richard Uhlerb730b782015-07-15 16:01:58 -070051 @Override
52 public String getHeapsDescription() {
53 return "Bytes Retained by Heap";
54 }
55
56 @Override
Richard Uhlercda4f2e2016-09-09 09:56:20 +010057 public long getSize(AhatInstance element, AhatHeap heap) {
58 return element.getRetainedSize(heap);
Richard Uhlerb730b782015-07-15 16:01:58 -070059 }
60
61 @Override
Richard Uhlercda4f2e2016-09-09 09:56:20 +010062 public List<HeapTable.ValueConfig<AhatInstance>> getValueConfigs() {
63 HeapTable.ValueConfig<AhatInstance> value = new HeapTable.ValueConfig<AhatInstance>() {
Richard Uhlerb730b782015-07-15 16:01:58 -070064 public String getDescription() {
65 return "Object";
66 }
67
Richard Uhlercda4f2e2016-09-09 09:56:20 +010068 public DocString render(AhatInstance element) {
69 return Summarizer.summarize(element);
Richard Uhlerb730b782015-07-15 16:01:58 -070070 }
71 };
72 return Collections.singletonList(value);
73 }
74 }
Richard Uhlerb730b782015-07-15 16:01:58 -070075}