blob: 2a92c90c4e5500ed253fff151cd476e91e6ffc4e [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.Instance;
20import com.android.tools.perflib.heap.RootObj;
21import java.io.IOException;
22import java.util.ArrayList;
23import java.util.HashSet;
24import java.util.List;
25import java.util.Set;
26
Richard Uhler1af86f12015-10-29 14:55:00 -070027class RootsHandler implements AhatHandler {
28
29 private static final String ROOTS_ID = "roots";
30
31 private AhatSnapshot mSnapshot;
32
Richard Uhlerb730b782015-07-15 16:01:58 -070033 public RootsHandler(AhatSnapshot snapshot) {
Richard Uhler1af86f12015-10-29 14:55:00 -070034 mSnapshot = snapshot;
Richard Uhlerb730b782015-07-15 16:01:58 -070035 }
36
37 @Override
38 public void handle(Doc doc, Query query) throws IOException {
39 doc.title("Roots");
40
41 Set<Instance> rootset = new HashSet<Instance>();
42 for (RootObj root : mSnapshot.getGCRoots()) {
43 Instance inst = root.getReferredInstance();
44 if (inst != null) {
45 rootset.add(inst);
46 }
47 }
48
49 List<Instance> roots = new ArrayList<Instance>();
50 for (Instance inst : rootset) {
51 roots.add(inst);
52 }
Richard Uhler1af86f12015-10-29 14:55:00 -070053 DominatedList.render(mSnapshot, doc, query, ROOTS_ID, roots);
Richard Uhlerb730b782015-07-15 16:01:58 -070054 }
55}
56