blob: 8ad3f481da492a801543ec98c77b5cf628952295 [file] [log] [blame]
Richard Uhlerb730b782015-07-15 16:01:58 -07001/*
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
17package com.android.ahat;
18
19import com.android.tools.perflib.heap.Instance;
20import java.io.IOException;
21import java.util.ArrayList;
22import java.util.Collections;
23import java.util.List;
24
Richard Uhler1af86f12015-10-29 14:55:00 -070025class ObjectsHandler implements AhatHandler {
26 private static final String OBJECTS_ID = "objects";
27
28 private AhatSnapshot mSnapshot;
29
Richard Uhlerb730b782015-07-15 16:01:58 -070030 public ObjectsHandler(AhatSnapshot snapshot) {
Richard Uhler1af86f12015-10-29 14:55:00 -070031 mSnapshot = snapshot;
Richard Uhlerb730b782015-07-15 16:01:58 -070032 }
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 Uhler1af86f12015-10-29 14:55:00 -070058 SubsetSelector<Instance> selector = new SubsetSelector(query, OBJECTS_ID, insts);
59 for (Instance inst : selector.selected()) {
Richard Uhlerb730b782015-07-15 16:01:58 -070060 doc.row(
Richard Uhlerc21e4e62015-08-31 16:16:14 -070061 DocString.format("%,d", inst.getSize()),
Richard Uhlerb730b782015-07-15 16:01:58 -070062 DocString.text(inst.getHeap().getName()),
63 Value.render(inst));
64 }
65 doc.end();
Richard Uhler1af86f12015-10-29 14:55:00 -070066 selector.render(doc);
Richard Uhlerb730b782015-07-15 16:01:58 -070067 }
68}
69