001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.results.cpu;
042:
043: import org.netbeans.lib.profiler.results.CCTNode;
044:
045: /**
046: * Presentation-Time CPU Profiling Calling Context Tree (CCT) Node that contains all necessary data in its data fields.
047: * These objects are used for reverse CCTs and other trees that have to be constructed incrementally, so that backing by
048: * flattened data cannot be easily implemented.
049: *
050: * @author Misha Dmitriev
051: */
052: public class PrestimeCPUCCTNodeFree extends PrestimeCPUCCTNode {
053: //~ Instance fields ----------------------------------------------------------------------------------------------------------
054:
055: protected int methodId;
056: protected int nCalls;
057: protected long sleepTime0;
058:
059: /** The same class used for both standard and "extended" nodes (collecting one or two timestamps) */
060: protected long totalTime0;
061: protected long totalTime1;
062:
063: /** The same class used for both standard and "extended" nodes (collecting one or two timestamps) */
064: protected long waitTime0;
065:
066: //~ Constructors -------------------------------------------------------------------------------------------------------------
067:
068: /**
069: * Constructor for creating normal nodes representing methods
070: */
071: protected PrestimeCPUCCTNodeFree(CPUCCTContainer container,
072: PrestimeCPUCCTNode parent, int methodId) {
073: super (container, parent);
074: this .methodId = methodId;
075: }
076:
077: //~ Methods ------------------------------------------------------------------------------------------------------------------
078:
079: public CCTNode getChild(int index) {
080: return children[index];
081: }
082:
083: public CCTNode[] getChildren() {
084: return children;
085: }
086:
087: public void setMethodId(int methodId) {
088: this .methodId = methodId;
089: }
090:
091: public int getMethodId() {
092: return methodId;
093: }
094:
095: public int getNCalls() {
096: return nCalls;
097: }
098:
099: public int getNChildren() {
100: return (children != null) ? children.length : 0;
101: }
102:
103: public long getSleepTime0() {
104: return 0; // TODO [wait]
105: }
106:
107: public int getThreadId() {
108: return container.getThreadId();
109: }
110:
111: public long getTotalTime0() {
112: return totalTime0;
113: }
114:
115: public float getTotalTime0InPerCent() {
116: float result = (float) ((double) totalTime0
117: / container.getWholeGraphNetTime0() * 100);
118:
119: return (result < 100) ? result : 100f;
120: }
121:
122: public long getTotalTime1() {
123: return totalTime1;
124: }
125:
126: public float getTotalTime1InPerCent() {
127: return (float) ((double) totalTime1
128: / container.getWholeGraphNetTime1() * 100);
129: }
130:
131: public long getWaitTime0() {
132: return 0; // TODO [wait]
133: }
134:
135: public void addChild(PrestimeCPUCCTNodeFree node) {
136: if (children == null) {
137: children = new PrestimeCPUCCTNodeFree[1];
138: } else {
139: PrestimeCPUCCTNodeFree[] newch = new PrestimeCPUCCTNodeFree[children.length + 1];
140: System.arraycopy(children, 0, newch, 0, children.length);
141: children = newch;
142: }
143:
144: children[children.length - 1] = node;
145: }
146:
147: /**
148: * Methods used during node merging
149: */
150: public void addNCalls(int addCalls) {
151: nCalls += addCalls;
152: }
153:
154: public void addSleepTime0(long addTime) {
155: sleepTime0 += addTime;
156: }
157:
158: public void addTotalTime0(long addTime) {
159: totalTime0 += addTime;
160: }
161:
162: public void addTotalTime1(long addTime) {
163: totalTime1 += addTime;
164: }
165:
166: public void addWaitTime0(long addTime) {
167: waitTime0 += addTime;
168: }
169:
170: /**
171: * Create a copy of this node, but with zero children
172: */
173: public PrestimeCPUCCTNodeFree createChildlessCopy() {
174: try {
175: PrestimeCPUCCTNodeFree res = (PrestimeCPUCCTNodeFree) this
176: .clone();
177: res.children = null;
178:
179: return res;
180: } catch (CloneNotSupportedException ex) {
181: return null; /* Shouldn't happen */
182: }
183: }
184:
185: public void sortChildren(int sortBy, boolean sortOrder) {
186: if (children != null) {
187: doSortChildren(sortBy, sortOrder);
188: }
189: }
190: }
|