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 java.io.IOException; |
| 21 | import java.util.ArrayList; |
| 22 | import java.util.Collections; |
| 23 | import java.util.List; |
| 24 | |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 25 | class ObjectsHandler implements AhatHandler { |
| 26 | private static final String OBJECTS_ID = "objects"; |
| 27 | |
| 28 | private AhatSnapshot mSnapshot; |
| 29 | |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 30 | public ObjectsHandler(AhatSnapshot snapshot) { |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 31 | mSnapshot = snapshot; |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public void handle(Doc doc, Query query) throws IOException { |
| 36 | int stackId = query.getInt("stack", 0); |
| 37 | int depth = query.getInt("depth", 0); |
| 38 | String className = query.get("class", null); |
| 39 | String heapName = query.get("heap", null); |
| 40 | Site site = mSnapshot.getSite(stackId, depth); |
| 41 | |
| 42 | List<Instance> insts = new ArrayList<Instance>(); |
| 43 | for (Instance inst : site.getObjects()) { |
| 44 | if ((heapName == null || inst.getHeap().getName().equals(heapName)) |
| 45 | && (className == null |
| 46 | || AhatSnapshot.getClassName(inst.getClassObj()).equals(className))) { |
| 47 | insts.add(inst); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | Collections.sort(insts, Sort.defaultInstanceCompare(mSnapshot)); |
| 52 | |
| 53 | doc.title("Objects"); |
| 54 | doc.table( |
| 55 | new Column("Size", Column.Align.RIGHT), |
| 56 | new Column("Heap"), |
| 57 | new Column("Object")); |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 58 | SubsetSelector<Instance> selector = new SubsetSelector(query, OBJECTS_ID, insts); |
| 59 | for (Instance inst : selector.selected()) { |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 60 | doc.row( |
Richard Uhler | c21e4e6 | 2015-08-31 16:16:14 -0700 | [diff] [blame] | 61 | DocString.format("%,d", inst.getSize()), |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 62 | DocString.text(inst.getHeap().getName()), |
Richard Uhler | 38f9eba | 2015-11-11 08:31:52 -0800 | [diff] [blame] | 63 | Value.render(mSnapshot, inst)); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 64 | } |
| 65 | doc.end(); |
Richard Uhler | 1af86f1 | 2015-10-29 14:55:00 -0700 | [diff] [blame] | 66 | selector.render(doc); |
Richard Uhler | b730b78 | 2015-07-15 16:01:58 -0700 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |