001: /*/////////////////////////////////////////////////////////////////////
002:
003: Copyright (C) 2006 TiVo Inc. All rights reserved.
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions are met:
007:
008: + Redistributions of source code must retain the above copyright notice,
009: this list of conditions and the following disclaimer.
010: + Redistributions in binary form must reproduce the above copyright notice,
011: this list of conditions and the following disclaimer in the documentation
012: and/or other materials provided with the distribution.
013: + Neither the name of TiVo Inc nor the names of its contributors may be
014: used to endorse or promote products derived from this software without
015: specific prior written permission.
016:
017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
020: ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
021: LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
022: CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
023: SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
024: INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
025: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
026: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
027: POSSIBILITY OF SUCH DAMAGE.
028:
029: /////////////////////////////////////////////////////////////////////*/
030:
031: package com.tivo.jipviewer;
032:
033: import java.util.List;
034: import java.util.ArrayList;
035:
036: /**
037: * Represents an invocation of a method. It holds the
038: *
039: * * the method
040: * * the number of times it was invoked.
041: * * the child frames
042: * * the total time spent in this method
043: * * the net time spent in this function alone.
044: */
045:
046: class JipFrame {
047:
048: private JipFrame mParent;
049: private final JipMethod mMethod;
050: private final long mThreadId;
051: private final long mCount;
052: private long mTotalTime;
053: private long mNetTime;
054: private List<JipFrame> mvChildren = new ArrayList<JipFrame>();
055:
056: JipFrame(JipFrame parent, JipMethod method, long threadId,
057: long count, long time) {
058: mParent = parent;
059: mMethod = method;
060: mThreadId = threadId;
061: mCount = count;
062: mTotalTime = time;
063:
064: if (mParent != null) {
065: mParent.mvChildren.add(this );
066: }
067: }
068:
069: JipMethod getMethod() {
070: return mMethod;
071: }
072:
073: long getCount() {
074: return mCount;
075: }
076:
077: long getTotalTime() {
078: return mTotalTime;
079: }
080:
081: long getNetTime() {
082: return mNetTime;
083: }
084:
085: JipFrame getParentOrNull() {
086: return mParent;
087: }
088:
089: List<JipFrame> getChildren() {
090: return mvChildren;
091: }
092:
093: /**
094: * returns true iff one of this frame's ancestors
095: * has the same method as this frame.
096: */
097: boolean isReentrant() {
098: JipFrame scan = mParent;
099: while (scan != null) {
100: if (scan.getMethod().equals(mMethod)) {
101: return true;
102: }
103: scan = scan.getParentOrNull();
104: }
105:
106: return false;
107: }
108:
109: void computeNetTime() {
110: long childTime = 0;
111:
112: for (JipFrame kid : mvChildren) {
113: childTime += kid.getTotalTime();
114: }
115:
116: mNetTime = mTotalTime - childTime;
117:
118: if (mNetTime < 0) {
119: mNetTime = 0;
120: }
121: }
122: }
|