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.tests.jfluid;
042:
043: import org.netbeans.junit.NbTestCase;
044: import org.netbeans.junit.diff.LineDiff;
045: import org.netbeans.lib.profiler.ProfilerEngineSettings;
046: import org.netbeans.lib.profiler.TargetAppRunner;
047: import org.netbeans.lib.profiler.classfile.ClassRepository;
048: import org.netbeans.lib.profiler.client.AppStatusHandler;
049: import org.netbeans.lib.profiler.client.ClientUtils;
050: import org.netbeans.lib.profiler.client.ClientUtils.SourceCodeSelection;
051: import org.netbeans.lib.profiler.global.CommonConstants;
052: import org.netbeans.lib.profiler.global.InstrumentationFilter;
053: import org.netbeans.lib.profiler.global.Platform;
054: import org.netbeans.lib.profiler.tests.jfluid.utils.DumpStream;
055: import org.netbeans.lib.profiler.utils.MiscUtils;
056: import java.io.File;
057: import java.io.FileOutputStream;
058: import java.io.IOException;
059: import java.io.PrintStream;
060: import java.util.ArrayList;
061: import java.util.Arrays;
062: import java.util.HashMap;
063:
064: public abstract class CommonProfilerTestCase extends NbTestCase {
065: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
066:
067: public static final int STATUS_ERROR = 255;
068: public static final int STATUS_NONE = 0;
069: public static final int STATUS_RUNNING = 1;
070: public static final int STATUS_RESULTS_AVAILABLE = 2;
071: public static final int STATUS_APP_FINISHED = 4;
072: public static final int STATUS_MEASURED = 8;
073: public static final int STATUS_FINISHED = 16;
074: public static final int STATUS_LIVERESULTS_AVAILABLE = 32;
075: private static final boolean CREATE_GOLDENS = false;
076: private static final String GOLDENS_CVS_PATH = "/space/cvs/profiler/profiler/libs/jfluid/test/functional/data/goldenfiles";
077:
078: //~ Instance fields ----------------------------------------------------------------------------------------------------------
079:
080: protected DumpStream err;
081: protected DumpStream out;
082: protected File diff;
083: protected File ref;
084: protected Process profilingProcess = null;
085: PrintStream goldenStream;
086: PrintStream logStream;
087: PrintStream refStream;
088: private String mainClass;
089: private String projectName;
090: private String[][] rootMethods;
091: private int status = 0;
092:
093: //~ Constructors -------------------------------------------------------------------------------------------------------------
094:
095: public CommonProfilerTestCase(String name) {
096: super (name);
097: }
098:
099: //~ Methods ------------------------------------------------------------------------------------------------------------------
100:
101: public void setMainClass(String mainClass) {
102: this .mainClass = mainClass;
103: }
104:
105: public String getMainClass() {
106: return mainClass;
107: }
108:
109: public void setProjectName(String projectName) {
110: this .projectName = projectName;
111: }
112:
113: public String getProjectName() {
114: return projectName;
115: }
116:
117: public void setRootMethods(String[][] rootMethods) {
118: this .rootMethods = rootMethods;
119: }
120:
121: public String[][] getRootMethods() {
122: return rootMethods;
123: }
124:
125: public synchronized void setStatus(int status) {
126: log("STATUS: set status " + getStatus(status));
127: System.err.println("STATUS: set status " + getStatus(status));
128:
129: if (STATUS_ERROR == status) {
130: new Exception("STATUS_ERROR set").printStackTrace();
131: }
132:
133: this .status |= status;
134: notifyAll();
135: }
136:
137: public int getStatus() {
138: return status;
139: }
140:
141: public String getStatus(int status) {
142: StringBuffer sb = new StringBuffer();
143:
144: if (status == STATUS_ERROR) {
145: sb.append("ERROR");
146: } else {
147: if ((status & STATUS_APP_FINISHED) > 0) {
148: sb.append("APP_FINISHED ");
149: }
150:
151: if ((status & STATUS_FINISHED) > 0) {
152: sb.append("FINISHED ");
153: }
154:
155: if ((status & STATUS_MEASURED) > 0) {
156: sb.append("MEASURED ");
157: }
158:
159: if (status == 0) {
160: sb.append("NONE ");
161: }
162:
163: if ((status & STATUS_RESULTS_AVAILABLE) > 0) {
164: sb.append("RESULTS_AVAILABLE ");
165: }
166:
167: if ((status & STATUS_RUNNING) > 0) {
168: sb.append("RUNNING ");
169: }
170:
171: if ((status & STATUS_LIVERESULTS_AVAILABLE) > 0) {
172: sb.append("LIVERESULTS_AVAILABLE ");
173: }
174: }
175:
176: return sb.toString();
177: }
178:
179: public boolean isStatus(int status) {
180: if (status == STATUS_ERROR) {
181: return (getStatus() == status);
182: }
183:
184: return ((getStatus() & status) > 0);
185: }
186:
187: public void log(Throwable t) {
188: t.printStackTrace(getLogStream());
189: }
190:
191: public void log(String s) {
192: getLogStream().println(s);
193: }
194:
195: public void log(Object o) {
196: log(o.toString());
197: }
198:
199: public void log(double[] ar) {
200: StringBuffer sb = new StringBuffer(ar.length * 10);
201: sb.append("[");
202:
203: for (int i = 0; i < ar.length; i++) {
204: sb.append(String.valueOf(ar[i]));
205:
206: if (i < (ar.length - 1)) {
207: sb.append(", ");
208: }
209: }
210:
211: sb.append("]");
212: log(sb.toString());
213: }
214:
215: public void log(int[] ar) {
216: StringBuffer sb = new StringBuffer(ar.length * 10);
217: sb.append("[");
218:
219: for (int i = 0; i < ar.length; i++) {
220: sb.append(String.valueOf(ar[i]));
221:
222: if (i < (ar.length - 1)) {
223: sb.append(", ");
224: }
225: }
226:
227: sb.append("]");
228: log(sb.toString());
229: }
230:
231: public void log(HashMap map) {
232: Object[] keys = map.keySet().toArray();
233: Arrays.sort(keys);
234:
235: for (int i = 0; i < keys.length; i++) {
236: log((String) keys[i] + " = " + (String) (map.get(keys[i])));
237: }
238: }
239:
240: public void log(ProfilerEngineSettings settings) {
241: HashMap map = new HashMap(32);
242: storeSettings(settings, map);
243: log(map);
244: }
245:
246: public void ref(String s) {
247: //System.out.println(s);
248: getRefStream().println(s);
249:
250: if (CREATE_GOLDENS) {
251: goldenStream.println(s);
252: }
253: }
254:
255: public void ref(String[] s) {
256: StringBuffer sb = new StringBuffer();
257:
258: for (int i = 0; i < s.length; i++) {
259: sb.append(s[i]);
260:
261: if (i < (s.length - 1)) {
262: sb.append(", ");
263: }
264: }
265:
266: ref(sb);
267: }
268:
269: public void ref(Object o) {
270: ref(o.toString());
271: }
272:
273: public void runTest() throws Throwable {
274: try {
275: super .runTest();
276: } catch (Throwable td) {
277: td.printStackTrace();
278:
279: if (!isStatus(STATUS_ERROR)) {
280: setStatus(STATUS_ERROR);
281: }
282:
283: throw td;
284: }
285: }
286:
287: public synchronized void unsetStatus(int status) {
288: if (status != STATUS_ERROR) {
289: log("STATUS: unset status " + getStatus(status));
290: System.err.println("STATUS: unset status "
291: + getStatus(status));
292: this .status &= ~status;
293: notifyAll();
294: }
295: }
296:
297: public void waitForStatus(int status) {
298: waitForStatus(status, 0L);
299: }
300:
301: public synchronized void waitForStatus(int status, long timeout) {
302: log("STATUS: wait for status " + getStatus(status));
303: System.err.println("STATUS: wait for status "
304: + getStatus(status));
305:
306: while (!isStatus(status) && !isStatus(STATUS_ERROR)) {
307: try {
308: wait(timeout);
309: } catch (InterruptedException e) {
310: }
311: }
312:
313: log("STATUS: reached status " + getStatus(getStatus()));
314: System.err.println("STATUS: reached status "
315: + getStatus(getStatus()));
316:
317: if (isStatus(STATUS_ERROR)) {
318: assertTrue("Error state of test", false);
319: }
320: }
321:
322: protected void setClassPath(ProfilerEngineSettings settings) {
323: String projPath = getProjectPath(getProjectName());
324: settings.setMainClassPath(projPath);
325: //coverage
326: //settings.setMainClassPath("/space/tmp/testrun/emma/lib/emma.jar:" + xData + jarPath);
327: settings.setMainClass(getMainClass());
328: ClassRepository.initClassPaths(getDataDir().getAbsolutePath(),
329: new String[] { projPath, "", "" });
330: }
331:
332: protected PrintStream getLogStream() {
333: if (logStream == null) {
334: logStream = getLog();
335: }
336:
337: return logStream;
338: }
339:
340: protected void setProfilerHome(ProfilerEngineSettings settings) {
341: try {
342: String profilerHome = System.getProperty("profiler.home");
343:
344: if ((profilerHome == null)
345: || !new File(profilerHome).exists()) {
346: profilerHome = "/space/Builds/profiler/profiler2";
347: }
348:
349: settings.initialize(profilerHome + "/lib");
350: } catch (IOException ex) {
351: ex.printStackTrace();
352: assertFalse("Error in initialization", true);
353: }
354: }
355:
356: protected String getProjectPath(String projectName) {
357: String jarPath = "/projects/" + projectName + "/distrib/"
358: + projectName + ".jar";
359:
360: if (!new File(getDataDir(), jarPath).exists()) {
361: jarPath = "/projects/" + projectName + "/dist/"
362: + projectName + ".jar";
363: }
364:
365: if (!new File(getDataDir(), jarPath).exists()) {
366: assertTrue("There is not profiled application", false);
367:
368: return "";
369: }
370:
371: String xData = getDataDir().getAbsolutePath();
372:
373: return xData + jarPath;
374: }
375:
376: protected PrintStream getRefStream() {
377: if (refStream == null) {
378: refStream = getRef();
379:
380: if (CREATE_GOLDENS) {
381: File file = new File(GOLDENS_CVS_PATH);
382: file = new File(file, getClass().getName().replace('.',
383: '/')
384: + "/" + getName() + ".pass");
385:
386: if (!file.getParentFile().exists()) {
387: file.getParentFile().mkdirs();
388: }
389:
390: try {
391: goldenStream = new PrintStream(
392: new FileOutputStream(file));
393: } catch (Exception ex) {
394: ex.printStackTrace();
395: }
396: }
397: }
398:
399: return refStream;
400: }
401:
402: protected void setRootMethods(ProfilerEngineSettings settings,
403: String[][] rootMethods) {
404: this .rootMethods = rootMethods;
405:
406: if (rootMethods == null) {
407: this .rootMethods = new String[][] { { mainClass, "main",
408: "([Ljava/lang/String;)V" } };
409: }
410:
411: ArrayList al = new ArrayList();
412:
413: for (int i = 0; i < this .rootMethods.length; i++) {
414: al.add(new ClientUtils.SourceCodeSelection(
415: this .rootMethods[i][0], this .rootMethods[i][1],
416: this .rootMethods[i][2]));
417: }
418:
419: settings
420: .setInstrumentationRootMethods((ClientUtils.SourceCodeSelection[]) al
421: .toArray(new ClientUtils.SourceCodeSelection[al
422: .size()]));
423: }
424:
425: protected void setTargetVM(ProfilerEngineSettings settings) {
426: String vers = System.getProperty("java.vm.version");
427:
428: if (vers.startsWith("1.5")) {
429: if (vers.startsWith("1.5.0")
430: && ((vers.charAt("1.5.0".length()) != '_') || (Integer
431: .parseInt(vers.substring(
432: "1.5.0".length() + 1, "1.5.0"
433: .length() + 3)) < 4))) {
434: System.err.println("Illegal version of JVM: " + vers);
435:
436: return;
437: }
438:
439: settings
440: .setTargetJDKVersionString(CommonConstants.JDK_15_STRING);
441: } else if (vers.startsWith("1.6")) {
442: settings
443: .setTargetJDKVersionString(CommonConstants.JDK_16_STRING);
444: } else if (vers.startsWith("1.7")) {
445: settings
446: .setTargetJDKVersionString(CommonConstants.JDK_17_STRING);
447: }
448:
449: String home = System.getProperty("java.home");
450:
451: if (File.separatorChar == '/') {
452: settings.setTargetJVMExeFile(home + "/bin/java");
453: } else {
454: settings.setTargetJVMExeFile(home + "\\bin\\java.exe");
455: }
456:
457: settings
458: .setSystemArchitecture(Platform.getSystemArchitecture());
459: }
460:
461: protected void setUp() throws Exception {
462: System.err.println("START TEST " + getClass().getName() + "."
463: + getName());
464:
465: //System.setProperty("org.netbeans.lib.profiler.TargetAppRunner", "true");
466: File workdir = getWorkDir();
467: diff = new File(getWorkDir(), getName() + ".diff");
468: ref = new File(getWorkDir(), getName() + ".ref");
469: log("Test Source: http://toolscvs.sfbay.sun.com/cvsweb/profiler/libs/jfluid/test/functional/src/"
470: + getClass().getName().replace('.', '/')
471: + ".java?cvsroot=/cvs/profiler");
472:
473: //check for running server
474: try {
475: java.net.Socket sock = new java.net.Socket("localhost",
476: 5140);
477: sock.getOutputStream().write(1);
478: sock.close();
479: assertTrue("There is running another server on port 5140",
480: false);
481: } catch (Exception ex) {
482: }
483: }
484:
485: protected void addJVMArgs(ProfilerEngineSettings settings,
486: String arg) {
487: String old = settings.getJVMArgsAsSingleString();
488:
489: if ((old == null) || (old.length() == 0)) {
490: settings.setJVMArgs(arg);
491: } else {
492: settings.setJVMArgs(old + " " + arg);
493: }
494: }
495:
496: protected void bindStreams(Process p) {
497: err = new DumpStream(p, p.getErrorStream(), getLogStream(),
498: "[App error] ");
499: err.start();
500: out = new DumpStream(p, p.getInputStream(), getLogStream(),
501: "[App output] ");
502: out.start();
503: }
504:
505: protected String complete(String s, int chars) {
506: StringBuffer sb = new StringBuffer(chars);
507: int tot = chars - s.length();
508: sb.append(s);
509:
510: for (int i = 0; i < tot; i++) {
511: sb.append(" ");
512: }
513:
514: return sb.substring(0, chars);
515: }
516:
517: protected void finalizeTest(TargetAppRunner runner) {
518: //finish client
519: if (!isStatus(STATUS_MEASURED)) { // to release handleShutdown call
520: System.err.println("must be set measured");
521: setStatus(STATUS_MEASURED);
522: }
523:
524: if (!isStatus(STATUS_APP_FINISHED)) { //not handled shutdown
525: System.err.println("must be treminated target vm");
526: runner.terminateTargetJVM();
527: }
528:
529: //wait for agent death
530: int cycles = 50;
531:
532: while ((cycles > 0) && runner.targetJVMIsAlive()) {
533: try {
534: Thread.sleep(500);
535: cycles--;
536: } catch (InterruptedException ex) {
537: }
538: }
539:
540: assertFalse("Target JVM is running after finish", runner
541: .targetJVMIsAlive());
542:
543: //test the profiled proces is finished
544: if (profilingProcess != null) {
545: try {
546: profilingProcess.waitFor();
547:
548: if (out != null) {
549: out.join();
550: err.join();
551: }
552:
553: profilingProcess.destroy();
554: } catch (InterruptedException ex) {
555: ex.printStackTrace();
556: }
557:
558: profilingProcess = null;
559: }
560:
561: //log settings
562: log("\nProfiler settings\n");
563: log(runner.getProfilerEngineSettings());
564: log("");
565: System.err.println("Test " + getName() + " finalized.");
566: }
567:
568: protected void initAppByStream(TargetAppRunner runner) {
569: Process p = runner.getRunningAppProcess();
570: assert p != null;
571:
572: try {
573: PrintStream ps = new PrintStream(p.getOutputStream());
574: ps.print("start");
575: ps.close();
576: } catch (Exception ex) {
577: }
578: }
579:
580: protected ProfilerEngineSettings initTest(String projectName,
581: String mainClass, String[][] rootMethods) {
582: ProfilerEngineSettings settings = new ProfilerEngineSettings();
583: settings.setPortNo(5140);
584: settings.setSeparateConsole(true);
585: settings
586: .setInstrScheme(ProfilerEngineSettings.INSTRSCHEME_TOTAL);
587: settings.setJVMArgs("");
588: //coverage
589: //addJVMArgs(settings, "-Demma.coverage.out.file=/space/tmp/testrun/coverage.emma");
590: setProjectName(projectName);
591: setMainClass(mainClass);
592: setRootMethods(settings, rootMethods);
593:
594: setTargetVM(settings);
595: setClassPath(settings);
596: setProfilerHome(settings);
597:
598: setStatus(STATUS_NONE);
599:
600: return settings;
601: }
602:
603: protected Process startTargetVM(TargetAppRunner runner) {
604: ProfilerEngineSettings settings = runner
605: .getProfilerEngineSettings();
606: AppStatusHandler handler = runner.getAppStatusHandler();
607: ArrayList commands = new ArrayList(10);
608:
609: commands.add(settings.getTargetJVMExeFile());
610:
611: //agentpath with options
612: String jfNativeLibFullName = Platform
613: .getAgentNativeLibFullName(settings
614: .getJFluidRootDirName(), false, settings
615: .getTargetJDKVersionString(), -1);
616: String libpath = jfNativeLibFullName.substring(0,
617: jfNativeLibFullName.indexOf("deployed") - 1);
618: String timeOut = System.getProperty(
619: "profiler.agent.connect.timeout", "10");
620: commands.add("-agentpath:" + jfNativeLibFullName + "="
621: + libpath + ","
622: + Integer.toString(settings.getPortNo()) + ","
623: + timeOut);
624:
625: if (!Platform.isWindows() && settings.getTargetWindowRemains()) {
626: commands.add("-XX:+ShowMessageBoxOnError"); // NOI18N
627: }
628:
629: //classptah
630: commands.add("-classpath");
631: commands.add(settings.getMainClassPath());
632:
633: //jvm arguments
634: for (int i = 0; i < settings.getJVMArgs().length; i++) {
635: commands.add(settings.getJVMArgs()[i]);
636: }
637:
638: // debugging property for agent side - wire I/O
639: if (System
640: .getProperty("org.netbeans.lib.profiler.wireprotocol.WireIO.agent") != null) { // NOI18N
641: commands
642: .add("-Dorg.netbeans.lib.profiler.wireprotocol.WireIO=true"); // NOI18N
643: }
644:
645: // debugging property for agent side - Class loader hook
646: if (System
647: .getProperty("org.netbeans.lib.profiler.server.ProfilerInterface.classLoadHook") != null) { // NOI18N
648: commands
649: .add("-Dorg.netbeans.lib.profiler.server.ProfilerInterface.classLoadHook=true"); // NOI18N
650: }
651:
652: //main class of application
653: commands.add(settings.getMainClassName());
654:
655: //arguments of application
656: for (int i = 0; i < settings.getMainArgs().length; i++) {
657: commands.add(settings.getMainArgs()[i]);
658: }
659:
660: String[] cmdArray = new String[commands.size()];
661: commands.toArray(cmdArray);
662:
663: MiscUtils.printInfoMessage("Starting target application..."); // NOI18N
664: MiscUtils.printVerboseInfoMessage(cmdArray);
665:
666: System.err.println("Starting VM with " + cmdArray.length
667: + " commands."); // NOI18N
668:
669: StringBuffer sb = new StringBuffer();
670:
671: for (int i = 0; i < cmdArray.length; i++) {
672: sb.append(cmdArray[i]);
673: sb.append(' ');
674: }
675:
676: System.err.println(sb.toString());
677:
678: try {
679: profilingProcess = Runtime.getRuntime().exec(cmdArray,
680: null, new File(settings.getWorkingDir()));
681:
682: if (profilingProcess != null) {
683: runner.initiateSession(0, false);
684: } else {
685: throw new NullPointerException();
686: }
687:
688: return profilingProcess;
689: } catch (IOException ex) {
690: String s = ""; // NOI18N
691:
692: for (int i = 0; i < cmdArray.length; i++) {
693: s = s + cmdArray[i] + "\n"; // NOI18N
694: }
695:
696: handler
697: .displayError("When starting target JVM, with command: "
698: + s
699: + ", caught an exception: "
700: + ex.getMessage());
701: ex.printStackTrace();
702: }
703:
704: return null;
705: }
706:
707: protected void storeSettings(ProfilerEngineSettings settings,
708: HashMap map) {
709: map
710: .put(
711: "profiler.settings.cpu.profiling.type",
712: ((settings.getCPUProfilingType() == CommonConstants.CPU_INSTR_FULL) ? "CPU_INSTR_FULL"
713: : "CPU_INSTR_SAMPLED"));
714:
715: if (settings.getInstrScheme() == CommonConstants.INSTRSCHEME_LAZY) {
716: map.put("profiler.settings.instr.scheme",
717: "INSTRSCHEME_LAZY");
718: } else if (settings.getInstrScheme() == CommonConstants.INSTRSCHEME_EAGER) {
719: map.put("profiler.settings.instr.scheme",
720: "INSTRSCHEME_EAGER");
721: } else {
722: map.put("profiler.settings.instr.scheme",
723: "INSTRSCHEME_TOTAL");
724: }
725:
726: map.put("profiler.settings.override.working.dir", settings
727: .getWorkingDir());
728: map.put("profiler.settings.override.jvm.args",
729: toString(settings.getJVMArgs()));
730: map.put("profiler.settings.override.port.no", Integer
731: .toString(settings.getPortNo()));
732: map.put("profiler.settings.thread.cpu.timer.on", Boolean
733: .toString(settings.getThreadCPUTimerOn()));
734: map.put("profiler.settings.istrument.getter.setter.methods",
735: Boolean.toString(settings
736: .getInstrumentGetterSetterMethods()));
737: map.put("profiler.settings.instrument.empty.methods", Boolean
738: .toString(settings.getInstrumentEmptyMethods()));
739: map.put("profiler.settings.instrument.method.invoke", Boolean
740: .toString(settings.getInstrumentMethodInvoke()));
741: map.put("profiler.settings.instrument.spawned.threads", Boolean
742: .toString(settings.getInstrumentSpawnedThreads()));
743: map.put("profiler.settings.n.profiled.threads.limit", Integer
744: .toString(settings.getNProfiledThreadsLimit()));
745: map.put("profiler.settings.sort.results.by.thread.cpu.time",
746: Boolean.toString(settings
747: .getSortResultsByThreadCPUTime()));
748: map.put("profiler.settings.sampling.interval", Integer
749: .toString(settings.getSamplingInterval()));
750: map
751: .put("profiler.settings.code.region.cpu.res.buf.size",
752: Integer.toString(settings
753: .getCodeRegionCPUResBufSize()));
754: map
755: .put(
756: "profiler.settings.run.gc.on.get.results.in.memory.profiling",
757: Boolean
758: .toString(settings
759: .getRunGCOnGetResultsInMemoryProfiling()));
760: map.put("profiler.settings.obj.alloc.stack.sampling.interval",
761: Integer.toString(settings.getAllocTrackEvery()));
762: map.put("profiler.settings.obj.alloc.stack.sampling.depth",
763: Integer.toString(settings.getAllocStackTraceLimit()));
764: map.put("profiler.settings.exclude.wait.time", Boolean
765: .toString(settings.getExcludeWaitTime()));
766:
767: InstrumentationFilter filter = settings
768: .getInstrumentationFilter();
769:
770: if (filter != null) {
771: map.put("profiler.settings.instrumentation.filter.string",
772: toString(filter.getFilterStrings()));
773: map
774: .put(
775: "profiler.settings.instrumentation.filter.type",
776: ((filter.getFilterType() == InstrumentationFilter.INSTR_FILTER_EXCLUSIVE) ? "EXCLUSIVE"
777: : "INCLUSIVE"));
778: } else {
779: map
780: .put(
781: "profiler.settings.instrumentation.filter.selected",
782: "NONE");
783: }
784:
785: SourceCodeSelection[] roots = settings
786: .getInstrumentationRootMethods();
787:
788: if ((roots != null) && (roots.length > 0)) {
789: map
790: .put(
791: "profiler.settings.instrumentation.root.methods.size",
792: Integer.toString(roots.length));
793:
794: StringBuffer sb = new StringBuffer();
795:
796: for (int i = 0; i < roots.length; i++) {
797: if (roots[i].getStartLine() > -1) {
798: sb.append(roots[i].getClassName());
799: sb.append("[");
800: sb.append(roots[i].getStartLine());
801: sb.append(", ");
802: sb.append(roots[i].getEndLine());
803: sb.append("]");
804: } else {
805: sb.append(roots[i].getClassName());
806: sb.append(".");
807: sb.append(roots[i].getMethodName());
808: sb.append(roots[i].getMethodSignature());
809: }
810:
811: if (i < (roots.length - 1)) {
812: sb.append(", ");
813: }
814: }
815:
816: map.put("profiler.settings.istrumentation.root.methods-",
817: sb.toString()); //prefix
818: } else {
819: map
820: .put(
821: "profiler.settings.instrumentation.root.methods.size",
822: "0");
823: map.put("profiler.settings.istrumentation.root.methods-",
824: "");
825: }
826: }
827:
828: protected void tearDown() throws Exception {
829: if (refStream != null) {
830: refStream.close();
831:
832: if (CREATE_GOLDENS) {
833: goldenStream.close();
834: } else {
835: boolean bgolden = true;
836:
837: try {
838: getGoldenFile();
839: } catch (Throwable t) {
840: bgolden = false;
841: }
842:
843: if ((bgolden || (ref.length() > 0))
844: && !isStatus(STATUS_ERROR)) {
845: LineDiff ld = new LineDiff();
846: assertFalse("Golden files differ", ld.diff(ref,
847: getGoldenFile(), diff));
848: }
849: }
850: }
851:
852: if (logStream != null) {
853: logStream.close();
854: }
855:
856: System.err.println("Test " + getName() + " finished.");
857: }
858:
859: protected String toString(String[] array) {
860: StringBuffer sb = new StringBuffer();
861:
862: for (int i = 0; i < array.length; i++) {
863: sb.append(array[i]);
864: sb.append(" ");
865: }
866:
867: return sb.toString();
868: }
869:
870: protected String toString(int[] array) {
871: StringBuffer sb = new StringBuffer();
872:
873: for (int i = 0; i < array.length; i++) {
874: sb.append(array[i]);
875: sb.append(" ");
876: }
877:
878: return sb.toString();
879: }
880: }
|