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.coderegion;
042:
043: import org.netbeans.lib.profiler.results.ResultsSnapshot;
044: import java.io.DataInputStream;
045: import java.io.DataOutputStream;
046: import java.io.IOException;
047: import java.text.MessageFormat;
048: import java.util.ResourceBundle;
049: import java.util.logging.Level;
050:
051: /**
052: * A class that holds single snapshot of Code Fragment profiling results.
053: *
054: * @author ian Formanek
055: */
056: public final class CodeRegionResultsSnapshot extends ResultsSnapshot {
057: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
058:
059: // -----
060: // I18N String constants
061: private static final ResourceBundle messages = ResourceBundle
062: .getBundle("org.netbeans.lib.profiler.results.coderegion.Bundle"); // NOI18N
063: private static final String CODE_FRAGMENT_MSG = messages
064: .getString("CodeRegionResultsSnapshot_CodeFragmentMsg"); // NOI18N
065: // -----
066:
067: //~ Instance fields ----------------------------------------------------------------------------------------------------------
068:
069: private long[] rawData;
070: private long timerCountsInSecond;
071:
072: //~ Constructors -------------------------------------------------------------------------------------------------------------
073:
074: public CodeRegionResultsSnapshot(long beginTime, long timeTaken,
075: long[] rawData, long timerCountsInSecond) {
076: super (beginTime, timeTaken);
077: this .rawData = rawData;
078: this .timerCountsInSecond = timerCountsInSecond;
079:
080: if (LOGGER.isLoggable(Level.FINEST)) {
081: debugValues();
082: }
083: }
084:
085: public CodeRegionResultsSnapshot() {
086: } // for loading from file
087:
088: //~ Methods ------------------------------------------------------------------------------------------------------------------
089:
090: /**
091: * @return The number of invocations for which we remember their time.
092: * @see #getTimes() - getTimes()[0] contains the total number of invocations of the tracked method/code
093: */
094: public int getInvocations() {
095: if (rawData == null) {
096: return 0;
097: } else {
098: return rawData.length;
099: }
100: }
101:
102: public long getTimerCountsInSecond() {
103: return timerCountsInSecond;
104: }
105:
106: /**
107: * @return an array of long values. times[0] is total number of invocations, times[1]-times[times.length-1] contain
108: * the invocation times for all invocations.
109: */
110: public long[] getTimes() {
111: return rawData;
112: }
113:
114: public void readFromStream(DataInputStream in) throws IOException {
115: super .readFromStream(in);
116: timerCountsInSecond = in.readLong();
117:
118: int len = in.readInt();
119: rawData = new long[len];
120:
121: for (int i = 0; i < len; i++) {
122: rawData[i] = in.readLong();
123: }
124:
125: if (LOGGER.isLoggable(Level.FINEST)) {
126: debugValues();
127: }
128: }
129:
130: public String toString() {
131: return MessageFormat.format(CODE_FRAGMENT_MSG,
132: new Object[] { super .toString() });
133: }
134:
135: public void writeToStream(DataOutputStream out) throws IOException {
136: super .writeToStream(out);
137: out.writeLong(timerCountsInSecond);
138: out.writeInt(rawData.length);
139:
140: for (int i = 0; i < rawData.length; i++) {
141: out.writeLong(rawData[i]);
142: }
143: }
144:
145: private void debugValues() {
146: LOGGER.finest("rawData.length: " + debugLength(rawData)); // NOI18N
147: LOGGER.finest("timerCountsInSecond: " + timerCountsInSecond); // NOI18N
148: }
149: }
|