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.ahat.heapdump.AhatInstance; 20 import com.android.ahat.heapdump.AhatSnapshot; 21 import com.android.ahat.heapdump.Site; 22 import com.android.ahat.heapdump.Sort; 23 import java.io.IOException; 24 import java.util.ArrayList; 25 import java.util.Collections; 26 import java.util.List; 27 28 class ObjectsHandler implements AhatHandler { 29 private static final String OBJECTS_ID = "objects"; 30 31 private AhatSnapshot mSnapshot; 32 33 public ObjectsHandler(AhatSnapshot snapshot) { 34 mSnapshot = snapshot; 35 } 36 37 @Override 38 public void handle(Doc doc, Query query) throws IOException { 39 int id = query.getInt("id", 0); 40 int depth = query.getInt("depth", 0); 41 String className = query.get("class", null); 42 String heapName = query.get("heap", null); 43 Site site = mSnapshot.getSite(id, depth); 44 45 List<AhatInstance> insts = new ArrayList<AhatInstance>(); 46 for (AhatInstance inst : site.getObjects()) { 47 if ((heapName == null || inst.getHeap().getName().equals(heapName)) 48 && (className == null || inst.getClassName().equals(className))) { 49 insts.add(inst); 50 } 51 } 52 53 Collections.sort(insts, Sort.defaultInstanceCompare(mSnapshot)); 54 55 doc.title("Objects"); 56 57 SizeTable.table(doc, mSnapshot.isDiffed(), 58 new Column("Heap"), 59 new Column("Object")); 60 61 SubsetSelector<AhatInstance> selector = new SubsetSelector(query, OBJECTS_ID, insts); 62 for (AhatInstance inst : selector.selected()) { 63 AhatInstance base = inst.getBaseline(); 64 SizeTable.row(doc, inst.getSize(), base.getSize(), 65 DocString.text(inst.getHeap().getName()), 66 Summarizer.summarize(inst)); 67 } 68 SizeTable.end(doc); 69 selector.render(doc); 70 } 71 } 72 73