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 | |
| 25 | class ObjectsHandler extends AhatHandler { |
| 26 | public ObjectsHandler(AhatSnapshot snapshot) { |
| 27 | super(snapshot); |
| 28 | } |
| 29 | |
| 30 | @Override |
| 31 | public void handle(Doc doc, Query query) throws IOException { |
| 32 | int stackId = query.getInt("stack", 0); |
| 33 | int depth = query.getInt("depth", 0); |
| 34 | String className = query.get("class", null); |
| 35 | String heapName = query.get("heap", null); |
| 36 | Site site = mSnapshot.getSite(stackId, depth); |
| 37 | |
| 38 | List<Instance> insts = new ArrayList<Instance>(); |
| 39 | for (Instance inst : site.getObjects()) { |
| 40 | if ((heapName == null || inst.getHeap().getName().equals(heapName)) |
| 41 | && (className == null |
| 42 | || AhatSnapshot.getClassName(inst.getClassObj()).equals(className))) { |
| 43 | insts.add(inst); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | Collections.sort(insts, Sort.defaultInstanceCompare(mSnapshot)); |
| 48 | |
| 49 | doc.title("Objects"); |
| 50 | doc.table( |
| 51 | new Column("Size", Column.Align.RIGHT), |
| 52 | new Column("Heap"), |
| 53 | new Column("Object")); |
| 54 | for (Instance inst : insts) { |
| 55 | doc.row( |
| 56 | DocString.text("%,d", inst.getSize()), |
| 57 | DocString.text(inst.getHeap().getName()), |
| 58 | Value.render(inst)); |
| 59 | } |
| 60 | doc.end(); |
| 61 | } |
| 62 | } |
| 63 | |