Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 055313a56091f498c61ef5111a387f161a758c68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*******************************************************************************
 *  Copyright (c) 2000, 2009 IBM Corporation and others.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 * 
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.debug.tests.performance;

import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.console.IConsole;
import org.eclipse.debug.ui.console.IConsoleLineTrackerExtension;
import org.eclipse.jdt.debug.testplugin.ConsoleLineTracker;
import org.eclipse.jdt.debug.tests.AbstractDebugPerformanceTest;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IRegion;
import org.eclipse.test.performance.Dimension;

/**
 * Tests performance of the console.
 */
public class PerfConsoleTests extends AbstractDebugPerformanceTest implements IConsoleLineTrackerExtension {

    protected boolean fWarmingUp = false;

    protected boolean fStarted = false;

    protected boolean fStopped = false;

    protected Object fLock = new Object();

    /**
     * Constructor
     * @param name
     */
    public PerfConsoleTests(String name) {
        super(name);
    }


    /**
     * Tests the performance of 1000 lines of plain output to the console
     * @throws Exception
     */
    public void testProcessConsolePlainOutput10000Lines() throws Exception {
        tagAsSummary("Process Console 10,000 lines: plain output", Dimension.ELAPSED_PROCESS);
        runConsole80CharsTest(10000, 75);
    }
    
    /**
     * Tests the performance of 10000 lines of stack trace output to the console
     * @throws Exception
     */
    public void testProcessConsoleStackTraceOutput10000Lines() throws Exception {
        tagAsSummary("Process Console 10,000 lines: stack trace output", Dimension.ELAPSED_PROCESS);
        runStackTrace(5000, 75); // 2 lines * 5000 repeats = 10000 lines
    }

    /**
     * Tests the performance of 10000 lines of wrapped process console output to the console 
     * @throws Exception
     */
    public void testProcessConsoleWrappedOutput10000Lines() throws Exception {
        tagAsSummary("Process Console 10,000 lines: wrapped output", Dimension.ELAPSED_PROCESS);
        runVariableLength(2500, 75); // 4 lines * 2500 repeats = 10000 lines
    }

    /**
     * @see org.eclipse.jdt.debug.tests.AbstractDebugPerformanceTest#setUp()
     */
    @Override
	protected void setUp() throws Exception {
        super.setUp();
        fStarted = false;
        fStopped = false;
        ConsoleLineTracker.setDelegate(this);
    }

    /**
     * @see org.eclipse.jdt.debug.tests.AbstractDebugPerformanceTest#tearDown()
     */
    @Override
	protected void tearDown() throws Exception {
        super.tearDown();
        ConsoleLineTracker.setDelegate(null);
    }

    /**
     * Runs the 
     * @param lines
     * @param repeatTest
     * @throws Exception
     */
    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);
        }
    }

    /**
     * A warmup run of launching and having output piped to the console
     * @param workingCopy
     * @throws Exception
     */
    protected void warmupRun(ILaunchConfigurationWorkingCopy workingCopy) throws Exception {
        fWarmingUp = true;
        for (int i = 0; i < 5; i++) {
            launchWorkingCopyAndWait(workingCopy);
            fStopped = false;
        }
        fWarmingUp = false;
    }

    /**
     * Launches the specified working copy and then waits
     * @param workingCopy
     * @throws Exception
     */
    protected void launchWorkingCopyAndWait(final ILaunchConfigurationWorkingCopy workingCopy) throws Exception {
        Runnable runnable = new Runnable() {
            public void run() {
                DebugUITools.launch(workingCopy, ILaunchManager.RUN_MODE);
            }
        };
        
        DebugUIPlugin.getStandardDisplay().asyncExec(runnable);
        
        synchronized (fLock) {
            if (!fStopped) {
                fLock.wait(360000);
            }
        }
    }

    /**
     * @see org.eclipse.debug.ui.console.IConsoleLineTrackerExtension#consoleClosed()
     */
    public void consoleClosed() {
        if (fStarted) {
            stopMeasuring();
        }
        synchronized (fLock) {
            fStopped = true;
            fLock.notifyAll();
        }
    }

    /**
     * @see org.eclipse.debug.ui.console.IConsoleLineTracker#init(org.eclipse.debug.ui.console.IConsole)
     */
    public void init(IConsole console) {
        if (!fWarmingUp) {
            fStarted = true;
            startMeasuring();
        }
    }

    /**
     * @see org.eclipse.debug.ui.console.IConsoleLineTracker#lineAppended(org.eclipse.jface.text.IRegion)
     */
    public void lineAppended(IRegion line) {
    }

    /**
     * @see org.eclipse.debug.ui.console.IConsoleLineTracker#dispose()
     */
    public void dispose() {
    }
}

Back to the top