Bug 78166 - [performance test] console
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/performance/PerfConsoleTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/performance/PerfConsoleTests.java
index b8761d0..91dd327 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/performance/PerfConsoleTests.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/performance/PerfConsoleTests.java
@@ -28,143 +28,192 @@
  * Tests performance of the console.
  */
 public class PerfConsoleTests extends AbstractDebugPerformanceTest implements IConsoleLineTrackerExtension {
-	
-	protected boolean fStarted = false;
-	protected boolean fStopped = false;
-	protected Object fLock = new Object();
-	
-	public PerfConsoleTests(String name) {
-		super(name);
-	}
 
-	public void testDefault10k() throws Exception {
-		runFixedWidthTest(10000);		
-	}
-	
-	public void testDefault100k() throws Exception {
-		tagAsSummary("100,000 lines", Dimension.CPU_TIME);
-		runFixedWidthTest(100000);		
-	}
-	
-	public void testStackTrace10k() throws Exception {
-	    runStackTrace(5000); // 2 lines * 5000 repeats = 10,000 hyperlinks
-	}
-	
-	public void testStackTrace100k() throws Exception {
-		tagAsSummary("100,000 lines with hyperlinks", Dimension.CPU_TIME);
-	    runStackTrace(50000); // 2 lines * 50,000 repeats = 100,000 hyperlinks
-	}
-	
-	public void testVarLength10k() throws Exception {
-	    runVariableLength(2500); // 4 lines * 2500 repeats = 10,000 lines
-	}
-	
-	public void testVarLength100k() throws Exception {
-		tagAsSummary("100,000 variable length lines", Dimension.CPU_TIME);
-	    runVariableLength(25000); // 4 lines * 25,000 repeats = 100,000 lines
-	}		
-		
+    protected boolean fWarmingUp = false;
+
+    protected boolean fStarted = false;
+
+    protected boolean fStopped = false;
+
+    protected Object fLock = new Object();
+
+    public PerfConsoleTests(String name) {
+        super(name);
+    }
+
+    public void testProcessConsolePlainOutput100Lines() throws Exception {
+        tagAsGlobalSummary("Process Console 100 lines: plain output", Dimension.CPU_TIME);
+        runConsole80CharsTest(100, 100);
+    }
+
+    public void testProcessConsolePlainOutput10000Lines() throws Exception {
+        tagAsSummary("Process Console 10,000 lines: plain output", Dimension.CPU_TIME);
+        runConsole80CharsTest(10000, 10);
+    }
+
+    public void testProcessConsoleStackTraceOutput100Lines() throws Exception {
+        tagAsSummary("Process Console 100 lines: stack trace output", Dimension.CPU_TIME);
+        runStackTrace(50, 100); // 2 lines * 50 repeats = 100 lines
+    }
+
+    public void testProcessConsoleStackTraceOutput10000Lines() throws Exception {
+        tagAsSummary("Process Console 10,000 lines: stack trace output", Dimension.CPU_TIME);
+        runStackTrace(5000, 10); // 2 lines * 5000 repeats = 10000 lines
+    }
+
+    public void testProcessConsoleWrappedOutput100Lines() throws Exception {
+        tagAsSummary("Process Console 100 lines: wrapped output", Dimension.CPU_TIME);
+        runVariableLength(25, 100); // 4 lines * 25 repeats = 100 lines
+    }
+
+    public void testProcessConsoleWrappedOutput10000Lines() throws Exception {
+        tagAsSummary("Process Console 10,000 lines: wrapped output", Dimension.CPU_TIME);
+        runVariableLength(2500, 10); // 4 lines * 2500 repeats = 10000 lines
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
         fStarted = false;
         fStopped = false;
         ConsoleLineTracker.setDelegate(this);
     }
-    
-    /* (non-Javadoc)
+
+    /*
+     * (non-Javadoc)
+     * 
      * @see junit.framework.TestCase#tearDown()
      */
     protected void tearDown() throws Exception {
         super.tearDown();
         ConsoleLineTracker.setDelegate(null);
     }
-    
-	protected void runFixedWidthTest(int lines) throws Exception {
-	    String typeName = "Console80Chars";
-	    ILaunchConfiguration configuration = getLaunchConfiguration(typeName);
-	    ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy();
-	    workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, Integer.toString(lines));
-        workingCopy.launch(ILaunchManager.RUN_MODE, null, false);
-		synchronized (fLock) {
-		    if (!fStopped) {
-		        fLock.wait(360000);
-		    }
-		}
-		assertTrue("Never received 'start' notification", fStarted);
-		assertTrue("Never received 'stopped' notification", fStopped);
-		commitMeasurements();
-		assertPerformance();	        
-	}
-	
-	protected void runStackTrace(int repeats) throws Exception {
-	    String typeName = "ConsoleStackTrace";
-	    ILaunchConfiguration configuration = getLaunchConfiguration(typeName);
-	    ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy();
-	    workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, Integer.toString(repeats));
-        workingCopy.launch(ILaunchManager.RUN_MODE, null, false);
-		synchronized (fLock) {
-		    if (!fStopped) {
-		        fLock.wait(360000);
-		    }
-		}
-		assertTrue("Never received 'start' notification", fStarted);
-		assertTrue("Never received 'stopped' notification", fStopped);
-		commitMeasurements();
-		assertPerformance();	        
-	}
-	
-	protected void runVariableLength(int repeats) throws Exception {
-	    String typeName = "ConsoleVariableLineLength";
-	    ILaunchConfiguration configuration = getLaunchConfiguration(typeName);
-	    ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy();
-	    workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, Integer.toString(repeats));
-	    IPreferenceStore debugUIPreferences = DebugUIPlugin.getDefault().getPreferenceStore();
-	    try {
-	        debugUIPreferences.setValue(IDebugPreferenceConstants.CONSOLE_WRAP, true);
-	        workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, Integer.toString(repeats));
-	        workingCopy.launch(ILaunchManager.RUN_MODE, null, false);
-			synchronized (fLock) {
-			    if (!fStopped) {
-			        fLock.wait(360000);
-			    }
-			}
-			assertTrue("Never received 'start' notification", fStarted);
-			assertTrue("Never received 'stopped' notification", fStopped);
-			commitMeasurements();
-			assertPerformance();	        
-	    } finally {
-	        debugUIPreferences.setValue(IDebugPreferenceConstants.CONSOLE_WRAP, false);
-	    }
-	}
 
-    /* (non-Javadoc)
+    protected void runConsole80CharsTest(int lines, int repeatTest) throws Exception {
+        String typeName = "Console80Chars";
+        ILaunchConfiguration configuration = getLaunchConfiguration(typeName);
+        ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy();
+        workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, Integer.toString(lines));
+
+        warmupRun(workingCopy);
+
+        for (int i = 0; i < repeatTest; i++) {
+            launchWorkingCopyAndWait(workingCopy);
+            assertTrue("Never received 'start' notification", fStarted);
+            assertTrue("Never received 'stopped' notification", fStopped);
+            fStopped = false;
+        }
+        commitMeasurements();
+        assertPerformance();
+    }
+
+    /*
+     * prints (2*prints)+2 lines
+     */
+    protected void runStackTrace(int prints, int repeatTest) throws Exception {
+        String typeName = "ConsoleStackTrace";
+        ILaunchConfiguration configuration = getLaunchConfiguration(typeName);
+        ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy();
+        workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, Integer.toString(prints));
+
+        warmupRun(workingCopy);
+
+        for (int i = 0; i < repeatTest; i++) {
+            launchWorkingCopyAndWait(workingCopy);
+            assertTrue("Never received 'start' notification", fStarted);
+            assertTrue("Never received 'stopped' notification", fStopped);
+            fStopped = false;
+
+        }
+        commitMeasurements();
+        assertPerformance();
+    }
+
+    /*
+     * prints (4*prints)+2 lines
+     */
+    protected void runVariableLength(int prints, int repeatTest) throws Exception {
+        String typeName = "ConsoleVariableLineLength";
+        ILaunchConfiguration configuration = getLaunchConfiguration(typeName);
+        ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy();
+        workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, Integer.toString(prints));
+        IPreferenceStore debugUIPreferences = DebugUIPlugin.getDefault().getPreferenceStore();
+        try {
+            debugUIPreferences.setValue(IDebugPreferenceConstants.CONSOLE_WRAP, true);
+            workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, Integer.toString(prints));
+
+            warmupRun(workingCopy);
+
+            for (int i = 0; i < repeatTest; i++) {
+                launchWorkingCopyAndWait(workingCopy);
+                assertTrue("Never received 'start' notification", fStarted);
+                assertTrue("Never received 'stopped' notification", fStopped);
+                fStopped = false;
+            }
+            commitMeasurements();
+            assertPerformance();
+        } finally {
+            debugUIPreferences.setValue(IDebugPreferenceConstants.CONSOLE_WRAP, false);
+        }
+    }
+
+    protected void warmupRun(ILaunchConfigurationWorkingCopy workingCopy) throws Exception {
+        fWarmingUp = true;
+        for (int i = 0; i < 5; i++) {
+            launchWorkingCopyAndWait(workingCopy);
+            fStopped = false;
+        }
+        fWarmingUp = false;
+    }
+
+    protected void launchWorkingCopyAndWait(ILaunchConfigurationWorkingCopy workingCopy) throws Exception {
+        workingCopy.launch(ILaunchManager.RUN_MODE, null, false);
+        synchronized (fLock) {
+            if (!fStopped) {
+                fLock.wait(360000);
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
      * @see org.eclipse.debug.ui.console.IConsoleLineTrackerExtension#consoleClosed()
      */
     public void consoleClosed() {
-        stopMeasuring();
-	    synchronized (fLock) {
-			fStopped = true;
-			fLock.notifyAll();
-        }        
+        if (fStarted) {
+            stopMeasuring();
+        }
+        synchronized (fLock) {
+            fStopped = true;
+            fLock.notifyAll();
+        }
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see org.eclipse.debug.ui.console.IConsoleLineTracker#init(org.eclipse.debug.ui.console.IConsole)
      */
     public void init(IConsole console) {
-        fStarted = true;
-        startMeasuring();
+        if (!fWarmingUp) {
+            fStarted = true;
+            startMeasuring();
+        }
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see org.eclipse.debug.ui.console.IConsoleLineTracker#lineAppended(org.eclipse.jface.text.IRegion)
      */
     public void lineAppended(IRegion line) {
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see org.eclipse.debug.ui.console.IConsoleLineTracker#dispose()
      */
-    public void dispose() {        
-    }		
+    public void dispose() {
+    }
 }