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.Instance; |
| 20 | import com.android.tools.perflib.heap.RootObj; |
| 21 | import java.io.IOException; |
| 22 | import java.util.ArrayList; |
| 23 | import java.util.HashSet; |
| 24 | import java.util.List; |
| 25 | import java.util.Set; |
| 26 | |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame^] | 27 | class RootsHandler implements AhatHandler { |
| 28 | |
| 29 | private static final String ROOTS_ID = "roots"; |
| 30 | |
| 31 | private AhatSnapshot mSnapshot; |
| 32 | |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 33 | public RootsHandler(AhatSnapshot snapshot) { |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame^] | 34 | mSnapshot = snapshot; |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 35 | } |
| 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 Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame^] | 53 | DominatedList.render(mSnapshot, doc, query, ROOTS_ID, roots); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |