aboutsummaryrefslogtreecommitdiffstats
path: root/ddms/libs/ddmlib/src/com/android/ddmlib/ThreadInfo.java
blob: 93db93188c468c184307ad734952e31c2e97c53a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.ddmlib;

/**
 * Holds a thread information.
 */
public final class ThreadInfo implements IStackTraceInfo {
    private int mThreadId;
    private String mThreadName;
    private int mStatus;
    private int mTid;
    private int mUtime;
    private int mStime;
    private boolean mIsDaemon;
    private StackTraceElement[] mTrace;
    private long mTraceTime;

    // priority?
    // total CPU used?
    // method at top of stack?

    /**
     * Construct with basic identification.
     */
    ThreadInfo(int threadId, String threadName) {
        mThreadId = threadId;
        mThreadName = threadName;

        mStatus = -1;
        //mTid = mUtime = mStime = 0;
        //mIsDaemon = false;
    }

    /**
     * Set with the values we get from a THST chunk.
     */
    void updateThread(int status, int tid, int utime, int stime, boolean isDaemon) {

        mStatus = status;
        mTid = tid;
        mUtime = utime;
        mStime = stime;
        mIsDaemon = isDaemon;
    }

    /**
     * Sets the stack call of the thread.
     * @param trace stackcall information.
     */
    void setStackCall(StackTraceElement[] trace) {
        mTrace = trace;
        mTraceTime = System.currentTimeMillis();
    }

    /**
     * Returns the thread's ID.
     */
    public int getThreadId() {
        return mThreadId;
    }

    /**
     * Returns the thread's name.
     */
    public String getThreadName() {
        return mThreadName;
    }

    void setThreadName(String name) {
        mThreadName = name;
    }

    /**
     * Returns the system tid.
     */
    public int getTid() {
        return mTid;
    }

    /**
     * Returns the VM thread status.
     */
    public int getStatus() {
        return mStatus;
    }

    /**
     * Returns the cumulative user time.
     */
    public int getUtime() {
        return mUtime;
    }

    /**
     * Returns the cumulative system time.
     */
    public int getStime() {
        return mStime;
    }

    /**
     * Returns whether this is a daemon thread.
     */
    public boolean isDaemon() {
        return mIsDaemon;
    }

    /*
     * (non-Javadoc)
     * @see com.android.ddmlib.IStackTraceInfo#getStackTrace()
     */
    @Override
    public StackTraceElement[] getStackTrace() {
        return mTrace;
    }

    /**
     * Returns the approximate time of the stacktrace data.
     * @see #getStackTrace()
     */
    public long getStackCallTime() {
        return mTraceTime;
    }
}