Home | History | Annotate | Download | only in src
      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.Heap;
     20 import java.util.ArrayList;
     21 import java.util.Collections;
     22 import java.util.List;
     23 
     24 class SitePrinter {
     25   public static void printSite(AhatSnapshot snapshot, Doc doc, Query query, String id, Site site) {
     26     List<Site> path = new ArrayList<Site>();
     27     for (Site parent = site; parent != null; parent = parent.getParent()) {
     28       path.add(parent);
     29     }
     30     Collections.reverse(path);
     31 
     32 
     33     HeapTable.TableConfig<Site> table = new HeapTable.TableConfig<Site>() {
     34       public String getHeapsDescription() {
     35         return "Reachable Bytes Allocated on Heap";
     36       }
     37 
     38       public long getSize(Site element, Heap heap) {
     39         return element.getSize(heap.getName());
     40       }
     41 
     42       public List<HeapTable.ValueConfig<Site>> getValueConfigs() {
     43         HeapTable.ValueConfig<Site> value = new HeapTable.ValueConfig<Site>() {
     44           public String getDescription() {
     45             return "Stack Frame";
     46           }
     47 
     48           public DocString render(Site element) {
     49             DocString str = new DocString();
     50             if (element.getParent() != null) {
     51               str.append(" ");
     52             }
     53             str.appendLink(
     54                 DocString.formattedUri("site?stack=%d&depth=%d",
     55                     element.getStackId(), element.getStackDepth()),
     56                 DocString.text(element.getName()));
     57             return str;
     58           }
     59         };
     60         return Collections.singletonList(value);
     61       }
     62     };
     63     HeapTable.render(doc, query, id, table, snapshot, path);
     64   }
     65 }
     66