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

MethodData

public class MethodData extends Object

Fields Summary
private int
mId
private int
mRank
private String
mClassName
private String
mMethodName
private String
mSignature
private String
mName
private String
mProfileName
private String
mPathname
private int
mLineNumber
private long
mElapsedExclusive
private long
mElapsedInclusive
private long
mTopExclusive
private int[]
mNumCalls
private org.eclipse.swt.graphics.Color
mColor
private org.eclipse.swt.graphics.Color
mFadedColor
private org.eclipse.swt.graphics.Image
mImage
private org.eclipse.swt.graphics.Image
mFadedImage
private HashMap
mParents
private HashMap
mChildren
private HashMap
mRecursiveParents
private HashMap
mRecursiveChildren
private ProfileNode[]
mProfileNodes
private int
mX
private int
mY
private double
mWeight
private Comparator
mByElapsedInclusive
Constructors Summary
public MethodData(int id, String className)


         
        mId = id;
        mClassName = className;
        mMethodName = null;
        mSignature = null;
        mPathname = null;
        mLineNumber = -1;
        computeName();
        computeProfileName();
    
public MethodData(int id, String className, String methodName, String signature, String pathname, int lineNumber)

        mId = id;
        mClassName = className;
        mMethodName = methodName;
        mSignature = signature;
        mPathname = pathname;
        mLineNumber = lineNumber;
        computeName();
        computeProfileName();
    
Methods Summary
public voidaddElapsedExclusive(long time)

        mElapsedExclusive += time;
    
public voidaddElapsedInclusive(long time, boolean isRecursive, Call parent)

        if (isRecursive == false) {
            mElapsedInclusive += time;
            mNumCalls[0] += 1;
        } else {
            mNumCalls[1] += 1;
        }

        if (parent == null)
            return;

        // Find the child method in the parent
        MethodData parentMethod = parent.mMethodData;
        if (parent.isRecursive()) {
            parentMethod.mRecursiveChildren = updateInclusive(time,
                    parentMethod, this, false,
                    parentMethod.mRecursiveChildren);
        } else {
            parentMethod.mChildren = updateInclusive(time,
                    parentMethod, this, false, parentMethod.mChildren);
        }

        // Find the parent method in the child
        if (isRecursive) {
            mRecursiveParents = updateInclusive(time, this, parentMethod, true,
                    mRecursiveParents);
        } else {
            mParents = updateInclusive(time, this, parentMethod, true,
                    mParents);
        }
    
private ProfileData[]addSelf(ProfileData[] children)

        ProfileData[] pdata;
        if (children == null) {
            pdata = new ProfileData[1];
        } else {
            pdata = new ProfileData[children.length + 1];
            System.arraycopy(children, 0, pdata, 1, children.length);
        }
        pdata[0] = new ProfileSelf(this);
        return pdata;
    
public voidaddTopExclusive(long time)

        mTopExclusive += time;
    
public doubleaddWeight(int x, int y, double weight)


            
        if (mX == x && mY == y)
            mWeight += weight;
        else {
            mX = x;
            mY = y;
            mWeight = weight;
        }
        return mWeight;
    
public voidanalyzeData()

        // Sort the parents and children into decreasing inclusive time
        ProfileData[] sortedParents;
        ProfileData[] sortedChildren;
        ProfileData[] sortedRecursiveParents;
        ProfileData[] sortedRecursiveChildren;
        
        sortedParents = sortProfileData(mParents);
        sortedChildren = sortProfileData(mChildren);
        sortedRecursiveParents = sortProfileData(mRecursiveParents);
        sortedRecursiveChildren = sortProfileData(mRecursiveChildren);
        
        // Add "self" time to the top of the sorted children
        sortedChildren = addSelf(sortedChildren);
        
        // Create the ProfileNode objects that we need
        ArrayList<ProfileNode> nodes = new ArrayList<ProfileNode>();
        ProfileNode profileNode;
        if (mParents != null) {
            profileNode = new ProfileNode("Parents", this, sortedParents,
                    true, false);
            nodes.add(profileNode);
        }
        if (mChildren != null) {
            profileNode = new ProfileNode("Children", this, sortedChildren,
                    false, false);
            nodes.add(profileNode);
        }
        if (mRecursiveParents!= null) {
            profileNode = new ProfileNode("Parents while recursive", this,
                    sortedRecursiveParents, true, true);
            nodes.add(profileNode);
        }
        if (mRecursiveChildren != null) {
            profileNode = new ProfileNode("Children while recursive", this,
                    sortedRecursiveChildren, false, true);
            nodes.add(profileNode);
        }
        mProfileNodes = nodes.toArray(new ProfileNode[nodes.size()]);
    
public voidclearWeight()

        mWeight = 0;
    
private voidcomputeName()

        if (mMethodName == null) {
            mName = mClassName;
            return;
        }

        StringBuilder sb = new StringBuilder();
        sb.append(mClassName);
        sb.append(".");  //$NON-NLS-1$
        sb.append(mMethodName);
        sb.append(" ");  //$NON-NLS-1$
        sb.append(mSignature);
        mName = sb.toString();
    
public voidcomputeProfileName()

        if (mRank == -1) {
            mProfileName = mName;
            return;
        }
        
        StringBuilder sb = new StringBuilder();
        sb.append(mRank);
        sb.append(" ");  //$NON-NLS-1$
        sb.append(getName());
        mProfileName = sb.toString();
    
public java.lang.StringgetCalls()

        return String.format("%d+%d", mNumCalls[0], mNumCalls[1]);
    
public java.lang.StringgetClassName()

        return mClassName;
    
public org.eclipse.swt.graphics.ColorgetColor()

        return mColor;
    
public longgetElapsedExclusive()

        return mElapsedExclusive;
    
public longgetElapsedInclusive()

        return mElapsedInclusive;
    
public org.eclipse.swt.graphics.ColorgetFadedColor()

        return mFadedColor;
    
public org.eclipse.swt.graphics.ImagegetFadedImage()

        return mFadedImage;
    
public intgetId()

        return mId;
    
public org.eclipse.swt.graphics.ImagegetImage()

        return mImage;
    
public intgetLineNumber()

        return mLineNumber;
    
public java.lang.StringgetMethodName()

        return mMethodName;
    
public java.lang.StringgetName()

        return mName;
    
public java.lang.StringgetPathname()

        return mPathname;
    
public java.lang.StringgetProfileName()

        return mProfileName;
    
public ProfileNode[]getProfileNodes()

        return mProfileNodes;
    
public intgetRank()

        return mRank;
    
public longgetTopExclusive()

        return mTopExclusive;
    
public intgetTotalCalls()

        return mNumCalls[0] + mNumCalls[1];
    
public voidsetColor(org.eclipse.swt.graphics.Color color)

        mColor = color;
    
public voidsetFadedColor(org.eclipse.swt.graphics.Color fadedColor)

        mFadedColor = fadedColor;
    
public voidsetFadedImage(org.eclipse.swt.graphics.Image fadedImage)

        mFadedImage = fadedImage;
    
public voidsetImage(org.eclipse.swt.graphics.Image image)

        mImage = image;
    
public voidsetLineNumber(int lineNumber)

        mLineNumber = lineNumber;
    
public voidsetPathname(java.lang.String pathname)

        mPathname = pathname;
    
public voidsetRank(int rank)

        mRank = rank;
        computeProfileName();
    
private ProfileData[]sortProfileData(java.util.HashMap map)

        if (map == null)
            return null;

        // Convert the hash values to an array of ProfileData
        Collection<ProfileData> values = map.values();
        ProfileData[] sorted = values.toArray(new ProfileData[values.size()]);
        
        // Sort the array by elapsed inclusive time
        Arrays.sort(sorted, mByElapsedInclusive);
        return sorted;
    
public java.lang.StringtoString()

        return getName();
    
private java.util.HashMapupdateInclusive(long time, com.android.traceview.MethodData contextMethod, com.android.traceview.MethodData elementMethod, boolean elementIsParent, java.util.HashMap map)

        if (map == null) {
            map = new HashMap<Integer, ProfileData>(4);
        } else {
            ProfileData profileData = map.get(elementMethod.mId);
            if (profileData != null) {
                profileData.addElapsedInclusive(time);
                return map;
            }
        }

        ProfileData elementData = new ProfileData(contextMethod,
                elementMethod, elementIsParent);
        elementData.setElapsedInclusive(time);
        elementData.setNumCalls(1);
        map.put(elementMethod.mId, elementData);
        return map;