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.cct.nodes;
042:
043: import org.netbeans.lib.profiler.results.cpu.cct.*;
044:
045: /**
046: *
047: * @author Jaroslav Bachorik
048: */
049: public abstract class TimedCPUCCTNode extends BaseCPUCCTNode implements
050: Cloneable, RuntimeCPUCCTNode {
051: //~ Inner Interfaces ---------------------------------------------------------------------------------------------------------
052:
053: private static interface TimingData {
054: //~ Methods --------------------------------------------------------------------------------------------------------------
055:
056: void setNetTime0(final long time);
057:
058: long getNetTime0();
059:
060: void setNetTime1(final long time);
061:
062: long getNetTime1();
063:
064: void setSleepTime0(final long time);
065:
066: long getSleepTime0();
067:
068: void setWaitTime0(final long time);
069:
070: long getWaitTime0();
071:
072: long addNetTime0(final long time);
073:
074: long addNetTime1(final long time);
075:
076: long addSleepTime0(final long time);
077:
078: long addWaitTime0(final long time);
079: }
080:
081: //~ Inner Classes ------------------------------------------------------------------------------------------------------------
082:
083: private static class TimingDataExtended extends TimingDataSimple {
084: //~ Instance fields ------------------------------------------------------------------------------------------------------
085:
086: private long netTime1;
087:
088: //~ Methods --------------------------------------------------------------------------------------------------------------
089:
090: public synchronized void setNetTime1(final long time) {
091: netTime1 = time;
092: }
093:
094: public synchronized long getNetTime1() {
095: return netTime1;
096: }
097:
098: public synchronized long addNetTime1(final long time) {
099: netTime1 += time;
100:
101: return netTime1;
102: }
103: }
104:
105: private static class TimingDataSimple implements TimingData {
106: //~ Instance fields ------------------------------------------------------------------------------------------------------
107:
108: private long netTime0;
109: private long sleepTime0;
110: private long waitTime0;
111:
112: //~ Methods --------------------------------------------------------------------------------------------------------------
113:
114: public synchronized void setNetTime0(final long time) {
115: netTime0 = time;
116: }
117:
118: public synchronized long getNetTime0() {
119: return netTime0;
120: }
121:
122: public void setNetTime1(final long time) {
123: }
124:
125: public long getNetTime1() {
126: return 0;
127: }
128:
129: public synchronized void setSleepTime0(final long time) {
130: sleepTime0 = time;
131: }
132:
133: public synchronized long getSleepTime0() {
134: return sleepTime0;
135: }
136:
137: public synchronized void setWaitTime0(final long time) {
138: waitTime0 = time;
139: }
140:
141: public synchronized long getWaitTime0() {
142: return waitTime0;
143: }
144:
145: public synchronized long addNetTime0(final long time) {
146: netTime0 += time;
147:
148: return netTime0;
149: }
150:
151: public long addNetTime1(final long time) {
152: return 0;
153: }
154:
155: public synchronized long addSleepTime0(final long time) {
156: sleepTime0 += time;
157:
158: return sleepTime0;
159: }
160:
161: public synchronized long addWaitTime0(final long time) {
162: waitTime0 += time;
163:
164: return waitTime0;
165: }
166: }
167:
168: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
169:
170: public static final int FILTERED_NO = 0;
171: public static final int FILTERED_YES = 2;
172: public static final int FILTERED_MAYBE = 1;
173:
174: //~ Instance fields ----------------------------------------------------------------------------------------------------------
175:
176: private TimingData timingData;
177: private char filteredStatus;
178: private int nCalls;
179: private int nCallsDiff;
180: private long lastWaitOrSleepStamp;
181:
182: //~ Constructors -------------------------------------------------------------------------------------------------------------
183:
184: // volatile protected boolean twoStamps;
185: public TimedCPUCCTNode(CPUCCTNodeFactory factory,
186: boolean collectingTwoTimestamps) {
187: super (factory);
188:
189: if (collectingTwoTimestamps) {
190: timingData = new TimingDataExtended();
191: } else {
192: timingData = new TimingDataSimple();
193: }
194:
195: // twoStamps = collectingTwoTimestamps;
196: }
197:
198: //~ Methods ------------------------------------------------------------------------------------------------------------------
199:
200: /**
201: * Sets the "filtered out" status of the node
202: * @param status Use one of the following:
203: * TimedCPUCCTNode.FILTERED_NO - if the node is not filtered out at all
204: * TimedCPUCCTNode.FILTERED_YES - if the node is unconditionally filtered out
205: * TimedCPUCCTNode.FILTERED_MAYBE - if the node might be filtered out, depending on other profiling settings
206: */
207: public synchronized void setFilteredStatus(int status) {
208: filteredStatus = (char) (status & 0xff);
209: }
210:
211: // public synchronized char getMarkID() {
212: // return markId;
213: // }
214: //
215: // public synchronized void setMarkID(final char markId) {
216: // this.markId = markId;
217: // }
218:
219: /**
220: * Returns the "filtered out" status of the node
221: * @return Returns one of the following values:
222: * TimedCPUCCTNode.FILTERED_NO - if the node is not filtered out at all
223: * TimedCPUCCTNode.FILTERED_YES - if the node is unconditionally filtered out
224: * TimedCPUCCTNode.FILTERED_MAYBE - if the node might be filtered out, depending on other profiling settings
225: */
226: public synchronized int getFilteredStatus() {
227: return filteredStatus;
228: }
229:
230: public synchronized void setLastWaitOrSleepStamp(final long time) {
231: lastWaitOrSleepStamp = time;
232: }
233:
234: public synchronized long getLastWaitOrSleepStamp() {
235: return lastWaitOrSleepStamp;
236: }
237:
238: public synchronized void setNCalls(final int calls) {
239: nCalls = calls;
240: }
241:
242: public synchronized int getNCalls() {
243: return nCalls;
244: }
245:
246: public synchronized void setNCallsDiff(final int calls) {
247: nCallsDiff = calls;
248: }
249:
250: public synchronized int getNCallsDiff() {
251: return nCallsDiff;
252: }
253:
254: public void setNetTime0(final long time) {
255: timingData.setNetTime0(time);
256: }
257:
258: public long getNetTime0() {
259: return timingData.getNetTime0();
260: }
261:
262: public void setNetTime1(final long time) {
263: timingData.setNetTime1(time);
264: }
265:
266: public long getNetTime1() {
267: return timingData.getNetTime1();
268: }
269:
270: public void setSleepTime0(final long time) {
271: timingData.setSleepTime0(time);
272: }
273:
274: public long getSleepTime0() {
275: return timingData.getSleepTime0();
276: }
277:
278: public void setWaitTime0(final long time) {
279: timingData.setWaitTime0(time);
280: }
281:
282: public synchronized long getWaitTime0() {
283: return timingData.getWaitTime0();
284: }
285:
286: public synchronized int addNCalls(final int calls) {
287: nCalls += calls;
288:
289: return nCalls;
290: }
291:
292: public synchronized int addNCallsDiff(final int calls) {
293: nCallsDiff += calls;
294:
295: return nCallsDiff;
296: }
297:
298: public long addNetTime0(final long time) {
299: return timingData.addNetTime0(time);
300: }
301:
302: public long addNetTime1(final long time) {
303: return timingData.addNetTime1(time);
304: }
305:
306: public long addSleepTime0(final long time) {
307: return timingData.addSleepTime0(time);
308: }
309:
310: public long addWaitTime0(final long time) {
311: return timingData.addWaitTime0(time);
312: }
313:
314: // @Override
315: public synchronized Object clone() {
316: TimedCPUCCTNode node = createSelfInstance();
317: node.setNCalls(getNCalls());
318: node.setNetTime0(getNetTime0());
319: node.setNetTime1(getNetTime1());
320: node.setSleepTime0(getSleepTime0());
321: node.setWaitTime0(getWaitTime0());
322: // node.setMarkID(getMarkID());
323: node.setFilteredStatus(getFilteredStatus());
324: node.setNCallsDiff(0);
325:
326: return node;
327: }
328:
329: protected abstract TimedCPUCCTNode createSelfInstance();
330: }
|