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 String className = query.get("class", null); 41 String heapName = query.get("heap", null); 42 Site site = mSnapshot.getSite(id); 43 44 List<AhatInstance> insts = new ArrayList<AhatInstance>(); 45 site.getObjects(heapName, className, insts); 46 Collections.sort(insts, Sort.defaultInstanceCompare(mSnapshot)); 47 48 doc.title("Objects"); 49 50 SizeTable.table(doc, mSnapshot.isDiffed(), 51 new Column("Heap"), 52 new Column("Object")); 53 54 SubsetSelector<AhatInstance> selector = new SubsetSelector(query, OBJECTS_ID, insts); 55 for (AhatInstance inst : selector.selected()) { 56 AhatInstance base = inst.getBaseline(); 57 SizeTable.row(doc, inst.getSize(), base.getSize(), 58 DocString.text(inst.getHeap().getName()), 59 Summarizer.summarize(inst)); 60 } 61 SizeTable.end(doc); 62 selector.render(doc); 63 } 64 } 65 66