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 implements AhatHandler { 26 private static final String OBJECTS_ID = "objects"; 27 28 private AhatSnapshot mSnapshot; 29 30 public ObjectsHandler(AhatSnapshot snapshot) { 31 mSnapshot = snapshot; 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")); 58 SubsetSelector<Instance> selector = new SubsetSelector(query, OBJECTS_ID, insts); 59 for (Instance inst : selector.selected()) { 60 doc.row( 61 DocString.format("%,d", inst.getSize()), 62 DocString.text(inst.getHeap().getName()), 63 Value.render(mSnapshot, inst)); 64 } 65 doc.end(); 66 selector.render(doc); 67 } 68 } 69 70