FileDocCategorySizeDatePackage
ThreadData.javaAPI DocAndroid 1.5 API6587Wed May 06 22:41:10 BST 2009com.android.traceview

ThreadData

public class ThreadData extends Object implements TimeLineView.Row

Fields Summary
private int
mId
private String
mName
private long
mGlobalStartTime
private long
mGlobalEndTime
private long
mLastEventTime
private long
mCpuTime
private Call
mRoot
private Call
mCurrent
private Call
mLastContextSwitch
private ArrayList
mStack
private HashMap
mStackMethods
private boolean
mIsEmpty
Constructors Summary
ThreadData(int id, String name, MethodData topLevel)


          
        mId = id;
        mName = String.format("[%d] %s", id, name);
        mRoot = new Call(mName, topLevel);
        mCurrent = mRoot;
        mIsEmpty = true;
    
Methods Summary
public longendTrace()

        // If we have calls on the stack when the trace ends, then clean up
        // the stack and compute the inclusive time of the methods by pretending
        // that we are exiting from their methods now.
        while (mCurrent != mRoot) {
            long duration = mLastEventTime - mCurrent.mThreadStartTime;
            pop();
            Call caller = top();
            mCurrent.addInclusiveTime(duration, caller);
            mCurrent.mGlobalEndTime = mGlobalEndTime;
            if (caller == null) {
                caller = mRoot;
            }
            mCurrent = caller;
        }
        return mLastEventTime;
    
private voidenter(Call c, long elapsed)

        Call caller = mCurrent;
        push(c);
        
        // Check the stack for a matching method to determine if this call
        // is recursive.
        MethodData md = c.mMethodData;
        Integer num = mStackMethods.get(md);
        if (num == null) {
            num = 0;
        } else if (num > 0) {
            c.setRecursive(true);
        }
        num += 1;
        mStackMethods.put(md, num);
        mCurrent = c;

        // Add the elapsed time to the caller's exclusive time
        caller.addExclusiveTime(elapsed);
    
private voidexit(Call c, long elapsed, long globalTime)

        mCurrent.mGlobalEndTime = globalTime;
        Call top = pop();
        if (top == null) {
            return;
        }

        if (mCurrent.mMethodData != c.mMethodData) {
            String error = "Method exit (" + c.getName()
                    + ") does not match current method (" + mCurrent.getName()
                    + ")";
            throw new RuntimeException(error);
        } else {
            long duration = c.mThreadStartTime - mCurrent.mThreadStartTime;
            Call caller = top();
            mCurrent.addExclusiveTime(elapsed);
            mCurrent.addInclusiveTime(duration, caller);
            if (caller == null) {
                caller = mRoot;
            }
            mCurrent = caller;
        }
    
public CallgetCalltreeRoot()

        return mRoot;
    
public longgetCpuTime()

        return mCpuTime;
    
public longgetGlobalEndTime()

        return mGlobalEndTime;
    
public longgetGlobalStartTime()

        return mGlobalStartTime;
    
public intgetId()

        return mId;
    
public CallgetLastContextSwitch()

        return mLastContextSwitch;
    
public longgetLastEventTime()

        return mLastEventTime;
    
public java.lang.StringgetName()

        return mName;
    
voidhandleCall(Call call, long globalTime)

        mIsEmpty = false;
        long currentTime = call.mThreadStartTime;
        if (currentTime < mLastEventTime) {
            System.err
            .printf(
                    "ThreadData: '%1$s' call time (%2$d) is less than previous time (%3$d) for thread '%4$s'\n",
                    call.getName(), currentTime, mLastEventTime, mName);
            System.exit(1);
        }
        long elapsed = currentTime - mLastEventTime;
        mCpuTime += elapsed;
        if (call.getMethodAction() == 0) {
            // This is a method entry.
            enter(call, elapsed);
        } else {
            // This is a method exit.
            exit(call, elapsed, globalTime);
        }
        mLastEventTime = currentTime;
        mGlobalEndTime = globalTime;
    
public booleanisEmpty()

        return mIsEmpty;
    
public Callpop()

        ArrayList<Call> stack = mStack;
        if (stack.size() == 0)
            return null;
        Call top = stack.get(stack.size() - 1);
        stack.remove(stack.size() - 1);
        
        // Decrement the count on the method in the hash table and remove
        // the entry when it goes to zero.
        MethodData md = top.mMethodData;
        Integer num = mStackMethods.get(md);
        if (num != null) {
            num -= 1;
            if (num <= 0) {
                mStackMethods.remove(md);
            } else {
                mStackMethods.put(md, num);
            }
        }
        return top;
    
public voidpush(Call c)

        mStack.add(c);
    
public voidsetCpuTime(long cpuTime)

        mCpuTime = cpuTime;
    
public voidsetGlobalEndTime(long globalEndTime)

        mGlobalEndTime = globalEndTime;
    
public voidsetGlobalStartTime(long globalStartTime)

        mGlobalStartTime = globalStartTime;
    
public voidsetLastContextSwitch(Call lastContextSwitch)

        mLastContextSwitch = lastContextSwitch;
    
public voidsetLastEventTime(long lastEventTime)

        mLastEventTime = lastEventTime;
    
public java.lang.StringtoString()

        return mName;
    
public Calltop()

        ArrayList<Call> stack = mStack;
        if (stack.size() == 0)
            return null;
        return stack.get(stack.size() - 1);