Home | History | Annotate | Download | only in stacks
      1 /*
      2  * Copyright (C) 2016 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.bugreport.stacks;
     18 
     19 import java.util.ArrayList;
     20 import java.util.HashMap;
     21 
     22 /**
     23  * One thread in a vm traces snapshot.
     24  */
     25 public class ThreadSnapshot implements Comparable<ThreadSnapshot> {
     26     public static final int TYPE_UNMANAGED = 0;
     27     public static final int TYPE_MANAGED = 1;
     28 
     29     public int type;
     30     public String name;
     31     public String daemon;
     32     public int priority;
     33     public int tid = -1;
     34     public int sysTid = -1;
     35     public String vmState;
     36     public ArrayList<String> attributeText = new ArrayList<String>();
     37     public String heldMutexes;
     38     public ArrayList<StackFrameSnapshot> frames = new ArrayList<StackFrameSnapshot>();
     39     public boolean runnable;
     40 
     41     public boolean blocked;
     42 
     43     public String outboundBinderPackage;
     44     public String outboundBinderClass;
     45     public String outboundBinderMethod;
     46 
     47     public String inboundBinderPackage;
     48     public String inboundBinderClass;
     49     public String inboundBinderMethod;
     50 
     51     public boolean interesting;
     52 
     53     public HashMap<String,LockSnapshot> locks = new HashMap<String,LockSnapshot>();
     54 
     55     /**
     56      * Construct an empty ThreadSnapshot.
     57      */
     58     public ThreadSnapshot() {
     59     }
     60 
     61     /**
     62      * Construct a deep copy of the ThreadSnapshot.
     63      */
     64     public ThreadSnapshot(ThreadSnapshot that) {
     65         this.name = that.name;
     66         this.daemon = that.daemon;
     67         this.priority = that.priority;
     68         this.tid = that.tid;
     69         this.sysTid = that.sysTid;
     70         this.vmState = that.vmState;
     71         int N = that.attributeText.size();
     72         for (int i=0; i<N; i++) {
     73             this.attributeText.add(that.attributeText.get(i));
     74         }
     75         this.heldMutexes = that.heldMutexes;
     76         N = that.frames.size();
     77         for (int i=0; i<N; i++) {
     78             this.frames.add(that.frames.get(i).clone());
     79         }
     80         this.runnable = that.runnable;
     81         this.blocked = that.blocked;
     82         this.outboundBinderPackage = that.outboundBinderPackage;
     83         this.outboundBinderClass = that.outboundBinderClass;
     84         this.outboundBinderMethod = that.outboundBinderMethod;
     85         this.inboundBinderPackage = that.inboundBinderPackage;
     86         this.inboundBinderClass = that.inboundBinderClass;
     87         this.inboundBinderMethod = that.inboundBinderMethod;
     88         this.interesting = that.interesting;
     89     }
     90 
     91     /**
     92      * Make a deep copy of the ThreadSnapshot.
     93      */
     94     @Override
     95     public ThreadSnapshot clone() {
     96         return new ThreadSnapshot(this);
     97     }
     98 
     99     /**
    100      * Compares the threads based on their tid.
    101      */
    102     public int compareTo(ThreadSnapshot that) {
    103         int cmp = this.tid - that.tid;
    104         if (cmp != 0) return cmp;
    105         return this.sysTid - that.sysTid;
    106     }
    107 
    108     /**
    109      * Returns true if this thread has an ingoing or an outgoing binder call.
    110      */
    111     public boolean isBinder() {
    112         return this.outboundBinderPackage != null
    113                 || this.outboundBinderClass != null
    114                 || this.outboundBinderMethod != null
    115                 || this.inboundBinderPackage != null
    116                 || this.inboundBinderClass != null
    117                 || this.inboundBinderMethod != null;
    118     }
    119 }
    120 
    121