View | Details | Raw Unified | Return to bug 116284 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse RCP Tests/org/eclipse/ui/tests/rcp/performance/EmptyWorkbenchPerfTest.java (-37 / +50 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-93 Link Here
13
import org.eclipse.swt.widgets.Display;
13
import org.eclipse.swt.widgets.Display;
14
import org.eclipse.test.performance.Dimension;
14
import org.eclipse.test.performance.Dimension;
15
import org.eclipse.test.performance.Performance;
15
import org.eclipse.test.performance.Performance;
16
import org.eclipse.test.performance.PerformanceMeter;
16
import org.eclipse.test.performance.PerformanceTestCase;
17
import org.eclipse.test.performance.PerformanceTestCase;
17
import org.eclipse.ui.PlatformUI;
18
import org.eclipse.ui.PlatformUI;
18
import org.eclipse.ui.application.WorkbenchAdvisor;
19
import org.eclipse.ui.application.WorkbenchAdvisor;
19
import org.eclipse.ui.tests.rcp.util.IPerformanceMeterArray;
20
import org.eclipse.ui.tests.rcp.util.IntervalMeters;
21
import org.eclipse.ui.tests.rcp.util.RestoreWorkbenchIntervalMonitor;
22
import org.eclipse.ui.tests.rcp.util.OpenWorkbenchIntervalMonitor;
20
import org.eclipse.ui.tests.rcp.util.OpenWorkbenchIntervalMonitor;
21
import org.eclipse.ui.tests.rcp.util.RestoreWorkbenchIntervalMonitor;
23
22
24
/**
23
/**
25
 * @since 3.1
24
 * @since 3.1
26
 */
25
 */
27
public class EmptyWorkbenchPerfTest extends PerformanceTestCase {
26
public class EmptyWorkbenchPerfTest extends PerformanceTestCase {
28
27
29
    private static final int REPEAT_COUNT = 10;
28
    private static final int REPEAT_COUNT = 25;
30
29
31
    public void testOpen() {
30
    public void testOpen() {
32
        Display display = PlatformUI.createDisplay();
31
        Display display = PlatformUI.createDisplay();
33
34
        Performance perf = Performance.getDefault();
32
        Performance perf = Performance.getDefault();
35
36
        String baseScenarioId = perf.getDefaultScenarioId(this);
33
        String baseScenarioId = perf.getDefaultScenarioId(this);
37
        IPerformanceMeterArray meters = new IntervalMeters(perf, baseScenarioId, OpenWorkbenchIntervalMonitor.intervalNames);
34
        PerformanceMeter startupMeter = perf.createPerformanceMeter( baseScenarioId + " [open]"); 
35
        PerformanceMeter shutdownMeter = perf.createPerformanceMeter( baseScenarioId + " [close]"); 
36
38
        tagAsSummary("Open RCP App", Dimension.CPU_TIME);
37
        tagAsSummary("Open RCP App", Dimension.CPU_TIME);
39
        for (int i = 0; i < REPEAT_COUNT; ++i ) {
38
        for (int i = 0; i < REPEAT_COUNT; ++i ) {
40
            meters.start(OpenWorkbenchIntervalMonitor.firstInterval);
39
        	startupMeter.start();
41
            int code = PlatformUI.createAndRunWorkbench(display,
40
            int code = PlatformUI.createAndRunWorkbench(display,
42
                    new OpenWorkbenchIntervalMonitor(meters));
41
            		new OpenWorkbenchIntervalMonitor(startupMeter, shutdownMeter));
43
            meters.stop(OpenWorkbenchIntervalMonitor.finalInterval);
42
            shutdownMeter.stop();
44
45
            assertEquals(PlatformUI.RETURN_OK, code);
43
            assertEquals(PlatformUI.RETURN_OK, code);
46
        }
44
        }
47
45
48
        display.dispose();
46
        display.dispose();
49
        assertTrue(display.isDisposed());
47
        assertTrue(display.isDisposed());
50
48
        startupMeter.commit();
51
        meters.commit();
49
        perf.assertPerformance(startupMeter);
52
        meters.assertPerformance();
50
        
53
        meters.dispose();
51
        // The shutdown timer is currently < 50ms on all test machine. Due to the granularity of timers
52
        // and inherent Java variability, values below 100ms usually can not be interpreted.
53
        // Rather, check for the absolute value to be below threshold of 120ms.
54
        // If the test goes above it, it probably needs to be investigated.
55
        perf.assertPerformanceInAbsoluteBand(shutdownMeter, Dimension.CPU_TIME, 0, 120);
56
        
57
    	startupMeter.dispose();
58
    	shutdownMeter.dispose();
54
    }
59
    }
55
60
56
    public void testRestore() {
61
    public void testRestore() {
57
        Display display = PlatformUI.createDisplay();
62
        Display display = PlatformUI.createDisplay();
58
63
        Performance perf = Performance.getDefault();
64
        String baseScenarioId = perf.getDefaultScenarioId(this);
65
        PerformanceMeter startupMeter = perf.createPerformanceMeter( baseScenarioId + " [open]"); 
66
        PerformanceMeter shutdownMeter = perf.createPerformanceMeter( baseScenarioId + " [close]");
67
        
59
        // create an advisor that will just start the workbench long enough to create
68
        // create an advisor that will just start the workbench long enough to create
60
        // something to be restored later
69
        // something to be restored later
61
        WorkbenchAdvisor wa = new RestoreWorkbenchIntervalMonitor();
70
        PerformanceMeter startupMeter0 = perf.createPerformanceMeter( baseScenarioId + " [0][open]"); 
62
71
        PerformanceMeter shutdownMeter0 = perf.createPerformanceMeter( baseScenarioId + " [0][close]");
72
        WorkbenchAdvisor wa = new RestoreWorkbenchIntervalMonitor(startupMeter0, shutdownMeter0, true);
63
        int code = PlatformUI.createAndRunWorkbench(display, wa);
73
        int code = PlatformUI.createAndRunWorkbench(display, wa);
64
        assertEquals(PlatformUI.RETURN_RESTART, code);
74
        assertEquals(PlatformUI.RETURN_RESTART, code);
65
        assertFalse(display.isDisposed());
75
        assertFalse(display.isDisposed());
66
76
    	startupMeter0.dispose();
67
        // the rest is a bunch of code to restore the workbench and monitor performance
77
    	shutdownMeter0.dispose();
68
        // while doing so
78
       
69
70
        Performance perf = Performance.getDefault();
71
72
        String baseScenarioId = perf.getDefaultScenarioId(this);
73
        IPerformanceMeterArray meters = new IntervalMeters(perf, baseScenarioId, RestoreWorkbenchIntervalMonitor.intervalNames);
74
75
        tagAsSummary("Restore RCP App", Dimension.CPU_TIME);
79
        tagAsSummary("Restore RCP App", Dimension.CPU_TIME);
76
        
80
        
81
        // the rest is a bunch of code to restore the workbench and monitor performance
82
        // while doing so
77
        for (int i = 0; i < REPEAT_COUNT; ++i ) {
83
        for (int i = 0; i < REPEAT_COUNT; ++i ) {
78
            meters.start(RestoreWorkbenchIntervalMonitor.firstInterval);
84
        	startupMeter.start();
79
            code = PlatformUI.createAndRunWorkbench(display,
85
            code = PlatformUI.createAndRunWorkbench(display,
80
                    new RestoreWorkbenchIntervalMonitor(meters));
86
                    new RestoreWorkbenchIntervalMonitor(startupMeter, shutdownMeter, false));
81
            meters.stop(RestoreWorkbenchIntervalMonitor.finalInterval);
87
            shutdownMeter.stop();
82
83
            assertEquals(PlatformUI.RETURN_OK, code);
88
            assertEquals(PlatformUI.RETURN_OK, code);
84
        }
89
        }
85
90
        
86
        meters.commit();
87
        meters.assertPerformance();
88
        meters.dispose();
89
90
        display.dispose();
91
        display.dispose();
91
        assertTrue(display.isDisposed());
92
        assertTrue(display.isDisposed());
93
        
94
        startupMeter.commit();
95
        perf.assertPerformance(startupMeter);
96
        
97
        // The shutdown timer is currently < 50ms on all test machine. Due to the granularity of timers
98
        // and inherit Java variability, values below 100ms usually can not be interpreted.
99
        // Rather, check for the absolute value to be below threshold of 120ms.
100
        // If the test goes above it, it probably needs to be investigated.
101
        perf.assertPerformanceInAbsoluteBand(shutdownMeter, Dimension.CPU_TIME, 0, 120);
102
        
103
    	startupMeter.dispose();
104
    	shutdownMeter.dispose();
92
    }
105
    }
93
}
106
}
(-)Eclipse RCP Tests/org/eclipse/ui/tests/rcp/util/OpenWorkbenchIntervalMonitor.java (-86 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.tests.rcp.util;
11
package org.eclipse.ui.tests.rcp.util;
12
12
13
import org.eclipse.ui.IWorkbenchWindow;
13
import org.eclipse.test.performance.PerformanceMeter;
14
import org.eclipse.ui.application.IActionBarConfigurer;
15
import org.eclipse.ui.application.IWorkbenchConfigurer;
16
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
17
import org.eclipse.ui.tests.harness.util.RCPTestWorkbenchAdvisor;
14
import org.eclipse.ui.tests.harness.util.RCPTestWorkbenchAdvisor;
18
15
19
16
Lines 25-121 Link Here
25
 */
22
 */
26
public class OpenWorkbenchIntervalMonitor extends RCPTestWorkbenchAdvisor {
23
public class OpenWorkbenchIntervalMonitor extends RCPTestWorkbenchAdvisor {
27
24
28
    public static final String[] intervalNames = new String[] {
25
    private PerformanceMeter startupMeter; 
29
        "open", //$NON-NLS-1$
26
    private PerformanceMeter shutdownMeter; 
30
        "close" //$NON-NLS-1$
31
	};
32
	
33
	public static final int openInterval = 0;
34
	public static final int closeInterval = 1;
35
	
36
	public static final int firstInterval = openInterval;
37
	public static final int finalInterval = closeInterval;
38
39
//    public static final String[] intervalNames = new String[] {
40
//            "to initialize", //$NON-NLS-1$
41
//            "initialize to preStartup", //$NON-NLS-1$
42
//            "preStartup to preWindowOpen", //$NON-NLS-1$
43
//            "preWindowOpen to fillActionBars", //$NON-NLS-1$
44
//            "fillActionBars to postWindowOpen", //$NON-NLS-1$
45
//            "postWindowOpen to postStartup", //$NON-NLS-1$
46
//            "preShutdown to postShutdown", //$NON-NLS-1$
47
//            "postShutdown to complete" //$NON-NLS-1$
48
//    };
49
//
50
//    public static final int initializeInterval = 0;
51
//    public static final int preStartupInterval = 1;
52
//    public static final int preWindowOpenInterval = 2;
53
//    public static final int fillActionBarsInterval = 3;
54
//    public static final int postWindowOpenInterval = 4;
55
//    public static final int postStartupInterval = 5;
56
//    public static final int shutdownInterval = 6;
57
//    public static final int workbenchDestroyedInterval = 7;
58
//
59
//    public static final int firstInterval = initializeInterval;
60
//    public static final int finalInterval = workbenchDestroyedInterval;
61
27
62
    private IPerformanceMeterArray meters;
28
    public OpenWorkbenchIntervalMonitor(PerformanceMeter startupMeter, PerformanceMeter shutdownMeter) {
63
64
    public OpenWorkbenchIntervalMonitor(IPerformanceMeterArray meters) {
65
        super(2);
29
        super(2);
66
        this.meters = meters;
30
        this.startupMeter = startupMeter;
67
    }
31
        this.shutdownMeter = shutdownMeter;
68
69
    public void initialize(IWorkbenchConfigurer configurer) {
70
//        meters.stop(initializeInterval);
71
//        meters.start(preStartupInterval);
72
        super.initialize(configurer);
73
    }
74
75
    public void preStartup() {
76
//        meters.stop(preStartupInterval);
77
//        meters.start(preWindowOpenInterval);
78
        super.preStartup();
79
    }
80
81
    public void preWindowOpen(IWorkbenchWindowConfigurer configurer) {
82
//        meters.stop(preWindowOpenInterval);
83
//        meters.start(fillActionBarsInterval);
84
        super.preWindowOpen(configurer);
85
    }
86
87
    public void fillActionBars(IWorkbenchWindow window, IActionBarConfigurer configurer, int flags) {
88
//        meters.stop(fillActionBarsInterval);
89
//        meters.start(postWindowOpenInterval);
90
        super.fillActionBars(window, configurer, flags);
91
92
    }
93
94
    public void postWindowOpen(IWorkbenchWindowConfigurer configurer) {
95
//        meters.stop(postWindowOpenInterval);
96
//        meters.start(postStartupInterval);
97
        super.postWindowOpen(configurer);
98
    }
32
    }
99
33
100
    public void postStartup() {
34
    public void postStartup() {
101
//        meters.stop(postStartupInterval);
35
    	startupMeter.stop();
102
    	meters.stop(openInterval);
36
        // no reason to track performance between when startup completes and shutdown starts
103
    	
104
        // no reason to track performace between when startup completes and shutdown starts
105
        // since that is just testing overhead
37
        // since that is just testing overhead
106
107
        super.postStartup();
38
        super.postStartup();
108
    }
39
    }
109
40
110
    public boolean preShutdown() {
41
    public boolean preShutdown() {
111
//        meters.start(shutdownInterval);
42
    	shutdownMeter.start();
112
    	meters.start(closeInterval);
113
        return super.preShutdown();
43
        return super.preShutdown();
114
    }
44
    }
115
116
    public void postShutdown() {
117
//        meters.stop(shutdownInterval);
118
//        meters.start(workbenchDestroyedInterval);
119
        super.postShutdown();
120
    }
121
}
45
}
(-)Eclipse RCP Tests/org/eclipse/ui/tests/rcp/util/RestoreWorkbenchIntervalMonitor.java (-100 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-21 Link Here
11
package org.eclipse.ui.tests.rcp.util;
11
package org.eclipse.ui.tests.rcp.util;
12
12
13
import org.eclipse.swt.widgets.Display;
13
import org.eclipse.swt.widgets.Display;
14
import org.eclipse.ui.IWorkbenchWindow;
14
import org.eclipse.test.performance.PerformanceMeter;
15
import org.eclipse.ui.WorkbenchException;
16
import org.eclipse.ui.application.IActionBarConfigurer;
17
import org.eclipse.ui.application.IWorkbenchConfigurer;
15
import org.eclipse.ui.application.IWorkbenchConfigurer;
18
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
19
import org.eclipse.ui.tests.harness.util.RCPTestWorkbenchAdvisor;
16
import org.eclipse.ui.tests.harness.util.RCPTestWorkbenchAdvisor;
20
17
21
18
Lines 27-154 Link Here
27
 */
24
 */
28
public class RestoreWorkbenchIntervalMonitor extends RCPTestWorkbenchAdvisor {
25
public class RestoreWorkbenchIntervalMonitor extends RCPTestWorkbenchAdvisor {
29
26
30
    public static final String[] intervalNames = new String[] {
27
    private PerformanceMeter startupMeter; 
31
        "open", //$NON-NLS-1$
28
    private PerformanceMeter shutdownMeter; 
32
        "close" //$NON-NLS-1$
33
	};
34
	
35
	public static final int openInterval = 0;
36
	public static final int closeInterval = 1;
37
	
38
	public static final int firstInterval = openInterval;
39
	public static final int finalInterval = closeInterval;
40
	
29
	
41
	private boolean createRestorableWorkbench = false;
30
	private boolean createRestorableWorkbench = false;
42
	private IPerformanceMeterArray meters = new NullMeters();
43
	
31
	
44
//    public static final String[] intervalNames = new String[] {
45
//            "to initialize", //$NON-NLS-1$
46
//            "initialize to preStartup", //$NON-NLS-1$
47
//            "preStartup to preWindowOpen", //$NON-NLS-1$
48
//            "preWindowOpen to fillActionBars", //$NON-NLS-1$
49
//            "fillActionBars to postWindowRestore", //$NON-NLS-1$
50
//            "postWindowRestore to postWindowOpen", //$NON-NLS-1$
51
//            "postWindowOpen to postStartup", //$NON-NLS-1$
52
//            "preShutdown to postShutdown", //$NON-NLS-1$
53
//            "postShutdown to complete" //$NON-NLS-1$
54
//    };
55
//
56
//    public static final int initializeInterval = 0;
57
//    public static final int preStartupInterval = 1;
58
//    public static final int preWindowOpenInterval = 2;
59
//    public static final int fillActionBarsInterval = 3;
60
//    public static final int postWindowRestoreInterval = 4;
61
//    public static final int postWindowOpenInterval = 5;
62
//    public static final int postStartupInterval = 6;
63
//    public static final int shutdownInterval = 7;
64
//    public static final int workbenchDestroyedInterval = 8;
65
//
66
//    public static final int firstInterval = initializeInterval;
67
//    public static final int finalInterval = workbenchDestroyedInterval;
68
//
69
//    private boolean createRestorableWorkbench = false;
70
//    private IPerformanceMeterArray meters = new NullMeters();
71
72
    private IWorkbenchConfigurer workbenchConfigurer;
32
    private IWorkbenchConfigurer workbenchConfigurer;
73
33
74
    /**
34
    /**
75
     * The default behaviour is to create a workbench that can be restored later.  This
35
     * The default behavior is to create a workbench that can be restored later.  This
76
     * constructor starts that behaviour by setting a flag that will be checked in the
36
     * constructor starts that behavior by setting a flag that will be checked in the
77
     * appropriate methods.
37
     * appropriate methods.
78
     */
38
     */
79
    public RestoreWorkbenchIntervalMonitor() {
39
    public RestoreWorkbenchIntervalMonitor(PerformanceMeter startupMeter, PerformanceMeter shutdownMeter, boolean createRestorableWorkbench) {
80
        super(2);
81
        createRestorableWorkbench = true;
82
    }
83
84
    public RestoreWorkbenchIntervalMonitor(IPerformanceMeterArray meters) {
85
        super(2);
40
        super(2);
86
        this.meters = meters;
41
        this.startupMeter = startupMeter;
42
        this.shutdownMeter = shutdownMeter;
43
        this.createRestorableWorkbench = createRestorableWorkbench;
87
    }
44
    }
88
45
89
    public void initialize(IWorkbenchConfigurer configurer) {
46
    public void initialize(IWorkbenchConfigurer configurer) {
90
//        meters.stop(initializeInterval);
91
92
        super.initialize(configurer);
47
        super.initialize(configurer);
93
        workbenchConfigurer = configurer;
48
        workbenchConfigurer = configurer;
94
        workbenchConfigurer.setSaveAndRestore(true);
49
        workbenchConfigurer.setSaveAndRestore(true);
95
96
//        meters.start(preStartupInterval);
97
    }
98
99
    public void preStartup() {
100
//        meters.stop(preStartupInterval);
101
        super.preStartup();
102
//        meters.start(preWindowOpenInterval);
103
    }
104
105
    public void preWindowOpen(IWorkbenchWindowConfigurer configurer) {
106
//        meters.stop(preWindowOpenInterval);
107
        super.preWindowOpen(configurer);
108
//        meters.start(fillActionBarsInterval);
109
    }
110
111
    public void fillActionBars(IWorkbenchWindow window, IActionBarConfigurer configurer, int flags) {
112
//        meters.stop(fillActionBarsInterval);
113
        super.fillActionBars(window, configurer, flags);
114
//        meters.start(postWindowRestoreInterval);
115
    }
116
117
    public void postWindowRestore(IWorkbenchWindowConfigurer configurer) throws WorkbenchException {
118
//        meters.stop(postWindowRestoreInterval);
119
        super.postWindowRestore(configurer);
120
//        meters.start(postWindowOpenInterval);
121
    }
122
123
    public void postWindowOpen(IWorkbenchWindowConfigurer configurer) {
124
//        meters.stop(postWindowOpenInterval);
125
        super.postWindowOpen(configurer);
126
//        meters.start(postStartupInterval);
127
    }
50
    }
128
51
129
    public void postStartup() {
52
    public void postStartup() {
130
//        meters.stop(postStartupInterval);
53
    	startupMeter.stop();
131
        meters.stop(openInterval);
54
        // no reason to track performance between when startup completes and shutdown starts
132
133
        // no reason to track performace between when startup completes and shutdown starts
134
        // since that is just testing overhead
55
        // since that is just testing overhead
135
136
        super.postStartup();
56
        super.postStartup();
137
    }
57
    }
138
58
139
    public boolean preShutdown() {
59
    public boolean preShutdown() {
140
        boolean ret = super.preShutdown();
60
        boolean ret = super.preShutdown();
141
//        meters.start(shutdownInterval);
61
        shutdownMeter.start();
142
        meters.start(closeInterval);
143
        return ret;
62
        return ret;
144
    }
63
    }
145
64
146
    public void postShutdown() {
147
//        meters.stop(shutdownInterval);
148
        super.postShutdown();
149
//        meters.start(workbenchDestroyedInterval);
150
    }
151
152
    public void eventLoopIdle(Display d) {
65
    public void eventLoopIdle(Display d) {
153
        if (createRestorableWorkbench)
66
        if (createRestorableWorkbench)
154
            workbenchConfigurer.getWorkbench().restart();
67
            workbenchConfigurer.getWorkbench().restart();
(-)Eclipse RCP Tests/org/eclipse/ui/tests/rcp/util/NullMeters.java (-47 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.tests.rcp.util;
12
13
/**
14
 * An empty array of meters, all calls are ignored.
15
 * 
16
 * @since 3.1
17
 */
18
public class NullMeters implements IPerformanceMeterArray {
19
20
    public NullMeters() {
21
        // do nothing
22
    }
23
24
    public void start(int meterIndex) {
25
        // do nothing
26
    }
27
28
    public void stop(int meterIndex) {
29
        // do nothing
30
    }
31
32
    public void intervalBoundary(int completedIntervalIndex) {
33
        // do nothing
34
    }
35
36
    public void commit() {
37
        // do nothing
38
    }
39
40
    public void assertPerformance() {
41
        // do nothing
42
    }
43
44
    public void dispose() {
45
        // do nothing
46
    }
47
}
(-)Eclipse RCP Tests/org/eclipse/ui/tests/rcp/util/IntervalMeters.java (-84 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.tests.rcp.util;
12
13
import org.eclipse.test.performance.Performance;
14
import org.eclipse.test.performance.PerformanceMeter;
15
16
/**
17
 * A set of meters that should be used to check performance of intervals.  For example, this
18
 * collection is used to check performance between all stages of the workbench life-cycle
19
 * (the significant events are marked in the WorkbenchAdvisor callbacks).
20
 * 
21
 * @since 3.1
22
 */
23
public class IntervalMeters implements IPerformanceMeterArray {
24
25
    private Performance perf;
26
    private String baseScenarioId;
27
28
    /**
29
     * Clients instantiate the interval meter set as a specific size and are then responsible
30
     * for controlling by index.
31
     */
32
    private PerformanceMeter[] meters;
33
34
    /**
35
     * Create an set of performance meters using the argument array of strings in the name
36
     * for each one
37
     * @param intervals
38
     */
39
    public IntervalMeters(Performance perf, String baseScenarioId, String[] intervals) {
40
        this.perf = perf;
41
        this.baseScenarioId = baseScenarioId;
42
43
        meters = new PerformanceMeter[intervals.length];
44
        for (int i = 0; i < intervals.length; ++i) {
45
            meters[i] = perf.createPerformanceMeter(getScenarioId(intervals[i]));
46
        }
47
    }
48
49
    private String getScenarioId(String intervalName) {
50
        return baseScenarioId + " [" + intervalName + ']'; //$NON-NLS-1$
51
    }
52
53
    public void start(int meterIndex) {
54
        meters[meterIndex].start();
55
    }
56
57
    public void stop(int meterIndex) {
58
        meters[meterIndex].stop();
59
    }
60
61
    /**
62
     * The interval at the argument has completed.  Stop that meter and start the next.
63
     * @param completedIntervalIndex
64
     */
65
    public void intervalBoundary(int completedIntervalIndex) {
66
        meters[completedIntervalIndex].stop();
67
        meters[completedIntervalIndex + 1].start();
68
    }
69
70
    public void commit() {
71
        for (int i = 0; i < meters.length; ++i)
72
            meters[i].commit();
73
    }
74
75
    public void assertPerformance() {
76
        for (int i = 0; i < meters.length; ++i)
77
            perf.assertPerformance(meters[i]);
78
    }
79
80
    public void dispose() {
81
        for (int i = 0; i < meters.length; ++i)
82
            meters[i].dispose();
83
    }
84
}
(-)Eclipse RCP Tests/org/eclipse/ui/tests/rcp/util/IPerformanceMeterArray.java (-44 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.tests.rcp.util;
12
13
/**
14
 * An array of performance meters that can be used for things like interval timing.
15
 * 
16
 * @since 3.1
17
 */
18
public interface IPerformanceMeterArray {
19
20
    /**
21
     * Start the meter at the argument index.
22
     */
23
    public void start(int meterIndex);
24
25
    /**
26
     * Stop the meter at the argument index.
27
     */
28
    public void stop(int meterIndex);
29
30
    /**
31
     * Commit all meters in this array.
32
     */
33
    public void commit();
34
35
    /**
36
     * Assert the performance of all meters in this array.
37
     */
38
    public void assertPerformance();
39
40
    /**
41
     * Dispose all meters in this array.
42
     */
43
    public void dispose();
44
}

Return to bug 116284