1 /* 2 * Copyright (C) 2007 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.ddmlib; 18 19 /** 20 * Holds a thread information. 21 */ 22 public final class ThreadInfo implements IStackTraceInfo { 23 private int mThreadId; 24 private String mThreadName; 25 private int mStatus; 26 private int mTid; 27 private int mUtime; 28 private int mStime; 29 private boolean mIsDaemon; 30 private StackTraceElement[] mTrace; 31 private long mTraceTime; 32 33 // priority? 34 // total CPU used? 35 // method at top of stack? 36 37 /** 38 * Construct with basic identification. 39 */ 40 ThreadInfo(int threadId, String threadName) { 41 mThreadId = threadId; 42 mThreadName = threadName; 43 44 mStatus = -1; 45 //mTid = mUtime = mStime = 0; 46 //mIsDaemon = false; 47 } 48 49 /** 50 * Set with the values we get from a THST chunk. 51 */ 52 void updateThread(int status, int tid, int utime, int stime, boolean isDaemon) { 53 54 mStatus = status; 55 mTid = tid; 56 mUtime = utime; 57 mStime = stime; 58 mIsDaemon = isDaemon; 59 } 60 61 /** 62 * Sets the stack call of the thread. 63 * @param trace stackcall information. 64 */ 65 void setStackCall(StackTraceElement[] trace) { 66 mTrace = trace; 67 mTraceTime = System.currentTimeMillis(); 68 } 69 70 /** 71 * Returns the thread's ID. 72 */ 73 public int getThreadId() { 74 return mThreadId; 75 } 76 77 /** 78 * Returns the thread's name. 79 */ 80 public String getThreadName() { 81 return mThreadName; 82 } 83 84 void setThreadName(String name) { 85 mThreadName = name; 86 } 87 88 /** 89 * Returns the system tid. 90 */ 91 public int getTid() { 92 return mTid; 93 } 94 95 /** 96 * Returns the VM thread status. 97 */ 98 public int getStatus() { 99 return mStatus; 100 } 101 102 /** 103 * Returns the cumulative user time. 104 */ 105 public int getUtime() { 106 return mUtime; 107 } 108 109 /** 110 * Returns the cumulative system time. 111 */ 112 public int getStime() { 113 return mStime; 114 } 115 116 /** 117 * Returns whether this is a daemon thread. 118 */ 119 public boolean isDaemon() { 120 return mIsDaemon; 121 } 122 123 /* 124 * (non-Javadoc) 125 * @see com.android.ddmlib.IStackTraceInfo#getStackTrace() 126 */ 127 public StackTraceElement[] getStackTrace() { 128 return mTrace; 129 } 130 131 /** 132 * Returns the approximate time of the stacktrace data. 133 * @see #getStackTrace() 134 */ 135 public long getStackCallTime() { 136 return mTraceTime; 137 } 138 } 139 140