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: /*
042: * CPUType.java
043: *
044: * Created on July 19, 2005, 5:20 PM
045: *
046: * To change this template, choose Tools | Options and locate the template under
047: * the Source Creation and Management node. Right-click the template and choose
048: * Open. You can then make changes to the template in the Source Editor.
049: */
050: package org.netbeans.lib.profiler.tests.jfluid.benchmarks;
051:
052: import org.netbeans.lib.profiler.ProfilerEngineSettings;
053: import org.netbeans.lib.profiler.TargetAppRunner;
054: import org.netbeans.lib.profiler.global.CommonConstants;
055: import org.netbeans.lib.profiler.tests.jfluid.*;
056: import org.netbeans.lib.profiler.tests.jfluid.utils.DumpStream;
057: import org.netbeans.lib.profiler.tests.jfluid.utils.TestProfilerAppHandler;
058: import org.netbeans.lib.profiler.tests.jfluid.utils.TestProfilingPointsProcessor;
059: import org.netbeans.lib.profiler.tests.jfluid.utils.Utils;
060: import java.io.BufferedInputStream;
061: import java.io.File;
062: import java.io.FileInputStream;
063: import java.io.IOException;
064: import java.util.*;
065:
066: /**
067: *
068: * @author ehucka
069: */
070: public abstract class JbbTestType extends CommonProfilerTestCase {
071: //~ Constructors -------------------------------------------------------------------------------------------------------------
072:
073: /**
074: * Creates a new instance of CPUType
075: */
076: public JbbTestType(String name) {
077: super (name);
078: }
079:
080: //~ Methods ------------------------------------------------------------------------------------------------------------------
081:
082: protected int[] checkResults(File workdir) {
083: try {
084: File rawres = new File(workdir,
085: "results/SPECjbbSingleJVM/SPECjbb.001.raw");
086: log(rawres.getAbsolutePath() + " exists " + rawres.exists());
087:
088: BufferedInputStream inp = new BufferedInputStream(
089: new FileInputStream(rawres));
090: Properties props = new Properties();
091: props.load(inp);
092: inp.close();
093:
094: int[] ret = new int[2];
095: ret[0] = (int) Double.parseDouble(props
096: .getProperty("result.test1.company.score"));
097: //ret[0][1]=(int)Double.parseDouble(props.getProperty("result.test1.company.heapused"));
098: ret[1] = (int) Double.parseDouble(props
099: .getProperty("result.test2.company.score"));
100:
101: //ret[1][1]=(int)Double.parseDouble(props.getProperty("result.test2.company.heapused"));
102: return ret;
103: } catch (IOException ex) {
104: ex.printStackTrace();
105: }
106:
107: return null;
108: }
109:
110: protected void evalueateResults(int[] without, int[] with) {
111: double[] diffs = new double[with.length];
112:
113: for (int i = 0; i < diffs.length; i++) {
114: diffs[i] = (100.0 * (without[i] - with[i])) / with[i];
115: }
116:
117: int maxmult = 0;
118: log("\n\nTests Normal Profiler Diff% Multiple");
119:
120: for (int i = 0; i < diffs.length; i++) {
121: log(complete("test " + String.valueOf(i + 1), 10)
122: + complete(String.valueOf(without[i]), 10)
123: + complete(String.valueOf(with[i]), 10)
124: + complete(String.valueOf(diffs[i]), 6) + " % "
125: + complete(String.valueOf(without[i] / with[i]), 8));
126:
127: if (maxmult < (without[i] / with[i])) {
128: maxmult = without[i] / with[i];
129: }
130: }
131:
132: log("\nMax multiple: " + String.valueOf(maxmult) + " %\n");
133: assertTrue("Difference multiple is greater than 5 - "
134: + String.valueOf(maxmult), (maxmult <= 5));
135: }
136:
137: protected ProfilerEngineSettings initCpuTest(String projectName,
138: String mainClass) {
139: ProfilerEngineSettings settings = initTest(projectName,
140: mainClass, null);
141:
142: //defaults
143: //addJVMArgs(settings, "-Dorg.netbeans.lib.profiler.wireprotocol.WireIO=true");
144: String xData = new File(getDataDir(), "/projects/"
145: + projectName + "/config.properties").getAbsolutePath();
146: addJVMArgs(settings, "-Xms256m -Xmx256m");
147: settings.setMainArgs("-propfile " + xData);
148: settings.setThreadCPUTimerOn(false);
149: settings.setCPUProfilingType(CommonConstants.CPU_INSTR_FULL);
150:
151: Utils.copyFolder(new File(getDataDir(), "/projects/"
152: + projectName + "/xml"), new File(settings
153: .getWorkingDir(), "xml"));
154:
155: return settings;
156: }
157:
158: protected void startBenchmarkTest(ProfilerEngineSettings settings,
159: long checkDelay) {
160: //without profiler
161: log("without profiler");
162: log("*******************************************************************************");
163:
164: ArrayList command = new ArrayList(20);
165: command.add(settings.getTargetJVMExeFile());
166: command.add("-cp");
167: command.add(settings.getMainClassPath());
168:
169: String[] args = settings.getJVMArgs();
170:
171: for (int i = 0; i < args.length; i++) {
172: command.add(args[i]);
173: }
174:
175: command.add(settings.getMainClassName());
176: args = settings.getMainArgs();
177:
178: for (int i = 0; i < args.length; i++) {
179: command.add(args[i]);
180: }
181:
182: try {
183: Process p = Runtime.getRuntime().exec(
184: (String[]) (command.toArray(new String[command
185: .size()])), null,
186: new File(settings.getWorkingDir()));
187: new DumpStream(p, p.getErrorStream(), getLogStream(),
188: "[App error] ").start();
189: new DumpStream(p, p.getInputStream(), getLogStream(),
190: "[App output] ").start();
191: p.waitFor();
192: } catch (Exception ex) {
193: ex.printStackTrace();
194: }
195:
196: File workdir = new File(settings.getWorkingDir());
197: int[] res1 = checkResults(workdir);
198: TargetAppRunner runner = new TargetAppRunner(settings,
199: new TestProfilerAppHandler(this ),
200: new TestProfilingPointsProcessor());
201:
202: try {
203: Utils.removeFolder(new File(workdir, "results"));
204: log("with profiler");
205: log("*******************************************************************************");
206: runner.addProfilingEventListener(Utils
207: .createProfilingListener(this ));
208:
209: runner.readSavedCalibrationData();
210: runner.getProfilerClient()
211: .initiateRecursiveCPUProfInstrumentation(
212: settings.getInstrumentationRootMethods());
213:
214: long time = System.currentTimeMillis();
215: Process p = startTargetVM(runner);
216: assertNotNull("Target JVM is not started", p);
217: time = System.currentTimeMillis();
218: runner.connectToStartedVMAndStartTA();
219: //Thread.sleep(delay);//wait for init
220: waitForStatus(STATUS_RUNNING);
221: assertTrue("runner is not running", runner
222: .targetAppIsRunning());
223:
224: ArrayList metods = new ArrayList();
225:
226: while (!isStatus(STATUS_APP_FINISHED)
227: && !isStatus(STATUS_ERROR)) {
228: time = System.currentTimeMillis();
229: Thread.sleep(checkDelay);
230:
231: //do nothing
232: }
233:
234: setStatus(STATUS_MEASURED);
235: log("finish ****************************** " + getStatus());
236:
237: int[] res2 = checkResults(workdir);
238: evalueateResults(res1, res2);
239: Utils.removeFolder(new File(workdir, "results"));
240: } catch (Exception ex) {
241: log(ex);
242: assertTrue("Exception thrown: " + ex.getMessage(), false);
243: } finally {
244: finalizeTest(runner);
245: }
246: }
247: }
|