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;
042:
043: import org.netbeans.lib.profiler.utils.StringUtils;
044: import java.io.DataInputStream;
045: import java.io.DataOutputStream;
046: import java.io.IOException;
047: import java.util.Date;
048: import java.util.logging.Level;
049: import java.util.logging.Logger;
050:
051: /**
052: * Root superclass for various types of profiling results snapshots
053: */
054: public class ResultsSnapshot {
055: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
056:
057: protected static final Logger LOGGER = Logger
058: .getLogger(ResultsSnapshot.class.getName());
059: private static final int SNAPSHOT_VERSION = 1;
060:
061: //~ Instance fields ----------------------------------------------------------------------------------------------------------
062:
063: // protected static final boolean DEBUG = System.getProperty("org.netbeans.lib.profiler.results.ResultsSnapshot")
064: // != null; // NOI18N // TODO [release] set tp TRUE at release
065: protected long beginTime;
066: protected long timeTaken;
067:
068: //~ Constructors -------------------------------------------------------------------------------------------------------------
069:
070: public ResultsSnapshot() {
071: } // for externalization
072:
073: protected ResultsSnapshot(long beginTime, long timeTaken) {
074: this .beginTime = beginTime;
075: this .timeTaken = timeTaken;
076:
077: if (LOGGER.isLoggable(Level.FINEST)) {
078: debugValues();
079: }
080: }
081:
082: //~ Methods ------------------------------------------------------------------------------------------------------------------
083:
084: public long getBeginTime() {
085: return beginTime;
086: }
087:
088: public long getTimeTaken() {
089: return timeTaken;
090: }
091:
092: public void readFromStream(DataInputStream in) throws IOException {
093: int version = in.readInt();
094:
095: if (version != SNAPSHOT_VERSION) {
096: throw new IOException("Stored version not supported: "
097: + version); // NOI18N
098: }
099:
100: beginTime = in.readLong();
101: timeTaken = in.readLong();
102:
103: if (LOGGER.isLoggable(Level.FINEST)) {
104: debugValues();
105: }
106: }
107:
108: public String toString() {
109: return StringUtils.formatUserDate(new Date(timeTaken));
110: }
111:
112: public void writeToStream(DataOutputStream out) throws IOException {
113: out.writeInt(SNAPSHOT_VERSION);
114: out.writeLong(beginTime);
115: out.writeLong(timeTaken);
116: }
117:
118: protected String debugLength(Object array) {
119: if (array == null) {
120: return "null"; // NOI18N
121: } else if (array instanceof int[]) {
122: return "" + ((int[]) array).length; // NOI18N
123: } else if (array instanceof long[]) {
124: return "" + ((long[]) array).length; // NOI18N
125: } else if (array instanceof float[]) {
126: return "" + ((float[]) array).length; // NOI18N
127: } else if (array instanceof Object[]) {
128: return "" + ((Object[]) array).length; // NOI18N
129: } else {
130: return "Unknown"; // NOI18N
131: }
132: }
133:
134: private void debugValues() {
135: LOGGER.finest("beginTime: " + beginTime); // NOI18N
136: LOGGER.finest("timeTaken: " + timeTaken); // NOI18N
137: }
138: }
|